diff --git a/Http/Controllers/DailySalePaymentReportModuleController.php b/Http/Controllers/DailySalePaymentReportModuleController.php
index 6b757c9..9c6b46b 100644
--- a/Http/Controllers/DailySalePaymentReportModuleController.php
+++ b/Http/Controllers/DailySalePaymentReportModuleController.php
@@ -23,7 +23,18 @@ class DailySalePaymentReportModuleController extends Controller
->orderBy('id')
->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')
@@ -71,7 +82,7 @@ class DailySalePaymentReportModuleController extends Controller
$sales_data = [];
foreach ($sales as $sale) {
$methodTotals = [];
-
+
// Sum from payments table
foreach ($paymentsTable->where('sale_id', $sale->id) as $p) {
$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)
@@ -166,12 +218,12 @@ class DailySalePaymentReportModuleController extends Controller
}
$rows[] = [
- 'date' => $sale->created_at,
- 'reference' => $sale->reference_no,
- 'cashier' => $users[$sale->user_id] ?? '-',
- 'customer' => $customers[$sale->customer_id] ?? '-',
+ 'date' => $sale->created_at,
+ 'reference' => $sale->reference_no,
+ 'cashier' => $users[$sale->user_id] ?? '-',
+ 'customer' => $customers[$sale->customer_id] ?? '-',
'grand_total' => $sale->grand_total - $sale->paid_amount,
- 'methods' => $methodTotals,
+ 'methods' => $methodTotals,
];
}
diff --git a/Resources/views/index.blade.php b/Resources/views/index.blade.php
index e180289..35b1a7d 100644
--- a/Resources/views/index.blade.php
+++ b/Resources/views/index.blade.php
@@ -63,8 +63,8 @@
Export CSV
+ Print Report
+ -->
@@ -174,80 +174,63 @@
| Total |
- 0.00 |
+ {{ number_format($creditTotals['grand_total'], 2) }} |
@foreach ($paymentOptions as $option)
- 0.00 |
+ {{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }} |
@endforeach
-
-
-
-
Payment Method Summary
-
-
-
-
- | Payment Option |
- Sale Amount |
- Received Amount |
- Total Amount |
-
-
-
-
- | Cash |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
- | Card 1 |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
- | Card 2 |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
- | Card 3 |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
- | Online Transfer |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
- | Link Pay |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
-
-
- | Grand Total |
- 0.00 |
- 0.00 |
- 0.00 |
-
-
-
+
+
+
Payment Method Summary
+
+
+
+
+ | Payment Option |
+ Sale Amount |
+ Received Amount |
+ Total Amount |
+
+
+
+ @php
+ $grand_sale = 0;
+ $grand_received = 0;
+ $grand_total = 0;
+ @endphp
+
+ @foreach ($summaryData as $summary)
+
+ | {{ $summary['name'] }} |
+ {{ number_format($summary['sale_amount'], 2) }} |
+ {{ number_format($summary['received_amount'], 2) }} |
+ {{ number_format($summary['total_amount'], 2) }} |
+
+ @php
+ $grand_sale += $summary['sale_amount'];
+ $grand_received += $summary['received_amount'];
+ $grand_total += $summary['total_amount'];
+ @endphp
+ @endforeach
+
+
+
+ | Grand Total |
+ {{ number_format($grand_sale, 2) }} |
+ {{ number_format($grand_received, 2) }} |
+ {{ number_format($grand_total, 2) }} |
+
+
+
+
+
-