mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-30 21:21:09 -04:00 
			
		
		
		
	Only show non-draft invoices on dashboard
An invoice cannot be considered due if it has not been sent (and thus still a 'DRAFT'). This change adds a `WHERE status != 'DRAFT'` to each invoice query in the dashboard controller. Additionally, this change replaces `->get()->count()` calls to just `->count()`, which should be equivalent and more efficient.
This commit is contained in:
		| @ -58,6 +58,7 @@ class DashboardController extends Controller | ||||
|                     'invoice_date', | ||||
|                     [$start->format('Y-m-d'), $end->format('Y-m-d')] | ||||
|                 ) | ||||
|                 ->where('status', '!=', Invoice::STATUS_DRAFT) | ||||
|                 ->whereCompany($request->header('company')) | ||||
|                 ->sum('total') | ||||
|             ); | ||||
| @ -94,6 +95,7 @@ class DashboardController extends Controller | ||||
|         $start->subMonth()->endOfMonth(); | ||||
|  | ||||
|         $salesTotal = Invoice::whereCompany($request->header('company')) | ||||
|             ->where('status', '!=', Invoice::STATUS_DRAFT) | ||||
|             ->whereBetween( | ||||
|                 'invoice_date', | ||||
|                 [$startDate->format('Y-m-d'), $start->format('Y-m-d')] | ||||
| @ -121,11 +123,21 @@ class DashboardController extends Controller | ||||
|             'netProfits' => $netProfits, | ||||
|         ]; | ||||
|  | ||||
|         $customersCount = User::customer()->whereCompany($request->header('company'))->get()->count(); | ||||
|         $invoicesCount = Invoice::whereCompany($request->header('company'))->get()->count(); | ||||
|         $estimatesCount = Estimate::whereCompany($request->header('company'))->get()->count(); | ||||
|         $totalDueAmount = Invoice::whereCompany($request->header('company'))->sum('due_amount'); | ||||
|         $dueInvoices = Invoice::with('user')->whereCompany($request->header('company'))->where('due_amount', '>', 0)->take(5)->latest()->get(); | ||||
|         $customersCount = User::customer()->whereCompany($request->header('company'))->count(); | ||||
|         $invoicesCount = Invoice::whereCompany($request->header('company')) | ||||
|             ->where('status', '!=', Invoice::STATUS_DRAFT) | ||||
|             ->count(); | ||||
|         $estimatesCount = Estimate::whereCompany($request->header('company'))->count(); | ||||
|         $totalDueAmount = Invoice::whereCompany($request->header('company')) | ||||
|             ->where('status', '!=', Invoice::STATUS_DRAFT) | ||||
|             ->sum('due_amount'); | ||||
|         $dueInvoices = Invoice::with('user') | ||||
|             ->whereCompany($request->header('company')) | ||||
|             ->where('status', '!=', Invoice::STATUS_DRAFT) | ||||
|             ->where('due_amount', '>', 0) | ||||
|             ->take(5) | ||||
|             ->latest() | ||||
|             ->get(); | ||||
|         $estimates = Estimate::with('user')->whereCompany($request->header('company'))->take(5)->latest()->get(); | ||||
|  | ||||
|         return response()->json([ | ||||
|  | ||||
		Reference in New Issue
	
	Block a user