document payment update errors fixed

This commit is contained in:
Cihan Şentürk
2022-07-03 14:59:17 +03:00
parent 87347f0df4
commit 14cd394563
3 changed files with 17 additions and 19 deletions

View File

@ -12,6 +12,7 @@ use App\Models\Setting\Currency;
use App\Utilities\Modules;
use App\Traits\Uploads;
use App\Traits\Transactions;
use Date;
class DocumentTransactions extends Controller
@ -58,6 +59,8 @@ class DocumentTransactions extends Controller
$document->grand_total = round($document->total - $paid, $currency->precision);
}
$document->paid_at = Date::now()->toDateString();
$buttons = [
'cancel' => [
'text' => trans('general.cancel'),
@ -79,9 +82,11 @@ class DocumentTransactions extends Controller
],
];
$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,
@ -139,20 +144,11 @@ class DocumentTransactions extends Controller
$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' => [
@ -170,9 +166,11 @@ class DocumentTransactions extends Controller
],
];
$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,

View File

@ -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;
@ -21,7 +21,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
$this->model = $model;
$this->transaction = $transaction;
parent::__construct($request);
$this->request = $this->getRequestInstance($request);
}
public function handle(): Transaction
@ -31,7 +31,7 @@ class UpdateBankingDocumentTransaction extends Job implements ShouldUpdate
$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')) {