Implement dynamic Payment Method Summary (Table 3)
This commit is contained in:
@@ -23,7 +23,18 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->get(['id', 'name']);
|
->get(['id', 'name']);
|
||||||
|
|
||||||
$creditCollections = $this->getCreditSaleCollections($report_date);
|
$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')
|
$sales = DB::table('sales')
|
||||||
@@ -71,7 +82,7 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
$sales_data = [];
|
$sales_data = [];
|
||||||
foreach ($sales as $sale) {
|
foreach ($sales as $sale) {
|
||||||
$methodTotals = [];
|
$methodTotals = [];
|
||||||
|
|
||||||
// Sum from payments table
|
// Sum from payments table
|
||||||
foreach ($paymentsTable->where('sale_id', $sale->id) as $p) {
|
foreach ($paymentsTable->where('sale_id', $sale->id) as $p) {
|
||||||
$optionId = $p->payment_option_id;
|
$optionId = $p->payment_option_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)
|
private function getCreditSaleCollections($date)
|
||||||
@@ -166,12 +218,12 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$rows[] = [
|
$rows[] = [
|
||||||
'date' => $sale->created_at,
|
'date' => $sale->created_at,
|
||||||
'reference' => $sale->reference_no,
|
'reference' => $sale->reference_no,
|
||||||
'cashier' => $users[$sale->user_id] ?? '-',
|
'cashier' => $users[$sale->user_id] ?? '-',
|
||||||
'customer' => $customers[$sale->customer_id] ?? '-',
|
'customer' => $customers[$sale->customer_id] ?? '-',
|
||||||
'grand_total' => $sale->grand_total - $sale->paid_amount,
|
'grand_total' => $sale->grand_total - $sale->paid_amount,
|
||||||
'methods' => $methodTotals,
|
'methods' => $methodTotals,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,8 +63,8 @@
|
|||||||
<i class="fa fa-file-text-o"></i> Export CSV
|
<i class="fa fa-file-text-o"></i> Export CSV
|
||||||
</button>
|
</button>
|
||||||
<!-- <button class="btn btn-secondary" onclick="window.print()" style="border-radius: 10px;">
|
<!-- <button class="btn btn-secondary" onclick="window.print()" style="border-radius: 10px;">
|
||||||
<i class="fa fa-print"></i> Print Report
|
<i class="fa fa-print"></i> Print Report
|
||||||
</button> -->
|
</button> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -174,80 +174,63 @@
|
|||||||
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="4" class="text-right">Total</td>
|
<td colspan="4" class="text-right">Total</td>
|
||||||
<td>0.00</td>
|
<td>{{ number_format($creditTotals['grand_total'], 2) }}</td>
|
||||||
@foreach ($paymentOptions as $option)
|
@foreach ($paymentOptions as $option)
|
||||||
<td>0.00</td>
|
<td>{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td>
|
||||||
@endforeach
|
@endforeach
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="container-fluid mt-5 mb-5">
|
<div class="container-fluid mt-5 mb-5">
|
||||||
<!-- Payment Method Summary Table -->
|
<!-- Payment Method Summary Table -->
|
||||||
<h4 class="mb-3" style="color: #00489f; font-weight: bold;">Payment Method Summary</h4>
|
<h4 class="mb-3" style="color: #00489f; font-weight: bold;">Payment Method Summary</h4>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table style="border-radius: 15px; background-color: #e0e5ea; width: 60%;"
|
<table style="border-radius: 15px; background-color: #e0e5ea; width: 60%;"
|
||||||
class="table table-hover table-bordered">
|
class="table table-hover table-bordered">
|
||||||
<thead
|
<thead
|
||||||
style="border-radius: 50px; background: linear-gradient(to right, #078bce, #1a1d1e); color: white;">
|
style="border-radius: 50px; background: linear-gradient(to right, #078bce, #1a1d1e); color: white;">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Payment Option</th>
|
<th>Payment Option</th>
|
||||||
<th>Sale Amount</th>
|
<th>Sale Amount</th>
|
||||||
<th>Received Amount</th>
|
<th>Received Amount</th>
|
||||||
<th>Total Amount</th>
|
<th>Total Amount</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
@php
|
||||||
<td>Cash</td>
|
$grand_sale = 0;
|
||||||
<td>0.00</td>
|
$grand_received = 0;
|
||||||
<td>0.00</td>
|
$grand_total = 0;
|
||||||
<td>0.00</td>
|
@endphp
|
||||||
</tr>
|
|
||||||
<tr>
|
@foreach ($summaryData as $summary)
|
||||||
<td>Card 1</td>
|
<tr>
|
||||||
<td>0.00</td>
|
<td>{{ $summary['name'] }}</td>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($summary['sale_amount'], 2) }}</td>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($summary['received_amount'], 2) }}</td>
|
||||||
</tr>
|
<td class="text-right">{{ number_format($summary['total_amount'], 2) }}</td>
|
||||||
<tr>
|
</tr>
|
||||||
<td>Card 2</td>
|
@php
|
||||||
<td>0.00</td>
|
$grand_sale += $summary['sale_amount'];
|
||||||
<td>0.00</td>
|
$grand_received += $summary['received_amount'];
|
||||||
<td>0.00</td>
|
$grand_total += $summary['total_amount'];
|
||||||
</tr>
|
@endphp
|
||||||
<tr>
|
@endforeach
|
||||||
<td>Card 3</td>
|
</tbody>
|
||||||
<td>0.00</td>
|
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
||||||
<td>0.00</td>
|
<tr>
|
||||||
<td>0.00</td>
|
<td class="text-right">Grand Total</td>
|
||||||
</tr>
|
<td class="text-right">{{ number_format($grand_sale, 2) }}</td>
|
||||||
<tr>
|
<td class="text-right">{{ number_format($grand_received, 2) }}</td>
|
||||||
<td>Online Transfer</td>
|
<td class="text-right">{{ number_format($grand_total, 2) }}</td>
|
||||||
<td>0.00</td>
|
</tr>
|
||||||
<td>0.00</td>
|
</tfoot>
|
||||||
<td>0.00</td>
|
|
||||||
</tr>
|
</table>
|
||||||
<tr>
|
</div>
|
||||||
<td>Link Pay</td>
|
|
||||||
<td>0.00</td>
|
|
||||||
<td>0.00</td>
|
|
||||||
<td>0.00</td>
|
|
||||||
</tr>
|
|
||||||
</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>
|
|
||||||
</tr>
|
|
||||||
</tfoot>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
Reference in New Issue
Block a user