diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php index 71167b148..81c0b5363 100644 --- a/app/Abstracts/View/Components/DocumentForm.php +++ b/app/Abstracts/View/Components/DocumentForm.php @@ -2,19 +2,151 @@ namespace App\Abstracts\View\Components; +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 { + use Documents; + public $type; - public $documents; + public $document; - public $bulkActions; + /** Advanced Component Start */ + /** @var bool */ + public $hideRecurring; /** @var bool */ - public $hideBulkAction; + public $hideCategory; + + /** @var bool */ + public $hideAttachment; + /** Advanced Component End */ + + /** Company Component Start */ + /** @var bool */ + public $hideLogo; + + /** @var bool */ + public $hideDocumentTitle; + + /** @var bool */ + public $hideDocumentSubheading; + + /** @var bool */ + public $hideCompanyEdit; + /** Company Component End */ + + /** Content Component Start */ + /** @var string */ + public $formRoute; + + /** @var string */ + public $formId; + + /** @var string */ + public $formSubmit; + + /** @var bool */ + public $hideCompany; + + /** @var bool */ + public $hideAdvanced; + + /** @var bool */ + public $hideFooter; + + /** @var bool */ + public $hideButtons; + /** Content Component End */ + + /** Metadata Component Start */ + public $contacts; + + /** @var string */ + public $contactType; + + /** @var bool */ + public $hideContact; + + /** @var bool */ + public $hideIssuedAt; + + /** @var bool */ + public $hideDocumentNumber; + + /** @var bool */ + public $hideDueAt; + + /** @var bool */ + public $hideOrderNumber; + + /** @var string */ + public $issuedAt; + + /** @var string */ + public $documentNumber; + + /** @var string */ + public $dueAt; + + /** @var string */ + public $orderNumber; + + /** @var string */ + public $textIssuedAt; + + /** @var string */ + public $textDueAt; + + /** @var string */ + public $textDocumentNumber; + + /** @var string */ + public $textOrderNumber; + /** Metadata Component End */ + + /** Items Component Start */ + /** @var bool */ + public $hideEditItemColumns; + + /** @var string */ + public $textItems; + + /** @var string */ + public $textQuantity; + + /** @var string */ + public $textPrice; + + /** @var string */ + public $textAmount; + + /** @var bool */ + public $hideItems; + + /** @var bool */ + public $hideName; + + /** @var bool */ + public $hideDescription; + + /** @var bool */ + public $hideQuantity; + + /** @var bool */ + public $hidePrice; + + /** @var bool */ + public $hideDiscount; + + /** @var bool */ + public $hideAmount; + /** Items Component End */ /** * Create a new component instance. @@ -22,13 +154,574 @@ abstract class DocumentForm extends Component * @return void */ public function __construct( - $type, $documents = [], $bulkActions = [], - bool $hideBulkAction = false + $type, $document = false, + /** Advanced Component Start */ + 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, + /** Company Component End */ + /** Content Component Start */ + string $formRoute = '', string $formId = 'document', string $formSubmit = 'onSubmit', + bool $hideCompany = false, bool $hideAdvanced = false, bool $hideFooter = false, bool $hideButtons = false, + /** Content Component End */ + /** Metadata Component Start */ + $contacts = [], string $contactType = '', + bool $hideContact = false, bool $hideIssuedAt = false, bool $hideDocumentNumber = false, bool $hideDueAt = false, bool $hideOrderNumber = false, + string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', + string $issuedAt = '', string $documentNumber = '', string $dueAt = '', string $orderNumber = '', + /** Metadata Component End */ + /** Items Component Start */ + string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = '', + bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, + bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, + bool $hideEditItemColumns = false + /** Items Component End */ ) { $this->type = $type; - $this->documents = $documents; + $this->document = $document; - $this->bulkActions = $bulkActions; - $this->hideBulkAction = $hideBulkAction; + /** Advanced Component Start */ + $this->hideRecurring = $hideRecurring; + $this->hideCategory = $hideCategory; + $this->hideAttachment = $hideAttachment; + /** Advanced Component End */ + + /** Company Component Start */ + $this->hideLogo = $hideLogo; + $this->hideDocumentTitle = $hideDocumentTitle; + $this->hideDocumentSubheading = $hideDocumentSubheading; + $this->hideCompanyEdit = $hideCompanyEdit; + /** Company Component End */ + + /** Content Component Start */ + $this->formRoute = ($formRoute) ? $formRoute : $this->getRoute($type, $document); + $this->formId = $formId; + $this->formSubmit = $formSubmit; + + $this->hideCompany = $hideCompany; + $this->hideAdvanced = $hideAdvanced; + $this->hideFooter = $hideFooter; + $this->hideButtons = $hideButtons; + /** Content Component End */ + + /** Metadata Component Start */ + $this->contacts = $this->getContacts($type, $contacts); + $this->contactType = $this->getContactType($type, $contactType); + + $this->hideContact = $hideContact; + $this->hideIssuedAt = $hideIssuedAt; + $this->hideDocumentNumber = $hideDocumentNumber; + $this->hideDueAt = $hideDueAt; + $this->hideOrderNumber = $hideOrderNumber; + $this->issuedAt = $this->getIssuedAt($type, $document, $issuedAt); + $this->documentNumber = $this->getDocumentNumber($type, $document, $documentNumber); + $this->dueAt = $this->getDueAt($type, $document, $dueAt); + $this->orderNumber = $this->getOrderNumber($type, $document, $orderNumber); + + $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt); + $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber); + $this->textDueAt = $this->getTextDueAt($type, $textDueAt); + $this->textOrderNumber = $this->getTextOrderNumber($type, $textOrderNumber); + /** Metadata Component End */ + + /** Items Component Start */ + $this->textItems = $this->getTextItems($type, $textItems); + $this->textQuantity = $this->getTextQuantity($type, $textQuantity); + $this->textPrice = $this->getTextPrice($type, $textPrice); + $this->textAmount = $this->getTextAmount($type, $textAmount); + + $this->hideItems = $this->getHideItems($type, $hideItems, $hideName, $hideDescription); + $this->hideName = $this->getHideName($type, $hideName); + $this->hideDescription = $this->getHideDescription($type, $hideDescription); + $this->hideQuantity = $this->getHideQuantity($type, $hideQuantity); + $this->hidePrice = $this->getHidePrice($type, $hidePrice); + $this->hideDiscount = $this->getHideDiscount($type, $hideDiscount); + $this->hideAmount = $this->getHideAmount($type, $hideAmount); + + $this->hideEditItemColumns = $hideEditItemColumns; + /** Items Component End */ + } + + protected function getRoute($type, $document, $parameters = []) + { + $page = Str::plural($type, 2); + + $route = $page . '.store'; + + if ($document) { + $parameters = [ + Str::replaceFirst('-', '_', $type) => $document->id + ]; + + $route = $page . '.update'; + } + + try { + route($route, $parameters); + } catch (\Exception $e) { + $route = ''; + } + + return $route; + } + + protected function getContacts($type, $contacts) + { + if (!empty($contacts)) { + return $contacts; + } + + $contact_type = $this->getContactType($type, null); + + if ($contact_type) { + $contacts = Contact::$contact_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); + } else { + $contacts = Contact::enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); + } + + return $contacts; + } + + protected function getContactType($type, $contact_type) + { + if (!empty($contact_type)) { + return $contact_type; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $contact_type = 'customer'; + break; + case 'bill': + case 'expense': + case 'purchase': + $contact_type = 'vendor'; + break; + } + + return $contact_type; + } + + protected function getIssuedAt($type, $document, $issued_at) + { + if (!empty($issued_at)) { + return $issued_at; + } + + if ($document) { + return $document->issued_at; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $issued_at = request()->get('invoiced_at', Date::now()->toDateString()); + break; + case 'bill': + case 'expense': + case 'purchase': + $issued_at = request()->get('billed_at', Date::now()->toDateString()); + break; + } + + return $issued_at; + } + + protected function getDocumentNumber($type, $document, $document_number) + { + if (!empty($document_number)) { + return $document_number; + } + + if ($document) { + return $document->document_number; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE); + break; + case 'bill': + case 'expense': + case 'purchase': + $document_number = $this->getNextDocumentNumber(Document::BILL_TYPE); + break; + } + + return $document_number; + } + + protected function getDueAt($type, $document, $due_at) + { + if (!empty($due_at)) { + return $due_at; + } + + if ($document) { + return $document->due_at; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $due_at = Date::parse(request()->get('invoiced_at', Date::now()->toDateString()))->addDays(setting('invoice.payment_terms', 0))->toDateString(); + break; + case 'bill': + case 'expense': + case 'purchase': + $due_at = request()->get('billed_at', Date::now()->toDateString()); + break; + } + + return $due_at; + } + + protected function getOrderNumber($type, $document, $order_number) + { + if (!empty($order_number)) { + return $order_number; + } + + if ($document) { + return $document->order_number; + } + + $order_number = null; + } + + protected function getTextDocumentNumber($type, $textDocumentNumber) + { + if (!empty($textDocumentNumber)) { + return $textDocumentNumber; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $textDocumentNumber = 'invoices.invoice_number'; + break; + case 'bill': + case 'expense': + case 'purchase': + $textDocumentNumber = 'bills.bill_number'; + break; + } + + return $textDocumentNumber; + } + + protected function getTextOrderNumber($type, $textOrderNumber) + { + if (!empty($textOrderNumber)) { + return $textOrderNumber; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $textOrderNumber = 'invoices.order_number'; + break; + case 'bill': + case 'expense': + case 'purchase': + $textOrderNumber = 'bills.order_number'; + break; + } + + return $textOrderNumber; + } + + protected function getTextIssuedAt($type, $textIssuedAt) + { + if (!empty($textIssuedAt)) { + return $textIssuedAt; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $textIssuedAt = 'invoices.invoice_date'; + break; + case 'bill': + case 'expense': + case 'purchase': + $textIssuedAt = 'bills.bill_date'; + break; + } + + return $textIssuedAt; + } + + protected function getTextDueAt($type, $textDueAt) + { + if (!empty($textDueAt)) { + return $textDueAt; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $textDueAt = 'invoices.due_date'; + break; + case 'bill': + case 'expense': + case 'purchase': + $textDueAt = 'bills.due_date'; + break; + } + + return $textDueAt; + } + + protected function getTextItems($type, $text_items) + { + if (!empty($text_items)) { + return $text_items; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $text_items = setting('invoice.item_name', 'general.items'); + + if ($text_items == 'custom') { + $text_items = setting('invoice.item_name_input'); + } + break; + case 'bill': + case 'expense': + case 'purchase': + $text_items = 'general.items'; + break; + } + + return $text_items; + } + + protected function getTextQuantity($type, $text_quantity) + { + if (!empty($text_quantity)) { + return $text_quantity; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $text_quantity = setting('invoice.quantity_name', 'invoices.quantity'); + + if ($text_quantity == 'custom') { + $text_quantity = setting('invoice.quantity_name_input'); + } + break; + case 'bill': + case 'expense': + case 'purchase': + $text_quantity = 'bills.quantity'; + break; + } + + return $text_quantity; + } + + protected function getTextPrice($type, $text_price) + { + if (!empty($text_price)) { + return $text_price; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $text_price = setting('invoice.price_name', 'invoices.price'); + + if ($text_price == 'custom') { + $text_price = setting('invoice.price_name_input'); + } + break; + case 'bill': + case 'expense': + case 'purchase': + $text_price = 'bills.price'; + break; + } + + return $text_price; + } + + protected function getTextAmount($type, $text_amount) + { + if (!empty($text_amount)) { + return $text_amount; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + case 'bill': + case 'expense': + case 'purchase': + $text_amount = 'general.amount'; + break; + } + + return $text_amount; + } + + protected function getHideItems($type, $hideItems, $hideName, $hideDescription) + { + if (!empty($hideItems)) { + return $hideItems; + } + + $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; + + return $hideItems; + } + + protected function getHideName($type, $hideName) + { + if (!empty($hideName)) { + return $hideName; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hideName = setting('invoice.hide_item_name', $hideName); + break; + case 'bill': + case 'expense': + case 'purchase': + $hideName = setting('bill.hide_item_name', $hideName); + break; + } + + return $hideName; + } + + protected function getHideDescription($type, $hideDescription) + { + if (!empty($hideDescription)) { + return $hideDescription; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hideDescription = setting('invoice.hide_item_description', $hideDescription); + break; + case 'bill': + case 'expense': + case 'purchase': + $hideDescription = setting('bill.hide_item_description', $hideDescription); + break; + } + + return $hideDescription; + } + + protected function getHideQuantity($type, $hideQuantity) + { + if (!empty($hideQuantity)) { + return $hideQuantity; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); + break; + case 'bill': + case 'expense': + case 'purchase': + $hideQuantity = setting('bill.hide_quantity', $hideQuantity); + break; + } + + return $hideQuantity; + } + + protected function getHidePrice($type, $hidePrice) + { + if (!empty($hidePrice)) { + return $hidePrice; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hidePrice = setting('invoice.hide_price', $hidePrice); + break; + case 'bill': + case 'expense': + case 'purchase': + $hidePrice = setting('bill.hide_price', $hidePrice); + break; + } + + return $hidePrice; + } + + protected function getHideDiscount($type, $hideDiscount) + { + if (!empty($hideDiscount)) { + return $hideDiscount; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hideDiscount = setting('invoice.hide_discount', $hideDiscount); + break; + case 'bill': + case 'expense': + case 'purchase': + $hideDiscount = setting('bill.hide_discount', $hideDiscount); + break; + } + + return $hideDiscount; + } + + protected function getHideAmount($type, $hideAmount) + { + if (!empty($hideAmount)) { + return $hideAmount; + } + + switch ($type) { + case 'sale': + case 'income': + case 'invoice': + $hideAmount = setting('invoice.hide_amount', $hideAmount); + break; + case 'bill': + case 'expense': + case 'purchase': + $hideAmount = setting('bill.hide_amount', $hideAmount); + break; + } + + return $hideAmount; } } diff --git a/app/View/Components/Documents/Form/Advanced.php b/app/View/Components/Documents/Form/Advanced.php index 22faa6c64..cb1494cd9 100644 --- a/app/View/Components/Documents/Form/Advanced.php +++ b/app/View/Components/Documents/Form/Advanced.php @@ -2,37 +2,11 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; use App\Models\Setting\Category; class Advanced extends Component { - /** @var string */ - public $type; - - /** @var bool */ - public $hideRecurring; - - /** @var bool */ - public $hideCategory; - - /** @var bool */ - public $hideAttachment; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct(string $type, bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false) - { - $this->type = $type; - - $this->hideRecurring = $hideRecurring; - $this->hideCategory = $hideCategory; - $this->hideAttachment = $hideAttachment; - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Buttons.php b/app/View/Components/Documents/Form/Buttons.php index b1988e41f..e523ca6aa 100644 --- a/app/View/Components/Documents/Form/Buttons.php +++ b/app/View/Components/Documents/Form/Buttons.php @@ -2,23 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class Buttons extends Component { - /** @var string */ - public $type; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct($type) - { - $this->type = $type; - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Company.php b/app/View/Components/Documents/Form/Company.php index fe966fe99..b8dd1da79 100644 --- a/app/View/Components/Documents/Form/Company.php +++ b/app/View/Components/Documents/Form/Company.php @@ -2,41 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\Support\Str; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class Company extends Component { - /** @var string */ - public $type; - - /** @var bool */ - public $hideLogo; - - /** @var bool */ - public $hideDocumentTitle; - - /** @var bool */ - public $hideDocumentSubheading; - - /** @var bool */ - public $hideCompanyEdit; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct( - string $type, bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false - ) { - $this->type = $type; - $this->hideLogo = $hideLogo; - $this->hideDocumentTitle = $hideDocumentTitle; - $this->hideDocumentSubheading = $hideDocumentSubheading; - $this->hideCompanyEdit = $hideCompanyEdit; - } - /** * Get the view / contents that represent the component. * @@ -50,29 +19,4 @@ class Company extends Component return view('components.documents.form.company', compact('company','inputNameType')); } - - protected function getFilterName($column) - { - if (strpos($column, '_id') !== false) { - $column = str_replace('_id', '', $column); - } else if (strpos($column, '_code') !== false) { - $column = str_replace('_code', '', $column); - } - - $plural = Str::plural($column, 2); - - if (trans_choice('general.' . $plural, 1) !== 'general.' . $plural) { - return trans_choice('general.' . $plural, 1); - } elseif (trans_choice('search_string.columns.' . $plural, 1) !== 'search_string.columns.' . $plural) { - return trans_choice('search_string.columns.' . $plural, 1); - } - - $name = trans('general.' . $column); - - if ($name == 'general.' . $column) { - $name = trans('search_string.columns.' . $column); - } - - return $name; - } } diff --git a/app/View/Components/Documents/Form/Content.php b/app/View/Components/Documents/Form/Content.php index 2186b43ae..c86339410 100644 --- a/app/View/Components/Documents/Form/Content.php +++ b/app/View/Components/Documents/Form/Content.php @@ -2,152 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; -use Illuminate\Support\Str; +use App\Abstracts\View\Components\DocumentForm as Component; class Content extends Component { - /** @var string */ - public $type; - - public $document; - - /** @var string */ - public $formRoute; - - /** @var string */ - public $formId; - - /** @var string */ - public $formSubmit; - - /** @var bool */ - public $hideCompany; - - /** @var bool */ - public $hideAdvanced; - - /** @var bool */ - public $hideFooter; - - /** @var bool */ - public $hideButtons; - - /* Company Component Field Status */ - /** @var bool */ - public $hideLogo; - - /** @var bool */ - public $hideDocumentTitle; - - /** @var bool */ - public $hideDocumentSubheading; - - /** @var bool */ - public $hideCompanyEdit; - /* Company Component Field Status */ - - /* Main.Header Fields */ - /** @var string */ - public $contactType; - - /** @var string */ - public $documentNumber; - - /** @var string */ - public $textIssuedAt; - - /** @var string */ - public $textDueAt; - - /** @var string */ - public $textDocumentNumber; - - /** @var string */ - public $textOrderNumber; - /* Main.Header Fields */ - - /* Main.Header Component Field Status */ - /** @var bool */ - public $hideContact; - - /** @var bool */ - public $hideIssuedAt; - - /** @var bool */ - public $hideDocumentNumber; - - /** @var bool */ - public $hideDueAt; - - /** @var bool */ - public $hideOrderNumber; - /* Main.Header Component Field Status */ - - /* Advanced Component Field Status */ - /** @var bool */ - public $hideRecurring; - - /** @var bool */ - public $hideCategory; - - /** @var bool */ - public $hideAttachment; - /* Advanced Component Field Status */ - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct( - string $type, $document = false, string $formRoute = '', string $formId = 'document', string $formSubmit = 'onSubmit', bool $hideCompany = false, bool $hideAdvanced = false, bool $hideFooter = false, bool $hideButtons = false, - bool $hideLogo = false, bool $hideDocumentTitle = false, bool $hideDocumentSubheading = false, bool $hideCompanyEdit = false, // Company - string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', // Main.Header - string $contactType = '', string $documentNumber = '', - bool $hideContact = false, bool $hideIssuedAt = false, bool $hideDocumentNumber = false, bool $hideDueAt = false, bool $hideOrderNumber = false, // Main.Header - bool $hideRecurring = false, bool $hideCategory = false, bool $hideAttachment = false // Advanced - ) - { - $this->type = $type; - $this->document = $document; - $this->formRoute = ($formRoute) ? $formRoute : $this->getRoute($type, $document); - $this->formId = $formId; - $this->formSubmit = $formSubmit; - - $this->hideCompany = $hideCompany; - $this->hideAdvanced = $hideAdvanced; - $this->hideFooter = $hideFooter; - $this->hideButtons = $hideButtons; - - // Company component fields status - $this->hideLogo = $hideLogo; - $this->hideDocumentTitle = $hideDocumentTitle; - $this->hideDocumentSubheading = $hideDocumentSubheading; - $this->hideCompanyEdit = $hideCompanyEdit; - - // Main.Header fields - $this->contactType = $contactType; - $this->documentNumber = $documentNumber; - - $this->textIssuedAt = $textIssuedAt; - $this->textDocumentNumber = $textDocumentNumber; - $this->textDueAt = $textDueAt; - $this->textOrderNumber = $textOrderNumber; - - // Main.Header component fields status - $this->hideContact = $hideContact; - $this->hideIssuedAt = $hideIssuedAt; - $this->hideDocumentNumber = $hideDocumentNumber; - $this->hideDueAt = $hideDueAt; - $this->hideOrderNumber = $hideOrderNumber; - - // Advanced component fields status - $this->hideRecurring = $hideRecurring; - $this->hideCategory = $hideCategory; - $this->hideAttachment = $hideAttachment; - } - /** * Get the view / contents that represent the component. * @@ -157,27 +15,4 @@ class Content extends Component { return view('components.documents.form.content'); } - - protected function getRoute($type, $document, $parameters = []) - { - $page = Str::plural($type, 2); - - $route = $page . '.store'; - - if ($document) { - $parameters = [ - Str::replaceFirst('-', '_', $type) => $document->id - ]; - - $route = $page . '.update'; - } - - try { - route($route, $parameters); - } catch (\Exception $e) { - $route = ''; - } - - return $route; - } } diff --git a/app/View/Components/Documents/Form/Footer.php b/app/View/Components/Documents/Form/Footer.php index 918a7bbd6..772880ca2 100644 --- a/app/View/Components/Documents/Form/Footer.php +++ b/app/View/Components/Documents/Form/Footer.php @@ -2,23 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class Footer extends Component { - /** @var string */ - public $type; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct($type) - { - $this->type = $type; - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Items.php b/app/View/Components/Documents/Form/Items.php index 9987156ef..442b2b146 100644 --- a/app/View/Components/Documents/Form/Items.php +++ b/app/View/Components/Documents/Form/Items.php @@ -2,85 +2,13 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; use App\Models\Setting\Currency; use App\Models\Setting\Tax; class Items extends Component { - /** @var string */ - public $type; - - public $document; - - /** @var bool */ - public $hideEditItemColumns; - - /** @var string */ - public $textItems; - - /** @var string */ - public $textQuantity; - - /** @var string */ - public $textPrice; - - /** @var string */ - public $textAmount; - - /** @var bool */ - public $hideItems; - - /** @var bool */ - public $hideName; - - /** @var bool */ - public $hideDescription; - - /** @var bool */ - public $hideQuantity; - - /** @var bool */ - public $hidePrice; - - /** @var bool */ - public $hideDiscount; - - /** @var bool */ - public $hideAmount; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct( - string $type, $document = false, - string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = '', - bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, - bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, - bool $hideEditItemColumns = false - ) { - $this->type = $type; - $this->document = $document; - - $this->textItems = $this->getTextItems($type, $textItems); - $this->textQuantity = $this->getTextQuantity($type, $textQuantity); - $this->textPrice = $this->getTextPrice($type, $textPrice); - $this->textAmount = $this->getTextAmount($type, $textAmount); - - $this->hideItems = $this->getHideItems($type, $hideItems, $hideName, $hideDescription); - $this->hideName = $this->getHideName($type, $hideName); - $this->hideDescription = $this->getHideDescription($type, $hideDescription); - $this->hideQuantity = $this->getHideQuantity($type, $hideQuantity); - $this->hidePrice = $this->getHidePrice($type, $hidePrice); - $this->hideDiscount = $this->getHideDiscount($type, $hideDiscount); - $this->hideAmount = $this->getHideAmount($type, $hideAmount); - - $this->hideEditItemColumns = $hideEditItemColumns; - } - /** * Get the view / contents that represent the component. * @@ -94,245 +22,4 @@ class Items extends Component return view('components.documents.form.items', compact('currency', 'taxes')); } - - protected function getTextItems($type, $text_items) - { - if (!empty($text_items)) { - return $text_items; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $text_items = setting('invoice.item_name', 'general.items'); - - if ($text_items == 'custom') { - $text_items = setting('invoice.item_name_input'); - } - break; - case 'bill': - case 'expense': - case 'purchase': - $text_items = 'general.items'; - break; - } - - return $text_items; - } - - protected function getTextQuantity($type, $text_quantity) - { - if (!empty($text_quantity)) { - return $text_quantity; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $text_quantity = setting('invoice.quantity_name', 'invoices.quantity'); - - if ($text_quantity == 'custom') { - $text_quantity = setting('invoice.quantity_name_input'); - } - break; - case 'bill': - case 'expense': - case 'purchase': - $text_quantity = 'bills.quantity'; - break; - } - - return $text_quantity; - } - - protected function getTextPrice($type, $text_price) - { - if (!empty($text_price)) { - return $text_price; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $text_price = setting('invoice.price_name', 'invoices.price'); - - if ($text_price == 'custom') { - $text_price = setting('invoice.price_name_input'); - } - break; - case 'bill': - case 'expense': - case 'purchase': - $text_price = 'bills.price'; - break; - } - - return $text_price; - } - - protected function getTextAmount($type, $text_amount) - { - if (!empty($text_amount)) { - return $text_amount; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - case 'bill': - case 'expense': - case 'purchase': - $text_amount = 'general.amount'; - break; - } - - return $text_amount; - } - - protected function getHideItems($type, $hideItems, $hideName, $hideDescription) - { - if (!empty($hideItems)) { - return $hideItems; - } - - $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false; - - return $hideItems; - } - - protected function getHideName($type, $hideName) - { - if (!empty($hideName)) { - return $hideName; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hideName = setting('invoice.hide_item_name', $hideName); - break; - case 'bill': - case 'expense': - case 'purchase': - $hideName = setting('bill.hide_item_name', $hideName); - break; - } - - return $hideName; - } - - protected function getHideDescription($type, $hideDescription) - { - if (!empty($hideDescription)) { - return $hideDescription; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hideDescription = setting('invoice.hide_item_description', $hideDescription); - break; - case 'bill': - case 'expense': - case 'purchase': - $hideDescription = setting('bill.hide_item_description', $hideDescription); - break; - } - - return $hideDescription; - } - - protected function getHideQuantity($type, $hideQuantity) - { - if (!empty($hideQuantity)) { - return $hideQuantity; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hideQuantity = setting('invoice.hide_quantity', $hideQuantity); - break; - case 'bill': - case 'expense': - case 'purchase': - $hideQuantity = setting('bill.hide_quantity', $hideQuantity); - break; - } - - return $hideQuantity; - } - - protected function getHidePrice($type, $hidePrice) - { - if (!empty($hidePrice)) { - return $hidePrice; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hidePrice = setting('invoice.hide_price', $hidePrice); - break; - case 'bill': - case 'expense': - case 'purchase': - $hidePrice = setting('bill.hide_price', $hidePrice); - break; - } - - return $hidePrice; - } - - protected function getHideDiscount($type, $hideDiscount) - { - if (!empty($hideDiscount)) { - return $hideDiscount; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hideDiscount = setting('invoice.hide_discount', $hideDiscount); - break; - case 'bill': - case 'expense': - case 'purchase': - $hideDiscount = setting('bill.hide_discount', $hideDiscount); - break; - } - - return $hideDiscount; - } - - protected function getHideAmount($type, $hideAmount) - { - if (!empty($hideAmount)) { - return $hideAmount; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $hideAmount = setting('invoice.hide_amount', $hideAmount); - break; - case 'bill': - case 'expense': - case 'purchase': - $hideAmount = setting('bill.hide_amount', $hideAmount); - break; - } - - return $hideAmount; - } } diff --git a/app/View/Components/Documents/Form/LineItem.php b/app/View/Components/Documents/Form/LineItem.php index 23efb5142..8ba674a4e 100644 --- a/app/View/Components/Documents/Form/LineItem.php +++ b/app/View/Components/Documents/Form/LineItem.php @@ -2,20 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class LineItem extends Component { - /** - * Create a new component instance. - * - * @return void - */ - public function __construct() - { - // - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Main.php b/app/View/Components/Documents/Form/Main.php index 11fadb1b1..bb590876b 100644 --- a/app/View/Components/Documents/Form/Main.php +++ b/app/View/Components/Documents/Form/Main.php @@ -2,83 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class Main extends Component { - /** @var string */ - public $type; - - public $document; - - /* Main.Header Fields */ - /** @var string */ - public $contactType; - - /** @var string */ - public $documentNumber; - - /** @var string */ - public $textIssuedAt; - - /** @var string */ - public $textDueAt; - - /** @var string */ - public $textDocumentNumber; - - /** @var string */ - public $textOrderNumber; - /* Main.Header Fields */ - - /* Main.Header Component Field Status */ - /** @var bool */ - public $hideContact; - - /** @var bool */ - public $hideIssuedAt; - - /** @var bool */ - public $hideDocumentNumber; - - /** @var bool */ - public $hideDueAt; - - /** @var bool */ - public $hideOrderNumber; - /* Main.Header Component Field Status */ - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct( - $type, $document = false, - string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', // Main.Header - string $contactType = '', string $documentNumber = '', - bool $hideContact = false, bool $hideIssuedAt = false, bool $hideDocumentNumber = false, bool $hideDueAt = false, bool $hideOrderNumber = false // Main.Header - ) { - $this->type = $type; - $this->document = $document; - - // Main.Header fields - $this->contactType = $contactType; - $this->documentNumber = $documentNumber; - - $this->textIssuedAt = $textIssuedAt; - $this->textDocumentNumber = $textDocumentNumber; - $this->textDueAt = $textDueAt; - $this->textOrderNumber = $textOrderNumber; - - // Main.Header component fields status - $this->hideContact = $hideContact; - $this->hideIssuedAt = $hideIssuedAt; - $this->hideDocumentNumber = $hideDocumentNumber; - $this->hideDueAt = $hideDueAt; - $this->hideOrderNumber = $hideOrderNumber; - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Metadata.php b/app/View/Components/Documents/Form/Metadata.php index f6d96dec8..382f72e2e 100644 --- a/app/View/Components/Documents/Form/Metadata.php +++ b/app/View/Components/Documents/Form/Metadata.php @@ -2,98 +2,11 @@ namespace App\View\Components\Documents\Form; -use App\Models\Common\Contact; -use App\Models\Document\Document; -use App\Traits\Documents; -use Date; -use Illuminate\View\Component; -use Illuminate\Support\Str; + +use App\Abstracts\View\Components\DocumentForm as Component; class Metadata extends Component { - use Documents; - - /** @var string */ - public $type; - - public $document; - - public $contacts; - - /** @var string */ - public $contactType; - - /** @var bool */ - public $hideContact; - - /** @var bool */ - public $hideIssuedAt; - - /** @var bool */ - public $hideDocumentNumber; - - /** @var bool */ - public $hideDueAt; - - /** @var bool */ - public $hideOrderNumber; - - /** @var string */ - public $issuedAt; - - /** @var string */ - public $documentNumber; - - /** @var string */ - public $dueAt; - - /** @var string */ - public $orderNumber; - - /** @var string */ - public $textIssuedAt; - - /** @var string */ - public $textDueAt; - - /** @var string */ - public $textDocumentNumber; - - /** @var string */ - public $textOrderNumber; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct( - string $type, $document = false, $contacts = [], string $contactType = '', - bool $hideContact = false, bool $hideIssuedAt = false, bool $hideDocumentNumber = false, bool $hideDueAt = false, bool $hideOrderNumber = false, - string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '', - string $issuedAt = '', string $documentNumber = '', string $dueAt = '', string $orderNumber = '' - ) { - $this->type = $type; - $this->document = $document; - $this->contacts = $this->getContacts($type, $contacts); - $this->contactType = $this->getContactType($type, $contactType); - - $this->hideContact = $hideContact; - $this->hideIssuedAt = $hideIssuedAt; - $this->hideDocumentNumber = $hideDocumentNumber; - $this->hideDueAt = $hideDueAt; - $this->hideOrderNumber = $hideOrderNumber; - $this->issuedAt = $this->getissuedAt($type, $document, $issuedAt); - $this->documentNumber = $this->getDocumentNumber($type, $document, $documentNumber); - $this->dueAt = $this->getDueAt($type, $document, $dueAt); - $this->orderNumber = $this->getOrderNumber($type, $document, $orderNumber); - - $this->textIssuedAt = $this->gettextIssuedAt($type, $textIssuedAt); - $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber); - $this->textDueAt = $this->getTextDueAt($type, $textDueAt); - $this->textOrderNumber = $this->getTextOrderNumber($type, $textOrderNumber); - } - /** * Get the view / contents that represent the component. * @@ -103,222 +16,4 @@ class Metadata extends Component { return view('components.documents.form.metadata'); } - - protected function getContacts($type, $contacts) - { - if (!empty($contacts)) { - return $contacts; - } - - $contact_type = $this->getContactType($type, null); - - if ($contact_type) { - $contacts = Contact::$contact_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); - } else { - $contacts = Contact::enabled()->orderBy('name')->take(setting('default.select_limit'))->pluck('name', 'id'); - } - - return $contacts; - } - - protected function getContactType($type, $contact_type) - { - if (!empty($contact_type)) { - return $contact_type; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $contact_type = 'customer'; - break; - case 'bill': - case 'expense': - case 'purchase': - $contact_type = 'vendor'; - break; - } - - return $contact_type; - } - - protected function getissuedAt($type, $document, $issued_at) - { - if (!empty($issued_at)) { - return $issued_at; - } - - if ($document) { - return $document->issued_at; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $issued_at = request()->get('invoiced_at', Date::now()->toDateString()); - break; - case 'bill': - case 'expense': - case 'purchase': - $issued_at = request()->get('billed_at', Date::now()->toDateString()); - break; - } - - return $issued_at; - } - - protected function getDocumentNumber($type, $document, $document_number) - { - if (!empty($document_number)) { - return $document_number; - } - - if ($document) { - return $document->document_number; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE); - break; - case 'bill': - case 'expense': - case 'purchase': - $document_number = $this->getNextDocumentNumber(Document::BILL_TYPE); - break; - } - - return $document_number; - } - - protected function getDueAt($type, $document, $due_at) - { - if (!empty($due_at)) { - return $due_at; - } - - if ($document) { - return $document->due_at; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $due_at = Date::parse(request()->get('invoiced_at', Date::now()->toDateString()))->addDays(setting('invoice.payment_terms', 0))->toDateString(); - break; - case 'bill': - case 'expense': - case 'purchase': - $due_at = request()->get('billed_at', Date::now()->toDateString()); - break; - } - - return $due_at; - } - - protected function getOrderNumber($type, $document, $order_number) - { - if (!empty($order_number)) { - return $order_number; - } - - if ($document) { - return $document->order_number; - } - - $order_number = null; - } - - protected function getTextDocumentNumber($type, $textDocumentNumber) - { - if (!empty($textDocumentNumber)) { - return $textDocumentNumber; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $textDocumentNumber = 'invoices.invoice_number'; - break; - case 'bill': - case 'expense': - case 'purchase': - $textDocumentNumber = 'bills.bill_number'; - break; - } - - return $textDocumentNumber; - } - - protected function getTextOrderNumber($type, $textOrderNumber) - { - if (!empty($textOrderNumber)) { - return $textOrderNumber; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $textOrderNumber = 'invoices.order_number'; - break; - case 'bill': - case 'expense': - case 'purchase': - $textOrderNumber = 'bills.order_number'; - break; - } - - return $textOrderNumber; - } - - protected function gettextIssuedAt($type, $textIssuedAt) - { - if (!empty($textIssuedAt)) { - return $textIssuedAt; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $textIssuedAt = 'invoices.invoice_date'; - break; - case 'bill': - case 'expense': - case 'purchase': - $textIssuedAt = 'bills.bill_date'; - break; - } - - return $textIssuedAt; - } - - protected function getTextDueAt($type, $textDueAt) - { - if (!empty($textDueAt)) { - return $textDueAt; - } - - switch ($type) { - case 'sale': - case 'income': - case 'invoice': - $textDueAt = 'invoices.due_date'; - break; - case 'bill': - case 'expense': - case 'purchase': - $textDueAt = 'bills.due_date'; - break; - } - - return $textDueAt; - } } diff --git a/app/View/Components/Documents/Form/Note.php b/app/View/Components/Documents/Form/Note.php index 8d04f4a18..f1089990d 100644 --- a/app/View/Components/Documents/Form/Note.php +++ b/app/View/Components/Documents/Form/Note.php @@ -2,23 +2,10 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; class Note extends Component { - /** @var string */ - public $type; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct($type) - { - $this->type = $type; - } - /** * Get the view / contents that represent the component. * diff --git a/app/View/Components/Documents/Form/Totals.php b/app/View/Components/Documents/Form/Totals.php index 4331d8490..c897797b9 100644 --- a/app/View/Components/Documents/Form/Totals.php +++ b/app/View/Components/Documents/Form/Totals.php @@ -2,24 +2,11 @@ namespace App\View\Components\Documents\Form; -use Illuminate\View\Component; +use App\Abstracts\View\Components\DocumentForm as Component; use App\Models\Setting\Currency; class Totals extends Component { - /** @var string */ - public $type; - - /** - * Create a new component instance. - * - * @return void - */ - public function __construct($type) - { - $this->type = $type; - } - /** * Get the view / contents that represent the component. * diff --git a/resources/views/components/documents/form/content.blade.php b/resources/views/components/documents/form/content.blade.php index 362b3b671..bcc3f1c40 100644 --- a/resources/views/components/documents/form/content.blade.php +++ b/resources/views/components/documents/form/content.blade.php @@ -45,6 +45,16 @@ text-due-at="{{ $textDueAt }}" hide-order-number="{{ $hideOrderNumber }}" text-order-number="{{ $textOrderNumber }}" + hide-edit-item-columns="{{ $hideEditItemColumns }}" + hide-items="{{ $hideItems }}" + text-items="{{ $textItems }}" + hide-quantity="{{ $hideQuantity }}" + text-quantity="{{ $textQuantity }}" + hide-price="{{ $hidePrice }}" + text-price="{{ $textPrice }}" + hide-discount="{{ $hideDiscount }}" + hide-amount="{{ $hideAmount }}" + text-amount="{{ $textAmount }}" /> @if (!$hideFooter) diff --git a/resources/views/components/documents/form/items.blade.php b/resources/views/components/documents/form/items.blade.php index bbe45d58a..140a619f8 100644 --- a/resources/views/components/documents/form/items.blade.php +++ b/resources/views/components/documents/form/items.blade.php @@ -24,7 +24,9 @@ @if (!$hideItems) @stack('name_th_start') -