update marketing
All checks were successful
Build, Push and Deploy / build-and-push (push) Successful in 5m14s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 17s
Build, Push and Deploy / deploy-staging (push) Successful in 41s
Build, Push and Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-05-14 11:55:22 +07:00
parent f80fcc4c1b
commit 05fd3230b8
448 changed files with 17545 additions and 5128 deletions

View File

@@ -3,14 +3,17 @@
namespace Modules\Business\App\Exports;
use App\Models\Transaction;
use App\Traits\DateFilterTrait;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportCashFlowReport implements FromView
{
use DateFilterTrait;
public function view(): View
{
$cash_flows = Transaction::with([
$query = Transaction::with([
'paymentType:id,name',
'sale:id,party_id',
'sale.party:id,name',
@@ -22,11 +25,44 @@ public function view(): View
'dueCollect.party:id,name',
])
->where('business_id', auth()->user()->business_id)
->whereIn('type', ['debit', 'credit'])
->latest()
->get();
->whereIn('type', ['debit', 'credit']);
$opening_balance = 0;
// Date Filter
$duration = request('custom_days') ?: 'today';
$this->applyDateFilter($query, $duration, 'date', request('from_date'), request('to_date'));
// Search filter
if (request('search')) {
$query->where(function ($query) {
$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) {
$q->where('name', 'like', '%' . request('search') . '%');
});
});
}
// Platform filter
if (request('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 view('business::cash-flow.excel-csv', compact('cash_flows', 'opening_balance'));
}