Merge pull request #1742 from cuneytsenturk/master

Add Document/Transaction/Contact types to the config vol 2
This commit is contained in:
Cüneyt Şentürk 2021-01-12 00:28:19 +03:00 committed by GitHub
commit de27dbf116
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 1456 additions and 1093 deletions

View File

@ -0,0 +1,175 @@
<?php
namespace App\Abstracts\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
abstract class Document extends Component
{
public function getTextFromConfig($type, $config_key, $default_key = '', $trans_type = 'trans')
{
$translation = '';
// if set config trasnlation config_key
if ($translation = config('type.' . $type . '.translation.' . $config_key)) {
return $translation;
}
$alias = config('type.' . $type . '.alias');
$prefix = config('type.' . $type . '.translation.prefix');
if (!empty($alias)) {
$alias .= '::';
}
// This magic trans key..
$translations = [
'general' => $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, $config_parameters = [])
{
$route = '';
// if set config trasnlation config_key
if ($route = config('type.' . $type . '.route.' . $config_key)) {
return $route;
}
$alias = config('type.' . $type . '.alias');
$prefix = config('type.' . $type . '.route.prefix');
// if use module set module alias
if (!empty($alias)) {
$route .= $alias . '.';
}
if (!empty($prefix)) {
$route .= $prefix . '.';
}
$route .= $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)
{
$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 = $config_key . '-';
// 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;
}
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;
}
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;
}
}

View File

@ -2,13 +2,14 @@
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;
@ -17,6 +18,9 @@ abstract class DocumentForm extends Component
public $document;
/** Advanced Component Start */
/** @var string */
public $categoryType;
/** @var bool */
public $hideRecurring;
@ -43,7 +47,13 @@ abstract class DocumentForm extends Component
/** Content Component Start */
/** @var string */
public $formRoute;
public $routeStore;
/** @var string */
public $routeUpdate;
/** @var string */
public $routeCancel;
/** @var string */
public $formId;
@ -185,13 +195,13 @@ abstract class DocumentForm extends Component
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,
/** Company Component End */
/** Content Component Start */
string $formRoute = '', 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 */
@ -213,6 +223,7 @@ abstract class DocumentForm extends Component
$this->document = $document;
/** Advanced Component Start */
$this->categoryType = $this->getCategoryType($type, $categoryType);
$this->hideRecurring = $hideRecurring;
$this->hideCategory = $hideCategory;
$this->hideAttachment = $hideAttachment;
@ -226,7 +237,9 @@ 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->routeCancel = $this->getRouteCancel($type, $routeCancel);
$this->formId = $formId;
$this->formSubmit = $formSubmit;
@ -283,27 +296,69 @@ 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");
$route = $page . '.store';
if ($document) {
$parameters = [
config("type.{$type}.route_parameter") => $document->id
];
$route = $page . '.update';
if (!empty($routeStore)) {
return $routeStore;
}
try {
route($route, $parameters);
} catch (\Exception $e) {
$route = '';
$route = $this->getRouteFromConfig($type, 'store');
if (!empty($route)) {
return $route;
}
return $route;
return 'invoices.store';
}
protected function getRouteUpdate($type, $routeUpdate, $document, $parameters = [])
{
if (!empty($routeUpdate)) {
return $routeUpdate;
}
$parameters = [
config('type.' . $type. '.route.parameter') => ($document) ? $document->id : 1,
];
$route = $this->getRouteFromConfig($type, 'update', $parameters);
if (!empty($route)) {
return $route;
}
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 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)
@ -338,13 +393,20 @@ abstract class DocumentForm extends Component
return $contact;
}
protected function getContactType($type, $contact_type)
protected function getContactType($type, $contactType)
{
if (!empty($contact_type)) {
if (!empty($contactType)) {
return $contactType;
}
if ($contact_type = config('type.' . $type . '.contact_type')) {
return $contact_type;
}
return config("type.{$type}.contact_type");
// set default type
$type = Document::INVOICE_TYPE;
return config('type.' . $type . '.contact_type');
}
protected function getTextAddContact($type, $textAddContact)
@ -353,24 +415,21 @@ 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;
$default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
$translation = $this->getTextFromConfig($type, 'add_contact', $default_key, '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 +438,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;
$default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
$translation = $this->getTextFromConfig($type, 'create_new_contact', $default_key, '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 +461,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 +480,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,83 +502,74 @@ 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;
$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 [
'general.form.choose_different',
$translation,
];
}
return $textChooseDifferentContact;
return [
'general.form.choose_different',
'general.customers',
];
}
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 {
$issuedAt = request()->get('invoiced_at', Date::now()->toDateString());
}
return $issued_at;
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) {
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;
}
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) {
return $document->due_at;
}
$addDays = (setting($type . '.payment_terms', 0)) ? setting($type . '.payment_terms', 0) : setting('invoice.payment_terms', 0);
switch ($type) {
case 'bill':
@ -530,17 +578,17 @@ abstract class DocumentForm extends Component
$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;
}
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) {
@ -560,14 +608,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 +630,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 +649,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,101 +671,88 @@ 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)
protected function getTextAmount($type, $textAmount)
{
if (!empty($text_amount)) {
return $text_amount;
if (!empty($textAmount)) {
return $textAmount;
}
$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)
@ -719,6 +761,12 @@ abstract class DocumentForm extends Component
return $hideItems;
}
$hide = $this->getHideFromConfig($type, 'items');
if ($hide) {
return $hide;
}
$hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
return $hideItems;
@ -730,18 +778,19 @@ abstract class DocumentForm extends Component
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)
@ -750,18 +799,19 @@ abstract class DocumentForm extends Component
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)
@ -770,18 +820,19 @@ abstract class DocumentForm extends Component
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)
@ -790,18 +841,19 @@ abstract class DocumentForm extends Component
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)
@ -810,18 +862,19 @@ abstract class DocumentForm extends Component
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)
@ -830,17 +883,18 @@ abstract class DocumentForm extends Component
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);
}
}

