orders && count($deliveryNote->orders) > 0) { foreach($deliveryNote->orders as $order) { if($order->id_invoice) { return $order->id_invoice; } } } return null; } public function isInvoiced(DeliveryNote $deliveryNote): bool { return (bool) $this->getInvoiceId($deliveryNote); } public function getInvoice(DeliveryNote $deliveryNote): ?Invoice { $idInvoice = (int) $this->getInvoiceId($deliveryNote); return Invoice::searchOne([ 'id' => $idInvoice ]); } }