fixed invoice/bill payment
This commit is contained in:
@ -45,7 +45,7 @@ class BillTransactions extends Controller
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
$paid = $this->getPaidAmount($bill);
|
||||
$paid = $bill->paid;
|
||||
|
||||
// Get Bill Totals
|
||||
foreach ($bill->totals as $bill_total) {
|
||||
@ -96,44 +96,4 @@ class BillTransactions extends Controller
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
protected function getPaidAmount($bill)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
// Get Bill Transactions
|
||||
if (!$bill->transactions->count()) {
|
||||
return $paid;
|
||||
}
|
||||
|
||||
$currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
foreach ($bill->transactions as $item) {
|
||||
$default_amount = (double) $item->amount;
|
||||
|
||||
if ($bill->currency_code == $item->currency_code) {
|
||||
$amount = $default_amount;
|
||||
} else {
|
||||
$default_amount_model = new Transaction();
|
||||
$default_amount_model->default_currency_code = $bill->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $item->currency_code;
|
||||
$default_amount_model->currency_rate = $currencies[$item->currency_code];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
|
||||
$convert_amount_model = new Transaction();
|
||||
$convert_amount_model->default_currency_code = $item->currency_code;
|
||||
$convert_amount_model->amount = $default_amount;
|
||||
$convert_amount_model->currency_code = $bill->currency_code;
|
||||
$convert_amount_model->currency_rate = $currencies[$bill->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount_model->getAmountConvertedFromCustomDefault();
|
||||
}
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
|
||||
return $paid;
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@
|
||||
namespace App\Http\Controllers\Modals;
|
||||
|
||||
use App\Abstracts\Http\Controller;
|
||||
use App\Events\Sale\PaymentReceived;
|
||||
use App\Http\Requests\Banking\Transaction as Request;
|
||||
use App\Jobs\Banking\CreateDocumentTransaction;
|
||||
use App\Models\Banking\Account;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Sale\Invoice;
|
||||
@ -45,7 +45,7 @@ class InvoiceTransactions extends Controller
|
||||
|
||||
$payment_methods = Modules::getPaymentMethods();
|
||||
|
||||
$paid = $this->getPaidAmount($invoice);
|
||||
$paid = $invoice->paid;
|
||||
|
||||
// Get Invoice Totals
|
||||
foreach ($invoice->totals as $invoice_total) {
|
||||
@ -83,7 +83,7 @@ class InvoiceTransactions extends Controller
|
||||
*/
|
||||
public function store(Invoice $invoice, Request $request)
|
||||
{
|
||||
$response = $this->ajaxDispatch(new PaymentReceived($invoice, $request));
|
||||
$response = $this->ajaxDispatch(new CreateDocumentTransaction($invoice, $request));
|
||||
|
||||
if ($response['success']) {
|
||||
$response['redirect'] = route('invoices.show', $invoice->id);
|
||||
@ -97,44 +97,4 @@ class InvoiceTransactions extends Controller
|
||||
|
||||
return response()->json($response);
|
||||
}
|
||||
|
||||
protected function getPaidAmount($invoice)
|
||||
{
|
||||
$paid = 0;
|
||||
|
||||
// Get invoice transactions
|
||||
if (!$invoice->transactions->count()) {
|
||||
return $paid;
|
||||
}
|
||||
|
||||
$_currencies = Currency::enabled()->pluck('rate', 'code')->toArray();
|
||||
|
||||
foreach ($invoice->transactions as $item) {
|
||||
$default_amount = $item->amount;
|
||||
|
||||
if ($invoice->currency_code == $item->currency_code) {
|
||||
$amount = (double) $default_amount;
|
||||
} else {
|
||||
$default_amount_model = new Transaction();
|
||||
$default_amount_model->default_currency_code = $invoice->currency_code;
|
||||
$default_amount_model->amount = $default_amount;
|
||||
$default_amount_model->currency_code = $item->currency_code;
|
||||
$default_amount_model->currency_rate = $_currencies[$item->currency_code];
|
||||
|
||||
$default_amount = (double) $default_amount_model->getDivideConvertedAmount();
|
||||
|
||||
$convert_amount_model = new Transaction();
|
||||
$convert_amount_model->default_currency_code = $item->currency_code;
|
||||
$convert_amount_model->amount = $default_amount;
|
||||
$convert_amount_model->currency_code = $invoice->currency_code;
|
||||
$convert_amount_model->currency_rate = $_currencies[$invoice->currency_code];
|
||||
|
||||
$amount = (double) $convert_amount_model->getAmountConvertedFromCustomDefault();
|
||||
}
|
||||
|
||||
$paid += $amount;
|
||||
}
|
||||
|
||||
return $paid;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user