Andrew Wallo 5 months ago
parent
commit
ecaf9babf1
1 changed files with 22 additions and 20 deletions
  1. 22
    20
      app/Services/AccountService.php

+ 22
- 20
app/Services/AccountService.php View File

@@ -381,18 +381,19 @@ class AccountService
381 381
         $driver = DB::getDriverName();
382 382
 
383 383
         $datediff = $driver === 'pgsql'
384
-            ? "DATE_PART('day', (:asOfDate)::date - invoices.due_date::date)"
385
-            : 'DATEDIFF(:asOfDate, invoices.due_date)';
384
+            ? "DATE_PART('day', ?::date - invoices.due_date)"
385
+            : 'DATEDIFF(?, invoices.due_date)';
386 386
 
387 387
         return Invoice::query()
388
-            ->selectRaw("
389
-            invoices.id,
390
-            invoices.client_id,
391
-            invoices.due_date,
392
-            invoices.amount_due,
393
-            invoices.currency_code,
394
-            {$datediff} as days_overdue
395
-        ", ['asOfDate' => $asOfDate])
388
+            ->select([
389
+                'invoices.id',
390
+                'invoices.client_id',
391
+                'invoices.due_date',
392
+                'invoices.amount_due',
393
+                'invoices.currency_code',
394
+                DB::raw("{$datediff} as days_overdue"),
395
+            ])
396
+            ->addBinding([$asOfDate], 'select')
396 397
             ->unpaid()
397 398
             ->where('amount_due', '>', 0);
398 399
     }
@@ -403,18 +404,19 @@ class AccountService
403 404
         $driver = DB::getDriverName();
404 405
 
405 406
         $datediff = $driver === 'pgsql'
406
-            ? "DATE_PART('day', (:asOfDate)::date - bills.due_date::date)"
407
-            : 'DATEDIFF(:asOfDate, bills.due_date)';
407
+            ? "DATE_PART('day', ?::date - bills.due_date)"
408
+            : 'DATEDIFF(?, bills.due_date)';
408 409
 
409 410
         return Bill::query()
410
-            ->selectRaw("
411
-            bills.id,
412
-            bills.vendor_id,
413
-            bills.due_date,
414
-            bills.amount_due,
415
-            bills.currency_code,
416
-            {$datediff} as days_overdue
417
-        ", ['asOfDate' => $asOfDate])
411
+            ->select([
412
+                'bills.id',
413
+                'bills.vendor_id',
414
+                'bills.due_date',
415
+                'bills.amount_due',
416
+                'bills.currency_code',
417
+                DB::raw("{$datediff} as days_overdue"),
418
+            ])
419
+            ->addBinding([$asOfDate], 'select')
418 420
             ->unpaid()
419 421
             ->where('amount_due', '>', 0);
420 422
     }

Loading…
Cancel
Save