Andrew Wallo 5 月之前
父節點
當前提交
843f6f46b0
共有 1 個檔案被更改,包括 20 行新增22 行删除
  1. 20
    22
      app/Services/AccountService.php

+ 20
- 22
app/Services/AccountService.php 查看文件

381
         $driver = DB::getDriverName();
381
         $driver = DB::getDriverName();
382
 
382
 
383
         $datediff = $driver === 'pgsql'
383
         $datediff = $driver === 'pgsql'
384
-            ? "DATE_PART('day', ?::date - invoices.due_date)"
385
-            : 'DATEDIFF(?, invoices.due_date)';
384
+            ? "DATE_PART('day', (:asOfDate)::date - invoices.due_date::date)"
385
+            : 'DATEDIFF(:asOfDate, invoices.due_date)';
386
 
386
 
387
         return Invoice::query()
387
         return Invoice::query()
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')
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])
397
             ->unpaid()
396
             ->unpaid()
398
             ->where('amount_due', '>', 0);
397
             ->where('amount_due', '>', 0);
399
     }
398
     }
404
         $driver = DB::getDriverName();
403
         $driver = DB::getDriverName();
405
 
404
 
406
         $datediff = $driver === 'pgsql'
405
         $datediff = $driver === 'pgsql'
407
-            ? "DATE_PART('day', ?::date - bills.due_date)"
408
-            : 'DATEDIFF(?, bills.due_date)';
406
+            ? "DATE_PART('day', (:asOfDate)::date - bills.due_date::date)"
407
+            : 'DATEDIFF(:asOfDate, bills.due_date)';
409
 
408
 
410
         return Bill::query()
409
         return Bill::query()
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')
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])
420
             ->unpaid()
418
             ->unpaid()
421
             ->where('amount_due', '>', 0);
419
             ->where('amount_due', '>', 0);
422
     }
420
     }

Loading…
取消
儲存