fetchesBooking = $fetchesBooking; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor; } /** * @param int $bookingId * @return void * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\JobResourceNotFoundException */ public function execute(int $bookingId) { $booking = $this->fetchesBooking->execute(['id' => $bookingId]); $purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->where('id', '!=', $purchaseOrder->id)->delete(); $this->updatesTransactionStatus->execute($purchaseOrder, ApprovalStatus::APPROVED); $this->createInvoiceTransactionProcessor->execute($booking); } }