added document events
This commit is contained in:
parent
4ecc172e92
commit
f29bd6f4b1
@ -3,7 +3,7 @@
|
|||||||
namespace App\Abstracts;
|
namespace App\Abstracts;
|
||||||
|
|
||||||
use App\Abstracts\Model;
|
use App\Abstracts\Model;
|
||||||
use App\Events\Sale\InvoicePaidCalculated;
|
use App\Events\Document\PaidAmountCalculated;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
use App\Traits\DateTime;
|
use App\Traits\DateTime;
|
||||||
@ -117,12 +117,11 @@ abstract class DocumentModel extends Model
|
|||||||
$this->setAttribute('reconciled', $reconciled);
|
$this->setAttribute('reconciled', $reconciled);
|
||||||
|
|
||||||
// TODO: find a cleaner way compatible with observer pattern
|
// TODO: find a cleaner way compatible with observer pattern
|
||||||
$invoice = clone $this;
|
$model = clone $this;
|
||||||
$invoice->paid_amount = $paid;
|
$model->paid_amount = $paid;
|
||||||
|
event(new PaidAmountCalculated($model));
|
||||||
|
|
||||||
event(new InvoicePaidCalculated($invoice));
|
return round($model->paid_amount, $precision);
|
||||||
|
|
||||||
return round($invoice->paid_amount, $precision);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Get the status label.
|
* Get the status label.
|
||||||
|
22
app/Events/Document/PaidAmountCalculated.php
Normal file
22
app/Events/Document/PaidAmountCalculated.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Document;
|
||||||
|
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class PaidAmountCalculated
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
public $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $model
|
||||||
|
*/
|
||||||
|
public function __construct($model)
|
||||||
|
{
|
||||||
|
$this->model = $model;
|
||||||
|
}
|
||||||
|
}
|
22
app/Events/Document/TransactionsCounted.php
Normal file
22
app/Events/Document/TransactionsCounted.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events\Document;
|
||||||
|
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class TransactionsCounted
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
public $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @param $model
|
||||||
|
*/
|
||||||
|
public function __construct($model)
|
||||||
|
{
|
||||||
|
$this->model = $model;
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Events\Sale;
|
|
||||||
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class InvoicePaidCalculated
|
|
||||||
{
|
|
||||||
use SerializesModels;
|
|
||||||
|
|
||||||
public $invoice;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new event instance.
|
|
||||||
*
|
|
||||||
* @param $invoice
|
|
||||||
*/
|
|
||||||
public function __construct($invoice)
|
|
||||||
{
|
|
||||||
$this->invoice = $invoice;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Observers;
|
namespace App\Observers;
|
||||||
|
|
||||||
use App\Abstracts\Observer;
|
use App\Abstracts\Observer;
|
||||||
|
use App\Events\Document\TransactionsCounted;
|
||||||
use App\Jobs\Purchase\CreateBillHistory;
|
use App\Jobs\Purchase\CreateBillHistory;
|
||||||
use App\Jobs\Sale\CreateInvoiceHistory;
|
use App\Jobs\Sale\CreateInvoiceHistory;
|
||||||
use App\Models\Banking\Transaction as Model;
|
use App\Models\Banking\Transaction as Model;
|
||||||
@ -33,7 +34,12 @@ class Transaction extends Observer
|
|||||||
{
|
{
|
||||||
$invoice = $transaction->invoice;
|
$invoice = $transaction->invoice;
|
||||||
|
|
||||||
$invoice->status = ($invoice->transactions->count() > 1) ? 'partial' : 'sent';
|
// TODO: find a cleaner way compatible with observer pattern
|
||||||
|
$model = clone $invoice;
|
||||||
|
$model->transactions_count = $invoice->transactions->count();
|
||||||
|
event(new TransactionsCounted($model));
|
||||||
|
|
||||||
|
$invoice->status = ($model->transactions_count > 1) ? 'partial' : 'sent';
|
||||||
|
|
||||||
$invoice->save();
|
$invoice->save();
|
||||||
|
|
||||||
@ -44,7 +50,12 @@ class Transaction extends Observer
|
|||||||
{
|
{
|
||||||
$bill = $transaction->bill;
|
$bill = $transaction->bill;
|
||||||
|
|
||||||
$bill->status = ($bill->transactions->count() > 1) ? 'partial' : 'received';
|
// TODO: find a cleaner way compatible with observer pattern
|
||||||
|
$model = clone $bill;
|
||||||
|
$model->transactions_count = $bill->transactions->count();
|
||||||
|
event(new TransactionsCounted($model));
|
||||||
|
|
||||||
|
$bill->status = ($model->transactions_count > 1) ? 'partial' : 'received';
|
||||||
|
|
||||||
$bill->save();
|
$bill->save();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user