| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace App\Http\Controllers;
- use App\Helpers\Price;
- use App\Models\ObjectType;
- use App\Models\Order;
- use App\Models\OrderStatus;
- use App\Models\Product;
- use App\Models\ProductSKU;
- use Illuminate\Http\Request;
- use Illuminate\Support\Str;
- class ReportController extends Controller
- {
- protected array $data = [
- 'active' => 'reports',
- 'title' => 'Отчёты',
- 'id' => 'reports',
- ];
- public function index()
- {
- $doneStatuses = [5, 7, 8, 9, 10];
- $objectTypes = ObjectType::query()->get()->pluck('name', 'id')->toArray();
- $this->data['objectTypes'] = $objectTypes;
- $this->data['totalOrders'] = Order::all()->count();
- $this->data['doneOrders'] = Order::query()->whereIn('order_status_id', [9, 10])->count();
- $this->data['totalMafs'] = ProductSKU::all()->count();
- $this->data['doneMafs'] = ProductSKU::query()->
- whereHas('order', function ($query) {
- $query->whereIn('order_status_id', [9, 10]);
- })->count();
- $this->data['totalSum'] = Price::format(
- ProductSKU::query()->
- whereHas('order', function ($query) use ($doneStatuses) {
- $query->whereIn('order_status_id', $doneStatuses);
- })
- ->withSum('product', 'total_price')
- ->get()
- ->sum('product_sum_total_price')
- );
- foreach ($objectTypes as $objectTypeId => $objectType) {
- // total by types
- $this->data['totalOrdersType'][$objectTypeId] = Order::where('object_type_id', '=', $objectTypeId)->count();
- $this->data['totalMafsType'][$objectTypeId] = ProductSKU::query()->
- whereHas('order', function ($query) use ($objectTypeId) {
- $query->where('object_type_id', '=', $objectTypeId);
- })->count();
- // со статусами: в монтаже, готова к сдаче, не сдана замечания, сдана замечания, сдана - зеленый цвет
- $this->data['doneOrdersType'][$objectTypeId] = Order::query()
- ->where('object_type_id', '=', $objectTypeId)
- ->whereIn('order_status_id', $doneStatuses)
- ->count();
- $this->data['doneMafsType'][$objectTypeId] = ProductSKU::query()->
- whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) {
- $query->where('object_type_id', '=', $objectTypeId)
- ->whereIn('order_status_id', $doneStatuses);
- })->count();
- // остальные - не готовы
- $this->data['notDoneOrdersType'][$objectTypeId] = Order::query()
- ->where('object_type_id', '=', $objectTypeId)
- ->whereNotIn('order_status_id', $doneStatuses)
- ->count();
- $this->data['notDoneMafsType'][$objectTypeId] = ProductSKU::query()->
- whereHas('order', function ($query) use ($objectTypeId, $doneStatuses) {
- $query->where('object_type_id', '=', $objectTypeId)
- ->whereNotIn('order_status_id', $doneStatuses);
- })->count();
- }
- return view('reports.index', $this->data);
- }
- }
|