mirror of
https://gitlab.com/omair-personal/izyim.git
synced 2026-08-19 04:14:05 +00:00
55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\ControllersLogic\Dashboard;
|
|
|
|
use App\Models\Order;
|
|
use Carbon\Carbon;
|
|
|
|
class OrdersReportLogic
|
|
{
|
|
/** @var Order */
|
|
private $repository;
|
|
|
|
/**
|
|
* OrdersReportLogic constructor.
|
|
* @param Order $repository
|
|
*/
|
|
public function __construct(Order $repository)
|
|
{
|
|
$this->repository = $repository;
|
|
}
|
|
|
|
public function execute() {
|
|
//Get Warehouse Order
|
|
$Orders= $this->repository->whereYear('created_at', '=', Carbon::now()->year)
|
|
->whereMonth('created_at', '=', Carbon::now()->month)->orderBy('created_at')->get();
|
|
|
|
$group = $Orders->groupBy(function($item) {
|
|
return Carbon::parse($item->created_at)->format('j');
|
|
});
|
|
|
|
$groupCount = $group->map(function ($item) {
|
|
return collect($item)->count();
|
|
})->toArray();
|
|
|
|
$report = [];
|
|
for($x = 1; $x <= Carbon::now()->daysInMonth; $x++){
|
|
$report[] = isset($groupCount[$x]) ? $groupCount[$x] : 0;
|
|
|
|
//Undefined offset:
|
|
// if(array_key_exists($x, $groupCount)){
|
|
// $report[] = $groupCount[$x];
|
|
// } else {
|
|
// $report[] = 0;
|
|
// }
|
|
|
|
}
|
|
|
|
// dd(Carbon::now()->daysInMonth);
|
|
// dd($groupCount);
|
|
// dd($groupCount["01"]);
|
|
return $report;
|
|
}
|
|
}
|
|
|