Merge Invoice and Bill into Document

This commit is contained in:
Burak Çakırel
2020-12-24 01:28:38 +03:00
parent 830cc05957
commit 0c1424db47
436 changed files with 31655 additions and 37350 deletions

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

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

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

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

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

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

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

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

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

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