2025-01-19 12:51:37 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Order;
|
|
|
|
|
|
|
|
class OrderObserver
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle the Order "created" event.
|
|
|
|
*/
|
|
|
|
public function created(Order $order): void
|
|
|
|
{
|
2025-02-14 22:23:51 -05:00
|
|
|
if ($order->invoice != null) {
|
2025-01-19 12:51:37 -05:00
|
|
|
$order->invoice->calculateTotals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Order "updated" event.
|
|
|
|
*/
|
|
|
|
public function updated(Order $order): void
|
|
|
|
{
|
2025-02-14 22:23:51 -05:00
|
|
|
if ($order->invoice != null) {
|
2025-01-19 12:51:37 -05:00
|
|
|
$order->invoice->calculateTotals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Order "saving" event.
|
|
|
|
*/
|
|
|
|
public function saved(Order $order): void
|
|
|
|
{
|
|
|
|
if ($order->isDirty(['invoice_id']) && Invoice::where('id', $order->invoice_id)->exists()) {
|
2025-02-14 22:23:51 -05:00
|
|
|
if ($order->invoice != null) {
|
|
|
|
$order->invoice->calculateTotals();
|
|
|
|
}
|
2025-01-19 12:51:37 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Order "deleted" event.
|
|
|
|
*/
|
|
|
|
public function deleted(Order $order): void
|
|
|
|
{
|
2025-02-14 22:23:51 -05:00
|
|
|
if ($order->invoice != null) {
|
2025-01-19 12:51:37 -05:00
|
|
|
$order->invoice->calculateTotals();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Order "restored" event.
|
|
|
|
*/
|
|
|
|
public function restored(Order $order): void
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Order "force deleted" event.
|
|
|
|
*/
|
|
|
|
public function forceDeleted(Order $order): void
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|