renamed income/expense
This commit is contained in:
25
app/Listeners/Sale/CreateInvoiceCreatedHistory.php
Normal file
25
app/Listeners/Sale/CreateInvoiceCreatedHistory.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceCreated as Event;
|
||||
use App\Jobs\Sale\CreateInvoiceHistory;
|
||||
use App\Traits\Jobs;
|
||||
|
||||
class CreateInvoiceCreatedHistory
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$message = trans('messages.success.added', ['type' => $event->invoice->invoice_number]);
|
||||
|
||||
$this->dispatch(new CreateInvoiceHistory($event->invoice, 0, $message));
|
||||
}
|
||||
}
|
44
app/Listeners/Sale/CreateInvoiceTransaction.php
Normal file
44
app/Listeners/Sale/CreateInvoiceTransaction.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\PaymentReceived as Event;
|
||||
use App\Jobs\Banking\CreateDocumentTransaction;
|
||||
use App\Traits\Jobs;
|
||||
|
||||
class CreateInvoiceTransaction
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
$request = $event->request;
|
||||
|
||||
try {
|
||||
$this->dispatch(new CreateDocumentTransaction($invoice, $request));
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
|
||||
if (!$user = user()) {
|
||||
flash($message)->error();
|
||||
|
||||
redirect()->route('signed.invoices.show', $invoice->id)->send();
|
||||
}
|
||||
|
||||
if ($user->can('read-client-portal')) {
|
||||
flash($message)->error();
|
||||
|
||||
redirect()->route('portal.invoices.show', $invoice->id)->send();
|
||||
}
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
23
app/Listeners/Sale/IncreaseNextInvoiceNumber.php
Normal file
23
app/Listeners/Sale/IncreaseNextInvoiceNumber.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceCreated as Event;
|
||||
use App\Traits\Incomes;
|
||||
|
||||
class IncreaseNextInvoiceNumber
|
||||
{
|
||||
use Incomes;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
// Update next invoice number
|
||||
$this->increaseNextInvoiceNumber();
|
||||
}
|
||||
}
|
34
app/Listeners/Sale/MarkInvoiceSent.php
Normal file
34
app/Listeners/Sale/MarkInvoiceSent.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceSent as Event;
|
||||
use App\Models\Sale\InvoiceHistory;
|
||||
|
||||
class MarkInvoiceSent
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
// Mark invoice as sent
|
||||
if ($event->invoice->invoice_status_code != 'partial') {
|
||||
$event->invoice->invoice_status_code = 'sent';
|
||||
|
||||
$event->invoice->save();
|
||||
}
|
||||
|
||||
// Add invoice history
|
||||
InvoiceHistory::create([
|
||||
'company_id' => $event->invoice->company_id,
|
||||
'invoice_id' => $event->invoice->id,
|
||||
'status_code' => 'sent',
|
||||
'notify' => 0,
|
||||
'description' => trans('invoices.mark_sent'),
|
||||
]);
|
||||
}
|
||||
}
|
28
app/Listeners/Sale/MarkInvoiceViewed.php
Normal file
28
app/Listeners/Sale/MarkInvoiceViewed.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceViewed as Event;
|
||||
|
||||
class MarkInvoiceViewed
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
|
||||
if ($invoice->invoice_status_code != 'sent') {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($invoice->paid);
|
||||
|
||||
$invoice->invoice_status_code = 'viewed';
|
||||
$invoice->save();
|
||||
}
|
||||
}
|
35
app/Listeners/Sale/SendInvoicePaymentNotification.php
Normal file
35
app/Listeners/Sale/SendInvoicePaymentNotification.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\PaymentReceived as Event;
|
||||
use App\Notifications\Portal\PaymentReceived as Notification;
|
||||
|
||||
class SendInvoicePaymentNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
$transaction = $invoice->transactions()->latest()->first();
|
||||
|
||||
// Notify the customer
|
||||
if ($invoice->contact && !empty($invoice->contact_email)) {
|
||||
$invoice->contact->notify(new Notification($invoice, $transaction, 'invoice_payment_customer'));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($invoice->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($invoice, $transaction, 'invoice_payment_admin'));
|
||||
}
|
||||
}
|
||||
}
|
34
app/Listeners/Sale/SendInvoiceRecurringNotification.php
Normal file
34
app/Listeners/Sale/SendInvoiceRecurringNotification.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Sale;
|
||||
|
||||
use App\Events\Sale\InvoiceRecurring as Event;
|
||||
use App\Notifications\Sale\Invoice as Notification;
|
||||
|
||||
class SendInvoiceRecurringNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$invoice = $event->invoice;
|
||||
|
||||
// Notify the customer
|
||||
if ($invoice->contact && !empty($invoice->contact_email)) {
|
||||
$invoice->contact->notify(new Notification($invoice, 'invoice_recur_customer'));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($invoice->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($invoice, 'invoice_recur_admin'));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user