Andrew Wallo 9 个月前
父节点
当前提交
3232187ee3

+ 2
- 2
app/Filament/Company/Resources/Purchases/BillResource.php 查看文件

@@ -426,9 +426,9 @@ class BillResource extends Resource
426 426
                         ->failureNotificationTitle('Failed to Record Payments')
427 427
                         ->deselectRecordsAfterCompletion()
428 428
                         ->beforeFormFilled(function (Collection $records, Tables\Actions\BulkAction $action) {
429
-                            $cantRecordPayments = $records->contains(fn (Bill $bill) => ! $bill->canRecordPayment());
429
+                            $isInvalid = $records->contains(fn (Bill $bill) => ! $bill->canRecordPayment());
430 430
 
431
-                            if ($cantRecordPayments) {
431
+                            if ($isInvalid) {
432 432
                                 Notification::make()
433 433
                                     ->title('Payment Recording Failed')
434 434
                                     ->body('Bills that are either paid, voided, or are in a foreign currency cannot be processed through bulk payments. Please adjust your selection and try again.')

+ 10
- 11
app/Filament/Company/Resources/Sales/EstimateResource.php 查看文件

@@ -362,6 +362,7 @@ class EstimateResource extends Resource
362 362
                             'expiration_date',
363 363
                             'approved_at',
364 364
                             'accepted_at',
365
+                            'converted_at',
365 366
                             'declined_at',
366 367
                             'last_sent_at',
367 368
                             'last_viewed_at',
@@ -393,9 +394,9 @@ class EstimateResource extends Resource
393 394
                         ->successNotificationTitle('Estimates Approved')
394 395
                         ->failureNotificationTitle('Failed to Approve Estimates')
395 396
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
396
-                            $containsNonDrafts = $records->contains(fn (Estimate $record) => ! $record->isDraft());
397
+                            $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeApproved());
397 398
 
398
-                            if ($containsNonDrafts) {
399
+                            if ($isInvalid) {
399 400
                                 Notification::make()
400 401
                                     ->title('Approval Failed')
401 402
                                     ->body('Only draft estimates can be approved. Please adjust your selection and try again.')
@@ -420,9 +421,9 @@ class EstimateResource extends Resource
420 421
                         ->successNotificationTitle('Estimates Sent')
421 422
                         ->failureNotificationTitle('Failed to Mark Estimates as Sent')
422 423
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
423
-                            $doesntContainUnsent = $records->contains(fn (Estimate $record) => $record->status !== EstimateStatus::Unsent);
424
+                            $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsSent());
424 425
 
425
-                            if ($doesntContainUnsent) {
426
+                            if ($isInvalid) {
426 427
                                 Notification::make()
427 428
                                     ->title('Sending Failed')
428 429
                                     ->body('Only unsent estimates can be marked as sent. Please adjust your selection and try again.')
@@ -435,9 +436,7 @@ class EstimateResource extends Resource
435 436
                         })
436 437
                         ->action(function (Collection $records, Tables\Actions\BulkAction $action) {
437 438
                             $records->each(function (Estimate $record) {
438
-                                $record->updateQuietly([
439
-                                    'status' => EstimateStatus::Sent,
440
-                                ]);
439
+                                $record->markAsSent();
441 440
                             });
442 441
 
443 442
                             $action->success();
@@ -449,9 +448,9 @@ class EstimateResource extends Resource
449 448
                         ->successNotificationTitle('Estimates Accepted')
450 449
                         ->failureNotificationTitle('Failed to Mark Estimates as Accepted')
451 450
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
452
-                            $doesntContainSent = $records->contains(fn (Estimate $record) => $record->status !== EstimateStatus::Sent || $record->wasAccepted());
451
+                            $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsAccepted());
453 452
 
454
-                            if ($doesntContainSent) {
453
+                            if ($isInvalid) {
455 454
                                 Notification::make()
456 455
                                     ->title('Acceptance Failed')
457 456
                                     ->body('Only sent estimates that haven\'t been accepted can be marked as accepted. Please adjust your selection and try again.')
@@ -480,9 +479,9 @@ class EstimateResource extends Resource
480 479
                         ->successNotificationTitle('Estimates Declined')
481 480
                         ->failureNotificationTitle('Failed to Mark Estimates as Declined')
482 481
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
483
-                            $doesntContainSent = $records->contains(fn (Estimate $record) => $record->status !== EstimateStatus::Sent || $record->wasDeclined());
482
+                            $isInvalid = $records->contains(fn (Estimate $record) => ! $record->canBeMarkedAsDeclined());
484 483
 
485
-                            if ($doesntContainSent) {
484
+                            if ($isInvalid) {
486 485
                                 Notification::make()
487 486
                                     ->title('Declination Failed')
488 487
                                     ->body('Only sent estimates that haven\'t been declined can be marked as declined. Please adjust your selection and try again.')

+ 10
- 6
app/Filament/Company/Resources/Sales/InvoiceResource.php 查看文件

@@ -468,6 +468,10 @@ class InvoiceResource extends Resource
468 468
                             'invoice_number',
469 469
                             'date',
470 470
                             'due_date',
471
+                            'approved_at',
472
+                            'paid_at',
473
+                            'last_sent_at',
474
+                            'last_viewed_at',
471 475
                         ])
472 476
                         ->beforeReplicaSaved(function (Invoice $replica) {
473 477
                             $replica->status = InvoiceStatus::Draft;
@@ -491,9 +495,9 @@ class InvoiceResource extends Resource
491 495
                         ->successNotificationTitle('Invoices Approved')
492 496
                         ->failureNotificationTitle('Failed to Approve Invoices')
493 497
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
494
-                            $containsNonDrafts = $records->contains(fn (Invoice $record) => ! $record->isDraft());
498
+                            $isInvalid = $records->contains(fn (Invoice $record) => ! $record->canBeApproved());
495 499
 
496
-                            if ($containsNonDrafts) {
500
+                            if ($isInvalid) {
497 501
                                 Notification::make()
498 502
                                     ->title('Approval Failed')
499 503
                                     ->body('Only draft invoices can be approved. Please adjust your selection and try again.')
@@ -518,9 +522,9 @@ class InvoiceResource extends Resource
518 522
                         ->successNotificationTitle('Invoices Sent')
519 523
                         ->failureNotificationTitle('Failed to Mark Invoices as Sent')
520 524
                         ->before(function (Collection $records, Tables\Actions\BulkAction $action) {
521
-                            $doesntContainUnsent = $records->contains(fn (Invoice $record) => $record->status !== InvoiceStatus::Unsent);
525
+                            $isInvalid = $records->contains(fn (Invoice $record) => ! $record->canBeMarkedAsSent());
522 526
 
523
-                            if ($doesntContainUnsent) {
527
+                            if ($isInvalid) {
524 528
                                 Notification::make()
525 529
                                     ->title('Sending Failed')
526 530
                                     ->body('Only unsent invoices can be marked as sent. Please adjust your selection and try again.')
@@ -550,9 +554,9 @@ class InvoiceResource extends Resource
550 554
                         ->failureNotificationTitle('Failed to Record Payments')
551 555
                         ->deselectRecordsAfterCompletion()
552 556
                         ->beforeFormFilled(function (Collection $records, Tables\Actions\BulkAction $action) {
553
-                            $cantRecordPayments = $records->contains(fn (Invoice $record) => ! $record->canBulkRecordPayment());
557
+                            $isInvalid = $records->contains(fn (Invoice $record) => ! $record->canBulkRecordPayment());
554 558
 
555
-                            if ($cantRecordPayments) {
559
+                            if ($isInvalid) {
556 560
                                 Notification::make()
557 561
                                     ->title('Payment Recording Failed')
558 562
                                     ->body('Invoices that are either draft, paid, overpaid, voided, or are in a foreign currency cannot be processed through bulk payments. Please adjust your selection and try again.')

+ 23
- 19
app/Models/Accounting/Bill.php 查看文件

@@ -394,28 +394,32 @@ class Bill extends Model
394 394
             })
395 395
             ->databaseTransaction()
396 396
             ->after(function (self $original, self $replica) {
397
-                $original->lineItems->each(function (DocumentLineItem $lineItem) use ($replica) {
398
-                    $replicaLineItem = $lineItem->replicate([
399
-                        'documentable_id',
400
-                        'documentable_type',
401
-                        'subtotal',
402
-                        'total',
403
-                        'created_by',
404
-                        'updated_by',
405
-                        'created_at',
406
-                        'updated_at',
407
-                    ]);
408
-
409
-                    $replicaLineItem->documentable_id = $replica->id;
410
-                    $replicaLineItem->documentable_type = $replica->getMorphClass();
411
-
412
-                    $replicaLineItem->save();
413
-
414
-                    $replicaLineItem->adjustments()->sync($lineItem->adjustments->pluck('id'));
415
-                });
397
+                $original->replicateLineItems($replica);
416 398
             })
417 399
             ->successRedirectUrl(static function (self $replica) {
418 400
                 return BillResource::getUrl('edit', ['record' => $replica]);
419 401
             });
420 402
     }
403
+
404
+    public function replicateLineItems(Model $target): void
405
+    {
406
+        $this->lineItems->each(function (DocumentLineItem $lineItem) use ($target) {
407
+            $replica = $lineItem->replicate([
408
+                'documentable_id',
409
+                'documentable_type',
410
+                'subtotal',
411
+                'total',
412
+                'created_by',
413
+                'updated_by',
414
+                'created_at',
415
+                'updated_at',
416
+            ]);
417
+
418
+            $replica->documentable_id = $target->id;
419
+            $replica->documentable_type = $target->getMorphClass();
420
+            $replica->save();
421
+
422
+            $replica->adjustments()->sync($lineItem->adjustments->pluck('id'));
423
+        });
424
+    }
421 425
 }

+ 9
- 2
app/Models/Accounting/Estimate.php 查看文件

@@ -171,7 +171,10 @@ class Estimate extends Model
171 171
 
172 172
     public function canBeMarkedAsDeclined(): bool
173 173
     {
174
-        return $this->hasBeenSent() && ! $this->wasDeclined();
174
+        return $this->hasBeenSent()
175
+            && ! $this->wasDeclined()
176
+            && ! $this->wasConverted()
177
+            && ! $this->wasAccepted();
175 178
     }
176 179
 
177 180
     public function canBeMarkedAsSent(): bool
@@ -181,7 +184,10 @@ class Estimate extends Model
181 184
 
182 185
     public function canBeMarkedAsAccepted(): bool
183 186
     {
184
-        return $this->hasBeenSent() && ! $this->wasAccepted();
187
+        return $this->hasBeenSent()
188
+            && ! $this->wasAccepted()
189
+            && ! $this->wasDeclined()
190
+            && ! $this->wasConverted();
185 191
     }
186 192
 
187 193
     public function hasLineItems(): bool
@@ -308,6 +314,7 @@ class Estimate extends Model
308 314
                 'expiration_date',
309 315
                 'approved_at',
310 316
                 'accepted_at',
317
+                'converted_at',
311 318
                 'declined_at',
312 319
                 'last_sent_at',
313 320
                 'last_viewed_at',

+ 1
- 0
app/Models/Accounting/Invoice.php 查看文件

@@ -499,6 +499,7 @@ class Invoice extends Model
499 499
                 'approved_at',
500 500
                 'paid_at',
501 501
                 'last_sent_at',
502
+                'last_viewed_at',
502 503
             ])
503 504
             ->modal(false)
504 505
             ->beforeReplicaSaved(function (self $original, self $replica) {

正在加载...
取消
保存