From c63515c21cbd669d1bff3c7c4b1a0118eaaafabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Duli=C3=A7i?= Date: Fri, 14 Aug 2020 23:15:54 +0300 Subject: [PATCH] added invoice paid calculation event --- app/Abstracts/DocumentModel.php | 9 ++++++++- app/Events/Sale/InvoicePaidCalculated.php | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/Events/Sale/InvoicePaidCalculated.php diff --git a/app/Abstracts/DocumentModel.php b/app/Abstracts/DocumentModel.php index 4235a5822..203151605 100644 --- a/app/Abstracts/DocumentModel.php +++ b/app/Abstracts/DocumentModel.php @@ -3,6 +3,7 @@ namespace App\Abstracts; use App\Abstracts\Model; +use App\Events\Sale\InvoicePaidCalculated; use App\Models\Setting\Tax; use App\Traits\Currencies; use App\Traits\DateTime; @@ -115,7 +116,13 @@ abstract class DocumentModel extends Model $this->setAttribute('reconciled', $reconciled); - return round($paid, $precision); + // TODO: find a cleaner way compatible with observer pattern + $i = new \stdClass(); + $i->paid = $paid; + + event(new InvoicePaidCalculated($i)); + + return round($i->paid, $precision); } /** * Get the status label. diff --git a/app/Events/Sale/InvoicePaidCalculated.php b/app/Events/Sale/InvoicePaidCalculated.php new file mode 100644 index 000000000..e092e077a --- /dev/null +++ b/app/Events/Sale/InvoicePaidCalculated.php @@ -0,0 +1,22 @@ +invoice = $invoice; + } +}