You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EstimateObserver.php 689B

123456789101112131415161718192021222324252627
  1. <?php
  2. namespace App\Observers;
  3. use App\Enums\Accounting\EstimateStatus;
  4. use App\Models\Accounting\DocumentLineItem;
  5. use App\Models\Accounting\Estimate;
  6. use Illuminate\Support\Facades\DB;
  7. class EstimateObserver
  8. {
  9. public function saving(Estimate $estimate): void
  10. {
  11. if ($estimate->approved_at && $estimate->is_currently_expired) {
  12. $estimate->status = EstimateStatus::Expired;
  13. }
  14. }
  15. public function deleted(Estimate $estimate): void
  16. {
  17. DB::transaction(function () use ($estimate) {
  18. $estimate->lineItems()->each(function (DocumentLineItem $lineItem) {
  19. $lineItem->delete();
  20. });
  21. });
  22. }
  23. }