Files
kulakpos_web/Modules/Business/App/Exports/ExportTransactionReport.php

86 lines
3.0 KiB
PHP
Raw Normal View History

2026-03-15 17:08:23 +07:00
<?php
namespace Modules\Business\App\Exports;
use App\Models\Transaction;
2026-05-14 11:55:22 +07:00
use App\Traits\DateFilterTrait;
2026-03-15 17:08:23 +07:00
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class ExportTransactionReport implements FromView
{
2026-05-14 11:55:22 +07:00
use DateFilterTrait;
2026-03-15 17:08:23 +07:00
public function view(): View
{
2026-05-14 11:55:22 +07:00
$businessId = auth()->user()->business_id;
$transactionsQuery = Transaction::with('paymentType')
->where('business_id', $businessId);
$duration = request('custom_days') ?: 'today';
$this->applyDateFilter($transactionsQuery, $duration, 'date', request('from_date'), request('to_date'));
// Search filter
if (request('search')) {
$transactionsQuery->where(function ($query) {
$query->where('amount', 'like', '%' . request('search') . '%')
->orWhere('invoice_no', 'like', '%' . request('search') . '%')
->orWhere('platform', 'like', '%' . request('search') . '%')
->orWhere('type', 'like', '%' . request('search') . '%');
});
}
// Platform filter
if (request('platform')) {
$transactionsQuery->where('platform', request('platform'));
}
// Party Filter
if (request('party_id')) {
$transactionsQuery->where(function ($q) {
$q->where(function ($saleQ) {
$saleQ->where('platform', 'sale')
->whereHas('sale', function ($s) {
$s->where('party_id', request('party_id'));
});
});
$q->where(function ($saleRtnQ) {
$saleRtnQ->where('platform', 'sale_return')
->whereHas('saleReturn.sale', function ($s) {
$s->where('party_id', request('party_id'));
});
});
$q->orWhere(function ($purQ) {
$purQ->where('platform', 'purchase')
->whereHas('purchase', function ($p) {
$p->where('party_id', request('party_id'));
});
});
$q->orWhere(function ($purRtnQ) {
$purRtnQ->where('platform', 'purchase_return')
->whereHas('purchaseReturn.purchase', function ($p) {
$p->where('party_id', request('party_id'));
});
});
$q->orWhere(function ($dueQ) {
$dueQ->where('platform', 'due_collect')
->whereHas('dueCollect', function ($d) {
$d->where('party_id', request('party_id'));
});
});
});
}
$transactions = $transactionsQuery->latest()->limit(request('per_page') ?? 20)->get();
2026-03-15 17:08:23 +07:00
return view('business::transactions.excel-csv', compact('transactions'));
}
}