finishing to dev
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 3m41s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 16s
Build, Push and Deploy / deploy-staging (push) Successful in 42s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-14 22:50:44 +07:00
parent 2fabdf8fc9
commit 8307b9e66d
212 changed files with 2451 additions and 4493 deletions

View File

@@ -31,6 +31,16 @@ public function index(Request $request)
->where('business_id', auth()->user()->business_id)
->whereIn('type', ['debit', 'credit']);
$total_cash_in = (clone $query)
->where('type', 'credit')
->sum('amount');
$total_cash_out = (clone $query)
->where('type', 'debit')
->sum('amount');
$total_running_cash = $total_cash_in - $total_cash_out;
// Date Filter
$duration = $request->custom_days ?: 'today';
[$filter_from_date, $filter_to_date] = $this->applyDateRange($duration, $request->from_date, $request->to_date);
@@ -60,16 +70,6 @@ public function index(Request $request)
$perPage = $request->input('per_page', 20);
$cash_flows = $query->paginate($perPage)->appends($request->query());
$cashflow_cash_in = (clone $query)
->where('type', 'credit')
->sum('amount');
$cashflow_cash_out = (clone $query)
->where('type', 'debit')
->sum('amount');
$total_running_cash = $cashflow_cash_in - $cashflow_cash_out;
$firstDate = $cash_flows->first()?->date;
if ($firstDate) {
@@ -83,14 +83,11 @@ public function index(Request $request)
if ($request->ajax()) {
return response()->json([
'data' => view('business::cash-flow.datas', compact('cash_flows', 'cashflow_cash_in', 'cashflow_cash_out', 'opening_balance', 'total_running_cash', 'filter_from_date', 'filter_to_date', 'duration'))->render(),
'cashflow_cash_in' => currency_format($cashflow_cash_in, 'icon', 2, business_currency()),
'cashflow_cash_out' => currency_format($cashflow_cash_out, 'icon', 2, business_currency()),
'total_running_cash' => currency_format($total_running_cash, 'icon', 2, business_currency()),
'data' => view('business::cash-flow.datas', compact('cash_flows', 'total_cash_in', 'total_cash_out', 'opening_balance', 'total_running_cash', 'filter_from_date', 'filter_to_date', 'duration'))->render()
]);
}
return view('business::cash-flow.index', compact('cash_flows', 'cashflow_cash_in', 'cashflow_cash_out', 'opening_balance', 'total_running_cash', 'filter_from_date', 'filter_to_date', 'duration'));
return view('business::cash-flow.index', compact('cash_flows', 'total_cash_in', 'total_cash_out', 'opening_balance', 'total_running_cash', 'filter_from_date', 'filter_to_date', 'duration'));
}
public function exportExcel()
@@ -103,9 +100,9 @@ public function exportCsv()
return Excel::download(new ExportCashFlowReport, 'cash-flow.csv');
}
public function exportPdf(Request $request)
public function exportPdf()
{
$query = Transaction::with([
$cash_flows = Transaction::with([
'paymentType:id,name',
'sale:id,party_id',
'sale.party:id,name',
@@ -117,47 +114,12 @@ public function exportPdf(Request $request)
'dueCollect.party:id,name',
])
->where('business_id', auth()->user()->business_id)
->whereIn('type', ['debit', 'credit']);
->whereIn('type', ['debit', 'credit'])
->latest()
->get();
// Date Filter
$duration = $request->custom_days ?: 'today';
[$filter_from_date, $filter_to_date] = $this->applyDateRange($duration, $request->from_date, $request->to_date);
$opening_balance = 0;
$this->applyDateFilter($query, $duration, 'date', $request->from_date, $request->to_date);
// Search filter
if ($request->filled('search')) {
$query->where(function ($query) use ($request) {
$query->where('date', 'like', '%' . $request->search . '%')
->orWhere('invoice_no', 'like', '%' . $request->search . '%')
->orWhere('platform', 'like', '%' . $request->search . '%')
->orWhere('amount', 'like', '%' . $request->search . '%')
->orWhere('transaction_type', 'like', '%' . $request->search . '%')
->orWhereHas('paymentType', function ($q) use ($request) {
$q->where('name', 'like', '%' . $request->search . '%');
});
});
}
// Platform filter
if ($request->filled('platform')) {
$query->where('platform', $request->platform);
}
// Paginate data
$cash_flows = $query->limit($request->per_page ?? 20)->get();
$firstDate = $cash_flows->first()?->date;
if ($firstDate) {
$opening_balance = (clone $query)
->whereDate('date', '<', $firstDate)
->selectRaw("SUM(CASE WHEN type='credit' THEN amount ELSE 0 END) - SUM(CASE WHEN type='debit' THEN amount ELSE 0 END) as balance")
->value('balance') ?? 0;
} else {
$opening_balance = 0;
}
return PdfService::render('business::cash-flow.pdf', compact('cash_flows', 'opening_balance', 'duration', 'filter_from_date', 'filter_to_date'),'cash-flow-report.pdf');
return PdfService::render('business::cash-flow.pdf', compact('cash_flows', 'opening_balance'),'cash-flow-report.pdf');
}
}