mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
fix base_due_amount calculation
This commit is contained in:
@ -389,6 +389,7 @@ class Invoice extends Model implements HasMedia
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['due_amount'] = ($this->due_amount + $oldTotal);
|
$data['due_amount'] = ($this->due_amount + $oldTotal);
|
||||||
|
$data['base_due_amount'] = $data['due_amount'] * $data['exchange_rate'];
|
||||||
$data['customer_sequence_number'] = $serial->nextCustomerSequenceNumber;
|
$data['customer_sequence_number'] = $serial->nextCustomerSequenceNumber;
|
||||||
|
|
||||||
$this->changeInvoiceStatus($data['due_amount']);
|
$this->changeInvoiceStatus($data['due_amount']);
|
||||||
@ -660,6 +661,7 @@ class Invoice extends Model implements HasMedia
|
|||||||
public function addInvoicePayment($amount)
|
public function addInvoicePayment($amount)
|
||||||
{
|
{
|
||||||
$this->due_amount += $amount;
|
$this->due_amount += $amount;
|
||||||
|
$this->base_due_amount = $this->due_amount * $this->exchange_rate;
|
||||||
|
|
||||||
$this->changeInvoiceStatus($this->due_amount);
|
$this->changeInvoiceStatus($this->due_amount);
|
||||||
}
|
}
|
||||||
@ -667,6 +669,7 @@ class Invoice extends Model implements HasMedia
|
|||||||
public function subtractInvoicePayment($amount)
|
public function subtractInvoicePayment($amount)
|
||||||
{
|
{
|
||||||
$this->due_amount -= $amount;
|
$this->due_amount -= $amount;
|
||||||
|
$this->base_due_amount = $this->due_amount * $this->exchange_rate;
|
||||||
|
|
||||||
$this->changeInvoiceStatus($this->due_amount);
|
$this->changeInvoiceStatus($this->due_amount);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Crater\Models\Invoice;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CalculateBaseDueAmount extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$invoices = Invoice::all();
|
||||||
|
|
||||||
|
foreach ($invoices as $invoice) {
|
||||||
|
if ($invoice->exchange_rate) {
|
||||||
|
$invoice->base_due_amount = $invoice->due_amount * $invoice->exchange_rate;
|
||||||
|
$invoice->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user