From 3c59a57a8a05aef6a541f049767178f975ff4b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 17:47:52 +0300 Subject: [PATCH 01/37] Document components text get config translation --- app/Abstracts/View/Components/Document.php | 99 +++++ .../View/Components/DocumentForm.php | 340 ++++++++++-------- .../View/Components/DocumentIndex.php | 107 +++--- .../View/Components/DocumentShow.php | 273 +++++++------- .../View/Components/DocumentTemplate.php | 161 ++++----- config/type.php | 68 +++- .../documents/form/content.blade.php | 4 +- 7 files changed, 617 insertions(+), 435 deletions(-) create mode 100644 app/Abstracts/View/Components/Document.php diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php new file mode 100644 index 000000000..f1b441605 --- /dev/null +++ b/app/Abstracts/View/Components/Document.php @@ -0,0 +1,99 @@ + $alias . 'general.' . $default_key, + 'prefix' => $alias . $prefix . '.' . $default_key, + 'config_general' => $alias . 'general.' . $config_key, + 'config_prefix' => $alias . $prefix . '.' . $config_key, + ]; + + switch ($trans_type) { + case 'trans': + foreach ($translations as $trans) { + if (trans($trans) !== $trans) { + return $trans; + } + } + + break; + case 'trans_choice': + foreach ($translations as $trans_choice) { + if (trans_choice($trans_choice, 1) !== $trans_choice) { + return $trans_choice; + } + } + + break; + } + + return $translation; + } + + public function getRouteFromConfig($type, $config_key) + { + $route = ''; + + // if set config trasnlation config_key + if ($route = config('type.' . $type . '.route.' . $config_key)) { + return $route; + } + + $prefix = config("type.' . $type . '.route.prefix"); + + + } + + public function getPermissionFromConfig($type, $config_key, $action) + { + $permission = ''; + + // if set config trasnlation config_key + if ($permission = config('type.' . $type . '.permission.' . $config_key)) { + return $permission; + } + + $alias = config('type.' . $type . '.alias'); + $group = config('type.' . $type . '.group'); + $prefix = config("type.' . $type . '.permission.prefix"); + + $permission = $action . '-'; + + // if use module set module alias + if (!empty($alias)) { + $permission .= $alias . '-'; + } + + // if controller in folder it must + if (!empty($group)) { + $permission .= $group . '-'; + } + + $permission .= $prefix; + + return $permission; + } +} diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 36fd9a2c7..c105fdbed 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -2,13 +2,13 @@ namespace App\Abstracts\View\Components; +use App\Abstracts\View\Components\Document as Base; use App\Models\Common\Contact; use App\Models\Document\Document; use App\Traits\Documents; use Date; -use Illuminate\View\Component; use Illuminate\Support\Str; -abstract class DocumentForm extends Component +abstract class DocumentForm extends Base { use Documents; @@ -43,7 +43,10 @@ abstract class DocumentForm extends Component /** Content Component Start */ /** @var string */ - public $formRoute; + public $routeStore; + + /** @var string */ + public $routeUpdate; /** @var string */ public $formId; @@ -191,7 +194,7 @@ abstract class DocumentForm extends Component bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, /** Company Component End */ /** Content Component Start */ - string $formRoute = '', string $formId = 'document', string $formSubmit = 'onSubmit', + string $routeStore = '', string $routeUpdate = '', string $formId = 'document', string $formSubmit = 'onSubmit', bool $hideCompany = false, bool $hideAdvanced = false, bool $hideFooter = false, bool $hideButtons = false, /** Content Component End */ /** Metadata Component Start */ @@ -226,7 +229,8 @@ abstract class DocumentForm extends Component /** Company Component End */ /** Content Component Start */ - $this->formRoute = ($formRoute) ? $formRoute : $this->getRoute($type, $document); + $this->routeStore = $this->getRouteStore($type, $routeStore); + $this->routeUpdate = $this->getRouteUpdate($type, $routeUpdate, $document); $this->formId = $formId; $this->formSubmit = $formSubmit; @@ -283,24 +287,65 @@ abstract class DocumentForm extends Component /** Items Component End */ } - protected function getRoute($type, $document, $parameters = []) + protected function getRouteStore($type, $routeStore) { - $page = config("type.{$type}.route_name"); + if (!empty($routeStore)) { + return $routeStore; + } - $route = $page . '.store'; + if ($route = config("type.{$type}.route.store")) { + return $route; + } - if ($document) { + $prefix = config("type.{$type}.route.prefix"); + + $route = $prefix . '.store'; + + try { + route($route); + } catch (\Exception $e) { + try { + $route = Str::plural($type, 2) . '.store'; + + route($route); + } catch (\Exception $e) { + $route = ''; + } + } + + return $route; + } + + protected function getRouteUpdate($type, $routeUpdate, $document, $parameters = []) + { + if (!empty($routeUpdate)) { + return $routeUpdate; + } + + if ($route = config("type.{$type}.route.update")) { + return $route; + } + + $prefix = config("type.{$type}.route.prefix"); + + $route = $prefix . '.update'; + + if (!empty($parameters)) { $parameters = [ - config("type.{$type}.route_parameter") => $document->id + config("type.{$type}.route.parameter") => $document->id ]; - - $route = $page . '.update'; } try { route($route, $parameters); } catch (\Exception $e) { - $route = ''; + try { + $route = Str::plural($type, 2) . '.update'; + + route($route, $parameters); + } catch (\Exception $e) { + $route = ''; + } } return $route; @@ -344,6 +389,13 @@ abstract class DocumentForm extends Component return $contact_type; } + if ($contact_type = config("type.{$type}.contact_type")) { + return $contact_type; + } + + // set default type + $type = Document::INVOICE_TYPE; + return config("type.{$type}.contact_type"); } @@ -353,24 +405,19 @@ abstract class DocumentForm extends Component return $textAddContact; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textAddContact = [ - 'general.form.add', - 'general.vendors' - ]; - break; - default: - $textAddContact = [ - 'general.form.add', - 'general.customers' - ]; - break; + $translation = $this->getTextFromConfig($type, 'add_contact', Str::plural($this->contactType, 2), 'trans_choice'); + + if (!empty($translation)) { + return [ + 'general.form.add', + $translation, + ]; } - return $textAddContact; + return [ + 'general.form.add', + 'general.customers', + ]; } protected function getTextCreateNewContact($type, $textCreateNewContact) @@ -379,24 +426,21 @@ abstract class DocumentForm extends Component return $textCreateNewContact; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textCreateNewContact = [ - 'general.form.add_new', - 'general.vendors' - ]; - break; - default: - $textCreateNewContact = [ - 'general.form.add_new', - 'general.customers' - ]; - break; + $contact_type = Str::plural(config('type.' . $type . '.contact_type'), 2); + + $translation = $this->getTextFromConfig($type, 'create_new_contact', $contact_type, 'trans_choice'); + + if (!empty($translation)) { + return [ + 'general.form.add_new', + $translation, + ]; } - return $textCreateNewContact; + return [ + 'general.form.add_new', + 'general.customers', + ]; } protected function getTextEditContact($type, $textEditContact) @@ -405,18 +449,13 @@ abstract class DocumentForm extends Component return $textEditContact; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textEditContact = 'general.form.edit'; - break; - default: - $textEditContact = 'general.form.edit'; - break; + $translation = $this->getTextFromConfig($type, 'edit_contact', 'form.edit'); + + if (!empty($translation)) { + return $translation; } - return $textEditContact; + return 'general.form.edit'; } protected function getTextContactInfo($type, $textContactInfo) @@ -429,14 +468,20 @@ abstract class DocumentForm extends Component case 'bill': case 'expense': case 'purchase': - $textContactInfo = 'bills.bill_from'; + $default_key = 'bill_from'; break; default: - $textContactInfo = 'invoices.bill_to'; + $default_key = 'bill_to'; break; } - return $textContactInfo; + $translation = $this->getTextFromConfig($type, 'contact_info', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.bill_to'; } protected function getTextChooseDifferentContact($type, $textChooseDifferentContact) @@ -445,24 +490,19 @@ abstract class DocumentForm extends Component return $textChooseDifferentContact; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textChooseDifferentContact = [ - 'general.form.choose_different', - 'general.vendors' - ]; - break; - default: - $textChooseDifferentContact = [ - 'general.form.choose_different', - 'general.customers' - ]; - break; + $translation = $this->getTextFromConfig($type, 'choose_different_contact', Str::plural($this->contactType, 2), 'trans_choice'); + + if (!empty($translation)) { + return [ + 'general.form.choose_different', + $translation, + ]; } - return $textChooseDifferentContact; + return [ + 'general.form.choose_different', + 'general.customers' + ]; } protected function getIssuedAt($type, $document, $issued_at) @@ -560,14 +600,20 @@ abstract class DocumentForm extends Component case 'bill': case 'expense': case 'purchase': - $textDocumentNumber = 'bills.bill_number'; + $default_key = 'bill_number'; break; default: - $textDocumentNumber = 'invoices.invoice_number'; + $default_key = 'invoice_number'; break; } - return $textDocumentNumber; + $translation = $this->getTextFromConfig($type, 'document_number', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.invoice_number'; } protected function getTextOrderNumber($type, $textOrderNumber) @@ -576,18 +622,13 @@ abstract class DocumentForm extends Component return $textOrderNumber; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textOrderNumber = 'bills.order_number'; - break; - default: - $textOrderNumber = 'invoices.order_number'; - break; + $translation = $this->getTextFromConfig($type, 'order_number'); + + if (!empty($translation)) { + return $translation; } - return $textOrderNumber; + return 'invoices.order_number'; } protected function getTextIssuedAt($type, $textIssuedAt) @@ -600,14 +641,20 @@ abstract class DocumentForm extends Component case 'bill': case 'expense': case 'purchase': - $textIssuedAt = 'bills.bill_date'; + $default_key = 'bill_date'; break; default: - $textIssuedAt = 'invoices.invoice_date'; + $default_key = 'invoice_date'; break; } - return $textIssuedAt; + $translation = $this->getTextFromConfig($type, 'issued_at', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.invoice_date'; } protected function getTextDueAt($type, $textDueAt) @@ -616,90 +663,73 @@ abstract class DocumentForm extends Component return $textDueAt; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textDueAt = 'bills.due_date'; - break; - default: - $textDueAt = 'invoices.due_date'; - break; + $translation = $this->getTextFromConfig($type, 'due_at', 'due_date'); + + if (!empty($translation)) { + return $translation; } - return $textDueAt; + return 'invoices.due_date'; } - protected function getTextItems($type, $text_items) + protected function getTextItems($type, $textItems) { - if (!empty($text_items)) { - return $text_items; + if (!empty($textItems)) { + return $textItems; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $text_items = 'general.items'; - break; - default: - $text_items = setting('invoice.item_name', 'general.items'); - - if ($text_items == 'custom') { - $text_items = setting('invoice.item_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.item_name', 'items') == 'custom') { + return setting($type . '.item_name_input'); } - return $text_items; + $translation = $this->getTextFromConfig($type, 'items'); + + if (!empty($translation)) { + return $translation; + } + + return 'general.items'; } - protected function getTextQuantity($type, $text_quantity) + protected function getTextQuantity($type, $textQuantity) { - if (!empty($text_quantity)) { - return $text_quantity; + if (!empty($textQuantity)) { + return $textQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $text_quantity = 'bills.quantity'; - break; - default: - $text_quantity = setting('invoice.quantity_name', 'invoices.quantity'); - - if ($text_quantity == 'custom') { - $text_quantity = setting('invoice.quantity_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.quantity_name', 'quantity') == 'custom') { + return setting($type . '.quantity_name_input'); } - return $text_quantity; + $translation = $this->getTextFromConfig($type, 'quantity'); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.quantity'; } - protected function getTextPrice($type, $text_price) + protected function getTextPrice($type, $textPrice) { - if (!empty($text_price)) { - return $text_price; + if (!empty($textPrice)) { + return $textPrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $text_price = 'bills.price'; - break; - default: - $text_price = setting('invoice.price_name', 'invoices.price'); - - if ($text_price == 'custom') { - $text_price = setting('invoice.price_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.price_name', 'price') == 'custom') { + return setting($type . '.price_name_input'); } - return $text_price; + $translation = $this->getTextFromConfig($type, 'price'); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.price'; } protected function getTextAmount($type, $text_amount) @@ -708,9 +738,13 @@ abstract class DocumentForm extends Component return $text_amount; } - $text_amount = 'general.amount'; + $translation = $this->getTextFromConfig($type, 'amount'); - return $text_amount; + if (!empty($translation)) { + return $translation; + } + + return 'general.amount'; } protected function getHideItems($type, $hideItems, $hideName, $hideDescription) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 0c92aaea7..4e72d5a3c 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -2,11 +2,11 @@ namespace App\Abstracts\View\Components; -use Illuminate\View\Component; -use Illuminate\Support\Str; +use App\Abstracts\View\Components\Document as Base; use App\Events\Common\BulkActionsAdding; +use Illuminate\Support\Str; -abstract class DocumentIndex extends Component +abstract class DocumentIndex extends Base { /** @var string */ public $type; @@ -292,7 +292,7 @@ abstract class DocumentIndex extends Component return $page; } - return config("type.{$type}.route_name"); + return config("type.{$type}.route.prefix"); } protected function getDocsPath($type, $docsPath) @@ -323,7 +323,7 @@ abstract class DocumentIndex extends Component return $createRoute; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.create'; @@ -355,7 +355,8 @@ abstract class DocumentIndex extends Component $importRouteParameters = [ 'group' => config("type.{$type}.group"), - 'type' => config("type.{$type}.route_name") + 'type' => config("type.{$type}.route.prefix"), + 'route' => 'invoices.import', ]; return $importRouteParameters; @@ -367,7 +368,7 @@ abstract class DocumentIndex extends Component return $exportRoute; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.export'; @@ -386,7 +387,7 @@ abstract class DocumentIndex extends Component return $formCardHeaderRoute; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.index'; @@ -427,9 +428,13 @@ abstract class DocumentIndex extends Component return $textBulkAction; } - $textBulkAction = 'general.' . config("type.{$type}.translation_key"); + $translation = $this->getTextFromConfig($type, 'bulk_action', Str::plural($type, 2)); - return $textBulkAction; + if (!empty($translation)) { + return $translation; + } + + return 'general.invoices'; } protected function getBulkActions($type, $bulkActions, $bulkActionClass) @@ -475,7 +480,7 @@ abstract class DocumentIndex extends Component $bulkActionRouteParameters = [ 'group' => config("type.{$type}.group"), - 'type' => config("type.{$type}.route_name") + 'type' => config("type.{$type}.route.prefix") ]; return $bulkActionRouteParameters; @@ -496,6 +501,12 @@ abstract class DocumentIndex extends Component return $textDocumentNumber; } + $translation = $this->getTextFromConfig($type, 'document_number', 'numbers'); + + if (!empty($translation)) { + return $translation; + } + return 'general.numbers'; } @@ -518,18 +529,15 @@ abstract class DocumentIndex extends Component return $textContactName; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textContactName = 'general.vendors'; - break; - default: - $textContactName = 'general.customers'; - break; + $contact_type = Str::plural(config('type.' . $type . '.contact_type'), 2); + + $translation = $this->getTextFromConfig($type, 'contact_name', $contact_type, 'trans_choice'); + + if (!empty($translation)) { + return $translation; } - return $textContactName; + return 'general.customers'; } protected function getClassContactName($type, $classContactName) @@ -564,18 +572,13 @@ abstract class DocumentIndex extends Component return $textIssuedAt; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textIssuedAt = 'bills.bill_date'; - break; - default: - $textIssuedAt = 'invoices.invoice_date'; - break; + $translation = $this->getTextFromConfig($type, 'issued_at'); + + if (!empty($translation)) { + return $translation; } - return $textIssuedAt; + return 'invoices.invoice_date'; } protected function getclassIssuedAt($type, $classIssuedAt) @@ -597,18 +600,13 @@ abstract class DocumentIndex extends Component return $textDueAt; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textDueAt = 'bills.due_date'; - break; - default: - $textDueAt = 'invoices.due_date'; - break; + $translation = $this->getTextFromConfig($type, 'due_at'); + + if (!empty($translation)) { + return $translation; } - return $textDueAt; + return 'invoices.due_date'; } protected function getClassDueAt($type, $classDueAt) @@ -630,18 +628,15 @@ abstract class DocumentIndex extends Component return $textDocumentStatus; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textDocumentStatus = 'bills.statuses.'; - break; - default: - $textDocumentStatus = 'invoices.statuses.'; - break; + $default_key = config("type.' . $type . '.translation.prefix") . '.statuses.'; + + $translation = $this->getTextFromConfig($type, 'document_status', $default_key); + + if (!empty($translation)) { + return $translation; } - return $textDocumentStatus; + return 'invoices.statuses.'; } protected function getClassStatus($type, $classStatus) @@ -676,7 +671,7 @@ abstract class DocumentIndex extends Component return $routeButtonShow; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.show'; @@ -698,7 +693,7 @@ abstract class DocumentIndex extends Component return $routeButtonEdit; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.edit'; @@ -720,7 +715,7 @@ abstract class DocumentIndex extends Component return $routeButtonDuplicate; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.duplicate'; @@ -742,7 +737,7 @@ abstract class DocumentIndex extends Component return $routeButtonCancelled; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.cancelled'; @@ -764,7 +759,7 @@ abstract class DocumentIndex extends Component return $routeButtonDelete; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.destroy'; diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index b2e58a432..22bf9cdea 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -2,16 +2,16 @@ namespace App\Abstracts\View\Components; -use Illuminate\View\Component; -use Illuminate\Support\Str; +use App\Abstracts\View\Components\Document as Base; use App\Traits\DateTime; use App\Models\Common\Media; use File; use Image; use Storage; use Illuminate\Support\Facades\URL; +use Illuminate\Support\Str; -abstract class DocumentShow extends Component +abstract class DocumentShow extends Base { use DateTime; @@ -521,18 +521,15 @@ abstract class DocumentShow extends Component return $textRecurringType; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textRecurringType = 'general.bills'; - break; - default: - $textRecurringType = 'general.invoices'; - break; + $default_key = config("type.' . $type . '.translation.prefix"); + + $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key); + + if (!empty($translation)) { + return $translation; } - return $textRecurringType; + return 'general.invoices'; } protected function getTextStatusMessage($type, $textStatusMessage) @@ -541,18 +538,15 @@ abstract class DocumentShow extends Component return $textStatusMessage; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textStatusMessage = 'bills.messages.draft'; - break; - default: - $textStatusMessage = 'invoices.messages.draft'; - break; + $default_key = config("type.' . $type . '.translation.prefix") . '.messages.draft'; + + $translation = $this->getTextFromConfig($type, 'status_message', $default_key); + + if (!empty($translation)) { + return $translation; } - return $textStatusMessage; + return 'invoices.messages.draft'; } protected function getDocumentTemplate($type, $documentTemplate) @@ -613,7 +607,7 @@ abstract class DocumentShow extends Component return $signedUrl; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = 'signed.' . $page . '.show'; @@ -634,18 +628,15 @@ abstract class DocumentShow extends Component return $textHistories; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textHistories = 'bills.histories'; - break; - default: - $textHistories = 'invoices.histories'; - break; + $default_key = config("type.' . $type . '.translation.prefix") . '.histories'; + + $translation = $this->getTextFromConfig($type, 'histories', $default_key); + + if (!empty($translation)) { + return $translation; } - return $textHistories; + return 'invoices.histories'; } protected function getTextHistoryStatus($type, $textHistoryStatus) @@ -654,18 +645,15 @@ abstract class DocumentShow extends Component return $textHistoryStatus; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textHistoryStatus = 'bills.statuses.'; - break; - default: - $textHistoryStatus = 'invoices.statuses.'; - break; + $default_key = config("type.' . $type . '.translation.prefix") . '.statuses.'; + + $translation = $this->getTextFromConfig($type, 'statuses', $default_key); + + if (!empty($translation)) { + return $translation; } - return $textHistoryStatus; + return 'invoices.statuses.'; } protected function getRouteButtonAddNew($type, $routeButtonAddNew) @@ -674,7 +662,7 @@ abstract class DocumentShow extends Component return $routeButtonAddNew; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.create'; @@ -693,7 +681,7 @@ abstract class DocumentShow extends Component return $routeButtonEdit; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.edit'; @@ -715,7 +703,7 @@ abstract class DocumentShow extends Component return $routeButtonDuplicate; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.duplicate'; @@ -737,7 +725,7 @@ abstract class DocumentShow extends Component return $routeButtonPrint; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.print'; @@ -759,7 +747,7 @@ abstract class DocumentShow extends Component return $routeButtonPdf; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.pdf'; @@ -781,7 +769,7 @@ abstract class DocumentShow extends Component return $routeButtonCancelled; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.cancelled'; @@ -820,7 +808,7 @@ abstract class DocumentShow extends Component return $routeButtonDelete; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.destroy'; @@ -842,7 +830,7 @@ abstract class DocumentShow extends Component return $routeButtonPaid; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.paid'; @@ -864,7 +852,7 @@ abstract class DocumentShow extends Component return $routeButtonSent; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.sent'; @@ -886,7 +874,7 @@ abstract class DocumentShow extends Component return $routeButtonReceived; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.received'; @@ -908,7 +896,7 @@ abstract class DocumentShow extends Component return $routeButtonEmail; } - $page = config("type.{$type}.route_name"); + $page = config("type.{$type}.route.prefix"); $route = $page . '.email'; @@ -1018,18 +1006,15 @@ abstract class DocumentShow extends Component return $textHeaderContact; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textHeaderContact = 'general.vendors'; - break; - default: - $textHeaderContact = 'general.customers'; - break; + $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); + + $translation = $this->getTextFromConfig($type, 'header_contact', $default_key, 'trans_choice'); + + if (!empty($translation)) { + return $translation; } - return $textHeaderContact; + return 'general.customers'; } protected function getTextHeaderAmount($type, $textHeaderAmount) @@ -1038,6 +1023,12 @@ abstract class DocumentShow extends Component return $textHeaderAmount; } + $translation = $this->getTextFromConfig($type, 'header_amount', 'amount_due'); + + if (!empty($translation)) { + return $translation; + } + return 'general.amount_due'; } @@ -1047,6 +1038,12 @@ abstract class DocumentShow extends Component return $textHeaderDueAt; } + $translation = $this->getTextFromConfig($type, 'header_due_at', 'due_on'); + + if (!empty($translation)) { + return $translation; + } + return 'general.due_on'; } @@ -1103,7 +1100,15 @@ abstract class DocumentShow extends Component return $textTimelineCreateTitle; } - return config("type.{$type}.translation_key") . '.create_' . $type; + $default_key = 'create_' . $type; + + $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.create_invoice'; } protected function getTextTimelineCreateMessage($type, $textTimelineCreateMessage) @@ -1112,7 +1117,13 @@ abstract class DocumentShow extends Component return $textTimelineCreateMessage; } - return config("type.{$type}.translation_key") . '.messages.status.created'; + $translation = $this->getTextFromConfig($type, 'timeline_create_message', 'messages.status.created'); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.messages.status.created'; } protected function getTextTimelineSentTitle($type, $textTimelineSentTitle) @@ -1125,14 +1136,20 @@ abstract class DocumentShow extends Component case 'bill': case 'expense': case 'purchase': - $textTimelineSentTitle = 'bills.receive_bill'; + $default_key = 'receive_bill'; break; default: - $textTimelineSentTitle = 'invoices.send_invoice'; + $default_key = 'send_invoice'; break; } - return $textTimelineSentTitle; + $translation = $this->getTextFromConfig($type, 'timeline_sent_title', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.send_invoice'; } protected function getTextTimelineSentStatusDraft($type, $textTimelineSentStatusDraft) @@ -1145,14 +1162,20 @@ abstract class DocumentShow extends Component case 'bill': case 'expense': case 'purchase': - $textTimelineSentStatusDraft = 'bills.messages.status.receive.draft'; + $default_key = 'messages.status.receive.draft'; break; default: - $textTimelineSentStatusDraft = 'invoices.messages.status.send.draft'; + $default_key = 'messages.status.send.draft'; break; } - return $textTimelineSentStatusDraft; + $translation = $this->getTextFromConfig($type, 'timeline_sent_status_draft', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.messages.status.send.draft'; } protected function getTextTimelineSentStatusMarkSent($type, $textTimelineSentStatusMarkSent) @@ -1165,14 +1188,20 @@ abstract class DocumentShow extends Component case 'bill': case 'expense': case 'purchase': - $textTimelineSentStatusMarkSent = 'bills.mark_received'; + $default_key = 'mark_received'; break; default: - $textTimelineSentStatusMarkSent = 'invoices.mark_sent'; + $default_key = 'mark_sent'; break; } - return $textTimelineSentStatusMarkSent; + $translation = $this->getTextFromConfig($type, 'timeline_sent_status_mark_sent', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.mark_sent'; } protected function getTextTimelineSentStatusReceived($type, $textTimelineSentStatusReceived) @@ -1185,14 +1214,20 @@ abstract class DocumentShow extends Component case 'bill': case 'expense': case 'purchase': - $textTimelineSentStatusReceived = 'bills.mark_received'; + $textTimelineSentStatusReceived = 'mark_received'; break; default: - $textTimelineSentStatusReceived = 'invoices.mark_sent'; + $textTimelineSentStatusReceived = 'mark_sent'; break; } - return $textTimelineSentStatusReceived; + $translation = $this->getTextFromConfig($type, 'timeline_sent_status_received', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.mark_sent'; } protected function getTextTimelineSendStatusMail($type, $textTimelineSendStatusMail) @@ -1201,18 +1236,13 @@ abstract class DocumentShow extends Component return $textTimelineSendStatusMail; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textTimelineSendStatusMail = 'bills.send_mail'; - break; - default: - $textTimelineSendStatusMail = 'invoices.send_mail'; - break; + $translation = $this->getTextFromConfig($type, 'timeline_sent_status_mail', 'send_mail'); + + if (!empty($translation)) { + return $translation; } - return $textTimelineSendStatusMail; + return 'invoices.send_mail'; } protected function getTextTimelineGetPaidTitle($type, $textTimelineGetPaidTitle) @@ -1225,14 +1255,20 @@ abstract class DocumentShow extends Component case 'bill': case 'expense': case 'purchase': - $textTimelineGetPaidTitle = 'bills.make_payment'; + $default_key = 'make_payment'; break; default: - $textTimelineGetPaidTitle = 'invoices.get_paid'; + $default_key = 'get_paid'; break; } - return $textTimelineGetPaidTitle; + $translation = $this->getTextFromConfig($type, 'timeline_get_paid_title', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.get_paid'; } protected function getTextTimelineGetPaidStatusAwait($type, $textTimelineGetPaidStatusAwait) @@ -1241,18 +1277,13 @@ abstract class DocumentShow extends Component return $textTimelineGetPaidStatusAwait; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textTimelineGetPaidStatusAwait = 'bills.messages.status.paid.await'; - break; - default: - $textTimelineGetPaidStatusAwait = 'invoices.messages.status.paid.await'; - break; + $translation = $this->getTextFromConfig($type, 'timeline_get_paid_status_await', 'messages.status.paid.await'); + + if (!empty($translation)) { + return $translation; } - return $textTimelineGetPaidStatusAwait; + return 'invoices.messages.status.paid.await'; } protected function getTextTimelineGetPaidStatusPartiallyPaid($type, $textTimelineGetPaidStatusPartiallyPaid) @@ -1261,9 +1292,13 @@ abstract class DocumentShow extends Component return $textTimelineGetPaidStatusPartiallyPaid; } - $textTimelineGetPaidStatusPartiallyPaid = 'general.partially_paid'; + $translation = $this->getTextFromConfig($type, 'timeline_get_paid_status_partially_paid', 'partially_paid'); - return $textTimelineGetPaidStatusPartiallyPaid; + if (!empty($translation)) { + return $translation; + } + + return 'general.partially_paid'; } protected function getTextTimelineGetPaidMarkPaid($type, $textTimelineGetPaidMarkPaid) @@ -1272,18 +1307,13 @@ abstract class DocumentShow extends Component return $textTimelineGetPaidMarkPaid; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textTimelineGetPaidMarkPaid = 'bills.mark_paid'; - break; - default: - $textTimelineGetPaidMarkPaid = 'invoices.mark_paid'; - break; + $translation = $this->getTextFromConfig($type, 'timeline_get_paid_mark_paid', 'mark_paid'); + + if (!empty($translation)) { + return $translation; } - return $textTimelineGetPaidMarkPaid; + return 'invoices.mark_paid'; } protected function getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment) @@ -1292,18 +1322,13 @@ abstract class DocumentShow extends Component return $textTimelineGetPaidAddPayment; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textTimelineGetPaidAddPayment = 'bills.add_payment'; - break; - default: - $textTimelineGetPaidAddPayment = 'invoices.add_payment'; - break; + $translation = $this->getTextFromConfig($type, 'timeline_get_paid_add_payment', 'add_payment'); + + if (!empty($translation)) { + return $translation; } - return $textTimelineGetPaidAddPayment; + return 'invoices.add_payment'; } protected function getHideItems($type, $hideItems, $hideName, $hideDescription) diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index bf30fdde2..d9a4dfe97 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -2,15 +2,15 @@ namespace App\Abstracts\View\Components; -use Illuminate\View\Component; -use Illuminate\Support\Str; +use App\Abstracts\View\Components\Document as Base; use App\Traits\DateTime; use App\Models\Common\Media; use File; use Image; use Storage; +use Illuminate\Support\Str; -abstract class DocumentTemplate extends Component +abstract class DocumentTemplate extends Base { use DateTime; @@ -251,18 +251,13 @@ abstract class DocumentTemplate extends Component return $textDocumentNumber; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textDocumentNumber = 'bills.bill_number'; - break; - default: - $textDocumentNumber = 'invoices.invoice_number'; - break; + $translation = $this->getTextFromConfig($type, 'document_number', 'numbers'); + + if (!empty($translation)) { + return $translation; } - return $textDocumentNumber; + return 'general.numbers'; } protected function getTextOrderNumber($type, $textOrderNumber) @@ -271,18 +266,13 @@ abstract class DocumentTemplate extends Component return $textOrderNumber; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textOrderNumber = 'bills.order_number'; - break; - default: - $textOrderNumber = 'invoices.order_number'; - break; + $translation = $this->getTextFromConfig($type, 'order_number'); + + if (!empty($translation)) { + return $translation; } - return $textOrderNumber; + return 'invoices.order_number'; } protected function getTextContactInfo($type, $textContactInfo) @@ -295,14 +285,20 @@ abstract class DocumentTemplate extends Component case 'bill': case 'expense': case 'purchase': - $textContactInfo = 'bills.bill_from'; + $default_key = 'bill_from'; break; default: - $textContactInfo = 'invoices.bill_to'; + $default_key = 'bill_to'; break; } - return $textContactInfo; + $translation = $this->getTextFromConfig($type, 'contact_info', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.bill_to'; } protected function getTextIssuedAt($type, $textIssuedAt) @@ -315,14 +311,20 @@ abstract class DocumentTemplate extends Component case 'bill': case 'expense': case 'purchase': - $textIssuedAt = 'bills.bill_date'; + $default_key = 'bill_date'; break; default: - $textIssuedAt = 'invoices.invoice_date'; + $default_key = 'invoice_date'; break; } - return $textIssuedAt; + $translation = $this->getTextFromConfig($type, 'issued_at', $default_key); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.invoice_date'; } protected function getTextDueAt($type, $textDueAt) @@ -331,18 +333,13 @@ abstract class DocumentTemplate extends Component return $textDueAt; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textDueAt = 'bills.due_date'; - break; - default: - $textDueAt = 'invoices.due_date'; - break; + $translation = $this->getTextFromConfig($type, 'due_at', 'due_date'); + + if (!empty($translation)) { + return $translation; } - return $textDueAt; + return 'invoices.due_date'; } protected function getTextItems($type, $textItems) @@ -351,22 +348,18 @@ abstract class DocumentTemplate extends Component return $textItems; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textItems = 'general.items'; - break; - default: - $textItems = setting('invoice.item_name', 'general.items'); - - if ($textItems == 'custom') { - $textItems = setting('invoice.item_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.item_name', 'items') == 'custom') { + return setting($type . '.item_name_input'); } - return $textItems; + $translation = $this->getTextFromConfig($type, 'items'); + + if (!empty($translation)) { + return $translation; + } + + return 'general.items'; } protected function getTextQuantity($type, $textQuantity) @@ -375,46 +368,38 @@ abstract class DocumentTemplate extends Component return $textQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $textQuantity = 'bills.quantity'; - break; - default: - $textQuantity = setting('invoice.quantity_name', 'invoices.quantity'); - - if ($textQuantity == 'custom') { - $textQuantity = setting('invoice.quantity_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.quantity_name', 'quantity') == 'custom') { + return setting($type . '.quantity_name_input'); } - return $textQuantity; + $translation = $this->getTextFromConfig($type, 'quantity'); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.quantity'; } - protected function getTextPrice($type, $text_price) + protected function getTextPrice($type, $textPrice) { - if (!empty($text_price)) { - return $text_price; + if (!empty($textPrice)) { + return $textPrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $text_price = 'bills.price'; - break; - default: - $text_price = setting('invoice.price_name', 'invoices.price'); - - if ($text_price == 'custom') { - $text_price = setting('invoice.price_name_input'); - } - break; + // if you use settting translation + if (setting($type . '.price_name', 'price') == 'custom') { + return setting($type . '.price_name_input'); } - return $text_price; + $translation = $this->getTextFromConfig($type, 'price'); + + if (!empty($translation)) { + return $translation; + } + + return 'invoices.price'; } protected function getTextAmount($type, $textAmount) @@ -423,9 +408,13 @@ abstract class DocumentTemplate extends Component return $textAmount; } - $textAmount = 'general.amount'; + $translation = $this->getTextFromConfig($type, 'amount'); - return $textAmount; + if (!empty($translation)) { + return $translation; + } + + return 'general.amount'; } protected function getHideItems($type, $hideItems, $hideName, $hideDescription) diff --git a/config/type.php b/config/type.php index 50a0a1006..9f4196d7f 100644 --- a/config/type.php +++ b/config/type.php @@ -3,42 +3,82 @@ use App\Models\Document\Document; return [ + // Documents Document::INVOICE_TYPE => [ - 'group' => 'sales', - 'route_name' => 'invoices', - 'route_parameter' => 'invoice', - 'permission_name' => 'sales-invoices', - 'translation_key' => 'invoices', - 'contact_type' => 'customer', + 'alias' => '', // core empty but module write own alias + 'group' => 'sales', // controller folder name for permission and route + 'route' => [ + 'prefix' => 'invoices', // core use with group + prefix, module ex. estimates + 'paramater' => 'invoice', // sales/invoices/{parameter}/edit + //'create' => 'invoices.create', // if you change route, you can write full path + ], + 'permission' => [ + 'prefix' => 'invoices', // this controller file name. + //'create' => 'create-sales-invoices', // if you change action permission key, you can write full permission + ], + 'translation' => [ + 'prefix' => 'invoices', // this translation file name. + 'add_contact' => 'general.customers', // + 'issued_at' => 'invoices.invoice_date', + 'due_at' => 'invoices.due_date', + ], + 'contact_type' => 'customer', // use contact type ], Document::BILL_TYPE => [ + 'alias' => '', 'group' => 'purchases', - 'route_name' => 'bills', - 'route_parameter' => 'bill', - 'permission_name' => 'purchases-bills', - 'translation_key' => 'bills', + 'route' => [ + 'prefix' => 'bills', + 'paramater' => 'bill', + //'create' => 'bilss.create', + ], + 'permission' => [ + 'prefix' => 'bills', + //'create' => 'create-purchases-bills', + ], + 'translation' => [ + 'prefix' => 'bills', + 'issued_at' => 'bills.bill_date', + 'due_at' => 'bills.due_date', + ], 'contact_type' => 'vendor', ], // Contacts 'customer' => [ - 'permission_name' => 'sales-customers', + 'group' => 'sales', + 'permission' => [ + 'prefix' => 'customers', + //'create' => 'create-sales-customers', + ], ], 'vendor' => [ - 'permission_name' => 'purchases-vendors', + 'group' => 'purchases', + 'permission' => [ + 'prefix' => 'vendors', + //'create' => 'create-purchases-vendors', + ], ], // Transactions 'income' => [ - 'permission_name' => 'sales-revenues', + 'group' => 'sales', + 'permission' => [ + 'prefix' => 'revenues', + //'create' => 'create-sales-revenues', + ], 'contact_type' => 'customer', ], 'expense' => [ - 'permission_name' => 'purchases-payments', + 'group' => 'purchases', + 'permission' => [ + 'prefix' => 'payments', + //'create' => 'create-purchases-payments', + ], 'contact_type' => 'vendor', ], ]; diff --git a/resources/views/components/documents/form/content.blade.php b/resources/views/components/documents/form/content.blade.php index ec74b2f6a..2dde4f456 100644 --- a/resources/views/components/documents/form/content.blade.php +++ b/resources/views/components/documents/form/content.blade.php @@ -1,6 +1,6 @@ @if (empty($document)) {!! Form::open([ - 'route' => $formRoute, + 'route' => $routeStore, 'id' => $formId, '@submit.prevent' => $formSubmit, '@keydown' => 'form.errors.clear($event.target.name)', @@ -11,7 +11,7 @@ ]) !!} @else {!! Form::model($document, [ - 'route' => [$formRoute, $document->id], + 'route' => [$routeUpdate, $document->id], 'id' => $formId, 'method' => 'PATCH', '@submit.prevent' => $formSubmit, From 78996c35ddc88605d90d2261475946d9f81fcc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 18:24:16 +0300 Subject: [PATCH 02/37] Document text dynamic fixed.. --- .../View/Components/DocumentForm.php | 19 ++++++++------ .../View/Components/DocumentIndex.php | 25 ++++++++++++++----- .../View/Components/DocumentShow.php | 10 ++++---- .../View/Components/DocumentTemplate.php | 13 +++++++++- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index c105fdbed..25e704ee4 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -8,6 +8,7 @@ use App\Models\Document\Document; use App\Traits\Documents; use Date; use Illuminate\Support\Str; + abstract class DocumentForm extends Base { use Documents; @@ -405,7 +406,9 @@ abstract class DocumentForm extends Base return $textAddContact; } - $translation = $this->getTextFromConfig($type, 'add_contact', Str::plural($this->contactType, 2), 'trans_choice'); + $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); + + $translation = $this->getTextFromConfig($type, 'add_contact', $default_key, 'trans_choice'); if (!empty($translation)) { return [ @@ -426,9 +429,9 @@ abstract class DocumentForm extends Base return $textCreateNewContact; } - $contact_type = Str::plural(config('type.' . $type . '.contact_type'), 2); + $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); - $translation = $this->getTextFromConfig($type, 'create_new_contact', $contact_type, 'trans_choice'); + $translation = $this->getTextFromConfig($type, 'create_new_contact', $default_key, 'trans_choice'); if (!empty($translation)) { return [ @@ -490,7 +493,9 @@ abstract class DocumentForm extends Base return $textChooseDifferentContact; } - $translation = $this->getTextFromConfig($type, 'choose_different_contact', Str::plural($this->contactType, 2), 'trans_choice'); + $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); + + $translation = $this->getTextFromConfig($type, 'choose_different_contact', $default_key, 'trans_choice'); if (!empty($translation)) { return [ @@ -732,10 +737,10 @@ abstract class DocumentForm extends Base return 'invoices.price'; } - protected function getTextAmount($type, $text_amount) + protected function getTextAmount($type, $textAmount) { - if (!empty($text_amount)) { - return $text_amount; + if (!empty($textAmount)) { + return $textAmount; } $translation = $this->getTextFromConfig($type, 'amount'); diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 4e72d5a3c..38b4be305 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -427,8 +427,10 @@ abstract class DocumentIndex extends Base if (!empty($textBulkAction)) { return $textBulkAction; } + + $default_key = config('type.' . $type . '.translation.prefix'); - $translation = $this->getTextFromConfig($type, 'bulk_action', Str::plural($type, 2)); + $translation = $this->getTextFromConfig($type, 'bulk_action', $default_key, 'trans_choice'); if (!empty($translation)) { return $translation; @@ -529,9 +531,9 @@ abstract class DocumentIndex extends Base return $textContactName; } - $contact_type = Str::plural(config('type.' . $type . '.contact_type'), 2); + $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2); - $translation = $this->getTextFromConfig($type, 'contact_name', $contact_type, 'trans_choice'); + $translation = $this->getTextFromConfig($type, 'contact_name', $default_key, 'trans_choice'); if (!empty($translation)) { return $translation; @@ -572,7 +574,18 @@ abstract class DocumentIndex extends Base return $textIssuedAt; } - $translation = $this->getTextFromConfig($type, 'issued_at'); + switch ($type) { + case 'bill': + case 'expense': + case 'purchase': + $default_key = 'bill_date'; + break; + default: + $default_key = 'invoice_date'; + break; + } + + $translation = $this->getTextFromConfig($type, 'issued_at', $default_key); if (!empty($translation)) { return $translation; @@ -600,7 +613,7 @@ abstract class DocumentIndex extends Base return $textDueAt; } - $translation = $this->getTextFromConfig($type, 'due_at'); + $translation = $this->getTextFromConfig($type, 'due_at', 'due_date'); if (!empty($translation)) { return $translation; @@ -628,7 +641,7 @@ abstract class DocumentIndex extends Base return $textDocumentStatus; } - $default_key = config("type.' . $type . '.translation.prefix") . '.statuses.'; + $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; $translation = $this->getTextFromConfig($type, 'document_status', $default_key); diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 22bf9cdea..9663d56a5 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -521,7 +521,7 @@ abstract class DocumentShow extends Base return $textRecurringType; } - $default_key = config("type.' . $type . '.translation.prefix"); + $default_key = config('type.' . $type . '.translation.prefix'); $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key); @@ -538,7 +538,7 @@ abstract class DocumentShow extends Base return $textStatusMessage; } - $default_key = config("type.' . $type . '.translation.prefix") . '.messages.draft'; + $default_key = config('type.' . $type . '.translation.prefix') . '.messages.draft'; $translation = $this->getTextFromConfig($type, 'status_message', $default_key); @@ -628,7 +628,7 @@ abstract class DocumentShow extends Base return $textHistories; } - $default_key = config("type.' . $type . '.translation.prefix") . '.histories'; + $default_key = config('type.' . $type . '.translation.prefix') . '.histories'; $translation = $this->getTextFromConfig($type, 'histories', $default_key); @@ -645,9 +645,9 @@ abstract class DocumentShow extends Base return $textHistoryStatus; } - $default_key = config("type.' . $type . '.translation.prefix") . '.statuses.'; + $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; - $translation = $this->getTextFromConfig($type, 'statuses', $default_key); + $translation = $this->getTextFromConfig($type, 'history_status', $default_key); if (!empty($translation)) { return $translation; diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index d9a4dfe97..be651ab39 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -251,7 +251,18 @@ abstract class DocumentTemplate extends Base return $textDocumentNumber; } - $translation = $this->getTextFromConfig($type, 'document_number', 'numbers'); + switch ($type) { + case 'bill': + case 'expense': + case 'purchase': + $default_key = 'bill_number'; + break; + default: + $default_key = 'invoice_number'; + break; + } + + $translation = $this->getTextFromConfig($type, 'document_number', $default_key); if (!empty($translation)) { return $translation; From 0a4e5cd0d6ac3483cd0c8d60ab2b3950adde02a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 18:56:11 +0300 Subject: [PATCH 03/37] Config type add hide for Document item columns.. --- app/Abstracts/View/Components/Document.php | 17 +- .../View/Components/DocumentForm.php | 132 +++++----- .../View/Components/DocumentShow.php | 234 +++++++++--------- .../View/Components/DocumentTemplate.php | 132 +++++----- config/type.php | 2 + 5 files changed, 283 insertions(+), 234 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index f1b441605..ac4aaa739 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -62,9 +62,7 @@ abstract class Document extends Component return $route; } - $prefix = config("type.' . $type . '.route.prefix"); - - + $prefix = config("type.' . $type . '.route.prefix"); } public function getPermissionFromConfig($type, $config_key, $action) @@ -96,4 +94,17 @@ abstract class Document extends Component return $permission; } + + public function getHideFromConfig($type, $config_key) + { + $hide = false; + + $hides = config('type.' . $type . '.hide'); + + if (!empty($hides) && (in_array($config_key, $hides))) { + $hide = true; + } + + return $hide; + } } diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 25e704ee4..79a1d9299 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -758,6 +758,12 @@ abstract class DocumentForm extends Base return $hideItems; } + $hide = $this->getHideFromConfig($type, 'items'); + + if ($hide) { + return $hide; + } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; return $hideItems; @@ -769,18 +775,19 @@ abstract class DocumentForm extends Base return $hideName; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; } - return $hideName; + $hide = $this->getHideFromConfig($type, 'name'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); } protected function getHideDescription($type, $hideDescription) @@ -789,18 +796,19 @@ abstract class DocumentForm extends Base return $hideDescription; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; } - return $hideDescription; + $hide = $this->getHideFromConfig($type, 'description'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); } protected function getHideQuantity($type, $hideQuantity) @@ -809,18 +817,19 @@ abstract class DocumentForm extends Base return $hideQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; } - return $hideQuantity; + $hide = $this->getHideFromConfig($type, 'quantity'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); } protected function getHidePrice($type, $hidePrice) @@ -829,18 +838,19 @@ abstract class DocumentForm extends Base return $hidePrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; } - return $hidePrice; + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); } protected function getHideDiscount($type, $hideDiscount) @@ -849,18 +859,19 @@ abstract class DocumentForm extends Base return $hideDiscount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; } - return $hideDiscount; + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); } protected function getHideAmount($type, $hideAmount) @@ -869,17 +880,18 @@ abstract class DocumentForm extends Base return $hideAmount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; } - return $hideAmount; + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); } } diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 9663d56a5..4c0e582ef 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -1317,7 +1317,7 @@ abstract class DocumentShow extends Base } protected function getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment) - { + { if (!empty($textTimelineGetPaidAddPayment)) { return $textTimelineGetPaidAddPayment; } @@ -1331,134 +1331,146 @@ abstract class DocumentShow extends Base return 'invoices.add_payment'; } - protected function getHideItems($type, $hideItems, $hideName, $hideDescription) - { - if (!empty($hideItems)) { - return $hideItems; - } + protected function getHideItems($type, $hideItems, $hideName, $hideDescription) + { + if (!empty($hideItems)) { + return $hideItems; + } - $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; + $hide = $this->getHideFromConfig($type, 'items'); - return $hideItems; - } + if ($hide) { + return $hide; + } - protected function getHideName($type, $hideName) - { - if (!empty($hideName)) { - return $hideName; - } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; - } + return $hideItems; + } - return $hideName; - } + protected function getHideName($type, $hideName) + { + if (!empty($hideName)) { + return $hideName; + } - protected function getHideDescription($type, $hideDescription) - { - if (!empty($hideDescription)) { - return $hideDescription; - } + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; - } + $hide = $this->getHideFromConfig($type, 'name'); - return $hideDescription; - } + if ($hide) { + return $hide; + } - protected function getHideQuantity($type, $hideQuantity) - { - if (!empty($hideQuantity)) { - return $hideQuantity; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; - } + protected function getHideDescription($type, $hideDescription) + { + if (!empty($hideDescription)) { + return $hideDescription; + } - return $hideQuantity; - } + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; + } - protected function getHidePrice($type, $hidePrice) - { - if (!empty($hidePrice)) { - return $hidePrice; - } + $hide = $this->getHideFromConfig($type, 'description'); - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; - } + if ($hide) { + return $hide; + } - return $hidePrice; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); + } - protected function getHideDiscount($type, $hideDiscount) - { - if (!empty($hideDiscount)) { - return $hideDiscount; - } + protected function getHideQuantity($type, $hideQuantity) + { + if (!empty($hideQuantity)) { + return $hideQuantity; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; - } + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; + } - return $hideDiscount; - } + $hide = $this->getHideFromConfig($type, 'quantity'); - protected function getHideAmount($type, $hideAmount) - { - if (!empty($hideAmount)) { - return $hideAmount; - } + if ($hide) { + return $hide; + } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; - } + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); + } - return $hideAmount; - } + protected function getHidePrice($type, $hidePrice) + { + if (!empty($hidePrice)) { + return $hidePrice; + } + + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; + } + + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); + } + + protected function getHideDiscount($type, $hideDiscount) + { + if (!empty($hideDiscount)) { + return $hideDiscount; + } + + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; + } + + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); + } + + protected function getHideAmount($type, $hideAmount) + { + if (!empty($hideAmount)) { + return $hideAmount; + } + + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; + } + + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); + } } diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index be651ab39..a7695d584 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -434,6 +434,12 @@ abstract class DocumentTemplate extends Base return $hideItems; } + $hide = $this->getHideFromConfig($type, 'items'); + + if ($hide) { + return $hide; + } + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; return $hideItems; @@ -445,18 +451,19 @@ abstract class DocumentTemplate extends Base return $hideName; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - default: - $hideName = setting('invoice.hide_item_name', $hideName); - break; + // if you use settting translation + if ($hideName = setting($type . '.hide_item_name', false)) { + return $hideName; } - return $hideName; + $hide = $this->getHideFromConfig($type, 'name'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_name', $hideName); } protected function getHideDescription($type, $hideDescription) @@ -465,18 +472,19 @@ abstract class DocumentTemplate extends Base return $hideDescription; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - default: - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; + // if you use settting translation + if ($hideDescription = setting($type . '.hide_item_description', false)) { + return $hideDescription; } - return $hideDescription; + $hide = $this->getHideFromConfig($type, 'description'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_item_description', $hideDescription); } protected function getHideQuantity($type, $hideQuantity) @@ -485,18 +493,19 @@ abstract class DocumentTemplate extends Base return $hideQuantity; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - default: - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; + // if you use settting translation + if ($hideQuantity = setting($type . '.hide_quantity', false)) { + return $hideQuantity; } - return $hideQuantity; + $hide = $this->getHideFromConfig($type, 'quantity'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_quantity', $hideQuantity); } protected function getHidePrice($type, $hidePrice) @@ -505,18 +514,19 @@ abstract class DocumentTemplate extends Base return $hidePrice; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - default: - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; + // if you use settting translation + if ($hidePrice = setting($type . '.hide_price', false)) { + return $hidePrice; } - return $hidePrice; + $hide = $this->getHideFromConfig($type, 'price'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_price', $hidePrice); } protected function getHideDiscount($type, $hideDiscount) @@ -525,18 +535,19 @@ abstract class DocumentTemplate extends Base return $hideDiscount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - default: - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; + // if you use settting translation + if ($hideDiscount = setting($type . '.hide_discount', false)) { + return $hideDiscount; } - return $hideDiscount; + $hide = $this->getHideFromConfig($type, 'discount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_discount', $hideDiscount); } protected function getHideAmount($type, $hideAmount) @@ -545,17 +556,18 @@ abstract class DocumentTemplate extends Base return $hideAmount; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - default: - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; + // if you use settting translation + if ($hideAmount = setting($type . '.hide_amount', false)) { + return $hideAmount; } - return $hideAmount; + $hide = $this->getHideFromConfig($type, 'amount'); + + if ($hide) { + return $hide; + } + + // @todo what return value invoice or always false?? + return setting('invoice.hide_amount', $hideAmount); } } diff --git a/config/type.php b/config/type.php index 9f4196d7f..be730bfc7 100644 --- a/config/type.php +++ b/config/type.php @@ -24,6 +24,7 @@ return [ 'due_at' => 'invoices.due_date', ], 'contact_type' => 'customer', // use contact type + 'hide' => [], // for document items ], Document::BILL_TYPE => [ @@ -44,6 +45,7 @@ return [ 'due_at' => 'bills.due_date', ], 'contact_type' => 'vendor', + 'hide' => [], ], // Contacts From fd2054cebe898bc9ad71d6441c77d0313851a588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 19:16:30 +0300 Subject: [PATCH 04/37] add permission dynamic.. --- app/Abstracts/View/Components/Document.php | 6 +- .../View/Components/DocumentIndex.php | 39 +------------ .../View/Components/DocumentShow.php | 56 ++----------------- 3 files changed, 11 insertions(+), 90 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index ac4aaa739..f0528be48 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -62,10 +62,10 @@ abstract class Document extends Component return $route; } - $prefix = config("type.' . $type . '.route.prefix"); + $prefix = config("type.' . $type . '.route.prefix"); } - public function getPermissionFromConfig($type, $config_key, $action) + public function getPermissionFromConfig($type, $config_key) { $permission = ''; @@ -78,7 +78,7 @@ abstract class Document extends Component $group = config('type.' . $type . '.group'); $prefix = config("type.' . $type . '.permission.prefix"); - $permission = $action . '-'; + $permission = $config_key . '-'; // if use module set module alias if (!empty($alias)) { diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 38b4be305..01cef1431 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -794,18 +794,7 @@ abstract class DocumentIndex extends Base return $permissionCreate; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionCreate = 'create-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionCreate = 'create-purchases-bills'; - break; - } + $permissionCreate = $this->getPermissionFromConfig($type, 'create'); return $permissionCreate; } @@ -816,18 +805,7 @@ abstract class DocumentIndex extends Base return $permissionUpdate; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionUpdate = 'update-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionUpdate = 'update-purchases-bills'; - break; - } + $permissionUpdate = $this->getPermissionFromConfig($type, 'update'); return $permissionUpdate; } @@ -838,18 +816,7 @@ abstract class DocumentIndex extends Base return $permissionDelete; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionDelete = 'delete-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionDelete = 'delete-purchases-bills'; - break; - } + $permissionDelete = $this->getPermissionFromConfig($type, 'delete'); return $permissionDelete; } diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 4c0e582ef..3181c9552 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -470,8 +470,6 @@ abstract class DocumentShow extends Base $this->textTimelineGetPaidMarkPaid = $this->getTextTimelineGetPaidMarkPaid($type, $textTimelineGetPaidMarkPaid); $this->textTimelineGetPaidAddPayment = $this->getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment); - $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate); - $this->routeButtonSent = $this->getRouteButtonSent($type, $routeButtonSent); $this->routeButtonReceived = $this->getRouteButtonReceived($type, $routeButtonReceived); $this->routeButtonEmail = $this->getRouteButtonEmail($type, $routeButtonEmail); @@ -918,18 +916,7 @@ abstract class DocumentShow extends Base return $permissionCreate; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionCreate = 'create-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionCreate = 'create-purchases-bills'; - break; - } + $permissionCreate = $this->getPermissionFromConfig($type, 'create'); return $permissionCreate; } @@ -940,18 +927,7 @@ abstract class DocumentShow extends Base return $permissionUpdate; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionUpdate = 'update-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionUpdate = 'update-purchases-bills'; - break; - } + $permissionUpdate = $this->getPermissionFromConfig($type, 'update'); return $permissionUpdate; } @@ -962,18 +938,7 @@ abstract class DocumentShow extends Base return $permissionDelete; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionDelete = 'delete-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionDelete = 'delete-purchases-bills'; - break; - } + $permissionDelete = $this->getPermissionFromConfig($type, 'delete'); return $permissionDelete; } @@ -984,20 +949,9 @@ abstract class DocumentShow extends Base return $permissionButtonCustomize; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $permissionButtonCustomize = 'update-sales-invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $permissionButtonCustomize = 'update-purchases-bills'; - break; - } + $permissionUpdate = $this->getPermissionFromConfig($type, 'update'); - return $permissionButtonCustomize; + return $permissionUpdate; } protected function getTextHeaderContact($type, $textHeaderContact) From 7f318911fd4c2e34e5d5b9a5093abe3f0889b7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 20:38:45 +0300 Subject: [PATCH 05/37] Config route get dynamic.. --- app/Abstracts/View/Components/Document.php | 20 +- .../View/Components/DocumentForm.php | 54 ++---- .../View/Components/DocumentIndex.php | 144 +++++++------- .../View/Components/DocumentShow.php | 178 +++++++----------- 4 files changed, 160 insertions(+), 236 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index f0528be48..2439cd802 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -53,7 +53,7 @@ abstract class Document extends Component return $translation; } - public function getRouteFromConfig($type, $config_key) + public function getRouteFromConfig($type, $config_key, $config_parameters = []) { $route = ''; @@ -62,7 +62,23 @@ abstract class Document extends Component return $route; } - $prefix = config("type.' . $type . '.route.prefix"); + $prefix = config('type.' . $type . '.route.prefix'); + + $route = $prefix . '.' . $config_key; + + try { + route($route, $config_parameters); + } catch (\Exception $e) { + try { + $route = Str::plural($type, 2) . '.' . $config_key; + + route($route, $config_parameters); + } catch (\Exception $e) { + $route = ''; + } + } + + return $route; } public function getPermissionFromConfig($type, $config_key) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 79a1d9299..3510ec501 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -294,27 +294,13 @@ abstract class DocumentForm extends Base return $routeStore; } - if ($route = config("type.{$type}.route.store")) { + $route = $this->getRouteFromConfig($type, 'store'); + + if (!empty($route)) { return $route; } - $prefix = config("type.{$type}.route.prefix"); - - $route = $prefix . '.store'; - - try { - route($route); - } catch (\Exception $e) { - try { - $route = Str::plural($type, 2) . '.store'; - - route($route); - } catch (\Exception $e) { - $route = ''; - } - } - - return $route; + return 'invoices.store'; } protected function getRouteUpdate($type, $routeUpdate, $document, $parameters = []) @@ -323,33 +309,17 @@ abstract class DocumentForm extends Base return $routeUpdate; } - if ($route = config("type.{$type}.route.update")) { + $parameters = [ + config('type.' . $type. '.route.parameter') => $document->id + ]; + + $route = $this->getRouteFromConfig($type, 'update', $parameters); + + if (!empty($route)) { return $route; } - $prefix = config("type.{$type}.route.prefix"); - - $route = $prefix . '.update'; - - if (!empty($parameters)) { - $parameters = [ - config("type.{$type}.route.parameter") => $document->id - ]; - } - - try { - route($route, $parameters); - } catch (\Exception $e) { - try { - $route = Str::plural($type, 2) . '.update'; - - route($route, $parameters); - } catch (\Exception $e) { - $route = ''; - } - } - - return $route; + return 'invoices.update'; } protected function getContacts($type, $contacts) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 01cef1431..38a386251 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -267,7 +267,7 @@ abstract class DocumentIndex extends Base $this->classDocumentNumber = $this->getClassDocumentNumber($type, $classDocumentNumber); $this->classContactName = $this->getClassContactName($type, $classContactName); $this->classAmount = $this->getClassAmount($type, $classAmount); - $this->classIssuedAt = $this->getclassIssuedAt($type, $classIssuedAt); + $this->classIssuedAt = $this->getClassIssuedAt($type, $classIssuedAt); $this->classDueAt = $this->getClassDueAt($type, $classDueAt); $this->classStatus = $this->getClassStatus($type, $classStatus); $this->classActions = $this->getClassActions($type, $classActions); @@ -292,6 +292,12 @@ abstract class DocumentIndex extends Base return $page; } + $route = $this->getRouteFromConfig($type, 'update'); + + if (!empty($route)) { + return $route; + } + return config("type.{$type}.route.prefix"); } @@ -323,17 +329,13 @@ abstract class DocumentIndex extends Base return $createRoute; } - $page = config("type.{$type}.route.prefix"); + $route = $this->getRouteFromConfig($type, 'create'); - $route = $page . '.create'; - - try { - route($route); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.create'; } protected function getImportRoute($importRoute) @@ -353,10 +355,12 @@ abstract class DocumentIndex extends Base return $importRouteParameters; } + $route = $this->getRouteFromConfig($type, 'import'); + $importRouteParameters = [ - 'group' => config("type.{$type}.group"), - 'type' => config("type.{$type}.route.prefix"), - 'route' => 'invoices.import', + 'group' => config('type.' . $type . '.group'), + 'type' => config('type.' . $type . '.route.prefix'), + 'route' => ($route) ? $route : 'invoices.import', ]; return $importRouteParameters; @@ -368,17 +372,13 @@ abstract class DocumentIndex extends Base return $exportRoute; } - $page = config("type.{$type}.route.prefix"); + $route = $this->getRouteFromConfig($type, 'export'); - $route = $page . '.export'; - - try { - route($route); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.export'; } protected function getRoute($type, $formCardHeaderRoute) @@ -387,17 +387,13 @@ abstract class DocumentIndex extends Base return $formCardHeaderRoute; } - $page = config("type.{$type}.route.prefix"); + $route = $this->getRouteFromConfig($type, 'index'); - $route = $page . '.index'; - - try { - route($route); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.index'; } protected function getSearchStringModel($type, $searchStringModel) @@ -480,9 +476,15 @@ abstract class DocumentIndex extends Base return $bulkActionRouteParameters; } + $group = config('type.' . $type . '.group'); + + if (!empty(config('type.' . $type . '.alias'))) { + $group = config('type.' . $type . '.alias'); + } + $bulkActionRouteParameters = [ - 'group' => config("type.{$type}.group"), - 'type' => config("type.{$type}.route.prefix") + 'group' => $group, + 'type' => config('type.' . $type . '.route.prefix') ]; return $bulkActionRouteParameters; @@ -594,7 +596,7 @@ abstract class DocumentIndex extends Base return 'invoices.invoice_date'; } - protected function getclassIssuedAt($type, $classIssuedAt) + protected function getClassIssuedAt($type, $classIssuedAt) { if (!empty($classIssuedAt)) { return $classIssuedAt; @@ -684,20 +686,16 @@ abstract class DocumentIndex extends Base return $routeButtonShow; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.show'; + $route = $this->getRouteFromConfig($type, 'show', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.show'; } protected function getRouteButtonEdit($type, $routeButtonEdit) @@ -706,20 +704,16 @@ abstract class DocumentIndex extends Base return $routeButtonEdit; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.edit'; + $route = $this->getRouteFromConfig($type, 'edit', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.edit'; } protected function getRouteButtonDuplicate($type, $routeButtonDuplicate) @@ -728,20 +722,16 @@ abstract class DocumentIndex extends Base return $routeButtonDuplicate; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.duplicate'; + $route = $this->getRouteFromConfig($type, 'duplicate', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.duplicate'; } protected function getRouteButtonCancelled($type, $routeButtonCancelled) @@ -750,20 +740,16 @@ abstract class DocumentIndex extends Base return $routeButtonCancelled; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.cancelled'; + $route = $this->getRouteFromConfig($type, 'cancelled', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.cancelled'; } protected function getRouteButtonDelete($type, $routeButtonDelete) @@ -772,20 +758,16 @@ abstract class DocumentIndex extends Base return $routeButtonDelete; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.destroy'; + $route = $this->getRouteFromConfig($type, 'destroy', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.destroy'; } protected function getPermissionCreate($type, $permissionCreate) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 3181c9552..0ee098c77 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -605,7 +605,7 @@ abstract class DocumentShow extends Base return $signedUrl; } - $page = config("type.{$type}.route.prefix"); + $page = config('type.' . $type . '.route.prefix'); $route = 'signed.' . $page . '.show'; @@ -614,7 +614,7 @@ abstract class DocumentShow extends Base $signedUrl = URL::signedRoute($route, [$this->document->id, 'company_id' => session('company_id')]); } catch (\Exception $e) { - $route = ''; + $signedUrl = URL::signedRoute('signed.invoices.show', [$this->document->id, 'company_id' => session('company_id')]); } return $signedUrl; @@ -660,17 +660,13 @@ abstract class DocumentShow extends Base return $routeButtonAddNew; } - $page = config("type.{$type}.route.prefix"); + $route = $this->getRouteFromConfig($type, 'create'); - $route = $page . '.create'; - - try { - route($route); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.create'; } protected function getRouteButtonEdit($type, $routeButtonEdit) @@ -679,20 +675,16 @@ abstract class DocumentShow extends Base return $routeButtonEdit; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.edit'; + $route = $this->getRouteFromConfig($type, 'edit', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.edit'; } protected function getRouteButtonDuplicate($type, $routeButtonDuplicate) @@ -701,20 +693,16 @@ abstract class DocumentShow extends Base return $routeButtonDuplicate; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.duplicate'; + $route = $this->getRouteFromConfig($type, 'duplicate', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.duplicate'; } protected function getRouteButtonPrint($type, $routeButtonPrint) @@ -723,20 +711,16 @@ abstract class DocumentShow extends Base return $routeButtonPrint; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.print'; + $route = $this->getRouteFromConfig($type, 'print', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.print'; } protected function getRouteButtonPdf($type, $routeButtonPdf) @@ -745,20 +729,16 @@ abstract class DocumentShow extends Base return $routeButtonPdf; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.pdf'; + $route = $this->getRouteFromConfig($type, 'pdf', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.pdf'; } protected function getRouteButtonCancelled($type, $routeButtonCancelled) @@ -767,20 +747,16 @@ abstract class DocumentShow extends Base return $routeButtonCancelled; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.cancelled'; + $route = $this->getRouteFromConfig($type, 'cancelled', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.cancelled'; } protected function getRouteButtonCustomize($type, $routeButtonCustomize) @@ -794,7 +770,7 @@ abstract class DocumentShow extends Base try { route($route); } catch (\Exception $e) { - $route = ''; + $route = 'settings.invoice.edit'; } return $route; @@ -806,20 +782,16 @@ abstract class DocumentShow extends Base return $routeButtonDelete; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.destroy'; + $route = $this->getRouteFromConfig($type, 'destroy', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.destroy'; } protected function getRouteButtonPaid($type, $routeButtonPaid) @@ -828,20 +800,16 @@ abstract class DocumentShow extends Base return $routeButtonPaid; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.paid'; + $route = $this->getRouteFromConfig($type, 'paid', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.paid'; } protected function getRouteButtonSent($type, $routeButtonSent) @@ -850,20 +818,16 @@ abstract class DocumentShow extends Base return $routeButtonSent; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.sent'; + $route = $this->getRouteFromConfig($type, 'sent', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.sent'; } protected function getRouteButtonReceived($type, $routeButtonReceived) @@ -872,20 +836,16 @@ abstract class DocumentShow extends Base return $routeButtonReceived; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.received'; + $route = $this->getRouteFromConfig($type, 'received', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.received'; } protected function getRouteButtonEmail($type, $routeButtonEmail) @@ -894,20 +854,16 @@ abstract class DocumentShow extends Base return $routeButtonEmail; } - $page = config("type.{$type}.route.prefix"); + //example route parameter. + $parameter = 1; - $route = $page . '.email'; + $route = $this->getRouteFromConfig($type, 'email', $parameter); - try { - //example route parameter. - $parameter = 1; - - route($route, $parameter); - } catch (\Exception $e) { - $route = ''; + if (!empty($route)) { + return $route; } - return $route; + return 'invoices.email'; } protected function getPermissionCreate($type, $permissionCreate) From 12e063eaff8e246d8cb17f533fdf9de37f77b5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 22:31:26 +0300 Subject: [PATCH 06/37] document typo.. --- app/Abstracts/View/Components/Document.php | 7 + .../View/Components/DocumentForm.php | 44 +++--- .../View/Components/DocumentIndex.php | 126 ++++++++++++++---- .../View/Components/DocumentShow.php | 40 ++++-- .../View/Components/DocumentTemplate.php | 29 ++-- 5 files changed, 163 insertions(+), 83 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index 2439cd802..c8a129019 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -123,4 +123,11 @@ abstract class Document extends Component return $hide; } + + public function getClassFromConfig($type, $config_key) + { + $class_key = 'type.' . $type . '.class.' . $config_key; + + return config($class_key, ''); + } } diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 3510ec501..4de0c323b 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -360,14 +360,14 @@ abstract class DocumentForm extends Base return $contact_type; } - if ($contact_type = config("type.{$type}.contact_type")) { + if ($contact_type = config('type.' . $type . '.contact_type')) { return $contact_type; } // set default type $type = Document::INVOICE_TYPE; - return config("type.{$type}.contact_type"); + return config('type.' . $type . '.contact_type'); } protected function getTextAddContact($type, $textAddContact) @@ -480,28 +480,25 @@ abstract class DocumentForm extends Base ]; } - protected function getIssuedAt($type, $document, $issued_at) + protected function getIssuedAt($type, $document, $issuedAt) { - if (!empty($issued_at)) { - return $issued_at; + if (!empty($issuedAt)) { + return $issuedAt; } if ($document) { return $document->issued_at; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $issued_at = request()->get('billed_at', Date::now()->toDateString()); - break; - default: - $issued_at = request()->get('invoiced_at', Date::now()->toDateString()); - break; + $issued_at = $type . '_at'; + + if (request()->has($issued_at)) { + $issuedAt = request()->get($issued_at); + } else { + request()->get('invoiced_at', Date::now()->toDateString()); } - return $issued_at; + return $issuedAt; } protected function getDocumentNumber($type, $document, $document_number) @@ -514,15 +511,10 @@ abstract class DocumentForm extends Base return $document->document_number; } - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $document_number = $this->getNextDocumentNumber(Document::BILL_TYPE); - break; - default: - $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE); - break; + $document_number = $this->getNextDocumentNumber($type); + + if (empty($document_number)) { + $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE); } return $document_number; @@ -537,6 +529,8 @@ abstract class DocumentForm extends Base if ($document) { return $document->due_at; } + + $addDays = (setting($type . '.payment_terms', 0)) ? setting($type . '.payment_terms', 0) : setting('invoice.payment_terms', 0); switch ($type) { case 'bill': @@ -545,7 +539,7 @@ abstract class DocumentForm extends Base $due_at = request()->get('billed_at', Date::now()->toDateString()); break; default: - $due_at = Date::parse(request()->get('invoiced_at', Date::now()->toDateString()))->addDays(setting('invoice.payment_terms', 0))->toDateString(); + $due_at = Date::parse(request()->get('invoiced_at', Date::now()->toDateString()))->addDays($addDays)->toDateString(); break; } diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 38a386251..dfaac194d 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -292,13 +292,7 @@ abstract class DocumentIndex extends Base return $page; } - $route = $this->getRouteFromConfig($type, 'update'); - - if (!empty($route)) { - return $route; - } - - return config("type.{$type}.route.prefix"); + return config('type.' . $type . '.route.prefix', 'invoices'); } protected function getDocsPath($type, $docsPath) @@ -307,6 +301,12 @@ abstract class DocumentIndex extends Base return $docsPath; } + $docs_path = config('type.' . $type . '.docs_path'); + + if (!empty($docs_path)) { + return $docs_path; + } + switch ($type) { case 'sale': case 'income': @@ -401,18 +401,23 @@ abstract class DocumentIndex extends Base if (!empty($searchStringModel)) { return $searchStringModel; } + + $search_string_model = config('type.' . $type . '.search_string_model'); - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $searchStringModel = 'App\Models\Sale\Invoice'; - break; - case 'bill': - case 'expense': - case 'purchase': - $searchStringModel = 'App\Models\Purchase\Bill'; - break; + if (!empty($search_string_model)) { + return $search_string_model; + } + + if ($group = config('type.' . $type . '.group')) { + $group = Str::studly(Str::plural($group, 1)) . '\\'; + } + + $prefix = Str::studly(Str::plural(config('type.' . $type . '.route.prefix'), 1)) + + if ($alias = config('type.' . $type . '.alias')) { + $searchStringModel = 'Modules\\' . Str::studly($alias) .'\Models\\' . $group . $prefix; + } else { + $searchStringModel = 'App\Models\\' . $group . $prefix; } return $searchStringModel; @@ -441,17 +446,32 @@ abstract class DocumentIndex extends Base return $bulkActions; } - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $bulkActionClass = 'App\BulkActions\Sales\Invoices'; - break; - case 'bill': - case 'expense': - case 'purchase': - $bulkActionClass = 'App\BulkActions\Purchases\Bills'; - break; + $bulk_actions = config('type.' . $type . '.bulk_actions'); + + if (!empty($bulk_actions)) { + return $bulk_actions; + } + + $file_name = ''; + + if ($group = config('type.' . $type . '.group')) { + $file_name .= Str::studly($group) . '\\'; + } + + if ($prefix = config('type.' . $type . '.route.prefix')) { + $file_name .= Str::studly($prefix); + } + + if ($alias = config('type.' . $type . '.alias')) { + $module = module($alias); + + if (!$module instanceof Module) { + return; + } + + $bulkActionClass = 'Modules\\' . $module->getStudlyName() . '\BulkActions\\' . $file_name; + } else { + $bulkActionClass = 'App\BulkActions\\' . $file_name; } if (class_exists($bulkActionClass)) { @@ -496,6 +516,12 @@ abstract class DocumentIndex extends Base return $classBulkAction; } + $class = $this->getTextFromConfig($type, 'bulk_action'); + + if (!empty($class)) { + return $class; + } + return 'col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block'; } @@ -524,6 +550,12 @@ abstract class DocumentIndex extends Base return $classDocumentNumber; } + $class = $this->getTextFromConfig($type, 'document_number'); + + if (!empty($class)) { + return $class; + } + return 'col-md-2 col-lg-1 col-xl-1 d-none d-md-block'; } @@ -554,6 +586,12 @@ abstract class DocumentIndex extends Base return $classContactName; } + $class = $this->getTextFromConfig($type, 'contact_name'); + + if (!empty($class)) { + return $class; + } + return 'col-xs-4 col-sm-4 col-md-4 col-lg-2 col-xl-2 text-left'; } @@ -567,6 +605,12 @@ abstract class DocumentIndex extends Base return $classAmount; } + $class = $this->getTextFromConfig($type, 'amount'); + + if (!empty($class)) { + return $class; + } + return 'col-xs-4 col-sm-4 col-md-3 col-lg-2 col-xl-2 text-right'; } @@ -606,6 +650,12 @@ abstract class DocumentIndex extends Base return $classIssuedAt; } + $class = $this->getTextFromConfig($type, 'issued_at'); + + if (!empty($class)) { + return $class; + } + return 'col-lg-2 col-xl-2 d-none d-lg-block text-left'; } @@ -630,6 +680,12 @@ abstract class DocumentIndex extends Base return $classDueAt; } + $class = $this->getTextFromConfig($type, 'due_at'); + + if (!empty($class)) { + return $class; + } + if ($classDueAt = $this->getClass('classDueAt')) { return $classDueAt; } @@ -664,6 +720,12 @@ abstract class DocumentIndex extends Base return $classStatus; } + $class = $this->getTextFromConfig($type, 'status'); + + if (!empty($class)) { + return $class; + } + return 'col-lg-1 col-xl-1 d-none d-lg-block text-center'; } @@ -677,6 +739,12 @@ abstract class DocumentIndex extends Base return $classActions; } + $class = $this->getTextFromConfig($type, 'actions'); + + if (!empty($class)) { + return $class; + } + return 'col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center'; } diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 0ee098c77..e4d287758 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -553,16 +553,12 @@ abstract class DocumentShow extends Base return $documentTemplate; } - $documentTemplate = 'default'; - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $documentTemplate = setting('invoice.template', 'default'); - break; + if ($template = config('type.' . $type . 'template', false)) { + return $template; } + $documentTemplate = setting($type . '.template', 'default'); + return $documentTemplate; } @@ -963,6 +959,12 @@ abstract class DocumentShow extends Base return $classHeaderStatus; } + $class = $this->getTextFromConfig($type, 'header_status'); + + if (!empty($class)) { + return $class; + } + return 'col-md-2'; } @@ -972,6 +974,12 @@ abstract class DocumentShow extends Base return $classHeaderContact; } + $class = $this->getTextFromConfig($type, 'header_contact'); + + if (!empty($class)) { + return $class; + } + return 'col-md-6'; } @@ -981,6 +989,12 @@ abstract class DocumentShow extends Base return $classHeaderAmount; } + $class = $this->getTextFromConfig($type, 'header_amount'); + + if (!empty($class)) { + return $class; + } + return 'col-md-2'; } @@ -990,6 +1004,12 @@ abstract class DocumentShow extends Base return $classHeaderDueAt; } + $class = $this->getTextFromConfig($type, 'header_due_at'); + + if (!empty($class)) { + return $class; + } + return 'col-md-2'; } @@ -1001,6 +1021,10 @@ abstract class DocumentShow extends Base $hideTimelineStatuses = ['paid', 'cancelled']; + if ($timelime_statuses = config('type.' . $type . 'timeline_statuses')) { + $hideTimelineStatuses = $timelime_statuses; + } + return $hideTimelineStatuses; } diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php index a7695d584..589687f65 100644 --- a/app/Abstracts/View/Components/DocumentTemplate.php +++ b/app/Abstracts/View/Components/DocumentTemplate.php @@ -175,18 +175,12 @@ abstract class DocumentTemplate extends Base return $documentTemplate; } - // $documentTemplate = 'components.documents.template.default'; - $documentTemplate = 'default'; - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - // $documentTemplate = 'components.documents.template.' . setting('invoice.template', 'default'); - $documentTemplate = setting('invoice.template', 'default'); - break; + if ($template = config('type.' . $type . 'template', false)) { + return $template; } + $documentTemplate = setting($type . '.template', 'default'); + return $documentTemplate; } @@ -229,19 +223,12 @@ abstract class DocumentTemplate extends Base return $backgroundColor; } - $backgroundColor = '#55588b'; - - switch ($type) { - case 'bill': - case 'expense': - case 'purchase': - $backgroundColor = setting('bill.color'); - break; - default: - $backgroundColor = setting('invoice.color'); - break; + if ($background_color = config('type.' . $type . 'color', false)) { + return $background_color; } + $backgroundColor = setting($type . '.color', '#55588b'); + return $backgroundColor; } From 77264525a72aa536f06955764aa812eeb12c0fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 22:42:18 +0300 Subject: [PATCH 07/37] document type --- .../View/Components/DocumentForm.php | 28 +++++++++---------- config/type.php | 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 4de0c323b..9f916a2b1 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -310,7 +310,7 @@ abstract class DocumentForm extends Base } $parameters = [ - config('type.' . $type. '.route.parameter') => $document->id + config('type.' . $type. '.route.parameter') => $document->id, ]; $route = $this->getRouteFromConfig($type, 'update', $parameters); @@ -354,10 +354,10 @@ abstract class DocumentForm extends Base return $contact; } - protected function getContactType($type, $contact_type) + protected function getContactType($type, $contactType) { - if (!empty($contact_type)) { - return $contact_type; + if (!empty($contactType)) { + return $contactType; } if ($contact_type = config('type.' . $type . '.contact_type')) { @@ -476,7 +476,7 @@ abstract class DocumentForm extends Base return [ 'general.form.choose_different', - 'general.customers' + 'general.customers', ]; } @@ -501,10 +501,10 @@ abstract class DocumentForm extends Base return $issuedAt; } - protected function getDocumentNumber($type, $document, $document_number) + protected function getDocumentNumber($type, $document, $documentNumber) { - if (!empty($document_number)) { - return $document_number; + if (!empty($documentNumber)) { + return $documentNumber; } if ($document) { @@ -520,10 +520,10 @@ abstract class DocumentForm extends Base return $document_number; } - protected function getDueAt($type, $document, $due_at) + protected function getDueAt($type, $document, $dueAt) { - if (!empty($due_at)) { - return $due_at; + if (!empty($dueAt)) { + return $dueAt; } if ($document) { @@ -546,10 +546,10 @@ abstract class DocumentForm extends Base return $due_at; } - protected function getOrderNumber($type, $document, $order_number) + protected function getOrderNumber($type, $document, $orderNumber) { - if (!empty($order_number)) { - return $order_number; + if (!empty($orderNumber)) { + return $orderNumber; } if ($document) { diff --git a/config/type.php b/config/type.php index be730bfc7..53196b502 100644 --- a/config/type.php +++ b/config/type.php @@ -25,6 +25,7 @@ return [ ], 'contact_type' => 'customer', // use contact type 'hide' => [], // for document items + 'class' => [], ], Document::BILL_TYPE => [ From d8c4a3aae9a1f2026ea2a8093250ceaba6366613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 23:06:36 +0300 Subject: [PATCH 08/37] test fixed.. --- app/Abstracts/View/Components/DocumentForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 9f916a2b1..5f38dccb3 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -310,7 +310,7 @@ abstract class DocumentForm extends Base } $parameters = [ - config('type.' . $type. '.route.parameter') => $document->id, + config('type.' . $type. '.route.parameter') => ($document) ? $document->id : 1, ]; $route = $this->getRouteFromConfig($type, 'update', $parameters); From 8056c87332b8730deb822d2cfd87858e4d52d8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 23:08:31 +0300 Subject: [PATCH 09/37] fixed test --- app/Abstracts/View/Components/DocumentIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index dfaac194d..99ca9446f 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -412,7 +412,7 @@ abstract class DocumentIndex extends Base $group = Str::studly(Str::plural($group, 1)) . '\\'; } - $prefix = Str::studly(Str::plural(config('type.' . $type . '.route.prefix'), 1)) + $prefix = Str::studly(Str::plural(config('type.' . $type . '.route.prefix'), 1)); if ($alias = config('type.' . $type . '.alias')) { $searchStringModel = 'Modules\\' . Str::studly($alias) .'\Models\\' . $group . $prefix; From 67fca4d5b9115f8b959a6b9bee976eef60cb4d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 23:24:59 +0300 Subject: [PATCH 10/37] fixed test --- app/Abstracts/View/Components/DocumentIndex.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 99ca9446f..5b09838c6 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -235,7 +235,7 @@ abstract class DocumentIndex extends Base /* -- Card Header End -- */ /* -- Card Body Start -- */ - $this->textDocumentNumber = $this->getTextDocumentNumber($textDocumentNumber); + $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber); $this->textContactName = $this->getTextContactName($type, $textContactName); $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); $this->textDueAt = $this->getTextDueAt($type, $textDueAt); @@ -525,7 +525,7 @@ abstract class DocumentIndex extends Base return 'col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block'; } - protected function getTextDocumentNumber($textDocumentNumber) + protected function getTextDocumentNumber($type, $textDocumentNumber) { if (!empty($textDocumentNumber)) { return $textDocumentNumber; From 2455ec5d7e14ebcc3f9eb4f7719a65598aac7b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 23:41:01 +0300 Subject: [PATCH 11/37] some changes.. --- app/Abstracts/View/Components/Document.php | 4 ++-- app/Http/Requests/Document/Document.php | 2 +- app/Listeners/Document/MarkDocumentCancelled.php | 14 +++++++++----- app/Listeners/Document/MarkDocumentReceived.php | 14 +++++++++----- app/Listeners/Document/MarkDocumentSent.php | 14 +++++++++----- app/Listeners/Document/MarkDocumentViewed.php | 14 +++++++++----- app/View/Components/Documents/Form/Company.php | 2 +- 7 files changed, 40 insertions(+), 24 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index c8a129019..45b66886f 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -17,7 +17,7 @@ abstract class Document extends Component } $alias = config('type.' . $type . '.alias'); - $prefix = config("type.' . $type . '.translation.prefix"); + $prefix = config('type.' . $type . '.translation.prefix'); if (!empty($alias)) { $alias .= '::'; @@ -92,7 +92,7 @@ abstract class Document extends Component $alias = config('type.' . $type . '.alias'); $group = config('type.' . $type . '.group'); - $prefix = config("type.' . $type . '.permission.prefix"); + $prefix = config('type.' . $type . '.permission.prefix'); $permission = $config_key . '-'; diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index 01d20745f..80fd4ff71 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -28,7 +28,7 @@ class Document extends FormRequest { $type = $this->request->get('type', Model::INVOICE_TYPE); - $type = config("type.{$type}.route_parameter"); + $type = config('type.' . $type . '.route_parameter'); // Check if store or update if ($this->getMethod() == 'PATCH') { diff --git a/app/Listeners/Document/MarkDocumentCancelled.php b/app/Listeners/Document/MarkDocumentCancelled.php index 5a7c7df0b..cbb52e2f7 100644 --- a/app/Listeners/Document/MarkDocumentCancelled.php +++ b/app/Listeners/Document/MarkDocumentCancelled.php @@ -21,11 +21,15 @@ class MarkDocumentCancelled { $this->dispatch(new CancelDocument($event->document)); - $type = trans_choice( - config("type.{$event->document->type}.alias", '') . - 'general.' . config("type.{$event->document->type}.translation_key"), - 1 - ); + $type_text = ''; + + if ($alias = config('type.' . $event->document->type . '.alias', '')) { + $type_text .= $alias . '::'; + } + + $type_text .= 'general.' . config('type.' . $event->document->type .'.translation.prefix'); + + $type = trans_choice($type_text, 1); $this->dispatch( new CreateDocumentHistory( diff --git a/app/Listeners/Document/MarkDocumentReceived.php b/app/Listeners/Document/MarkDocumentReceived.php index bae62d368..db6696d0a 100644 --- a/app/Listeners/Document/MarkDocumentReceived.php +++ b/app/Listeners/Document/MarkDocumentReceived.php @@ -24,11 +24,15 @@ class MarkDocumentReceived $event->document->save(); } - $type = trans_choice( - config("type.{$event->document->type}.alias", '') . - 'general.' . config("type.{$event->document->type}.translation_key"), - 1 - ); + $type_text = ''; + + if ($alias = config('type.' . $event->document->type . '.alias', '')) { + $type_text .= $alias . '::'; + } + + $type_text .= 'general.' . config('type.' . $event->document->type .'.translation.prefix'); + + $type = trans_choice($type_text, 1); $this->dispatch( new CreateDocumentHistory( diff --git a/app/Listeners/Document/MarkDocumentSent.php b/app/Listeners/Document/MarkDocumentSent.php index 8f88e7842..db68140c0 100644 --- a/app/Listeners/Document/MarkDocumentSent.php +++ b/app/Listeners/Document/MarkDocumentSent.php @@ -24,11 +24,15 @@ class MarkDocumentSent $event->document->save(); } - $type = trans_choice( - config("type.{$event->document->type}.alias", '') . - 'general.' . config("type.{$event->document->type}.translation_key"), - 1 - ); + $type_text = ''; + + if ($alias = config('type.' . $event->document->type . '.alias', '')) { + $type_text .= $alias . '::'; + } + + $type_text .= 'general.' . config('type.' . $event->document->type .'.translation.prefix'); + + $type = trans_choice($type_text, 1); $this->dispatch( new CreateDocumentHistory( diff --git a/app/Listeners/Document/MarkDocumentViewed.php b/app/Listeners/Document/MarkDocumentViewed.php index 7a447e518..cd862eaa8 100644 --- a/app/Listeners/Document/MarkDocumentViewed.php +++ b/app/Listeners/Document/MarkDocumentViewed.php @@ -29,11 +29,15 @@ class MarkDocumentViewed $document->status = 'viewed'; $document->save(); - $type = trans_choice( - config("type.{$event->document->type}.alias", '') . - 'general.' . config("type.{$event->document->type}.translation_key"), - 1 - ); + $type_text = ''; + + if ($alias = config('type.' . $event->document->type . '.alias', '')) { + $type_text .= $alias . '::'; + } + + $type_text .= 'general.' . config('type.' . $event->document->type .'.translation.prefix'); + + $type = trans_choice($type_text, 1); $this->dispatch( new CreateDocumentHistory( diff --git a/app/View/Components/Documents/Form/Company.php b/app/View/Components/Documents/Form/Company.php index 329379c7d..7931216b1 100644 --- a/app/View/Components/Documents/Form/Company.php +++ b/app/View/Components/Documents/Form/Company.php @@ -16,7 +16,7 @@ class Company extends Component { $company = user()->companies()->first(); - $inputNameType = config("type.{$this->type}.route_parameter"); + $inputNameType = config('type.' . $this->type . '.route.parameter'); return view('components.documents.form.company', compact('company','inputNameType')); } From 88ca122ba0f8f0ea76149efee44d3d2b935e37fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sat, 9 Jan 2021 23:44:50 +0300 Subject: [PATCH 12/37] fixed test parameter.. --- app/Http/Requests/Document/Document.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index 80fd4ff71..9d7a9ebbd 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -28,7 +28,7 @@ class Document extends FormRequest { $type = $this->request->get('type', Model::INVOICE_TYPE); - $type = config('type.' . $type . '.route_parameter'); + $type = config('type.' . $type . '.route.parameter'); // Check if store or update if ($this->getMethod() == 'PATCH') { From e2d9f0cb92b13c7739f6723b2a15e4f29b369587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 00:01:58 +0300 Subject: [PATCH 13/37] fixed document request test --- app/Http/Requests/Document/Document.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index 9d7a9ebbd..629c0cec9 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -28,7 +28,7 @@ class Document extends FormRequest { $type = $this->request->get('type', Model::INVOICE_TYPE); - $type = config('type.' . $type . '.route.parameter'); + $type = config('type.' . $type . '.route.paramater'); // Check if store or update if ($this->getMethod() == 'PATCH') { From 00c1ea15b3f4bbd8f84d5067ceb2520807461862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 00:04:28 +0300 Subject: [PATCH 14/37] fixed permission trait.. --- app/Traits/Permissions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Traits/Permissions.php b/app/Traits/Permissions.php index 48ca8ceba..d5bf228c4 100644 --- a/app/Traits/Permissions.php +++ b/app/Traits/Permissions.php @@ -405,7 +405,7 @@ trait Permissions // Fire event to find the proper controller for common API endpoints if (in_array($table, ['contacts', 'documents', 'transactions'])) { - $controller = config('type.' . request()->get('type') . '.permission_name'); + $controller = config('type.' . request()->get('type') . '.permission.prefix'); } else { $route = app(Route::class); From 39f4a1913c0dfb1eb2476123695f470cc57ca7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 00:11:03 +0300 Subject: [PATCH 15/37] permission trait changed for module.. --- app/Traits/Permissions.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Traits/Permissions.php b/app/Traits/Permissions.php index d5bf228c4..91f102e70 100644 --- a/app/Traits/Permissions.php +++ b/app/Traits/Permissions.php @@ -405,7 +405,25 @@ trait Permissions // Fire event to find the proper controller for common API endpoints if (in_array($table, ['contacts', 'documents', 'transactions'])) { - $controller = config('type.' . request()->get('type') . '.permission.prefix'); + $controller = ''; + + $type = request()->get('type'); + + $alias = config('type.' . $type . '.alias'); + $group = config('type.' . $type . '.group'); + $prefix = config('type.' . $type . '.permission.prefix'); + + // if use module set module alias + if (!empty($alias)) { + $controller .= $alias . '-'; + } + + // if controller in folder it must + if (!empty($group)) { + $controller .= $group . '-'; + } + + $controller .= $prefix; } else { $route = app(Route::class); From 401a8ca8eaa748010f831a40fd39121915a434c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 14:28:22 +0300 Subject: [PATCH 16/37] fixed type --- app/Http/Requests/Document/Document.php | 2 +- config/type.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index 629c0cec9..9d7a9ebbd 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -28,7 +28,7 @@ class Document extends FormRequest { $type = $this->request->get('type', Model::INVOICE_TYPE); - $type = config('type.' . $type . '.route.paramater'); + $type = config('type.' . $type . '.route.parameter'); // Check if store or update if ($this->getMethod() == 'PATCH') { diff --git a/config/type.php b/config/type.php index 53196b502..cda42d5bb 100644 --- a/config/type.php +++ b/config/type.php @@ -10,7 +10,7 @@ return [ 'group' => 'sales', // controller folder name for permission and route 'route' => [ 'prefix' => 'invoices', // core use with group + prefix, module ex. estimates - 'paramater' => 'invoice', // sales/invoices/{parameter}/edit + 'parameter' => 'invoice', // sales/invoices/{parameter}/edit //'create' => 'invoices.create', // if you change route, you can write full path ], 'permission' => [ @@ -33,7 +33,7 @@ return [ 'group' => 'purchases', 'route' => [ 'prefix' => 'bills', - 'paramater' => 'bill', + 'parameter' => 'bill', //'create' => 'bilss.create', ], 'permission' => [ From c9269c9b700f08583fafd8aa640d680a431106a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 15:43:51 +0300 Subject: [PATCH 17/37] fixed document module bulk action class.. --- app/Abstracts/View/Components/DocumentIndex.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 5b09838c6..d80ee4eff 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -2,6 +2,7 @@ namespace App\Abstracts\View\Components; +use Akaunting\Module\Module; use App\Abstracts\View\Components\Document as Base; use App\Events\Common\BulkActionsAdding; use Illuminate\Support\Str; @@ -466,7 +467,12 @@ abstract class DocumentIndex extends Base $module = module($alias); if (!$module instanceof Module) { - return; + $b = new \stdClass(); + $b->actions = []; + + event(new BulkActionsAdding($b)); + + return $b->actions; } $bulkActionClass = 'Modules\\' . $module->getStudlyName() . '\BulkActions\\' . $file_name; From fb219f877eeea6abed8fe333062901673d2813cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 16:31:08 +0300 Subject: [PATCH 18/37] add alias for route --- app/Abstracts/View/Components/Document.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index 45b66886f..362599aa1 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -62,9 +62,19 @@ abstract class Document extends Component return $route; } + $alias = config('type.' . $type . '.alias'); $prefix = config('type.' . $type . '.route.prefix'); - $route = $prefix . '.' . $config_key; + // if use module set module alias + if (!empty($alias)) { + $route .= $alias . '.'; + } + + if (!empty($prefix)) { + $route .= $prefix . '.'; + } + + $route .= $config_key; try { route($route, $config_parameters); From 648f9f6e629b7917531758653068cd8b50278ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 18:59:36 +0300 Subject: [PATCH 19/37] fixed document model class fixed.. --- app/Abstracts/View/Components/DocumentIndex.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index d80ee4eff..257f569f4 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -410,10 +410,10 @@ abstract class DocumentIndex extends Base } if ($group = config('type.' . $type . '.group')) { - $group = Str::studly(Str::plural($group, 1)) . '\\'; + $group = Str::studly(Str::singular($group) . '\\'; } - $prefix = Str::studly(Str::plural(config('type.' . $type . '.route.prefix'), 1)); + $prefix = Str::studly(Str::singular(config('type.' . $type . '.route.prefix'))); if ($alias = config('type.' . $type . '.alias')) { $searchStringModel = 'Modules\\' . Str::studly($alias) .'\Models\\' . $group . $prefix; From aad70daa54594e955d1ef3f3f9ddc6fcbecd3235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 19:21:21 +0300 Subject: [PATCH 20/37] fixed type.. --- app/Abstracts/View/Components/DocumentIndex.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 257f569f4..92e37ce7c 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -410,7 +410,7 @@ abstract class DocumentIndex extends Base } if ($group = config('type.' . $type . '.group')) { - $group = Str::studly(Str::singular($group) . '\\'; + $group = Str::studly(Str::singular($group)) . '\\'; } $prefix = Str::studly(Str::singular(config('type.' . $type . '.route.prefix'))); From b3b4c866fc89f6617eac38ec861c1d29c2e5a2b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 20:36:37 +0300 Subject: [PATCH 21/37] Fixed class config function name.. --- app/Abstracts/View/Components/DocumentIndex.php | 16 ++++++++-------- app/Abstracts/View/Components/DocumentShow.php | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 92e37ce7c..6df551e5a 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -522,7 +522,7 @@ abstract class DocumentIndex extends Base return $classBulkAction; } - $class = $this->getTextFromConfig($type, 'bulk_action'); + $class = $this->getClassFromConfig($type, 'bulk_action'); if (!empty($class)) { return $class; @@ -556,7 +556,7 @@ abstract class DocumentIndex extends Base return $classDocumentNumber; } - $class = $this->getTextFromConfig($type, 'document_number'); + $class = $this->getClassFromConfig($type, 'document_number'); if (!empty($class)) { return $class; @@ -592,7 +592,7 @@ abstract class DocumentIndex extends Base return $classContactName; } - $class = $this->getTextFromConfig($type, 'contact_name'); + $class = $this->getClassFromConfig($type, 'contact_name'); if (!empty($class)) { return $class; @@ -611,7 +611,7 @@ abstract class DocumentIndex extends Base return $classAmount; } - $class = $this->getTextFromConfig($type, 'amount'); + $class = $this->getClassFromConfig($type, 'amount'); if (!empty($class)) { return $class; @@ -656,7 +656,7 @@ abstract class DocumentIndex extends Base return $classIssuedAt; } - $class = $this->getTextFromConfig($type, 'issued_at'); + $class = $this->getClassFromConfig($type, 'issued_at'); if (!empty($class)) { return $class; @@ -686,7 +686,7 @@ abstract class DocumentIndex extends Base return $classDueAt; } - $class = $this->getTextFromConfig($type, 'due_at'); + $class = $this->getClassFromConfig($type, 'due_at'); if (!empty($class)) { return $class; @@ -726,7 +726,7 @@ abstract class DocumentIndex extends Base return $classStatus; } - $class = $this->getTextFromConfig($type, 'status'); + $class = $this->getClassFromConfig($type, 'status'); if (!empty($class)) { return $class; @@ -745,7 +745,7 @@ abstract class DocumentIndex extends Base return $classActions; } - $class = $this->getTextFromConfig($type, 'actions'); + $class = $this->getClassFromConfig($type, 'actions'); if (!empty($class)) { return $class; diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index e4d287758..783d670d6 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -959,7 +959,7 @@ abstract class DocumentShow extends Base return $classHeaderStatus; } - $class = $this->getTextFromConfig($type, 'header_status'); + $class = $this->getClassFromConfig($type, 'header_status'); if (!empty($class)) { return $class; @@ -974,7 +974,7 @@ abstract class DocumentShow extends Base return $classHeaderContact; } - $class = $this->getTextFromConfig($type, 'header_contact'); + $class = $this->getClassFromConfig($type, 'header_contact'); if (!empty($class)) { return $class; @@ -989,7 +989,7 @@ abstract class DocumentShow extends Base return $classHeaderAmount; } - $class = $this->getTextFromConfig($type, 'header_amount'); + $class = $this->getClassFromConfig($type, 'header_amount'); if (!empty($class)) { return $class; @@ -1004,7 +1004,7 @@ abstract class DocumentShow extends Base return $classHeaderDueAt; } - $class = $this->getTextFromConfig($type, 'header_due_at'); + $class = $this->getClassFromConfig($type, 'header_due_at'); if (!empty($class)) { return $class; From 0c31fd8c9d99a3f385c1388b086162e5f025b03b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 21:39:32 +0300 Subject: [PATCH 22/37] fixed default_key --- app/Abstracts/View/Components/DocumentShow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 783d670d6..8da7e2dd0 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -1148,10 +1148,10 @@ abstract class DocumentShow extends Base case 'bill': case 'expense': case 'purchase': - $textTimelineSentStatusReceived = 'mark_received'; + $default_key = 'mark_received'; break; default: - $textTimelineSentStatusReceived = 'mark_sent'; + $default_key = 'mark_sent'; break; } From 8bcb173a922b7387543fb4069238e45d0c26aa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 22:04:22 +0300 Subject: [PATCH 23/37] Customize button route add alias for module --- app/Abstracts/View/Components/DocumentShow.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 8da7e2dd0..cb7dfff54 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -761,7 +761,15 @@ abstract class DocumentShow extends Base return $routeButtonCustomize; } - $route = 'settings.' . $type . '.edit'; + $route = ''; + + $alias = config('type.' . $type . '.alias'); + + if (!empty($alias)) { + $route .= $alias . '.'; + } + + $route .= 'settings.' . $type . '.edit'; try { route($route); From 0f158cdc7eb81c35e00a92aee49175637b79edc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Sun, 10 Jan 2021 22:09:45 +0300 Subject: [PATCH 24/37] index status translations.. --- app/Abstracts/View/Components/DocumentIndex.php | 2 +- app/Abstracts/View/Components/DocumentShow.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 6df551e5a..724ac5165 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -713,7 +713,7 @@ abstract class DocumentIndex extends Base return $translation; } - return 'invoices.statuses.'; + return $default_key; } protected function getClassStatus($type, $classStatus) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index cb7dfff54..fee4eb296 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -647,7 +647,7 @@ abstract class DocumentShow extends Base return $translation; } - return 'invoices.statuses.'; + return $default_key; } protected function getRouteButtonAddNew($type, $routeButtonAddNew) From 00ed7bcd49cc427cff53344161dcdf5e6af611db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 11:10:30 +0300 Subject: [PATCH 25/37] move document statutes keys.. --- .../View/Components/DocumentIndex.php | 12 ++++++- .../View/Components/DocumentShow.php | 16 ++++++++-- app/Notifications/Portal/PaymentReceived.php | 2 +- app/Traits/Documents.php | 32 +++++++++++++++++-- resources/lang/en-GB/bills.php | 10 ------ resources/lang/en-GB/documents.php | 20 ++++++++++++ resources/lang/en-GB/invoices.php | 12 ------- .../views/purchases/payments/index.blade.php | 4 +-- .../views/purchases/vendors/show.blade.php | 2 +- .../views/sales/customers/show.blade.php | 2 +- .../views/sales/revenues/index.blade.php | 4 +-- 11 files changed, 81 insertions(+), 35 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 724ac5165..fe21ddfb7 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -713,7 +713,17 @@ abstract class DocumentIndex extends Base return $translation; } - return $default_key; + $alias = config('type.' . $type . '.alias'); + + if (!empty($alias)) { + $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; + + if (is_array(trans($$translation))) { + return $translation . '.'; + } + } + + return 'documents.statuses.'; } protected function getClassStatus($type, $classStatus) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index fee4eb296..e2f22f518 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -637,17 +637,27 @@ abstract class DocumentShow extends Base { if (!empty($textHistoryStatus)) { return $textHistoryStatus; - } + } $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; - $translation = $this->getTextFromConfig($type, 'history_status', $default_key); + $translation = $this->getTextFromConfig($type, 'document_status', $default_key); if (!empty($translation)) { return $translation; } - return $default_key; + $alias = config('type.' . $type . '.alias'); + + if (!empty($alias)) { + $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; + + if (is_array(trans($$translation))) { + return $translation . '.'; + } + } + + return 'documents.statuses.'; } protected function getRouteButtonAddNew($type, $routeButtonAddNew) diff --git a/app/Notifications/Portal/PaymentReceived.php b/app/Notifications/Portal/PaymentReceived.php index f448e0a34..45f8d5c55 100644 --- a/app/Notifications/Portal/PaymentReceived.php +++ b/app/Notifications/Portal/PaymentReceived.php @@ -104,7 +104,7 @@ class PaymentReceived extends Notification $this->invoice->document_number, money($this->invoice->amount, $this->invoice->currency_code, true), company_date($this->invoice->due_at), - trans('invoices.statuses.' . $this->invoice->status), + trans('documents.statuses.' . $this->invoice->status), URL::signedRoute('signed.invoices.show', [$this->invoice->id, 'company_id' => $this->invoice->company_id]), route('invoices.show', $this->invoice->id), route('portal.invoices.show', $this->invoice->id), diff --git a/app/Traits/Documents.php b/app/Traits/Documents.php index 00370da43..f14212601 100644 --- a/app/Traits/Documents.php +++ b/app/Traits/Documents.php @@ -3,6 +3,7 @@ namespace App\Traits; use App\Models\Document\Document; +use App\Abstracts\View\Components\Document as DocumentComponent; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -50,10 +51,14 @@ trait Documents ], ]; - $statuses = collect($list[$type])->each(function ($code) use ($type) { + // @todo get dynamic path + //$trans_key = $this->getTextDocumentStatuses($type); + $trans_key = 'documents.statuses.'; + + $statuses = collect($list[$type])->each(function ($code) use ($type, $trans_key) { $item = new \stdClass(); $item->code = $code; - $item->name = trans(Str::plural($type) . '.statuses.' . $code); + $item->name = trans($trans_key . $code); return $item; }); @@ -70,4 +75,27 @@ trait Documents { return Str::slug($document->document_number, $separator, language()->getShortCode()); } + + protected function getTextDocumentStatuses($type) + { + $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; + + $translation = DocumentComponent::getTextFromConfig($type, 'document_status', $default_key); + + if (!empty($translation)) { + return $translation; + } + + $alias = config('type.' . $type . '.alias'); + + if (!empty($alias)) { + $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; + + if (is_array(trans($$translation))) { + return $translation . '.'; + } + } + + return 'documents.statuses.'; + } } diff --git a/resources/lang/en-GB/bills.php b/resources/lang/en-GB/bills.php index fe53be0d9..9bec668cd 100644 --- a/resources/lang/en-GB/bills.php +++ b/resources/lang/en-GB/bills.php @@ -38,16 +38,6 @@ return [ 'receive_bill' => 'Receive Bill', 'make_payment' => 'Make Payment', - 'statuses' => [ - 'draft' => 'Draft', - 'received' => 'Received', - 'partial' => 'Partial', - 'paid' => 'Paid', - 'overdue' => 'Overdue', - 'unpaid' => 'Unpaid', - 'cancelled' => 'Cancelled', - ], - 'messages' => [ 'draft' => 'This is a DRAFT bill and will be reflected to charts after it gets received.', diff --git a/resources/lang/en-GB/documents.php b/resources/lang/en-GB/documents.php index ff193bc35..3f919e023 100644 --- a/resources/lang/en-GB/documents.php +++ b/resources/lang/en-GB/documents.php @@ -1,6 +1,26 @@ [ + 'draft' => 'Draft', + 'sent' => 'Sent', + 'expired' => 'Expired', + 'viewed' => 'Viewed', + 'approved' => 'Approved', + 'received' => 'Received', + 'refused' => 'Refused', + 'restored' => 'Restored', + 'reversed' => 'Reversed', + 'partial' => 'Partial', + 'paid' => 'Paid', + 'invoiced' => 'Invoiced', + 'overdue' => 'Overdue', + 'unpaid' => 'Unpaid', + 'cancelled' => 'Cancelled', + 'void' => 'Void', + ], + 'messages' => [ 'email_sent' => ':type email has been sent!', 'marked_sent' => ':type marked as sent!', diff --git a/resources/lang/en-GB/invoices.php b/resources/lang/en-GB/invoices.php index 5083f69cf..c5daffdea 100644 --- a/resources/lang/en-GB/invoices.php +++ b/resources/lang/en-GB/invoices.php @@ -40,18 +40,6 @@ return [ 'get_paid' => 'Get Paid', 'accept_payments' => 'Accept Online Payments', - 'statuses' => [ - 'draft' => 'Draft', - 'sent' => 'Sent', - 'viewed' => 'Viewed', - 'approved' => 'Approved', - 'partial' => 'Partial', - 'paid' => 'Paid', - 'overdue' => 'Overdue', - 'unpaid' => 'Unpaid', - 'cancelled' => 'Cancelled', - ], - 'messages' => [ 'email_required' => 'No email address for this customer!', 'draft' => 'This is a DRAFT invoice and will be reflected to charts after it gets sent.', diff --git a/resources/views/purchases/payments/index.blade.php b/resources/views/purchases/payments/index.blade.php index d6b31990f..f70f89c6b 100644 --- a/resources/views/purchases/payments/index.blade.php +++ b/resources/views/purchases/payments/index.blade.php @@ -57,7 +57,7 @@ @if($item->bill) @if ($item->bill->status == 'paid') - @@ -66,7 +66,7 @@ @elseif ($item->bill->status == 'partial') - diff --git a/resources/views/purchases/vendors/show.blade.php b/resources/views/purchases/vendors/show.blade.php index 9a78141a8..3a4aba493 100644 --- a/resources/views/purchases/vendors/show.blade.php +++ b/resources/views/purchases/vendors/show.blade.php @@ -194,7 +194,7 @@ @money($item->amount, $item->currency_code, true) @date($item->issued_at) @date($item->due_at) - {{ trans('bills.statuses.' . $item->status) }} + {{ trans('documents.statuses.' . $item->status) }} @endforeach diff --git a/resources/views/sales/customers/show.blade.php b/resources/views/sales/customers/show.blade.php index 022b2bac5..e47799414 100644 --- a/resources/views/sales/customers/show.blade.php +++ b/resources/views/sales/customers/show.blade.php @@ -194,7 +194,7 @@ @money($item->amount, $item->currency_code, true) @date($item->issued_at) @date($item->due_at) - {{ trans('invoices.statuses.' . $item->status) }} + {{ trans('documents.statuses.' . $item->status) }} @endforeach diff --git a/resources/views/sales/revenues/index.blade.php b/resources/views/sales/revenues/index.blade.php index e60abc9db..dc35b83a4 100644 --- a/resources/views/sales/revenues/index.blade.php +++ b/resources/views/sales/revenues/index.blade.php @@ -57,7 +57,7 @@ @if($item->invoice) @if ($item->invoice->status == 'paid') - @@ -66,7 +66,7 @@ @elseif ($item->invoice->status == 'partial') - From 7b001d039ce0b6f169cec27f251c0852f408d5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 12:22:51 +0300 Subject: [PATCH 26/37] fixed cancel button path for document form refs #1729 --- .../View/Components/DocumentForm.php | 21 ++++++++++++++++++- .../documents/form/buttons.blade.php | 2 +- .../documents/form/content.blade.php | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 5f38dccb3..16cd00f9a 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -49,6 +49,9 @@ abstract class DocumentForm extends Base /** @var string */ public $routeUpdate; + /** @var string */ + public $routeCancel; + /** @var string */ public $formId; @@ -195,7 +198,7 @@ abstract class DocumentForm extends Base bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, /** Company Component End */ /** Content Component Start */ - string $routeStore = '', string $routeUpdate = '', string $formId = 'document', string $formSubmit = 'onSubmit', + string $routeStore = '', string $routeUpdate = '', string $formId = 'document', string $formSubmit = 'onSubmit', string $routeCancel = '', bool $hideCompany = false, bool $hideAdvanced = false, bool $hideFooter = false, bool $hideButtons = false, /** Content Component End */ /** Metadata Component Start */ @@ -232,6 +235,7 @@ abstract class DocumentForm extends Base /** Content Component Start */ $this->routeStore = $this->getRouteStore($type, $routeStore); $this->routeUpdate = $this->getRouteUpdate($type, $routeUpdate, $document); + $this->routeCancel = $this->getRouteCancel($type, $routeCancel); $this->formId = $formId; $this->formSubmit = $formSubmit; @@ -322,6 +326,21 @@ abstract class DocumentForm extends Base return 'invoices.update'; } + protected function getRouteCancel($type, $routeCancel) + { + if (!empty($routeCancel)) { + return $routeCancel; + } + + $route = $this->getRouteFromConfig($type, 'index'); + + if (!empty($route)) { + return $route; + } + + return 'invoices.index'; + } + protected function getContacts($type, $contacts) { if (!empty($contacts)) { diff --git a/resources/views/components/documents/form/buttons.blade.php b/resources/views/components/documents/form/buttons.blade.php index a87f137d3..56da609e3 100644 --- a/resources/views/components/documents/form/buttons.blade.php +++ b/resources/views/components/documents/form/buttons.blade.php @@ -2,7 +2,7 @@
diff --git a/resources/views/components/documents/form/content.blade.php b/resources/views/components/documents/form/content.blade.php index 2dde4f456..dfd63aeb0 100644 --- a/resources/views/components/documents/form/content.blade.php +++ b/resources/views/components/documents/form/content.blade.php @@ -88,6 +88,7 @@ @endif From 49fef6b67b66833fc77be3d1d8f26bacd380ad3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 12:28:31 +0300 Subject: [PATCH 27/37] type fixed.. --- app/Abstracts/View/Components/DocumentIndex.php | 2 +- app/Abstracts/View/Components/DocumentShow.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index fe21ddfb7..c6701fdaa 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -718,7 +718,7 @@ abstract class DocumentIndex extends Base if (!empty($alias)) { $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; - if (is_array(trans($$translation))) { + if (is_array(trans($translation))) { return $translation . '.'; } } diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index e2f22f518..ac1d2363a 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -652,7 +652,7 @@ abstract class DocumentShow extends Base if (!empty($alias)) { $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; - if (is_array(trans($$translation))) { + if (is_array(trans($translation))) { return $translation . '.'; } } From da5b617537288f95ec9a142f920cfdf9c05934e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 12:33:00 +0300 Subject: [PATCH 28/37] timeline create text fixed.. --- app/Abstracts/View/Components/DocumentShow.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index ac1d2363a..73cb73204 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -1052,7 +1052,15 @@ abstract class DocumentShow extends Base return $textTimelineCreateTitle; } - $default_key = 'create_' . $type; + $default_key = 'create_' . str_replace('-', '_', $type); + + $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key); + + if (!empty($translation)) { + return $translation; + } + + $default_key = 'create_' . str_replace('-', '_', config('type.' . $type . '.alias'); $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key); From ee296cdf84a91b77085062c16ea6f9a3e64253e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 13:06:21 +0300 Subject: [PATCH 29/37] fixed show issue.. --- app/Abstracts/View/Components/DocumentShow.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 73cb73204..d146936ca 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -1060,7 +1060,7 @@ abstract class DocumentShow extends Base return $translation; } - $default_key = 'create_' . str_replace('-', '_', config('type.' . $type . '.alias'); + $default_key = 'create_' . str_replace('-', '_', config('type.' . $type . '.alias')); $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key); From 265e3bbc6fc8a40e51f1d8f1f882a8642e533d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 13:09:58 +0300 Subject: [PATCH 30/37] fixed statutes keys.. --- app/Abstracts/View/Components/DocumentIndex.php | 4 +--- app/Abstracts/View/Components/DocumentShow.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index c6701fdaa..48d51464b 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -705,9 +705,7 @@ abstract class DocumentIndex extends Base return $textDocumentStatus; } - $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; - - $translation = $this->getTextFromConfig($type, 'document_status', $default_key); + $translation = $this->getTextFromConfig($type, 'document_status', '.statuses.'); if (!empty($translation)) { return $translation; diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index d146936ca..64657e9ce 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -639,9 +639,7 @@ abstract class DocumentShow extends Base return $textHistoryStatus; } - $default_key = config('type.' . $type . '.translation.prefix') . '.statuses.'; - - $translation = $this->getTextFromConfig($type, 'document_status', $default_key); + $translation = $this->getTextFromConfig($type, 'document_status', '.statuses.'); if (!empty($translation)) { return $translation; From 7bdbaa973cab364bc016c00f374676e37d1a8708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 16:02:09 +0300 Subject: [PATCH 31/37] fixed assignment --- app/Abstracts/View/Components/DocumentForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 16cd00f9a..942edab3f 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -514,7 +514,7 @@ abstract class DocumentForm extends Base if (request()->has($issued_at)) { $issuedAt = request()->get($issued_at); } else { - request()->get('invoiced_at', Date::now()->toDateString()); + $issuedAt = request()->get('invoiced_at', Date::now()->toDateString()); } return $issuedAt; From 381ce21f254d21a2abb97361fa96af2f755c5e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 16:18:17 +0300 Subject: [PATCH 32/37] Add dynamic category type for modules.. --- app/Abstracts/View/Components/Document.php | 34 ++++++++++++++++++- .../View/Components/DocumentForm.php | 22 +++++++++++- .../Components/Documents/Form/Advanced.php | 29 +--------------- config/type.php | 2 ++ .../documents/form/advanced.blade.php | 2 +- .../documents/form/content.blade.php | 1 + 6 files changed, 59 insertions(+), 31 deletions(-) diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php index 362599aa1..a9942ac91 100644 --- a/app/Abstracts/View/Components/Document.php +++ b/app/Abstracts/View/Components/Document.php @@ -133,11 +133,43 @@ abstract class Document extends Component return $hide; } - + public function getClassFromConfig($type, $config_key) { $class_key = 'type.' . $type . '.class.' . $config_key; return config($class_key, ''); } + + public function getCategoryFromConfig($type) + { + $category_type = ''; + + // if set config trasnlation config_key + if ($category_type = config('type.' . $type . '.category_type')) { + return $category_type; + } + + switch ($type) { + case 'bill': + case 'expense': + case 'purchase': + $category_type = 'expense'; + break; + case 'item': + $category_type = 'item'; + break; + case 'other': + $category_type = 'other'; + break; + case 'transfer': + $category_type = 'transfer'; + break; + default: + $category_type = 'income'; + break; + } + + return $category_type; + } } diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 942edab3f..40998a413 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -18,6 +18,9 @@ abstract class DocumentForm extends Base public $document; /** Advanced Component Start */ + /** @var string */ + public $categoryType; + /** @var bool */ public $hideRecurring; @@ -192,7 +195,7 @@ abstract class DocumentForm extends Base public function __construct( $type, $document = false, /** Advanced Component Start */ - bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false, + string $categoryType = '', bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false, /** Advanced Component End */ /** Company Component Start */ bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, @@ -220,6 +223,7 @@ abstract class DocumentForm extends Base $this->document = $document; /** Advanced Component Start */ + $this->categoryType = $this->getCategoryType($type, $categoryType); $this->hideRecurring = $hideRecurring; $this->hideCategory = $hideCategory; $this->hideAttachment = $hideAttachment; @@ -341,6 +345,22 @@ abstract class DocumentForm extends Base return 'invoices.index'; } + protected function getCategoryType($type, $categoryType) + { + if (!empty($categoryType)) { + return $categoryType; + } + + if ($category_type = config('type.' . $type . '.category_type')) { + return $category_type; + } + + // set default type + $type = Document::INVOICE_TYPE; + + return config('type.' . $type . '.category_type'); + } + protected function getContacts($type, $contacts) { if (!empty($contacts)) { diff --git a/app/View/Components/Documents/Form/Advanced.php b/app/View/Components/Documents/Form/Advanced.php index 800db9b80..c976fc360 100644 --- a/app/View/Components/Documents/Form/Advanced.php +++ b/app/View/Components/Documents/Form/Advanced.php @@ -14,7 +14,7 @@ class Advanced extends Component */ public function render() { - $category_type = $this->getCategoryType(); + $category_type = $this->categoryType; if ($category_type) { $categories = Category::$category_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); @@ -24,31 +24,4 @@ class Advanced extends Component return view('components.documents.form.advanced', compact('categories', 'category_type')); } - - protected function getCategoryType() - { - $type = ''; - - switch ($this->type) { - case 'bill': - case 'expense': - case 'purchase': - $type = 'expense'; - break; - case 'item': - $type = 'item'; - break; - case 'other': - $type = 'other'; - break; - case 'transfer': - $type = 'transfer'; - break; - default: - $type = 'income'; - break; - } - - return $type; - } } diff --git a/config/type.php b/config/type.php index cda42d5bb..bcda981ba 100644 --- a/config/type.php +++ b/config/type.php @@ -23,6 +23,7 @@ return [ 'issued_at' => 'invoices.invoice_date', 'due_at' => 'invoices.due_date', ], + 'category_type' => 'income', 'contact_type' => 'customer', // use contact type 'hide' => [], // for document items 'class' => [], @@ -45,6 +46,7 @@ return [ 'issued_at' => 'bills.bill_date', 'due_at' => 'bills.due_date', ], + 'category_type' => 'expense', 'contact_type' => 'vendor', 'hide' => [], ], diff --git a/resources/views/components/documents/form/advanced.blade.php b/resources/views/components/documents/form/advanced.blade.php index f7727fdba..469bd8101 100644 --- a/resources/views/components/documents/form/advanced.blade.php +++ b/resources/views/components/documents/form/advanced.blade.php @@ -15,7 +15,7 @@
@if (!$hideCategory) - {{ Form::selectRemoteAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, setting('default.' . $category_type . '_category'), ['required' => 'required', 'path' => route('modals.categories.create') . '?type=' . $category_type, 'remote_action' => route('categories.index'). '?type=' . $category_type], 'col-md-12') }} + {{ Form::selectRemoteAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, setting('default.' . $categoryType . '_category'), ['required' => 'required', 'path' => route('modals.categories.create') . '?type=' . $categoryType, 'remote_action' => route('categories.index'). '?type=' . $categoryType], 'col-md-12') }} @endif @if (!$hideAttachment) diff --git a/resources/views/components/documents/form/content.blade.php b/resources/views/components/documents/form/content.blade.php index dfd63aeb0..60de7f01c 100644 --- a/resources/views/components/documents/form/content.blade.php +++ b/resources/views/components/documents/form/content.blade.php @@ -78,6 +78,7 @@ Date: Mon, 11 Jan 2021 16:28:16 +0300 Subject: [PATCH 33/37] fixed trait duplicate symbol --- app/Traits/Documents.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Traits/Documents.php b/app/Traits/Documents.php index f14212601..d4e7137dc 100644 --- a/app/Traits/Documents.php +++ b/app/Traits/Documents.php @@ -91,7 +91,7 @@ trait Documents if (!empty($alias)) { $translation = $alias . '::' . config('type.' . $type . '.translation.prefix') . '.statuses'; - if (is_array(trans($$translation))) { + if (is_array(trans($translation))) { return $translation . '.'; } } From 813ebfe600596f7cd132a058842c4adbb2161a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 18:37:16 +0300 Subject: [PATCH 34/37] import path fixed --- app/Abstracts/View/Components/DocumentIndex.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 48d51464b..39c0da87b 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -358,8 +358,17 @@ abstract class DocumentIndex extends Base $route = $this->getRouteFromConfig($type, 'import'); + $alias = config('type.' . $type . '.alias'); + $group = config('type.' . $type . '.group'); + + if (empty($group) && !empty($alias)){ + $group = $alias; + } else if (empty($group) && empty($alias)) { + $group = 'sales'; + } + $importRouteParameters = [ - 'group' => config('type.' . $type . '.group'), + 'group' => $group, 'type' => config('type.' . $type . '.route.prefix'), 'route' => ($route) ? $route : 'invoices.import', ]; @@ -402,7 +411,7 @@ abstract class DocumentIndex extends Base if (!empty($searchStringModel)) { return $searchStringModel; } - + $search_string_model = config('type.' . $type . '.search_string_model'); if (!empty($search_string_model)) { @@ -429,7 +438,7 @@ abstract class DocumentIndex extends Base if (!empty($textBulkAction)) { return $textBulkAction; } - + $default_key = config('type.' . $type . '.translation.prefix'); $translation = $this->getTextFromConfig($type, 'bulk_action', $default_key, 'trans_choice'); From b4d406096bec853932de858902046cd0b874e1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 23:04:55 +0300 Subject: [PATCH 35/37] translation fixes.. --- app/Abstracts/View/Components/DocumentIndex.php | 2 +- app/Abstracts/View/Components/DocumentShow.php | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php index 39c0da87b..5252c8f9c 100644 --- a/app/Abstracts/View/Components/DocumentIndex.php +++ b/app/Abstracts/View/Components/DocumentIndex.php @@ -714,7 +714,7 @@ abstract class DocumentIndex extends Base return $textDocumentStatus; } - $translation = $this->getTextFromConfig($type, 'document_status', '.statuses.'); + $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.'); if (!empty($translation)) { return $translation; diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php index 64657e9ce..27da0512c 100644 --- a/app/Abstracts/View/Components/DocumentShow.php +++ b/app/Abstracts/View/Components/DocumentShow.php @@ -536,7 +536,7 @@ abstract class DocumentShow extends Base return $textStatusMessage; } - $default_key = config('type.' . $type . '.translation.prefix') . '.messages.draft'; + $default_key = 'messages.draft'; $translation = $this->getTextFromConfig($type, 'status_message', $default_key); @@ -622,9 +622,7 @@ abstract class DocumentShow extends Base return $textHistories; } - $default_key = config('type.' . $type . '.translation.prefix') . '.histories'; - - $translation = $this->getTextFromConfig($type, 'histories', $default_key); + $translation = $this->getTextFromConfig($type, 'histories', 'histories'); if (!empty($translation)) { return $translation; @@ -639,7 +637,7 @@ abstract class DocumentShow extends Base return $textHistoryStatus; } - $translation = $this->getTextFromConfig($type, 'document_status', '.statuses.'); + $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.'); if (!empty($translation)) { return $translation; From 8237d0f3e4170616da7363e27f5f9af23b8d392c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Mon, 11 Jan 2021 23:55:38 +0300 Subject: [PATCH 36/37] update statutes keys.. --- resources/lang/en-GB/documents.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/lang/en-GB/documents.php b/resources/lang/en-GB/documents.php index 3f919e023..f4e59e2e1 100644 --- a/resources/lang/en-GB/documents.php +++ b/resources/lang/en-GB/documents.php @@ -18,7 +18,13 @@ return [ 'overdue' => 'Overdue', 'unpaid' => 'Unpaid', 'cancelled' => 'Cancelled', - 'void' => 'Void', + 'voided' => 'Voided', + 'completed' => 'Completed', + 'shipped' => 'Shipped', + 'refunded' => 'Refunded', + 'failed' => 'Failed', + 'denied' => 'Denied', + 'processed' => 'Processed', ], 'messages' => [ From e1e8aecb03bbe8070e78c45dacdb65adec82e3f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 12 Jan 2021 00:19:18 +0300 Subject: [PATCH 37/37] Document translation add new status.. --- resources/lang/en-GB/documents.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/lang/en-GB/documents.php b/resources/lang/en-GB/documents.php index f4e59e2e1..c6c623ffc 100644 --- a/resources/lang/en-GB/documents.php +++ b/resources/lang/en-GB/documents.php @@ -14,6 +14,7 @@ return [ 'reversed' => 'Reversed', 'partial' => 'Partial', 'paid' => 'Paid', + 'pending' => 'Pending', 'invoiced' => 'Invoiced', 'overdue' => 'Overdue', 'unpaid' => 'Unpaid', @@ -25,10 +26,17 @@ return [ 'failed' => 'Failed', 'denied' => 'Denied', 'processed' => 'Processed', + 'open' => 'Open', + 'closed' => 'Closed', + 'billed' => 'Billed', + 'delivered' => 'Delivered', + 'returned' => 'Returned', + 'drawn' => 'Drawn', ], 'messages' => [ 'email_sent' => ':type email has been sent!', + 'marked_as' => ':type marked as :status!', 'marked_sent' => ':type marked as sent!', 'marked_paid' => ':type marked as paid!', 'marked_viewed' => ':type marked as viewed!',