added bill received event

This commit is contained in:
denisdulici
2020-01-23 17:57:28 +03:00
parent 80f0aee1fc
commit 8ddb877dae
5 changed files with 75 additions and 32 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\Events\Purchase;
use Illuminate\Queue\SerializesModels;
class BillReceived
{
use SerializesModels;
public $bill;
/**
* Create a new event instance.
*
* @param $bill
*/
public function __construct($bill)
{
$this->bill = $bill;
}
}

View File

@ -16,7 +16,6 @@ use App\Models\Banking\Account;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Purchase\Bill;
use App\Models\Purchase\BillHistory;
use App\Models\Setting\Category;
use App\Models\Setting\Currency;
use App\Models\Setting\Tax;
@ -267,17 +266,7 @@ class Bills extends Controller
*/
public function markReceived(Bill $bill)
{
$bill->status = 'received';
$bill->save();
// Add bill history
BillHistory::create([
'company_id' => $bill->company_id,
'bill_id' => $bill->id,
'status' => 'received',
'notify' => 0,
'description' => trans('bills.mark_received'),
]);
event(new \App\Events\Purchase\BillReceived($bill));
$message = trans('bills.messages.received');

View File

@ -0,0 +1,29 @@
<?php
namespace App\Listeners\Purchase;
use App\Events\Purchase\BillReceived as Event;
use App\Jobs\Purchase\CreateBillHistory;
use App\Traits\Jobs;
class MarkBillReceived
{
use Jobs;
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
if ($event->bill->status != 'partial') {
$event->bill->status = 'received';
$event->bill->save();
}
$this->dispatch(new CreateBillHistory($event->bill, 0, trans('bills.mark_received')));
}
}

View File

@ -25,6 +25,9 @@ class Event extends Provider
'App\Events\Purchase\BillCreated' => [
'App\Listeners\Purchase\CreateBillCreatedHistory',
],
'App\Events\Purchase\BillReceived' => [
'App\Listeners\Purchase\MarkBillReceived',
],
'App\Events\Purchase\BillRecurring' => [
'App\Listeners\Purchase\SendBillRecurringNotification',
],