Implement dynamic Payment Method Summary (Table 3)
This commit is contained in:
@@ -25,6 +25,17 @@ class DailySalePaymentReportModuleController extends Controller
|
||||
|
||||
$creditCollections = $this->getCreditSaleCollections($report_date);
|
||||
|
||||
$creditTotals = [
|
||||
'grand_total' => $creditCollections->sum('grand_total'),
|
||||
'methods' => [],
|
||||
];
|
||||
|
||||
foreach ($paymentOptions as $option) {
|
||||
$creditTotals['methods'][$option->id] = $creditCollections->sum(
|
||||
fn($row) => $row['methods'][$option->id] ?? 0
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$sales = DB::table('sales')
|
||||
->leftJoin('users', 'sales.user_id', '=', 'users.id')
|
||||
@@ -97,7 +108,48 @@ class DailySalePaymentReportModuleController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
return view('dailysalepaymentreportmodule::index', compact('sales_data', 'report_date', 'paymentOptions', 'creditCollections'));
|
||||
|
||||
// --- Table 3: Payment Method Summary Calculation ---
|
||||
$summaryData = [];
|
||||
|
||||
// මුලින්ම හැම Payment Option එකටම බින්දුව දාලා Array එකක් හදාගන්නවා
|
||||
foreach ($paymentOptions as $option) {
|
||||
$summaryData[$option->id] = [
|
||||
'name' => $option->name,
|
||||
'sale_amount' => 0,
|
||||
'received_amount' => 0,
|
||||
'total_amount' => 0
|
||||
];
|
||||
}
|
||||
|
||||
// Table 1 (Daily Sales) වල සල්ලි ටික එකතු කරනවා
|
||||
foreach ($sales_data as $sale) {
|
||||
foreach ($paymentOptions as $option) {
|
||||
$amount = $sale->methods[$option->id] ?? 0;
|
||||
$summaryData[$option->id]['sale_amount'] += $amount;
|
||||
$summaryData[$option->id]['total_amount'] += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
// Table 2 (Credit Collections) වල සල්ලි ටික එකතු කරනවා
|
||||
foreach ($creditCollections as $credit) {
|
||||
foreach ($paymentOptions as $option) {
|
||||
$amount = $credit['methods'][$option->id] ?? 0;
|
||||
$summaryData[$option->id]['received_amount'] += $amount;
|
||||
$summaryData[$option->id]['total_amount'] += $amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return view('dailysalepaymentreportmodule::index', compact(
|
||||
'sales_data',
|
||||
'report_date',
|
||||
'paymentOptions',
|
||||
'creditCollections',
|
||||
'creditTotals',
|
||||
'summaryData'
|
||||
));
|
||||
}
|
||||
|
||||
private function getCreditSaleCollections($date)
|
||||
|
||||
@@ -174,15 +174,14 @@
|
||||
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
||||
<tr>
|
||||
<td colspan="4" class="text-right">Total</td>
|
||||
<td>0.00</td>
|
||||
<td>{{ number_format($creditTotals['grand_total'], 2) }}</td>
|
||||
@foreach ($paymentOptions as $option)
|
||||
<td>0.00</td>
|
||||
<td>{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td>
|
||||
@endforeach
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container-fluid mt-5 mb-5">
|
||||
<!-- Payment Method Summary Table -->
|
||||
@@ -200,51 +199,35 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@php
|
||||
$grand_sale = 0;
|
||||
$grand_received = 0;
|
||||
$grand_total = 0;
|
||||
@endphp
|
||||
|
||||
@foreach ($summaryData as $summary)
|
||||
<tr>
|
||||
<td>Cash</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Card 1</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Card 2</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Card 3</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Online Transfer</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Link Pay</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>{{ $summary['name'] }}</td>
|
||||
<td class="text-right">{{ number_format($summary['sale_amount'], 2) }}</td>
|
||||
<td class="text-right">{{ number_format($summary['received_amount'], 2) }}</td>
|
||||
<td class="text-right">{{ number_format($summary['total_amount'], 2) }}</td>
|
||||
</tr>
|
||||
@php
|
||||
$grand_sale += $summary['sale_amount'];
|
||||
$grand_received += $summary['received_amount'];
|
||||
$grand_total += $summary['total_amount'];
|
||||
@endphp
|
||||
@endforeach
|
||||
</tbody>
|
||||
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
||||
<tr>
|
||||
<td class="text-right">Grand Total</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td>0.00</td>
|
||||
<td class="text-right">{{ number_format($grand_sale, 2) }}</td>
|
||||
<td class="text-right">{{ number_format($grand_received, 2) }}</td>
|
||||
<td class="text-right">{{ number_format($grand_total, 2) }}</td>
|
||||
</tr>
|
||||
</tfoot>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user