Merge pull request #461 from batuhawk/master

refs #451 invoice and bill currency issue some fix
This commit is contained in:
Cüneyt Şentürk 2018-08-29 19:51:02 +03:00 committed by GitHub
commit 4fe94cf1a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 45 deletions

View File

@ -280,8 +280,8 @@ class Items extends Controller
$item_tax_price = ($item->sale_price / 100) * $tax->rate; $item_tax_price = ($item->sale_price / 100) * $tax->rate;
} }
$item->sale_price = $this->convertPrice($item->sale_price, $currency_code, $currency->rate); //$item->sale_price = $this->convertPrice($item->sale_price, $currency_code, $currency->rate);
$item->purchase_price = $this->convertPrice($item->purchase_price, $currency_code, $currency->rate); //$item->purchase_price = $this->convertPrice($item->purchase_price, $currency_code, $currency->rate);
switch ($type) { switch ($type) {
case 'bill': case 'bill':

View File

@ -76,7 +76,9 @@ class Invoices extends Controller
foreach ($invoice->payments as $item) { foreach ($invoice->payments as $item) {
$default_amount = $item->amount; $default_amount = $item->amount;
if ($invoice->currency_code != $item->currency_code) { if ($invoice->currency_code == $item->currency_code) {
$amount = (double)$default_amount;
} else {
$default_amount_model = new InvoicePayment(); $default_amount_model = new InvoicePayment();
$default_amount_model->default_currency_code = $invoice->currency_code; $default_amount_model->default_currency_code = $invoice->currency_code;
@ -85,7 +87,6 @@ class Invoices extends Controller
$default_amount_model->currency_rate = $_currencies[$item->currency_code]; $default_amount_model->currency_rate = $_currencies[$item->currency_code];
$default_amount = (double) $default_amount_model->getDivideConvertedAmount(); $default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}
$convert_amount = new InvoicePayment(); $convert_amount = new InvoicePayment();
@ -95,6 +96,7 @@ class Invoices extends Controller
$convert_amount->currency_rate = $_currencies[$invoice->currency_code]; $convert_amount->currency_rate = $_currencies[$invoice->currency_code];
$amount = (double) $convert_amount->getDynamicConvertedAmount(); $amount = (double) $convert_amount->getDynamicConvertedAmount();
}
$paid += $amount; $paid += $amount;
} }

View File

@ -39,13 +39,13 @@ class InvoicePayments extends Controller
$currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray(); $currencies = Currency::enabled()->orderBy('name')->pluck('name', 'code')->toArray();
$currency = Currency::where('code', setting('general.default_currency'))->first();
$account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first(); $account_currency_code = Account::where('id', setting('general.default_account'))->pluck('currency_code')->first();
$currency = Currency::where('code', $account_currency_code)->first();
$payment_methods = Modules::getPaymentMethods(); $payment_methods = Modules::getPaymentMethods();
$invoice->paid = $this->getPaid($invoice); $paid = $this->getPaid($invoice);
// Get Invoice Totals // Get Invoice Totals
foreach ($invoice->totals as $invoice_total) { foreach ($invoice->totals as $invoice_total) {
@ -88,7 +88,9 @@ class InvoicePayments extends Controller
$default_amount = (double) $request['amount']; $default_amount = (double) $request['amount'];
if ($invoice->currency_code != $request['currency_code']) { if ($invoice->currency_code == $request['currency_code']) {
$amount = $default_amount;
} else {
$default_amount_model = new InvoicePayment(); $default_amount_model = new InvoicePayment();
$default_amount_model->default_currency_code = $invoice->currency_code; $default_amount_model->default_currency_code = $invoice->currency_code;
@ -97,7 +99,6 @@ class InvoicePayments extends Controller
$default_amount_model->currency_rate = $currencies[$request['currency_code']]; $default_amount_model->currency_rate = $currencies[$request['currency_code']];
$default_amount = (double) $default_amount_model->getDivideConvertedAmount(); $default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}
$convert_amount = new InvoicePayment(); $convert_amount = new InvoicePayment();
@ -107,6 +108,7 @@ class InvoicePayments extends Controller
$convert_amount->currency_rate = $currencies[$invoice->currency_code]; $convert_amount->currency_rate = $currencies[$invoice->currency_code];
$amount = (double) $convert_amount->getDynamicConvertedAmount(); $amount = (double) $convert_amount->getDynamicConvertedAmount();
}
if ($invoice->payments()->count()) { if ($invoice->payments()->count()) {
$total_amount -= $this->getPaid($invoice); $total_amount -= $this->getPaid($invoice);
@ -134,7 +136,6 @@ class InvoicePayments extends Controller
$error_amount_model->currency_rate = $currencies[$invoice->currency_code]; $error_amount_model->currency_rate = $currencies[$invoice->currency_code];
$error_amount = (double) $error_amount_model->getDivideConvertedAmount(); $error_amount = (double) $error_amount_model->getDivideConvertedAmount();
}
$convert_amount = new InvoicePayment(); $convert_amount = new InvoicePayment();
@ -144,6 +145,7 @@ class InvoicePayments extends Controller
$convert_amount->currency_rate = $currencies[$request['currency_code']]; $convert_amount->currency_rate = $currencies[$request['currency_code']];
$error_amount = (double) $convert_amount->getDynamicConvertedAmount(); $error_amount = (double) $convert_amount->getDynamicConvertedAmount();
}
$message = trans('messages.error.over_payment', ['amount' => money($error_amount, $request['currency_code'],true)]); $message = trans('messages.error.over_payment', ['amount' => money($error_amount, $request['currency_code'],true)]);
@ -217,7 +219,9 @@ class InvoicePayments extends Controller
foreach ($invoice->payments as $item) { foreach ($invoice->payments as $item) {
$default_amount = $item->amount; $default_amount = $item->amount;
if ($invoice->currency_code != $item->currency_code) { if ($invoice->currency_code == $item->currency_code) {
$amount = (double) $default_amount;
} else {
$default_amount_model = new InvoicePayment(); $default_amount_model = new InvoicePayment();
$default_amount_model->default_currency_code = $invoice->currency_code; $default_amount_model->default_currency_code = $invoice->currency_code;
@ -226,7 +230,6 @@ class InvoicePayments extends Controller
$default_amount_model->currency_rate = $_currencies[$item->currency_code]; $default_amount_model->currency_rate = $_currencies[$item->currency_code];
$default_amount = (double) $default_amount_model->getDivideConvertedAmount(); $default_amount = (double) $default_amount_model->getDivideConvertedAmount();
}
$convert_amount = new InvoicePayment(); $convert_amount = new InvoicePayment();
@ -236,6 +239,7 @@ class InvoicePayments extends Controller
$convert_amount->currency_rate = $_currencies[$invoice->currency_code]; $convert_amount->currency_rate = $_currencies[$invoice->currency_code];
$amount = (double) $convert_amount->getDynamicConvertedAmount(); $amount = (double) $convert_amount->getDynamicConvertedAmount();
}
$paid += $amount; $paid += $amount;
} }

View File

@ -373,6 +373,11 @@
$('#currency_rate').val(data.currency_rate); $('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){ $('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
amount = $(this).maskMoney('unmasked')[0]; amount = $(this).maskMoney('unmasked')[0];
$(this).maskMoney({ $(this).maskMoney({

View File

@ -381,6 +381,11 @@
$('#currency_rate').val(data.currency_rate); $('#currency_rate').val(data.currency_rate);
$('.input-price').each(function(){ $('.input-price').each(function(){
input_price_id = $(this).attr('id');
input_currency_id = input_price_id.replace('price', 'currency');
$('#' + input_currency_id).val(data.currency_code);
amount = $(this).maskMoney('unmasked')[0]; amount = $(this).maskMoney('unmasked')[0];
$(this).maskMoney({ $(this).maskMoney({