added bill received event
This commit is contained in:
22
app/Events/Purchase/BillReceived.php
Normal file
22
app/Events/Purchase/BillReceived.php
Normal 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;
|
||||
}
|
||||
}
|
@ -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');
|
||||
|
||||
|
29
app/Listeners/Purchase/MarkBillReceived.php
Normal file
29
app/Listeners/Purchase/MarkBillReceived.php
Normal 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')));
|
||||
}
|
||||
}
|
@ -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',
|
||||
],
|
||||
|
Reference in New Issue
Block a user