Skip to content

Commit

Permalink
document payment update errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Jul 3, 2022
1 parent 87347f0 commit 14cd394
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
26 changes: 12 additions & 14 deletions app/Http/Controllers/Modals/DocumentTransactions.php
Expand Up @@ -12,6 +12,7 @@
use App\Utilities\Modules;
use App\Traits\Uploads;
use App\Traits\Transactions;
use Date;


class DocumentTransactions extends Controller
Expand Down Expand Up @@ -58,6 +59,8 @@ public function create(Document $document)
$document->grand_total = round($document->total - $paid, $currency->precision);
}

$document->paid_at = Date::now()->toDateString();

$buttons = [
'cancel' => [
'text' => trans('general.cancel'),
Expand All @@ -79,9 +82,11 @@ public function create(Document $document)
],
];

$method = 'POST';

$route = ['modals.documents.document.transactions.store', $document->id];

$html = view('modals.documents.payment', compact('document', 'route', 'currency', 'number'))->render();
$html = view('modals.documents.payment', compact('document', 'method', 'route', 'currency', 'number'))->render();

return response()->json([
'success' => true,
Expand Down Expand Up @@ -139,20 +144,11 @@ public function edit(Document $document, Transaction $transaction)

$paid = $document->paid;

$number = $this->getNextTransactionNumber();
$number = $transaction->number;

// Get document Totals
foreach ($document->totals as $document_total) {
$document->{$document_total->code} = $document_total->amount;
}
$document->grand_total = money($transaction->amount, $currency->code)->getAmount();

$total = money($document->total, $currency->code, true)->format();

$document->grand_total = money($total, $currency->code)->getAmount();

if (! empty($paid)) {
$document->grand_total = round($document->total - $paid, $currency->precision);
}
$document->paid_at = $transaction->paid_at;

$buttons = [
'cancel' => [
Expand All @@ -170,9 +166,11 @@ public function edit(Document $document, Transaction $transaction)
],
];

$method = 'PATCH';

$route = ['modals.documents.document.transactions.update', $document->id, $transaction->id];

$html = view('modals.documents.payment', compact('document', 'transaction', 'route', 'currency', 'number'))->render();
$html = view('modals.documents.payment', compact('document', 'transaction', 'method', 'route', 'currency', 'number'))->render();

return response()->json([
'success' => true,
Expand Down
6 changes: 3 additions & 3 deletions app/Jobs/Banking/UpdateBankingDocumentTransaction.php
Expand Up @@ -3,7 +3,7 @@
namespace App\Jobs\Banking;

use App\Abstracts\Job;
use App\Jobs\Banking\CreateTransaction;
use App\Jobs\Banking\UpdateTransaction;
use App\Jobs\Document\CreateDocumentHistory;
use App\Events\Document\PaidAmountCalculated;
use App\Interfaces\Job\ShouldUpdate;
Expand All @@ -21,7 +21,7 @@ public function __construct(Document $model, Transaction $transaction, $request)
$this->model = $model;
$this->transaction = $transaction;

parent::__construct($request);
$this->request = $this->getRequestInstance($request);
}

public function handle(): Transaction
Expand All @@ -31,7 +31,7 @@ public function handle(): Transaction
$this->checkAmount();

\DB::transaction(function () {
$this->transaction = $this->dispatch(new CreateTransaction($this->request));
$this->transaction = $this->dispatch(new UpdateTransaction($this->transaction, $this->request));

// Upload attachment
if ($this->request->file('attachment')) {
Expand Down
4 changes: 2 additions & 2 deletions resources/views/modals/documents/payment.blade.php
@@ -1,4 +1,4 @@
<x-form id="form-transaction" :route="$route" :model="!empty($transaction) ? $transaction : false">
<x-form id="form-transaction" :method="$method" :route="$route" :model="!empty($transaction) ? $transaction : false">
<div class="rounded-xl px-5 py-3 mb-5 bg-red-100" v-if="typeof form.response !== 'undefined' && form.response.error">
<p class="text-sm mb-0 text-red-600" v-html="form.response.message"></p>
</div>
Expand Down Expand Up @@ -40,7 +40,7 @@

<div id="tab-general" data-tabs-content="general" x-show="active === 'general'">
<div class="grid sm:grid-cols-6 gap-x-8 gap-y-6 my-3.5">
<x-form.group.date name="paid_at" label="{{ trans('general.date') }}" icon="calendar_today" value="{{ Date::now()->toDateString() }}" show-date-format="{{ company_date_format() }}" date-format="Y-m-d" autocomplete="off" form-group-class="col-span-6" />
<x-form.group.date name="paid_at" label="{{ trans('general.date') }}" icon="calendar_today" value="{{ $document->paid_at }}" show-date-format="{{ company_date_format() }}" date-format="Y-m-d" autocomplete="off" form-group-class="col-span-6" />

<x-form.group.money name="amount" label="{{ trans('general.amount') }}" value="{{ $document->grand_total }}" autofocus="autofocus" :currency="$currency" dynamicCurrency="currency" form-group-class="col-span-6" />

Expand Down

0 comments on commit 14cd394

Please sign in to comment.