Selaa lähdekoodia

wip adjustment statuses

3.x
Andrew Wallo 6 kuukautta sitten
vanhempi
commit
97f9cbd483
2 muutettua tiedostoa jossa 25 lisäystä ja 56 poistoa
  1. 19
    50
      app/Models/Accounting/Adjustment.php
  2. 6
    6
      composer.lock

+ 19
- 50
app/Models/Accounting/Adjustment.php Näytä tiedosto

27
     use CompanyOwned;
27
     use CompanyOwned;
28
     use HasFactory;
28
     use HasFactory;
29
 
29
 
30
-    protected $table = 'adjustments';
31
-
32
     protected $fillable = [
30
     protected $fillable = [
33
         'company_id',
31
         'company_id',
34
         'account_id',
32
         'account_id',
101
         return $this->category->isDiscount() && $this->type->isPurchase();
99
         return $this->category->isDiscount() && $this->type->isPurchase();
102
     }
100
     }
103
 
101
 
104
-    // Add these methods to your Adjustment model
105
-
106
-    /**
107
-     * Check if adjustment can be paused
108
-     */
109
     public function canBePaused(): bool
102
     public function canBePaused(): bool
110
     {
103
     {
111
         return $this->status === AdjustmentStatus::Active;
104
         return $this->status === AdjustmentStatus::Active;
112
     }
105
     }
113
 
106
 
114
-    /**
115
-     * Check if adjustment can be resumed
116
-     */
117
     public function canBeResumed(): bool
107
     public function canBeResumed(): bool
118
     {
108
     {
119
         return $this->status === AdjustmentStatus::Paused;
109
         return $this->status === AdjustmentStatus::Paused;
120
     }
110
     }
121
 
111
 
122
-    /**
123
-     * Check if adjustment can be archived
124
-     */
125
     public function canBeArchived(): bool
112
     public function canBeArchived(): bool
126
     {
113
     {
127
         return $this->status !== AdjustmentStatus::Archived;
114
         return $this->status !== AdjustmentStatus::Archived;
128
     }
115
     }
129
 
116
 
130
-    /**
131
-     * Calculate the natural status of the adjustment based on dates
132
-     */
133
     public function calculateNaturalStatus(): AdjustmentStatus
117
     public function calculateNaturalStatus(): AdjustmentStatus
