mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Fix tax per item issue & check currency key
This commit is contained in:
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use Crater\Models\InvoiceItem;
|
||||
use Crater\Models\Tax;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CalculateBaseValuesForInvoiceItems extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$taxes = Tax::whereRelation('invoiceItem', 'base_amount', null)->get();
|
||||
|
||||
if ($taxes) {
|
||||
$taxes->map(function ($tax) {
|
||||
$invoiceItem = InvoiceItem::find($tax->invoice_item_id);
|
||||
$exchange_rate = $invoiceItem->exchange_rate;
|
||||
$tax->exchange_rate = $exchange_rate;
|
||||
$tax->base_amount = $tax->amount * $exchange_rate;
|
||||
$tax->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user