update marketing
All checks were successful
All checks were successful
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
use App\Services\PdfService;
|
||||
use App\Traits\DateFilterTrait;
|
||||
use App\Traits\DateRangeTrait;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Business\App\Exports\ExportTransaction;
|
||||
|
||||
@@ -24,15 +23,6 @@ public function __construct()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$businessId = auth()->user()->business_id;
|
||||
$today = Carbon::today()->format('Y-m-d');
|
||||
|
||||
$total_due = DueCollect::where('business_id', $businessId)
|
||||
->whereDate('paymentDate', $today)
|
||||
->sum('totalDue');
|
||||
|
||||
$total_paid = DueCollect::where('business_id', $businessId)
|
||||
->whereDate('paymentDate', $today)
|
||||
->sum('payDueAmount');
|
||||
|
||||
$transactionsQuery = DueCollect::with('party:id,name,type', 'payment_type:id,name', 'transactions')->where('business_id', $businessId);
|
||||
|
||||
@@ -93,12 +83,44 @@ public function exportCsv()
|
||||
return Excel::download(new ExportTransaction, 'transaction-history.csv');
|
||||
}
|
||||
|
||||
public function exportPdf()
|
||||
public function exportPdf(Request $request)
|
||||
{
|
||||
$transactions = DueCollect::with('party:id,name,type', 'payment_type:id,name', 'transactions')->where('business_id', auth()->user()->business_id)
|
||||
->latest()
|
||||
->get();
|
||||
$businessId = auth()->user()->business_id;
|
||||
|
||||
return PdfService::render('business::reports.transaction-history.pdf', compact('transactions'),'due-transactions-report.pdf');
|
||||
$transactionsQuery = DueCollect::with('party:id,name,type', 'payment_type:id,name', 'transactions')->where('business_id', $businessId);
|
||||
|
||||
// Date Filter
|
||||
$duration = $request->custom_days ?: 'today';
|
||||
[$filter_from_date, $filter_to_date] = $this->applyDateRange($duration, $request->from_date, $request->to_date);
|
||||
|
||||
$this->applyDateFilter($transactionsQuery, $duration, 'paymentDate', $request->from_date, $request->to_date);
|
||||
|
||||
// Search Filter
|
||||
if ($request->filled('search')) {
|
||||
$transactionsQuery->where(function ($query) use ($request) {
|
||||
$query->where('paymentType', 'like', '%' . $request->search . '%')
|
||||
->orWhere('totalDue', 'like', '%' . $request->search . '%')
|
||||
->orWhere('invoiceNumber', 'like', '%' . $request->search . '%')
|
||||
->orWhere('payDueAmount', 'like', '%' . $request->search . '%')
|
||||
->orWhereHas('party', function ($q) use ($request) {
|
||||
$q->where('name', 'like', '%' . $request->search . '%');
|
||||
})
|
||||
->orWhereHas('payment_type', function ($q) use ($request) {
|
||||
$q->where('name', 'like', '%' . $request->search . '%');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->filled('type')) {
|
||||
$transactionsQuery->whereHas('party', function ($q) use ($request) {
|
||||
$q->where(function ($q) use ($request) {
|
||||
$q->where('type', $request->type);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$transactions = $transactionsQuery->latest()->limit($request->per_page)->get();
|
||||
|
||||
return PdfService::render('business::reports.transaction-history.pdf', compact('transactions', 'duration', 'filter_from_date', 'filter_to_date'),'due-transactions-report.pdf');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user