Add Document/Transaction/Contact types to the config

This commit is contained in:
Burak Çakırel
2021-01-05 23:22:38 +03:00
parent 1deff6e5b4
commit 3aa94bc9e2
14 changed files with 130 additions and 147 deletions

View File

@@ -1,61 +0,0 @@
<?php
namespace App\Listeners\Auth;
use App\Events\Auth\ApiPermissionsAssigning as Event;
class SetPermissionControllerForApi
{
/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
// Not a common API endpoint
if (!in_array($event->table, ['contacts', 'documents', 'transactions'])) {
return;
}
// api/contacts?type=customer
// api/contacts?type=vendor
if ($event->table == 'contacts') {
switch ($event->type) {
case 'customer':
$event->permission->controller = 'sales-customers';
break;
case 'vendor':
$event->permission->controller = 'purchases-vendors';
break;
}
}
// api/documents?type=invoice
// api/documents?type=bill
if ($event->table == 'documents') {
switch ($event->type) {
case 'invoice':
$event->permission->controller = 'sales-invoices';
break;
case 'bill':
$event->permission->controller = 'purchases-bills';
break;
}
}
// api/transactions?type=income
// api/transactions?type=expense
if ($event->table == 'transactions') {
switch ($event->type) {
case 'income':
$event->permission->controller = 'sales-revenues';
break;
case 'expense':
$event->permission->controller = 'purchases-payments';
break;
}
}
}
}

View File

@@ -21,6 +21,18 @@ class MarkDocumentCancelled
{
$this->dispatch(new CancelDocument($event->document));
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('documents.messages.marked_cancelled', ['type' => ''])));
$type = trans_choice(
config("type.{$event->document->type}.alias", '') .
'general.' . config("type.{$event->document->type}.translation_key"),
1
);
$this->dispatch(
new CreateDocumentHistory(
$event->document,
0,
trans('documents.messages.marked_cancelled', ['type' => $type])
)
);
}
}

View File

@@ -24,6 +24,18 @@ class MarkDocumentReceived
$event->document->save();
}
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('documents.messages.marked_received', ['type' => ''])));
$type = trans_choice(
config("type.{$event->document->type}.alias", '') .
'general.' . config("type.{$event->document->type}.translation_key"),
1
);
$this->dispatch(
new CreateDocumentHistory(
$event->document,
0,
trans('documents.messages.marked_received', ['type' => $type])
)
);
}
}

View File

@@ -24,6 +24,18 @@ class MarkDocumentSent
$event->document->save();
}
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('documents.messages.marked_sent', ['type' => ''])));
$type = trans_choice(
config("type.{$event->document->type}.alias", '') .
'general.' . config("type.{$event->document->type}.translation_key"),
1
);
$this->dispatch(
new CreateDocumentHistory(
$event->document,
0,
trans('documents.messages.marked_sent', ['type' => $type])
)
);
}
}

View File

@@ -29,6 +29,18 @@ class MarkDocumentViewed
$document->status = 'viewed';
$document->save();
$this->dispatch(new CreateDocumentHistory($event->document, 0, trans('documents.messages.marked_viewed', ['type' => ''])));
$type = trans_choice(
config("type.{$event->document->type}.alias", '') .
'general.' . config("type.{$event->document->type}.translation_key"),
1
);
$this->dispatch(
new CreateDocumentHistory(
$event->document,
0,
trans('documents.messages.marked_viewed', ['type' => $type])
)
);
}
}