update marketing
All checks were successful
All checks were successful
This commit is contained in:
@@ -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'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user