From f99b8b4a1c48cd3cd7ee3a6ecb7bb14f9ad5e745 Mon Sep 17 00:00:00 2001 From: Mohit Panjwani Date: Thu, 2 Dec 2021 14:16:12 +0530 Subject: [PATCH] fix base_due_amount calculation --- app/Models/Invoice.php | 3 ++ ...12_02_063005_calculate_base_due_amount.php | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 database/migrations/2021_12_02_063005_calculate_base_due_amount.php diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 5dec7b61..99eb2849 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -389,6 +389,7 @@ class Invoice extends Model implements HasMedia } $data['due_amount'] = ($this->due_amount + $oldTotal); + $data['base_due_amount'] = $data['due_amount'] * $data['exchange_rate']; $data['customer_sequence_number'] = $serial->nextCustomerSequenceNumber; $this->changeInvoiceStatus($data['due_amount']); @@ -660,6 +661,7 @@ class Invoice extends Model implements HasMedia public function addInvoicePayment($amount) { $this->due_amount += $amount; + $this->base_due_amount = $this->due_amount * $this->exchange_rate; $this->changeInvoiceStatus($this->due_amount); } @@ -667,6 +669,7 @@ class Invoice extends Model implements HasMedia public function subtractInvoicePayment($amount) { $this->due_amount -= $amount; + $this->base_due_amount = $this->due_amount * $this->exchange_rate; $this->changeInvoiceStatus($this->due_amount); } diff --git a/database/migrations/2021_12_02_063005_calculate_base_due_amount.php b/database/migrations/2021_12_02_063005_calculate_base_due_amount.php new file mode 100644 index 00000000..c37ef2f2 --- /dev/null +++ b/database/migrations/2021_12_02_063005_calculate_base_due_amount.php @@ -0,0 +1,34 @@ +exchange_rate) { + $invoice->base_due_amount = $invoice->due_amount * $invoice->exchange_rate; + $invoice->save(); + } + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}