ソースを参照

Merge pull request #200 from avenjamin/3.x

Add SQLite support in getStats() function
3.x
Andrew Wallo 1ヶ月前
コミット
3ebcf04cea
コミッターのメールアドレスに関連付けられたアカウントが存在しません

+ 1
- 0
.gitignore ファイルの表示

@@ -24,3 +24,4 @@ Homestead.yaml
24 24
 Thumbs.db
25 25
 /public/css/
26 26
 /public/js/
27
+.DS_Store

+ 2
- 0
app/Filament/Company/Resources/Purchases/BillResource/Widgets/BillOverview.php ファイルの表示

@@ -37,6 +37,8 @@ class BillOverview extends EnhancedStatsOverviewWidget
37 37
 
38 38
             if ($driver === 'pgsql') {
39 39
                 $query->selectRaw('AVG(EXTRACT(EPOCH FROM (paid_at - date)) / 86400) as avg_days');
40
+            } elseif ($driver === 'sqlite') {
41
+                $query->selectRaw('AVG(julianday(paid_at) - julianday(date)) as avg_days');
40 42
             } else {
41 43
                 $query->selectRaw('AVG(TIMESTAMPDIFF(DAY, date, paid_at)) as avg_days');
42 44
             }

+ 2
- 0
app/Filament/Company/Resources/Purchases/VendorResource/Widgets/BillOverview.php ファイルの表示

@@ -40,6 +40,8 @@ class BillOverview extends EnhancedStatsOverviewWidget
40 40
 
41 41
         if ($driver === 'pgsql') {
42 42
             $query->selectRaw('AVG(EXTRACT(EPOCH FROM (paid_at - date)) / 86400) as avg_days');
43
+        } elseif ($driver === 'sqlite') {
44
+            $query->selectRaw('AVG(julianday(paid_at) - julianday(date)) as avg_days');
43 45
         } else {
44 46
             $query->selectRaw('AVG(TIMESTAMPDIFF(DAY, date, paid_at)) as avg_days');
45 47
         }

+ 2
- 0
app/Filament/Company/Resources/Sales/ClientResource/Widgets/InvoiceOverview.php ファイルの表示

@@ -51,6 +51,8 @@ class InvoiceOverview extends EnhancedStatsOverviewWidget
51 51
 
52 52
         if ($driver === 'pgsql') {
53 53
             $query->selectRaw('AVG(EXTRACT(EPOCH FROM (paid_at - date)) / 86400) as avg_days');
54
+        } elseif ($driver === 'sqlite') {
55
+            $query->selectRaw('AVG(julianday(paid_at) - julianday(date)) as avg_days');
54 56
         } else {
55 57
             $query->selectRaw('AVG(TIMESTAMPDIFF(DAY, date, paid_at)) as avg_days');
56 58
         }

+ 2
- 0
app/Filament/Company/Resources/Sales/InvoiceResource/Widgets/InvoiceOverview.php ファイルの表示

@@ -83,6 +83,8 @@ class InvoiceOverview extends EnhancedStatsOverviewWidget
83 83
 
84 84
             if ($driver === 'pgsql') {
85 85
                 $query->selectRaw('AVG(EXTRACT(EPOCH FROM (paid_at - approved_at)) / 86400) as avg_days');
86
+            } elseif ($driver === 'sqlite') {
87
+                $query->selectRaw('AVG(julianday(paid_at) - julianday(approved_at)) as avg_days');
86 88
             } else {
87 89
                 $query->selectRaw('AVG(TIMESTAMPDIFF(DAY, approved_at, paid_at)) as avg_days');
88 90
             }

+ 22
- 6
app/Services/AccountService.php ファイルの表示

@@ -380,9 +380,17 @@ class AccountService
380 380
         $asOfDate = $asOfDate ?? company_today()->toDateString();
381 381
         $driver = DB::getDriverName();
382 382
 
383
-        $datediff = $driver === 'pgsql'
384
-            ? '(?::date - invoices.due_date::date)'
385
-            : 'DATEDIFF(?, invoices.due_date)';
383
+        switch ($driver) {
384
+            case 'pgsql':
385
+                $datediff = '(?::date - invoices.due_date::date)';
386
+                break;
387
+            case 'sqlite':
388
+                $datediff = 'JULIANDAY(?) - JULIANDAY(invoices.due_date)';
389
+                break;
390
+            default:
391
+                $datediff = 'DATEDIFF(?, invoices.due_date)';
392
+                break;
393
+        }
386 394
 
387 395
         return Invoice::query()
388 396
             ->select([
@@ -403,9 +411,17 @@ class AccountService
403 411
         $asOfDate = $asOfDate ?? company_today()->toDateString();
404 412
         $driver = DB::getDriverName();
405 413
 
406
-        $datediff = $driver === 'pgsql'
407
-            ? '(?::date - bills.due_date::date)'
408
-            : 'DATEDIFF(?, bills.due_date)';
414
+        switch ($driver) {
415
+            case 'pgsql':
416
+                $datediff = '(?::date - bills.due_date::date)';
417
+                break;
418
+            case 'sqlite':
419
+                $datediff = 'JULIANDAY(?) - JULIANDAY(bills.due_date)';
420
+                break;
421
+            default:
422
+                $datediff = 'DATEDIFF(?, bills.due_date)';
423
+                break;
424
+        }
409 425
 
410 426
         return Bill::query()
411 427
             ->select([

読み込み中…
キャンセル
保存