Compare commits
7 Commits
f8e6dbb81e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08133c68ae | ||
|
|
a4a7b09c10 | ||
|
|
720752a781 | ||
| 640ef324b3 | |||
| 70ca6fe789 | |||
| 26273d92c2 | |||
| d849bd41ff |
27
Database/factories/CustomerFactory.php
Normal file
27
Database/factories/CustomerFactory.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace Modules\DailySalePaymentReportModule\Database\factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class CustomerFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = \Modules\DailySalePaymentReportModule\Entities\Customer::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
42
Entities/Customer.php
Normal file
42
Entities/Customer.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\DailySalePaymentReportModule\Entities;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class Customer extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
"customer_group_id",
|
||||||
|
"user_id",
|
||||||
|
"name",
|
||||||
|
"company_name",
|
||||||
|
"email",
|
||||||
|
"phone_number",
|
||||||
|
"tax_no",
|
||||||
|
"address",
|
||||||
|
"city",
|
||||||
|
"state",
|
||||||
|
"postal_code",
|
||||||
|
"country",
|
||||||
|
"customer_route",
|
||||||
|
"points",
|
||||||
|
"deposit",
|
||||||
|
"expense",
|
||||||
|
"is_active",
|
||||||
|
"credit_limit",
|
||||||
|
"document",
|
||||||
|
"employee_id",
|
||||||
|
"payable_account_id",
|
||||||
|
"receivable_account_id",
|
||||||
|
"customer_area_id"
|
||||||
|
];
|
||||||
|
|
||||||
|
protected static function newFactory()
|
||||||
|
{
|
||||||
|
return \Modules\DailySalePaymentReportModule\Database\factories\CustomerFactory::new();
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Exports/DailySalePaymentReportExport.php
Normal file
43
Exports/DailySalePaymentReportExport.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\DailySalePaymentReportModule\Exports;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Maatwebsite\Excel\Concerns\FromView;
|
||||||
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||||
|
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||||
|
use Maatwebsite\Excel\Events\AfterSheet;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
|
|
||||||
|
class DailySalePaymentReportExport implements FromView, ShouldAutoSize, WithEvents
|
||||||
|
{
|
||||||
|
protected $data;
|
||||||
|
|
||||||
|
public function __construct($data)
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(): View
|
||||||
|
{
|
||||||
|
return view('dailysalepaymentreportmodule::export', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function registerEvents(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
AfterSheet::class => function (AfterSheet $event) {
|
||||||
|
$sheet = $event->sheet->getDelegate();
|
||||||
|
$highestColumn = $sheet->getHighestColumn();
|
||||||
|
$highestRow = $sheet->getHighestRow();
|
||||||
|
$dataRange = 'A1:' . $highestColumn . $highestRow;
|
||||||
|
|
||||||
|
// Set borders for everything
|
||||||
|
$sheet->getStyle($dataRange)->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
|
||||||
|
$sheet->getStyle($dataRange)->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Modules\DailySalePaymentReportModule\Http\Controllers;
|
namespace Modules\DailySalePaymentReportModule\Http\Controllers;
|
||||||
|
|
||||||
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Illuminate\Contracts\Support\Renderable;
|
use Illuminate\Contracts\Support\Renderable;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
@@ -18,6 +19,14 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
{
|
{
|
||||||
$report_date = $request->input('report_date', Carbon::today()->toDateString());
|
$report_date = $request->input('report_date', Carbon::today()->toDateString());
|
||||||
|
|
||||||
|
$data = $this->getReportData($report_date);
|
||||||
|
$pdf = $this->buildReportData($report_date);
|
||||||
|
|
||||||
|
return view('dailysalepaymentreportmodule::index', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getReportData($report_date)
|
||||||
|
{
|
||||||
// Fetch dynamic payment options using DB facade since the model is missing in this branch
|
// Fetch dynamic payment options using DB facade since the model is missing in this branch
|
||||||
$paymentOptions = DB::table('payment_options')->where('is_active', 1)
|
$paymentOptions = DB::table('payment_options')->where('is_active', 1)
|
||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
@@ -108,13 +117,46 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('dailysalepaymentreportmodule::index', compact(
|
|
||||||
|
// --- 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 compact(
|
||||||
'sales_data',
|
'sales_data',
|
||||||
'report_date',
|
'report_date',
|
||||||
'paymentOptions',
|
'paymentOptions',
|
||||||
'creditCollections',
|
'creditCollections',
|
||||||
'creditTotals',
|
'creditTotals',
|
||||||
));
|
'summaryData',
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getCreditSaleCollections($date)
|
private function getCreditSaleCollections($date)
|
||||||
@@ -195,6 +237,117 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
return collect($rows);
|
return collect($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildReportData($report_date)
|
||||||
|
{
|
||||||
|
$paymentOptions = DB::table('payment_options')->where('is_active', 1)
|
||||||
|
->orderBy('id')
|
||||||
|
->get(['id', 'name']);
|
||||||
|
|
||||||
|
$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')
|
||||||
|
->leftJoin('customers', 'sales.customer_id', '=', 'customers.id')
|
||||||
|
->whereDate('sales.created_at', $report_date)
|
||||||
|
->select(
|
||||||
|
'sales.id',
|
||||||
|
'sales.created_at as date',
|
||||||
|
'sales.reference_no',
|
||||||
|
'users.name as cashier',
|
||||||
|
'customers.name as customer',
|
||||||
|
'sales.grand_total',
|
||||||
|
'sales.due_amount',
|
||||||
|
)->get();
|
||||||
|
|
||||||
|
$saleIds = $sales->pluck('id')->all();
|
||||||
|
|
||||||
|
$paymentsTable = DB::table('payments')
|
||||||
|
->whereIn('sale_id', $saleIds)
|
||||||
|
->whereDate('created_at', $report_date)
|
||||||
|
->get(['id', 'sale_id', 'amount', 'payment_option_id']);
|
||||||
|
|
||||||
|
$usedPaymentIds = $paymentsTable->pluck('id')->all();
|
||||||
|
|
||||||
|
$salesPaymentsTable = DB::table('sales_payments')
|
||||||
|
->whereIn('sale_id', $saleIds)
|
||||||
|
->whereDate('created_at', $report_date)
|
||||||
|
->where(function ($q) use ($usedPaymentIds) {
|
||||||
|
$q->whereNull('payment_id');
|
||||||
|
if (!empty($usedPaymentIds)) {
|
||||||
|
$q->orWhereNotIn('payment_id', $usedPaymentIds);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->get(['id', 'sale_id', 'amount', 'payment_id']);
|
||||||
|
|
||||||
|
$linkedPaymentIds = $salesPaymentsTable->whereNotNull('payment_id')->pluck('payment_id')->unique();
|
||||||
|
$linkedOptionMap = DB::table('payments')->whereIn('id', $linkedPaymentIds)->pluck('payment_option_id', 'id');
|
||||||
|
|
||||||
|
$sales_data = [];
|
||||||
|
foreach ($sales as $sale) {
|
||||||
|
$methodTotals = [];
|
||||||
|
foreach ($paymentsTable->where('sale_id', $sale->id) as $p) {
|
||||||
|
$optionId = $p->payment_option_id;
|
||||||
|
$methodTotals[$optionId] = ($methodTotals[$optionId] ?? 0) + $p->amount;
|
||||||
|
}
|
||||||
|
foreach ($salesPaymentsTable->where('sale_id', $sale->id) as $sp) {
|
||||||
|
$optionId = $sp->payment_id ? ($linkedOptionMap[$sp->payment_id] ?? null) : null;
|
||||||
|
if ($optionId) {
|
||||||
|
$methodTotals[$optionId] = ($methodTotals[$optionId] ?? 0) + $sp->amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$sales_data[] = (object) [
|
||||||
|
'date' => Carbon::parse($sale->date)->format('Y-m-d'),
|
||||||
|
'reference_no' => $sale->reference_no,
|
||||||
|
'cashier' => $sale->cashier ?? 'N/A',
|
||||||
|
'customer' => $sale->customer ?? 'N/A',
|
||||||
|
'grand_total' => $sale->grand_total,
|
||||||
|
'due_amount' => $sale->due_amount,
|
||||||
|
'methods' => $methodTotals
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$summaryData = [];
|
||||||
|
foreach ($paymentOptions as $option) {
|
||||||
|
$summaryData[$option->id] = [
|
||||||
|
'name' => $option->name,
|
||||||
|
'sale_amount' => 0,
|
||||||
|
'received_amount' => 0,
|
||||||
|
'total_amount' => 0
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 compact('report_date', 'paymentOptions', 'sales_data', 'creditCollections', 'creditTotals', 'summaryData');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
* @return Renderable
|
* @return Renderable
|
||||||
@@ -255,13 +408,37 @@ class DailySalePaymentReportModuleController extends Controller
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
public function exportReport(Request $request)
|
public function exportPDF(Request $request)
|
||||||
{
|
{
|
||||||
|
$date = $request->query('date', Carbon::today()->toDateString());
|
||||||
$date = $request->query('date');
|
|
||||||
$type = $request->query('type');
|
$type = $request->query('type');
|
||||||
|
|
||||||
|
$data = $this->buildReportData($date);
|
||||||
|
|
||||||
return "Export function is working. Selected Date: " . $date . " | Export Type: " . $type;
|
if ($type === 'pdf') {
|
||||||
|
$pdf = Pdf::loadView('dailysalepaymentreportmodule::export.pdf', $data)
|
||||||
|
->setPaper('a4', 'landscape');
|
||||||
|
return $pdf->download('daily-sale-payment-report-' . $date . '.pdf');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function exportReport(Request $request)
|
||||||
|
{
|
||||||
|
$date = $request->query('date', Carbon::today()->toDateString());
|
||||||
|
$type = $request->query('type', 'excel');
|
||||||
|
|
||||||
|
$data = $this->getReportData($date);
|
||||||
|
|
||||||
|
$filename = 'Daily_Sale_Payment_Report_' . $date;
|
||||||
|
|
||||||
|
// For Excel and CSV, use Maatwebsite Excel
|
||||||
|
$export = new \Modules\DailySalePaymentReportModule\Exports\DailySalePaymentReportExport($data);
|
||||||
|
|
||||||
|
if ($type === 'csv') {
|
||||||
|
return \Maatwebsite\Excel\Facades\Excel::download($export, $filename . '.csv', \Maatwebsite\Excel\Excel::CSV);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to Excel
|
||||||
|
return \Maatwebsite\Excel\Facades\Excel::download($export, $filename . '.xlsx', \Maatwebsite\Excel\Excel::XLSX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
152
Resources/views/export.blade.php
Normal file
152
Resources/views/export.blade.php
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="7" style="font-size: 16px; font-weight: bold;">Daily Sale Payment Report - {{ $report_date }}</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th colspan="7" style="font-size: 14px; font-weight: bold;">Sales Table (Daily Sale)</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Date</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Reference Number</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Cashier</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Customer</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Grand Total</th>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">{{ $option->name }}</th>
|
||||||
|
@endforeach
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Due Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@php
|
||||||
|
$tot_grand = 0;
|
||||||
|
$tot_due = 0;
|
||||||
|
$option_totals = [];
|
||||||
|
foreach ($paymentOptions as $opt) {
|
||||||
|
$option_totals[$opt->id] = 0;
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
@foreach($sales_data as $sale)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $sale->date }}</td>
|
||||||
|
<td>{{ $sale->reference_no }}</td>
|
||||||
|
<td>{{ $sale->cashier }}</td>
|
||||||
|
<td>{{ $sale->customer }}</td>
|
||||||
|
<td>{{ number_format($sale->grand_total, 2) }}</td>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<td>{{ number_format($sale->methods[$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
<td>{{ number_format($sale->due_amount, 2) }}</td>
|
||||||
|
</tr>
|
||||||
|
@php
|
||||||
|
$tot_grand += $sale->grand_total;
|
||||||
|
$tot_due += $sale->due_amount;
|
||||||
|
foreach ($paymentOptions as $opt) {
|
||||||
|
$option_totals[$opt->id] += ($sale->methods[$opt->id] ?? 0);
|
||||||
|
}
|
||||||
|
@endphp
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" style="font-weight: bold; text-align: right;">Total</td>
|
||||||
|
<td style="font-weight: bold;">{{ number_format($tot_grand, 2) }}</td>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<td style="font-weight: bold;">{{ number_format($option_totals[$option->id], 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
<td style="font-weight: bold;">{{ number_format($tot_due, 2) }}</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><td></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="5" style="font-size: 14px; font-weight: bold;">Credit Sale Collections</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Original Bill Date</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Reference Number</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Cashier</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Customer</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Grand Total</th>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">{{ $option->name }}</th>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($creditCollections as $row)
|
||||||
|
<tr>
|
||||||
|
<td>{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}</td>
|
||||||
|
<td>{{ $row['reference'] }}</td>
|
||||||
|
<td>{{ $row['cashier'] }}</td>
|
||||||
|
<td>{{ $row['customer'] }}</td>
|
||||||
|
<td>{{ number_format($row['grand_total'], 2) }}</td>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<td>{{ number_format($row['methods'][$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" style="font-weight: bold; text-align: right;">Total</td>
|
||||||
|
<td style="font-weight: bold;">{{ number_format($creditTotals['grand_total'], 2) }}</td>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<td style="font-weight: bold;">{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr><td></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th colspan="4" style="font-size: 14px; font-weight: bold;">Payment Method Summary</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Payment Option</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Sale Amount</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Received Amount</th>
|
||||||
|
<th style="font-weight: bold; background-color: #cccccc;">Total Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@php
|
||||||
|
$grand_sale = 0;
|
||||||
|
$grand_received = 0;
|
||||||
|
$grand_total = 0;
|
||||||
|
@endphp
|
||||||
|
@foreach ($summaryData as $summary)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $summary['name'] }}</td>
|
||||||
|
<td>{{ number_format($summary['sale_amount'], 2) }}</td>
|
||||||
|
<td>{{ number_format($summary['received_amount'], 2) }}</td>
|
||||||
|
<td>{{ 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>
|
||||||
|
<tr>
|
||||||
|
<td style="font-weight: bold; text-align: right;">Grand Total</td>
|
||||||
|
<td style="font-weight: bold;">{{ number_format($grand_sale, 2) }}</td>
|
||||||
|
<td style="font-weight: bold;">{{ number_format($grand_received, 2) }}</td>
|
||||||
|
<td style="font-weight: bold;">{{ number_format($grand_total, 2) }}</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
187
Resources/views/export/pdf.blade.php
Normal file
187
Resources/views/export/pdf.blade.php
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: sans-serif;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
h2,
|
||||||
|
h4 {
|
||||||
|
margin: 5px 0;
|
||||||
|
color: #00489f;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
th,
|
||||||
|
td {
|
||||||
|
border: 1px solid #999;
|
||||||
|
padding: 4px 6px;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #078bce;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
tfoot td {
|
||||||
|
background-color: #cdd4da;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h2>Sunbeam Lanka Tailoring - Daily Sale Payment Report</h2>
|
||||||
|
<p>Date: {{ $report_date }}</p>
|
||||||
|
|
||||||
|
<h4>Sales Table (Daily Sale)</h4>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Reference Number</th>
|
||||||
|
<th>Cashier</th>
|
||||||
|
<th>Customer</th>
|
||||||
|
<th>Grand Total</th>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<th>{{ $option->name }}</th>
|
||||||
|
@endforeach
|
||||||
|
<th>Due Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@php
|
||||||
|
$tot_grand = 0; $tot_due = 0; $option_totals = [];
|
||||||
|
foreach ($paymentOptions as $opt) { $option_totals[$opt->id] = 0; }
|
||||||
|
@endphp
|
||||||
|
@foreach ($sales_data as $sale)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $sale->date }}</td>
|
||||||
|
<td>{{ $sale->reference_no }}</td>
|
||||||
|
<td>{{ $sale->cashier }}</td>
|
||||||
|
<td>{{ $sale->customer }}</td>
|
||||||
|
<td class="text-right">{{ number_format($sale->grand_total, 2) }}</td>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<td class="text-right">{{ number_format($sale->methods[$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
<td class="text-right">{{ number_format($sale->due_amount, 2) }}</td>
|
||||||
|
</tr>
|
||||||
|
@php
|
||||||
|
$tot_grand += $sale->grand_total;
|
||||||
|
$tot_due += $sale->due_amount;
|
||||||
|
foreach ($paymentOptions as $opt) { $option_totals[$opt->id] += ($sale->methods[$opt->id] ?? 0); }
|
||||||
|
@endphp
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="text-right">Total</td>
|
||||||
|
<td class="text-right">{{ number_format($tot_grand, 2) }}</td>
|
||||||
|
@foreach($paymentOptions as $option)
|
||||||
|
<td class="text-right">{{ number_format($option_totals[$option->id], 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
<td class="text-right">{{ number_format($tot_due, 2) }}</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<div style="page-break-inside: avoid;">
|
||||||
|
<h4>Credit Sale Collections</h4>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Original Bill Date</th>
|
||||||
|
<th>Reference Number</th>
|
||||||
|
<th>Cashier</th>
|
||||||
|
<th>Customer</th>
|
||||||
|
<th>Grand Total</th>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<th>{{ $option->name }}</th>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($creditCollections as $row)
|
||||||
|
<tr>
|
||||||
|
<td>{{ \Carbon\Carbon::parse($row['date'])->format('Y-m-d') }}</td>
|
||||||
|
<td>{{ $row['reference'] }}</td>
|
||||||
|
<td>{{ $row['cashier'] }}</td>
|
||||||
|
<td>{{ $row['customer'] }}</td>
|
||||||
|
<td class="text-right">{{ number_format($row['grand_total'], 2) }}</td>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<td class="text-right">{{ number_format($row['methods'][$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="text-right">Total</td>
|
||||||
|
<td class="text-right">{{ number_format($creditTotals['grand_total'], 2) }}</td>
|
||||||
|
@foreach ($paymentOptions as $option)
|
||||||
|
<td class="text-right">{{ number_format($creditTotals['methods'][$option->id] ?? 0, 2) }}</td>
|
||||||
|
@endforeach
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style="page-break-inside: avoid;">
|
||||||
|
<h4>Payment Method Summary</h4>
|
||||||
|
|
||||||
|
<table style="width: 60%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Payment Option</th>
|
||||||
|
<th>Sale Amount</th>
|
||||||
|
<th>Received Amount</th>
|
||||||
|
<th>Total Amount</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@php
|
||||||
|
$grand_sale = 0; $grand_received = 0; $grand_total = 0;
|
||||||
|
@endphp
|
||||||
|
@foreach ($summaryData as $summary)
|
||||||
|
<tr>
|
||||||
|
<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>
|
||||||
|
<tr>
|
||||||
|
<td class="text-right">Grand Total</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>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<!-- අලුතෙන් දාපු Single Export Buttons ටික -->
|
<!-- අලුතෙන් දාපු Single Export Buttons ටික -->
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
<div class="col-md-12 text-right">
|
<div class="col-md-12 text-right">
|
||||||
<button class="btn btn-danger" onclick="exportFullReport('pdf')" style="border-radius: 10px;">
|
<button class="btn btn-danger" onclick="exportFullPdf('pdf')" style="border-radius: 10px;">
|
||||||
<i class="fa fa-file-pdf-o"></i> Export PDF
|
<i class="fa fa-file-pdf-o"></i> Export PDF
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-success" onclick="exportFullReport('excel')" style="border-radius: 10px;">
|
<button class="btn btn-success" onclick="exportFullReport('excel')" style="border-radius: 10px;">
|
||||||
@@ -62,9 +62,9 @@
|
|||||||
<button class="btn btn-info" onclick="exportFullReport('csv')" style="border-radius: 10px;">
|
<button class="btn btn-info" onclick="exportFullReport('csv')" style="border-radius: 10px;">
|
||||||
<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>
|
||||||
|
|
||||||
@@ -182,7 +182,6 @@
|
|||||||
</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 -->
|
||||||
@@ -200,51 +199,35 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@php
|
||||||
|
$grand_sale = 0;
|
||||||
|
$grand_received = 0;
|
||||||
|
$grand_total = 0;
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@foreach ($summaryData as $summary)
|
||||||
<tr>
|
<tr>
|
||||||
<td>Cash</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>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($summary['total_amount'], 2) }}</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>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
@php
|
||||||
|
$grand_sale += $summary['sale_amount'];
|
||||||
|
$grand_received += $summary['received_amount'];
|
||||||
|
$grand_total += $summary['total_amount'];
|
||||||
|
@endphp
|
||||||
|
@endforeach
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
<tfoot style="background-color: #cdd4da; font-weight: bold;">
|
||||||
<tr>
|
<tr>
|
||||||
<td class="text-right">Grand Total</td>
|
<td class="text-right">Grand Total</td>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($grand_sale, 2) }}</td>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($grand_received, 2) }}</td>
|
||||||
<td>0.00</td>
|
<td class="text-right">{{ number_format($grand_total, 2) }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -295,5 +278,12 @@
|
|||||||
|
|
||||||
window.location.href = exportUrl;
|
window.location.href = exportUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function exportFullPdf(exportType) {
|
||||||
|
var selectedDate = $('#report_date').val();
|
||||||
|
|
||||||
|
var exportUrl = "{{ url('/dailysalepaymentreportmodule/export_pdf') }}" + "?date=" + selectedDate + "&type=" + exportType;
|
||||||
|
window.location.href = exportUrl;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
@@ -17,5 +17,6 @@ Route::middleware(['common', 'auth', 'active'])->group(function () {
|
|||||||
Route::controller(DailySalePaymentReportModuleController::class)->prefix('dailysalepaymentreportmodule')->group(function () {
|
Route::controller(DailySalePaymentReportModuleController::class)->prefix('dailysalepaymentreportmodule')->group(function () {
|
||||||
Route::get('/', 'index');
|
Route::get('/', 'index');
|
||||||
Route::get('/export', 'exportReport');
|
Route::get('/export', 'exportReport');
|
||||||
|
Route::get('/export_pdf', 'exportPDF');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
138
Tests/Feature/DailySalePaymentReportExportTest.php
Normal file
138
Tests/Feature/DailySalePaymentReportExportTest.php
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\DailySalePaymentReportModule\Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Modules\DailySalePaymentReportModule\Entities\Customer;
|
||||||
|
|
||||||
|
class DailySalePaymentReportExportTest extends TestCase
|
||||||
|
{
|
||||||
|
protected $reportDate;
|
||||||
|
protected $cashier;
|
||||||
|
protected $customer;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
if (app()->environment() !== 'local') {
|
||||||
|
putenv('APP_ENV=local');
|
||||||
|
$_ENV['APP_ENV'] = 'local';
|
||||||
|
$_SERVER['APP_ENV'] = 'local';
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$this->reportDate = Carbon::today()->toDateString();
|
||||||
|
|
||||||
|
$this->cashier = User::factory()->create([
|
||||||
|
'name' => fake()->name(),
|
||||||
|
'is_active' => 1,
|
||||||
|
'is_deleted' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->customer = Customer::factory()->create([
|
||||||
|
'name' => fake()->name(),
|
||||||
|
'customer_group_id' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$cashOptionId = DB::table('payment_options')->insertGetId([
|
||||||
|
'name' => 'Cash',
|
||||||
|
'is_active' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$saleId = DB::table('sales')->insertGetId([
|
||||||
|
'reference_no' => 'INV-EXPORT-' . fake()->unique()->numerify('####'),
|
||||||
|
'user_id' => $this->cashier->id,
|
||||||
|
'customer_id' => $this->customer->id,
|
||||||
|
'warehouse_id' => 1,
|
||||||
|
'item' => 1,
|
||||||
|
'total_qty' => 1,
|
||||||
|
'total_discount' => 0,
|
||||||
|
'total_tax' => 0,
|
||||||
|
'total_price' => 4000,
|
||||||
|
'grand_total' => 4000,
|
||||||
|
'sale_status' => 1,
|
||||||
|
'payment_status' => 1,
|
||||||
|
'due_amount' => 0,
|
||||||
|
'paid_amount' => 4000,
|
||||||
|
'created_at' => $this->reportDate . ' 09:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::table('payments')->insert([
|
||||||
|
'payment_reference' => 'PAY-EXPORT-1',
|
||||||
|
'user_id' => $this->cashier->id,
|
||||||
|
'sale_id' => $saleId,
|
||||||
|
'amount' => 4000,
|
||||||
|
'change' => 0,
|
||||||
|
'paying_method' => 'cash',
|
||||||
|
'payment_option_id' => $cashOptionId,
|
||||||
|
'created_at' => $this->reportDate . ' 09:00:00',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
DB::rollBack();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_pdf_export_downloads_successfully_with_correct_headers()
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export_pdf?date=' . $this->reportDate . '&type=pdf');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertHeader('content-type', 'application/pdf');
|
||||||
|
|
||||||
|
$contentDisposition = $response->headers->get('content-disposition');
|
||||||
|
$this->assertStringContainsString('daily-sale-payment-report-' . $this->reportDate, $contentDisposition);
|
||||||
|
$this->assertStringContainsString('.pdf', $contentDisposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_excel_export_downloads_successfully_with_correct_headers()
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export?date=' . $this->reportDate . '&type=excel');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$contentDisposition = $response->headers->get('content-disposition');
|
||||||
|
$this->assertStringContainsString('Daily_Sale_Payment_Report_' . $this->reportDate, $contentDisposition);
|
||||||
|
$this->assertStringContainsString('.xlsx', $contentDisposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_csv_export_downloads_successfully_with_correct_headers()
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export?date=' . $this->reportDate . '&type=csv');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$contentDisposition = $response->headers->get('content-disposition');
|
||||||
|
$this->assertStringContainsString('Daily_Sale_Payment_Report_' . $this->reportDate, $contentDisposition);
|
||||||
|
$this->assertStringContainsString('.csv', $contentDisposition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function export_still_works_when_no_sales_exist_for_selected_date()
|
||||||
|
{
|
||||||
|
$emptyDate = Carbon::today()->subYears(5)->toDateString();
|
||||||
|
|
||||||
|
$pdfResponse = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export_pdf?date=' . $emptyDate . '&type=pdf');
|
||||||
|
$pdfResponse->assertStatus(200);
|
||||||
|
|
||||||
|
$excelResponse = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export?date=' . $emptyDate . '&type=excel');
|
||||||
|
$excelResponse->assertStatus(200);
|
||||||
|
|
||||||
|
$csvResponse = $this->actingAs($this->cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule/export?date=' . $emptyDate . '&type=csv');
|
||||||
|
$csvResponse->assertStatus(200);
|
||||||
|
}
|
||||||
|
}
|
||||||
154
Tests/Feature/DailySalePaymentReportGenerateTest.php
Normal file
154
Tests/Feature/DailySalePaymentReportGenerateTest.php
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Modules\DailySalePaymentReportModule\Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\WithFaker;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Modules\DailySalePaymentReportModule\Entities\Customer;
|
||||||
|
|
||||||
|
class DailySalePaymentReportGenerateTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A basic feature test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
|
||||||
|
protected $reportDate;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
if (app()->environment() !== 'local') {
|
||||||
|
putenv('APP_ENV=local');
|
||||||
|
$_ENV['APP_ENV'] = 'local';
|
||||||
|
$_SERVER['APP_ENV'] = 'local';
|
||||||
|
}
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$this->reportDate = Carbon::today()->toDateString();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void
|
||||||
|
{
|
||||||
|
DB::rollBack();
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**@test */
|
||||||
|
public function test_generate_report_button_loads_sales_and_credit_collection_data_correctly()
|
||||||
|
{
|
||||||
|
$cashier = User::factory()->create([
|
||||||
|
'name' => fake()->name(),
|
||||||
|
'is_active' => 1,
|
||||||
|
'is_deleted' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$customer = Customer::factory()->create([
|
||||||
|
'name' => fake()->name(),
|
||||||
|
'customer_group_id' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$cashOptionId = DB::table('payment_options')->insertGetId([
|
||||||
|
'name' => 'Cash',
|
||||||
|
'is_active' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$card1OptionId = DB::table('payment_options')->insertGetId([
|
||||||
|
'name' => 'Card 1',
|
||||||
|
'is_active' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$todaySaleId = DB::table('sales')->insertGetId([
|
||||||
|
'reference_no' => 'INV-TEST-' . fake()->unique()->numerify('####'),
|
||||||
|
'user_id' => $cashier->id,
|
||||||
|
'customer_id' => $customer->id,
|
||||||
|
'warehouse_id' => 1,
|
||||||
|
'item' => 1,
|
||||||
|
'total_qty' => 1,
|
||||||
|
'total_discount' => 0,
|
||||||
|
'total_tax' => 0,
|
||||||
|
'total_price' => 5000,
|
||||||
|
'grand_total' => 5000,
|
||||||
|
'sale_status' => 1,
|
||||||
|
'payment_status' => 1,
|
||||||
|
'due_amount' => 0,
|
||||||
|
'paid_amount' => 5000,
|
||||||
|
'created_at' => $this->reportDate . ' 10:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::table('payments')->insert([
|
||||||
|
'payment_reference' => 'PAY-TEST-1',
|
||||||
|
'user_id' => $cashier->id,
|
||||||
|
'sale_id' => $todaySaleId,
|
||||||
|
'amount' => 5000,
|
||||||
|
'change' => 0,
|
||||||
|
'paying_method' => 'cash',
|
||||||
|
'payment_option_id' => $cashOptionId,
|
||||||
|
'created_at' => $this->reportDate . ' 10:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$creditSaleId = DB::table('sales')->insertGetId([
|
||||||
|
'reference_no' => 'INV-TEST-' . fake()->unique()->numerify('####'),
|
||||||
|
'user_id' => $cashier->id,
|
||||||
|
'customer_id' => $customer->id,
|
||||||
|
'warehouse_id' => 1,
|
||||||
|
'item' => 1,
|
||||||
|
'total_qty' => 1,
|
||||||
|
'total_discount' => 0,
|
||||||
|
'total_tax' => 0,
|
||||||
|
'total_price' => 3000,
|
||||||
|
'grand_total' => 3000,
|
||||||
|
'sale_status' => 1,
|
||||||
|
'payment_status' => 0,
|
||||||
|
'due_amount' => 3000,
|
||||||
|
'paid_amount' => 0,
|
||||||
|
'created_at' => Carbon::parse($this->reportDate)->subDays(5)->format('Y-m-d H:i:s'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
DB::table('payments')->insert([
|
||||||
|
'payment_reference' => 'PAY-TEST-2',
|
||||||
|
'user_id' => $cashier->id,
|
||||||
|
'sale_id' => $creditSaleId,
|
||||||
|
'amount' => 3000,
|
||||||
|
'change' => 0,
|
||||||
|
'paying_method' => 'card',
|
||||||
|
'payment_option_id' => $card1OptionId,
|
||||||
|
'created_at' => $this->reportDate . ' 14:00:00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->actingAs($cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule?report_date=' . $this->reportDate);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
|
||||||
|
$response->assertSee($customer->name);
|
||||||
|
$response->assertSee('5,000.00');
|
||||||
|
|
||||||
|
$response->assertSee('3,000.00');
|
||||||
|
|
||||||
|
$response->assertSee('Payment Method Summary');
|
||||||
|
$response->assertSee('8,000.00');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_generate_report_shows_no_records_message_when_no_sales_exist_for_selected_date(){
|
||||||
|
$cashier = User::factory()->create([
|
||||||
|
'is_active' => 1,
|
||||||
|
'is_deleted' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$emptyDate = Carbon::today()->subYears(5)->toDateString();
|
||||||
|
|
||||||
|
$response = $this->actingAs($cashier)
|
||||||
|
->get('/dailysalepaymentreportmodule?report_date=' . $emptyDate);
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
$response->assertSee('0.00');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user