Files
izyim/app/Classes/Modules/ControllersLogic/Dashboard/OrdersReportLogic.php
T
2019-03-19 17:11:21 +08:00

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;
}
}