renamed income/expense

This commit is contained in:
denisdulici
2019-12-31 15:49:09 +03:00
parent e2189158b9
commit 2428feb73b
235 changed files with 815 additions and 2147 deletions

View 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));
}
}

View 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);
}
}
}

View 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();
}
}

View 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'),
]);
}
}

View 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();
}
}

View 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'));
}
}
}

View 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'));
}
}
}