134
     {
118
     {
135
         if ($this->start_date?->isFuture()) {
119
         if ($this->start_date?->isFuture()) {
143
         return AdjustmentStatus::Active;
127
         return AdjustmentStatus::Active;
144
     }
128
     }
145
 
129
 
146
-    /**
147
-     * Pause the adjustment
148
-     */
149
     public function pause(?string $reason = null, ?\DateTime $untilDate = null): bool
130
     public function pause(?string $reason = null, ?\DateTime $untilDate = null): bool
150
     {
131
     {
151
         if (! $this->canBePaused()) {
132
         if (! $this->canBePaused()) {
152
             return false;
133
             return false;
153
         }
134
         }
154
 
135
 
155
-        $this->paused_at = now();
156
-        $this->paused_until = $untilDate;
157
-        $this->status = AdjustmentStatus::Paused;
158
-        $this->status_reason = $reason;
159
-
160
-        return $this->save();
136
+        return $this->update([
137
+            'paused_at' => now(),
138
+            'paused_until' => $untilDate,
139
+            'status' => AdjustmentStatus::Paused,
140
+            'status_reason' => $reason,
141
+        ]);
161
     }
142
     }
162
 
143
 
163
-    /**
164
-     * Resume the adjustment
165
-     */
166
     public function resume(): bool
144
     public function resume(): bool
167
     {
145
     {
168
         if (! $this->canBeResumed()) {
146
         if (! $this->canBeResumed()) {
169
             return false;
147
             return false;
170
         }
148
         }
171
 
149
 
172
-        $this->paused_at = null;
173
-        $this->paused_until = null;
174
-        $this->status_reason = null;
175
-        $this->status = $this->calculateNaturalStatus();
176
-
177
-        return $this->save();
150
+        return $this->update([
151
+            'paused_at' => null,
152
+            'paused_until' => null,
153
+            'status_reason' => null,
154
+            'status' => $this->calculateNaturalStatus(),
155
+        ]);
178
     }
156
     }
179
 
157
 
180
-    /**
181
-     * Archive the adjustment
182
-     */
183
     public function archive(?string $reason = null): bool
158
     public function archive(?string $reason = null): bool
184
     {
159
     {
185
         if (! $this->canBeArchived()) {
160
         if (! $this->canBeArchived()) {
186
             return false;
161
             return false;
187
         }
162
         }
188
 
163
 
189
-        $this->status = AdjustmentStatus::Archived;
190
-        $this->status_reason = $reason;
191
-
192
-        return $this->save();
164
+        return $this->update([
165
+            'status' => AdjustmentStatus::Archived,
166
+            'status_reason' => $reason,
167
+        ]);
193
     }
168
     }
194
 
169
 
195
-    /**
196
-     * Check if the adjustment should be automatically resumed
197
-     */
198
     public function shouldAutoResume(): bool
170
     public function shouldAutoResume(): bool
199
     {
171
     {
200
         return $this->status === AdjustmentStatus::Paused &&
172
         return $this->status === AdjustmentStatus::Paused &&
202
             $this->paused_until->isPast();
174
             $this->paused_until->isPast();
203
     }
175
     }
204
 
176
 
205
-    /**
206
-     * Refresh the status based on current dates and conditions
207
-     */
208
     public function refreshStatus(): bool
177
     public function refreshStatus(): bool
209
     {
178
     {
210
         // Don't automatically change archived or paused status
179
         // Don't automatically change archived or paused status
223
 
192
 
224
         // Only update if the status would change
193
         // Only update if the status would change
225
         if ($this->status !== $naturalStatus) {
194
         if ($this->status !== $naturalStatus) {
226
-            $this->status = $naturalStatus;
227
-
228
-            return $this->save();
195
+            return $this->update([
196
+                'status' => $naturalStatus,
197
+            ]);
229
         }
198
         }
230
 
199
 
231
         return false;
200
         return false;

+ 6
- 6
composer.lock Näytä tiedosto

302
         },
302
         },
303
         {
303
         {
304
             "name": "anourvalar/eloquent-serialize",
304
             "name": "anourvalar/eloquent-serialize",
305
-            "version": "1.3.0",
305
+            "version": "1.3.1",
306
             "source": {
306
             "source": {
307
                 "type": "git",
307
                 "type": "git",
308
                 "url": "https://github.com/AnourValar/eloquent-serialize.git",
308
                 "url": "https://github.com/AnourValar/eloquent-serialize.git",
309
-                "reference": "91188f82c5ec2842a5469fca6d7d64baa37ea593"
309
+                "reference": "060632195821e066de1fc0f869881dd585e2f299"
310
             },
310
             },
311
             "dist": {
311
             "dist": {
312
                 "type": "zip",
312
                 "type": "zip",
313
-                "url": "https://api.github.com/repos/AnourValar/eloquent-serialize/zipball/91188f82c5ec2842a5469fca6d7d64baa37ea593",
314
-                "reference": "91188f82c5ec2842a5469fca6d7d64baa37ea593",
313
+                "url": "https://api.github.com/repos/AnourValar/eloquent-serialize/zipball/060632195821e066de1fc0f869881dd585e2f299",
314
+                "reference": "060632195821e066de1fc0f869881dd585e2f299",
315
                 "shasum": ""
315
                 "shasum": ""
316
             },
316
             },
317
             "require": {
317
             "require": {
362
             ],
362
             ],
363
             "support": {
363
             "support": {
364
                 "issues": "https://github.com/AnourValar/eloquent-serialize/issues",
364
                 "issues": "https://github.com/AnourValar/eloquent-serialize/issues",
365
-                "source": "https://github.com/AnourValar/eloquent-serialize/tree/1.3.0"
365
+                "source": "https://github.com/AnourValar/eloquent-serialize/tree/1.3.1"
366
             },
366
             },
367
-            "time": "2025-03-22T08:49:12+00:00"
367
+            "time": "2025-04-06T06:54:34+00:00"
368
         },
368
         },
369
         {
369
         {
370
             "name": "awcodes/filament-table-repeater",
370
             "name": "awcodes/filament-table-repeater",

Loading…
Peruuta
Tallenna