Report Request LOG dan Final LOG
This commit is contained in:
58
Modules/Internal/Transformers/ReportLogResource.php
Normal file
58
Modules/Internal/Transformers/ReportLogResource.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Internal\Transformers;
|
||||
|
||||
use App\Helpers\Helper;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Organization;
|
||||
use App\Models\File;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ReportLogResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$filesGroupByType = $this->files->mapToGroups(function($file) {
|
||||
return [Str::slug($file->type, '_') => $file];
|
||||
});
|
||||
$provider = Organization::where('id', $this->organization_id)->first();
|
||||
$documentQty = File::where(['fileable_type' => 'App\Models\RequestLog', 'fileable_id' => $this->id])->get()->toArray();
|
||||
$parsedDateTime = Carbon::parse($this->created_at);
|
||||
$formattedDateTime = $parsedDateTime->format('Y-m-d H:i:s');
|
||||
|
||||
$durationGl = Helper::differenceTime($formattedDateTime, $this->submission_date);
|
||||
$durationFinalGl = Helper::differenceTime($this->created_final_at, $this->approved_by);
|
||||
|
||||
$data = [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'created_at' => $formattedDateTime,
|
||||
'created_final_at' => $this->created_final_at,
|
||||
'submission_date' => $this->submission_date,
|
||||
'approved_by' => Helper::userName($this->approved_by),
|
||||
'approved_final_log_at' => $this->approved_final_log_at,
|
||||
'approved_final_log_by' => Helper::userName($this->approved_final_log_by),
|
||||
'service_name' => $this->service ? $this->service->name : '',
|
||||
'provider' => $provider ? $provider->name : '-',
|
||||
'document_qty' => count($documentQty),
|
||||
'status' => $this->status ?? '-',
|
||||
'status_final_log' => $this->status_final_log ?? '-',
|
||||
'member_name' => $this->member->name,
|
||||
'payment_type' => $this->payment_type,
|
||||
'payment_type_name' => $this->payment_type_name,
|
||||
'duration_gl' => $durationGl,
|
||||
'duration_final_gl' => $this->final_log == 1 ? $durationFinalGl : '-',
|
||||
'files_by_type' => $filesGroupByType
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user