mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/izyim.git
synced 2026-08-19 04:24:00 +00:00
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: ayen
|
|
* Date: 18/03/2019
|
|
* Time: 10:16 AM
|
|
*/
|
|
|
|
namespace App\Classes\Modules\ControllersLogic\Dashboard;
|
|
|
|
use App\Models\Package;
|
|
use Carbon\Carbon;
|
|
|
|
class CbmReportLogic
|
|
{
|
|
/* @var Package */
|
|
private $repository;
|
|
|
|
/**
|
|
* CbmReportLogic constructor.
|
|
* @param Package $repository
|
|
*/
|
|
public function __construct(Package $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
public function execute() {
|
|
|
|
$cbm = $this->repository->selectRaw('created_at, ((((width/100) * (length/100) * (height/100))) * quantity) as cbm')->whereYear('created_at', '=', Carbon::now()->year)->whereMonth('created_at', '=', Carbon::now()->month)->orderBy('created_at')->get();
|
|
|
|
$cbmGroup = $cbm->groupBy(function ($item) {
|
|
return Carbon::parse($item->created_at)->format('j');
|
|
});
|
|
|
|
$cbmMap = $cbmGroup->map(function ($item){
|
|
return collect($item)->sum("cbm");
|
|
})->toArray();
|
|
|
|
$report = [];
|
|
for($x = 1; $x <= Carbon::now()->daysInMonth; $x++){
|
|
$report[] = isset($cbmMap[$x]) ? $cbmMap[$x] : 0;
|
|
}
|
|
|
|
return $report;
|
|
}
|
|
} |