Skip to content

Commit

Permalink
added invoice paid calculation event
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Aug 14, 2020
1 parent 0d8f524 commit c63515c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Abstracts/DocumentModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,7 +116,13 @@ public function getPaidAttribute()

$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.
Expand Down
22 changes: 22 additions & 0 deletions app/Events/Sale/InvoicePaidCalculated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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;
}
}

0 comments on commit c63515c

Please sign in to comment.