@extends('layouts.app')
@section('content')
@php
$summary = $summary ?? [];
$machineStats = $machineStats ?? [];
$machines = $machines ?? collect();
$categories = $categories ?? collect();
$products = $products ?? collect();
$materials = $materials ?? collect();
$dailyData = $dailyData ?? collect();
$materialMachines = $materialMachines ?? [];
$materialMachineCostPerClick = $materialMachineCostPerClick ?? [];
$startDate = $startDate ?? now()->startOfMonth()->toDateString();
$endDate = $endDate ?? now()->toDateString();
/*
* Sinkronisasi total:
* - "Rincian per Mesin" memakai $machineStats.
* - Supaya "Total Klik" dan "Total Biaya" tidak berbeda,
* total utama juga dihitung dari sumber yang sama.
* - Jika $machineStats kosong, fallback ke $summary.
*/
$machineStatsCollection = collect($machineStats);
$machineStatsTotalClicks = (int) $machineStatsCollection->sum(fn ($stat) => (int) ($stat['total_clicks'] ?? 0));
$machineStatsTotalCost = (float) $machineStatsCollection->sum(fn ($stat) => (float) ($stat['total_cost'] ?? 0));
$syncedTotalClicks = $machineStatsCollection->isNotEmpty()
? $machineStatsTotalClicks
: (int) ($summary['total_clicks'] ?? 0);
$syncedTotalCost = $machineStatsCollection->isNotEmpty()
? $machineStatsTotalCost
: (float) ($summary['total_cost'] ?? 0);
$reportData = $reportData ?? new \Illuminate\Pagination\LengthAwarePaginator(
[],
0,
(int) request('per_page', 15),
1,
[
'path' => request()->url(),
'query' => request()->query(),
]
);
@endphp
Belum ada data mesin.
@endifSaring data berdasarkan periode, mesin, kategori, produk, dan bahan.
| Produk | Bahan | Mesin | Order | Qty | Total Klik | Biaya/Klik | Total Biaya |
|---|---|---|---|---|---|---|---|
| {{ $row->product_name ?: '-' }} | {{ $row->material_name ?: '-' }} | {{ $row->machine_names ?? ($materialMachines[$row->material_id] ?? '-') }} | {{ number_format($row->total_orders ?? 0) }} | {{ number_format($row->total_qty ?? 0) }} | {{ number_format($row->total_clicks ?? 0) }} | Rp {{ number_format($row->cost_per_click ?? ($materialMachineCostPerClick[$row->material_id] ?? 0), 0, ',', '.') }} | Rp {{ number_format($row->total_cost ?? 0, 0, ',', '.') }} |
| Total | {{ number_format($syncedTotalClicks) }} | - | Rp {{ number_format($syncedTotalCost, 0, ',', '.') }} | ||||
@if($products->count() == 0 && $materials->count() == 0) Belum ada produk atau bahan dengan tracking klik yang diaktifkan. @else Tidak ada order dalam periode yang dipilih. @endif
Tidak ada produk dengan tracking aktif
@endifTidak ada bahan dengan tracking aktif
@endif