Andrew Wallo 6 месяцев назад
Родитель
Сommit
97f9cbd483
2 измененных файлов: 25 добавлений и 56 удалений
  1. 19
    50
      app/Models/Accounting/Adjustment.php
  2. 6
    6
      composer.lock

+ 19
- 50
app/Models/Accounting/Adjustment.php Просмотреть файл

@@ -27,8 +27,6 @@ class Adjustment extends Model
27 27
     use CompanyOwned;
28 28
     use HasFactory;
29 29
 
30
-    protected $table = 'adjustments';
31
-
32 30
     protected $fillable = [
33 31
         'company_id',
34 32
         'account_id',
@@ -101,35 +99,21 @@ class Adjustment extends Model
101 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 102
     public function canBePaused(): bool
110 103
     {
111 104
         return $this->status === AdjustmentStatus::Active;
112 105
     }
113 106
 
114
-    /**
115
-     * Check if adjustment can be resumed
116
-     */
117 107
     public function canBeResumed(): bool
118 108
     {
119 109
         return $this->status === AdjustmentStatus::Paused;
120 110
     }
121 111
 
122
-    /**
123
-     * Check if adjustment can be archived
124
-     */
125 112
     public function canBeArchived(): bool
126 113
     {
127 114
         return $this->status !== AdjustmentStatus::Archived;
128 115
     }
129 116
 
130
-    /**
131
-     * Calculate the natural status of the adjustment based on dates
132
-     */
133 117
     public function calculateNaturalStatus(): AdjustmentStatus
134 118
     {
135 119
         if ($this->start_date?->isFuture()) {
@@ -143,58 +127,46 @@ class Adjustment extends Model
143 127
         return AdjustmentStatus::Active;
144 128
     }
145 129
 
146
-    /**
147
-     * Pause the adjustment
148
-     */
149 130
     public function pause(?string $reason = null, ?\DateTime $untilDate = null): bool
150 131
     {
151 132
         if (! $this->canBePaused()) {
152 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 144
     public function resume(): bool
167 145
     {
168 146
         if (! $this->canBeResumed()) {
169 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 158
     public function archive(?string $reason = null): bool
184 159
     {
185 160
         if (! $this->canBeArchived()) {
186 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 170
     public function shouldAutoResume(): bool
199 171
     {
200 172
         return $this->status === AdjustmentStatus::Paused &&
@@ -202,9 +174,6 @@ class Adjustment extends Model
202 174
             $this->paused_until->isPast();
203 175
     }
204 176
 
205
-    /**
206
-     * Refresh the status based on current dates and conditions
207
-     */
208 177
     public function refreshStatus(): bool
209 178
     {
210 179
         // Don't automatically change archived or paused status
@@ -223,9 +192,9 @@ class Adjustment extends Model
223 192
 
224 193
         // Only update if the status would change
225 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 200
         return false;

+ 6
- 6
composer.lock Просмотреть файл

@@ -302,16 +302,16 @@
302 302
         },
303 303
         {
304 304
             "name": "anourvalar/eloquent-serialize",
305
-            "version": "1.3.0",
305
+            "version": "1.3.1",
306 306
             "source": {
307 307
                 "type": "git",
308 308
                 "url": "https://github.com/AnourValar/eloquent-serialize.git",
309
-                "reference": "91188f82c5ec2842a5469fca6d7d64baa37ea593"
309
+                "reference": "060632195821e066de1fc0f869881dd585e2f299"
310 310
             },
311 311
             "dist": {
312 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 315
                 "shasum": ""
316 316
             },
317 317
             "require": {
@@ -362,9 +362,9 @@
362 362
             ],
363 363
             "support": {
364 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 370
             "name": "awcodes/filament-table-repeater",

Загрузка…
Отмена
Сохранить