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; } }