Merge Invoice and Bill into Document

This commit is contained in:
Burak Çakırel
2020-12-24 01:28:38 +03:00
parent 830cc05957
commit 0c1424db47
436 changed files with 31655 additions and 37350 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace App\Abstracts\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
abstract class DocumentForm extends Component
{
public $type;
public $documents;
public $bulkActions;
/** @var bool */
public $hideBulkAction;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
$type, $documents = [], $bulkActions = [],
bool $hideBulkAction = false
) {
$this->type = $type;
$this->documents = $documents;
$this->bulkActions = $bulkActions;
$this->hideBulkAction = $hideBulkAction;
}
}

View File

@ -0,0 +1,933 @@
<?php
namespace App\Abstracts\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
use App\Events\Common\BulkActionsAdding;
abstract class DocumentIndex extends Component
{
/** @var string */
public $type;
public $documents;
/** @var string */
public $page;
/** @var string */
public $docsPath;
/** @var bool */
public $checkCreatePermission;
/** @var string */
public $createPermission;
/** @var string */
public $createRoute;
/** @var string */
public $importRoute;
/** @var array */
public $importRouteParameters;
/** @var string */
public $exportRoute;
/** @var bool */
public $hideCreate;
/** @var bool */
public $hideImport;
/** @var bool */
public $hideExport;
/* -- Card Header Start -- */
/** @var string */
public $textBulkAction;
/** @var string */
public $bulkActionClass;
/** @var array */
public $bulkActions;
/** @var array */
public $bulkActionRouteParameters;
/** @var string */
public $formCardHeaderRoute;
/** @var bool */
public $hideBulkAction;
/** @var string */
public $classBulkAction;
/** @var string */
public $searchStringModel;
/** @var bool */
public $hideSearchString;
/* -- Card Header End -- */
/* -- Card Body Start -- */
/** @var string */
public $textDocumentNumber;
/** @var string */
public $textContactName;
/** @var string */
public $textIssueAt;
/** @var string */
public $textDueAt;
/** @var string */
public $textDocumentStatus;
/** @var bool */
public $checkButtonReconciled;
/** @var bool */
public $checkButtonCancelled;
/** @var bool */
public $hideDocumentNumber;
/** @var string */
public $classDocumentNumber;
/** @var bool */
public $hideContactName;
/** @var string */
public $classContactName;
/** @var bool */
public $hideAmount;
/** @var string */
public $classAmount;
/** @var bool */
public $hideIssuedAt;
/** @var string */
public $classIssuedAt;
/** @var bool */
public $hideDueAt;
/** @var string */
public $classDueAt;
/** @var bool */
public $hideStatus;
/** @var string */
public $classStatus;
/** @var bool */
public $hideActions;
/** @var string */
public $routeButtonShow;
/** @var string */
public $routeButtonEdit;
/** @var string */
public $routeButtonDuplicate;
/** @var string */
public $routeButtonCancelled;
/** @var string */
public $routeButtonDelete;
/** @var bool */
public $hideButtonShow;
/** @var bool */
public $hideButtonEdit;
/** @var bool */
public $hideButtonDuplicate;
/** @var bool */
public $hideButtonCancel;
/** @var bool */
public $hideButtonDelete;
/** @var string */
public $permissionDocumentCreate;
/** @var string */
public $permissionDocumentUpdate;
/** @var string */
public $permissionDocumentDelete;
/* -- Card Body End -- */
public $limits;
public $hideEmptyPage;
public $classActions;
public $class_count;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
string $type, $documents = [], string $page = '', string $docsPath = '', $limits = [], $hideEmptyPage = false,
bool $checkCreatePermission = true, string $createPermission = '', string $createRoute = '', string $importRoute = '', array $importRouteParameters = [], string $exportRoute = '',
bool $hideCreate = false, bool $hideImport = false, bool $hideExport = false, // Advanced
string $textBulkAction = '', array $bulkActions = [], string $bulkActionClass = '', array $bulkActionRouteParameters = [], string $formCardHeaderRoute = '', string $searchStringModel = '',
bool $hideBulkAction = false, bool $hideSearchString = false,
string $classActions = '', string $classBulkAction = '', string $classDocumentNumber = '', string $classContactName = '', string $classIssuedAt = '', string $classDueAt = '', string $classStatus = '',
string $textDocumentNumber = '', string $textContactName = '', string $classAmount = '', string $textIssueAt = '', string $textDueAt = '', string $textDocumentStatus = '',
bool $checkButtonReconciled = true, bool $checkButtonCancelled = true,
string $routeButtonShow = '', string $routeButtonEdit = '', string $routeButtonDuplicate = '', string $routeButtonCancelled = '', string $routeButtonDelete = '',
bool $hideDocumentNumber = false, bool $hideContactName = false, bool $hideAmount = false, bool $hideIssuedAt = false, bool $hideDueAt = false, bool $hideStatus = false, bool $hideActions = false,
bool $hideButtonShow = false, bool $hideButtonEdit = false, bool $hideButtonDuplicate = false, bool $hideButtonCancel = false, bool $hideButtonDelete = false,
string $permissionDocumentCreate = '', string $permissionDocumentUpdate = '', string $permissionDocumentDelete = ''
) {
$this->type = $type;
$this->documents = $documents;
$this->page = $this->getPage($type, $page);
$this->docsPath = $this->getDocsPath($type, $docsPath);
$this->hideEmptyPage = $hideEmptyPage;
/* -- Top Buttons Start -- */
$this->checkCreatePermission = $checkCreatePermission;
$this->createPermission = $this->getCreatePermission($type, $createPermission);
$this->createRoute = $this->getCreateRoute($type, $createRoute);
$this->importRoute = $this->getImportRoute($importRoute);
$this->importRouteParameters = $this->getImportRouteParameters($type, $importRouteParameters);
$this->exportRoute = $this->getExportRoute($type, $exportRoute);
$this->hideCreate = $hideCreate;
$this->hideImport = $hideImport;
$this->hideExport = $hideExport;
/* -- Top Buttons End -- */
/* -- Card Header Start -- */
$this->textBulkAction = $this->getTextBulkAction($type, $textBulkAction);
$this->bulkActionClass = $bulkActionClass;
$this->bulkActions = $this->getBulkActions($type, $bulkActions, $bulkActionClass);
$this->bulkActionRouteParameters = $this->getBulkActionRouteParameters($type, $bulkActionRouteParameters);
$this->formCardHeaderRoute = $this->getRoute($type, $formCardHeaderRoute);
$this->searchStringModel = $this->getSearchStringModel($type, $searchStringModel);
$this->hideBulkAction = $hideBulkAction;
$this->hideSearchString = $hideSearchString;
/* -- Card Header End -- */
/* -- Card Body Start -- */
$this->textDocumentNumber = $this->getTextDocumentNumber($textDocumentNumber);
$this->textContactName = $this->getTextContactName($type, $textContactName);
$this->textIssueAt = $this->getTextIssueAt($type, $textIssueAt);
$this->textDueAt = $this->getTextDueAt($type, $textDueAt);
$this->textDocumentStatus = $this->getTextDocumentStatus($type, $textDocumentStatus);
$this->checkButtonReconciled = $checkButtonReconciled;
$this->checkButtonCancelled = $checkButtonCancelled;
$this->routeButtonShow = $this->getRouteButtonShow($type, $routeButtonShow);
$this->routeButtonEdit = $this->getRouteButtonEdit($type, $routeButtonEdit);
$this->routeButtonDuplicate = $this->getRouteButtonDuplicate($type, $routeButtonDuplicate);
$this->routeButtonCancelled = $this->getRouteButtonCancelled($type, $routeButtonCancelled);
$this->routeButtonDelete = $this->getRouteButtonDelete($type, $routeButtonDelete);
$this->hideBulkAction = $hideBulkAction;
$this->hideDocumentNumber = $hideDocumentNumber;
$this->hideContactName = $hideContactName;
$this->hideAmount = $hideAmount;
$this->hideIssuedAt = $hideIssuedAt;
$this->hideDueAt = $hideDueAt;
$this->hideStatus = $hideStatus;
$this->hideActions = $hideActions;
$this->class_count = 12;
$this->calculateClass();
$this->classBulkAction = $this->getClassBulkAction($type, $classBulkAction);
$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->classDueAt = $this->getClassDueAt($type, $classDueAt);
$this->classStatus = $this->getClassStatus($type, $classStatus);
$this->classActions = $this->getClassActions($type, $classActions);
$this->hideButtonShow = $hideButtonShow;
$this->hideButtonEdit = $hideButtonEdit;
$this->hideButtonDuplicate = $hideButtonDuplicate;
$this->hideButtonCancel = $hideButtonCancel;
$this->hideButtonDelete = $hideButtonDelete;
$this->permissionDocumentCreate = $this->getPermissionDocumentCreate($type, $permissionDocumentCreate);
$this->permissionDocumentUpdate = $this->getPermissionDocumentUpdate($type, $permissionDocumentUpdate);
$this->permissionDocumentDelete = $this->getPermissionDocumentDelete($type, $permissionDocumentDelete);
/* -- Card Body End -- */
$this->limits = ($limits) ? $limits : ['10' => '10', '25' => '25', '50' => '50', '100' => '100'];
}
protected function getPage($type, $page)
{
if (!empty($page)) {
return $page;
}
return Str::plural($type, 2);
}
protected function getDocsPath($type, $docsPath)
{
if (!empty($docsPath)) {
return $docsPath;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$docsPath = 'sales/invoices';
break;
case 'bill':
case 'expense':
case 'purchase':
$docsPath = 'purchases/bills';
break;
}
return $docsPath;
}
protected function getCreatePermission($type, $createPermission)
{
if (!empty($createPermission)) {
return $createPermission;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$createPermission = 'create-sales-invoices';
break;
case 'bill':
case 'expense':
case 'purchase':
$createPermission = 'create-purchases-bills';
break;
}
return $createPermission;
}
protected function getCreateRoute($type, $createRoute)
{
if (!empty($createRoute)) {
return $createRoute;
}
$page = Str::plural($type, 2);
$route = $page . '.create';
try {
route($route);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getImportRoute($importRoute)
{
if (!empty($importRoute)) {
return $importRoute;
}
$route = 'import.create';
return $route;
}
protected function getImportRouteParameters($type, $importRouteParameters)
{
if (!empty($importRouteParameters)) {
return $importRouteParameters;
}
$importRouteParameters = [
'group' => ($type == 'invoice') ? 'sales' : 'purchases',
'type' => Str::plural($type, 2)
];
return $importRouteParameters;
}
protected function getExportRoute($type, $exportRoute)
{
if (!empty($exportRoute)) {
return $exportRoute;
}
$page = Str::plural($type, 2);
$route = $page . '.export';
try {
route($route);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getRoute($type, $formCardHeaderRoute)
{
if (!empty($formCardHeaderRoute)) {
return $formCardHeaderRoute;
}
$page = Str::plural($type, 2);
$route = $page . '.index';
try {
route($route);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getSearchStringModel($type, $searchStringModel)
{
if (!empty($searchStringModel)) {
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;
}
return $searchStringModel;
}
protected function getTextBulkAction($type, $textBulkAction)
{
if (!empty($textBulkAction)) {
return $textBulkAction;
}
$textBulkAction = 'general.' . Str::plural($type, 2);
return $textBulkAction;
}
protected function getBulkActions($type, $bulkActions, $bulkActionClass)
{
if (!empty($bulkActions)) {
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;
}
if (class_exists($bulkActionClass)) {
event(new BulkActionsAdding(app($bulkActionClass)));
$bulkActions = app($bulkActionClass)->actions;
} else {
$b = new \stdClass();
$b->actions = [];
event(new BulkActionsAdding($b));
$bulkActions = $b->actions;
}
return $bulkActions;
}
protected function getBulkActionRouteParameters($type, $bulkActionRouteParameters)
{
if (!empty($bulkActionRouteParameters)) {
return $bulkActionRouteParameters;
}
$bulkActionRouteParameters = [
'group' => ($type == 'invoice') ? 'sales' : 'purchases',
'type' => Str::plural($type, 2)
];
return $bulkActionRouteParameters;
}
protected function getClassBulkAction($type, $classBulkAction)
{
if (!empty($classBulkAction)) {
return $classBulkAction;
}
return 'col-sm-2 col-md-1 col-lg-1 col-xl-1 d-none d-sm-block';
}
protected function getTextDocumentNumber($textDocumentNumber)
{
if (!empty($textDocumentNumber)) {
return $textDocumentNumber;
}
return trans_choice('general.numbers', 1);
}
protected function getClassDocumentNumber($type, $classDocumentNumber)
{
if (!empty($classDocumentNumber)) {
return $classDocumentNumber;
}
if ($classDocumentNumber = $this->getClass('classDocumentNumber')) {
return $classDocumentNumber;
}
return 'col-md-2 col-lg-1 col-xl-1 d-none d-md-block';
}
protected function getTextContactName($type, $textContactName)
{
if (!empty($textContactName)) {
return $textContactName;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textContactName = trans_choice('general.customers', 1);
break;
case 'bill':
case 'expense':
case 'purchase':
$textContactName = trans_choice('general.vendors', 1);
break;
}
return $textContactName;
}
protected function getClassContactName($type, $classContactName)
{
if (!empty($classContactName)) {
return $classContactName;
}
if ($classContactName = $this->getClass('classContactName')) {
return $classContactName;
}
return 'col-xs-4 col-sm-4 col-md-4 col-lg-2 col-xl-2 text-left';
}
protected function getClassAmount($type, $classAmount)
{
if (!empty($classAmount)) {
return $classAmount;
}
if ($classAmount = $this->getClass('classAmount')) {
return $classAmount;
}
return 'col-xs-4 col-sm-4 col-md-3 col-lg-2 col-xl-2 text-right';
}
protected function getTextIssueAt($type, $textIssueAt)
{
if (!empty($textIssueAt)) {
return $textIssueAt;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textIssueAt = trans('invoices.invoice_date');
break;
case 'bill':
case 'expense':
case 'purchase':
$textIssueAt = trans('bills.bill_date');
break;
}
return $textIssueAt;
}
protected function getclassIssuedAt($type, $classIssuedAt)
{
if (!empty($classIssuedAt)) {
return $classIssuedAt;
}
if ($classIssuedAt = $this->getClass('classIssuedAt')) {
return $classIssuedAt;
}
return 'col-lg-2 col-xl-2 d-none d-lg-block text-left';
}
protected function getTextDueAt($type, $textDueAt)
{
if (!empty($textDueAt)) {
return $textDueAt;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textDueAt = trans('invoices.due_date');
break;
case 'bill':
case 'expense':
case 'purchase':
$textDueAt = trans('bills.due_date');
break;
}
return $textDueAt;
}
protected function getClassDueAt($type, $classDueAt)
{
if (!empty($classDueAt)) {
return $classDueAt;
}
if ($classDueAt = $this->getClass('classDueAt')) {
return $classDueAt;
}
return 'col-lg-2 col-xl-2 d-none d-lg-block text-left';
}
protected function getTextDocumentStatus($type, $textDocumentStatus)
{
if (!empty($textDocumentStatus)) {
return $textDocumentStatus;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textDocumentStatus = 'invoices.statuses.';
break;
case 'bill':
case 'expense':
case 'purchase':
$textDocumentStatus = 'bills.statuses.';
break;
}
return $textDocumentStatus;
}
protected function getClassStatus($type, $classStatus)
{
if (!empty($classStatus)) {
return $classStatus;
}
if ($classStatus = $this->getClass('classStatus')) {
return $classStatus;
}
return 'col-lg-1 col-xl-1 d-none d-lg-block text-center';
}
protected function getClassActions($type, $classActions)
{
if (!empty($classActions)) {
return $classActions;
}
if ($classActions = $this->getClass('classActions')) {
return $classActions;
}
return 'col-xs-4 col-sm-2 col-md-2 col-lg-1 col-xl-1 text-center';
}
protected function getRouteButtonShow($type, $routeButtonShow)
{
if (!empty($routeButtonShow)) {
return $routeButtonShow;
}
$page = Str::plural($type, 2);
$route = $page . '.show';
try {
//example route parameter.
$parameter = 1;
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getRouteButtonEdit($type, $routeButtonEdit)
{
if (!empty($routeButtonEdit)) {
return $routeButtonEdit;
}
$page = Str::plural($type, 2);
$route = $page . '.edit';
try {
//example route parameter.
$parameter = 1;
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
{
if (!empty($routeButtonDuplicate)) {
return $routeButtonDuplicate;
}
$page = Str::plural($type, 2);
$route = $page . '.duplicate';
try {
//example route parameter.
$parameter = 1;
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getRouteButtonCancelled($type, $routeButtonCancelled)
{
if (!empty($routeButtonCancelled)) {
return $routeButtonCancelled;
}
$page = Str::plural($type, 2);
$route = $page . '.cancelled';
try {
//example route parameter.
$parameter = 1;
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getRouteButtonDelete($type, $routeButtonDelete)
{
if (!empty($routeButtonDelete)) {
return $routeButtonDelete;
}
$page = Str::plural($type, 2);
$route = $page . '.destroy';
try {
//example route parameter.
$parameter = 1;
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
return $route;
}
protected function getPermissionDocumentCreate($type, $permissionDocumentCreate)
{
if (!empty($permissionDocumentCreate)) {
return $permissionDocumentCreate;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$permissionDocumentCreate = 'create-sales-invoices';
break;
case 'bill':
case 'expense':
case 'purchase':
$permissionDocumentCreate = 'create-purchases-bills';
break;
}
return $permissionDocumentCreate;
}
protected function getPermissionDocumentUpdate($type, $permissionDocumentUpdate)
{
if (!empty($permissionDocumentUpdate)) {
return $permissionDocumentUpdate;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$permissionDocumentUpdate = 'update-sales-invoices';
break;
case 'bill':
case 'expense':
case 'purchase':
$permissionDocumentUpdate = 'update-purchases-bills';
break;
}
return $permissionDocumentUpdate;
}
protected function getPermissionDocumentDelete($type, $permissionDocumentDelete)
{
if (!empty($permissionDocumentDelete)) {
return $permissionDocumentDelete;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$permissionDocumentDelete = 'delete-sales-invoices';
break;
case 'bill':
case 'expense':
case 'purchase':
$permissionDocumentDelete = 'delete-purchases-bills';
break;
}
return $permissionDocumentDelete;
}
protected function calculateClass()
{
$hides = [
'BulkAction' => '1',
'DocumentNumber' => '1',
'ContactName' => '2',
'Amount' => '2',
'IssuedAt' => '2',
'DueAt' => '2',
'Status' => '1',
'Actions' => '1',
];
foreach ($hides as $hide => $count) {
if ($this->{'hide'. $hide}) {
$this->class_count -= $count;
}
}
}
protected function getClass($type)
{
$hide_count = 12 - $this->class_count;
if (empty($hide_count)) {
//return false;
}
$class = false;
switch($type) {
case 'classDocumentNumber':
switch ($hide_count) {
case 1:
$class = 'col-md-3 col-lg-2 col-xl-2 d-none d-md-block';
$this->class_count++;
break;
case 2:
$class = 'col-md-4 col-lg-2 col-xl-2 d-none d-md-block';
$this->class_count += 2;
break;
case 3:
$class = 'col-md-5 col-lg-2 col-xl-2 d-none d-md-block';
$this->class_count += 3;
break;
}
}
return $class;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,597 @@
<?php
namespace App\Abstracts\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
use App\Traits\DateTime;
use App\Models\Common\Media;
use File;
use Image;
use Storage;
abstract class DocumentTemplate extends Component
{
use DateTime;
public $type;
public $document;
/** @var string */
public $documentTemplate;
public $date_format;
public $logo;
public $backGroundColor;
public $hideFooter;
public $hideCompanyLogo;
public $hideCompanyDetails;
public $hideCompanyName;
public $hideCompanyAddress;
public $hideCompanyTaxNumber;
public $hideCompanyPhone;
public $hideCompanyEmail;
public $hideContactInfo;
public $hideContactName;
public $hideContactAddress;
public $hideContactTaxNumber;
public $hideContactPhone;
public $hideContactEmail;
public $hideOrderNumber;
public $hideDocumentNumber;
public $hideIssuedAt;
public $hideDueAt;
public $textContactInfo;
/** @var string */
public $textIssuedAt;
/** @var string */
public $textDueAt;
/** @var string */
public $textDocumentNumber;
/** @var string */
public $textOrderNumber;
public $hideItems;
public $hideName;
public $hideDescription;
public $hideQuantity;
public $hidePrice;
public $hideDiscount;
public $hideAmount;
/** @var string */
public $textItems;
/** @var string */
public $textQuantity;
/** @var string */
public $textPrice;
/** @var string */
public $textAmount;
public $hideNote;
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
$type, $document, $documentTemplate = '', $logo = '', $backgroundColor = '',
bool $hideFooter = false, bool $hideCompanyLogo = false, bool $hideCompanyDetails = false,
bool $hideCompanyName = false, bool $hideCompanyAddress = false, bool $hideCompanyTaxNumber = false, bool $hideCompanyPhone = false, bool $hideCompanyEmail = false, bool $hideContactInfo = false,
bool $hideContactName = false, bool $hideContactAddress = false, bool $hideContactTaxNumber = false, bool $hideContactPhone = false, bool $hideContactEmail = false,
bool $hideOrderNumber = false, bool $hideDocumentNumber = false, bool $hideIssuedAt = false, bool $hideDueAt = false,
string $textContactInfo = '', string $textDocumentNumber = '', string $textOrderNumber = '', string $textIssuedAt = '', string $textDueAt = '',
bool $hideItems = false, bool $hideName = false, bool $hideDescription = false, bool $hideQuantity = false, bool $hidePrice = false, bool $hideDiscount = false, bool $hideAmount = false, bool $hideNote = false,
string $textItems = '', string $textQuantity = '', string $textPrice = '', string $textAmount = ''
) {
$this->type = $type;
$this->document = $document;
$this->documentTemplate = $this->getDocumentTemplate($type, $documentTemplate);
$this->logo = $this->getLogo($logo);
$this->backGroundColor = $this->getBackgroundColor($type, $backgroundColor);
$this->hideFooter = $hideFooter;
$this->hideCompanyLogo = $hideCompanyLogo;
$this->hideCompanyDetails = $hideCompanyDetails;
$this->hideCompanyName = $hideCompanyName;
$this->hideCompanyAddress = $hideCompanyAddress;
$this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
$this->hideCompanyPhone = $hideCompanyPhone;
$this->hideCompanyEmail = $hideCompanyEmail;
$this->hideContactInfo = $hideContactInfo;
$this->hideContactName = $hideContactName;
$this->hideContactAddress = $hideContactAddress;
$this->hideContactTaxNumber = $hideContactTaxNumber;
$this->hideContactPhone = $hideContactPhone;
$this->hideContactEmail = $hideContactEmail;
$this->hideOrderNumber = $hideOrderNumber;
$this->hideDocumentNumber = $hideDocumentNumber;
$this->hideIssuedAt = $hideIssuedAt;
$this->hideDueAt = $hideDueAt;
$this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
$this->textIssuedAt = $this->gettextIssuedAt($type, $textIssuedAt);
$this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber);
$this->textDueAt = $this->getTextDueAt($type, $textDueAt);
$this->textOrderNumber = $this->getTextOrderNumber($type, $textOrderNumber);
$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->hideNote = $hideNote;
$this->textItems = $this->getTextItems($type, $textItems);
$this->textQuantity = $this->getTextQuantity($type, $textQuantity);
$this->textPrice = $this->getTextPrice($type, $textPrice);
$this->textAmount = $this->getTextAmount($type, $textAmount);
}
protected function getDocumentTemplate($type, $documentTemplate)
{
if (!empty($documentTemplate)) {
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;
}
return $documentTemplate;
}
protected function getLogo($logo)
{
if (!empty($logo)) {
return $logo;
}
$media = Media::find(setting('company.logo'));
if (!empty($media)) {
$path = Storage::path($media->getDiskPath());
if (!is_file($path)) {
return $logo;
}
} else {
$path = base_path('public/img/company.png');
}
$image = Image::cache(function($image) use ($path) {
$width = $height = setting('invoice.logo_size', 128);
$image->make($path)->resize($width, $height)->encode();
});
if (empty($image)) {
return $logo;
}
$extension = File::extension($path);
return 'data:image/' . $extension . ';base64,' . base64_encode($image);
}
protected function getBackgroundColor($type, $backgroundColor)
{
if (!empty($backgroundColor)) {
return $backgroundColor;
}
$backgroundColor = '#55588b';
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$backgroundColor = setting('invoice.color');
break;
case 'bill':
case 'expense':
case 'purchase':
$backgroundColor = setting('bill.color');
break;
}
return $backgroundColor;
}
protected function getTextDocumentNumber($type, $textDocumentNumber)
{
if (!empty($textDocumentNumber)) {
return $textDocumentNumber;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textDocumentNumber = trans('invoices.invoice_number');
break;
case 'bill':
case 'expense':
case 'purchase':
$textDocumentNumber = trans('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 = trans('invoices.order_number');
break;
case 'bill':
case 'expense':
case 'purchase':
$textOrderNumber = trans('bills.order_number');
break;
}
return $textOrderNumber;
}
protected function getTextContactInfo($type, $textContactInfo)
{
if (!empty($textContactInfo)) {
return $textContactInfo;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textContactInfo = trans('invoices.bill_to');
break;
case 'bill':
case 'expense':
case 'purchase':
$textContactInfo = trans('bills.bill_from');
break;
}
return $textContactInfo;
}
protected function gettextIssuedAt($type, $textIssuedAt)
{
if (!empty($textIssuedAt)) {
return $textIssuedAt;
}
switch ($type) {
case 'sale':
case 'income':
case 'invoice':
$textIssuedAt = trans('invoices.invoice_date');
break;
case 'bill':
case 'expense':
case 'purchase':
$textIssuedAt = trans('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 = trans('invoices.due_date');
break;
case 'bill':
case 'expense':
case 'purchase':
$textDueAt = trans('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 = trans_choice(setting('invoice.item_name', 'general.items'), 2);
if ($text_items == 'custom') {
$text_items = setting('invoice.item_name_input');
}
break;
case 'bill':
case 'expense':
case 'purchase':
$text_items = trans_choice('general.items', 2);
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 = trans(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 = trans('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 = trans(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 = trans('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 = trans('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;
}
}