mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Transformers;
|
|
|
|
use App\Models\Schedule;
|
|
use Carbon\Carbon;
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
class ScheduleTransformer extends TransformerAbstract
|
|
{
|
|
/**
|
|
* List of resources to automatically include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $defaultIncludes = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* List of resources possible to include
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $availableIncludes = [
|
|
//
|
|
];
|
|
|
|
/**
|
|
* A Fractal transformer.
|
|
*
|
|
* @param Schedule $schedule
|
|
* @return array
|
|
*/
|
|
public function transform(Schedule $schedule): array
|
|
{
|
|
return [
|
|
'id' => $schedule->id,
|
|
'etd' => $schedule->etd ? $schedule->etd->format('d-m-Y') : 'n/a',
|
|
'eta' => $schedule->eta ? $schedule->eta->format('d-m-Y') : 'n/a',
|
|
'billing_days_left' => [
|
|
'value' => (Carbon::parse($schedule->eta)->subDays(7)->gt(Carbon::now())) ? '+' : '-',
|
|
'duration' => Carbon::parse($schedule->eta)->subDays(7)->diffInDays(Carbon::now()),
|
|
],
|
|
'status' => $schedule->status,
|
|
];
|
|
}
|
|
}
|