23 lines
496 B
PHP
23 lines
496 B
PHP
<?php
|
|
|
|
namespace App\Services\PurchaseOrders;
|
|
|
|
use App\Models\PurchaseOrder;
|
|
use RuntimeException;
|
|
|
|
class PurchaseOrderStatusService
|
|
{
|
|
public function cancel(int $poId): PurchaseOrder
|
|
{
|
|
$po = PurchaseOrder::query()->find($poId);
|
|
if (!$po || $po->status === PurchaseOrder::STATUS_RECEIVED) {
|
|
throw new RuntimeException('Cannot cancel this PO.');
|
|
}
|
|
|
|
$po->status = PurchaseOrder::STATUS_CANCELED;
|
|
$po->save();
|
|
|
|
return $po;
|
|
}
|
|
}
|