Andrew Wallo пре 6 месеци
родитељ
комит
574cad7af4

+ 30
- 9
app/Filament/Company/Resources/Sales/EstimateResource/Widgets/EstimateOverview.php Прегледај датотеку

@@ -21,6 +21,24 @@ class EstimateOverview extends EnhancedStatsOverviewWidget
21 21
 
22 22
     protected function getStats(): array
23 23
     {
24
+        $activeTab = $this->activeTab;
25
+
26
+        if ($activeTab === 'draft') {
27
+            return [
28
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Active Estimates', '-')
29
+                    ->suffix('')
30
+                    ->description(''),
31
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Accepted Estimates', '-')
32
+                    ->suffix('')
33
+                    ->description(''),
34
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Converted Estimates', '-')
35
+                    ->suffix('')
36
+                    ->description(''),
37
+                EnhancedStatsOverviewWidget\EnhancedStat::make('Average Estimate Total', '-')
38
+                    ->suffix(''),
39
+            ];
40
+        }
41
+
24 42
         $activeEstimates = $this->getPageTableQuery()->active();
25 43
 
26 44
         $totalActiveCount = $activeEstimates->count();
@@ -36,18 +54,21 @@ class EstimateOverview extends EnhancedStatsOverviewWidget
36 54
             ->where('status', EstimateStatus::Converted);
37 55
 
38 56
         $totalConvertedCount = $convertedEstimates->count();
39
-        $totalEstimatesCount = $this->getPageTableQuery()->count();
40 57
 
41
-        $percentConverted = $totalEstimatesCount > 0
42
-            ? Number::percentage(($totalConvertedCount / $totalEstimatesCount) * 100, maxPrecision: 1)
43
-            : Number::percentage(0, maxPrecision: 1);
58
+        $validEstimates = $this->getPageTableQuery()
59
+            ->whereNotIn('status', [
60
+                EstimateStatus::Draft,
61
+            ]);
44 62
 
45
-        $totalEstimateAmount = $this->getPageTableQuery()
46
-            ->get()
47
-            ->sumMoneyInDefaultCurrency('total');
63
+        $totalValidEstimatesCount = $validEstimates->count();
64
+        $totalValidEstimateAmount = $validEstimates->get()->sumMoneyInDefaultCurrency('total');
65
+
66
+        $percentConverted = $totalValidEstimatesCount > 0
67
+            ? Number::percentage(($totalConvertedCount / $totalValidEstimatesCount) * 100, maxPrecision: 1)
68
+            : Number::percentage(0, maxPrecision: 1);
48 69
 
49
-        $averageEstimateTotal = $totalEstimatesCount > 0
50
-            ? (int) round($totalEstimateAmount / $totalEstimatesCount)
70
+        $averageEstimateTotal = $totalValidEstimatesCount > 0
71
+            ? (int) round($totalValidEstimateAmount / $totalValidEstimatesCount)
51 72
             : 0;
52 73
 
53 74
         return [

+ 2
- 1
app/Models/Accounting/Estimate.php Прегледај датотеку

@@ -124,7 +124,7 @@ class Estimate extends Document
124 124
     protected function isCurrentlyExpired(): Attribute
125 125
     {
126 126
         return Attribute::get(function () {
127
-            return $this->expiration_date?->isBefore(today()) && $this->canBeExpired();
127
+            return $this->expiration_date?->isBefore(today());
128 128
         });
129 129
     }
130 130
 
@@ -170,6 +170,7 @@ class Estimate extends Document
170 170
             EstimateStatus::Accepted,
171 171
             EstimateStatus::Declined,
172 172
             EstimateStatus::Converted,
173
+            EstimateStatus::Expired,
173 174
         ]);
174 175
     }
175 176
 

+ 11
- 1
app/Observers/EstimateObserver.php Прегледај датотеку

@@ -11,7 +11,17 @@ class EstimateObserver
11 11
 {
12 12
     public function saving(Estimate $estimate): void
13 13
     {
14
-        if ($estimate->approved_at && $estimate->is_currently_expired) {
14
+        if (! $estimate->wasApproved()) {
15
+            return;
16
+        }
17
+
18
+        if ($estimate->isDirty('expiration_date') && $estimate->status === EstimateStatus::Expired && ! $estimate->is_currently_expired) {
19
+            $estimate->status = $estimate->hasBeenSent() ? EstimateStatus::Sent : EstimateStatus::Unsent;
20
+
21
+            return;
22
+        }
23
+
24
+        if ($estimate->is_currently_expired && $estimate->canBeExpired()) {
15 25
             $estimate->status = EstimateStatus::Expired;
16 26
         }
17 27
     }

Loading…
Откажи
Сачувај