Merge Invoice and Bill into Document
This commit is contained in:
25
app/Listeners/Document/CreateDocumentCreatedHistory.php
Normal file
25
app/Listeners/Document/CreateDocumentCreatedHistory.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentCreated as Event;
|
||||
use App\Jobs\Document\CreateDocumentHistory;
|
||||
use App\Traits\Jobs;
|
||||
|
||||
class CreateDocumentCreatedHistory
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$message = trans('messages.success.added', ['type' => $event->document->document_number]);
|
||||
|
||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, $message));
|
||||
}
|
||||
}
|
||||
49
app/Listeners/Document/CreateDocumentTransaction.php
Normal file
49
app/Listeners/Document/CreateDocumentTransaction.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\PaymentReceived as Event;
|
||||
use App\Jobs\Banking\CreateBankingDocumentTransaction;
|
||||
use App\Traits\Jobs;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreateDocumentTransaction
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$document = $event->document;
|
||||
$request = $event->request;
|
||||
|
||||
try {
|
||||
$this->dispatch(new CreateBankingDocumentTransaction($document, $request));
|
||||
} catch (\Exception $e) {
|
||||
$message = $e->getMessage();
|
||||
|
||||
$user = user();
|
||||
|
||||
$type = Str::plural($event->document->type);
|
||||
|
||||
if (empty($user)) {
|
||||
flash($message)->error();
|
||||
|
||||
redirect()->route("signed.$type.show", $document->id)->send();
|
||||
}
|
||||
|
||||
if ($user->can('read-client-portal')) {
|
||||
flash($message)->error();
|
||||
|
||||
redirect()->route("portal.$type.show", $document->id)->send();
|
||||
}
|
||||
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
app/Listeners/Document/IncreaseNextDocumentNumber.php
Normal file
23
app/Listeners/Document/IncreaseNextDocumentNumber.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentCreated as Event;
|
||||
use App\Traits\Documents;
|
||||
|
||||
class IncreaseNextDocumentNumber
|
||||
{
|
||||
use Documents;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
// Update next invoice number
|
||||
$this->increaseNextDocumentNumber($event->document->type);
|
||||
}
|
||||
}
|
||||
28
app/Listeners/Document/MarkDocumentCancelled.php
Normal file
28
app/Listeners/Document/MarkDocumentCancelled.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentCancelled as Event;
|
||||
use App\Jobs\Document\CancelDocument;
|
||||
use App\Jobs\Document\CreateDocumentHistory;
|
||||
use App\Traits\Jobs;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MarkDocumentCancelled
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$this->dispatch(new CancelDocument($event->document));
|
||||
|
||||
$type = Str::plural($event->document->type);
|
||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_cancelled")));
|
||||
}
|
||||
}
|
||||
31
app/Listeners/Document/MarkDocumentReceived.php
Normal file
31
app/Listeners/Document/MarkDocumentReceived.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentReceived as Event;
|
||||
use App\Jobs\Document\CreateDocumentHistory;
|
||||
use App\Traits\Jobs;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MarkDocumentReceived
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($event->document->status != 'partial') {
|
||||
$event->document->status = 'received';
|
||||
|
||||
$event->document->save();
|
||||
}
|
||||
|
||||
$type = Str::plural($event->document->type);
|
||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_received")));
|
||||
}
|
||||
}
|
||||
32
app/Listeners/Document/MarkDocumentSent.php
Normal file
32
app/Listeners/Document/MarkDocumentSent.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentSent as Event;
|
||||
use App\Jobs\Document\CreateDocumentHistory;
|
||||
use App\Traits\Jobs;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MarkDocumentSent
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($event->document->status != 'partial') {
|
||||
$event->document->status = 'sent';
|
||||
|
||||
$event->document->save();
|
||||
}
|
||||
|
||||
$type = Str::plural($event->document->type);
|
||||
|
||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_sent")));
|
||||
}
|
||||
}
|
||||
37
app/Listeners/Document/MarkDocumentViewed.php
Normal file
37
app/Listeners/Document/MarkDocumentViewed.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentViewed as Event;
|
||||
use App\Jobs\Document\CreateDocumentHistory;
|
||||
use App\Traits\Jobs;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class MarkDocumentViewed
|
||||
{
|
||||
use Jobs;
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$document = $event->document;
|
||||
|
||||
if ($document->status != 'sent') {
|
||||
return;
|
||||
}
|
||||
|
||||
unset($document->paid);
|
||||
|
||||
$document->status = 'viewed';
|
||||
$document->save();
|
||||
|
||||
$type = Str::plural($document->type);
|
||||
|
||||
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans("$type.messages.marked_viewed")));
|
||||
}
|
||||
}
|
||||
35
app/Listeners/Document/SendDocumentPaymentNotification.php
Normal file
35
app/Listeners/Document/SendDocumentPaymentNotification.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\PaymentReceived as Event;
|
||||
use App\Notifications\Portal\PaymentReceived as Notification;
|
||||
|
||||
class SendDocumentPaymentNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$document = $event->document;
|
||||
$transaction = $document->transactions()->latest()->first();
|
||||
|
||||
// Notify the customer
|
||||
if ($document->contact && !empty($document->contact_email)) {
|
||||
$document->contact->notify(new Notification($document, $transaction, "{$document->type}_payment_customer"));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($document->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($document, $transaction, "{$document->type}_payment_admin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
34
app/Listeners/Document/SendDocumentRecurringNotification.php
Normal file
34
app/Listeners/Document/SendDocumentRecurringNotification.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentRecurring as Event;
|
||||
use App\Notifications\Sale\Invoice as Notification;
|
||||
|
||||
class SendDocumentRecurringNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$document = $event->document;
|
||||
|
||||
// Notify the customer
|
||||
if ($document->contact && !empty($document->contact_email)) {
|
||||
$document->contact->notify(new Notification($document, "{$document->type}_recur_customer"));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($document->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new Notification($document, "{$document->type}_recur_admin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
41
app/Listeners/Document/SendDocumentReminderNotification.php
Normal file
41
app/Listeners/Document/SendDocumentReminderNotification.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Document;
|
||||
|
||||
use App\Events\Document\DocumentReminded as Event;
|
||||
use App\Models\Document\Document;
|
||||
use App\Notifications\Sale\Invoice as InvoiceNotification;
|
||||
use App\Notifications\Purchase\Bill as BillNotification;
|
||||
|
||||
class SendDocumentReminderNotification
|
||||
{
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return array
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
$document = $event->document;
|
||||
|
||||
$notification = InvoiceNotification::class;
|
||||
if ($document->type === Document::BILL_TYPE) {
|
||||
$notification = BillNotification::class;
|
||||
}
|
||||
|
||||
// Notify the customer
|
||||
if ($document->contact && !empty($document->contact_email)) {
|
||||
$document->contact->notify(new $notification($document, "{$document->type}_remind_customer"));
|
||||
}
|
||||
|
||||
// Notify all users assigned to this company
|
||||
foreach ($document->company->users as $user) {
|
||||
if (!$user->can('read-notifications')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$user->notify(new $notification($document, "{$document->type}_remind_admin"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user