added marked sent event

This commit is contained in:
Denis Duliçi 2022-06-14 01:18:34 +03:00
parent d17c3a89b3
commit 4940720ec0
6 changed files with 98 additions and 83 deletions

View File

@ -5,7 +5,7 @@ namespace App\BulkActions\Sales;
use App\Abstracts\BulkAction; use App\Abstracts\BulkAction;
use App\Events\Document\DocumentCancelled; use App\Events\Document\DocumentCancelled;
use App\Events\Document\DocumentCreated; use App\Events\Document\DocumentCreated;
use App\Events\Document\DocumentSent; use App\Events\Document\DocumentMarkedSent;
use App\Events\Document\PaymentReceived; use App\Events\Document\PaymentReceived;
use App\Exports\Sales\Invoices as Export; use App\Exports\Sales\Invoices as Export;
use App\Jobs\Document\DeleteDocument; use App\Jobs\Document\DeleteDocument;
@ -58,7 +58,7 @@ class Invoices extends BulkAction
continue; continue;
} }
event(new DocumentSent($invoice)); event(new DocumentMarkedSent($invoice));
} }
} }

View File

@ -0,0 +1,20 @@
<?php
namespace App\Events\Document;
use App\Abstracts\Event;
class DocumentMarkedSent extends Event
{
public $document;
/**
* Create a new event instance.
*
* @param $document
*/
public function __construct($document)
{
$this->document = $document;
}
}

View File

