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

@@ -5,6 +5,7 @@
use App\Models\Branch;
use App\Models\Expense;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use App\Http\Controllers\Controller;
use App\Services\PdfService;
use App\Traits\DateFilterTrait;
@@ -25,6 +26,10 @@ public function index(Request $request)
{
$businessId = auth()->user()->business_id;
$total_expense = Expense::where('business_id', $businessId)
->whereDate('expenseDate', Carbon::today()->format('Y-m-d'))
->sum('amount');
$expenseQuery = Expense::with('category:id,categoryName', 'payment_type:id,name', 'branch:id,name', 'transactions')
->where('business_id', $businessId);
@@ -85,40 +90,10 @@ public function exportCsv()
public function exportPdf(Request $request)
{
$expenseQuery = Expense::with('category:id,categoryName', 'payment_type:id,name', 'branch:id,name', 'transactions')
->where('business_id', auth()->user()->business_id);
$expense_reports = Expense::with('category:id,categoryName', 'payment_type:id,name', 'branch:id,name', 'transactions')->where('business_id', auth()->user()->business_id)
->latest()
->get();
$expenseQuery->when($request->branch_id, function ($q) use ($request) {
$q->where('branch_id', $request->branch_id);
});
// Date Filter
$duration = $request->custom_days ?: 'today';
[$filter_from_date, $filter_to_date] = $this->applyDateRange($duration, $request->from_date, $request->to_date);
$this->applyDateFilter($expenseQuery, $duration, 'expenseDate', $request->from_date, $request->to_date);
// Search Filter
if ($request->filled('search')) {
$expenseQuery->where(function ($query) use ($request) {
$query->where('expanseFor', 'like', '%' . $request->search . '%')
->orWhere('paymentType', 'like', '%' . $request->search . '%')
->orWhere('referenceNo', 'like', '%' . $request->search . '%')
->orWhere('amount', 'like', '%' . $request->search . '%')
->orWhereHas('category', function ($q) use ($request) {
$q->where('categoryName', 'like', '%' . $request->search . '%');
})
->orWhereHas('payment_type', function ($q) use ($request) {
$q->where('name', 'like', '%' . $request->search . '%');
})
->orWhereHas('branch', function ($q) use ($request) {
$q->where('name', 'like', '%' . $request->search . '%');
});
});
}
$expense_reports = $expenseQuery->latest()->limit($request->per_page ?? 20)->get();
return PdfService::render('business::reports.expense.pdf', compact('expense_reports', 'duration', 'filter_from_date', 'filter_to_date'),'expenses-report.pdf');
return PdfService::render('business::reports.expense.pdf', compact('expense_reports'),'expenses-report.pdf');
}
}