Skip to content

Commit

Permalink
close #2186 Fixed: Invoice/Bill mark paid currency code issue. #nqbpdm
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jul 11, 2021
1 parent fc57b3b commit 552ad0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Sales/Invoices.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function pdfInvoice(Document $invoice)
public function markPaid(Document $invoice)
{
try {
event(new \App\Events\Document\PaymentReceived($invoice, ['type' => 'income']));
event(new \App\Events\Document\PaymentReceived($invoice, ['type' => 'income', 'mark_paid' => 'invoice']));

$message = trans('documents.messages.marked_paid', ['type' => trans_choice('general.invoices', 1)]);

Expand Down
16 changes: 16 additions & 0 deletions app/Jobs/Banking/CreateBankingDocumentTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Jobs\Banking\CreateTransaction;
use App\Jobs\Document\CreateDocumentHistory;
use App\Events\Document\PaidAmountCalculated;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Traits\Currencies;
use App\Utilities\Date;
Expand Down Expand Up @@ -83,12 +84,27 @@ protected function prepareRequest()
$this->request['category_id'] = isset($this->request['category_id']) ? $this->request['category_id'] : $this->model->category_id;
$this->request['payment_method'] = isset($this->request['payment_method']) ? $this->request['payment_method'] : setting('default.payment_method');
$this->request['notify'] = isset($this->request['notify']) ? $this->request['notify'] : 0;

if ($this->request['mark_paid'] || $this->request['account_id'] == setting('default.account')) {
$account = Account::find((int) $this->request['account_id']);

$code = $account->currency_code;
$rate = config('money.' . $account->currency_code . '.rate');

if ($account->currency_code != $this->model->currency_code) {
$this->request['currency_code'] = $code;
$this->request['currency_rate'] = $rate;

$this->request['amount'] = $this->convertBetween($this->request['amount'], $this->model->currency_code, $this->model->currency_rate, $code, $rate);
}
}
}

protected function checkAmount()
{
$code = $this->request['currency_code'];
$rate = $this->request['currency_rate'];

$precision = config('money.' . $code . '.precision');

$amount = $this->request['amount'] = round($this->request['amount'], $precision);
Expand Down

0 comments on commit 552ad0e

Please sign in to comment.