@ -220,7 +220,7 @@ class Invoices extends Controller
*/ */
public function markSent(Document $invoice) public function markSent(Document $invoice)
{ {
event(new \App\Events\Document\DocumentSent($invoice)); event(new \App\Events\Document\DocumentMarkedSent($invoice));
$message = trans('documents.messages.marked_sent', ['type' => trans_choice('general.invoices', 1)]); $message = trans('documents.messages.marked_sent', ['type' => trans_choice('general.invoices', 1)]);

View File

@ -2,7 +2,8 @@
namespace App\Listeners\Document; namespace App\Listeners\Document;
use App\Events\Document\DocumentSent as Event; use App\Events\Document\DocumentMarkedSent;
use App\Events\Document\DocumentSent;
use App\Jobs\Document\CreateDocumentHistory; use App\Jobs\Document\CreateDocumentHistory;
use App\Traits\Jobs; use App\Traits\Jobs;
@ -10,13 +11,7 @@ class MarkDocumentSent
{ {
use Jobs; use Jobs;
/** public function handle(DocumentMarkedSent|DocumentSent $event): void
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{ {
if ($event->document->status != 'partial') { if ($event->document->status != 'partial') {
$event->document->status = 'sent'; $event->document->status = 'sent';
@ -24,6 +19,11 @@ class MarkDocumentSent
$event->document->save(); $event->document->save();
} }
$this->dispatch(new CreateDocumentHistory($event->document, 0, $this->getDescription($event)));
}
public function getDescription(DocumentMarkedSent|DocumentSent $event): string
{
$type_text = ''; $type_text = '';
if ($alias = config('type.document.' . $event->document->type . '.alias', '')) { if ($alias = config('type.document.' . $event->document->type . '.alias', '')) {
@ -34,12 +34,8 @@ class MarkDocumentSent
$type = trans_choice($type_text, 1); $type = trans_choice($type_text, 1);
$this->dispatch( $message = ($event instanceof DocumentMarkedSent) ? 'marked_sent' : 'email_sent';
new CreateDocumentHistory(
$event->document, return trans('documents.messages.' . $message, ['type' => $type]);
0,
trans('documents.messages.marked_sent', ['type' => $type])
)
);
} }
} }

View File

@ -57,6 +57,9 @@ class Event extends Provider
'App\Listeners\Document\CreateDocumentTransaction', 'App\Listeners\Document\CreateDocumentTransaction',
'App\Listeners\Document\SendDocumentPaymentNotification', 'App\Listeners\Document\SendDocumentPaymentNotification',
], ],
'App\Events\Document\DocumentMarkedSent' => [
'App\Listeners\Document\MarkDocumentSent',
],
'App\Events\Document\DocumentSent' => [ 'App\Events\Document\DocumentSent' => [
'App\Listeners\Document\MarkDocumentSent', 'App\Listeners\Document\MarkDocumentSent',
], ],

View File

@ -2,84 +2,80 @@
return [ return [
'edit_columns' => 'Edit Columns', 'edit_columns' => 'Edit Columns',
'empty_items' => 'You have not added any items.', 'empty_items' => 'You have not added any items.',
'grand_total' => 'Grand Total',
'accept_payment_online' => 'Accept Payments Online',
'transaction' => 'A payment for :amount was made using :account.',
'billing' => 'Billing',
'advanced' => 'Advanced',
'invoice_detail' => [ 'invoice_detail' => [
'marked' => '<b> You </b> marked this invoice as', 'marked' => '<b>You</b> marked this invoice as',
'services' => 'Services', 'services' => 'Services',
'another_item' => 'Another Item', 'another_item' => 'Another Item',
'another_description' => 'and another description', 'another_description' => 'and another description',
'more_item' => '+:count more item', 'more_item' => '+:count more item',
], ],
'grand_total' => 'Grand Total',
'accept_payment_online' => 'Accept Payments Online',
'transaction' => 'A payment for :amount was made using :account.',
'billing' => 'Billing',
'advanced' => 'Advanced',
'statuses' => [ 'statuses' => [
'draft' => 'Draft', 'draft' => 'Draft',
'sent' => 'Sent', 'sent' => 'Sent',
'expired' => 'Expired', 'expired' => 'Expired',
'viewed' => 'Viewed', 'viewed' => 'Viewed',
'approved' => 'Approved', 'approved' => 'Approved',
'received' => 'Received', 'received' => 'Received',
'refused' => 'Refused', 'refused' => 'Refused',
'restored' => 'Restored', 'restored' => 'Restored',
'reversed' => 'Reversed', 'reversed' => 'Reversed',
'partial' => 'Partial', 'partial' => 'Partial',
'paid' => 'Paid', 'paid' => 'Paid',
'pending' => 'Pending', 'pending' => 'Pending',
'invoiced' => 'Invoiced', 'invoiced' => 'Invoiced',
'overdue' => 'Overdue', 'overdue' => 'Overdue',
'unpaid' => 'Unpaid', 'unpaid' => 'Unpaid',
'cancelled' => 'Cancelled', 'cancelled' => 'Cancelled',
'voided' => 'Voided', 'voided' => 'Voided',
'completed' => 'Completed', 'completed' => 'Completed',
'shipped' => 'Shipped', 'shipped' => 'Shipped',
'refunded' => 'Refunded', 'refunded' => 'Refunded',
'failed' => 'Failed', 'failed' => 'Failed',
'denied' => 'Denied', 'denied' => 'Denied',
'processed' => 'Processed', 'processed' => 'Processed',
'open' => 'Open', 'open' => 'Open',
'closed' => 'Closed', 'closed' => 'Closed',
'billed' => 'Billed', 'billed' => 'Billed',
'delivered' => 'Delivered', 'delivered' => 'Delivered',
'returned' => 'Returned', 'returned' => 'Returned',
'drawn' => 'Drawn', 'drawn' => 'Drawn',
'not_billed' => 'Not Billed', 'not_billed' => 'Not Billed',
'issued' => 'Issued', 'issued' => 'Issued',
'not_invoiced' => 'Not Invoiced', 'not_invoiced' => 'Not Invoiced',
'confirmed' => 'Confirmed', 'confirmed' => 'Confirmed',
'not_confirmed' => 'Not Confirmed', 'not_confirmed' => 'Not Confirmed',
'active' => 'Active', 'active' => 'Active',
'ended' => 'Ended', 'ended' => 'Ended',
], ],
'form_description' => [ 'form_description' => [
'companies' => 'Change the address, logo, and other information for your company.', 'companies' => 'Change the address, logo, and other information for your company.',
'billing' => 'Billing details appears in your document.', 'billing' => 'Billing details appears in your document.',
'advanced' => 'Select the category, add or edit the footer, and add attachments to your :type.', 'advanced' => 'Select the category, add or edit the footer, and add attachments to your :type.',
'attachment' => 'Download the files attached to this :type', 'attachment' => 'Download the files attached to this :type',
], ],
'messages' => [ 'messages' => [
'email_sent' => ':type email has been sent!', 'email_sent' => ':type email has been sent!',
'marked_as' => ':type marked as :status!', 'marked_as' => ':type marked as :status!',
'marked_sent' => ':type marked as sent!', 'marked_sent' => ':type marked as sent!',
'marked_paid' => ':type marked as paid!', 'marked_paid' => ':type marked as paid!',
'marked_viewed' => ':type marked as viewed!', 'marked_viewed' => ':type marked as viewed!',
'marked_cancelled' => ':type marked as cancelled!', 'marked_cancelled' => ':type marked as cancelled!',
'marked_received' => ':type marked as received!', 'marked_received' => ':type marked as received!',
], ],
'recurring' => [ 'recurring' => [
'auto_generated' => 'Auto-generated', 'auto_generated' => 'Auto-generated',
'tooltip' => [ 'tooltip' => [
'document_date' => 'The :type date will be automatically assigned based on the :type schedule and frequency.', 'document_date' => 'The :type date will be automatically assigned based on the :type schedule and frequency.',