added bill received event
This commit is contained in:
parent
80f0aee1fc
commit
8ddb877dae
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\Contact;
|
||||||
use App\Models\Common\Item;
|
use App\Models\Common\Item;
|
||||||
use App\Models\Purchase\Bill;
|
use App\Models\Purchase\Bill;
|
||||||
use App\Models\Purchase\BillHistory;
|
|
||||||
use App\Models\Setting\Category;
|
use App\Models\Setting\Category;
|
||||||
use App\Models\Setting\Currency;
|
use App\Models\Setting\Currency;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
@ -267,17 +266,7 @@ class Bills extends Controller
|
|||||||
*/
|
*/
|
||||||
public function markReceived(Bill $bill)
|
public function markReceived(Bill $bill)
|
||||||
{
|
{
|
||||||
$bill->status = 'received';
|
event(new \App\Events\Purchase\BillReceived($bill));
|
||||||
$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'),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$message = trans('bills.messages.received');
|
$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\Events\Purchase\BillCreated' => [
|
||||||
'App\Listeners\Purchase\CreateBillCreatedHistory',
|
'App\Listeners\Purchase\CreateBillCreatedHistory',
|
||||||
],
|
],
|
||||||
|
'App\Events\Purchase\BillReceived' => [
|
||||||
|
'App\Listeners\Purchase\MarkBillReceived',
|
||||||
|
],
|
||||||
'App\Events\Purchase\BillRecurring' => [
|
'App\Events\Purchase\BillRecurring' => [
|
||||||
'App\Listeners\Purchase\SendBillRecurringNotification',
|
'App\Listeners\Purchase\SendBillRecurringNotification',
|
||||||
],
|
],
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Events\Purchase\BillCreated;
|
use App\Events\Purchase\BillCreated;
|
||||||
|
use App\Events\Purchase\BillReceived;
|
||||||
use App\Jobs\Banking\CreateDocumentTransaction;
|
use App\Jobs\Banking\CreateDocumentTransaction;
|
||||||
use App\Jobs\Purchase\CreateBillHistory;
|
|
||||||
use App\Jobs\Purchase\UpdateBill;
|
use App\Jobs\Purchase\UpdateBill;
|
||||||
use App\Models\Auth\User;
|
use App\Models\Auth\User;
|
||||||
use App\Models\Common\Contact;
|
use App\Models\Common\Contact;
|
||||||
@ -98,19 +98,11 @@ $factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) {
|
|||||||
session(['company_id' => $company->id]);
|
session(['company_id' => $company->id]);
|
||||||
setting()->setExtraColumns(['company_id' => $company->id]);
|
setting()->setExtraColumns(['company_id' => $company->id]);
|
||||||
|
|
||||||
$status = $bill->status;
|
$init_status = $bill->status;
|
||||||
|
|
||||||
$bill->status = 'draft';
|
$bill->status = 'draft';
|
||||||
|
|
||||||
event(new BillCreated($bill));
|
event(new BillCreated($bill));
|
||||||
|
$bill->status = $init_status;
|
||||||
$bill->status = $status;
|
|
||||||
|
|
||||||
if ($bill->status == 'received') {
|
|
||||||
$bill->status = 'received';
|
|
||||||
$bill->save();
|
|
||||||
|
|
||||||
dispatch_now(new CreateBillHistory($bill, 0, trans('bills.mark_received')));
|
|
||||||
}
|
|
||||||
|
|
||||||
$amount = $faker->randomFloat(2, 1, 1000);
|
$amount = $faker->randomFloat(2, 1, 1000);
|
||||||
|
|
||||||
@ -131,15 +123,23 @@ $factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) {
|
|||||||
|
|
||||||
$updated_bill = dispatch_now(new UpdateBill($bill, $request));
|
$updated_bill = dispatch_now(new UpdateBill($bill, $request));
|
||||||
|
|
||||||
if (in_array($bill->status, ['partial', 'paid'])) {
|
switch ($init_status) {
|
||||||
$payment_request = [
|
case 'received':
|
||||||
'paid_at' => $bill->due_at,
|
event(new BillReceived($bill));
|
||||||
];
|
|
||||||
|
|
||||||
if ($bill->status == 'partial') {
|
break;
|
||||||
$payment_request['amount'] = (double) $amount / 2;
|
case 'partial':
|
||||||
}
|
case 'paid':
|
||||||
|
$payment_request = [
|
||||||
|
'paid_at' => $bill->due_at,
|
||||||
|
];
|
||||||
|
|
||||||
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request));
|
if ($init_status == 'partial') {
|
||||||
|
$payment_request['amount'] = (double) $amount / 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request));
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user