Files
2019-03-21 11:02:19 +08:00

44 lines
1.0 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() {
$Orders= $this->repository->whereYear('created_at', '=', Carbon::now()->year)
->whereMonth('created_at', '=', Carbon::now()->month)->where('company_id', '!=', 349)->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;
}
return $report;
}
}