diff --git a/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php index 8dab2d24..1a48fc31 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateProformaInvoiceTransactionProcessor.php @@ -118,14 +118,20 @@ class CreateProformaInvoiceTransactionProcessor $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); + $transaction = $booking->transactions() + ->where('type', TransactionType::PAYMENT) + ->first(); - $object = new TransactionObject($billNumber, TransactionType::PAYMENT, 1, $booking->company->id, - $configurations->getConfigurations()->getBankId(), $configurations->getConversionObject()->getPaymentMethod(), - $configurations->getTotal(), $configurations->getForeignTotal(), 1, - $configurations->getConversionObject()->getCurrencyId(), $configurations->getConfigurations()->getRate(), - $configurations->getTax(), $configurations->getServiceCharge(), Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_SUBMISSION, [], isset($billPlzBill) ? $billPlzBill->id : NULL); + if (!$transaction) { + $object = new TransactionObject($billNumber, TransactionType::PAYMENT, 1, $booking->company->id, + $configurations->getConfigurations()->getBankId(), $configurations->getConversionObject()->getPaymentMethod(), + $configurations->getTotal(), $configurations->getForeignTotal(), 1, + $configurations->getConversionObject()->getCurrencyId(), $configurations->getConfigurations()->getRate(), + $configurations->getTax(), $configurations->getServiceCharge(), Carbon::now()->addMinutes($paymentAttemptLimit), ApprovalStatus::PENDING_SUBMISSION, [], isset($billPlzBill) ? $billPlzBill->id : NULL + ); - $this->createsTransaction->execute($booking, $object); + $this->createsTransaction->execute($booking, $object); + } $billNumber = $this->generatesTransactionBillNumber->execute('PROFORMA-'); @@ -160,6 +166,11 @@ class CreateProformaInvoiceTransactionProcessor ->whereIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::SUSPENDED]) ->sum('tax'); + // delete prev proforma transactions + $booking->transactions() + ->where('type', TransactionType::PROFORMA) + ->delete(); + $transaction_object = new TransactionObject( $billNumber, TransactionType::PROFORMA, @@ -178,11 +189,11 @@ class CreateProformaInvoiceTransactionProcessor ApprovalStatus::APPROVED ); - $perofrma_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); + $proforma_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]); - $purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.proforma_invoice', ['invoice_transaction' => $perofrma_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); + $purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.proforma_invoice', ['invoice_transaction' => $proforma_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); $document_object = new DocumentObject( DocumentType::PROFORMA_INVOICE, [chunk_split('data:application/pdf;base64,'.base64_encode($purchase_order_pdf->output()))], diff --git a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue index 30daf141..f721851d 100644 --- a/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/PurchaseOrderFormComponent.vue @@ -176,7 +176,7 @@ - +