improved document events
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Abstracts\Job;
|
||||
use App\Jobs\Banking\CreateTransaction;
|
||||
use App\Jobs\Purchase\CreateBillHistory;
|
||||
use App\Jobs\Sale\CreateInvoiceHistory;
|
||||
use App\Events\Document\PaidAmountCalculated;
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Sale\Invoice;
|
||||
use App\Traits\Currencies;
|
||||
@@ -64,11 +65,17 @@ class CreateDocumentTransaction extends Job
|
||||
|
||||
protected function prepareRequest()
|
||||
{
|
||||
if (!isset($this->request['amount'])) {
|
||||
$this->model->paid_amount = $this->model->paid;
|
||||
event(new PaidAmountCalculated($this->model));
|
||||
|
||||
$this->request['amount'] = $this->model->amount - $this->model->paid_amount;
|
||||
}
|
||||
|
||||
$this->request['company_id'] = session('company_id');
|
||||
$this->request['currency_code'] = isset($this->request['currency_code']) ? $this->request['currency_code'] : $this->model->currency_code;
|
||||
$this->request['type'] = ($this->model instanceof Invoice) ? 'income' : 'expense';
|
||||
$this->request['paid_at'] = isset($this->request['paid_at']) ? $this->request['paid_at'] : Date::now()->format('Y-m-d');
|
||||
$this->request['amount'] = isset($this->request['amount']) ? $this->request['amount'] : ($this->model->amount - $this->model->paid);
|
||||
$this->request['currency_rate'] = config('money.' . $this->request['currency_code'] . '.rate');
|
||||
$this->request['account_id'] = isset($this->request['account_id']) ? $this->request['account_id'] : setting('default.account');
|
||||
$this->request['document_id'] = isset($this->request['document_id']) ? $this->request['document_id'] : $this->model->id;
|
||||
@@ -92,8 +99,13 @@ class CreateDocumentTransaction extends Job
|
||||
$amount = round($converted_amount, $precision);
|
||||
}
|
||||
|
||||
$total_amount = round($this->model->amount - $this->model->paid, $precision);
|
||||
$this->model->paid_amount = $this->model->paid;
|
||||
event(new PaidAmountCalculated($this->model));
|
||||
|
||||
$total_amount = round($this->model->amount - $this->model->paid_amount, $precision);
|
||||
|
||||
unset($this->model->reconciled);
|
||||
unset($this->model->paid_amount);
|
||||
|
||||
$compare = bccomp($amount, $total_amount, $precision);
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Purchase;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Document\PaidAmountCalculated;
|
||||
use App\Events\Purchase\BillUpdated;
|
||||
use App\Events\Purchase\BillUpdating;
|
||||
use App\Jobs\Purchase\CreateBillItemsAndTotals;
|
||||
@@ -53,14 +54,16 @@ class UpdateBill extends Job
|
||||
|
||||
$this->dispatch(new CreateBillItemsAndTotals($this->bill, $this->request));
|
||||
|
||||
$bill_paid = $this->bill->paid;
|
||||
$this->bill->paid_amount = $this->bill->paid;
|
||||
event(new PaidAmountCalculated($this->bill));
|
||||
|
||||
unset($this->bill->reconciled);
|
||||
|
||||
if (($bill_paid) && $this->request['amount'] > $bill_paid) {
|
||||
if ($this->request['amount'] > $this->bill->paid_amount) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
unset($this->bill->reconciled);
|
||||
unset($this->bill->paid_amount);
|
||||
|
||||
$this->bill->update($this->request->input());
|
||||
|
||||
$this->bill->updateRecurring();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Jobs\Sale;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Document\PaidAmountCalculated;
|
||||
use App\Events\Sale\InvoiceUpdated;
|
||||
use App\Events\Sale\InvoiceUpdating;
|
||||
use App\Jobs\Sale\CreateInvoiceItemsAndTotals;
|
||||
@@ -53,14 +54,16 @@ class UpdateInvoice extends Job
|
||||
|
||||
$this->dispatch(new CreateInvoiceItemsAndTotals($this->invoice, $this->request));
|
||||
|
||||
$invoice_paid = $this->invoice->paid;
|
||||
$this->invoice->paid_amount = $this->invoice->paid;
|
||||
event(new PaidAmountCalculated($this->invoice));
|
||||
|
||||
unset($this->invoice->reconciled);
|
||||
|
||||
if (($invoice_paid) && $this->request['amount'] > $invoice_paid) {
|
||||
if ($this->request['amount'] > $this->invoice->paid_amount) {
|
||||
$this->request['status'] = 'partial';
|
||||
}
|
||||
|
||||
unset($this->invoice->reconciled);
|
||||
unset($this->invoice->paid_amount);
|
||||
|
||||
$this->invoice->update($this->request->all());
|
||||
|
||||
$this->invoice->updateRecurring();
|
||||
|
||||
Reference in New Issue
Block a user