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] 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') -