View File

@ -2,11 +2,12 @@
namespace App\Abstracts\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
use Akaunting\Module\Module;
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;
@ -235,7 +236,7 @@ abstract class DocumentIndex extends Component
/* -- 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);
@ -267,7 +268,7 @@ abstract class DocumentIndex extends Component
$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,7 +293,7 @@ abstract class DocumentIndex extends Component
return $page;
}
return config("type.{$type}.route_name");
return config('type.' . $type . '.route.prefix', 'invoices');
}
protected function getDocsPath($type, $docsPath)
@ -301,6 +302,12 @@ abstract class DocumentIndex extends Component
return $docsPath;
}
$docs_path = config('type.' . $type . '.docs_path');
if (!empty($docs_path)) {
return $docs_path;
}
switch ($type) {
case 'sale':
case 'income':
@ -323,17 +330,13 @@ abstract class DocumentIndex extends Component
return $createRoute;
}
$page = config("type.{$type}.route_name");
$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,9 +356,21 @@ abstract class DocumentIndex extends Component
return $importRouteParameters;
}
$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"),
'type' => config("type.{$type}.route_name")
'group' => $group,
'type' => config('type.' . $type . '.route.prefix'),
'route' => ($route) ? $route : 'invoices.import',
];
return $importRouteParameters;
@ -367,17 +382,13 @@ abstract class DocumentIndex extends Component
return $exportRoute;
}
$page = config("type.{$type}.route_name");
$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)
@ -386,17 +397,13 @@ abstract class DocumentIndex extends Component
return $formCardHeaderRoute;
}
$page = config("type.{$type}.route_name");
$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)
@ -405,17 +412,22 @@ abstract class DocumentIndex extends Component
return $searchStringModel;
}
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;
$search_string_model = config('type.' . $type . '.search_string_model');
if (!empty($search_string_model)) {
return $search_string_model;
}
if ($group = config('type.' . $type . '.group')) {
$group = Str::studly(Str::singular($group)) . '\\';
}
$prefix = Str::studly(Str::singular(config('type.' . $type . '.route.prefix')));
if ($alias = config('type.' . $type . '.alias')) {
$searchStringModel = 'Modules\\' . Str::studly($alias) .'\Models\\' . $group . $prefix;
} else {
$searchStringModel = 'App\Models\\' . $group . $prefix;
}
return $searchStringModel;
@ -427,9 +439,15 @@ abstract class DocumentIndex extends Component
return $textBulkAction;
}
$textBulkAction = 'general.' . config("type.{$type}.translation_key");
$default_key = config('type.' . $type . '.translation.prefix');
return $textBulkAction;
$translation = $this->getTextFromConfig($type, 'bulk_action', $default_key, 'trans_choice');
if (!empty($translation)) {
return $translation;
}
return 'general.invoices';
}
protected function getBulkActions($type, $bulkActions, $bulkActionClass)
@ -438,17 +456,37 @@ abstract class DocumentIndex extends Component
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) {
$b = new \stdClass();
$b->actions = [];
event(new BulkActionsAdding($b));
return $b->actions;
}
$bulkActionClass = 'Modules\\' . $module->getStudlyName() . '\BulkActions\\' . $file_name;
} else {
$bulkActionClass = 'App\BulkActions\\' . $file_name;
}
if (class_exists($bulkActionClass)) {
@ -473,9 +511,15 @@ abstract class DocumentIndex extends Component
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_name")
'group' => $group,
'type' => config('type.' . $type . '.route.prefix')
];
return $bulkActionRouteParameters;
@ -487,15 +531,27 @@ abstract class DocumentIndex extends Component
return $classBulkAction;
}
$class = $this->getClassFromConfig($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';
}
protected function getTextDocumentNumber($textDocumentNumber)
protected function getTextDocumentNumber($type, $textDocumentNumber)
{
if (!empty($textDocumentNumber)) {
return $textDocumentNumber;
}
$translation = $this->getTextFromConfig($type, 'document_number', 'numbers');
if (!empty($translation)) {
return $translation;
}
return 'general.numbers';
}
@ -509,6 +565,12 @@ abstract class DocumentIndex extends Component
return $classDocumentNumber;
}
$class = $this->getClassFromConfig($type, 'document_number');
if (!empty($class)) {
return $class;
}
return 'col-md-2 col-lg-1 col-xl-1 d-none d-md-block';
}
@ -518,18 +580,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;
$default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
$translation = $this->getTextFromConfig($type, 'contact_name', $default_key, 'trans_choice');
if (!empty($translation)) {
return $translation;
}
return $textContactName;
return 'general.customers';
}
protected function getClassContactName($type, $classContactName)
@ -542,6 +601,12 @@ abstract class DocumentIndex extends Component
return $classContactName;
}
$class = $this->getClassFromConfig($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';
}
@ -555,6 +620,12 @@ abstract class DocumentIndex extends Component
return $classAmount;
}
$class = $this->getClassFromConfig($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';
}
@ -568,17 +639,23 @@ abstract class DocumentIndex 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 getclassIssuedAt($type, $classIssuedAt)
protected function getClassIssuedAt($type, $classIssuedAt)
{
if (!empty($classIssuedAt)) {
return $classIssuedAt;
@ -588,6 +665,12 @@ abstract class DocumentIndex extends Component
return $classIssuedAt;
}
$class = $this->getClassFromConfig($type, 'issued_at');
if (!empty($class)) {
return $class;
}
return 'col-lg-2 col-xl-2 d-none d-lg-block text-left';
}
@ -597,18 +680,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', 'due_date');
if (!empty($translation)) {
return $translation;
}
return $textDueAt;
return 'invoices.due_date';
}
protected function getClassDueAt($type, $classDueAt)
@ -617,6 +695,12 @@ abstract class DocumentIndex extends Component
return $classDueAt;
}
$class = $this->getClassFromConfig($type, 'due_at');
if (!empty($class)) {
return $class;
}
if ($classDueAt = $this->getClass('classDueAt')) {
return $classDueAt;
}
@ -630,18 +714,23 @@ abstract class DocumentIndex extends Component
return $textDocumentStatus;
}
switch ($type) {
case 'bill':
case 'expense':
case 'purchase':
$textDocumentStatus = 'bills.statuses.';
break;
default:
$textDocumentStatus = 'invoices.statuses.';
break;
$translation = $this->getTextFromConfig($type, 'document_status', 'statuses.');
if (!empty($translation)) {
return $translation;
}
return $textDocumentStatus;
$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)
@ -654,6 +743,12 @@ abstract class DocumentIndex extends Component
return $classStatus;
}
$class = $this->getClassFromConfig($type, 'status');
if (!empty($class)) {
return $class;
}
return 'col-lg-1 col-xl-1 d-none d-lg-block text-center';
}
@ -667,6 +762,12 @@ abstract class DocumentIndex extends Component
return $classActions;
}
$class = $this->getClassFromConfig($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';
}
@ -676,20 +777,16 @@ abstract class DocumentIndex extends Component
return $routeButtonShow;
}
$page = config("type.{$type}.route_name");
//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)
@ -698,20 +795,16 @@ abstract class DocumentIndex extends Component
return $routeButtonEdit;
}
$page = config("type.{$type}.route_name");
//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)
@ -720,20 +813,16 @@ abstract class DocumentIndex extends Component
return $routeButtonDuplicate;
}
$page = config("type.{$type}.route_name");
//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)
@ -742,20 +831,16 @@ abstract class DocumentIndex extends Component
return $routeButtonCancelled;
}
$page = config("type.{$type}.route_name");
//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)
@ -764,20 +849,16 @@ abstract class DocumentIndex extends Component
return $routeButtonDelete;
}
$page = config("type.{$type}.route_name");
//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)
@ -786,18 +867,7 @@ abstract class DocumentIndex extends Component
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;
}
@ -808,18 +878,7 @@ abstract class DocumentIndex extends Component
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;
}
@ -830,18 +889,7 @@ abstract class DocumentIndex extends Component
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;
}

File diff suppressed because it is too large Load Diff

View File

@ -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;
@ -175,18 +175,12 @@ abstract class DocumentTemplate extends Component
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 Component
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;
}
@ -255,14 +242,20 @@ abstract class DocumentTemplate 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 'general.numbers';
}
protected function getTextOrderNumber($type, $textOrderNumber)
@ -271,18 +264,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 +283,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 +309,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 +331,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 +346,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 +366,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 +406,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)
@ -434,6 +421,12 @@ abstract class DocumentTemplate extends Component
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 +438,19 @@ abstract class DocumentTemplate extends Component
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 +459,19 @@ abstract class DocumentTemplate extends Component
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 +480,19 @@ abstract class DocumentTemplate extends Component
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 +501,19 @@ abstract class DocumentTemplate extends Component
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 +522,19 @@ abstract class DocumentTemplate extends Component
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 +543,18 @@ abstract class DocumentTemplate extends Component
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);
}
}

View File

@ -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') {

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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(

View File

@ -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),

View File

@ -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.';
}
}

View File

@ -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_name');
$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);

View File

@ -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;
}
}

View File

@ -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'));
}

View File

@ -3,42 +3,87 @@
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
'parameter' => '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',
],
'category_type' => 'income',
'contact_type' => 'customer', // use contact type
'hide' => [], // for document items
'class' => [],
],
Document::BILL_TYPE => [
'alias' => '',
'group' => 'purchases',
'route_name' => 'bills',
'route_parameter' => 'bill',
'permission_name' => 'purchases-bills',
'translation_key' => 'bills',
'route' => [
'prefix' => 'bills',
'parameter' => 'bill',
//'create' => 'bilss.create',
],
'permission' => [
'prefix' => 'bills',
//'create' => 'create-purchases-bills',
],
'translation' => [
'prefix' => 'bills',
'issued_at' => 'bills.bill_date',
'due_at' => 'bills.due_date',
],
'category_type' => 'expense',
'contact_type' => 'vendor',
'hide' => [],
],
// 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',
],
];

View File

@ -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 <b>DRAFT</b> bill and will be reflected to charts after it gets received.',

View File

@ -1,8 +1,42 @@
<?php
return [
'statuses' => [
'draft' => 'Draft',
'sent' => 'Sent',
'expired' => 'Expired',
'viewed' => 'Viewed',
'approved' => 'Approved',
'received' => 'Received',
'refused' => 'Refused',
'restored' => 'Restored',
'reversed' => 'Reversed',
'partial' => 'Partial',
'paid' => 'Paid',
'pending' => 'Pending',
'invoiced' => 'Invoiced',
'overdue' => 'Overdue',
'unpaid' => 'Unpaid',
'cancelled' => 'Cancelled',
'voided' => 'Voided',
'completed' => 'Completed',
'shipped' => 'Shipped',
'refunded' => 'Refunded',
'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!',

View File

@ -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 <b>DRAFT</b> invoice and will be reflected to charts after it gets sent.',

View File

@ -15,7 +15,7 @@
<div class="col-sm-6 col-md-6 col-lg-6 col-xl-6">
@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)

View File

@ -2,7 +2,7 @@
<div class="card">
<div class="card-footer">
<div class="row save-buttons">
{{ Form::saveButtons('invoices.index') }}
{{ Form::saveButtons($routeCancel) }}
</div>
</div>
</div>

View File

@ -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,
@ -78,6 +78,7 @@
<x-documents.form.advanced
type="{{ $type }}"
:document="$document"
category-type="{{ $categoryType }}"
hide-recurring="{{ $hideRecurring }}"
hide-category="{{ $hideCategory }}"
hide-attachment="{{ $hideAttachment }}"
@ -88,6 +89,7 @@
<x-documents.form.buttons
type="{{ $type }}"
:document="$document"
route-cancel="{{ $routeCancel }}"
/>
@endif

View File

@ -57,7 +57,7 @@
@if($item->bill)
@if ($item->bill->status == 'paid')
<el-tooltip content="{{ $item->bill->document_number }} / {{ trans('bills.statuses.paid') }}"
<el-tooltip content="{{ $item->bill->document_number }} / {{ trans('documents.statuses.paid') }}"
effect="success"
:open-delay="100"
placement="top">
@ -66,7 +66,7 @@
</span>
</el-tooltip>
@elseif ($item->bill->status == 'partial')
<el-tooltip content="{{ $item->bill->document_number }} / {{ trans('bills.statuses.partial') }}"
<el-tooltip content="{{ $item->bill->document_number }} / {{ trans('documents.statuses.partial') }}"
effect="info"
:open-delay="100"
placement="top">

View File

@ -194,7 +194,7 @@
<td class="col-xs-4 col-sm-3 text-right">@money($item->amount, $item->currency_code, true)</td>
<td class="col-sm-3 d-none d-sm-block text-left">@date($item->issued_at)</td>
<td class="col-sm-3 d-none d-sm-block text-left">@date($item->due_at)</td>
<td class="col-xs-4 col-sm-2"><span class="badge badge-pill badge-{{ $item->status_label }} my--2">{{ trans('bills.statuses.' . $item->status) }}</span></td>
<td class="col-xs-4 col-sm-2"><span class="badge badge-pill badge-{{ $item->status_label }} my--2">{{ trans('documents.statuses.' . $item->status) }}</span></td>
</tr>
@endforeach
</tbody>

View File

@ -194,7 +194,7 @@
<td class="col-xs-4 col-sm-3 text-right">@money($item->amount, $item->currency_code, true)</td>
<td class="col-sm-3 d-none d-sm-block text-left">@date($item->issued_at)</td>
<td class="col-sm-3 d-none d-sm-block text-left">@date($item->due_at)</td>
<td class="col-xs-4 col-sm-2"><span class="badge badge-pill badge-{{ $item->status_label }} my--2">{{ trans('invoices.statuses.' . $item->status) }}</span></td>
<td class="col-xs-4 col-sm-2"><span class="badge badge-pill badge-{{ $item->status_label }} my--2">{{ trans('documents.statuses.' . $item->status) }}</span></td>
</tr>
@endforeach
</tbody>

View File

@ -57,7 +57,7 @@
@if($item->invoice)
@if ($item->invoice->status == 'paid')
<el-tooltip content="{{ $item->invoice->document_number }} / {{ trans('invoices.statuses.paid') }}"
<el-tooltip content="{{ $item->invoice->document_number }} / {{ trans('documents.statuses.paid') }}"
effect="success"
:open-delay="100"
placement="top">
@ -66,7 +66,7 @@
</span>
</el-tooltip>
@elseif ($item->invoice->status == 'partial')
<el-tooltip content="{{ $item->invoice->document_number }} / {{ trans('invoices.statuses.partial') }}"
<el-tooltip content="{{ $item->invoice->document_number }} / {{ trans('documents.statuses.partial') }}"
effect="info"
:open-delay="100"
placement="top">