diff --git a/.env.example b/.env.example
index ab3781400..17d0b2d37 100644
--- a/.env.example
+++ b/.env.example
@@ -19,7 +19,10 @@ BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_CONNECTION=sync
+
LOG_CHANNEL=stack
+LOG_DEPRECATIONS_CHANNEL=null
+LOG_LEVEL=debug
MAIL_MAILER=mail
MAIL_HOST=localhost
@@ -33,3 +36,6 @@ MAIL_FROM_ADDRESS=null
FIREWALL_ENABLED=false
MODEL_CACHE_ENABLED=false
+
+DEBUGBAR_EDITOR=vscode
+IGNITION_EDITOR=vscode
diff --git a/.git-ftp-ignore b/.git-ftp-ignore
new file mode 100644
index 000000000..907ef8b94
--- /dev/null
+++ b/.git-ftp-ignore
@@ -0,0 +1,14 @@
+.gitignore
+.gitattributes
+.git-ftp-ignore
+.git-ftp-include
+.git-ftp-log
+.gitlab-ci.yml
+.ftpquota
+.git/*
+.github/*
+.public/js/*
+.vendor/*
+.node_modules/*
+
+composer.lock
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 9e9e29341..3168d5f1e 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -1,7 +1,7 @@
name: Tests
on:
- push:
+ push:
pull_request:
schedule:
- cron: '0 0 * * *'
@@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
- php: ['7.3', '7.4']
+ php: ['8.0', '8.1']
steps:
- name: Checkout code
diff --git a/.gitignore b/.gitignore
index 57a2d9411..224f38185 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,7 +85,6 @@ Homestead.json
Homestead.yaml
npm-debug.log
.env
-.env.example
robots.txt
_ide_helper.php
_ide_helper_models.php
@@ -95,3 +94,4 @@ _ide_helper_models.php
modules/*
!modules/.gitkeep
.laravelstatsrc
+.DS_Store
diff --git a/README.md b/README.md
index 85c2f67b3..82b389b97 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
[](https://github.com/akaunting/akaunting/actions)
[](LICENSE.txt)
-Akaunting is a free, open source and online accounting software designed for small businesses and freelancers. It is built with modern technologies such as Laravel, VueJS, Bootstrap 4, RESTful API etc. Thanks to its modular structure, Akaunting provides an awesome App Store for users and developers.
+Akaunting is a free, open source and online accounting software designed for small businesses and freelancers. It is built with modern technologies such as Laravel, VueJS, Tailwind, RESTful API etc. Thanks to its modular structure, Akaunting provides an awesome App Store for users and developers.
* [Home](https://akaunting.com) - The house of Akaunting
* [Forum](https://akaunting.com/forum) - Ask for support
@@ -17,7 +17,7 @@ Akaunting is a free, open source and online accounting software designed for sma
## Requirements
-* PHP 7.3 or higher
+* PHP 8.0 or higher
* Database (eg: MySQL, PostgreSQL, SQLite)
* Web Server (eg: Apache, Nginx, IIS)
* [Other libraries](https://akaunting.com/docs/requirements)
@@ -65,16 +65,6 @@ Please review [our security policy](https://github.com/akaunting/akaunting/secur
* [Cüneyt Şentürk](https://github.com/cuneytsenturk)
* [All Contributors](../../contributors)
-## Partners
-
-Each of our partners can help you craft a beautiful, well-architected project. Feel free to get in [contact](https://akaunting.com/contact) with us to become a partner.
-
-* [Creative Tim](https://www.creative-tim.com) is our design partner since Akaunting 2.0 version. They create beautiful UI Kits, Templates, and Dashboards built on top of Bootstrap, Vue.js, React, Angular, Node.js, and Laravel.
-
-## Sponsors
-
-Support Akaunting by becoming a sponsor on [Patreon](https://www.patreon.com/akaunting). Your logo will show up here with a link to your website.
-
## License
Akaunting is released under the [GPLv3 license](LICENSE.txt).
diff --git a/app/Abstracts/BulkAction.php b/app/Abstracts/BulkAction.php
index 4aeb91894..3f49455c4 100644
--- a/app/Abstracts/BulkAction.php
+++ b/app/Abstracts/BulkAction.php
@@ -18,28 +18,54 @@ abstract class BulkAction
public $model = false;
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-common-items',
+ 'enable' => [
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-common-items',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-common-items',
+ 'disable' => [
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-common-items',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-common-items',
+ 'delete' => [
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-common-items',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download'
+ 'export' => [
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download'
],
];
+ public $icons = [
+ 'enable' => 'check_circle',
+ 'disable' => 'hide_source',
+ 'delete' => 'delete',
+ 'export' => 'file_download',
+ 'reconcile' => 'published_with_changes',
+ 'unreconcile' => 'layers_clear',
+ 'received' => 'call_received',
+ 'cancelled' => 'cancel',
+ 'sent' => 'send',
+ 'approved' => 'approval',
+ 'refused' => 'do_not_disturb_on',
+ 'issued' => 'mark_email_read',
+ 'confirmed' => 'thumb_up_alt',
+ ];
+
+ public $messages = [
+ 'general' => 'bulk_actions.success.general',
+ 'enable' => 'messages.success.enabled',
+ 'disable' => 'messages.success.disabled',
+ 'delete' => 'messages.success.deleted',
+ 'duplicate' => 'messages.success.duplicated',
+ 'invite' => 'messages.success.invited',
+ 'end' => 'messages.success.ended',
+ ];
+
public function getSelectedRecords($request, $relationships = null)
{
if (empty($relationships)) {
diff --git a/app/Abstracts/Factory.php b/app/Abstracts/Factory.php
index c01afcf90..179226337 100644
--- a/app/Abstracts/Factory.php
+++ b/app/Abstracts/Factory.php
@@ -5,6 +5,7 @@ namespace App\Abstracts;
use App\Models\Auth\User;
use App\Models\Common\Company;
use App\Traits\Jobs;
+use Closure;
use Illuminate\Database\Eloquent\Factories\Factory as BaseFactory;
use Illuminate\Database\Eloquent\Model as EloquentModel;
@@ -28,16 +29,46 @@ abstract class Factory extends BaseFactory
config(['mail.default' => 'array']);
- $this->user = User::first();
- $this->company = $this->user->companies()->first();
+ // TODO: this location was put to make US | for "gmail.co.uk" issue
+ $this->faker = \Faker\Factory::create();
- company($this->company->id)->makeCurrent();
+ $this->setUser();
+
+ $this->setCompany();
+ }
+
+ public function getCompanyUsers(): array
+ {
+ return $this->company->users()->enabled()->get()->pluck('id')->toArray();
+ }
+
+ public function company(int $id): static
+ {
+ return $this->state([
+ 'company_id' => $id,
+ ]);
+ }
+
+ public function setUser(): void
+ {
+ $this->user = User::first();
+ }
+
+ public function setCompany(): void
+ {
+ $company_id = $this->getRawAttribute('company_id');
+
+ $this->company = !empty($company_id) ? Company::find($company_id) : $this->user->companies()->first();
+
+ $this->company->makeCurrent();
app('url')->defaults(['company_id' => company_id()]);
}
- public function getCompanyUsers()
+ public function getRawAttribute($key)
{
- return $this->company->users()->enabled()->get()->pluck('id')->toArray();
+ $raw = $this->state([])->getExpandedAttributes(null);
+
+ return $raw[$key] ?? null;
}
}
diff --git a/app/Abstracts/Http/ApiController.php b/app/Abstracts/Http/ApiController.php
index e84ad0cef..075f2573c 100644
--- a/app/Abstracts/Http/ApiController.php
+++ b/app/Abstracts/Http/ApiController.php
@@ -5,16 +5,18 @@ namespace App\Abstracts\Http;
use App\Traits\Jobs;
use App\Traits\Permissions;
use App\Traits\Relationships;
-use Dingo\Api\Exception\ResourceException;
-use Dingo\Api\Routing\Helpers;
+use App\Exceptions\Http\Resource as ResourceException;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
+use Illuminate\Http\Response;
use Illuminate\Routing\Controller as BaseController;
+use Symfony\Component\HttpKernel\Exception\HttpException;
abstract class ApiController extends BaseController
{
- use AuthorizesRequests, Jobs, Helpers, Permissions, Relationships, ValidatesRequests;
+ use AuthorizesRequests, Jobs, Permissions, Relationships, ValidatesRequests;
/**
* Instantiate a new controller instance.
@@ -39,4 +41,146 @@ abstract class ApiController extends BaseController
return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
}
+
+ /**
+ * Respond with a location and a created resource.
+ *
+ * @param string $location
+ * @param object $resource
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function created($location, $resource): JsonResponse
+ {
+ return $resource
+ ->response()
+ ->setStatusCode(201)
+ ->header('Location', $location);
+ }
+
+ /**
+ * Respond with a location and an accepted resource.
+ *
+ * @param string $location
+ * @param object $resource
+ *
+ * @return \Illuminate\Http\JsonResponse
+ */
+ public function accepted($location, $resource): JsonResponse
+ {
+ return $resource
+ ->response()
+ ->setStatusCode(202)
+ ->header('Location', $location);
+ }
+
+ /**
+ * Respond with empty content.
+ *
+ * @return \Illuminate\Http\Response
+ */
+ public function noContent(): Response
+ {
+ return (new Response)
+ ->setStatusCode(204);
+ }
+
+ /**
+ * Return an error response.
+ *
+ * @param string $message
+ * @param int $statusCode
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function error($message, $statusCode)
+ {
+ throw new HttpException($statusCode, $message);
+ }
+
+ /**
+ * Return a 404 not found error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorNotFound($message = 'Not Found')
+ {
+ $this->error($message, 404);
+ }
+
+ /**
+ * Return a 400 bad request error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorBadRequest($message = 'Bad Request')
+ {
+ $this->error($message, 400);
+ }
+
+ /**
+ * Return a 403 forbidden error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorForbidden($message = 'Forbidden')
+ {
+ $this->error($message, 403);
+ }
+
+ /**
+ * Return a 500 internal server error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorInternal($message = 'Internal Error')
+ {
+ $this->error($message, 500);
+ }
+
+ /**
+ * Return a 401 unauthorized error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorUnauthorized($message = 'Unauthorized')
+ {
+ $this->error($message, 401);
+ }
+
+ /**
+ * Return a 405 method not allowed error.
+ *
+ * @param string $message
+ *
+ * @throws \Symfony\Component\HttpKernel\Exception\HttpException
+ *
+ * @return void
+ */
+ public function errorMethodNotAllowed($message = 'Method Not Allowed')
+ {
+ $this->error($message, 405);
+ }
}
diff --git a/app/Abstracts/Http/FormRequest.php b/app/Abstracts/Http/FormRequest.php
index 1cd0b505b..1d5b6ac43 100644
--- a/app/Abstracts/Http/FormRequest.php
+++ b/app/Abstracts/Http/FormRequest.php
@@ -25,7 +25,7 @@ abstract class FormRequest extends BaseFormRequest
* @param string $offset
* @return bool
*/
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
return Arr::has(
$this->route() ? $this->all() + $this->route()->parameters() : $this->all(),
diff --git a/app/Abstracts/Http/PaymentController.php b/app/Abstracts/Http/PaymentController.php
index 157429b49..d903dbfa3 100644
--- a/app/Abstracts/Http/PaymentController.php
+++ b/app/Abstracts/Http/PaymentController.php
@@ -41,16 +41,18 @@ abstract class PaymentController extends BaseController
});
}
- public function show(Document $invoice, PaymentRequest $request)
+ public function show(Document $invoice, PaymentRequest $request, $cards = [])
{
$this->setContactFirstLastName($invoice);
$confirm_url = $this->getConfirmUrl($invoice);
- $html = view('partials.portal.payment_method.' . $this->type, [
+ $html = view('components.payment_method.' . $this->type, [
'setting' => $this->setting,
'invoice' => $invoice,
'confirm_url' => $confirm_url,
+ 'store_card' => !empty($this->setting['store_card']) ? true : false,
+ 'cards' => $cards,
])->render();
return response()->json([
@@ -101,15 +103,15 @@ abstract class PaymentController extends BaseController
flash($message)->success();
- $invoice_url = $this->getInvoiceUrl($invoice);
+ $finish_url = $this->getFinishUrl($invoice);
if ($force_redirect || ($this->type == 'redirect')) {
- return redirect($invoice_url);
+ return redirect($finish_url);
}
return response()->json([
'error' => $message,
- 'redirect' => $invoice_url,
+ 'redirect' => $finish_url,
'success' => true,
'data' => false,
]);
@@ -122,6 +124,13 @@ abstract class PaymentController extends BaseController
: URL::signedRoute('signed.invoices.show', [$invoice->id]);
}
+ public function getFinishUrl($invoice)
+ {
+ return request()->isPortal($invoice->company_id)
+ ? route('portal.invoices.finish', $invoice->id)
+ : URL::signedRoute('signed.invoices.finish', [$invoice->id]);
+ }
+
public function getConfirmUrl($invoice)
{
return $this->getModuleUrl($invoice, 'confirm');
diff --git a/app/Abstracts/Http/SettingController.php b/app/Abstracts/Http/SettingController.php
new file mode 100644
index 000000000..cc0dfbc74
--- /dev/null
+++ b/app/Abstracts/Http/SettingController.php
@@ -0,0 +1,161 @@
+all();
+ $prefix = $request->get('_prefix', 'general');
+ $company_id = $request->get('company_id');
+
+ if (empty($company_id)) {
+ $company_id = company_id();
+ }
+
+ $company = Company::find($company_id);
+
+ $total_companies = Company::count();
+
+ foreach ($fields as $key => $value) {
+ $real_key = $prefix . '.' . $key;
+
+ // Don't process unwanted keys
+ if (in_array($key, $this->skip_keys)) {
+ continue;
+ }
+
+ // change dropzone middleware already uploaded file
+ if (in_array($real_key, $this->uploaded_file_keys)) {
+ continue;
+ }
+
+ // Process file uploads
+ if (in_array($real_key, $this->file_keys)) {
+ // Upload attachment
+ if ($request->file($key)) {
+ $media = $this->getMedia($request->file($key), 'settings');
+
+ $company->attachMedia($media, Str::snake($real_key));
+
+ $value = $media->id;
+ }
+
+ // Prevent reset
+ if (empty($value)) {
+ continue;
+ }
+ }
+
+ if ($real_key == 'default.locale') {
+ if (!in_array($value, config('language.allowed'))) {
+ continue;
+ }
+
+ user()->setAttribute('locale', $value)->save();
+ }
+
+ if ($real_key == 'default.currency') {
+ $currencies = Currency::enabled()->pluck('code')->toArray();
+
+ if (!in_array($value, $currencies)) {
+ continue;
+ }
+
+ $currency = Currency::code($value)->first();
+ $currency->rate = '1';
+ $currency->save();
+ }
+
+ // If only 1 company
+ if ($total_companies == 1) {
+ $this->oneCompany($real_key, $value);
+ }
+
+ setting()->set($real_key, $value);
+ }
+
+ // Save all settings
+ setting()->save();
+
+ $message = trans('messages.success.updated', ['type' => trans_choice('general.settings', 2)]);
+
+ $redirect_url = !empty($this->redirect_route) ? route($this->redirect_route) : url()->previous();
+
+ $response = [
+ 'status' => null,
+ 'success' => true,
+ 'error' => false,
+ 'message' => $message,
+ 'data' => null,
+ 'redirect' => $redirect_url,
+ ];
+
+ flash($message)->success();
+
+ return response()->json($response);
+ }
+
+ protected function oneCompany($real_key, $value)
+ {
+ switch ($real_key) {
+ case 'company.name':
+ Installer::updateEnv(['MAIL_FROM_NAME' => '"' . $value . '"']);
+ break;
+ case 'company.email':
+ Installer::updateEnv(['MAIL_FROM_ADDRESS' => '"' . $value . '"']);
+ break;
+ case 'default.locale':
+ Installer::updateEnv(['APP_LOCALE' => '"' . $value . '"']);
+ break;
+ case 'schedule.time':
+ Installer::updateEnv(['APP_SCHEDULE_TIME' => '"' . $value . '"']);
+ break;
+ case 'email.protocol':
+ Installer::updateEnv(['MAIL_MAILER' => '"' . $value . '"']);
+ break;
+ case 'email.smtp_host':
+ Installer::updateEnv(['MAIL_HOST' => '"' . $value . '"']);
+ break;
+ case 'email.smtp_port':
+ Installer::updateEnv(['MAIL_PORT' => '"' . $value . '"']);
+ break;
+ case 'email.smtp_username':
+ Installer::updateEnv(['MAIL_USERNAME' => '"' . $value . '"']);
+ break;
+ case 'email.smtp_password':
+ Installer::updateEnv(['MAIL_PASSWORD' => '"' . $value . '"']);
+ break;
+ case 'email.smtp_encryption':
+ Installer::updateEnv(['MAIL_ENCRYPTION' => '"' . $value . '"']);
+ break;
+ }
+ }
+}
diff --git a/app/Abstracts/Listeners/Report.php b/app/Abstracts/Listeners/Report.php
index 12cd95e2a..eee1f4715 100644
--- a/app/Abstracts/Listeners/Report.php
+++ b/app/Abstracts/Listeners/Report.php
@@ -84,7 +84,7 @@ abstract class Report
public function getCategories($types, $limit = false)
{
- $model = Category::type($types)->orderBy('name');
+ $model = Category::withSubCategory()->type($types)->orderBy('name');
if ($limit !== false) {
$model->take(setting('default.select_limit'));
@@ -183,14 +183,69 @@ abstract class Report
public function setRowNamesAndValues($event, $rows)
{
+ $nodes = [];
+
foreach ($event->class->dates as $date) {
- foreach ($event->class->tables as $table) {
+ foreach ($event->class->tables as $table_key => $table_name) {
foreach ($rows as $id => $name) {
- $event->class->row_names[$table][$id] = $name;
- $event->class->row_values[$table][$id][$date] = 0;
+ $event->class->row_names[$table_key][$id] = $name;
+ $event->class->row_values[$table_key][$id][$date] = 0;
+
+ $nodes[$id] = null;
}
}
}
+
+ $this->setTreeNodes($event, $nodes);
+ }
+
+ public function setTreeNodes($event, $nodes)
+ {
+ foreach ($event->class->tables as $table_key => $table_name) {
+ foreach ($nodes as $id => $node) {
+ $event->class->row_tree_nodes[$table_key][$id] = $node;
+ }
+ }
+ }
+
+ public function getCategoriesNodes($categories)
+ {
+ $nodes = [];
+
+ foreach ($categories as $id => $name) {
+ $category = Category::withSubCategory()->find($id);
+
+ if (!is_null($category->parent_id)) {
+ unset($categories[$id]);
+
+ continue;
+ }
+
+ $nodes[$id] = $this->getSubCategories($category);
+ }
+
+ return $nodes;
+ }
+
+ public function getSubCategories($category)
+ {
+ if ($category->sub_categories->count() == 0) {
+ return null;
+ }
+
+ $sub_categories = [];
+
+ foreach ($category->sub_categories as $sub_category) {
+ $sub_category->load('sub_categories');
+
+ $sub_categories[$sub_category->id] = $this->getSubCategories($sub_category);
+ }
+
+ if (!empty($sub_categories)) {
+ $sub_categories[$category->id] = null;
+ }
+
+ return $sub_categories;
}
public function getFormattedDate($event, $date)
diff --git a/app/Abstracts/Livewire/Document.php b/app/Abstracts/Livewire/Document.php
deleted file mode 100644
index 481faf6ab..000000000
--- a/app/Abstracts/Livewire/Document.php
+++ /dev/null
@@ -1,1208 +0,0 @@
-type = $type;
- $this->imageEmptyPage = $this->getImageEmptyPage($type, $imageEmptyPage);
- $this->textEmptyPage = $this->getTextEmptyPage($type, $textEmptyPage);
- $this->textPage = $this->getTextPage($type, $textPage);
- $this->textTitle = $this->getTextTitle($type, $textTitle);
- $this->urlDocsPath = $this->getUrlDocsPath($type, $urlDocsPath);
- $this->hideEmptyPage = $hideEmptyPage;
-
- /* -- Top Buttons Start -- */
- $this->checkPermissionCreate = $checkPermissionCreate;
-
- $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($type, $textDocumentNumber);
- $this->textContactName = $this->getTextContactName($type, $textContactName);
- $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
- $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->textModalDelete = $this->getTextModalDelete($type, $textModalDelete);
- $this->valueModalDelete = $valueModalDelete;
-
- $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->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
- $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
- $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
- /* -- Card Body End -- */
-
- $this->limits = ($limits) ? $limits : ['10' => '10', '25' => '25', '50' => '50', '100' => '100'];
- }
-
- protected function getImageEmptyPage($type, $imageEmptyPage)
- {
- if (!empty($imageEmptyPage)) {
- return $imageEmptyPage;
- }
-
- $image_empty_page = config('type.' . $type . '.image_empty_page');
-
- if (!empty($image_empty_page)) {
- return $image_empty_page;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
- $image_path = 'public/img/empty_pages/' . $page . '.png';
-
- if ($alias = config('type.' . $type . '.alias')) {
- $image_path = 'modules/' . Str::studly($alias) . '/Resources/assets/img/empty_pages/' . $page . '.png';
- }
-
- return $image_path;
- }
-
- protected function getTextEmptyPage($type, $textEmptyPage)
- {
- if (!empty($textEmptyPage)) {
- return $textEmptyPage;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
-
- $translation = $this->getTextFromConfig($type, 'empty_page', 'empty.' . $page);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.empty.' . $page;
- }
-
- protected function getUrlDocsPath($type, $urlDocsPath)
- {
- if (!empty($urlDocsPath)) {
- return $urlDocsPath;
- }
-
- $docs_path = config('type.' . $type . '.docs_path');
-
- if (!empty($docs_path)) {
- return $docs_path;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $docsPath = 'purchases/bills';
- break;
- default:
- $docsPath = 'sales/invoices';
- break;
- }
-
- return 'https://akaunting.com/docs/user-manual/' . $docsPath;
- }
-
- protected function getTextTitle($type, $textTitle)
- {
- if (!empty($textTitle)) {
- return $textTitle;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
-
- $translation = $this->getTextFromConfig($type, 'title', $page);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.' . $page;
- }
-
- protected function getTextPage($type, $textPage)
- {
- if (!empty($textPage)) {
- return $textPage;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
-
- $translation = $this->getTextFromConfig($type, 'page', $page);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.' . $page;
- }
-
- protected function getCreateRoute($type, $createRoute)
- {
- if (!empty($createRoute)) {
- return $createRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'create');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.create';
- }
-
- protected function getImportRoute($importRoute)
- {
- if (!empty($importRoute)) {
- return $importRoute;
- }
-
- $route = 'import.create';
-
- return $route;
- }
-
- protected function getImportRouteParameters($type, $importRouteParameters)
- {
- if (!empty($importRouteParameters)) {
- 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' => $group,
- 'type' => config('type.' . $type . '.route.prefix'),
- 'route' => ($route) ? $route : 'invoices.import',
- ];
-
- return $importRouteParameters;
- }
-
- protected function getExportRoute($type, $exportRoute)
- {
- if (!empty($exportRoute)) {
- return $exportRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'export');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.export';
- }
-
- protected function getRoute($type, $formCardHeaderRoute)
- {
- if (!empty($formCardHeaderRoute)) {
- return $formCardHeaderRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'index');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.index';
- }
-
- protected function getSearchStringModel($type, $searchStringModel)
- {
- if (!empty($searchStringModel)) {
- return $searchStringModel;
- }
-
- $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;
- }
-
- protected function getTextBulkAction($type, $textBulkAction)
- {
- if (!empty($textBulkAction)) {
- return $textBulkAction;
- }
-
- $default_key = config('type.' . $type . '.translation.prefix');
-
- $translation = $this->getTextFromConfig($type, 'bulk_action', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.invoices';
- }
-
- protected function getBulkActions($type, $bulkActions, $bulkActionClass)
- {
- if (!empty($bulkActions)) {
- return $bulkActions;
- }
-
- $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)) {
- 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;
- }
-
- $group = config('type.' . $type . '.group');
-
- if (!empty(config('type.' . $type . '.alias'))) {
- $group = config('type.' . $type . '.alias');
- }
-
- $bulkActionRouteParameters = [
- 'group' => $group,
- 'type' => config('type.' . $type . '.route.prefix')
- ];
-
- return $bulkActionRouteParameters;
- }
-
- protected function getClassBulkAction($type, $classBulkAction)
- {
- if (!empty($classBulkAction)) {
- 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($type, $textDocumentNumber)
- {
- if (!empty($textDocumentNumber)) {
- return $textDocumentNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_number', 'numbers');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.numbers';
- }
-
- protected function getClassDocumentNumber($type, $classDocumentNumber)
- {
- if (!empty($classDocumentNumber)) {
- return $classDocumentNumber;
- }
-
- if ($classDocumentNumber = $this->getClass('classDocumentNumber')) {
- return $classDocumentNumber;
- }
-
- $class = $this->getClassFromConfig($type, 'document_number');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-md-3 col-lg-2 col-xl-2 d-none d-md-block';
- }
-
- protected function getTextContactName($type, $textContactName)
- {
- if (!empty($textContactName)) {
- return $textContactName;
- }
-
- $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 'general.customers';
- }
-
- protected function getClassContactName($type, $classContactName)
- {
- if (!empty($classContactName)) {
- return $classContactName;
- }
-
- if ($classContactName = $this->getClass('classContactName')) {
- 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';
- }
-
- protected function getClassAmount($type, $classAmount)
- {
- if (!empty($classAmount)) {
- return $classAmount;
- }
-
- if ($classAmount = $this->getClass('classAmount')) {
- 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';
- }
-
- protected function getTextIssuedAt($type, $textIssuedAt)
- {
- if (!empty($textIssuedAt)) {
- return $textIssuedAt;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getClassIssuedAt($type, $classIssuedAt)
- {
- if (!empty($classIssuedAt)) {
- return $classIssuedAt;
- }
-
- if ($classIssuedAt = $this->getClass('classIssuedAt')) {
- 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';
- }
-
- protected function getTextDueAt($type, $textDueAt)
- {
- if (!empty($textDueAt)) {
- return $textDueAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.due_date';
- }
-
- protected function getClassDueAt($type, $classDueAt)
- {
- if (!empty($classDueAt)) {
- return $classDueAt;
- }
-
- $class = $this->getClassFromConfig($type, 'due_at');
-
- if (!empty($class)) {
- return $class;
- }
-
- 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;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.');
-
- 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.';
- }
-
- protected function getClassStatus($type, $classStatus)
- {
- if (!empty($classStatus)) {
- return $classStatus;
- }
-
- if ($classStatus = $this->getClass('classStatus')) {
- 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';
- }
-
- protected function getClassActions($type, $classActions)
- {
- if (!empty($classActions)) {
- return $classActions;
- }
-
- if ($classActions = $this->getClass('classActions')) {
- 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';
- }
-
- protected function getRouteButtonShow($type, $routeButtonShow)
- {
- if (!empty($routeButtonShow)) {
- return $routeButtonShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'show', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.show';
- }
-
- protected function getRouteButtonEdit($type, $routeButtonEdit)
- {
- if (!empty($routeButtonEdit)) {
- return $routeButtonEdit;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'edit', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.edit';
- }
-
- protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
- {
- if (!empty($routeButtonDuplicate)) {
- return $routeButtonDuplicate;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'duplicate', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.duplicate';
- }
-
- protected function getRouteButtonCancelled($type, $routeButtonCancelled)
- {
- if (!empty($routeButtonCancelled)) {
- return $routeButtonCancelled;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'cancelled', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.cancelled';
- }
-
- protected function getRouteButtonDelete($type, $routeButtonDelete)
- {
- if (!empty($routeButtonDelete)) {
- return $routeButtonDelete;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'destroy', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.destroy';
- }
-
- protected function getTextModalDelete($type, $textModalDelete)
- {
- if (!empty($textModalDelete)) {
- return $textModalDelete;
- }
-
- if ($alias = config('type.' . $type . '.alias')) {
- return $alias . '::general.' . Str::plural(str_replace('-', '_', $type));
- }
-
- return '';
- }
-
- protected function getPermissionCreate($type, $permissionCreate)
- {
- if (!empty($permissionCreate)) {
- return $permissionCreate;
- }
-
- $permissionCreate = $this->getPermissionFromConfig($type, 'create');
-
- return $permissionCreate;
- }
-
- protected function getPermissionUpdate($type, $permissionUpdate)
- {
- if (!empty($permissionUpdate)) {
- return $permissionUpdate;
- }
-
- $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
-
- return $permissionUpdate;
- }
-
- protected function getPermissionDelete($type, $permissionDelete)
- {
- if (!empty($permissionDelete)) {
- return $permissionDelete;
- }
-
- $permissionDelete = $this->getPermissionFromConfig($type, 'delete');
-
- return $permissionDelete;
- }
-
- 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-3 col-xl-3 d-none d-md-block';
- $this->class_count += 2;
- break;
- case 3:
- $class = 'col-md-5 col-lg-4 col-xl-4 d-none d-md-block';
- $this->class_count += 3;
- break;
- }
- }
-
- return $class;
- }
-
- public function getTextFromConfig($type, $config_key, $default_key = '', $trans_type = 'trans')
- {
- $translation = '';
-
- // if set config translation 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;
- }
-}
diff --git a/app/Abstracts/Model.php b/app/Abstracts/Model.php
index 76fc5950a..2d9b81761 100644
--- a/app/Abstracts/Model.php
+++ b/app/Abstracts/Model.php
@@ -2,6 +2,7 @@
namespace App\Abstracts;
+use Akaunting\Sortable\Traits\Sortable;
use App\Events\Common\SearchStringApplied;
use App\Events\Common\SearchStringApplying;
use App\Traits\DateTime;
@@ -9,9 +10,9 @@ use App\Traits\Owners;
use App\Traits\Sources;
use App\Traits\Tenants;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
+use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletes;
-use Kyslik\ColumnSortable\Sortable;
use Laratrust\Contracts\Ownable;
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
@@ -30,30 +31,18 @@ abstract class Model extends Eloquent implements Ownable
public $allAttributes = [];
/**
- * Create a new Eloquent model instance.
+ * Fill the model with an array of attributes.
*
* @param array $attributes
- * @return void
+ * @return $this
+ *
+ * @throws \Illuminate\Database\Eloquent\MassAssignmentException
*/
- public function __construct(array $attributes = [])
+ public function fill(array $attributes)
{
$this->allAttributes = $attributes;
- parent::__construct($attributes);
- }
-
- /**
- * Update the model in the database.
- *
- * @param array $attributes
- * @param array $options
- * @return bool
- */
- public function update(array $attributes = [], array $options = [])
- {
- $this->allAttributes = $attributes;
-
- return parent::update($attributes, $options);
+ return parent::fill($attributes);
}
/**
@@ -231,6 +220,16 @@ abstract class Model extends Eloquent implements Ownable
return $query->where($this->qualifyColumn('created_by'), '<>', user_id());
}
+ public function scopeIsRecurring(Builder $query): Builder
+ {
+ return $query->where($this->qualifyColumn('type'), 'like', '%-recurring');
+ }
+
+ public function scopeIsNotRecurring(Builder $query): Builder
+ {
+ return $query->where($this->qualifyColumn('type'), 'not like', '%-recurring');
+ }
+
public function ownerKey($owner)
{
if ($this->isNotOwnable()) {
diff --git a/app/Abstracts/Notification.php b/app/Abstracts/Notification.php
index 36ff85072..cd3e23788 100644
--- a/app/Abstracts/Notification.php
+++ b/app/Abstracts/Notification.php
@@ -6,11 +6,19 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification as BaseNotification;
+use Illuminate\Support\Str;
abstract class Notification extends BaseNotification implements ShouldQueue
{
use Queueable;
+ /**
+ * Custom mail subject, body, etc.
+ *
+ * @var array
+ */
+ public $custom_mail;
+
/**
* Create a notification instance.
*/
@@ -33,31 +41,38 @@ abstract class Notification extends BaseNotification implements ShouldQueue
/**
* Initialise the mail representation of the notification.
*
- * @return \Illuminate\Notifications\Messages\MailMessage
*/
- public function initMessage()
+ public function initMailMessage(): MailMessage
{
app('url')->defaults(['company_id' => company_id()]);
$message = (new MailMessage)
->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->getSubject())
- ->view('partials.email.body', ['body' => $this->getBody()]);
+ ->view('components.email.body', ['body' => $this->getBody()]);
+
+ if (!empty($this->custom_mail['cc'])) {
+ $message->cc($this->custom_mail['cc']);
+ }
return $message;
}
- public function getSubject()
+ public function getSubject(): string
{
- return $this->replaceTags($this->template->subject);
+ return !empty($this->custom_mail['subject'])
+ ? $this->custom_mail['subject']
+ : $this->replaceTags($this->template->subject);
}
public function getBody()
{
- return $this->replaceTags($this->template->body);
+ $body = !empty($this->custom_mail['body']) ? $this->custom_mail['body'] : $this->replaceTags($this->template->body);
+
+ return $body . $this->getFooter();
}
- public function replaceTags($content)
+ public function replaceTags(string $content): string
{
$pattern = $this->getTagsPattern();
$replacement = $this->applyQuote($this->getTagsReplacement());
@@ -65,7 +80,16 @@ abstract class Notification extends BaseNotification implements ShouldQueue
return $this->revertQuote(preg_replace($pattern, $replacement, $content));
}
- public function getTagsPattern()
+ public function getFooter()
+ {
+ $url = 'https://akaunting.com/lp/accounting-software?utm_source=email&utm_medium=software&utm_campaign=footer&utm_content=' . $this->template->alias;
+
+ $get_started = '' . trans('footer.get_started') . '';
+
+ return view('components.email.footer', compact('url', 'get_started'));
+ }
+
+ public function getTagsPattern(): array
{
$pattern = [];
@@ -76,17 +100,35 @@ abstract class Notification extends BaseNotification implements ShouldQueue
return $pattern;
}
- public function getTags()
+ public function getTags(): array
{
return [];
}
- public function getTagsReplacement()
+ public function getTagsReplacement(): array
{
return [];
}
- public function applyQuote($vars)
+ public function getTagsBinding(): array
+ {
+ $bindings = [];
+
+ $tags = $this->getTags();
+ $replacements = $this->getTagsReplacement();
+
+ $wrappers = ['{', '}'];
+
+ foreach ($tags as $index => $tag) {
+ $key = Str::replace($wrappers, '', $tag);
+
+ $bindings[$key] = $replacements[$index];
+ }
+
+ return $bindings;
+ }
+
+ public function applyQuote(array $vars): array
{
$new_vars = [];
@@ -97,8 +139,16 @@ abstract class Notification extends BaseNotification implements ShouldQueue
return $new_vars;
}
- public function revertQuote($content)
+ public function revertQuote(string $content): string
{
return str_replace('\\', '', $content);
}
+
+ /**
+ * @deprecated 3.0
+ */
+ public function initMessage()
+ {
+ return $this->initMailMessage();
+ }
}
diff --git a/app/Abstracts/Observer.php b/app/Abstracts/Observer.php
index a6edc2c59..c10b0db37 100644
--- a/app/Abstracts/Observer.php
+++ b/app/Abstracts/Observer.php
@@ -2,9 +2,9 @@
namespace App\Abstracts;
-use Monooso\Unobserve\CanMute;
+use Akaunting\MutableObserver\Traits\Mutable;
abstract class Observer
{
- use CanMute;
+ use Mutable;
}
diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php
index 7f7046f21..66324dc26 100644
--- a/app/Abstracts/Report.php
+++ b/app/Abstracts/Report.php
@@ -2,6 +2,7 @@
namespace App\Abstracts;
+use Akaunting\Apexcharts\Charts as Apexcharts;
use App\Events\Report\DataLoaded;
use App\Events\Report\DataLoading;
use App\Events\Report\FilterApplying;
@@ -12,17 +13,18 @@ use App\Events\Report\RowsShowing;
use App\Exports\Common\Reports as Export;
use App\Models\Common\Report as Model;
use App\Models\Document\Document;
+use App\Models\Setting\Category;
use App\Traits\Charts;
use App\Traits\DateTime;
use App\Traits\SearchString;
-use App\Utilities\Chartjs;
+use App\Traits\Translations;
use App\Utilities\Date;
use App\Utilities\Export as ExportHelper;
use Illuminate\Support\Str;
abstract class Report
{
- use Charts, DateTime, SearchString;
+ use Charts, DateTime, SearchString, Translations;
public $model;
@@ -30,7 +32,9 @@ abstract class Report
public $category = 'reports.income_expense';
- public $icon = 'fa fa-chart-pie';
+ public $icon = 'donut_small';
+
+ public $type = 'detail';
public $has_money = true;
@@ -53,23 +57,21 @@ abstract class Report
public $loaded = false;
public $chart = [
- 'line' => [
- 'width' => '0',
- 'height' => '300',
- 'options' => [
- 'color' => '#6da252',
- 'legend' => [
- 'display' => false,
- ],
+ 'bar' => [
+ 'colors' => [
+ '#6da252',
],
],
- 'dates' => [],
- 'datasets' => [],
+ 'donut' => [
+ //
+ ],
];
public $column_name_width = 'report-column-name';
public $column_value_width = 'report-column-value';
+ public $row_tree_nodes = [];
+
public function __construct(Model $model = null, $load_data = true)
{
$this->setGroups();
@@ -126,6 +128,18 @@ abstract class Report
return trans($this->category);
}
+ public function getCategoryDescription()
+ {
+ if (!empty($this->category_description)) {
+ return trans($this->category_description);
+ }
+
+ return $this->findTranslation([
+ $this->category . '_desc',
+ $this->category . '_description',
+ ]);
+ }
+
public function getIcon()
{
return $this->icon;
@@ -152,47 +166,77 @@ abstract class Report
return $total;
}
- public function getChart()
+ public function getCharts($table_key)
{
- $chart = new Chartjs();
+ return [
+ 'bar' => $this->getBarChart($table_key),
+ 'donut' => $this->getDonutChart($table_key),
+ ];
+ }
- if (!$type = $this->getSetting('chart')) {
+ public function getBarChart($table_key)
+ {
+ $chart = new Apexcharts();
+
+ if (empty($this->chart)) {
return $chart;
}
- $config = $this->chart[$type];
+ $options = !empty($this->chart[$table_key]) ? $this->chart[$table_key]['bar'] : $this->chart['bar'];
- $default_options = $this->getLineChartOptions();
+ $chart->setType('bar')
+ ->setOptions($options)
+ ->setLabels(array_values($this->dates))
+ ->setDataset($this->tables[$table_key], 'column', array_values($this->footer_totals[$table_key]));
- $options = array_merge($default_options, (array) $config['options']);
+ return $chart;
+ }
- $chart->type($type)
- ->width((int) $config['width'])
- ->height((int) $config['height'])
- ->options($options)
- ->labels(!empty($config['dates']) ? array_values($config['dates']) : array_values($this->dates));
+ public function getDonutChart($table_key)
+ {
+ $chart = new Apexcharts();
- if (!empty($config['datasets'])) {
- foreach ($config['datasets'] as $dataset) {
- $chart->dataset($dataset['name'], 'line', array_values($dataset['totals']))
- ->backgroundColor(isset($dataset['backgroundColor']) ? $dataset['backgroundColor'] : '#6da252')
- ->color(isset($dataset['color']) ? $dataset['color'] : '#6da252')
- ->options((array) $dataset['options'])
- ->fill(false);
- }
- } else {
- foreach ($this->footer_totals as $total) {
- $chart->dataset($this->model->name, 'line', array_values($total))
- ->backgroundColor(isset($config['backgroundColor']) ? $config['backgroundColor'] : '#6da252')
- ->color(isset($config['color']) ? $config['color'] : '#6da252')
- ->options([
- 'borderWidth' => 4,
- 'pointStyle' => 'line',
- ])
- ->fill(false);
+ if (empty($this->chart)) {
+ return $chart;
+ }
+
+ $tmp_values = [];
+
+ if (! empty($this->row_values[$table_key])) {
+ foreach ($this->row_values[$table_key] as $id => $dates) {
+ $tmp_values[$id] = 0;
+
+ foreach ($dates as $date) {
+ $tmp_values[$id] += $date;
+ }
}
}
+ $tmp_values = collect($tmp_values)->sort()->reverse()->take(10)->all();
+
+ $total = array_sum($tmp_values);
+ $total = !empty($total) ? $total : 1;
+
+ $group = $this->getSetting('group');
+
+ $labels = $colors = $values = [];
+
+ foreach ($tmp_values as $id => $value) {
+ $labels[$id] = $this->row_names[$table_key][$id];
+
+ $colors[$id] = ($group == 'category') ? Category::find($id)?->color : '#' . dechex(rand(0x000000, 0xFFFFFF));
+
+ $values[$id] = round(($value * 100 / $total), 0);
+ }
+
+ $options = !empty($this->chart[$table_key]) ? $this->chart[$table_key]['donut'] : $this->chart['donut'];
+
+ $chart->setType('donut')
+ ->setOptions($options)
+ ->setLabels(array_values($labels))
+ ->setColors(array_values($colors))
+ ->setDataset($this->tables[$table_key], 'donut', array_values($values));
+
return $chart;
}
@@ -208,7 +252,7 @@ abstract class Report
public function export()
{
- return ExportHelper::toExcel(new Export($this->views['content'], $this), $this->model->name);
+ return ExportHelper::toExcel(new Export($this->views[$this->type], $this), $this->model->name);
}
public function setColumnWidth()
@@ -221,10 +265,10 @@ abstract class Report
switch ($period) {
case 'quarterly':
- $width = 'col-sm-2';
+ $width = 'w-2/12 col-2';
break;
case 'yearly':
- $width = 'col-sm-4';
+ $width = 'w-4/12 col-4';
break;
}
@@ -243,31 +287,41 @@ abstract class Report
public function setViews()
{
$this->views = [
- 'chart' => 'partials.reports.chart',
- 'content' => 'partials.reports.content',
- 'content.header' => 'partials.reports.content.header',
- 'content.footer' => 'partials.reports.content.footer',
- 'show' => 'partials.reports.show',
- 'header' => 'partials.reports.header',
- 'filter' => 'partials.reports.filter',
- 'print' => 'partials.reports.print',
- 'table' => 'partials.reports.table',
- 'table.footer' => 'partials.reports.table.footer',
- 'table.header' => 'partials.reports.table.header',
- 'table.rows' => 'partials.reports.table.rows',
+ 'show' => 'components.reports.show',
+ 'print' => 'components.reports.print',
+ 'filter' => 'components.reports.filter',
+
+ 'detail' => 'components.reports.detail',
+ 'detail.content.header' => 'components.reports.detail.content.header',
+ 'detail.content.footer' => 'components.reports.detail.content.footer',
+ 'detail.table' => 'components.reports.detail.table',
+ 'detail.table.header' => 'components.reports.detail.table.header',
+ 'detail.table.body' => 'components.reports.detail.table.body',
+ 'detail.table.row' => 'components.reports.detail.table.row',
+ 'detail.table.footer' => 'components.reports.detail.table.footer',
+
+ 'summary' => 'components.reports.summary',
+ 'summary.content.header' => 'components.reports.summary.content.header',
+ 'summary.content.footer' => 'components.reports.summary.content.footer',
+ 'summary.table' => 'components.reports.summary.table',
+ 'summary.table.header' => 'components.reports.summary.table.header',
+ 'summary.table.body' => 'components.reports.summary.table.body',
+ 'summary.table.row' => 'components.reports.summary.table.row',
+ 'summary.table.footer' => 'components.reports.summary.table.footer',
+ 'summary.chart' => 'components.reports.summary.chart',
];
}
public function setTables()
{
$this->tables = [
- 'default' => 'default',
+ 'default' => trans_choice('general.totals', 1),
];
}
public function setDates()
{
- if (!$period = $this->getSetting('period')) {
+ if (! $period = $this->getSetting('period')) {
return;
}
@@ -299,8 +353,8 @@ abstract class Report
$this->dates[] = $date;
- foreach ($this->tables as $table) {
- $this->footer_totals[$table][$date] = 0;
+ foreach ($this->tables as $table_key => $table_name) {
+ $this->footer_totals[$table_key][$date] = 0;
}
}
}
@@ -498,13 +552,17 @@ abstract class Report
return $this->model->settings->$name ?? $default;
}
+ public function getBasis()
+ {
+ return $this->getSearchStringValue('basis', $this->getSetting('basis'));
+ }
+
public function getFields()
{
return [
$this->getGroupField(),
$this->getPeriodField(),
$this->getBasisField(),
- $this->getChartField(),
];
}
@@ -513,7 +571,7 @@ abstract class Report
$this->setGroups();
return [
- 'type' => 'selectGroup',
+ 'type' => 'select',
'name' => 'group',
'title' => trans('general.group_by'),
'icon' => 'folder',
@@ -528,7 +586,7 @@ abstract class Report
public function getPeriodField()
{
return [
- 'type' => 'selectGroup',
+ 'type' => 'select',
'name' => 'period',
'title' => trans('general.period'),
'icon' => 'calendar',
@@ -547,7 +605,7 @@ abstract class Report
public function getBasisField()
{
return [
- 'type' => 'selectGroup',
+ 'type' => 'select',
'name' => 'basis',
'title' => trans('general.basis'),
'icon' => 'file',
@@ -561,22 +619,4 @@ abstract class Report
],
];
}
-
- public function getChartField()
- {
- return [
- 'type' => 'selectGroup',
- 'name' => 'chart',
- 'title' => trans_choice('general.charts', 1),
- 'icon' => 'chart-pie',
- 'values' => [
- '0' => trans('general.disabled'),
- 'line' => trans('reports.charts.line'),
- ],
- 'selected' => '0',
- 'attributes' => [
- 'required' => 'required',
- ],
- ];
- }
}
diff --git a/app/Abstracts/View/Component.php b/app/Abstracts/View/Component.php
new file mode 100644
index 000000000..4b1f81cca
--- /dev/null
+++ b/app/Abstracts/View/Component.php
@@ -0,0 +1,13 @@
+getConsumableComponentData($key, $default);
+ }
+}
diff --git a/app/Abstracts/View/Components/Contacts/Form.php b/app/Abstracts/View/Components/Contacts/Form.php
new file mode 100644
index 000000000..f457f4466
--- /dev/null
+++ b/app/Abstracts/View/Components/Contacts/Form.php
@@ -0,0 +1,503 @@
+type = $type;
+
+ $this->model = ! empty($model) ? $model : $contact;
+ $this->contact = $this->model;
+
+ /* -- Content Start -- */
+ $this->formId = $formId;
+ $this->formRoute = $this->getFormRoute($type, $formRoute, $this->model);
+ $this->formMethod = $this->getFormMethod($type, $formMethod, $this->model);
+
+ $this->hideSectionGeneral = $hideSectionGeneral;
+ $this->hideSectionBilling = $hideSectionBilling;
+ $this->hideSectionAddress = $hideSectionAddress;
+
+ /* -- General Start -- */
+ $this->textSectionGeneralTitle = $this->getTextSectionGeneralTitle($type, $textSectionGeneralTitle);
+ $this->textSectionGeneralDescription = $this->getTextSectionGeneralDescription($type, $textSectionGeneralDescription);
+
+ $this->hideName = $hideName;
+ $this->textName = $this->getTextName($type, $textName);
+ $this->classNameFromGroupClass = $this->getClassNameFormGroupClass($type, $classNameFromGroupClass);
+
+ $this->hideEmail = $hideEmail;
+ $this->textEmail = $this->getTextEmail($type, $textEmail);
+
+ $this->hidePhone = $hidePhone;
+ $this->textPhone = $this->getTextPhone($type, $textPhone);
+
+ $this->hideWebsite = $hideWebsite;
+ $this->textWebsite = $this->getTextWebsite($type, $textWebsite);
+
+ $this->hideReference = $hideReference;
+ $this->textReference = $this->getTextReference($type, $textReference);
+
+ $this->hideCanLogin = $hideCanLogin;
+ $this->hideLogo = $hideLogo;
+ /* -- General End -- */
+
+ /* -- Billing Start -- */
+ $this->textSectionBillingTitle = $this->getTextSectionBillingTitle($type, $textSectionBillingTitle);
+ $this->textSectionBillingDescription = $this->getTextSectionBillingDescription($type, $textSectionBillingDescription);
+
+ $this->hideTaxNumber = $hideTaxNumber;
+ $this->textTaxNumber = $this->getTextTaxNumber($type, $textTaxNumber);
+
+ $this->hideCurrency = $hideCurrency;
+ /* -- Billing End -- */
+
+ /* -- Address Start -- */
+ $this->textSectionAddressTitle = $this->getTextSectionAddressTitle($type, $textSectionAddressTitle);
+ $this->textSectionAddressDescription = $this->getTextSectionAddressDescription($type, $textSectionAddressDescription);
+
+ $this->hideAddress = $hideAddress;
+ $this->textAddress = $this->getTextAddress($type, $textAddress);
+
+ $this->hideCity = $hideCity;
+ $this->textCity = $this->getTextCity($type, $textCity);
+
+ $this->hideZipCode = $hideZipCode;
+ $this->textZipCode = $this->getTextZipCode($type, $textZipCode);
+
+ $this->hideState = $hideState;
+ $this->textState = $this->getTextState($type, $textState);
+
+ $this->hideState = $hideTaxNumber;
+ /* -- Address End -- */
+
+ /* -- Buttons Start -- */
+ $this->cancelRoute = $this->getCancelRoute($type, $cancelRoute);
+ /* -- Buttons End -- */
+ /* -- Content End -- */
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ /* -- Content Start -- */
+ /* -- General Start -- */
+ protected function getTextSectionGeneralTitle($type, $textSectionGeneralTitle)
+ {
+ if (! empty($textSectionGeneralTitle)) {
+ return $textSectionGeneralTitle;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_general_title', 'general');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.general';
+ }
+
+ protected function getTextSectionGeneralDescription($type, $textSectionGeneralDescription)
+ {
+ if (! empty($textSectionGeneralDescription)) {
+ return $textSectionGeneralDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_general_description', 'form_description.general');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'customers.form_description.general';
+ }
+
+ protected function getTextName($type, $textName)
+ {
+ if (! empty($textName)) {
+ return $textName;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'name', 'name');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.name';
+ }
+
+ protected function getClassNameFormGroupClass($type, $classNameFromGroupClass)
+ {
+ if (! empty($classNameFromGroupClass)) {
+ return $classNameFromGroupClass;
+ }
+
+ $class = $this->getClassFromConfig($type, 'name');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'sm:col-span-6';
+ }
+
+ protected function getTextEmail($type, $textEmail)
+ {
+ if (! empty($textEmail)) {
+ return $textEmail;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'email', 'email');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.email';
+ }
+
+ protected function getTextPhone($type, $textPhone)
+ {
+ if (! empty($textPhone)) {
+ return $textPhone;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'phone', 'phone');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.phone';
+ }
+
+ protected function getTextWebsite($type, $textWebsite)
+ {
+ if (! empty($textWebsite)) {
+ return $textWebsite;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'website', 'website');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.website';
+ }
+
+ protected function getTextReference($type, $textReference)
+ {
+ if (! empty($textReference)) {
+ return $textReference;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'reference', 'reference');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.reference';
+ }
+ /* -- General End -- */
+
+ /* -- Billing Start -- */
+ protected function getTextSectionBillingTitle($type, $textSectionBillingTitle)
+ {
+ if (! empty($textSectionBillingTitle)) {
+ return $textSectionBillingTitle;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_billing_title');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'items.billing';
+ }
+
+ protected function getTextSectionBillingDescription($type, $textSectionBillingDescription)
+ {
+ if (! empty($textSectionBillingDescription)) {
+ return $textSectionBillingDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_billing_description');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'customers.form_description.billing';
+ }
+
+ protected function getTextTaxNumber($type, $textTaxNumber)
+ {
+ if (! empty($textTaxNumber)) {
+ return $textTaxNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'tax_number', 'tax_number');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.tax_number';
+ }
+ /* -- Billing End -- */
+
+ /* -- Address Start -- */
+ protected function getTextSectionAddressTitle($type, $textSectionAddressTitle)
+ {
+ if (! empty($textSectionAddressTitle)) {
+ return $textSectionAddressTitle;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_address_title', 'address');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.address';
+ }
+
+ protected function getTextSectionAddressDescription($type, $textSectionAddressDescription)
+ {
+ if (! empty($textSectionAddressDescription)) {
+ return $textSectionAddressDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'section_address_description');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'customers.form_description.address';
+ }
+
+ protected function getTextAddress($type, $textAddress)
+ {
+ if (! empty($textAddress)) {
+ return $textAddress;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'address', 'address');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.address';
+ }
+
+ protected function getTextCity($type, $textCity)
+ {
+ if (! empty($textCity)) {
+ return $textCity;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'city', 'cities');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.cities';
+ }
+
+ protected function getTextZipCode($type, $textZipCode)
+ {
+ if (! empty($textZipCode)) {
+ return $textZipCode;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'zip_code', 'zip_code');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.zip_code';
+ }
+
+ protected function getTextState($type, $textState)
+ {
+ if (! empty($textState)) {
+ return $textState;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'state', 'state');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.state';
+ }
+ /* -- Address End -- */
+ /* -- Content End -- */
+}
diff --git a/app/Abstracts/View/Components/Contacts/Index.php b/app/Abstracts/View/Components/Contacts/Index.php
new file mode 100644
index 000000000..a5e591a02
--- /dev/null
+++ b/app/Abstracts/View/Components/Contacts/Index.php
@@ -0,0 +1,492 @@
+type = $type;
+ $this->group = $this->getGroup($type, $group);
+ $this->page = $this->getPage($type, $page);
+ $this->contacts = ($contacts) ? $contacts : collect();
+ $this->textPage = $this->getTextPage($type, $textPage);
+
+ $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
+ $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
+ $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
+ /* -- Main End -- */
+
+ /* -- Buttons Start -- */
+ $this->checkPermissionCreate = $checkPermissionCreate;
+
+ $this->hideCreate = $hideCreate;
+ $this->hideImport = $hideImport;
+ $this->hideExport = $hideExport;
+
+ $this->routeButtonShow = $this->getRouteButtonShow($type, $routeButtonShow);
+ $this->createRoute = $this->getCreateRoute($type, $createRoute);
+ $this->importRoute = $this->getImportRoute($importRoute);
+ $this->importRouteParameters = $this->getImportRouteParameters($type, $importRouteParameters);
+ $this->exportRoute = $this->getExportRoute($type, $exportRoute);
+ /* -- Buttons End -- */
+
+ /* -- Content Start -- */
+ $this->hideEmptyPage = $hideEmptyPage;
+
+ $this->hideSummary = $hideSummary;
+ $this->summaryItems = $this->getSummaryItems($type, $summaryItems);
+
+ $this->hideSearchString = $hideSearchString;
+ $this->hideBulkAction = $hideBulkAction;
+
+ $this->searchStringModel = $this->getSearchStringModel($type, $searchStringModel);
+
+ $this->bulkActionClass = $this->getBulkActionClass($type, $bulkActionClass);
+ $this->bulkActionRouteParameters = $this->getBulkActionRouteParameters($type, $bulkActionRouteParameters);
+
+ $this->searchRoute = $this->getIndexRoute($type, $searchRoute);
+
+ $this->classBulkAction = $this->getClassBulkAction($type, $classBulkAction);
+
+ $this->showPicture = $showPicture;
+ $this->hideName = $hideName;
+ $this->hideTaxNumber = $hideTaxNumber;
+ $this->classNameAndTaxNumber = $this->getClassNameAndTaxNumber($type, $classNameAndTaxNumber);
+ $this->textName = $this->getTextName($type, $textName);
+ $this->textTaxNumber = $this->getTextTaxNumber($type, $textTaxNumber);
+
+ $this->hideEmail = $hideEmail;
+ $this->hidePhone = $hidePhone;
+ $this->classEmailAndPhone = $this->getClassEmailAndPhone($type, $classEmailAndPhone);
+ $this->textEmail = $this->getTextEmail($type, $textEmail);
+ $this->textPhone = $this->getTextPhone($type, $textPhone);
+
+ $this->hideCountry = $hideCountry;
+ $this->hideCurrencyCode = $hideCurrencyCode;
+ $this->classCountryAndCurrencyCode = $this->getClassCountryAndCurrencyCode($type, $classCountryAndCurrencyCode);
+ $this->textCountry = $this->getTextCountry($type, $textCountry);
+ $this->textCurrencyCode = $this->getTextCurrencyCode($type, $textCurrencyCode);
+
+ $this->hideOpen = $hideOpen;
+ $this->hideOverdue = $hideOverdue;
+ $this->classOpenAndOverdue = $this->getClassOpenAndOverdue($type, $classOpenAndOverdue);
+ $this->textOpen = $this->getTextOpen($type, $textOpen);
+ $this->textOverdue = $this->getTextOverdue($type, $textOverdue);
+ /* -- Content End -- */
+
+ /* -- Empty Start -- */
+ $this->imageEmptyPage = $this->getImageEmptyPage($type, $imageEmptyPage);
+ $this->textEmptyPage = $this->getTextEmptyPage($type, $textEmptyPage);
+ $this->urlDocsPath = $this->getUrlDocsPath($type, $urlDocsPath);
+ /* -- Empty End -- */
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ public function getSummaryItems($type, $summaryItems)
+ {
+ if (! empty($summaryItems)) {
+ return $summaryItems;
+ }
+
+ $route = $this->getIndexRoute($type, null);
+
+ $document_type = config('type.contact.' . $type . '.document_type', 'invoice');
+
+ $totals = $this->getTotalsForFutureDocuments($document_type);
+
+ $items = [];
+
+ foreach ($totals as $key => $total) {
+ $items[] = [
+ 'title' => ($key == 'overdue') ? trans('general.overdue') : trans('documents.statuses.' . $key),
+ 'href' => route($route, ['search' => 'status:' . $key]),
+ 'amount' => money($total, setting('default.currency'), true),
+ ];
+ }
+
+ return $items;
+ }
+
+ /* -- Content Start -- */
+ protected function getClassNameAndTaxNumber($type, $classNameAndTaxNumber)
+ {
+ if (! empty($classNameAndTaxNumber)) {
+ return $classNameAndTaxNumber;
+ }
+
+ $class = $this->getClassFromConfig($type, 'name_and_tax_number');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-6/12 sm:w-3/12 truncate';
+ }
+
+ protected function getTextName($type, $textName)
+ {
+ if (! empty($textName)) {
+ return $textName;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'name', 'name');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.name';
+ }
+
+ protected function getTextTaxNumber($type, $textTaxNumber)
+ {
+ if (! empty($textTaxNumber)) {
+ return $textTaxNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'tax_number', 'tax_number');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.tax_number';
+ }
+
+ protected function getClassEmailAndPhone($type, $classEmailAndPhone)
+ {
+ if (! empty($classEmailAndPhone)) {
+ return $classEmailAndPhone;
+ }
+
+ $class = $this->getClassFromConfig($type, 'email_and_phone');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-3/12 hidden sm:table-cell';
+ }
+
+ protected function getTextEmail($type, $textEmail)
+ {
+ if (! empty($textEmail)) {
+ return $textEmail;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'email', 'email');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.email';
+ }
+
+ protected function getTextPhone($type, $textPhone)
+ {
+ if (! empty($textPhone)) {
+ return $textPhone;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'phone', 'phone');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.phone';
+ }
+
+ protected function getClassCountryAndCurrencyCode($type, $classCountryAndCurrencyCode)
+ {
+ if (! empty($classCountryAndCurrencyCode)) {
+ return $classCountryAndCurrencyCode;
+ }
+
+ $class = $this->getClassFromConfig($type, 'country_and_currency_code');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-3/12 hidden sm:table-cell';
+ }
+
+ protected function getTextCountry($type, $textCountry)
+ {
+ if (! empty($textCountry)) {
+ return $textCountry;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'country', 'countries');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.countries';
+ }
+
+ protected function getTextCurrencyCode($type, $textCurrencyCode)
+ {
+ if (! empty($textCurrencyCode)) {
+ return $textCurrencyCode;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'currency_code', 'currencies');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.currencies';
+ }
+
+ protected function getClassOpenAndOverdue($type, $classOpenAndOverdue)
+ {
+ if (! empty($classOpenAndOverdue)) {
+ return $classOpenAndOverdue;
+ }
+
+ $class = $this->getClassFromConfig($type, 'open_and_overdue');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-6/12 sm:w-3/12';
+ }
+
+ protected function getTextOpen($type, $textOpen)
+ {
+ if (! empty($textOpen)) {
+ return $textOpen;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'open', 'open');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.open';
+ }
+
+ protected function getTextOverdue($type, $textOverdue)
+ {
+ if (! empty($textOverdue)) {
+ return $textOverdue;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'overdue', 'overdue');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.overdue';
+ }
+
+ protected function getRouteButtonShow($type, $routeButtonShow)
+ {
+ if (!empty($routeButtonShow)) {
+ return $routeButtonShow;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'show', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'customer.show';
+ }
+ /* -- Content End -- */
+}
diff --git a/app/Abstracts/View/Components/Contacts/Show.php b/app/Abstracts/View/Components/Contacts/Show.php
new file mode 100644
index 000000000..19f2929ac
--- /dev/null
+++ b/app/Abstracts/View/Components/Contacts/Show.php
@@ -0,0 +1,316 @@
+type = $type;
+
+ $this->model = ! empty($model) ? $model : $contact;
+ $this->contact = $this->model;
+
+ $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
+ $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
+ $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
+ /* -- Main End -- */
+
+ /* -- Buttons Start -- */
+ $this->hideNewDropdown = $hideNewDropdown;
+ $this->hideButtonDocument = $hideButtonDocument;
+ $this->hideButtonTransaction = $hideButtonTransaction;
+
+ $this->permissionCreateDocument = $this->getPermissionCreateDocument($type, $permissionCreateDocument);
+ $this->permissionCreateTransaction = $this->getPermissionCreateTransaction($type, $permissionCreateTransaction);
+
+ $this->routeButtonDocument = $this->getCreateDocumentRoute($type, $routeButtonDocument);
+ $this->routeButtonTransaction = $this->getCreateTransactionRoute($type, $routeButtonTransaction);
+
+ $this->textDocument = $this->getTextDocument($type, $textDocument);
+ $this->textTransaction = $this->getTextTransaction($type, $textTransaction);
+
+ $this->hideButtonEdit = $hideButtonEdit;
+ $this->routeButtonEdit = $this->getEditRoute($type, $routeButtonEdit);
+
+ $this->hideActionsDropdown = $hideActionsDropdown;
+ $this->hideButtonDuplicate = $hideButtonDuplicate;
+ $this->routeButtonDuplicate = $this->getDuplicateRoute($type, $routeButtonDuplicate);
+
+ $this->hideButtonDelete = $hideButtonDelete;
+ $this->routeButtonDelete = $this->getDeleteRoute($type, $routeButtonDelete);
+ $this->textDeleteModal = $this->getTextDeleteModal($type, $textDeleteModal);
+ /* -- Buttons End -- */
+
+ /* -- Profile Start -- */
+ $this->hideProfile = $hideTopLeft;
+ $this->hideAvatar = $hideAvatar;
+ $this->hideEmail = $hideEmail;
+ $this->hidePhone = $hidePhone;
+
+ $this->hideDetails = $hideTopRight;
+ $this->hideOverdue = $hideOverdue;
+ $this->hideOpen = $hideOpen;
+ $this->hidePaid = $hidePaid;
+
+ $this->hideSummary = $hideBottomLeft;
+ $this->hideAddress = $hideAddress;
+ $this->hideTaxNumber = $hideTaxNumber;
+ $this->hideWebsite = $hideWebsite;
+ $this->hideReference = $hideReference;
+ $this->hideUser = $hideUser;
+
+ $this->hideContent = $hideBottomRight;
+ /* -- Profile End -- */
+ }
+
+ protected function getPermissionCreateDocument($type, $permissionCreateDocument)
+ {
+ if (! empty($permissionCreateDocument)) {
+ return $permissionCreateDocument;
+ }
+
+ $document_type = config('type.contact.' . $type . '.document_type', 'invoice');
+
+ $permission = '';
+ $config_key = 'create';
+
+ // if set config trasnlation config_key
+ if ($permission = config('type.document.' . $document_type . '.permission.' . $config_key)) {
+ return $permission;
+ }
+
+ $alias = config('type.document.' . $document_type . '.alias');
+ $group = config('type.document.' . $document_type . '.group');
+ $prefix = config('type.document.' . $document_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;
+
+ $permissionCreateDocument = $permission;
+
+ return $permissionCreateDocument;
+ }
+
+ protected function getPermissionCreateTransaction($type, $permissionCreateTransaction)
+ {
+ if (! empty($permissionCreateTransaction)) {
+ return $permissionCreateTransaction;
+ }
+
+ $permissionCreateTransaction = 'create-banking-transactions';
+
+ return $permissionCreateTransaction;
+ }
+
+ protected function getCreateDocumentRoute($type, $routeButtonDocument)
+ {
+ if (! empty($routeButtonDocument)) {
+ return $routeButtonDocument;
+ }
+
+ $prefix = config('type.contact.' . $type . '.route.prefix');
+ $document_type = config('type.contact.' . $type . '.document_type');
+
+ return $prefix . '.create-' . $document_type;
+ }
+
+ protected function getCreateTransactionRoute($type, $routeButtonDocument)
+ {
+ if (! empty($routeButtonDocument)) {
+ return $routeButtonDocument;
+ }
+
+ $prefix = config('type.contact.' . $type . '.route.prefix');
+ $transaction_type = config('type.contact.' . $type . '.transaction_type');
+
+ return $prefix . '.create-' . $transaction_type;
+ }
+
+ protected function getTextDocument($type, $textDocument)
+ {
+ if (! empty($textDocument)) {
+ return $textDocument;
+ }
+
+ $document_type = config('type.contact.' . $type . '.document_type');
+
+ switch ($document_type) {
+ case 'invoice':
+ $text = 'general.invoices';
+ break;
+ case 'bill':
+ $text = 'general.bills';
+ break;
+ default:
+ $text = config('type.contact.' . $type . '.translation.prefix') . '.' . config('type.contact.' . $type . '.route.prefix');
+ }
+
+ return $text;
+ }
+
+ protected function getTextTransaction($type, $textTransaction)
+ {
+ if (! empty($textTransaction)) {
+ return $textTransaction;
+ }
+
+ $document_type = config('type.contact.' . $type . '.document_type');
+
+ switch ($document_type) {
+ case 'invoice':
+ $text = 'general.incomes';
+ break;
+ case 'bill':
+ $text = 'general.expenses';
+ break;
+ default:
+ $text = config('type.contact.' . $type . '.translation.prefix') . '.' . config('type.contact.' . $type . '.transaction_type') . 's';
+ }
+
+ return $text;
+ }
+
+ protected function getTextDeleteModal($type, $textDeleteModal)
+ {
+ if (! empty($textDeleteModal)) {
+ return $textDeleteModal;
+ }
+
+ $document_type = config('type.contact.' . $type . '.document_type');
+
+ switch ($document_type) {
+ case 'invoice':
+ $text = 'general.incomes';
+ break;
+ case 'bill':
+ $text = 'general.expenses';
+ break;
+ default:
+ $text = config('type.contact.' . $type . '.translation.prefix') . '.' . config('type.contact.' . $type . '.transaction_type') . 's';
+ }
+
+ return $text;
+ }
+}
diff --git a/app/Abstracts/View/Components/Document.php b/app/Abstracts/View/Components/Document.php
deleted file mode 100644
index 82323a590..000000000
--- a/app/Abstracts/View/Components/Document.php
+++ /dev/null
@@ -1,175 +0,0 @@
- $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;
- }
-}
diff --git a/app/Abstracts/View/Components/DocumentForm.php b/app/Abstracts/View/Components/DocumentForm.php
deleted file mode 100644
index daaf64966..000000000
--- a/app/Abstracts/View/Components/DocumentForm.php
+++ /dev/null
@@ -1,1082 +0,0 @@
-type = $type;
- $this->document = $document;
- $this->currencies = $this->getCurrencies($currencies);
- $this->currency = $this->getCurrency($document, $currency, $currency_code);
- $this->currency_code = !empty($this->currency) ? $this->currency->code : setting('default.currency');
-
- /** Advanced Component Start */
- $this->categoryType = $this->getCategoryType($type, $categoryType);
- $this->textAdvancedAccordion = $this->getTextAdvancedAccordion($type, $textAdvancedAccordion);
- $this->hideRecurring = $hideRecurring;
- $this->hideCategory = $hideCategory;
- $this->hideAttachment = $hideAttachment;
- /** Advanced Component End */
-
- /** Company Component Start */
- $this->hideLogo = $hideLogo;
- $this->hideDocumentTitle = $hideDocumentTitle;
- $this->hideDocumentSubheading = $hideDocumentSubheading;
- $this->hideCompanyEdit = $hideCompanyEdit;
- $this->titleSetting = $this->getTitleSettingValue($titleSetting);
- $this->subheadingSetting = $this->getSubheadingSettingValue($subheadingSetting);
- /** Company Component End */
-
- /** Content Component Start */
- $this->routeStore = $this->getRouteStore($type, $routeStore);
- $this->routeUpdate = $this->getRouteUpdate($type, $routeUpdate, $document);
- $this->routeCancel = $this->getRouteCancel($type, $routeCancel);
- $this->formId = $formId;
- $this->formSubmit = $formSubmit;
-
- $this->hideCompany = $hideCompany;
- $this->hideAdvanced = $hideAdvanced;
- $this->hideFooter = $hideFooter;
- $this->hideButtons = $hideButtons;
- $this->footerSetting = $this->getFooterSettingValue($footerSetting);
- $this->notesSetting = $this->getNotesSettingValue($notesSetting);
- /** Content Component End */
-
- /** Metadata Component Start */
- $this->contacts = $this->getContacts($type, $document, $contacts);
- $this->contact = $this->getContact($contact, $document);
- $this->contactType = $this->getContactType($type, $contactType);
-
- $this->textAddContact = $this->getTextAddContact($type, $textAddContact);
- $this->textCreateNewContact = $this->getTextCreateNewContact($type, $textCreateNewContact);
- $this->textEditContact = $this->getTextEditContact($type, $textEditContact);
- $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
- $this->textChooseDifferentContact = $this->getTextChooseDifferentContact($type, $textChooseDifferentContact);
-
- $this->hideContact = $hideContact;
- $this->hideIssuedAt = $hideIssuedAt;
- $this->hideDocumentNumber = $hideDocumentNumber;
- $this->hideDueAt = $hideDueAt;
- $this->hideOrderNumber = $hideOrderNumber;
- $this->issuedAt = $this->getIssuedAt($type, $document, $issuedAt);
- $this->documentNumber = $this->getDocumentNumber($type, $document, $documentNumber);
- $this->dueAt = $this->getDueAt($type, $document, $dueAt);
- $this->orderNumber = $this->getOrderNumber($type, $document, $orderNumber);
-
- $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
- $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber);
- $this->textDueAt = $this->getTextDueAt($type, $textDueAt);
- $this->textOrderNumber = $this->getTextOrderNumber($type, $textOrderNumber);
- /** Metadata Component End */
-
- /** Items Component Start */
- $this->textItems = $this->getTextItems($type, $textItems);
- $this->textQuantity = $this->getTextQuantity($type, $textQuantity);
- $this->textPrice = $this->getTextPrice($type, $textPrice);
- $this->textAmount = $this->getTextAmount($type, $textAmount);
-
- $this->hideItems = $this->getHideItems($type, $hideItems, $hideName, $hideDescription);
- $this->hideName = $this->getHideName($type, $hideName);
- $this->hideDescription = $this->getHideDescription($type, $hideDescription);
- $this->hideQuantity = $this->getHideQuantity($type, $hideQuantity);
- $this->hidePrice = $this->getHidePrice($type, $hidePrice);
- $this->hideDiscount = $this->getHideDiscount($type, $hideDiscount);
- $this->hideAmount = $this->getHideAmount($type, $hideAmount);
-
- $this->hideEditItemColumns = $hideEditItemColumns;
- $this->isSalePrice = $isSalePrice;
- $this->isPurchasePrice = $isPurchasePrice;
- $this->searchCharLimit = $this->getSearchCharLimit($type, $searchCharLimit);
- /** Items Component End */
- }
-
- protected function getCurrencies($currencies)
- {
- if (!empty($currencies)) {
- return $currencies;
- }
-
- return Currency::enabled()->pluck('name', 'code');
- }
-
- protected function getCurrency($document, $currency, $currency_code)
- {
- if (!empty($currency)) {
- return $currency;
- }
-
- if (!empty($currency_code)) {
- $currency = Currency::where('code', $currency_code)->first();
- }
-
- if (empty($currency) && !empty($document)) {
- $currency = Currency::where('code', $document->currency_code)->first();
- }
-
- if (empty($currency)) {
- $currency = Currency::where('code', setting('default.currency'))->first();
- }
-
- return $currency;
- }
-
- protected function getRouteStore($type, $routeStore)
- {
- if (!empty($routeStore)) {
- return $routeStore;
- }
-
- $route = $this->getRouteFromConfig($type, 'store');
-
- if (!empty($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 getTextAdvancedAccordion($type, $textAdvancedAccordion)
- {
- if (!empty($textAdvancedAccordion)) {
- return $textAdvancedAccordion;
- }
-
- $translation = $this->getTextFromConfig($type, 'advanced_accordion');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.recurring_and_more';
- }
-
- protected function getContacts($type, $document, $contacts)
- {
- if (!empty($contacts)) {
- return $contacts;
- }
-
- $contact_type = $this->getContactType($type, null);
-
- if ($contact_type) {
- $contacts = Contact::$contact_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get();
- } else {
- $contacts = Contact::enabled()->orderBy('name')->take(setting('default.select_limit'))->get();
- }
-
- if (!empty($document) && ($document->contact && !$contacts->contains('id', $document->contact_id))) {
- $contacts->push($document->contact);
- }
-
- return $contacts;
- }
-
- protected function getContact($contact, $document)
- {
- if (!empty($contact)) {
- return $contact;
- }
-
- $contact = new \stdClass();
-
- if (!empty($document) && !empty($document->contact)) {
- $contact = $document->contact;
- }
-
- if (request()->old('contact', false)) {
- $contact = request()->old('contact');
- }
-
- return $contact;
- }
-
- protected function getContactType($type, $contactType)
- {
- if (!empty($contactType)) {
- return $contactType;
- }
-
- if ($contact_type = config('type.' . $type . '.contact_type')) {
- return $contact_type;
- }
-
- // set default type
- $type = Document::INVOICE_TYPE;
-
- return config('type.' . $type . '.contact_type');
- }
-
- protected function getTextAddContact($type, $textAddContact)
- {
- if (!empty($textAddContact)) {
- return $textAddContact;
- }
-
- $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 [
- 'general.form.add',
- 'general.customers',
- ];
- }
-
- protected function getTextCreateNewContact($type, $textCreateNewContact)
- {
- if (!empty($textCreateNewContact)) {
- return $textCreateNewContact;
- }
-
- /*
- $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 'general.add_new';
- }
-
- protected function getTextEditContact($type, $textEditContact)
- {
- if (!empty($textEditContact)) {
- return $textEditContact;
- }
-
- $translation = $this->getTextFromConfig($type, 'edit_contact', 'form.edit');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.form.edit';
- }
-
- protected function getTextContactInfo($type, $textContactInfo)
- {
- if (!empty($textContactInfo)) {
- return $textContactInfo;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_from';
- break;
- default:
- $default_key = 'bill_to';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'contact_info', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.bill_to';
- }
-
- protected function getTextChooseDifferentContact($type, $textChooseDifferentContact)
- {
- if (!empty($textChooseDifferentContact)) {
- return $textChooseDifferentContact;
- }
-
- $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 [
- 'general.form.choose_different',
- 'general.customers',
- ];
- }
-
- protected function getIssuedAt($type, $document, $issuedAt)
- {
- if (!empty($issuedAt)) {
- return $issuedAt;
- }
-
- if ($document) {
- return $document->issued_at;
- }
-
- $issued_at = $type . '_at';
-
- if (request()->has($issued_at)) {
- $issuedAt = request()->get($issued_at);
- } else {
- $issuedAt = request()->get('invoice_at', Date::now()->toDateString());
- }
-
- return $issuedAt;
- }
-
- protected function getDocumentNumber($type, $document, $documentNumber)
- {
- if (!empty($documentNumber)) {
- return $documentNumber;
- }
-
- if ($document) {
- return $document->document_number;
- }
-
- $document_number = $this->getNextDocumentNumber($type);
-
- if (empty($document_number)) {
- $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE);
- }
-
- return $document_number;
- }
-
- protected function getDueAt($type, $document, $dueAt)
- {
- if (!empty($dueAt)) {
- return $dueAt;
- }
-
- if ($document) {
- return $document->due_at;
- }
-
- $issued_at = $type . '_at';
-
- if (request()->has($issued_at)) {
- $issuedAt = request()->get($issued_at);
- } else {
- $issuedAt = Date::now()->toDateString();
- }
-
- $addDays = setting($this->getSettingKey($type, 'payment_terms'), 0) ?: 0;
-
- $dueAt = Date::parse($issuedAt)->addDays($addDays)->toDateString();
-
- return $dueAt;
- }
-
- protected function getOrderNumber($type, $document, $orderNumber)
- {
- if (!empty($orderNumber)) {
- return $orderNumber;
- }
-
- if ($document) {
- return $document->order_number;
- }
-
- $order_number = null;
- }
-
- protected function getTextDocumentNumber($type, $textDocumentNumber)
- {
- if (!empty($textDocumentNumber)) {
- return $textDocumentNumber;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_number';
- break;
- default:
- $default_key = 'invoice_number';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_number', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_number';
- }
-
- protected function getTextOrderNumber($type, $textOrderNumber)
- {
- if (!empty($textOrderNumber)) {
- return $textOrderNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'order_number');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.order_number';
- }
-
- protected function getTextIssuedAt($type, $textIssuedAt)
- {
- if (!empty($textIssuedAt)) {
- return $textIssuedAt;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getTextDueAt($type, $textDueAt)
- {
- if (!empty($textDueAt)) {
- return $textDueAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.due_date';
- }
-
- protected function getTextItems($type, $textItems)
- {
- if (!empty($textItems)) {
- return $textItems;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'item_name'), 'items') === 'custom') {
- if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
- $textItems = 'general.items';
- }
-
- return $textItems;
- }
-
- if (setting($this->getSettingKey($type, 'item_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'item_name'))) != setting($this->getSettingKey($type, 'item_name')))
- ) {
- return setting($this->getSettingKey($type, 'item_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'items');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.items';
- }
-
- protected function getTextQuantity($type, $textQuantity)
- {
- if (!empty($textQuantity)) {
- return $textQuantity;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
- if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
- $textQuantity = 'invoices.quantity';
- }
-
- return $textQuantity;
- }
-
- if (setting($this->getSettingKey($type, 'quantity_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'quantity_name'))) != setting($this->getSettingKey($type, 'quantity_name')))
- ) {
- return setting($this->getSettingKey($type, 'quantity_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'quantity');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.quantity';
- }
-
- protected function getTextPrice($type, $textPrice)
- {
- if (!empty($textPrice)) {
- return $textPrice;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
- if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
- $textPrice = 'invoices.price';
- }
-
- return $textPrice;
- }
-
- if (setting($this->getSettingKey($type, 'price_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'price_name'))) != setting($this->getSettingKey($type, 'price_name')))
- ) {
- return setting($this->getSettingKey($type, 'price_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'price');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.price';
- }
-
- protected function getTextAmount($type, $textAmount)
- {
- if (!empty($textAmount)) {
- return $textAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
- {
- if (!empty($hideItems)) {
- return $hideItems;
- }
-
- $hide = $this->getHideFromConfig($type, 'items');
-
- if ($hide) {
- return $hide;
- }
-
- $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
-
- return $hideItems;
- }
-
- protected function getHideName($type, $hideName)
- {
- if (!empty($hideName)) {
- return $hideName;
- }
-
- // if you use settting translation
- if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
- 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)
- {
- if (!empty($hideDescription)) {
- return $hideDescription;
- }
-
- // if you use settting translation
- if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
- 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)
- {
- if (!empty($hideQuantity)) {
- return $hideQuantity;
- }
-
- // if you use settting translation
- if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
- 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)
- {
- if (!empty($hidePrice)) {
- return $hidePrice;
- }
-
- // if you use settting translation
- if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
- return $hidePrice;
- }
-
- $hide = $this->getHideFromConfig($type, 'price');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_price', $hidePrice);
- }
-
- protected function getHideDiscount($type, $hideDiscount)
- {
- if (!empty($hideDiscount)) {
- return $hideDiscount;
- }
-
- // if you use settting translation
- if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
- return $hideDiscount;
- }
-
- $hide = $this->getHideFromConfig($type, 'discount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_discount', $hideDiscount);
- }
-
- protected function getHideAmount($type, $hideAmount)
- {
- if (!empty($hideAmount)) {
- return $hideAmount;
- }
-
- // if you use settting translation
- if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
- return $hideAmount;
- }
-
- $hide = $this->getHideFromConfig($type, 'amount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_amount', $hideAmount);
- }
-
- protected function getTitleSettingValue($titleSetting)
- {
- if (!empty($titleSetting)) {
- return $titleSetting;
- }
-
- return setting($this->getSettingKey($this->type, 'title'));
- }
-
- protected function getSubheadingSettingValue($subheadingSetting)
- {
- if (!empty($subheadingSetting)) {
- return $subheadingSetting;
- }
-
- return setting($this->getSettingKey($this->type, 'subheading'));
- }
-
- protected function getFooterSettingValue($footerSetting)
- {
- if (!empty($footerSetting)) {
- return $footerSetting;
- }
-
- if (!empty($this->document)) {
- return $this->document->footer;
- }
-
- return setting($this->getSettingKey($this->type, 'footer'));
- }
-
- protected function getNotesSettingValue($notesSetting)
- {
- if (!empty($notesSetting)) {
- return $notesSetting;
- }
-
- if (!empty($this->document)) {
- return $this->document->notes;
- }
-
- return setting($this->getSettingKey($this->type, 'notes'));
- }
-
- protected function getSearchCharLimit($type, $searchCharLimit)
- {
- if (!empty($searchCharLimit)) {
- return $searchCharLimit;
- }
-
- // if you use settting translation
- if ($settingCharLimit = setting($this->getSettingKey($type, 'item_search_chart_limit'), false)) {
- return $settingCharLimit;
- }
-
- $hide = $this->getHideFromConfig($type, 'item_search_char_limit');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.item_search_char_limit', $searchCharLimit);
- }
-}
diff --git a/app/Abstracts/View/Components/DocumentIndex.php b/app/Abstracts/View/Components/DocumentIndex.php
deleted file mode 100644
index d042a8a1c..000000000
--- a/app/Abstracts/View/Components/DocumentIndex.php
+++ /dev/null
@@ -1,1021 +0,0 @@
-type = $type;
- $this->documents = $documents;
- $this->imageEmptyPage = $this->getImageEmptyPage($type, $imageEmptyPage);
- $this->textEmptyPage = $this->getTextEmptyPage($type, $textEmptyPage);
- $this->textPage = $this->getTextPage($type, $textPage);
- $this->urlDocsPath = $this->getUrlDocsPath($type, $urlDocsPath);
- $this->hideEmptyPage = $hideEmptyPage;
-
- /* -- Top Buttons Start -- */
- $this->checkPermissionCreate = $checkPermissionCreate;
-
- $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($type, $textDocumentNumber);
- $this->textContactName = $this->getTextContactName($type, $textContactName);
- $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
- $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->textModalDelete = $this->getTextModalDelete($type, $textModalDelete);
- $this->valueModalDelete = $valueModalDelete;
-
- $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->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
- $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
- $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
- /* -- Card Body End -- */
-
- $this->limits = ($limits) ? $limits : ['10' => '10', '25' => '25', '50' => '50', '100' => '100'];
- }
-
- protected function getImageEmptyPage($type, $imageEmptyPage)
- {
- if (!empty($imageEmptyPage)) {
- return $imageEmptyPage;
- }
-
- $image_empty_page = config('type.' . $type . '.image_empty_page');
-
- if (!empty($image_empty_page)) {
- return $image_empty_page;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
- $image_path = 'public/img/empty_pages/' . $page . '.png';
-
- if ($alias = config('type.' . $type . '.alias')) {
- $image_path = 'modules/' . Str::studly($alias) . '/Resources/assets/img/empty_pages/' . $page . '.png';
- }
-
- return $image_path;
- }
-
- protected function getTextEmptyPage($type, $textEmptyPage)
- {
- if (!empty($textEmptyPage)) {
- return $textEmptyPage;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
-
- $translation = $this->getTextFromConfig($type, 'empty_page', 'empty.' . $page);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.empty.' . $page;
- }
-
- protected function getUrlDocsPath($type, $urlDocsPath)
- {
- if (!empty($urlDocsPath)) {
- return $urlDocsPath;
- }
-
- $docs_path = config('type.' . $type . '.docs_path');
-
- if (!empty($docs_path)) {
- return $docs_path;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $docsPath = 'purchases/bills';
- break;
- default:
- $docsPath = 'sales/invoices';
- break;
- }
-
- return 'https://akaunting.com/docs/user-manual/' . $docsPath;
- }
-
- protected function getTextPage($type, $textPage)
- {
- if (!empty($textPage)) {
- return $textPage;
- }
-
- $page = str_replace('-', '_', config('type.' . $type . '.route.prefix', 'invoices'));
-
- $translation = $this->getTextFromConfig($type, 'page', $page);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.' . $page;
- }
-
- protected function getCreateRoute($type, $createRoute)
- {
- if (!empty($createRoute)) {
- return $createRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'create');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.create';
- }
-
- protected function getImportRoute($importRoute)
- {
- if (!empty($importRoute)) {
- return $importRoute;
- }
-
- $route = 'import.create';
-
- return $route;
- }
-
- protected function getImportRouteParameters($type, $importRouteParameters)
- {
- if (!empty($importRouteParameters)) {
- return $importRouteParameters;
- }
-
- $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' => $group,
- 'type' => config('type.' . $type . '.route.prefix'),
- ];
-
- return $importRouteParameters;
- }
-
- protected function getExportRoute($type, $exportRoute)
- {
- if (!empty($exportRoute)) {
- return $exportRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'export');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.export';
- }
-
- protected function getRoute($type, $formCardHeaderRoute)
- {
- if (!empty($formCardHeaderRoute)) {
- return $formCardHeaderRoute;
- }
-
- $route = $this->getRouteFromConfig($type, 'index');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.index';
- }
-
- protected function getSearchStringModel($type, $searchStringModel)
- {
- if (!empty($searchStringModel)) {
- return $searchStringModel;
- }
-
- $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;
- }
-
- protected function getTextBulkAction($type, $textBulkAction)
- {
- if (!empty($textBulkAction)) {
- return $textBulkAction;
- }
-
- $default_key = config('type.' . $type . '.translation.prefix');
-
- $translation = $this->getTextFromConfig($type, 'bulk_action', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.invoices';
- }
-
- protected function getBulkActions($type, $bulkActions, $bulkActionClass)
- {
- if (!empty($bulkActions)) {
- return $bulkActions;
- }
-
- $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)) {
- 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;
- }
-
- $group = config('type.' . $type . '.group');
-
- if (!empty(config('type.' . $type . '.alias'))) {
- $group = config('type.' . $type . '.alias');
- }
-
- $bulkActionRouteParameters = [
- 'group' => $group,
- 'type' => config('type.' . $type . '.route.prefix')
- ];
-
- return $bulkActionRouteParameters;
- }
-
- protected function getClassBulkAction($type, $classBulkAction)
- {
- if (!empty($classBulkAction)) {
- 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($type, $textDocumentNumber)
- {
- if (!empty($textDocumentNumber)) {
- return $textDocumentNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_number', 'numbers');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.numbers';
- }
-
- protected function getClassDocumentNumber($type, $classDocumentNumber)
- {
- if (!empty($classDocumentNumber)) {
- return $classDocumentNumber;
- }
-
- if ($classDocumentNumber = $this->getClass('classDocumentNumber')) {
- 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';
- }
-
- protected function getTextContactName($type, $textContactName)
- {
- if (!empty($textContactName)) {
- return $textContactName;
- }
-
- $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 'general.customers';
- }
-
- protected function getClassContactName($type, $classContactName)
- {
- if (!empty($classContactName)) {
- return $classContactName;
- }
-
- if ($classContactName = $this->getClass('classContactName')) {
- 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 long-texts';
- }
-
- protected function getClassAmount($type, $classAmount)
- {
- if (!empty($classAmount)) {
- return $classAmount;
- }
-
- if ($classAmount = $this->getClass('classAmount')) {
- 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';
- }
-
- protected function getTextIssuedAt($type, $textIssuedAt)
- {
- if (!empty($textIssuedAt)) {
- return $textIssuedAt;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getClassIssuedAt($type, $classIssuedAt)
- {
- if (!empty($classIssuedAt)) {
- return $classIssuedAt;
- }
-
- if ($classIssuedAt = $this->getClass('classIssuedAt')) {
- 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';
- }
-
- protected function getTextDueAt($type, $textDueAt)
- {
- if (!empty($textDueAt)) {
- return $textDueAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.due_date';
- }
-
- protected function getClassDueAt($type, $classDueAt)
- {
- if (!empty($classDueAt)) {
- return $classDueAt;
- }
-
- $class = $this->getClassFromConfig($type, 'due_at');
-
- if (!empty($class)) {
- return $class;
- }
-
- 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;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.');
-
- 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.';
- }
-
- protected function getClassStatus($type, $classStatus)
- {
- if (!empty($classStatus)) {
- return $classStatus;
- }
-
- if ($classStatus = $this->getClass('classStatus')) {
- 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';
- }
-
- protected function getClassActions($type, $classActions)
- {
- if (!empty($classActions)) {
- return $classActions;
- }
-
- if ($classActions = $this->getClass('classActions')) {
- 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';
- }
-
- protected function getRouteButtonShow($type, $routeButtonShow)
- {
- if (!empty($routeButtonShow)) {
- return $routeButtonShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'show', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.show';
- }
-
- protected function getRouteButtonEdit($type, $routeButtonEdit)
- {
- if (!empty($routeButtonEdit)) {
- return $routeButtonEdit;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'edit', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.edit';
- }
-
- protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
- {
- if (!empty($routeButtonDuplicate)) {
- return $routeButtonDuplicate;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'duplicate', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.duplicate';
- }
-
- protected function getRouteButtonCancelled($type, $routeButtonCancelled)
- {
- if (!empty($routeButtonCancelled)) {
- return $routeButtonCancelled;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'cancelled', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.cancelled';
- }
-
- protected function getRouteButtonDelete($type, $routeButtonDelete)
- {
- if (!empty($routeButtonDelete)) {
- return $routeButtonDelete;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'destroy', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.destroy';
- }
-
- protected function getTextModalDelete($type, $textModalDelete)
- {
- if (!empty($textModalDelete)) {
- return $textModalDelete;
- }
-
- if ($alias = config('type.' . $type . '.alias')) {
- return $alias . '::general.' . Str::plural(str_replace('-', '_', $type));
- }
-
- return '';
- }
-
- protected function getPermissionCreate($type, $permissionCreate)
- {
- if (!empty($permissionCreate)) {
- return $permissionCreate;
- }
-
- $permissionCreate = $this->getPermissionFromConfig($type, 'create');
-
- return $permissionCreate;
- }
-
- protected function getPermissionUpdate($type, $permissionUpdate)
- {
- if (!empty($permissionUpdate)) {
- return $permissionUpdate;
- }
-
- $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
-
- return $permissionUpdate;
- }
-
- protected function getPermissionDelete($type, $permissionDelete)
- {
- if (!empty($permissionDelete)) {
- return $permissionDelete;
- }
-
- $permissionDelete = $this->getPermissionFromConfig($type, 'delete');
-
- return $permissionDelete;
- }
-
- 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-3 col-xl-3 d-none d-md-block';
- $this->class_count += 2;
- break;
- case 3:
- $class = 'col-md-5 col-lg-4 col-xl-4 d-none d-md-block';
- $this->class_count += 3;
- break;
- }
- }
-
- return $class;
- }
-}
diff --git a/app/Abstracts/View/Components/DocumentShow.php b/app/Abstracts/View/Components/DocumentShow.php
deleted file mode 100644
index 211b83183..000000000
--- a/app/Abstracts/View/Components/DocumentShow.php
+++ /dev/null
@@ -1,1621 +0,0 @@
-type = $type;
- $this->document = $document;
- $this->documentTemplate = $this->getDocumentTemplate($type, $documentTemplate);
- $this->logo = $this->getLogo($logo);
- $this->backgroundColor = $backgroundColor;
- $this->signedUrl = $this->getSignedUrl($type, $signedUrl);
- $this->routePrefix = $this->getRoutePrefix($type);
-
- $this->histories = ($histories) ? $histories : $document->histories;
- $this->transactions = ($transactions) ? $transactions : $document->transactions;
-
- $this->date_format = $this->getCompanyDateFormat();
- $this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType);
- $this->textStatusMessage = $this->getTextStatusMessage($type, $textStatusMessage);
-
- $this->textHistories = $this->getTextHistories($type, $textHistories);
- $this->textHistoryStatus = $this->getTextHistoryStatus($type, $textHistoryStatus);
-
- $this->checkButtonReconciled = $checkButtonReconciled;
- $this->checkButtonCancelled = $checkButtonCancelled;
-
- $this->routeButtonAddNew = $this->getRouteButtonAddNew($type, $routeButtonAddNew);
- $this->routeButtonEdit = $this->getRouteButtonEdit($type, $routeButtonEdit);
- $this->routeButtonDuplicate = $this->getRouteButtonDuplicate($type, $routeButtonDuplicate);
- $this->routeButtonPrint = $this->getRouteButtonPrint($type, $routeButtonPrint);
- $this->routeButtonPdf = $this->getRouteButtonPdf($type, $routeButtonPdf);
- $this->routeButtonCancelled = $this->getRouteButtonCancelled($type, $routeButtonCancelled);
- $this->routeButtonCustomize = $this->getRouteButtonCustomize($type, $routeButtonCustomize);
- $this->routeButtonDelete = $this->getRouteButtonDelete($type, $routeButtonDelete);
- $this->routeButtonPaid = $this->getRouteButtonPaid($type, $routeButtonPaid);
- $this->routeContactShow = $this->getRouteContactShow($type, $routeContactShow);
-
- $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
- $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
- $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
- $this->permissionTransactionDelete = $this->getPermissionTransactionDelete($type, $permissionTransactionDelete);
- $this->permissionButtonCustomize = $this->getPermissionButtonCustomize($type, $permissionButtonCustomize);
-
- $this->hideButtonGroupDivider1 = $hideButtonGroupDivider1;
- $this->hideButtonGroupDivider2 = $hideButtonGroupDivider2;
- $this->hideButtonGroupDivider3 = $hideButtonGroupDivider3;
-
- $this->hideButtonMoreActions = $hideButtonMoreActions;
- $this->hideButtonAddNew = $hideButtonAddNew;
- $this->hideButtonEdit = $hideButtonEdit;
- $this->hideButtonDuplicate = $hideButtonDuplicate;
- $this->hideButtonPrint = $hideButtonPrint;
- $this->hideButtonPdf = $hideButtonPdf;
- $this->hideButtonCancel = $hideButtonCancel;
- $this->hideButtonCustomize = $hideButtonCustomize;
- $this->hideButtonDelete = $hideButtonDelete;
-
- $this->hideHeader = $hideHeader;
- $this->hideRecurringMessage = $hideRecurringMessage;
- $this->hideStatusMessage = $hideStatusMessage;
- $this->hideTimeline = $hideTimeline;
- $this->hideFooter = $hideFooter;
- $this->hideFooterHistories = $hideFooterHistories;
- $this->hideFooterTransactions = $hideFooterTransactions;
-
- $this->classHeaderStatus = $this->getClassHeaderStatus($type, $classHeaderStatus);
- $this->classHeaderContact = $this->getClassHeaderContact($type, $classHeaderContact);
- $this->classHeaderAmount = $this->getClassHeaderAmount($type, $classHeaderAmount);
- $this->classHeaderDueAt = $this->getClassHeaderDueAt($type, $classHeaderDueAt);
-
- $this->classFooterHistories = $this->getClassFooterHistories($type, $classFooterHistories);
- $this->classFooterTransactions = $this->getClassFooterTransactions($type, $classFooterTransactions);
-
- $this->hideHeaderStatus = $hideHeaderStatus;
- $this->hideHeaderContact = $hideHeaderContact;
- $this->hideHeaderAmount = $hideHeaderAmount;
- $this->hideHeaderDueAt = $hideHeaderDueAt;
-
- $this->textHeaderContact = $this->getTextHeaderContact($type, $textHeaderContact);
- $this->textHeaderAmount = $this->getTextHeaderAmount($type, $textHeaderAmount);
- $this->textHeaderDueAt = $this->getTextHeaderDueAt($type, $textHeaderDueAt);
-
- $this->hideTimelineStatuses = $this->getTimelineStatuses($type, $hideTimelineStatuses);
-
- $this->hideTimelineCreate = $hideTimelineCreate;
- $this->hideTimelineSent = $hideTimelineSent;
- $this->hideTimelinePaid = $hideTimelinePaid;
- $this->hideButtonSent = $hideButtonSent;
- $this->hideButtonReceived = $hideButtonReceived;
- $this->hideButtonEmail = $hideButtonEmail;
- $this->hideButtonShare = $hideButtonShare;
- $this->hideButtonPaid = $hideButtonPaid;
-
- $this->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle);
- $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading);
- $this->textTimelineCreateTitle = $this->getTextTimelineCreateTitle($type, $textTimelineCreateTitle);
- $this->textTimelineCreateMessage = $this->getTextTimelineCreateMessage($type, $textTimelineCreateMessage);
- $this->textTimelineSentTitle = $this->getTextTimelineSentTitle($type, $textTimelineSentTitle);
- $this->textTimelineSentStatusDraft = $this->getTextTimelineSentStatusDraft($type, $textTimelineSentStatusDraft);
- $this->textTimelineSentStatusMarkSent = $this->getTextTimelineSentStatusMarkSent($type, $textTimelineSentStatusMarkSent);
- $this->textTimelineSentStatusReceived = $this->getTextTimelineSentStatusReceived($type, $textTimelineSentStatusReceived);
- $this->textTimelineSendStatusMail = $this->getTextTimelineSendStatusMail($type, $textTimelineSendStatusMail);
- $this->textTimelineGetPaidTitle = $this->getTextTimelineGetPaidTitle($type, $textTimelineGetPaidTitle);
- $this->textTimelineGetPaidStatusAwait = $this->getTextTimelineGetPaidStatusAwait($type, $textTimelineGetPaidStatusAwait);
- $this->textTimelineGetPaidStatusPartiallyPaid = $this->getTextTimelineGetPaidStatusPartiallyPaid($type, $textTimelineGetPaidStatusPartiallyPaid);
- $this->textTimelineGetPaidMarkPaid = $this->getTextTimelineGetPaidMarkPaid($type, $textTimelineGetPaidMarkPaid);
- $this->textTimelineGetPaidAddPayment = $this->getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment);
-
- $this->routeButtonSent = $this->getRouteButtonSent($type, $routeButtonSent);
- $this->routeButtonReceived = $this->getRouteButtonReceived($type, $routeButtonReceived);
- $this->routeButtonEmail = $this->getRouteButtonEmail($type, $routeButtonEmail);
-
- $this->hideCompanyDetails = $hideCompanyDetails;
- $this->hideCompanyLogo = $hideCompanyLogo;
- $this->hideCompanyName = $hideCompanyName;
- $this->hideContactAddress = $hideContactAddress;
- $this->hideContactTaxNumber = $hideContactTaxNumber;
- $this->hideContactPhone = $hideContactPhone;
- $this->hideContactEmail = $hideContactEmail;
- $this->hideOrderNumber = $hideOrderNumber;
- $this->hideDocumentNumber = $hideDocumentNumber;
- $this->hideOrderNumber = $hideOrderNumber;
- $this->hideIssuedAt = $hideIssuedAt;
- $this->hideDueAt = $hideDueAt;
-
- $this->textContactInfo = $textContactInfo;
- $this->textIssuedAt = $textIssuedAt;
- $this->textDocumentNumber = $textDocumentNumber;
- $this->textDueAt = $textDueAt;
- $this->textOrderNumber = $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->hideAttachment = $hideAttachment;
-
- $this->attachment = '';
-
- if (!empty($attachment)) {
- $this->attachment = $attachment;
- } else if (!empty($document)) {
- $this->attachment = $document->attachment;
- }
-
- $this->textItems = $textItems;
- $this->textQuantity = $textQuantity;
- $this->textPrice = $textPrice;
- $this->textAmount = $textAmount;
-
- $this->textDeleteModal = $textDeleteModal;
- }
-
- protected function getTextRecurringType($type, $textRecurringType)
- {
- if (!empty($textRecurringType)) {
- return $textRecurringType;
- }
-
- $default_key = config('type.' . $type . '.translation.prefix');
-
- $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.invoices';
- }
-
- protected function getTextStatusMessage($type, $textStatusMessage)
- {
- if (!empty($textStatusMessage)) {
- return $textStatusMessage;
- }
-
- $default_key = 'messages.draft';
-
- $translation = $this->getTextFromConfig($type, 'status_message', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.messages.draft';
- }
-
- protected function getDocumentTemplate($type, $documentTemplate)
- {
- if (!empty($documentTemplate)) {
- return $documentTemplate;
- }
-
- if ($template = config('type.' . $type . 'template', false)) {
- return $template;
- }
-
- $documentTemplate = setting($this->getSettingKey($type, 'template')) ?: 'default';
-
- return $documentTemplate;
- }
-
- protected function getLogo($logo)
- {
- if (!empty($logo)) {
- return $logo;
- }
-
- $media_id = (!empty($this->document->contact->logo) && !empty($this->document->contact->logo->id)) ? $this->document->contact->logo->id : setting('company.logo');
-
- $media = Media::find($media_id);
-
- if (!empty($media)) {
- $path = $media->getDiskPath();
-
- if (Storage::missing($path)) {
- return $logo;
- }
- } else {
- $path = base_path('public/img/company.png');
- }
-
- try {
- $image = Image::cache(function($image) use ($media, $path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- if ($media) {
- $image->make(Storage::get($path))->resize($width, $height)->encode();
- } else {
- $image->make($path)->resize($width, $height)->encode();
- }
- });
- } catch (NotReadableException | \Exception $e) {
- Log::info('Company ID: ' . company_id() . ' components/documentshow.php exception.');
- Log::info($e->getMessage());
-
- $path = base_path('public/img/company.png');
-
- $image = Image::cache(function($image) use ($path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- $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 getSignedUrl($type, $signedUrl)
- {
- if (!empty($signedUrl)) {
- return $signedUrl;
- }
-
- $page = config('type.' . $type . '.route.prefix');
- $alias = config('type.' . $type . '.alias');
-
- $route = '';
-
- if (!empty($alias)) {
- $route .= $alias . '.';
- }
-
- $route .= 'signed.' . $page . '.show';
-
- try {
- route($route, [$this->document->id, 'company_id' => company_id()]);
-
- $signedUrl = URL::signedRoute($route, [$this->document->id]);
- } catch (\Exception $e) {
- $signedUrl = URL::signedRoute('signed.invoices.show', [$this->document->id]);
- }
-
- return $signedUrl;
- }
-
- protected function getTextHistories($type, $textHistories)
- {
- if (!empty($textHistories)) {
- return $textHistories;
- }
-
- $translation = $this->getTextFromConfig($type, 'histories', 'histories');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.histories';
- }
-
- protected function getTextHistoryStatus($type, $textHistoryStatus)
- {
- if (!empty($textHistoryStatus)) {
- return $textHistoryStatus;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.');
-
- 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.';
- }
-
- protected function getRouteButtonAddNew($type, $routeButtonAddNew)
- {
- if (!empty($routeButtonAddNew)) {
- return $routeButtonAddNew;
- }
-
- $route = $this->getRouteFromConfig($type, 'create');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.create';
- }
-
- protected function getRouteButtonEdit($type, $routeButtonEdit)
- {
- if (!empty($routeButtonEdit)) {
- return $routeButtonEdit;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'edit', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.edit';
- }
-
- protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
- {
- if (!empty($routeButtonDuplicate)) {
- return $routeButtonDuplicate;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'duplicate', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.duplicate';
- }
-
- protected function getRouteButtonPrint($type, $routeButtonPrint)
- {
- if (!empty($routeButtonPrint)) {
- return $routeButtonPrint;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'print', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.print';
- }
-
- protected function getRouteButtonPdf($type, $routeButtonPdf)
- {
- if (!empty($routeButtonPdf)) {
- return $routeButtonPdf;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'pdf', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.pdf';
- }
-
- protected function getRouteButtonCancelled($type, $routeButtonCancelled)
- {
- if (!empty($routeButtonCancelled)) {
- return $routeButtonCancelled;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'cancelled', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.cancelled';
- }
-
- protected function getRouteButtonCustomize($type, $routeButtonCustomize)
- {
- if (!empty($routeButtonCustomize)) {
- return $routeButtonCustomize;
- }
-
- $route = '';
-
- $alias = config('type.' . $type . '.alias');
-
- if (!empty($alias)) {
- $route .= $alias . '.';
- }
-
- $route .= 'settings.' . $type . '.edit';
-
- try {
- route($route);
- } catch (\Exception $e) {
- $route = 'settings.invoice.edit';
- }
-
- return $route;
- }
-
- protected function getRouteButtonDelete($type, $routeButtonDelete)
- {
- if (!empty($routeButtonDelete)) {
- return $routeButtonDelete;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'destroy', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.destroy';
- }
-
- protected function getRouteButtonPaid($type, $routeButtonPaid)
- {
- if (!empty($routeButtonPaid)) {
- return $routeButtonPaid;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'paid', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.paid';
- }
-
- protected function getRouteContactShow($type, $routeContactShow)
- {
- if (!empty($routeContactShow)) {
- return $routeContactShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = Str::plural(config('type.' . $type . '.contact_type'), 2) . '.show';
-
- try {
- route($route, $parameter);
- } catch (\Exception $e) {
- try {
- $route = Str::plural($type, 2) . '.' . $config_key;
-
- route($route, $parameter);
- } catch (\Exception $e) {
- $route = '';
- }
- }
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'customers.show';
- }
-
- protected function getRouteButtonSent($type, $routeButtonSent)
- {
- if (!empty($routeButtonSent)) {
- return $routeButtonSent;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'sent', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.sent';
- }
-
- protected function getRouteButtonReceived($type, $routeButtonReceived)
- {
- if (!empty($routeButtonReceived)) {
- return $routeButtonReceived;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'received', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.received';
- }
-
- protected function getRouteButtonEmail($type, $routeButtonEmail)
- {
- if (!empty($routeButtonEmail)) {
- return $routeButtonEmail;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'email', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.email';
- }
-
- protected function getPermissionCreate($type, $permissionCreate)
- {
- if (!empty($permissionCreate)) {
- return $permissionCreate;
- }
-
- $permissionCreate = $this->getPermissionFromConfig($type, 'create');
-
- return $permissionCreate;
- }
-
- protected function getPermissionUpdate($type, $permissionUpdate)
- {
- if (!empty($permissionUpdate)) {
- return $permissionUpdate;
- }
-
- $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
-
- return $permissionUpdate;
- }
-
- protected function getPermissionDelete($type, $permissionDelete)
- {
- if (!empty($permissionDelete)) {
- return $permissionDelete;
- }
-
- $permissionDelete = $this->getPermissionFromConfig($type, 'delete');
-
- return $permissionDelete;
- }
-
- protected function getPermissionTransactionDelete($type, $permissionTransactionDelete)
- {
- if (!empty($permissionTransactionDelete)) {
- return $permissionTransactionDelete;
- }
-
- $permissionTransactionDelete = 'delete-banking-transactions';
-
- return $permissionTransactionDelete;
- }
-
- protected function getPermissionButtonCustomize($type, $permissionButtonCustomize)
- {
- if (!empty($permissionButtonCustomize)) {
- return $permissionButtonCustomize;
- }
-
- $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
-
- return $permissionUpdate;
- }
-
- protected function getTextHeaderContact($type, $textHeaderContact)
- {
- if (!empty($textHeaderContact)) {
- return $textHeaderContact;
- }
-
- $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
-
- $translation = $this->getTextFromConfig($type, 'header_contact', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.customers';
- }
-
- protected function getTextHeaderAmount($type, $textHeaderAmount)
- {
- if (!empty($textHeaderAmount)) {
- return $textHeaderAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_amount', 'amount_due');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount_due';
- }
-
- protected function getTextHeaderDueAt($type, $textHeaderDueAt)
- {
- if (!empty($textHeaderDueAt)) {
- return $textHeaderDueAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_due_at', 'due_on');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.due_on';
- }
-
- protected function getClassHeaderStatus($type, $classHeaderStatus)
- {
- if (!empty($classHeaderStatus)) {
- return $classHeaderStatus;
- }
-
- $class = $this->getClassFromConfig($type, 'header_status');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-md-2';
- }
-
- protected function getClassHeaderContact($type, $classHeaderContact)
- {
- if (!empty($classHeaderContact)) {
- return $classHeaderContact;
- }
-
- $class = $this->getClassFromConfig($type, 'header_contact');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-md-6';
- }
-
- protected function getClassHeaderAmount($type, $classHeaderAmount)
- {
- if (!empty($classHeaderAmount)) {
- return $classHeaderAmount;
- }
-
- $class = $this->getClassFromConfig($type, 'header_amount');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-md-2';
- }
-
- protected function getClassHeaderDueAt($type, $classHeaderDueAt)
- {
- if (!empty($classHeaderDueAt)) {
- return $classHeaderDueAt;
- }
-
- $class = $this->getClassFromConfig($type, 'header_due_at');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-md-2';
- }
-
- protected function getClassFooterHistories($type, $classFooterHistories)
- {
- if (!empty($classFooterHistories)) {
- return $classFooterHistories;
- }
-
- $class = $this->getClassFromConfig($type, 'footer_histories');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-sm-6 col-md-6 col-lg-6 col-xl-6';
- }
-
- protected function getClassFooterTransactions($type, $classFooterTransactions)
- {
- if (!empty($classFooterTransactions)) {
- return $classFooterTransactions;
- }
-
- $class = $this->getClassFromConfig($type, 'footer_transactions');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-sm-6 col-md-6 col-lg-6 col-xl-6';
- }
-
- protected function getTimelineStatuses($type, $hideTimelineStatuses)
- {
- if (!empty($hideTimelineStatuses)) {
- return $hideTimelineStatuses;
- }
-
- $hideTimelineStatuses = ['paid', 'cancelled'];
-
- if ($timelime_statuses = config('type.' . $type . '.timeline_statuses')) {
- $hideTimelineStatuses = $timelime_statuses;
- }
-
- return $hideTimelineStatuses;
- }
-
- protected function getTextDocumentTitle($type, $textDocumentTitle)
- {
- if (!empty($textDocumentTitle)) {
- return $textDocumentTitle;
- }
-
- $key = $this->getSettingKey($type, 'title');
-
- if (!empty(setting($key))) {
- return setting($key);
- }
-
- $translation = $this->getTextFromConfig($type, 'document_title', Str::plural($type), 'trans_choice');
-
- if (!empty($translation)) {
- return trans_choice($translation, 1);
- }
-
- return setting('invoice.title');
- }
-
- protected function getTextDocumentSubheading($type, $textDocumentSubheading)
- {
- if (!empty($textDocumentSubheading)) {
- return $textDocumentSubheading;
- }
-
- $key = $this->getSettingKey($type, 'subheading');
-
- if (!empty(setting($key))) {
- return setting($key);
- }
-
- $translation = $this->getTextFromConfig($type, 'document_subheading', 'subheading');
-
- if (!empty($translation)) {
- return trans($translation);
- }
-
- return setting('invoice.subheading');
- }
-
- protected function getTextTimelineCreateTitle($type, $textTimelineCreateTitle)
- {
- if (!empty($textTimelineCreateTitle)) {
- return $textTimelineCreateTitle;
- }
-
- $default_key = 'create_' . str_replace('-', '_', $type);
-
- $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- $default_key = 'create_' . str_replace('-', '_', config('type.' . $type . '.alias'));
-
- $translation = $this->getTextFromConfig($type, 'timeline_create_title', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.create_invoice';
- }
-
- protected function getTextTimelineCreateMessage($type, $textTimelineCreateMessage)
- {
- if (!empty($textTimelineCreateMessage)) {
- return $textTimelineCreateMessage;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_create_message', 'messages.status.created');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.messages.status.created';
- }
-
- protected function getTextTimelineSentTitle($type, $textTimelineSentTitle)
- {
- if (!empty($textTimelineSentTitle)) {
- return $textTimelineSentTitle;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'receive_bill';
- break;
- default:
- $default_key = 'send_invoice';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_sent_title', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.send_invoice';
- }
-
- protected function getTextTimelineSentStatusDraft($type, $textTimelineSentStatusDraft)
- {
- if (!empty($textTimelineSentStatusDraft)) {
- return $textTimelineSentStatusDraft;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'messages.status.receive.draft';
- break;
- default:
- $default_key = 'messages.status.send.draft';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_sent_status_draft', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.messages.status.send.draft';
- }
-
- protected function getTextTimelineSentStatusMarkSent($type, $textTimelineSentStatusMarkSent)
- {
- if (!empty($textTimelineSentStatusMarkSent)) {
- return $textTimelineSentStatusMarkSent;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'mark_received';
- break;
- default:
- $default_key = 'mark_sent';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_sent_status_mark_sent', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.mark_sent';
- }
-
- protected function getTextTimelineSentStatusReceived($type, $textTimelineSentStatusReceived)
- {
- if (!empty($textTimelineSentStatusReceived)) {
- return $textTimelineSentStatusReceived;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'mark_received';
- break;
- default:
- $default_key = 'mark_sent';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_sent_status_received', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.mark_sent';
- }
-
- protected function getTextTimelineSendStatusMail($type, $textTimelineSendStatusMail)
- {
- if (!empty($textTimelineSendStatusMail)) {
- return $textTimelineSendStatusMail;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_sent_status_mail', 'send_mail');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.send_mail';
- }
-
- protected function getTextTimelineGetPaidTitle($type, $textTimelineGetPaidTitle)
- {
- if (!empty($textTimelineGetPaidTitle)) {
- return $textTimelineGetPaidTitle;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'make_payment';
- break;
- default:
- $default_key = 'get_paid';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_get_paid_title', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.get_paid';
- }
-
- protected function getTextTimelineGetPaidStatusAwait($type, $textTimelineGetPaidStatusAwait)
- {
- if (!empty($textTimelineGetPaidStatusAwait)) {
- return $textTimelineGetPaidStatusAwait;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_get_paid_status_await', 'messages.status.paid.await');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.messages.status.paid.await';
- }
-
- protected function getTextTimelineGetPaidStatusPartiallyPaid($type, $textTimelineGetPaidStatusPartiallyPaid)
- {
- if (!empty($textTimelineGetPaidStatusPartiallyPaid)) {
- return $textTimelineGetPaidStatusPartiallyPaid;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_get_paid_status_partially_paid', 'partially_paid');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.partially_paid';
- }
-
- protected function getTextTimelineGetPaidMarkPaid($type, $textTimelineGetPaidMarkPaid)
- {
- if (!empty($textTimelineGetPaidMarkPaid)) {
- return $textTimelineGetPaidMarkPaid;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_get_paid_mark_paid', 'mark_paid');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.mark_paid';
- }
-
- protected function getTextTimelineGetPaidAddPayment($type, $textTimelineGetPaidAddPayment)
- {
- if (!empty($textTimelineGetPaidAddPayment)) {
- return $textTimelineGetPaidAddPayment;
- }
-
- $translation = $this->getTextFromConfig($type, 'timeline_get_paid_add_payment', 'add_payment');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.add_payment';
- }
-
- protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
- {
- if (!empty($hideItems)) {
- return $hideItems;
- }
-
- $hide = $this->getHideFromConfig($type, 'items');
-
- if ($hide) {
- return $hide;
- }
-
- $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
-
- return $hideItems;
- }
-
- protected function getHideName($type, $hideName)
- {
- if (!empty($hideName)) {
- return $hideName;
- }
-
- // if you use settting translation
- if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
- 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)
- {
- if (!empty($hideDescription)) {
- return $hideDescription;
- }
-
- // if you use settting translation
- if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
- 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)
- {
- if (!empty($hideQuantity)) {
- return $hideQuantity;
- }
-
- // if you use settting translation
- if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
- 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)
- {
- if (!empty($hidePrice)) {
- return $hidePrice;
- }
-
- // if you use settting translation
- if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
- return $hidePrice;
- }
-
- $hide = $this->getHideFromConfig($type, 'price');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_price', $hidePrice);
- }
-
- protected function getHideDiscount($type, $hideDiscount)
- {
- if (!empty($hideDiscount)) {
- return $hideDiscount;
- }
-
- // if you use settting translation
- if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
- return $hideDiscount;
- }
-
- $hide = $this->getHideFromConfig($type, 'discount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_discount', $hideDiscount);
- }
-
- protected function getHideAmount($type, $hideAmount)
- {
- if (!empty($hideAmount)) {
- return $hideAmount;
- }
-
- // if you use settting translation
- if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
- return $hideAmount;
- }
-
- $hide = $this->getHideFromConfig($type, 'amount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_amount', $hideAmount);
- }
-
- protected function getRoutePrefix($type) {
- if ($prefix = config('type.' . $type . '.route.prefix', false)){
- return 'invoices';
- }
-
- return $prefix;
- }
-}
diff --git a/app/Abstracts/View/Components/DocumentTemplate.php b/app/Abstracts/View/Components/DocumentTemplate.php
deleted file mode 100644
index c8b44c6e3..000000000
--- a/app/Abstracts/View/Components/DocumentTemplate.php
+++ /dev/null
@@ -1,666 +0,0 @@
-type = $type;
- $this->item = $item;
- $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->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle);
- $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading);
- $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;
- }
-
- if ($template = config('type.' . $type . 'template', false)) {
- return $template;
- }
-
- $documentTemplate = setting($this->getSettingKey($type, 'template'), 'default');
-
- return $documentTemplate;
- }
-
- protected function getLogo($logo)
- {
- if (!empty($logo)) {
- return $logo;
- }
-
- $media_id = (!empty($this->document->contact->logo) && !empty($this->document->contact->logo->id)) ? $this->document->contact->logo->id : setting('company.logo');
-
- $media = Media::find($media_id);
-
- if (!empty($media)) {
- $path = $media->getDiskPath();
-
- if (Storage::missing($path)) {
- return $logo;
- }
- } else {
- $path = base_path('public/img/company.png');
- }
-
- try {
- $image = Image::cache(function($image) use ($media, $path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- if ($media) {
- $image->make(Storage::get($path))->resize($width, $height)->encode();
- } else {
- $image->make($path)->resize($width, $height)->encode();
- }
- });
- } catch (NotReadableException | \Exception $e) {
- Log::info('Company ID: ' . company_id() . ' components/documentshow.php exception.');
- Log::info($e->getMessage());
-
- $path = base_path('public/img/company.png');
-
- $image = Image::cache(function($image) use ($path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- $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;
- }
-
- if ($background_color = config('type.' . $type . 'color', false)) {
- return $background_color;
- }
-
- $backgroundColor = setting($this->getSettingKey($type, 'color'), '#55588b');
-
- return $backgroundColor;
- }
-
- protected function getTextDocumentTitle($type, $textDocumentTitle)
- {
- if (!empty($textDocumentTitle)) {
- return $textDocumentTitle;
- }
-
- $key = $this->getSettingKey($type, 'title');
-
- if (!empty(setting($key))) {
- return setting($key);
- }
-
- $translation = $this->getTextFromConfig($type, 'document_title', Str::plural($type));
-
- if (!empty($translation)) {
- return trans_choice($translation, 1);
- }
-
- return setting('invoice.title');
- }
-
- protected function getTextDocumentSubheading($type, $textDocumentSubheading)
- {
- if (!empty($textDocumentSubheading)) {
- return $textDocumentSubheading;
- }
-
- $key = $this->getSettingKey($type, 'subheading');
-
- if (!empty(setting($key))) {
- return setting($key);
- }
-
- $translation = $this->getTextFromConfig($type, 'document_subheading', 'subheading');
-
- if (!empty($translation)) {
- return trans($translation);
- }
-
- return false;
- }
-
- protected function getTextDocumentNumber($type, $textDocumentNumber)
- {
- if (!empty($textDocumentNumber)) {
- return $textDocumentNumber;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_number';
- break;
- default:
- $default_key = 'invoice_number';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'document_number', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.numbers';
- }
-
- protected function getTextOrderNumber($type, $textOrderNumber)
- {
- if (!empty($textOrderNumber)) {
- return $textOrderNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'order_number');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.order_number';
- }
-
- protected function getTextContactInfo($type, $textContactInfo)
- {
- if (!empty($textContactInfo)) {
- return $textContactInfo;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_from';
- break;
- default:
- $default_key = 'bill_to';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'contact_info', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.bill_to';
- }
-
- protected function getTextIssuedAt($type, $textIssuedAt)
- {
- if (!empty($textIssuedAt)) {
- return $textIssuedAt;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getTextDueAt($type, $textDueAt)
- {
- if (!empty($textDueAt)) {
- return $textDueAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.due_date';
- }
-
- protected function getTextItems($type, $textItems)
- {
- if (!empty($textItems)) {
- return $textItems;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'item_name'), 'items') === 'custom') {
- if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
- $textItems = 'general.items';
- }
-
- return $textItems;
- }
-
- if (setting($this->getSettingKey($type, 'item_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'item_name'))) != setting($this->getSettingKey($type, 'item_name')))
- ) {
- return setting($this->getSettingKey($type, 'item_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'items');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.items';
- }
-
- protected function getTextQuantity($type, $textQuantity)
- {
- if (!empty($textQuantity)) {
- return $textQuantity;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
- if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
- $textQuantity = 'invoices.quantity';
- }
-
- return $textQuantity;
- }
-
- if (setting($this->getSettingKey($type, 'quantity_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'quantity_name'))) != setting($this->getSettingKey($type, 'quantity_name')))
- ) {
- return setting($this->getSettingKey($type, 'quantity_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'quantity');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.quantity';
- }
-
- protected function getTextPrice($type, $textPrice)
- {
- if (!empty($textPrice)) {
- return $textPrice;
- }
-
- // if you use settting translation
- if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
- if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
- $textPrice = 'invoices.price';
- }
-
- return $textPrice;
- }
-
- if (setting($this->getSettingKey($type, 'price_name')) !== null &&
- (trans(setting($this->getSettingKey($type, 'price_name'))) != setting($this->getSettingKey($type, 'price_name')))
- ) {
- return setting($this->getSettingKey($type, 'price_name'));
- }
-
- $translation = $this->getTextFromConfig($type, 'price');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.price';
- }
-
- protected function getTextAmount($type, $textAmount)
- {
- if (!empty($textAmount)) {
- return $textAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
- {
- if (!empty($hideItems)) {
- return $hideItems;
- }
-
- $hide = $this->getHideFromConfig($type, 'items');
-
- if ($hide) {
- return $hide;
- }
-
- $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
-
- return $hideItems;
- }
-
- protected function getHideName($type, $hideName)
- {
- if (!empty($hideName)) {
- return $hideName;
- }
-
- // if you use settting translation
- if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
- 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)
- {
- if (!empty($hideDescription)) {
- return $hideDescription;
- }
-
- // if you use settting translation
- if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
- 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)
- {
- if (!empty($hideQuantity)) {
- return $hideQuantity;
- }
-
- // if you use settting translation
- if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
- 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)
- {
- if (!empty($hidePrice)) {
- return $hidePrice;
- }
-
- // if you use settting translation
- if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
- return $hidePrice;
- }
-
- $hide = $this->getHideFromConfig($type, 'price');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_price', $hidePrice);
- }
-
- protected function getHideDiscount($type, $hideDiscount)
- {
- if (!empty($hideDiscount)) {
- return $hideDiscount;
- }
-
- // if you use settting translation
- if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
- return $hideDiscount;
- }
-
- $hide = $this->getHideFromConfig($type, 'discount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_discount', $hideDiscount);
- }
-
- protected function getHideAmount($type, $hideAmount)
- {
- if (!empty($hideAmount)) {
- return $hideAmount;
- }
-
- // if you use settting translation
- if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
- return $hideAmount;
- }
-
- $hide = $this->getHideFromConfig($type, 'amount');
-
- if ($hide) {
- return $hide;
- }
-
- // @todo what return value invoice or always false??
- return setting('invoice.hide_amount', $hideAmount);
- }
-}
diff --git a/app/Abstracts/View/Components/Documents/Form.php b/app/Abstracts/View/Components/Documents/Form.php
new file mode 100644
index 000000000..44ecf1352
--- /dev/null
+++ b/app/Abstracts/View/Components/Documents/Form.php
@@ -0,0 +1,1229 @@
+type = $type;
+
+ $this->model = ! empty($model) ? $model : $document;
+ $this->document = $this->model;
+ $this->currencies = $this->getCurrencies($currencies);
+ $this->currency = $this->getCurrency($document, $currency, $currency_code);
+ $this->currency_code = ! empty($this->currency) ? $this->currency->code : setting('default.currency');
+ $this->taxes = Tax::enabled()->orderBy('name')->get()->pluck('title', 'id');
+
+ /* -- Content Start -- */
+ /* -- Form Start -- */
+ $this->formId = $formId;
+ $this->formRoute = $this->getFormRoute($type, $formRoute, $this->model);
+ $this->formMethod = $this->getFormMethod($type, $formMethod, $this->model);
+ /* -- Form End -- */
+
+ /* -- Company Start -- */
+ $this->hideCompany = $hideCompany;
+ $this->textSectionCompaniesTitle = $this->getTextSectionCompaniesTitle($type, $textSectionCompaniesTitle);
+ $this->textSectionCompaniesDescription = $this->getTextSectionCompaniesDescription($type, $textSectionCompaniesDescription);
+ $this->hideLogo = $hideLogo;
+ $this->hideDocumentTitle = $hideDocumentTitle;
+ $this->hideDocumentSubheading = $hideDocumentSubheading;
+ $this->hideCompanyEdit = $hideCompanyEdit;
+ $this->titleSetting = $this->getTitleSettingValue($type, $titleSetting);
+ $this->subheadingSetting = $this->getSubheadingSettingValue($type, $subheadingSetting);
+ /** Company End */
+
+ /* -- Main Start -- */
+ $this->textSectionMainTitle = $this->getTextSectionMainTitle($type, $textSectionMainTitle);
+ $this->textSectionMainDescription = $this->getTextSectionMainDescription($type, $textSectionMainDescription);
+
+ /* -- Metadata Start -- */
+ $this->typeContact = $this->getTypeContact($type, $typeContact);
+ $this->contact = $this->getContact($contact, $document);
+ $this->contacts = $this->getContacts($type, $document, $contacts);
+
+ $this->searchContactRoute = $this->getSearchContactRoute($type, $searchContactRoute);
+ $this->createContactRoute = $this->getCreateContactRoute($type, $createContactRoute);
+
+ $this->textContact = $this->getTextContact($type, $textContact);
+ $this->textAddContact = $this->getTextAddContact($type, $textAddContact);
+ $this->textCreateNewContact = $this->getTextCreateNewContact($type, $textCreateNewContact);
+ $this->textEditContact = $this->getTextEditContact($type, $textEditContact);
+ $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
+ $this->textChooseDifferentContact = $this->getTextChooseDifferentContact($type, $textChooseDifferentContact);
+
+ $this->hideIssuedAt = $hideIssuedAt;
+ $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
+ $this->issuedAt = $this->getIssuedAt($type, $document, $issuedAt);
+
+ $this->hideDueAt = $hideDueAt;
+ $this->textDueAt = $this->getTextDueAt($type, $textDueAt);
+ $this->dueAt = $this->getDueAt($type, $document, $dueAt);
+ $this->periodDueAt = $this->getPeriodDueAt($type, $periodDueAt);
+
+ $this->hideDocumentNumber = $hideDocumentNumber;
+ $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber);
+ $this->documentNumber = $this->getDocumentNumber($type, $document, $documentNumber);
+
+ $this->hideOrderNumber = $hideOrderNumber;
+ $this->textOrderNumber = $this->getTextOrderNumber($type, $textOrderNumber);
+ $this->orderNumber = $this->getOrderNumber($type, $document, $orderNumber);
+ /* -- Metadata End -- */
+
+ /** Items Start */
+ $this->hideEditItemColumns = $hideEditItemColumns;
+
+ $this->hideItems = $this->getHideItems($type, $hideItems, $hideItemName, $hideItemDescription);
+ $this->hideItemName = $this->getHideItemName($type, $hideItemName);
+ $this->textItemName = $this->getTextItemName($type, $textItemName);
+
+ $this->hideItemDescription = $this->getHideItemDescription($type, $hideItemDescription);
+ $this->textItemDescription = $this->getTextItemDescription($type, $textItemDescription);
+
+ $this->hideItemQuantity = $this->getHideItemQuantity($type, $hideItemQuantity);
+ $this->textItemQuantity = $this->getTextItemQuantity($type, $textItemQuantity);
+
+ $this->hideItemPrice = $this->getHideItemPrice($type, $hideItemPrice);
+ $this->textItemPrice = $this->getTextItemPrice($type, $textItemPrice);
+
+ $this->hideItemAmount = $this->getHideItemAmount($type, $hideItemAmount);
+ $this->textItemAmount = $this->getTextItemAmount($type, $textItemAmount);
+
+ $this->hideDiscount = $this->getHideDiscount($type, $hideDiscount);
+
+ $this->isSalePrice = $isSalePrice;
+ $this->isPurchasePrice = $isPurchasePrice;
+ $this->searchCharLimit = $this->getSearchCharLimit($type, $searchCharLimit);
+ /** Items End */
+
+ /** Note Start */
+ $this->note = $this->getNoteValue($note);
+ /** Note End */
+ /** Main End */
+
+ /* -- Recurring Start -- */
+ $this->showRecurring = $showRecurring;
+ /* -- Recurring End -- */
+
+ /* -- Advanced Start -- */
+ $this->hideAdvanced = $hideAdvanced;
+ $this->textSectionAdvancedTitle = $this->getTextSectionAdvancedTitle($type, $textSectionAdvancedTitle);
+ $this->textSectionAdvancedDescription = $this->getTextSectionAdvancedDescription($type, $textSectionAdvancedDescription);
+
+ $this->hideFooter = $hideFooter;
+ $this->classFooter = !empty($classFooter) ? $classFooter : 'sm:col-span-3';
+ $this->footer = $this->getFooterValue($footer);
+
+ $this->hideCategory = $hideCategory;
+ $this->classCategory = !empty($classCategory) ? $classCategory : 'sm:col-span-4 grid gap-x-8 gap-y-3';
+ $this->typeCategory = $this->getTypeCategory($type, $typeCategory);
+ $this->categoryId = $this->getCategoryId($type, $categoryId);
+
+ $this->hideAttachment = $hideAttachment;
+ $this->classAttachment = !empty($classAttachment) ? $classAttachment : 'sm:col-span-4';
+ /** Advanced End */
+
+ /** Buttons Start */
+ $this->hideButtons = $hideButtons;
+ $this->cancelRoute = $this->getCancelRoute($type, $cancelRoute);
+ $this->hideSendTo = $hideSendTo;
+ /** Buttons End */
+ /* -- Content End -- */
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ protected function getCurrencies($currencies)
+ {
+ if (!empty($currencies)) {
+ return $currencies;
+ }
+
+ return Currency::enabled()->pluck('name', 'code');
+ }
+
+ protected function getCurrency($document, $currency, $currency_code)
+ {
+ if (!empty($currency)) {
+ return $currency;
+ }
+
+ if (!empty($currency_code)) {
+ $currency = Currency::where('code', $currency_code)->first();
+ }
+
+ if (empty($currency) && !empty($document)) {
+ $currency = Currency::where('code', $document->currency_code)->first();
+ }
+
+ if (empty($currency)) {
+ $currency = Currency::where('code', setting('default.currency'))->first();
+ }
+
+ return $currency;
+ }
+
+ protected function getTextSectionCompaniesTitle($type, $textSectionCompaniesTitle)
+ {
+ if (! empty($textSectionCompaniesTitle)) {
+ return $textSectionCompaniesTitle;
+ }
+
+ return $this->getTextSectionTitle($type, 'companies', 'general.companies');
+ }
+
+ protected function getTextSectionCompaniesDescription($type, $textSectionCompaniesDescription)
+ {
+ if (! empty($textSectionCompaniesDescription)) {
+ return $textSectionCompaniesDescription;
+ }
+
+ return $this->getTextSectionDescription($type, 'companies', 'documents.form_description.companies');
+ }
+
+ protected function getTextSectionMainTitle($type, $textSectionMainTitle)
+ {
+ if (! empty($textSectionMainTitle)) {
+ return $textSectionMainTitle;
+ }
+
+ return $this->getTextSectionTitle($type, 'main', 'documents.billing');
+ }
+
+ protected function getTextSectionMainDescription($type, $textSectionMainDescription)
+ {
+ if (! empty($textSectionMainDescription)) {
+ return $textSectionMainDescription;
+ }
+
+ return $this->getTextSectionDescription($type, 'billing', 'documents.form_description.billing');
+ }
+
+ protected function getTypeContact($type, $typeContact)
+ {
+ if (! empty($typeContact)) {
+ return $typeContact;
+ }
+
+ return config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type', 'customer');
+ }
+
+ protected function getTextContact($type, $textContact)
+ {
+ if (! empty($textContact)) {
+ return $textContact;
+ }
+
+ $contact_type = config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type');
+
+ $default_key = config('type.contact.' . $contact_type . '.translation.prefix');
+
+ $translation = $this->getTextFromConfig($type, 'contact', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.customers';
+ }
+
+ protected function getContact($contact, $document)
+ {
+ if (!empty($contact)) {
+ return $contact;
+ }
+
+ $contact = new \stdClass();
+
+ if (!empty($document) && !empty($document->contact)) {
+ $contact = $document->contact;
+ }
+
+ if (request()->old('contact', false)) {
+ $contact = request()->old('contact');
+ }
+
+ return $contact;
+ }
+
+ protected function getContacts($type, $document, $contacts)
+ {
+ if (!empty($contacts)) {
+ return $contacts;
+ }
+
+ $contact_type = $this->getTypeContact($type, null);
+
+ if ($contact_type) {
+ $contacts = Contact::$contact_type()->enabled()->orderBy('name')->take(setting('default.select_limit'))->get();
+ } else {
+ $contacts = Contact::enabled()->orderBy('name')->take(setting('default.select_limit'))->get();
+ }
+
+ if (!empty($document) && ($document->contact && !$contacts->contains('id', $document->contact_id))) {
+ $contacts->push($document->contact);
+ }
+
+ return $contacts;
+ }
+
+ protected function getSearchContactRoute($type, $searchContactRoute)
+ {
+ if (! empty($searchContactRoute)) {
+ return $searchContactRoute;
+ }
+
+ $contact_type = config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type');
+
+ $default_key = config('type.contact.' . $contact_type . '.route.prefix');
+
+ return route($default_key . '.index');
+ }
+
+ protected function getCreateContactRoute($type, $createContactRoute)
+ {
+ if (! empty($createContactRoute)) {
+ return $createContactRoute;
+ }
+
+ $contact_type = config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type');
+
+ $default_key = config('type.contact.' . $contact_type . '.route.prefix');
+
+ return route('modals.' . $default_key . '.create');
+ }
+
+ protected function getTextAddContact($type, $textAddContact)
+ {
+ if (!empty($textAddContact)) {
+ return $textAddContact;
+ }
+
+ $default_key = Str::plural(config('type.document.' . $type . '.contact_type'), 2);
+
+ $translation = $this->getTextFromConfig($type, 'add_contact', $default_key, 'trans_choice');
+
+ if (!empty($translation)) {
+ return [
+ 'general.form.add',
+ $translation,
+ ];
+ }
+
+ return [
+ 'general.form.add',
+ 'general.customers',
+ ];
+ }
+
+ protected function getTextCreateNewContact($type, $textCreateNewContact)
+ {
+ if (!empty($textCreateNewContact)) {
+ return $textCreateNewContact;
+ }
+
+ /*
+ $default_key = Str::plural(config('type.document.' . $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 'general.add_new';
+ }
+
+ protected function getTextEditContact($type, $textEditContact)
+ {
+ if (!empty($textEditContact)) {
+ return $textEditContact;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'edit_contact', 'form.edit');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.form.edit';
+ }
+
+ protected function getTextContactInfo($type, $textContactInfo)
+ {
+ if (!empty($textContactInfo)) {
+ return $textContactInfo;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_from';
+ break;
+ default:
+ $default_key = 'bill_to';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'contact_info', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.bill_to';
+ }
+
+ protected function getTextChooseDifferentContact($type, $textChooseDifferentContact)
+ {
+ if (!empty($textChooseDifferentContact)) {
+ return $textChooseDifferentContact;
+ }
+
+ $default_key = Str::plural(config('type.document.' . $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 [
+ 'general.form.choose_different',
+ 'general.customers',
+ ];
+ }
+
+ protected function getTextIssuedAt($type, $textIssuedAt)
+ {
+ if (!empty($textIssuedAt)) {
+ return $textIssuedAt;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getIssuedAt($type, $document, $issuedAt)
+ {
+ if (!empty($issuedAt)) {
+ return $issuedAt;
+ }
+
+ if ($document) {
+ return $document->issued_at;
+ }
+
+ $issued_at = $type . '_at';
+
+ if (request()->has($issued_at)) {
+ $issuedAt = request()->get($issued_at);
+ } else {
+ $issuedAt = request()->get('invoice_at', Date::now()->toDateString());
+ }
+
+ return $issuedAt;
+ }
+
+ protected function getTextDueAt($type, $textDueAt)
+ {
+ if (!empty($textDueAt)) {
+ return $textDueAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.due_date';
+ }
+
+ protected function getDueAt($type, $document, $dueAt)
+ {
+ if (!empty($dueAt)) {
+ return $dueAt;
+ }
+
+ if ($document) {
+ return $document->due_at;
+ }
+
+ $issued_at = $type . '_at';
+
+ if (request()->has($issued_at)) {
+ $issuedAt = request()->get($issued_at);
+ } else {
+ $issuedAt = Date::now()->toDateString();
+ }
+
+ $addDays = setting($this->getSettingKey($type, 'payment_terms'), 0) ?: 0;
+
+ $dueAt = Date::parse($issuedAt)->addDays($addDays)->toDateString();
+
+ return $dueAt;
+ }
+
+ protected function getPeriodDueAt($type, $periodDueAt)
+ {
+ if (! empty($periodDueAt)) {
+ return $periodDueAt;
+ }
+
+ return setting($type. '.payment_terms', 0);
+ }
+
+ protected function getTextDocumentNumber($type, $textDocumentNumber)
+ {
+ if (! empty($textDocumentNumber)) {
+ return $textDocumentNumber;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_number';
+ break;
+ default:
+ $default_key = 'invoice_number';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_number', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_number';
+ }
+
+ protected function getDocumentNumber($type, $document, $documentNumber)
+ {
+ if (! empty($documentNumber)) {
+ return $documentNumber;
+ }
+
+ if ($document) {
+ return $document->document_number;
+ }
+
+ $document_number = $this->getNextDocumentNumber($type);
+
+ if (empty($document_number)) {
+ $document_number = $this->getNextDocumentNumber(Document::INVOICE_TYPE);
+ }
+
+ return $document_number;
+ }
+
+ protected function getTextOrderNumber($type, $textOrderNumber)
+ {
+ if (! empty($textOrderNumber)) {
+ return $textOrderNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'order_number');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.order_number';
+ }
+
+ protected function getOrderNumber($type, $document, $orderNumber)
+ {
+ if (! empty($orderNumber)) {
+ return $orderNumber;
+ }
+
+ if ($document) {
+ return $document->order_number;
+ }
+
+ $order_number = null;
+ }
+
+ protected function getHideItems($type, $hideItems, $hideItemName, $hideItemDescription)
+ {
+ if (! empty($hideItems)) {
+ return $hideItems;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'items');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ $hideItems = ($this->getHideItemName($type, $hideItemName) & $this->getHideItemDescription($type, $hideItemDescription)) ? true : false;
+
+ return $hideItems;
+ }
+
+ protected function getHideItemName($type, $hideItemName)
+ {
+ if (! empty($hideItemName)) {
+ return $hideItemName;
+ }
+
+ // if you use settting translation
+ if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
+ 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 getTextItemName($type, $textItemName)
+ {
+ if (! empty($textItemName)) {
+ return $textItemName;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'item_name'), 'items') === 'custom') {
+ if (empty($textItemName = setting($this->getSettingKey($type, 'item_name_input')))) {
+ $textItemName = 'general.items';
+ }
+
+ return $textItemName;
+ }
+
+ if (setting($this->getSettingKey($type, 'item_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'item_name'))) != setting($this->getSettingKey($type, 'item_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'item_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'items');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.items';
+ }
+
+ protected function getHideItemDescription($type, $hideItemDescription)
+ {
+ if (! empty($hideItemDescription)) {
+ return $hideItemDescription;
+ }
+
+ // if you use settting translation
+ if ($hideItemDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
+ return $hideItemDescription;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'description');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_item_description', $hideItemDescription);
+ }
+
+ protected function getTextItemDescription($type, $textItemDescription)
+ {
+ if (! empty($textItemDescription)) {
+ return $textItemDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'description');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.description';
+ }
+
+ protected function getHideItemQuantity($type, $hideItemQuantity)
+ {
+ if (! empty($hideItemQuantity)) {
+ return $hideItemQuantity;
+ }
+
+ // if you use settting translation
+ if ($hideItemQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
+ return $hideItemQuantity;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'quantity');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_quantity', $hideItemQuantity);
+ }
+
+ protected function getTextItemQuantity($type, $textItemQuantity)
+ {
+ if (! empty($textItemQuantity)) {
+ return $textItemQuantity;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
+ if (empty($textItemQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
+ $textItemQuantity = 'invoices.quantity';
+ }
+
+ return $textItemQuantity;
+ }
+
+ if (setting($this->getSettingKey($type, 'quantity_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'quantity_name'))) != setting($this->getSettingKey($type, 'quantity_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'quantity_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'quantity');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.quantity';
+ }
+
+ protected function getHideItemPrice($type, $hideItemPrice)
+ {
+ if (! empty($hideItemPrice)) {
+ return $hideItemPrice;
+ }
+
+ // if you use settting translation
+ if ($hideItemPrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
+ return $hideItemPrice;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'price');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_price', $hideItemPrice);
+ }
+
+ protected function getTextItemPrice($type, $textItemPrice)
+ {
+ if (! empty($textItemPrice)) {
+ return $textItemPrice;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
+ if (empty($textItemPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
+ $textItemPrice = 'invoices.price';
+ }
+
+ return $textItemPrice;
+ }
+
+ if (setting($this->getSettingKey($type, 'price_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'price_name'))) != setting($this->getSettingKey($type, 'price_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'price_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'price');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.price';
+ }
+
+ protected function getHideItemAmount($type, $hideItemAmount)
+ {
+ if (! empty($hideItemAmount)) {
+ return $hideItemAmount;
+ }
+
+ // if you use settting translation
+ if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
+ return $hideAmount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'amount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_amount', $hideAmount);
+ }
+
+ protected function getTextItemAmount($type, $textItemAmount)
+ {
+ if (!empty($textItemAmount)) {
+ return $textItemAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'amount');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getHideDiscount($type, $hideDiscount)
+ {
+ if (! empty($hideDiscount)) {
+ return $hideDiscount;
+ }
+
+ // if you use settting translation
+ if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
+ return $hideDiscount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'discount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_discount', $hideDiscount);
+ }
+
+ protected function getSearchCharLimit($type, $searchCharLimit)
+ {
+ if (! empty($searchCharLimit)) {
+ return $searchCharLimit;
+ }
+
+ // if you use settting translation
+ if ($settingCharLimit = setting($this->getSettingKey($type, 'item_search_chart_limit'), false)) {
+ return $settingCharLimit;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'item_search_char_limit');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.item_search_char_limit', $searchCharLimit);
+ }
+
+ protected function getNoteValue($note)
+ {
+ if (! empty($note)) {
+ return $note;
+ }
+
+ if (! empty($this->document)) {
+ return $this->document->notes;
+ }
+
+ return setting($this->getSettingKey($this->type, 'note'));
+ }
+
+ protected function getTextSectionAdvancedTitle($type, $textSectionAdvancedTitle)
+ {
+ if (! empty($textSectionAdvancedTitle)) {
+ return $textSectionAdvancedTitle;
+ }
+
+ return $this->getTextSectionTitle($type, 'advanced', 'documents.advanced');
+ }
+
+ protected function getTextSectionAdvancedDescription($type, $textSectionAdvancedDescription)
+ {
+ if (! empty($textSectionAdvancedDescription)) {
+ return $textSectionAdvancedDescription;
+ }
+
+ return $this->getTextSectionDescription($type, 'advanced', 'documents.form_description.advanced');
+ }
+
+ protected function getTitleSettingValue($type, $titleSetting)
+ {
+ if (! empty($titleSetting)) {
+ return $titleSetting;
+ }
+
+ return setting($this->getSettingKey($type, 'title'));
+ }
+
+ protected function getSubheadingSettingValue($type, $subheadingSetting)
+ {
+ if (! empty($subheadingSetting)) {
+ return $subheadingSetting;
+ }
+
+ return setting($this->getSettingKey($type, 'subheading'));
+ }
+
+ protected function getFooterValue($footer)
+ {
+ if (! empty($footer)) {
+ return $footer;
+ }
+
+ if (! empty($this->document)) {
+ return $this->document->footer;
+ }
+
+ return setting($this->getSettingKey($this->type, 'footer'));
+ }
+
+ protected function getTypeCategory($type, $typeCategory)
+ {
+ if (!empty($typeCategory)) {
+ return $typeCategory;
+ }
+
+ if ($category_type = config('type.' . static::OBJECT_TYPE . '.' . $type . '.category_type')) {
+ return $category_type;
+ }
+
+ // set default type
+ $type = Document::INVOICE_TYPE;
+
+ return config('type.' . static::OBJECT_TYPE .'.' . $type . '.category_type');
+ }
+
+ protected function getCategoryId($type, $categoryId)
+ {
+ if (!empty($categoryId)) {
+ return $categoryId;
+ }
+
+ if (! empty($this->document) && ! empty($this->document->category_id)) {
+ return $this->document->category_id;
+ }
+
+ return setting('default.' . $this->typeCategory . '_category');
+ }
+}
diff --git a/app/Abstracts/View/Components/Documents/Index.php b/app/Abstracts/View/Components/Documents/Index.php
new file mode 100644
index 000000000..2fd3cda5d
--- /dev/null
+++ b/app/Abstracts/View/Components/Documents/Index.php
@@ -0,0 +1,642 @@
+type = $type;
+ $this->alias = $this->getAlias($type, $alias);
+ $this->documents = ($documents) ? $documents : collect();
+ $this->group = $this->getGroup($type, $group);
+ $this->page = $this->getPage($type, $page);
+ $this->textTabDocument = $this->getTextTabDocument($type, $textTabDocument);
+ $this->textPage = $this->getTextPage($type, $textPage);
+
+ $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
+ $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
+ $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
+
+ $this->routeTabDocument = $this->getRouteTabDocument($type, $routeTabDocument);
+ $this->routeTabRecurring = $this->getRouteTabRecurring($type, $routeTabRecurring);
+ /* -- Main End -- */
+
+ /* -- Buttons Start -- */
+ $this->hideAcceptPayment = $hideAcceptPayment;
+
+ $this->checkPermissionCreate = $checkPermissionCreate;
+
+ $this->hideCreate = $hideCreate;
+ $this->hideImport = $hideImport;
+ $this->hideExport = $hideExport;
+
+ $this->createRoute = $this->getCreateRoute($type, $createRoute);
+ $this->importRoute = $this->getImportRoute($importRoute);
+ $this->importRouteParameters = $this->getImportRouteParameters($type, $importRouteParameters);
+ $this->exportRoute = $this->getExportRoute($type, $exportRoute);
+ /* -- Buttons End -- */
+
+ /* -- Content Start -- */
+ /* -- Empty Page Start -- */
+ $this->hideEmptyPage = $hideEmptyPage;
+
+ $this->emptyPageButtons = $this->getEmptyPageButtons($type, $emptyPageButtons);
+ $this->imageEmptyPage = $this->getImageEmptyPage($type, $imageEmptyPage);
+ $this->textEmptyPage = $this->getTextEmptyPage($type, $textEmptyPage);
+ $this->urlDocsPath = $this->getUrlDocsPath($type, $urlDocsPath);
+ /* -- Empty Page End -- */
+
+ /* -- Summary Start -- */
+ $this->hideSummary = $hideSummary;
+ $this->summaryItems = $this->getSummaryItems($type, $summaryItems);
+ /* -- Sumamry End -- */
+
+ /* Container Start */
+ $this->withoutTabs = $withoutTabs;
+ $this->tabActive = $this->getTabActive($type, $tabActive);
+
+ $this->hideRecurringTemplates = $hideRecurringTemplates;
+
+ $this->hideSearchString = $hideSearchString;
+ $this->hideBulkAction = $hideBulkAction;
+
+ $this->searchStringModel = $this->getSearchStringModel($type, $searchStringModel);
+
+ $this->bulkActionClass = $this->getBulkActionClass($type, $bulkActionClass);
+ $this->bulkActionRouteParameters = $this->getBulkActionRouteParameters($type, $bulkActionRouteParameters);
+
+ $this->searchRoute = $this->getIndexRoute($type, $searchRoute);
+
+ $this->classBulkAction = $this->getClassBulkAction($type, $classBulkAction);
+
+ /* Document Start */
+ $this->hideDueAt = $hideDueAt;
+ $this->hideIssuedAt = $hideIssuedAt;
+ $this->classDueAtAndIssueAt = $this->getClassDueAtAndIssueAt($type, $classDueAtAndIssueAt);
+ $this->textDueAt = $this->getTextDueAt($type, $textDueAt);
+ $this->textIssuedAt = $this->getTextIssuedAt($type, $textIssuedAt);
+
+ $this->hideStatus = $hideStatus;
+ $this->classStatus = $this->getClassStatus($type, $classStatus);
+
+ $this->hideContactName = $hideContactName;
+ $this->hideDocumentNumber = $hideDocumentNumber;
+ $this->classContactNameAndDocumentNumber = $this->getClassContactNameAndDocumentNumber($type, $classContactNameAndDocumentNumber);
+ $this->textContactName = $this->getTextContactName($type, $textContactName);
+ $this->showContactRoute = $this->getShowContactRoute($type, $showContactRoute);
+ $this->textDocumentNumber = $this->getTextDocumentNumber($type, $textDocumentNumber);
+
+ $this->hideAmount = $hideAmount;
+ $this->classAmount = $this->getClassAmount($type, $classAmount);
+
+ $this->hideShow = $hideShow;
+ $this->showRoute = $this->getShowRoute($type, $showRoute);
+
+ $this->hideEdit = $hideEdit;
+ $this->editRoute = $this->getEditRoute($type, $editRoute);
+
+ $this->hideDuplicate = $hideDuplicate;
+ $this->duplicateRoute = $this->getDuplicateRoute($type, $duplicateRoute);
+
+ $this->textDocumentStatus = $this->getTextDocumentStatus($type, $textDocumentStatus);
+
+ $this->checkButtonReconciled = $checkButtonReconciled;
+ $this->checkButtonCancelled = $checkButtonCancelled;
+ /* Document End */
+ /* Container End */
+ /* -- Content End -- */
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ protected function getEmptyPageButtons($type, $emptyPageButtons)
+ {
+ if (! empty($emptyPageButtons)) {
+ return $emptyPageButtons;
+ }
+
+ $prefix = config('type.' . static::OBJECT_TYPE . '.' . $type . '.route.prefix', 'invoices');
+
+ $buttons = [];
+
+ if (! $this->hideCreate) {
+ $route = $this->getRouteFromConfig($type, 'create');
+
+ $buttons[] = [
+ 'permission' => $this->permissionCreate,
+ 'url' => route($this->createRoute),
+ 'text' => trans('general.title.new', ['type' => trans_choice($this->textPage ?? 'general.' . $prefix, 1)]),
+ 'description' => trans('general.empty.actions.new', ['type' => strtolower(trans_choice($this->textPage ?? 'general.' . $prefix, 1))]),
+ 'active_badge' => true,
+ ];
+ }
+
+ if (! $this->hideImport) {
+ $route = $this->getRouteFromConfig($type, 'import');
+
+ $buttons[] = [
+ 'permission' => $this->permissionCreate,
+ 'url' => route($this->importRoute, $this->importRouteParameters),
+ 'text' => trans('import.title', ['type' => trans_choice($this->textPage ?? 'general.' . $prefix, 1)]),
+ 'description' => trans('general.empty.actions.import', ['type' => strtolower(trans_choice($this->textPage ?? 'general.' . $prefix, 1))]),
+ ];
+ }
+
+ return $buttons;
+ }
+
+ public function getSummaryItems($type, $summaryItems)
+ {
+ if (! empty($summaryItems)) {
+ return $summaryItems;
+ }
+
+ $route = $this->getIndexRoute($type, null);
+
+ $totals = $this->getTotalsForFutureDocuments($type);
+
+ $items = [];
+
+ foreach ($totals as $key => $total) {
+ $title = ($key == 'overdue') ? trans('general.overdue') : trans('documents.statuses.' . $key);
+ $href = route($route, ['search' => 'status:' . $key]);
+ $amount = money($total, setting('default.currency'), true);
+
+ $items[] = [
+ 'title' => $title,
+ 'href' => $href,
+ 'amount' => $amount,
+ ];
+ }
+
+ return $items;
+ }
+
+ protected function getTextTabDocument($type, $textTabDocument)
+ {
+ if (! empty($textTabDocument)) {
+ return $textTabDocument;
+ }
+
+ $default_key = config('type.' . static::OBJECT_TYPE . '.' . $type . '.translation.prefix');
+
+ $translation = $this->getTextFromConfig($type, 'tab_document', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.invoices';
+ }
+
+ public function getTabActive($type, $tabActive)
+ {
+ if (! empty($tabActive)) {
+ return $tabActive;
+ }
+
+ return $type;
+ }
+
+ protected function getRouteTabDocument($type, $routeTabDocument)
+ {
+ if (! empty($routeTabDocument)) {
+ return $routeTabDocument;
+ }
+
+ $route = $this->getRouteFromConfig($type, 'document', 'invoices');
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.index';
+ }
+
+ protected function getRouteTabRecurring($type, $routeTabDocument)
+ {
+ if (! empty($routeTabDocument)) {
+ return $routeTabDocument;
+ }
+
+ $route = $this->getRouteFromConfig($type, 'recurring', 'recurring-invoices');
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'recurring-invoices.index';
+ }
+
+ protected function getClassDueAtAndIssueAt($type, $classDueAtAndIssueAt)
+ {
+ if (! empty($classDueAtAndIssueAt)) {
+ return $classDueAtAndIssueAt;
+ }
+
+ $class = $this->getClassFromConfig($type, 'due_at_and_issue_at');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-4/12 table-title hidden sm:table-cell';
+ }
+
+ protected function getTextDueAt($type, $textDueAt)
+ {
+ if (! empty($textDueAt)) {
+ return $textDueAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.due_date';
+ }
+
+ protected function getTextIssuedAt($type, $textIssuedAt)
+ {
+ if (! empty($textIssuedAt)) {
+ return $textIssuedAt;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getClassStatus($type, $classStatus)
+ {
+ if (! empty($classStatus)) {
+ return $classStatus;
+ }
+
+ $class = $this->getClassFromConfig($type, 'status');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-3/12 table-title hidden sm:table-cell';
+ }
+
+ protected function getClassContactNameAndDocumentNumber($type, $classContactNameAndDocumentNumber)
+ {
+ if (! empty($classContactNameAndDocumentNumber)) {
+ return $classContactNameAndDocumentNumber;
+ }
+
+ $class = $this->getClassFromConfig($type, 'contact_name');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-6/12 sm:w-3/12 table-title';
+ }
+
+ protected function getTextContactName($type, $textContactName)
+ {
+ if (! empty($textContactName)) {
+ return $textContactName;
+ }
+
+ $default_key = Str::plural(config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type'), 2);
+
+ $translation = $this->getTextFromConfig($type, 'contact_name', $default_key, 'trans_choice');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.customers';
+ }
+
+ protected function getShowContactRoute($type, $showContactRoute)
+ {
+ if (! empty($showContactRoute)) {
+ return $showContactRoute;
+ }
+
+
+ if (! empty($showRoute)) {
+ return $showRoute;
+ }
+
+ $route = $this->getRouteFromConfig($type, 'contact.show', 1);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ $default_key = Str::plural(config('type.' . static::OBJECT_TYPE . '.' . $type . '.contact_type'), 2);
+
+ return $default_key . '.show';
+ }
+
+ 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';
+ }
+
+ protected function getClassAmount($type, $classAmount)
+ {
+ if (! empty($classAmount)) {
+ return $classAmount;
+ }
+
+ $class = $this->getClassFromConfig($type, 'amount');
+
+ if (! empty($class)) {
+ return $class;
+ }
+
+ return 'w-6/12 sm:w-2/12';
+ }
+
+ protected function getTextDocumentStatus($type, $textDocumentStatus)
+ {
+ if (! empty($textDocumentStatus)) {
+ return $textDocumentStatus;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_status', 'statuses.');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ $alias = config('type.' . static::OBJECT_TYPE . '.' . $type . '.alias');
+
+ if (! empty($alias)) {
+ $translation = $alias . '::' . config('type.' . static::OBJECT_TYPE . '.' . $type . '.translation.prefix') . '.statuses';
+
+ if (is_array(trans($translation))) {
+ return $translation . '.';
+ }
+ }
+
+ return 'documents.statuses.';
+ }
+}
diff --git a/app/Abstracts/View/Components/Documents/Show.php b/app/Abstracts/View/Components/Documents/Show.php
new file mode 100644
index 000000000..412df24cd
--- /dev/null
+++ b/app/Abstracts/View/Components/Documents/Show.php
@@ -0,0 +1,1352 @@
+type = $type;
+ $this->document = $document;
+ $this->transactions = ($transactions) ? $transactions : $document->transactions;
+
+ $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
+ $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
+ $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
+ /* -- Main End -- */
+
+ /* -- Buttons Start -- */
+ $this->hideCreate = $hideCreate;
+ $this->createRoute = $this->getCreateRoute($type, $createRoute);
+ $this->textCreate = $this->getTextCreate($type, $textCreate);
+
+ $this->hideButtonStatuses = $this->getHideButtonStatuses($type, $hideButtonStatuses);
+ $this->hideEdit = $hideEdit;
+ $this->editRoute = $this->getEditRoute($type, $editRoute);
+
+ $this->hideMoreActions = $hideMoreActions;
+ $this->hideDuplicate = $hideDuplicate;
+ $this->duplicateRoute = $this->getDuplicateRoute($type, $duplicateRoute);
+
+ $this->hidePrint = $hidePrint;
+ $this->checkCancelled = $checkCancelled;
+ $this->printRoute = $this->getPrintRoute($type, $printRoute);
+
+ $this->hideShare = $hideShare;
+ $this->shareRoute = $this->getShareRoute($type, $shareRoute);
+ $this->signedUrl = $this->getSignedUrl($type, $signedUrl);
+
+ $this->hideEmail = $hideEmail;
+ $this->emailRoute = $this->getEmailRoute($type, $emailRoute);
+ $this->textEmail = $this->getTextEmail($type, $textEmail);
+
+ $this->hidePdf = $hidePdf;
+ $this->pdfRoute = $this->getPdfRoute($type, $pdfRoute);
+
+ $this->hideCancel = $hideCancel;
+ $this->cancelledRoute = $this->getCancelledRoute($type, $cancelledRoute);
+
+ $this->hideCustomize = $hideCustomize;
+ $this->permissionCustomize = $this->getPermissionCustomize($type, $permissionCustomize);
+ $this->customizeRoute = $this->getCustomizeRoute($type, $customizeRoute);
+
+ $this->hideEnd = $hideEnd;
+ $this->endRoute = $this->getEndRoute($type, $endRoute);
+
+ $this->hideDelete = $hideDelete;
+ $this->checkReconciled = $checkReconciled;
+ $this->deleteRoute = $this->getDeleteRoute($type, $deleteRoute);
+ $this->textDeleteModal = $textDeleteModal;
+
+ $this->hideDivider1 = $hideDivider1;
+ $this->hideDivider2 = $hideDivider2;
+ $this->hideDivider3 = $hideDivider3;
+ $this->hideDivider4 = $hideDivider4;
+ /* -- Buttons End -- */
+
+ /* -- Content Start -- */
+ $this->accordionActive = $this->getAccordionActive($type, $accordionActive);
+ $this->hideRecurringMessage = $hideRecurringMessage;
+ $this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType);
+
+ $this->hideStatusMessage = $hideStatusMessage;
+ $this->textStatusMessage = $this->getTextStatusMessage($type, $textStatusMessage);
+
+ $this->hideCreated = $hideCreated;
+
+ $this->hideSend = $hideSend;
+ $this->hideMarkSent = $hideMarkSent;
+ $this->textMarkSent = $this->getTextMarkSent($type, $textMarkSent);
+ $this->markSentRoute = $this->getMarkSentRoute($type, $markSentRoute);
+
+ $this->hideReceive = $hideReceive;
+ $this->hideMarkReceived = $hideMarkReceived;
+ $this->textMarkReceived = $this->getTextMarkReceived($type, $textMarkReceived);
+ $this->markReceivedRoute = $this->getMarkReceivedRoute($type, $markReceivedRoute);
+
+ $this->hideGetPaid = $hideGetPaid;
+
+ $this->hideAddPayment = $hideAddPayment;
+ $this->hideAcceptPayment = $hideAcceptPayment;
+
+ $this->transactionEmailRoute = $this->getTransactionEmailRoute($type, $transactionEmailRoute);
+
+ $this->hideRestore = $this->getHideRestore($hideRestore);
+
+ $this->hideMakePayment = $hideMakePayment;
+
+ $this->hideSchedule = $hideSchedule;
+ $this->hideChildren = $hideChildren;
+
+ $this->hideAttachment = $hideAttachment;
+ $this->attachment = '';
+
+ if (! empty($attachment)) {
+ $this->attachment = $attachment;
+ } else if (! empty($document)) {
+ $this->attachment = $document->attachment;
+ }
+ /* -- Content End -- */
+
+ /* -- Template Start -- */
+ $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->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle);
+ $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading);
+ $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);
+ /* -- Template End -- */
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ protected function getTextCreate($type, $textCreate)
+ {
+ if (! empty($textCreate)) {
+ return $textCreate;
+ }
+
+ return trans('general.new') . ' ' . ucfirst($type);
+ }
+
+ protected function getHideButtonStatuses($type, $hideButtonStatuses)
+ {
+ if (! empty($hideButtonStatuses)) {
+ return $hideButtonStatuses;
+ }
+
+ $hideButtonStatuses = ['paid', 'cancelled'];
+
+ if ($button_statuses = config('type.' . static::OBJECT_TYPE . '.' . $type . '.button_statuses')) {
+ $hideButtonStatuses = $button_statuses;
+ }
+
+ return $hideButtonStatuses;
+ }
+
+ protected function getPrintRoute($type, $printRoute)
+ {
+ if (! empty($printRoute)) {
+ return $printRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'print', $parameter);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.print';
+ }
+
+ protected function getShareRoute($type, $shareRoute)
+ {
+ if (! empty($shareRoute)) {
+ return $shareRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'share', $parameter, true);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'modals.invoices.share.create';
+ }
+
+ protected function getSignedUrl($type, $signedUrl)
+ {
+ if (! empty($signedUrl)) {
+ return $signedUrl;
+ }
+
+ $page = config('type.' . static::OBJECT_TYPE . '.' . $type . '.route.prefix');
+ $alias = config('type.' . static::OBJECT_TYPE . '.' . $type . '.alias');
+
+ $route = '';
+
+ if (! empty($alias)) {
+ $route .= $alias . '.';
+ }
+
+ $route .= 'signed.' . $page . '.show';
+
+ try {
+ route($route, [$this->document->id, 'company_id' => company_id()]);
+
+ $signedUrl = URL::signedRoute($route, [$this->document->id]);
+ } catch (\Exception $e) {
+ $signedUrl = URL::signedRoute('signed.invoices.show', [$this->document->id]);
+ }
+
+ return $signedUrl;
+ }
+
+ protected function getEmailRoute($type, $emailRoute)
+ {
+ if (! empty($emailRoute)) {
+ return $emailRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'emails.create', $parameter, true);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'modals.invoices.emails.create';
+ }
+
+ protected function getTextEmail($type, $textEmail)
+ {
+ if (! empty($textEmail)) {
+ return $textEmail;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'send_mail', 'send_mail');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.send_mail';
+ }
+
+ protected function getPdfRoute($type, $pdfRoute)
+ {
+ if (! empty($pdfRoute)) {
+ return $pdfRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'pdf', $parameter);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.pdf';
+ }
+
+ protected function getCancelledRoute($type, $cancelledRoute)
+ {
+ if (! empty($cancelledRoute)) {
+ return $cancelledRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'cancelled', $parameter);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.cancelled';
+ }
+
+ protected function getPermissionCustomize($type, $permissionCustomize)
+ {
+ if (! empty($permissionCustomize)) {
+ return $permissionCustomize;
+ }
+
+ $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
+
+ return $permissionUpdate;
+ }
+
+ protected function getCustomizeRoute($type, $customizeRoute)
+ {
+ if (!empty($customizeRoute)) {
+ return $customizeRoute;
+ }
+
+ $route = '';
+
+ $alias = config('type.' . static::OBJECT_TYPE . '.' . $type . '.alias');
+
+ if (!empty($alias)) {
+ $route .= $alias . '.';
+ }
+
+ $route .= 'settings.' . $type . '.edit';
+
+ try {
+ route($route);
+ } catch (\Exception $e) {
+ $route = 'settings.invoice.edit';
+ }
+
+ return $route;
+ }
+
+ protected function getEndRoute($type, $endButton)
+ {
+ if (!empty($endButton)) {
+ return $endButton;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'end', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'recurring-invoices.end';
+ }
+
+ protected function getAccordionActive($type, $accordionActive)
+ {
+ if (! empty($accordionActive)) {
+ return $accordionActive;
+ }
+
+ $status_workflow = $alias = config('type.' . static::OBJECT_TYPE . '.' . $type . '.status_workflow');
+
+ $status = false;
+
+ if (! empty($status_workflow[$this->document->status])) {
+ $status = $status_workflow[$this->document->status];
+ }
+
+ return $status;
+ }
+
+ protected function getTextRecurringType($type, $textRecurringType)
+ {
+ if (! empty($textRecurringType)) {
+ return $textRecurringType;
+ }
+
+ $default_key = config('type.' . static::OBJECT_TYPE . '.' . $type . '.translation.prefix');
+
+ $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.invoices';
+ }
+
+ protected function getTextStatusMessage($type, $textStatusMessage)
+ {
+ if (! empty($textStatusMessage)) {
+ return $textStatusMessage;
+ }
+
+ $default_key = 'messages.draft';
+
+ $translation = $this->getTextFromConfig($type, 'status_message', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.messages.draft';
+ }
+
+ protected function getTextMarkSent($type, $textMarkSent)
+ {
+ if (! empty($textMarkSent)) {
+ return $textMarkSent;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'mark_received';
+ break;
+ default:
+ $default_key = 'mark_sent';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'mark_sent', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.mark_sent';
+ }
+
+ protected function getMarkSentRoute($type, $markSentRoute)
+ {
+ if (! empty($markSentRoute)) {
+ return $markSentRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'sent', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.sent';
+ }
+
+ protected function getTextMarkReceived($type, $textMarkReceived)
+ {
+ if (! empty($textMarkReceived)) {
+ return $textMarkReceived;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'mark_received';
+ break;
+ default:
+ $default_key = 'mark_sent';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'mark_received', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'bills.mark_received';
+ }
+
+ protected function getMarkReceivedRoute($type, $markReceivedRoute)
+ {
+ if (! empty($markReceivedRoute)) {
+ return $markReceivedRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'received', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'bills.received';
+ }
+
+ protected function getTransactionEmailRoute($type, $transactionEmailRoute)
+ {
+ if (! empty($transactionEmailRoute)) {
+ return $transactionEmailRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'transaction_email', $parameter);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'modals.transactions.emails.create';
+ }
+
+ protected function getHideRestore($hideRestore)
+ {
+ if (! empty($hideRestore)) {
+ return $hideRestore;
+ }
+
+ $hideRestore = true;
+
+ if ($this->document->status == 'cancelled') {
+ $hideRestore = false;
+ }
+
+ return $hideRestore;
+ }
+
+ protected function getDocumentTemplate($type, $documentTemplate)
+ {
+ if (! empty($documentTemplate)) {
+ return $documentTemplate;
+ }
+
+ if ($template = config('type.' . static::OBJECT_TYPE . '.' . $type . '.template', false)) {
+ return $template;
+ }
+
+ $documentTemplate = setting($this->getSettingKey($type, 'template'), 'default');
+
+ return $documentTemplate;
+ }
+
+ protected function getLogo($logo)
+ {
+ if (! empty($logo)) {
+ return $logo;
+ }
+
+ $media_id = (! empty($this->document->contact->logo) && ! empty($this->document->contact->logo->id)) ? $this->document->contact->logo->id : setting('company.logo');
+
+ $media = Media::find($media_id);
+
+ if (! empty($media)) {
+ $path = $media->getDiskPath();
+
+ if (Storage::missing($path)) {
+ return $logo;
+ }
+ } else {
+ $path = base_path('public/img/company.png');
+ }
+
+ try {
+ $image = Image::cache(function($image) use ($media, $path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ if ($media) {
+ $image->make(Storage::get($path))->resize($width, $height)->encode();
+ } else {
+ $image->make($path)->resize($width, $height)->encode();
+ }
+ });
+ } catch (NotReadableException | \Exception $e) {
+ Log::info('Company ID: ' . company_id() . ' components/documentshow.php exception.');
+ Log::info($e->getMessage());
+
+ $path = base_path('public/img/company.png');
+
+ $image = Image::cache(function($image) use ($path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ $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;
+ }
+
+ if ($background_color = config('type.' . static::OBJECT_TYPE . '.' . $type . '.color', false)) {
+ return $background_color;
+ }
+
+ if (! empty($alias = config('type.' . static::OBJECT_TYPE . '.' . $type . '.alias'))) {
+ $type = $alias . '.' . str_replace('-', '_', $type);
+ }
+
+ $backgroundColor = setting($this->getSettingKey($type, 'color'), '#55588b');
+
+ return $backgroundColor;
+ }
+
+ protected function getTextDocumentTitle($type, $textDocumentTitle)
+ {
+ if (! empty($textDocumentTitle)) {
+ return $textDocumentTitle;
+ }
+
+ $key = $this->getSettingKey($type, 'title');
+
+ if (! empty(setting($key))) {
+ return setting($key);
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_title', Str::plural($type));
+
+ if (! empty($translation)) {
+ return trans_choice($translation, 1);
+ }
+
+ return setting('invoice.title');
+ }
+
+ protected function getTextDocumentSubheading($type, $textDocumentSubheading)
+ {
+ if (! empty($textDocumentSubheading)) {
+ return $textDocumentSubheading;
+ }
+
+ $key = $this->getSettingKey($type, 'subheading');
+
+ if (!empty(setting($key))) {
+ return setting($key);
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_subheading', 'subheading');
+
+ if (! empty($translation)) {
+ return trans($translation);
+ }
+
+ return false;
+ }
+
+ protected function getTextDocumentNumber($type, $textDocumentNumber)
+ {
+ if (! empty($textDocumentNumber)) {
+ return $textDocumentNumber;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_number';
+ break;
+ default:
+ $default_key = 'invoice_number';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_number', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextOrderNumber($type, $textOrderNumber)
+ {
+ if (! empty($textOrderNumber)) {
+ return $textOrderNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'order_number');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.order_number';
+ }
+
+ protected function getTextContactInfo($type, $textContactInfo)
+ {
+ if (! empty($textContactInfo)) {
+ return $textContactInfo;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_from';
+ break;
+ default:
+ $default_key = 'bill_to';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'contact_info', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.bill_to';
+ }
+
+ protected function getTextIssuedAt($type, $textIssuedAt)
+ {
+ if (! empty($textIssuedAt)) {
+ return $textIssuedAt;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getTextDueAt($type, $textDueAt)
+ {
+ if (! empty($textDueAt)) {
+ return $textDueAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.due_date';
+ }
+
+ protected function getTextItems($type, $textItems)
+ {
+ if (! empty($textItems)) {
+ return $textItems;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'item_name'), 'items') == 'custom') {
+ if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
+ $textItems = 'general.items';
+ }
+
+ return $textItems;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'items');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.items';
+ }
+
+ protected function getTextQuantity($type, $textQuantity)
+ {
+ if (! empty($textQuantity)) {
+ return $textQuantity;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
+ if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
+ $textQuantity = 'invoices.quantity';
+ }
+
+ return $textQuantity;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'quantity');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.quantity';
+ }
+
+ protected function getTextPrice($type, $textPrice)
+ {
+ if (!empty($textPrice)) {
+ return $textPrice;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
+ if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
+ $textPrice = 'invoices.price';
+ }
+
+ return $textPrice;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'price');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.price';
+ }
+
+ protected function getTextAmount($type, $textAmount)
+ {
+ if (! empty($textAmount)) {
+ return $textAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'amount');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
+ {
+ if (! empty($hideItems)) {
+ return $hideItems;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'items');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
+
+ return $hideItems;
+ }
+
+ protected function getHideName($type, $hideName)
+ {
+ if (! empty($hideName)) {
+ return $hideName;
+ }
+
+ // if you use settting translation
+ if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
+ 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)
+ {
+ if (! empty($hideDescription)) {
+ return $hideDescription;
+ }
+
+ // if you use settting translation
+ if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
+ 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)
+ {
+ if (! empty($hideQuantity)) {
+ return $hideQuantity;
+ }
+
+ // if you use settting translation
+ if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
+ 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)
+ {
+ if (! empty($hidePrice)) {
+ return $hidePrice;
+ }
+
+ // if you use settting translation
+ if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
+ return $hidePrice;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'price');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_price', $hidePrice);
+ }
+
+ protected function getHideDiscount($type, $hideDiscount)
+ {
+ if (! empty($hideDiscount)) {
+ return $hideDiscount;
+ }
+
+ // if you use settting translation
+ if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
+ return $hideDiscount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'discount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_discount', $hideDiscount);
+ }
+
+ protected function getHideAmount($type, $hideAmount)
+ {
+ if (! empty($hideAmount)) {
+ return $hideAmount;
+ }
+
+ // if you use settting translation
+ if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
+ return $hideAmount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'amount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_amount', $hideAmount);
+ }
+}
diff --git a/app/Abstracts/View/Components/Documents/Template.php b/app/Abstracts/View/Components/Documents/Template.php
new file mode 100644
index 000000000..2934fb50b
--- /dev/null
+++ b/app/Abstracts/View/Components/Documents/Template.php
@@ -0,0 +1,679 @@
+type = $type;
+ $this->item = $item;
+ $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->textDocumentTitle = $this->getTextDocumentTitle($type, $textDocumentTitle);
+ $this->textDocumentSubheading = $this->gettextDocumentSubheading($type, $textDocumentSubheading);
+ $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);
+
+ // Set Parent data
+ //$this->setParentData();
+ }
+
+ protected function getDocumentTemplate($type, $documentTemplate)
+ {
+ if (! empty($documentTemplate)) {
+ return $documentTemplate;
+ }
+
+ if ($template = config('type.document.' . $type . '.template', false)) {
+ return $template;
+ }
+
+ $documentTemplate = setting($this->getSettingKey($type, 'template'), 'default');
+
+ return $documentTemplate;
+ }
+
+ protected function getLogo($logo)
+ {
+ if (! empty($logo)) {
+ return $logo;
+ }
+
+ $media_id = (! empty($this->document->contact->logo) && ! empty($this->document->contact->logo->id)) ? $this->document->contact->logo->id : setting('company.logo');
+
+ $media = Media::find($media_id);
+
+ if (! empty($media)) {
+ $path = $media->getDiskPath();
+
+ if (Storage::missing($path)) {
+ return $logo;
+ }
+ } else {
+ $path = base_path('public/img/company.png');
+ }
+
+ try {
+ $image = Image::cache(function($image) use ($media, $path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ if ($media) {
+ $image->make(Storage::get($path))->resize($width, $height)->encode();
+ } else {
+ $image->make($path)->resize($width, $height)->encode();
+ }
+ });
+ } catch (NotReadableException | \Exception $e) {
+ Log::info('Company ID: ' . company_id() . ' components/documentshow.php exception.');
+ Log::info($e->getMessage());
+
+ $path = base_path('public/img/company.png');
+
+ $image = Image::cache(function($image) use ($path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ $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;
+ }
+
+ if ($background_color = config('type.document.' . $type . '.color', false)) {
+ return $background_color;
+ }
+
+
+ if (! empty($alias = config('type.document.' . $type . '.alias'))) {
+ $type = $alias . '.' . str_replace('-', '_', $type);
+ }
+
+ $backgroundColor = setting($this->getSettingKey($type, 'color'), '#55588b');
+
+ return $backgroundColor;
+ }
+
+ protected function getTextDocumentTitle($type, $textDocumentTitle)
+ {
+ if (! empty($textDocumentTitle)) {
+ return $textDocumentTitle;
+ }
+
+ $key = $this->getSettingKey($type, 'title');
+
+ if (! empty(setting($key))) {
+ return setting($key);
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_title', Str::plural($type));
+
+ if (! empty($translation)) {
+ return trans_choice($translation, 1);
+ }
+
+ return setting('invoice.title');
+ }
+
+ protected function getTextDocumentSubheading($type, $textDocumentSubheading)
+ {
+ if (! empty($textDocumentSubheading)) {
+ return $textDocumentSubheading;
+ }
+
+ $key = $this->getSettingKey($type, 'subheading');
+
+ if (! empty(setting($key))) {
+ return setting($key);
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_subheading', 'subheading');
+
+ if (! empty($translation)) {
+ return trans($translation);
+ }
+
+ return false;
+ }
+
+ protected function getTextDocumentNumber($type, $textDocumentNumber)
+ {
+ if (! empty($textDocumentNumber)) {
+ return $textDocumentNumber;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_number';
+ break;
+ default:
+ $default_key = 'invoice_number';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'document_number', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextOrderNumber($type, $textOrderNumber)
+ {
+ if (! empty($textOrderNumber)) {
+ return $textOrderNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'order_number');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.order_number';
+ }
+
+ protected function getTextContactInfo($type, $textContactInfo)
+ {
+ if (! empty($textContactInfo)) {
+ return $textContactInfo;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_from';
+ break;
+ default:
+ $default_key = 'bill_to';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'contact_info', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.bill_to';
+ }
+
+ protected function getTextIssuedAt($type, $textIssuedAt)
+ {
+ if (! empty($textIssuedAt)) {
+ return $textIssuedAt;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'issued_at', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getTextDueAt($type, $textDueAt)
+ {
+ if (! empty($textDueAt)) {
+ return $textDueAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'due_at', 'due_date');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.due_date';
+ }
+
+ protected function getTextItems($type, $textItems)
+ {
+ if (! empty($textItems)) {
+ return $textItems;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'item_name'), 'items') === 'custom') {
+ if (empty($textItems = setting($this->getSettingKey($type, 'item_name_input')))) {
+ $textItems = 'general.items';
+ }
+
+ return $textItems;
+ }
+
+ if (setting($this->getSettingKey($type, 'item_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'item_name'))) != setting($this->getSettingKey($type, 'item_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'item_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'items');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.items';
+ }
+
+ protected function getTextQuantity($type, $textQuantity)
+ {
+ if (! empty($textQuantity)) {
+ return $textQuantity;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'quantity_name'), 'quantity') === 'custom') {
+ if (empty($textQuantity = setting($this->getSettingKey($type, 'quantity_name_input')))) {
+ $textQuantity = 'invoices.quantity';
+ }
+
+ return $textQuantity;
+ }
+
+ if (setting($this->getSettingKey($type, 'quantity_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'quantity_name'))) != setting($this->getSettingKey($type, 'quantity_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'quantity_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'quantity');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.quantity';
+ }
+
+ protected function getTextPrice($type, $textPrice)
+ {
+ if (! empty($textPrice)) {
+ return $textPrice;
+ }
+
+ // if you use settting translation
+ if (setting($this->getSettingKey($type, 'price_name'), 'price') === 'custom') {
+ if (empty($textPrice = setting($this->getSettingKey($type, 'price_name_input')))) {
+ $textPrice = 'invoices.price';
+ }
+
+ return $textPrice;
+ }
+
+ if (setting($this->getSettingKey($type, 'price_name')) !== null
+ && (trans(setting($this->getSettingKey($type, 'price_name'))) != setting($this->getSettingKey($type, 'price_name')))
+ ) {
+ return setting($this->getSettingKey($type, 'price_name'));
+ }
+
+ $translation = $this->getTextFromConfig($type, 'price');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.price';
+ }
+
+ protected function getTextAmount($type, $textAmount)
+ {
+ if (! empty($textAmount)) {
+ return $textAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'amount');
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getHideItems($type, $hideItems, $hideName, $hideDescription)
+ {
+ if (! empty($hideItems)) {
+ return $hideItems;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'items');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ $hideItems = ($this->getHideName($type, $hideName) & $this->getHideDescription($type, $hideDescription)) ? true : false;
+
+ return $hideItems;
+ }
+
+ protected function getHideName($type, $hideName)
+ {
+ if (! empty($hideName)) {
+ return $hideName;
+ }
+
+ // if you use settting translation
+ if ($hideName = setting($this->getSettingKey($type, 'hide_item_name'), false)) {
+ 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)
+ {
+ if (! empty($hideDescription)) {
+ return $hideDescription;
+ }
+
+ // if you use settting translation
+ if ($hideDescription = setting($this->getSettingKey($type, 'hide_item_description'), false)) {
+ 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)
+ {
+ if (! empty($hideQuantity)) {
+ return $hideQuantity;
+ }
+
+ // if you use settting translation
+ if ($hideQuantity = setting($this->getSettingKey($type, 'hide_quantity'), false)) {
+ 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)
+ {
+ if (! empty($hidePrice)) {
+ return $hidePrice;
+ }
+
+ // if you use settting translation
+ if ($hidePrice = setting($this->getSettingKey($type, 'hide_price'), false)) {
+ return $hidePrice;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'price');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_price', $hidePrice);
+ }
+
+ protected function getHideDiscount($type, $hideDiscount)
+ {
+ if (! empty($hideDiscount)) {
+ return $hideDiscount;
+ }
+
+ // if you use settting translation
+ if ($hideDiscount = setting($this->getSettingKey($type, 'hide_discount'), false)) {
+ return $hideDiscount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'discount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_discount', $hideDiscount);
+ }
+
+ protected function getHideAmount($type, $hideAmount)
+ {
+ if (! empty($hideAmount)) {
+ return $hideAmount;
+ }
+
+ // if you use settting translation
+ if ($hideAmount = setting($this->getSettingKey($type, 'hide_amount'), false)) {
+ return $hideAmount;
+ }
+
+ $hide = $this->getHideFromConfig($type, 'amount');
+
+ if ($hide) {
+ return $hide;
+ }
+
+ // @todo what return value invoice or always false??
+ return setting('invoice.hide_amount', $hideAmount);
+ }
+}
diff --git a/app/Abstracts/View/Components/Form.php b/app/Abstracts/View/Components/Form.php
new file mode 100644
index 000000000..aed1573eb
--- /dev/null
+++ b/app/Abstracts/View/Components/Form.php
@@ -0,0 +1,307 @@
+type = $this->getType($type);
+ $this->name = $this->getName($name);
+ $this->label = $label;
+ $this->id = $id ?? $name;
+ $this->value = $this->getValue($value, $valueKey);
+ $this->placeholder = $this->getPlaceholder($placeholder);
+ $this->rows = $rows;
+
+ $this->remote = $remote;
+ $this->multiple = $multiple;
+ $this->addNew = $addNew;
+ $this->group = $group;
+
+ $this->disabled = $disabled;
+ $this->readonly = $readonly;
+ $this->required = $this->getRequired($required, $notRequired);
+
+ $this->options = $this->getOptions($options);
+ $this->option = $option;
+ $this->optionKey = $optionKey;
+ $this->optionValue = $optionValue;
+ $this->checked = $this->getChecked($checked, $checkedKey);
+ $this->selected = $this->getSelected($selected, $selectedKey);
+
+ $this->formGroupClass = $this->getFromGroupClass($formGroupClass);
+ $this->inputGroupClass = $this->getInputGroupClass($inputGroupClass);
+
+ $this->custom_attributes = $this->getCustomAttributes();
+
+ $this->setDynamicAttributes($dynamicAttributes);
+ }
+
+ protected function getType($type)
+ {
+ if (! empty($type) && (! empty($this->type) && $type != 'text')) {
+ return $type;
+ }
+
+ if (! empty($this->type)) {
+ return $this->type;
+ }
+ }
+
+ protected function getName($name)
+ {
+ if (! empty($name)) {
+ return $name;
+ }
+
+ return $this->name;
+ }
+
+ protected function getValue($value, $valueKey)
+ {
+ if ($value != '') {
+ return $value;
+ }
+
+ if (empty($valueKey)) {
+ $valueKey = $this->name;
+ }
+
+ if (empty($valueKey)) {
+ return '';
+ }
+
+ // set model value.
+ $model = $this->getParentData('model');
+
+ $value_keys = explode('.', $valueKey);
+
+ if (count($value_keys) > 1) {
+ $valueKey = $value_keys[0];
+ }
+
+ if (! empty($model->{$valueKey})) {
+ $value = $model->{$valueKey};
+ }
+
+ if ($model instanceof Collection) {
+ $value = $model->get($valueKey);
+ }
+
+ if (count($value_keys) > 1) {
+ $value = $value[0]->{$value_keys[1]};
+ }
+
+ if (empty($value) && request()->has($valueKey)) {
+ $value = request()->get($valueKey);
+ }
+
+ return old($valueKey, $value);
+ }
+
+ protected function getPlaceholder($placeholder)
+ {
+ if (! empty($placeholder)) {
+ return $placeholder;
+ }
+
+ $label = $this->label;
+
+ if (! empty($this->label) && ! empty($this->label->contents)) {
+ $label = $this->name;
+ }
+
+ return trans('general.form.enter', ['field' => $label]);
+ }
+
+ protected function getOptions($options)
+ {
+ if (! empty($options)) {
+ if (is_array($options) && ! $this->group) {
+ $o = collect();
+
+ foreach ($options as $key => $value) {
+ if (is_array($value)) {
+ $o->push((object) $value);
+ } else {
+ $o->push((object) [
+ 'id' => $key,
+ 'name' => $value,
+ ]);
+ }
+ }
+
+ $options = $o;
+ }
+
+ return $options;
+ }
+
+ return [];
+ }
+
+ protected function getChecked($checked, $checkedKey)
+ {
+ return $this->getValue($checked, $checkedKey);
+ }
+
+ protected function getSelected($selected, $selectedKey)
+ {
+ return $this->getValue($selected, $selectedKey);
+ }
+
+ protected function getRequired($required, $notRequired)
+ {
+ if (! empty($notRequired)) {
+ return false;
+ }
+
+ return $required;
+ }
+
+ protected function getFromGroupClass($formGroupClass)
+ {
+ if (! empty($formGroupClass)) {
+ return $formGroupClass;
+ }
+
+ return $this->formGroupClass;
+ }
+
+ protected function getInputGroupClass($inputGroupClass)
+ {
+ if (! empty($inputGroupClass)) {
+ return $inputGroupClass;
+ }
+
+ return $this->inputGroupClass;
+ }
+
+ protected function getCustomAttributes()
+ {
+ $attributes = [];
+
+ if (! empty($this->required)) {
+ $attributes['required'] = $this->required;
+ }
+
+ if (! empty($this->disabled)) {
+ $attributes['disabled'] = $this->disabled;
+ }
+
+ if (! empty($this->readonly)) {
+ $attributes['readonly'] = $this->readonly;
+ }
+
+ foreach ($this->custom_attributes as $key => $value) {
+ $attributes[$key] = $value;
+ }
+
+ return $attributes;
+ }
+
+ protected function setDynamicAttributes($dynamicAttributes)
+ {
+ if (! empty($dynamicAttributes)) {
+ $this->dynamicAttributes = $dynamicAttributes;
+ }
+ }
+}
diff --git a/app/Abstracts/View/Components/Transaction.php b/app/Abstracts/View/Components/Transaction.php
deleted file mode 100644
index 4174533cc..000000000
--- a/app/Abstracts/View/Components/Transaction.php
+++ /dev/null
@@ -1,175 +0,0 @@
- $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;
- }
-}
diff --git a/app/Abstracts/View/Components/TransactionShow.php b/app/Abstracts/View/Components/TransactionShow.php
deleted file mode 100644
index 21b41d650..000000000
--- a/app/Abstracts/View/Components/TransactionShow.php
+++ /dev/null
@@ -1,1312 +0,0 @@
-type = $type;
- $this->transaction = $transaction;
- $this->transactionTemplate = $this->getTransactionTemplate($type, $transactionTemplate);
- $this->logo = $this->getLogo($logo);
- $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
- $this->date_format = $this->getCompanyDateFormat();
- $this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType);
- $this->hideRecurringMessage = $hideRecurringMessage;
- $this->routePrefix = $this->getRoutePrefix($type);
-
- // Navbar Hide
- $this->hideButtonAddNew = $hideButtonAddNew;
- $this->hideButtonMoreActions = $hideButtonMoreActions;
- $this->hideButtonEdit = $hideButtonEdit;
- $this->hideButtonDuplicate = $hideButtonDuplicate;
- $this->hideButtonPrint = $hideButtonPrint;
- $this->hideButtonShare = $hideButtonShare;
- $this->hideButtonEmail = $hideButtonEmail;
- $this->hideButtonPdf = $hideButtonPdf;
- $this->hideButtonDelete = $hideButtonDelete;
- $this->checkButtonReconciled = $checkButtonReconciled;
- $this->hideButtonGroupDivider1 = $hideButtonGroupDivider1;
- $this->hideButtonGroupDivider2 = $hideButtonGroupDivider2;
- $this->hideButtonGroupDivider3 = $hideButtonGroupDivider3;
-
- // Navbar Permission
- $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
- $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
- $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
-
- // Navbar route
- $this->routeButtonAddNew = $this->getRouteButtonAddNew($type, $routeButtonAddNew);
- $this->routeButtonEdit = $this->getRouteButtonEdit($type, $routeButtonEdit);
- $this->routeButtonDuplicate = $this->getRouteButtonDuplicate($type, $routeButtonDuplicate);
- $this->routeButtonPrint = $this->getRouteButtonPrint($type, $routeButtonPrint);
- $this->signedUrl = $this->getSignedUrl($type, $signedUrl);
- $this->routeButtonEmail = $this->getRouteButtonEmail($type, $routeButtonEmail);
- $this->routeButtonPdf = $this->getRouteButtonPdf($type, $routeButtonPdf);
- $this->routeButtonDelete = $this->getRouteButtonDelete($type, $routeButtonDelete);
- $this->routeContactShow = $this->getRouteContactShow($type, $routeContactShow);
-
- // Navbar Text
- $this->textDeleteModal = $textDeleteModal;
-
- // Header Hide
- $this->hideHeader = $hideHeader;
-
- $this->hideHeaderAccount = $hideHeaderAccount;
- $this->hideHeaderCategory = $hideHeaderCategory;
- $this->hideHeaderContact = $hideHeaderContact;
- $this->hideHeaderCategory = $hideHeaderCategory;
- $this->hideHeaderAmount = $hideHeaderAmount;
- $this->hideHeaderPaidAt = $hideHeaderPaidAt;
-
- // Header Text
- $this->textHeaderAccount = $this->getTextHeaderAccount($type, $textHeaderAccount);
- $this->textHeaderCategory = $this->getTextHeaderCategory($type, $textHeaderCategory);
- $this->textHeaderContact = $this->getTextHeaderContact($type, $textHeaderContact);
- $this->textHeaderAmount = $this->getTextHeaderAmount($type, $textHeaderAmount);
- $this->textHeaderPaidAt = $this->gettextHeaderPaidAt($type, $textHeaderPaidAt);
-
- // Header Class
- $this->classHeaderAccount = $this->getClassHeaderAccount($type, $classHeaderAccount);
- $this->classHeaderContact = $this->getClassHeaderContact($type, $classHeaderContact);
- $this->classHeaderCategory = $this->getClassHeaderCategory($type, $classHeaderCategory);
- $this->classHeaderAmount = $this->getClassHeaderAmount($type, $classHeaderAmount);
- $this->classHeaderPaidAt = $this->getClassHeaderPaidAt($type, $classHeaderPaidAt);
-
- // Hide Attachment
- $this->hideAttachment = $hideAttachment;
-
- // Company Information Hide checker
- $this->hideCompany = $hideCompany;
- $this->hideCompanyLogo = $hideCompanyLogo;
- $this->hideCompanyDetails = $hideCompanyDetails;
- $this->hideCompanyName = $hideCompanyName;
- $this->hideCompanyAddress = $hideCompanyAddress;
- $this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
- $this->hideCompanyPhone = $hideCompanyPhone;
- $this->hideCompanyEmail = $hideCompanyEmail;
-
- // Transaction Information Hide checker
- $this->hideContentTitle = $hideContentTitle;
- $this->hidePaidAt = $hidePaidAt;
- $this->hideAccount = $hideAccount;
- $this->hideCategory = $hideCategory;
- $this->hidePaymentMethods = $hidePaymentMethods;
- $this->hideReference = $hideReference;
- $this->hideDescription = $hideDescription;
- $this->hideAmount = $hideAmount;
-
- // Transaction Information Text
- $this->textContentTitle = $this->getTextContentTitle($type, $textContentTitle);
- $this->textPaidAt = $this->getTextPaidAt($type, $textPaidAt);
- $this->textAccount = $this->getTextAccount($type, $textAccount);
- $this->textCategory = $this->getTextCategory($type, $textCategory);
- $this->textPaymentMethods = $this->getTextPaymentMethods($type, $textPaymentMethods);
- $this->textReference = $this->getTextReference($type, $textReference);
- $this->textDescription = $this->getTextDescription($type, $textDescription);
- $this->textAmount = $this->getTextAmount($type, $textAmount);
- $this->textPaidBy = $this->getTextPaidBy($type, $textPaidBy);
-
- // Contact Information Hide checker
- $this->hideContact = $hideContact;
- $this->hideContactInfo = $hideContactInfo;
- $this->hideContactName = $hideContactName;
- $this->hideContactAddress = $hideContactAddress;
- $this->hideContactTaxNumber = $hideContactTaxNumber;
- $this->hideContactPhone = $hideContactPhone;
- $this->hideContactEmail = $hideContactEmail;
-
- // Related Information Hide checker
- $this->hideRelated = $hideRelated;
- $this->hideRelatedDocumentNumber = $hideRelatedDocumentNumber;
- $this->hideRelatedContact = $hideRelatedContact;
- $this->hideRelatedDocumentDate = $hideRelatedDocumentDate;
- $this->hideRelatedDocumentAmount = $hideRelatedDocumentAmount;
- $this->hideRelatedAmount = $hideRelatedAmount;
-
- // Related Information Text
- $this->textRelatedTransansaction = $this->getTextRelatedTransansaction($type, $textRelatedTransansaction);
- $this->textRelatedDocumentNumber = $this->getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber);
- $this->textRelatedContact = $this->getTextRelatedContact($type, $textRelatedContact);
- $this->textRelatedDocumentDate = $this->getTextRelatedDocumentDate($type, $textRelatedDocumentDate);
- $this->textRelatedDocumentAmount = $this->getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount);
- $this->textRelatedAmount = $this->getTextRelatedAmount($type, $textRelatedAmount);
-
- $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow);
-
- // Attachment data..
- $this->attachment = '';
-
- if (!empty($attachment)) {
- $this->attachment = $attachment;
- } else if (!empty($transaction)) {
- $this->attachment = $transaction->attachment;
- }
-
- // Histories Hide
- $this->hideFooter = $hideFooter;
- $this->hideFooterHistories = $hideFooterHistories;
-
- // Histories
- $this->histories = $this->getHistories($histories);
- $this->textHistories = $this->getTextHistories($type, $textHistories);
- $this->classFooterHistories = $this->getClassFooterHistories($type, $classFooterHistories);
- }
-
- protected function getTransactionTemplate($type, $transactionTemplate)
- {
- if (!empty($transactionTemplate)) {
- return $transactionTemplate;
- }
-
- if ($template = config('type.' . $type . 'template', false)) {
- return $template;
- }
-
- $transactionTemplate = setting($this->getSettingKey($type, 'template')) ?: 'default';
-
- return $transactionTemplate;
- }
-
- protected function getLogo($logo)
- {
- if (!empty($logo)) {
- return $logo;
- }
-
- $media_id = (!empty($this->transaction->contact->logo) && !empty($this->transaction->contact->logo->id)) ? $this->transaction->contact->logo->id : setting('company.logo');
-
- $media = Media::find($media_id);
-
- if (!empty($media)) {
- $path = $media->getDiskPath();
-
- if (Storage::missing($path)) {
- return $logo;
- }
- } else {
- $path = base_path('public/img/company.png');
- }
-
- try {
- $image = Image::cache(function($image) use ($media, $path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- if ($media) {
- $image->make(Storage::get($path))->resize($width, $height)->encode();
- } else {
- $image->make($path)->resize($width, $height)->encode();
- }
- });
- } catch (NotReadableException | \Exception $e) {
- Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.');
- Log::info($e->getMessage());
-
- $path = base_path('public/img/company.png');
-
- $image = Image::cache(function($image) use ($path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- $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 getRouteButtonAddNew($type, $routeButtonAddNew)
- {
- if (!empty($routeButtonAddNew)) {
- return $routeButtonAddNew;
- }
-
- $route = $this->getRouteFromConfig($type, 'create');
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.create';
- }
-
- protected function getRouteButtonEdit($type, $routeButtonEdit)
- {
- if (!empty($routeButtonEdit)) {
- return $routeButtonEdit;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'edit', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.edit';
- }
-
- protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
- {
- if (!empty($routeButtonDuplicate)) {
- return $routeButtonDuplicate;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'duplicate', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.duplicate';
- }
-
- protected function getRouteButtonPrint($type, $routeButtonPrint)
- {
- if (!empty($routeButtonPrint)) {
- return $routeButtonPrint;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'print', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.print';
- }
-
- protected function getSignedUrl($type, $signedUrl)
- {
- if (!empty($signedUrl)) {
- return $signedUrl;
- }
-
- $page = config('type.' . $type . '.route.prefix');
- $alias = config('type.' . $type . '.alias');
-
- $route = '';
-
- if (!empty($alias)) {
- $route .= $alias . '.';
- }
-
- $route .= 'signed.' . $page . '.show';
-
- try {
- route($route, [$this->transaction->id, 'company_id' => company_id()]);
-
- $signedUrl = URL::signedRoute($route, [$this->transaction->id]);
- } catch (\Exception $e) {
- $signedUrl = URL::signedRoute('signed.payments.show', [$this->transaction->id]);
- }
-
- return $signedUrl;
- }
-
- protected function getRouteButtonEmail($type, $routeButtonEmail)
- {
- if (!empty($routeButtonEmail)) {
- return $routeButtonEmail;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'email', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.email';
- }
-
- protected function getRouteButtonPdf($type, $routeButtonPdf)
- {
- if (!empty($routeButtonPdf)) {
- return $routeButtonPdf;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'pdf', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.pdf';
- }
-
- protected function getRouteButtonDelete($type, $routeButtonDelete)
- {
- if (!empty($routeButtonDelete)) {
- return $routeButtonDelete;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($type, 'destroy', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'revenues.destroy';
- }
-
- protected function getRouteContactShow($type, $routeContactShow)
- {
- if (!empty($routeContactShow)) {
- return $routeContactShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = Str::plural(config('type.' . $type . '.contact_type'), 2) . '.show';
-
- try {
- route($route, $parameter);
- } catch (\Exception $e) {
- try {
- $route = Str::plural($type, 2) . '.' . $config_key;
-
- route($route, $parameter);
- } catch (\Exception $e) {
- $route = '';
- }
- }
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'customers.show';
- }
-
- protected function getPermissionCreate($type, $permissionCreate)
- {
- if (!empty($permissionCreate)) {
- return $permissionCreate;
- }
-
- $permissionCreate = $this->getPermissionFromConfig($type, 'create');
-
- return $permissionCreate;
- }
-
- protected function getPermissionUpdate($type, $permissionUpdate)
- {
- if (!empty($permissionUpdate)) {
- return $permissionUpdate;
- }
-
- $permissionUpdate = $this->getPermissionFromConfig($type, 'update');
-
- return $permissionUpdate;
- }
-
- protected function getPermissionDelete($type, $permissionDelete)
- {
- if (!empty($permissionDelete)) {
- return $permissionDelete;
- }
-
- $permissionDelete = $this->getPermissionFromConfig($type, 'delete');
-
- return $permissionDelete;
- }
-
- protected function getTextHeaderAccount($type, $textHeaderAccount)
- {
- if (!empty($textHeaderAccount)) {
- return $textHeaderAccount;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_account', 'accounts', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.accounts';
- }
-
- protected function getTextHeaderCategory($type, $textHeaderCategory)
- {
- if (!empty($textHeaderCategory)) {
- return $textHeaderCategory;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_category', 'categories', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.categories';
- }
-
- protected function getTextHeaderContact($type, $textHeaderContact)
- {
- if (!empty($textHeaderContact)) {
- return $textHeaderContact;
- }
-
- $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
-
- $translation = $this->getTextFromConfig($type, 'header_contact', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.customers';
- }
-
- protected function getTextHeaderAmount($type, $textHeaderAmount)
- {
- if (!empty($textHeaderAmount)) {
- return $textHeaderAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_amount', 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getTextHeaderPaidAt($type, $textHeaderPaidAt)
- {
- if (!empty($textHeaderPaidAt)) {
- return $textHeaderPaidAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'header_paid_at', 'date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.date';
- }
-
- protected function getClassHeaderAccount($type, $classHeaderAccount)
- {
- if (!empty($classHeaderAccount)) {
- return $classHeaderAccount;
- }
-
- $class = $this->getClassFromConfig($type, 'header_account');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-4 col-lg-3';
- }
-
- protected function getClassHeaderContact($type, $classHeaderContact)
- {
- if (!empty($classHeaderContact)) {
- return $classHeaderContact;
- }
-
- $class = $this->getClassFromConfig($type, 'header_contact');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-4 col-lg-2';
- }
-
- protected function getClassHeaderCategory($type, $classHeaderCategory)
- {
- if (!empty($classHeaderCategory)) {
- return $classHeaderCategory;
- }
-
- $class = $this->getClassFromConfig($type, 'header_category');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-4 col-lg-3';
- }
-
- protected function getClassHeaderAmount($type, $classHeaderAmount)
- {
- if (!empty($classHeaderAmount)) {
- return $classHeaderAmount;
- }
-
- $class = $this->getClassFromConfig($type, 'header_amount');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-4 col-lg-2';
- }
-
- protected function getClassHeaderPaidAt($type, $classHeaderPaidAt)
- {
- if (!empty($classHeaderPaidAt)) {
- return $classHeaderPaidAt;
- }
-
- $class = $this->getClassFromConfig($type, 'header_paid_at');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-4 col-lg-2';
- }
-
- protected function getTextContentTitle($type, $textContentTitle)
- {
- if (!empty($textContentTitle)) {
- return $textContentTitle;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'payment_made';
- break;
- default:
- $default_key = 'revenue_received';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, $type . '_made', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.revenue_received';
- }
-
- protected function getTextPaidAt($type, $textPaidAt)
- {
- if (!empty($textPaidAt)) {
- return $textPaidAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'paid_at', 'date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.date';
- }
-
- protected function getTextAccount($type, $textAccount)
- {
- if (!empty($textAccount)) {
- return $textAccount;
- }
-
- $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.accounts';
- }
-
- protected function getTextCategory($type, $textCategory)
- {
- if (!empty($textCategory)) {
- return $textCategory;
- }
-
- $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.categories';
- }
-
- protected function getTextPaymentMethods($type, $textPaymentMethods)
- {
- if (!empty($textPaymentMethods)) {
- return $textPaymentMethods;
- }
-
- $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.payment_methods';
- }
-
- protected function getTextReference($type, $textReference)
- {
- if (!empty($textReference)) {
- return $textReference;
- }
-
- $translation = $this->getTextFromConfig($type, 'reference', 'reference');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.reference';
- }
-
- protected function getTextDescription($type, $textDescription)
- {
- if (!empty($textDescription)) {
- return $textDescription;
- }
-
- $translation = $this->getTextFromConfig($type, 'description', 'description');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.description';
- }
-
- protected function getTextAmount($type, $textAmount)
- {
- if (!empty($textAmount)) {
- return $textAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'amount', 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getTextPaidBy($type, $textPaidBy)
- {
- if (!empty($textPaidBy)) {
- return $textPaidBy;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'paid_to';
- break;
- default:
- $default_key = 'paid_by';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.paid_by';
- }
-
- protected function getTextRelatedTransansaction($type, $textRelatedTransansaction)
- {
- if (!empty($textRelatedTransansaction)) {
- return $textRelatedTransansaction;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'related_bill';
- break;
- default:
- $default_key = 'related_invoice';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_type', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.related_invoice';
- }
-
- protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber)
- {
- if (!empty($textRelatedDocumentNumber)) {
- return $textRelatedDocumentNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.numbers';
- }
-
- protected function getTextRelatedContact($type, $textRelatedContact)
- {
- if (!empty($textRelatedContact)) {
- return $textRelatedContact;
- }
-
- $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
-
- $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.customers';
- }
-
- protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate)
- {
- if (!empty($textRelatedDocumentDate)) {
- return $textRelatedDocumentDate;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount)
- {
- if (!empty($textRelatedDocumentAmount)) {
- return $textRelatedDocumentAmount;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_amount';
- break;
- default:
- $default_key = 'invoice_amount';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getTextRelatedAmount($type, $textRelatedAmount)
- {
- if (!empty($textRelatedAmount)) {
- return $textRelatedAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_amount', 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function routeDocumentShow($type, $routeDocumentShow)
- {
- if (!empty($routeDocumentShow)) {
- return $routeDocumentShow;
- }
-
- if (!$this->transaction->document) {
- return $routeDocumentShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.show';
- }
-
- protected function getHistories($histories)
- {
- if (!empty($histories)) {
- return $histories;
- }
-
- $histories[] = $this->transaction;
-
- return $histories;
- }
-
- protected function getTextHistories($type, $textHistories)
- {
- if (!empty($textHistories)) {
- return $textHistories;
- }
-
- $translation = $this->getTextFromConfig($type, 'histories', 'histories');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.histories';
- }
-
- protected function getClassFooterHistories($type, $classFooterHistories)
- {
- if (!empty($classFooterHistories)) {
- return $classFooterHistories;
- }
-
- $class = $this->getClassFromConfig($type, 'footer_histories');
-
- if (!empty($class)) {
- return $class;
- }
-
- return 'col-sm-6 col-md-6 col-lg-6 col-xl-6';
- }
-
- protected function getTextRecurringType($type, $textRecurringType)
- {
- if (!empty($textRecurringType)) {
- return $textRecurringType;
- }
-
- $default_key = config('type.' . $type . '.translation.prefix');
-
- $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.revenues';
- }
-
- protected function getRoutePrefix($type) {
- if ($prefix = config('type.' . $type . '.route.prefix', false)){
- return 'revenues';
- }
-
- return $prefix;
- }
-}
diff --git a/app/Abstracts/View/Components/TransactionTemplate.php b/app/Abstracts/View/Components/TransactionTemplate.php
deleted file mode 100644
index 83ebe676e..000000000
--- a/app/Abstracts/View/Components/TransactionTemplate.php
+++ /dev/null
@@ -1,632 +0,0 @@
-type = $type;
- $this->transaction = $transaction;
-
- $this->logo = $this->getLogo($logo);
- $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
-
- // Company Information Hide checker
- $this->hideCompany = $hideCompany;
- $this->hideCompanyLogo = $hideCompanyLogo;
- $this->hideCompanyDetails = $hideCompanyDetails;
- $this->hideCompanyName = $hideCompanyName;
- $this->hideCompanyAddress = $hideCompanyAddress;
- $this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
- $this->hideCompanyPhone = $hideCompanyPhone;
- $this->hideCompanyEmail = $hideCompanyEmail;
-
- // Transaction Information Hide checker
- $this->hideContentTitle = $hideContentTitle;
- $this->hidePaidAt = $hidePaidAt;
- $this->hideAccount = $hideAccount;
- $this->hideCategory = $hideCategory;
- $this->hidePaymentMethods = $hidePaymentMethods;
- $this->hideReference = $hideReference;
- $this->hideDescription = $hideDescription;
- $this->hideAmount = $hideAmount;
-
- // Transaction Information Text
- $this->textContentTitle = $this->getTextContentTitle($type, $textContentTitle);
- $this->textPaidAt = $this->getTextPaidAt($type, $textPaidAt);
- $this->textAccount = $this->getTextAccount($type, $textAccount);
- $this->textCategory = $this->getTextCategory($type, $textCategory);
- $this->textPaymentMethods = $this->getTextPaymentMethods($type, $textPaymentMethods);
- $this->textReference = $this->getTextReference($type, $textReference);
- $this->textDescription = $this->getTextDescription($type, $textDescription);
- $this->textAmount = $this->getTextAmount($type, $textAmount);
- $this->textPaidBy = $this->getTextPaidBy($type, $textPaidBy);
- $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
-
- // Contact Information Hide checker
- $this->hideContact = $hideContact;
- $this->hideContactInfo = $hideContactInfo;
- $this->hideContactName = $hideContactName;
- $this->hideContactAddress = $hideContactAddress;
- $this->hideContactTaxNumber = $hideContactTaxNumber;
- $this->hideContactPhone = $hideContactPhone;
- $this->hideContactEmail = $hideContactEmail;
-
- // Related Information Hide checker
- $this->hideRelated = $hideRelated;
- $this->hideRelatedDocumentNumber = $hideRelatedDocumentNumber;
- $this->hideRelatedContact = $hideRelatedContact;
- $this->hideRelatedDocumentDate = $hideRelatedDocumentDate;
- $this->hideRelatedDocumentAmount = $hideRelatedDocumentAmount;
- $this->hideRelatedAmount = $hideRelatedAmount;
-
- // Related Information Text
- $this->textRelatedTransansaction = $this->getTextRelatedTransansaction($type, $textRelatedTransansaction);
- $this->textRelatedDocumentNumber = $this->getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber);
- $this->textRelatedContact = $this->getTextRelatedContact($type, $textRelatedContact);
- $this->textRelatedDocumentDate = $this->getTextRelatedDocumentDate($type, $textRelatedDocumentDate);
- $this->textRelatedDocumentAmount = $this->getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount);
- $this->textRelatedAmount = $this->getTextRelatedAmount($type, $textRelatedAmount);
-
- $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow);
- }
-
- protected function getTextContactInfo($type, $textContactInfo)
- {
- if (!empty($textContactInfo)) {
- return $textContactInfo;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $textContactInfo = 'bills.bill_from';
- break;
- default:
- $textContactInfo = 'invoices.bill_to';
- break;
- }
-
- return $textContactInfo;
- }
-
- protected function getLogo($logo)
- {
- if (!empty($logo)) {
- return $logo;
- }
-
- $media_id = (!empty($this->transaction->contact->logo) && !empty($this->transaction->contact->logo->id)) ? $this->transaction->contact->logo->id : setting('company.logo');
-
- $media = Media::find($media_id);
-
- if (!empty($media)) {
- $path = $media->getDiskPath();
-
- if (Storage::missing($path)) {
- return $logo;
- }
- } else {
- $path = base_path('public/img/company.png');
- }
-
- try {
- $image = Image::cache(function($image) use ($media, $path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- if ($media) {
- $image->make(Storage::get($path))->resize($width, $height)->encode();
- } else {
- $image->make($path)->resize($width, $height)->encode();
- }
- });
- } catch (NotReadableException | \Exception $e) {
- Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.');
- Log::info($e->getMessage());
-
- $path = base_path('public/img/company.png');
-
- $image = Image::cache(function($image) use ($path) {
- $width = setting('invoice.logo_size_width');
- $height = setting('invoice.logo_size_height');
-
- $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 getTextContentTitle($type, $textContentTitle)
- {
- if (!empty($textContentTitle)) {
- return $textContentTitle;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'payment_made';
- break;
- default:
- $default_key = 'revenue_received';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, $type . '_made', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.revenue_received';
- }
-
- protected function getTextPaidAt($type, $textPaidAt)
- {
- if (!empty($textPaidAt)) {
- return $textPaidAt;
- }
-
- $translation = $this->getTextFromConfig($type, 'paid_at', 'date');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.date';
- }
-
- protected function getTextAccount($type, $textAccount)
- {
- if (!empty($textAccount)) {
- return $textAccount;
- }
-
- $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.accounts';
- }
-
- protected function getTextCategory($type, $textCategory)
- {
- if (!empty($textCategory)) {
- return $textCategory;
- }
-
- $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.categories';
- }
-
- protected function getTextPaymentMethods($type, $textPaymentMethods)
- {
- if (!empty($textPaymentMethods)) {
- return $textPaymentMethods;
- }
-
- $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.payment_methods';
- }
-
- protected function getTextReference($type, $textReference)
- {
- if (!empty($textReference)) {
- return $textReference;
- }
-
- $translation = $this->getTextFromConfig($type, 'reference', 'reference');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.reference';
- }
-
- protected function getTextDescription($type, $textDescription)
- {
- if (!empty($textDescription)) {
- return $textDescription;
- }
-
- $translation = $this->getTextFromConfig($type, 'description', 'description');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.description';
- }
-
- protected function getTextAmount($type, $textAmount)
- {
- if (!empty($textAmount)) {
- return $textAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'amount', 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getTextPaidBy($type, $textPaidBy)
- {
- if (!empty($textPaidBy)) {
- return $textPaidBy;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'paid_to';
- break;
- default:
- $default_key = 'paid_by';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.paid_by';
- }
-
- protected function getTextRelatedTransansaction($type, $textRelatedTransansaction)
- {
- if (!empty($textRelatedTransansaction)) {
- return $textRelatedTransansaction;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'related_bill';
- break;
- default:
- $default_key = 'related_invoice';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_type', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'revenues.related_invoice';
- }
-
- protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber)
- {
- if (!empty($textRelatedDocumentNumber)) {
- return $textRelatedDocumentNumber;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.numbers';
- }
-
- protected function getTextRelatedContact($type, $textRelatedContact)
- {
- if (!empty($textRelatedContact)) {
- return $textRelatedContact;
- }
-
- $default_key = Str::plural(config('type.' . $type . '.contact_type'), 2);
-
- $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.customers';
- }
-
- protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate)
- {
- if (!empty($textRelatedDocumentDate)) {
- return $textRelatedDocumentDate;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_date';
- break;
- default:
- $default_key = 'invoice_date';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'invoices.invoice_date';
- }
-
- protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount)
- {
- if (!empty($textRelatedDocumentAmount)) {
- return $textRelatedDocumentAmount;
- }
-
- switch ($type) {
- case 'bill':
- case 'expense':
- case 'purchase':
- $default_key = 'bill_amount';
- break;
- default:
- $default_key = 'invoice_amount';
- break;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key);
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function getTextRelatedAmount($type, $textRelatedAmount)
- {
- if (!empty($textRelatedAmount)) {
- return $textRelatedAmount;
- }
-
- $translation = $this->getTextFromConfig($type, 'related_amount', 'amount');
-
- if (!empty($translation)) {
- return $translation;
- }
-
- return 'general.amount';
- }
-
- protected function routeDocumentShow($type, $routeDocumentShow)
- {
- if (!empty($routeDocumentShow)) {
- return $routeDocumentShow;
- }
-
- if (!$this->transaction->document) {
- return $routeDocumentShow;
- }
-
- //example route parameter.
- $parameter = 1;
-
- $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter);
-
- if (!empty($route)) {
- return $route;
- }
-
- return 'invoices.show';
- }
-}
diff --git a/app/Abstracts/View/Components/Transactions/Show.php b/app/Abstracts/View/Components/Transactions/Show.php
new file mode 100644
index 000000000..64bb0994e
--- /dev/null
+++ b/app/Abstracts/View/Components/Transactions/Show.php
@@ -0,0 +1,1095 @@
+type = $type;
+ $this->transaction = $transaction;
+ $this->transactionTemplate = $this->getTransactionTemplate($type, $transactionTemplate);
+ $this->logo = $this->getLogo($logo);
+ $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
+ $this->date_format = $this->getCompanyDateFormat();
+
+ // Navbar Hide
+ $this->hideButtonAddNew = $hideButtonAddNew;
+ $this->hideButtonMoreActions = $hideButtonMoreActions;
+ $this->hideButtonEdit = $hideButtonEdit;
+ $this->hideButtonDuplicate = $hideButtonDuplicate;
+ $this->hideButtonConnect = $hideButtonConnect;
+ $this->hideButtonPrint = $hideButtonPrint;
+ $this->hideButtonShare = $hideButtonShare;
+ $this->hideButtonEmail = $hideButtonEmail;
+ $this->hideButtonPdf = $hideButtonPdf;
+ $this->hideButtonEnd = $hideButtonEnd;
+ $this->hideButtonDelete = $hideButtonDelete;
+ $this->checkButtonReconciled = $checkButtonReconciled;
+
+ $this->hideDivider1 = $hideDivider1;
+ $this->hideDivider2 = $hideDivider2;
+ $this->hideDivider3 = $hideDivider3;
+ $this->hideDivider4 = $hideDivider4;
+
+ // Navbar Permission
+ $this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
+ $this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
+ $this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
+
+ // Navbar route
+ $this->routeButtonAddNew = $this->getRouteButtonAddNew($type, $routeButtonAddNew);
+ $this->routeButtonEdit = $this->getRouteButtonEdit($type, $routeButtonEdit);
+ $this->routeButtonDuplicate = $this->getRouteButtonDuplicate($type, $routeButtonDuplicate);
+ $this->routeButtonPrint = $this->getRouteButtonPrint($type, $routeButtonPrint);
+ $this->shareRoute = $this->getShareRoute($type, $shareRoute);
+ $this->signedUrl = $this->getSignedUrl($type, $signedUrl);
+ $this->routeButtonEmail = $this->getRouteButtonEmail($type, $routeButtonEmail);
+ $this->routeButtonPdf = $this->getRouteButtonPdf($type, $routeButtonPdf);
+ $this->routeButtonEnd = $this->getRouteButtonEnd($type, $routeButtonEnd);
+ $this->routeButtonDelete = $this->getRouteButtonDelete($type, $routeButtonDelete);
+ $this->routeContactShow = $this->getRouteContactShow($type, $routeContactShow);
+
+ // Navbar Text
+ $this->textButtonAddNew = $this->getTextButtonAddNew($type, $textButtonAddNew);
+ $this->textDeleteModal = $textDeleteModal;
+
+ // Hide Schedule
+ $this->hideSchedule = $hideSchedule;
+
+ // Hide Children
+ $this->hideChildren = $hideChildren;
+
+ // Hide Attachment
+ $this->hideAttachment = $hideAttachment;
+
+ // Company Information Hide checker
+ $this->hideCompany = $hideCompany;
+ $this->hideCompanyLogo = $hideCompanyLogo;
+ $this->hideCompanyDetails = $hideCompanyDetails;
+ $this->hideCompanyName = $hideCompanyName;
+ $this->hideCompanyAddress = $hideCompanyAddress;
+ $this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
+ $this->hideCompanyPhone = $hideCompanyPhone;
+ $this->hideCompanyEmail = $hideCompanyEmail;
+
+ // Transaction Information Hide checker
+ $this->hideContentTitle = $hideContentTitle;
+ $this->hideNumber = $hideNumber;
+ $this->hidePaidAt = $hidePaidAt;
+ $this->hideAccount = $hideAccount;
+ $this->hideCategory = $hideCategory;
+ $this->hidePaymentMethods = $hidePaymentMethods;
+ $this->hideReference = $hideReference;
+ $this->hideDescription = $hideDescription;
+ $this->hideAmount = $hideAmount;
+
+ // Transaction Information Text
+ $this->textContentTitle = $this->getTextContentTitle($type, $textContentTitle);
+ $this->textNumber = $this->getTextNumber($type, $textNumber);
+ $this->textPaidAt = $this->getTextPaidAt($type, $textPaidAt);
+ $this->textAccount = $this->getTextAccount($type, $textAccount);
+ $this->textCategory = $this->getTextCategory($type, $textCategory);
+ $this->textPaymentMethods = $this->getTextPaymentMethods($type, $textPaymentMethods);
+ $this->textReference = $this->getTextReference($type, $textReference);
+ $this->textDescription = $this->getTextDescription($type, $textDescription);
+ $this->textAmount = $this->getTextAmount($type, $textAmount);
+ $this->textPaidBy = $this->getTextPaidBy($type, $textPaidBy);
+
+ // Contact Information Hide checker
+ $this->hideContact = $hideContact;
+ $this->hideContactInfo = $hideContactInfo;
+ $this->hideContactName = $hideContactName;
+ $this->hideContactAddress = $hideContactAddress;
+ $this->hideContactTaxNumber = $hideContactTaxNumber;
+ $this->hideContactPhone = $hideContactPhone;
+ $this->hideContactEmail = $hideContactEmail;
+
+ // Related Information Hide checker
+ $this->hideRelated = $hideRelated;
+ $this->hideRelatedDocumentNumber = $hideRelatedDocumentNumber;
+ $this->hideRelatedContact = $hideRelatedContact;
+ $this->hideRelatedDocumentDate = $hideRelatedDocumentDate;
+ $this->hideRelatedDocumentAmount = $hideRelatedDocumentAmount;
+ $this->hideRelatedAmount = $hideRelatedAmount;
+
+ // Related Information Text
+ $this->textRelatedTransansaction = $this->getTextRelatedTransansaction($type, $textRelatedTransansaction);
+ $this->textRelatedDocumentNumber = $this->getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber);
+ $this->textRelatedContact = $this->getTextRelatedContact($type, $textRelatedContact);
+ $this->textRelatedDocumentDate = $this->getTextRelatedDocumentDate($type, $textRelatedDocumentDate);
+ $this->textRelatedDocumentAmount = $this->getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount);
+ $this->textRelatedAmount = $this->getTextRelatedAmount($type, $textRelatedAmount);
+
+ $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow);
+
+ // Attachment data..
+ $this->attachment = '';
+
+ if (!empty($attachment)) {
+ $this->attachment = $attachment;
+ } else if (!empty($transaction)) {
+ $this->attachment = $transaction->attachment;
+ }
+
+ // Connect translations
+ $this->connectTranslations = $this->getTranslationsForConnect($type);
+
+ $this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType);
+ $this->hideRecurringMessage = $hideRecurringMessage;
+ }
+
+ protected function getTransactionTemplate($type, $transactionTemplate)
+ {
+ if (!empty($transactionTemplate)) {
+ return $transactionTemplate;
+ }
+
+ if ($template = config('type.transaction.' . $type . '.template', false)) {
+ return $template;
+ }
+
+ $transactionTemplate = setting($this->getSettingKey($type, 'template')) ?: 'default';
+
+ return $transactionTemplate;
+ }
+
+ protected function getLogo($logo)
+ {
+ if (!empty($logo)) {
+ return $logo;
+ }
+
+ $media_id = (!empty($this->transaction->contact->logo) && !empty($this->transaction->contact->logo->id)) ? $this->transaction->contact->logo->id : setting('company.logo');
+
+ $media = Media::find($media_id);
+
+ if (!empty($media)) {
+ $path = $media->getDiskPath();
+
+ if (Storage::missing($path)) {
+ return $logo;
+ }
+ } else {
+ $path = base_path('public/img/company.png');
+ }
+
+ try {
+ $image = Image::cache(function($image) use ($media, $path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ if ($media) {
+ $image->make(Storage::get($path))->resize($width, $height)->encode();
+ } else {
+ $image->make($path)->resize($width, $height)->encode();
+ }
+ });
+ } catch (NotReadableException | \Exception $e) {
+ Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.');
+ Log::info($e->getMessage());
+
+ $path = base_path('public/img/company.png');
+
+ $image = Image::cache(function($image) use ($path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ $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 getRouteButtonAddNew($type, $routeButtonAddNew)
+ {
+ if (!empty($routeButtonAddNew)) {
+ return $routeButtonAddNew;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'create', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.create';
+ }
+
+ protected function getRouteButtonEdit($type, $routeButtonEdit)
+ {
+ if (!empty($routeButtonEdit)) {
+ return $routeButtonEdit;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'edit', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.edit';
+ }
+
+ protected function getRouteButtonDuplicate($type, $routeButtonDuplicate)
+ {
+ if (!empty($routeButtonDuplicate)) {
+ return $routeButtonDuplicate;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'duplicate', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.duplicate';
+ }
+
+ protected function getRouteButtonPrint($type, $routeButtonPrint)
+ {
+ if (!empty($routeButtonPrint)) {
+ return $routeButtonPrint;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'print', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.print';
+ }
+
+ protected function getShareRoute($type, $shareRoute)
+ {
+ if (! empty($shareRoute)) {
+ return $shareRoute;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'share', $parameter);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'modals.transactions.share.create';
+ }
+
+ protected function getSignedUrl($type, $signedUrl)
+ {
+ if (!empty($signedUrl)) {
+ return $signedUrl;
+ }
+
+ $page = config('type.transaction.' . $type . '.route.prefix');
+ $alias = config('type.transaction.' . $type . '.alias');
+
+ $route = '';
+
+ if (!empty($alias)) {
+ $route .= $alias . '.';
+ }
+
+ $route .= 'signed.' . $page . '.show';
+
+ try {
+ route($route, [$this->transaction->id, 'company_id' => company_id()]);
+
+ $signedUrl = URL::signedRoute($route, [$this->transaction->id]);
+ } catch (\Exception $e) {
+ $signedUrl = URL::signedRoute('signed.payments.show', [$this->transaction->id]);
+ }
+
+ return $signedUrl;
+ }
+
+ protected function getRouteButtonEmail($type, $routeButtonEmail)
+ {
+ if (! empty($routeButtonEmail)) {
+ return $routeButtonEmail;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'emails.create', $parameter, true);
+
+ if (! empty($route)) {
+ return $route;
+ }
+
+ return 'modals.transactions.emails.create';
+ }
+
+ protected function getRouteButtonPdf($type, $routeButtonPdf)
+ {
+ if (!empty($routeButtonPdf)) {
+ return $routeButtonPdf;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'pdf', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.pdf';
+ }
+
+ protected function getRouteButtonEnd($type, $routeButtonEnd)
+ {
+ if (!empty($routeButtonEnd)) {
+ return $routeButtonEnd;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'end', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'recurring-transactions.end';
+ }
+
+ protected function getRouteButtonDelete($type, $routeButtonDelete)
+ {
+ if (!empty($routeButtonDelete)) {
+ return $routeButtonDelete;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($type, 'destroy', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'transactions.destroy';
+ }
+
+ protected function getRouteContactShow($type, $routeContactShow)
+ {
+ if (!empty($routeContactShow)) {
+ return $routeContactShow;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = Str::plural(config('type.transaction.' . $type . '.contact_type'), 2) . '.show';
+
+ try {
+ route($route, $parameter);
+ } catch (\Exception $e) {
+ try {
+ $route = Str::plural($type, 2) . '.' . $config_key;
+
+ route($route, $parameter);
+ } catch (\Exception $e) {
+ $route = '';
+ }
+ }
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'customers.show';
+ }
+
+ protected function getTextButtonAddNew($type, $textButtonAddNew)
+ {
+ if (!empty($textButtonAddNew)) {
+ return $textButtonAddNew;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'transactions');
+
+ if (!empty($translation)) {
+ return trans('general.title.new', ['type' => trans_choice($translation, 1)]);
+ }
+
+ return trans('general.title.new', ['type' => trans_choice('general.' . Str::plural($type), 1)]);
+ }
+
+ protected function getTextContentTitle($type, $textContentTitle)
+ {
+ if (!empty($textContentTitle)) {
+ return $textContentTitle;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'payment_made';
+ break;
+ default:
+ $default_key = 'receipts';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, $type . '_made', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.receipts';
+ }
+
+ protected function getTextNumber($type, $textNumber)
+ {
+ if (!empty($textNumber)) {
+ return $textNumber;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextPaidAt($type, $textPaidAt)
+ {
+ if (!empty($textPaidAt)) {
+ return $textPaidAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'paid_at', 'date');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.date';
+ }
+
+ protected function getTextAccount($type, $textAccount)
+ {
+ if (!empty($textAccount)) {
+ return $textAccount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.accounts';
+ }
+
+ protected function getTextCategory($type, $textCategory)
+ {
+ if (!empty($textCategory)) {
+ return $textCategory;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.categories';
+ }
+
+ protected function getTextPaymentMethods($type, $textPaymentMethods)
+ {
+ if (!empty($textPaymentMethods)) {
+ return $textPaymentMethods;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.payment_methods';
+ }
+
+ protected function getTextReference($type, $textReference)
+ {
+ if (!empty($textReference)) {
+ return $textReference;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'reference', 'reference');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.reference';
+ }
+
+ protected function getTextDescription($type, $textDescription)
+ {
+ if (!empty($textDescription)) {
+ return $textDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'description', 'description');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.description';
+ }
+
+ protected function getTextAmount($type, $textAmount)
+ {
+ if (!empty($textAmount)) {
+ return $textAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'amount', 'amount');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getTextPaidBy($type, $textPaidBy)
+ {
+ if (!empty($textPaidBy)) {
+ return $textPaidBy;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'paid_to';
+ break;
+ default:
+ $default_key = 'paid_by';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'transactions.paid_by';
+ }
+
+ protected function getTextRelatedTransansaction($type, $textRelatedTransansaction)
+ {
+ if (!empty($textRelatedTransansaction)) {
+ return $textRelatedTransansaction;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'related_bill';
+ break;
+ default:
+ $default_key = 'related_invoice';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_type', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'transactions.related_invoice';
+ }
+
+ protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber)
+ {
+ if (!empty($textRelatedDocumentNumber)) {
+ return $textRelatedDocumentNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextRelatedContact($type, $textRelatedContact)
+ {
+ if (!empty($textRelatedContact)) {
+ return $textRelatedContact;
+ }
+
+ $default_key = Str::plural(config('type.transaction.' . $type . '.contact_type'), 2);
+
+ $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.customers';
+ }
+
+ protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate)
+ {
+ if (!empty($textRelatedDocumentDate)) {
+ return $textRelatedDocumentDate;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount)
+ {
+ if (!empty($textRelatedDocumentAmount)) {
+ return $textRelatedDocumentAmount;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_amount';
+ break;
+ default:
+ $default_key = 'invoice_amount';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getTextRelatedAmount($type, $textRelatedAmount)
+ {
+ if (!empty($textRelatedAmount)) {
+ return $textRelatedAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_amount', 'amount');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function routeDocumentShow($type, $routeDocumentShow)
+ {
+ if (!empty($routeDocumentShow)) {
+ return $routeDocumentShow;
+ }
+
+ if (!$this->transaction->document) {
+ return $routeDocumentShow;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.show';
+ }
+
+ protected function getTextRecurringType($type, $textRecurringType)
+ {
+ if (! empty($textRecurringType)) {
+ return $textRecurringType;
+ }
+
+ $default_key = config('type.' . $type . '.translation.prefix');
+
+ $translation = $this->getTextFromConfig($type, 'recurring_tye', $default_key);
+
+ if (! empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.revenues';
+ }
+}
diff --git a/app/Abstracts/View/Components/Transactions/Template.php b/app/Abstracts/View/Components/Transactions/Template.php
new file mode 100644
index 000000000..5727a22bf
--- /dev/null
+++ b/app/Abstracts/View/Components/Transactions/Template.php
@@ -0,0 +1,653 @@
+type = $type;
+ $this->transaction = $transaction;
+
+ $this->logo = $this->getLogo($logo);
+ $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
+
+ // Company Information Hide checker
+ $this->hideCompany = $hideCompany;
+ $this->hideCompanyLogo = $hideCompanyLogo;
+ $this->hideCompanyDetails = $hideCompanyDetails;
+ $this->hideCompanyName = $hideCompanyName;
+ $this->hideCompanyAddress = $hideCompanyAddress;
+ $this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
+ $this->hideCompanyPhone = $hideCompanyPhone;
+ $this->hideCompanyEmail = $hideCompanyEmail;
+
+ // Transaction Information Hide checker
+ $this->hideContentTitle = $hideContentTitle;
+ $this->hideNumber = $hideNumber;
+ $this->hidePaidAt = $hidePaidAt;
+ $this->hideAccount = $hideAccount;
+ $this->hideCategory = $hideCategory;
+ $this->hidePaymentMethods = $hidePaymentMethods;
+ $this->hideReference = $hideReference;
+ $this->hideDescription = $hideDescription;
+ $this->hideAmount = $hideAmount;
+
+ // Transaction Information Text
+ $this->textContentTitle = $this->getTextContentTitle($type, $textContentTitle);
+ $this->textNumber = $this->getTextNumber($type, $textNumber);
+ $this->textPaidAt = $this->getTextPaidAt($type, $textPaidAt);
+ $this->textAccount = $this->getTextAccount($type, $textAccount);
+ $this->textCategory = $this->getTextCategory($type, $textCategory);
+ $this->textPaymentMethods = $this->getTextPaymentMethods($type, $textPaymentMethods);
+ $this->textReference = $this->getTextReference($type, $textReference);
+ $this->textDescription = $this->getTextDescription($type, $textDescription);
+ $this->textAmount = $this->getTextAmount($type, $textAmount);
+ $this->textPaidBy = $this->getTextPaidBy($type, $textPaidBy);
+ $this->textContactInfo = $this->getTextContactInfo($type, $textContactInfo);
+
+ // Contact Information Hide checker
+ $this->hideContact = $hideContact;
+ $this->hideContactInfo = $hideContactInfo;
+ $this->hideContactName = $hideContactName;
+ $this->hideContactAddress = $hideContactAddress;
+ $this->hideContactTaxNumber = $hideContactTaxNumber;
+ $this->hideContactPhone = $hideContactPhone;
+ $this->hideContactEmail = $hideContactEmail;
+
+ // Related Information Hide checker
+ $this->hideRelated = $hideRelated;
+ $this->hideRelatedDocumentNumber = $hideRelatedDocumentNumber;
+ $this->hideRelatedContact = $hideRelatedContact;
+ $this->hideRelatedDocumentDate = $hideRelatedDocumentDate;
+ $this->hideRelatedDocumentAmount = $hideRelatedDocumentAmount;
+ $this->hideRelatedAmount = $hideRelatedAmount;
+
+ // Related Information Text
+ $this->textRelatedTransansaction = $this->getTextRelatedTransansaction($type, $textRelatedTransansaction);
+ $this->textRelatedDocumentNumber = $this->getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber);
+ $this->textRelatedContact = $this->getTextRelatedContact($type, $textRelatedContact);
+ $this->textRelatedDocumentDate = $this->getTextRelatedDocumentDate($type, $textRelatedDocumentDate);
+ $this->textRelatedDocumentAmount = $this->getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount);
+ $this->textRelatedAmount = $this->getTextRelatedAmount($type, $textRelatedAmount);
+
+ $this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow);
+ }
+
+ protected function getLogo($logo)
+ {
+ if (!empty($logo)) {
+ return $logo;
+ }
+
+ $media_id = (!empty($this->transaction->contact->logo) && !empty($this->transaction->contact->logo->id)) ? $this->transaction->contact->logo->id : setting('company.logo');
+
+ $media = Media::find($media_id);
+
+ if (!empty($media)) {
+ $path = $media->getDiskPath();
+
+ if (Storage::missing($path)) {
+ return $logo;
+ }
+ } else {
+ $path = base_path('public/img/company.png');
+ }
+
+ try {
+ $image = Image::cache(function($image) use ($media, $path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ if ($media) {
+ $image->make(Storage::get($path))->resize($width, $height)->encode();
+ } else {
+ $image->make($path)->resize($width, $height)->encode();
+ }
+ });
+ } catch (NotReadableException | \Exception $e) {
+ Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.');
+ Log::info($e->getMessage());
+
+ $path = base_path('public/img/company.png');
+
+ $image = Image::cache(function($image) use ($path) {
+ $width = setting('invoice.logo_size_width');
+ $height = setting('invoice.logo_size_height');
+
+ $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 getTextContentTitle($type, $textContentTitle)
+ {
+ if (!empty($textContentTitle)) {
+ return $textContentTitle;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'payment_made';
+ break;
+ default:
+ $default_key = 'receipts';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, $type . '_made', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.receipts';
+ }
+
+ protected function getTextNumber($type, $textNumber)
+ {
+ if (!empty($textNumber)) {
+ return $textNumber;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextPaidAt($type, $textPaidAt)
+ {
+ if (!empty($textPaidAt)) {
+ return $textPaidAt;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'paid_at', 'date');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.date';
+ }
+
+ protected function getTextAccount($type, $textAccount)
+ {
+ if (!empty($textAccount)) {
+ return $textAccount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.accounts';
+ }
+
+ protected function getTextCategory($type, $textCategory)
+ {
+ if (!empty($textCategory)) {
+ return $textCategory;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.categories';
+ }
+
+ protected function getTextPaymentMethods($type, $textPaymentMethods)
+ {
+ if (!empty($textPaymentMethods)) {
+ return $textPaymentMethods;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.payment_methods';
+ }
+
+ protected function getTextReference($type, $textReference)
+ {
+ if (!empty($textReference)) {
+ return $textReference;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'reference', 'reference');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.reference';
+ }
+
+ protected function getTextDescription($type, $textDescription)
+ {
+ if (!empty($textDescription)) {
+ return $textDescription;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'description', 'description');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.description';
+ }
+
+ protected function getTextAmount($type, $textAmount)
+ {
+ if (!empty($textAmount)) {
+ return $textAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'amount', 'amount');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getTextPaidBy($type, $textPaidBy)
+ {
+ if (!empty($textPaidBy)) {
+ return $textPaidBy;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'paid_to';
+ break;
+ default:
+ $default_key = 'paid_by';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'transactions.paid_by';
+ }
+
+ protected function getTextContactInfo($type, $textContactInfo)
+ {
+ if (!empty($textContactInfo)) {
+ return $textContactInfo;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $textContactInfo = 'bills.bill_from';
+ break;
+ default:
+ $textContactInfo = 'invoices.bill_to';
+ break;
+ }
+
+ return $textContactInfo;
+ }
+
+ protected function getTextRelatedTransansaction($type, $textRelatedTransansaction)
+ {
+ if (!empty($textRelatedTransansaction)) {
+ return $textRelatedTransansaction;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'related_bill';
+ break;
+ default:
+ $default_key = 'related_invoice';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_type', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'transactions.related_invoice';
+ }
+
+ protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber)
+ {
+ if (!empty($textRelatedDocumentNumber)) {
+ return $textRelatedDocumentNumber;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.numbers';
+ }
+
+ protected function getTextRelatedContact($type, $textRelatedContact)
+ {
+ if (!empty($textRelatedContact)) {
+ return $textRelatedContact;
+ }
+
+ $default_key = Str::plural(config('type.transaction.' . $type . '.contact_type'), 2);
+
+ $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.customers';
+ }
+
+ protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate)
+ {
+ if (!empty($textRelatedDocumentDate)) {
+ return $textRelatedDocumentDate;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_date';
+ break;
+ default:
+ $default_key = 'invoice_date';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'invoices.invoice_date';
+ }
+
+ protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount)
+ {
+ if (!empty($textRelatedDocumentAmount)) {
+ return $textRelatedDocumentAmount;
+ }
+
+ switch ($type) {
+ case 'bill':
+ case 'expense':
+ case 'purchase':
+ $default_key = 'bill_amount';
+ break;
+ default:
+ $default_key = 'invoice_amount';
+ break;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key);
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function getTextRelatedAmount($type, $textRelatedAmount)
+ {
+ if (!empty($textRelatedAmount)) {
+ return $textRelatedAmount;
+ }
+
+ $translation = $this->getTextFromConfig($type, 'related_amount', 'amount');
+
+ if (!empty($translation)) {
+ return $translation;
+ }
+
+ return 'general.amount';
+ }
+
+ protected function routeDocumentShow($type, $routeDocumentShow)
+ {
+ if (!empty($routeDocumentShow)) {
+ return $routeDocumentShow;
+ }
+
+ if (!$this->transaction->document) {
+ return $routeDocumentShow;
+ }
+
+ //example route parameter.
+ $parameter = 1;
+
+ $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter);
+
+ if (!empty($route)) {
+ return $route;
+ }
+
+ return 'invoices.show';
+ }
+}
diff --git a/app/Abstracts/View/Components/TransferShow.php b/app/Abstracts/View/Components/TransferShow.php
deleted file mode 100644
index 2244dd80f..000000000
--- a/app/Abstracts/View/Components/TransferShow.php
+++ /dev/null
@@ -1,747 +0,0 @@
-transfer = $transfer;
- $this->transferTemplate = $this->getTransferTemplate($transferTemplate);
- $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
- $this->date_format = $this->getCompanyDateFormat();
-
- // Navbar Hide
- $this->hideButtonAddNew = $hideButtonAddNew;
- $this->hideButtonMoreActions = $hideButtonMoreActions;
- $this->hideButtonEdit = $hideButtonEdit;
- $this->hideButtonDuplicate = $hideButtonDuplicate;
- $this->hideButtonPrint = $hideButtonPrint;
- $this->hideButtonShare = $hideButtonShare;
- $this->hideButtonEmail = $hideButtonEmail;
- $this->hideButtonPdf = $hideButtonPdf;
- $this->hideButtonTemplate = $hideButtonTemplate;
- $this->hideButtonDelete = $hideButtonDelete;
- $this->hideButtonGroupDivider1 = $hideButtonGroupDivider1;
- $this->hideButtonGroupDivider2 = $hideButtonGroupDivider2;
- $this->hideButtonGroupDivider3 = $hideButtonGroupDivider3;
-
- // Navbar Permission
- $this->permissionCreate = $this->getPermissionCreate($permissionCreate);
- $this->permissionUpdate = $this->getPermissionUpdate($permissionUpdate);
- $this->permissionDelete = $this->getPermissionDelete($permissionDelete);
-
- // Navbar route
- $this->routeButtonAddNew = $this->getRouteButtonAddNew($routeButtonAddNew);
- $this->routeButtonEdit = $this->getRouteButtonEdit($routeButtonEdit);
- $this->routeButtonDuplicate = $this->getRouteButtonDuplicate($routeButtonDuplicate);
- $this->routeButtonPrint = $this->getRouteButtonPrint($routeButtonPrint);
- $this->signedUrl = $this->getSignedUrl($signedUrl);
- $this->routeButtonEmail = $this->getRouteButtonEmail($routeButtonEmail);
- $this->routeButtonPdf = $this->getRouteButtonPdf($routeButtonPdf);
- $this->routeButtonDelete = $this->getRouteButtonDelete($routeButtonDelete);
- $this->routeFromAccountShow = $this->getRouteFromAccountShow($routeFromAccountShow);
- $this->routeToAccountShow = $this->getRouteToAccountShow($routeToAccountShow);
-
- // Navbar Text
- $this->textDeleteModal = $textDeleteModal;
-
- // Header Hide
- $this->hideHeader = $hideHeader;
-
- $this->hideHeaderFromAccount = $hideHeaderFromAccount;
- $this->hideHeaderToAccount = $hideHeaderToAccount;
- $this->hideHeaderToAccount = $hideHeaderToAccount;
- $this->hideHeaderAmount = $hideHeaderAmount;
- $this->hideHeaderPaidAt = $hideHeaderPaidAt;
-
- // Header Text
- $this->textHeaderFromAccount = $this->getTextHeaderFromAccount($textHeaderFromAccount);
- $this->textHeaderToAccount = $this->getTextHeaderToAccount($textHeaderToAccount);
- $this->textHeaderAmount = $this->getTextHeaderAmount($textHeaderAmount);
- $this->textHeaderPaidAt = $this->gettextHeaderPaidAt($textHeaderPaidAt);
-
- // Header Class
- $this->classHeaderFromAccount = $this->getclassHeaderFromAccount($classHeaderFromAccount);
- $this->classHeaderToAccount = $this->getClassHeaderToAccount($classHeaderToAccount);
- $this->classHeaderAmount = $this->getClassHeaderAmount($classHeaderAmount);
- $this->classHeaderPaidAt = $this->getclassHeaderPaidAt($classHeaderPaidAt);
-
- // From account Hide
- $this->hideFromAccount = $hideFromAccount;
- $this->hideFromAccountTitle = $hideFromAccountTitle;
- $this->hideFromAccountName = $hideFromAccountName;
- $this->hideFromAccountNumber = $hideFromAccountNumber;
- $this->hideFromAccountBankName = $hideFromAccountBankName;
- $this->hideFromAccountBankPhone = $hideFromAccountBankPhone;
- $this->hideFromAccountBankAddress = $hideFromAccountBankAddress;
-
- // From account text
- $this->textFromAccountTitle = $this->getTextFromAccountTitle($textFromAccountTitle);
- $this->textFromAccountNumber = $this->getTextFromAccountNumber($textFromAccountNumber);
-
- // To account Hide
- $this->hideToAccount = $hideToAccount;
- $this->hideToAccountTitle = $hideToAccountTitle;
- $this->hideToAccountName = $hideToAccountName;
- $this->hideToAccountNumber = $hideToAccountNumber;
- $this->hideToAccountBankName = $hideToAccountBankName;
- $this->hideToAccountBankPhone = $hideToAccountBankPhone;
- $this->hideToAccountBankAddress = $hideToAccountBankAddress;
-
- // To account text
- $this->textToAccountTitle = $this->getTextToAccountTitle($textToAccountTitle);
- $this->textToAccountNumber = $this->getTextToAccountNumber($textToAccountNumber);
-
- // Detail Information Hide checker
- $this->hideDetails = $hideDetails;
- $this->hideDetailTitle = $hideDetailTitle;
- $this->hideDetailDate = $hideDetailDate;
- $this->hideDetailPaymentMethod = $hideDetailPaymentMethod;
- $this->hideDetailReference = $hideDetailReference;
- $this->hideDetailDescription = $hideDetailDescription;
- $this->hideDetailAmount = $hideDetailAmount;
-
- // Related Information Text
- $this->textDetailTitle = $this->getTextDetailTitle($textDetailTitle);
- $this->textDetailDate = $this->getTextDetailDate($textDetailDate);
- $this->textDetailPaymentMethod = $this->getTextDetailPaymentMethod($textDetailPaymentMethod);
- $this->textDetailReference = $this->getTextDetailReference($textDetailReference);
- $this->textDetailDescription = $this->getTextDetailDescription($textDetailDescription);
- $this->textDetailAmount = $this->getTextDetailAmount($textDetailAmount);
-
- // Hide Attachment
- $this->hideAttachment = $hideAttachment;
-
- // Attachment data..
- $this->attachment = '';
-
- if (!empty($attachment)) {
- $this->attachment = $attachment;
- } else if (!empty($transfer)) {
- $this->attachment = $transfer->attachment;
- }
-
- // Histories Hide
- $this->hideFooter = $hideFooter;
- $this->hideFooterHistories = $hideFooterHistories;
-
- // Histories
- $this->histories = $this->getHistories($histories);
- $this->textHistories = $this->getTextHistories($textHistories);
- $this->classFooterHistories = $this->getClassFooterHistories($classFooterHistories);
- }
-
- protected function getTransferTemplate($transferTemplate)
- {
- if (!empty($transferTemplate)) {
- return $transferTemplate;
- }
-
- return setting('transfer.template');
- }
-
- protected function getRouteButtonAddNew($routeButtonAddNew)
- {
- if (!empty($routeButtonAddNew)) {
- return $routeButtonAddNew;
- }
-
- return 'transfers.create';
- }
-
- protected function getRouteButtonEdit($routeButtonEdit)
- {
- if (!empty($routeButtonEdit)) {
- return $routeButtonEdit;
- }
-
- return 'transfers.edit';
- }
-
- protected function getRouteButtonDuplicate($routeButtonDuplicate)
- {
- if (!empty($routeButtonDuplicate)) {
- return $routeButtonDuplicate;
- }
-
- return 'transfers.duplicate';
- }
-
- protected function getRouteButtonPrint($routeButtonPrint)
- {
- if (!empty($routeButtonPrint)) {
- return $routeButtonPrint;
- }
-
- return 'transfers.print';
- }
-
- protected function getSignedUrl($signedUrl)
- {
- if (!empty($signedUrl)) {
- return $signedUrl;
- }
-
- try {
- $signedUrl = URL::signedRoute('signed.transfer.show', [$this->transfer->id]);
- } catch (\Exception $e) {
- $signedUrl = false;
- }
-
- return $signedUrl;
- }
-
- protected function getRouteButtonEmail($routeButtonEmail)
- {
- if (!empty($routeButtonEmail)) {
- return $routeButtonEmail;
- }
-
- return 'transfers.email';
- }
-
- protected function getRouteButtonPdf($routeButtonPdf)
- {
- if (!empty($routeButtonPdf)) {
- return $routeButtonPdf;
- }
-
- return 'transfers.pdf';
- }
-
- protected function getRouteButtonDelete($routeButtonDelete)
- {
- if (!empty($routeButtonDelete)) {
- return $routeButtonDelete;
- }
-
- return 'transfers.destroy';
- }
-
- protected function getRouteFromAccountShow($routeFromAccountShow)
- {
- if (!empty($routeFromAccountShow)) {
- return $routeFromAccountShow;
- }
-
- return 'accounts.show';
- }
-
- protected function getRouteToAccountShow($routeToAccountShow)
- {
- if (!empty($routeToAccountShow)) {
- return $routeToAccountShow;
- }
-
- return 'accounts.show';
- }
-
- protected function getPermissionCreate($permissionCreate)
- {
- if (!empty($permissionCreate)) {
- return $permissionCreate;
- }
-
- return 'create-banking-transfers';
- }
-
- protected function getPermissionUpdate($permissionUpdate)
- {
- if (!empty($permissionUpdate)) {
- return $permissionUpdate;
- }
-
- return 'update-banking-transfers';
- }
-
- protected function getPermissionDelete($permissionDelete)
- {
- if (!empty($permissionDelete)) {
- return $permissionDelete;
- }
-
- return 'delete-banking-transfers';
- }
-
- protected function getTextHeaderFromAccount($textHeaderFromAccount)
- {
- if (!empty($textHeaderFromAccount)) {
- return $textHeaderFromAccount;
- }
-
- return 'transfers.from_account';
- }
-
- protected function getTextHeaderToAccount($textHeaderToAccount)
- {
- if (!empty($textHeaderToAccount)) {
- return $textHeaderToAccount;
- }
-
- return 'transfers.to_account';
- }
-
- protected function getTextHeaderAmount($textHeaderAmount)
- {
- if (!empty($textHeaderAmount)) {
- return $textHeaderAmount;
- }
-
- return 'general.amount';
- }
-
- protected function getTextHeaderPaidAt($textHeaderPaidAt)
- {
- if (!empty($textHeaderPaidAt)) {
- return $textHeaderPaidAt;
- }
-
- return 'general.date';
- }
-
- protected function getClassHeaderFromAccount($classHeaderFromAccount)
- {
- if (!empty($classHeaderFromAccount)) {
- return $classHeaderFromAccount;
- }
-
- return 'col-4 col-lg-2';
- }
-
- protected function getClassHeaderToAccount($classHeaderToAccount)
- {
- if (!empty($classHeaderToAccount)) {
- return $classHeaderToAccount;
- }
-
- return 'col-4 col-lg-6';
- }
-
- protected function getClassHeaderAmount($classHeaderAmount)
- {
- if (!empty($classHeaderAmount)) {
- return $classHeaderAmount;
- }
-
- return 'col-4 col-lg-2 float-right';
- }
-
- protected function getClassHeaderPaidAt($classHeaderPaidAt)
- {
- if (!empty($classHeaderPaidAt)) {
- return $classHeaderPaidAt;
- }
-
- return 'col-4 col-lg-2';
- }
-
- protected function getTextFromAccountTitle($textToAccountTitle)
- {
- if (!empty($textToAccountTitle)) {
- return $textToAccountTitle;
- }
-
- return 'transfers.from_account';
- }
-
- protected function getTextFromAccountNumber($textFromAccountNumber)
- {
- if (!empty($textFromAccountNumber)) {
- return $textFromAccountNumber;
- }
-
- return 'accounts.number';
- }
-
- protected function getTextToAccountTitle($textFromAccountTitle)
- {
- if (!empty($textFromAccountTitle)) {
- return $textFromAccountTitle;
- }
-
- return 'transfers.to_account';
- }
-
- protected function getTextToAccountNumber($textToAccountNumber)
- {
- if (!empty($textToAccountNumber)) {
- return $textToAccountNumber;
- }
-
- return 'accounts.number';
- }
-
- protected function getTextDetailTitle($textDetailTitle)
- {
- if (!empty($textDetailTitle)) {
- return $textDetailTitle;
- }
-
- return 'transfers.details';
- }
-
- protected function getTextDetailDate($textDetailDate)
- {
- if (!empty($textDetailDate)) {
- return $textDetailDate;
- }
-
- return 'general.date';
- }
-
- protected function getTextDetailPaymentMethod($textDetailPaymentMethod)
- {
- if (!empty($textDetailPaymentMethod)) {
- return $textDetailPaymentMethod;
- }
-
- return 'general.payment_methods';
- }
-
- protected function getTextDetailReference($textDetailReference)
- {
- if (!empty($textDetailReference)) {
- return $textDetailReference;
- }
-
- return 'general.reference';
- }
-
- protected function getTextDetailDescription($textDetailDescription)
- {
- if (!empty($textDetailDescription)) {
- return $textDetailDescription;
- }
-
- return 'general.description';
- }
-
- protected function getTextDetailAmount($textDetailAmount)
- {
- if (!empty($textDetailAmount)) {
- return $textDetailAmount;
- }
-
- return 'general.amount';
- }
-
- protected function getHistories($histories)
- {
- if (!empty($histories)) {
- return $histories;
- }
-
- $histories[] = $this->transfer;
-
- return $histories;
- }
-
- protected function getTextHistories($textHistories)
- {
- if (!empty($textHistories)) {
- return $textHistories;
- }
-
- return 'invoices.histories';
- }
-
- protected function getClassFooterHistories($classFooterHistories)
- {
- if (!empty($classFooterHistories)) {
- return $classFooterHistories;
- }
-
- return 'col-sm-6 col-md-6 col-lg-6 col-xl-6';
- }
-}
diff --git a/app/Abstracts/View/Components/TransferTemplate.php b/app/Abstracts/View/Components/TransferTemplate.php
deleted file mode 100644
index 6f54f4360..000000000
--- a/app/Abstracts/View/Components/TransferTemplate.php
+++ /dev/null
@@ -1,278 +0,0 @@
-transfer = $transfer;
-
- $this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
-
- // From account Hide
- $this->hideFromAccount = $hideFromAccount;
- $this->hideFromAccountTitle = $hideFromAccountTitle;
- $this->hideFromAccountName = $hideFromAccountName;
- $this->hideFromAccountNumber = $hideFromAccountNumber;
- $this->hideFromAccountBankName = $hideFromAccountBankName;
- $this->hideFromAccountBankPhone = $hideFromAccountBankPhone;
- $this->hideFromAccountBankAddress = $hideFromAccountBankAddress;
-
- // From account text
- $this->textFromAccountTitle = $this->getTextFromAccountTitle($textFromAccountTitle);
- $this->textFromAccountNumber = $this->getTextFromAccountNumber($textFromAccountNumber);
-
- // To account Hide
- $this->hideToAccount = $hideToAccount;
- $this->hideToAccountTitle = $hideToAccountTitle;
- $this->hideToAccountName = $hideToAccountName;
- $this->hideToAccountNumber = $hideToAccountNumber;
- $this->hideToAccountBankName = $hideToAccountBankName;
- $this->hideToAccountBankPhone = $hideToAccountBankPhone;
- $this->hideToAccountBankAddress = $hideToAccountBankAddress;
-
- // To account text
- $this->textToAccountTitle = $this->getTextToAccountTitle($textToAccountTitle);
- $this->textToAccountNumber = $this->getTextToAccountNumber($textToAccountNumber);
-
- // Detail Information Hide checker
- $this->hideDetails = $hideDetails;
- $this->hideDetailTitle = $hideDetailTitle;
- $this->hideDetailDate = $hideDetailDate;
- $this->hideDetailPaymentMethod = $hideDetailPaymentMethod;
- $this->hideDetailReference = $hideDetailReference;
- $this->hideDetailDescription = $hideDetailDescription;
- $this->hideDetailAmount = $hideDetailAmount;
-
- // Related Information Text
- $this->textDetailTitle = $this->getTextDetailTitle($textDetailTitle);
- $this->textDetailDate = $this->getTextDetailDate($textDetailDate);
- $this->textDetailPaymentMethod = $this->getTextDetailPaymentMethod($textDetailPaymentMethod);
- $this->textDetailReference = $this->getTextDetailReference($textDetailReference);
- $this->textDetailDescription = $this->getTextDetailDescription($textDetailDescription);
- $this->textDetailAmount = $this->getTextDetailAmount($textDetailAmount);
- }
-
- protected function getTextFromAccountTitle($textToAccountTitle)
- {
- if (!empty($textToAccountTitle)) {
- return $textToAccountTitle;
- }
-
- return 'transfers.from_account';
- }
-
- protected function getTextFromAccountNumber($textFromAccountNumber)
- {
- if (!empty($textFromAccountNumber)) {
- return $textFromAccountNumber;
- }
-
- return 'accounts.number';
- }
-
- protected function getTextToAccountTitle($textFromAccountTitle)
- {
- if (!empty($textFromAccountTitle)) {
- return $textFromAccountTitle;
- }
-
- return 'transfers.to_account';
- }
-
- protected function getTextToAccountNumber($textToAccountNumber)
- {
- if (!empty($textToAccountNumber)) {
- return $textToAccountNumber;
- }
-
- return 'accounts.number';
- }
-
- protected function getTextDetailTitle($textDetailTitle)
- {
- if (!empty($textDetailTitle)) {
- return $textDetailTitle;
- }
-
- return 'transfers.details';
- }
-
- protected function getTextDetailDate($textDetailDate)
- {
- if (!empty($textDetailDate)) {
- return $textDetailDate;
- }
-
- return 'general.date';
- }
-
- protected function getTextDetailPaymentMethod($textDetailPaymentMethod)
- {
- if (!empty($textDetailPaymentMethod)) {
- return $textDetailPaymentMethod;
- }
-
- return 'general.payment_methods';
- }
-
- protected function getTextDetailReference($textDetailReference)
- {
- if (!empty($textDetailReference)) {
- return $textDetailReference;
- }
-
- return 'general.reference';
- }
-
- protected function getTextDetailDescription($textDetailDescription)
- {
- if (!empty($textDetailDescription)) {
- return $textDetailDescription;
- }
-
- return 'general.description';
- }
-
- protected function getTextDetailAmount($textDetailAmount)
- {
- if (!empty($textDetailAmount)) {
- return $textDetailAmount;
- }
-
- return 'general.amount';
- }
-}
diff --git a/app/Abstracts/View/Components/Transfers/Show.php b/app/Abstracts/View/Components/Transfers/Show.php
new file mode 100644
index 000000000..fd06b53a9
--- /dev/null
+++ b/app/Abstracts/View/Components/Transfers/Show.php
@@ -0,0 +1,46 @@
+model = $model;
+ $this->transfer = $this->getTransfer($model, $transfer);
+ $this->template = ! empty($template) ? $template : setting('transfer.template');
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ protected function getTransfer($model, $transfer)
+ {
+ if (! empty($model)) {
+ return $model;
+ }
+
+ if (! empty($transfer)) {
+ return $transfer;
+ }
+
+ return false;
+ }
+}
diff --git a/app/Abstracts/View/Components/Transfers/Template.php b/app/Abstracts/View/Components/Transfers/Template.php
new file mode 100644
index 000000000..4e3b161b4
--- /dev/null
+++ b/app/Abstracts/View/Components/Transfers/Template.php
@@ -0,0 +1,46 @@
+model = $model;
+ $this->transfer = $this->getTransfer($model, $transfer);
+ $this->template = ! empty($template) ? $template : setting('transfer.template');
+
+ // Set Parent data
+ $this->setParentData();
+ }
+
+ protected function getTransfer($model, $transfer)
+ {
+ if (! empty($model)) {
+ return $model;
+ }
+
+ if (! empty($transfer)) {
+ return $transfer;
+ }
+
+ return false;
+ }
+}
diff --git a/app/Abstracts/Widget.php b/app/Abstracts/Widget.php
index 82bbefd6b..92620a984 100644
--- a/app/Abstracts/Widget.php
+++ b/app/Abstracts/Widget.php
@@ -2,8 +2,11 @@
namespace App\Abstracts;
+use App\Models\Common\Report;
use App\Traits\Charts;
use App\Utilities\Date;
+use App\Utilities\Reports;
+use Illuminate\Support\Str;
abstract class Widget
{
@@ -14,11 +17,15 @@ abstract class Widget
public $default_name = '';
public $default_settings = [
- 'width' => 'col-md-4',
+ 'width' => 'w-full lg:w-2/4 px-12 my-8',
];
+ public $description = '';
+
+ public $report_class = '';
+
public $views = [
- 'header' => 'partials.widgets.standard_header',
+ 'header' => 'components.widgets.header',
];
public function __construct($model = null)
@@ -36,6 +43,47 @@ abstract class Widget
return $this->default_settings;
}
+ public function getDescription()
+ {
+ return trans($this->description);
+ }
+
+ public function getReportUrl(): string
+ {
+ $empty_url = '';
+
+ if (empty($this->report_class)) {
+ return $empty_url;
+ }
+
+ if (Reports::isModule($this->report_class) && Reports::isModuleDisabled($this->report_class)) {
+ $alias = Reports::getModuleAlias($this->report_class);
+
+ return route('apps.app.show', [
+ 'alias' => $alias,
+ 'utm_source' => 'widget',
+ 'utm_medium' => 'app',
+ 'utm_campaign' => Str::snake(Str::camel($alias)),
+ ]);
+ }
+
+ if (! class_exists($this->report_class)) {
+ return $empty_url;
+ }
+
+ if (Reports::cannotRead($this->report_class)) {
+ return $empty_url;
+ }
+
+ $model = Report::where('class', $this->report_class)->first();
+
+ if (! $model instanceof Report) {
+ return route('reports.create');
+ }
+
+ return route('reports.show', $model->id);
+ }
+
public function getViews()
{
return $this->views;
diff --git a/app/Builders/Category.php b/app/Builders/Category.php
new file mode 100644
index 000000000..bee4c7707
--- /dev/null
+++ b/app/Builders/Category.php
@@ -0,0 +1,73 @@
+withChildren('sub_categories', function ($list, $parent, $relation, $level, $addChildren) {
+ $parent->load($relation);
+ $parent->level = $level;
+
+ $list->push($parent);
+
+ if ($parent->$relation->count() == 0) {
+ return;
+ }
+
+ foreach ($parent->$relation as $item) {
+ $addChildren($list, $item, $relation, $level + 1, $addChildren);
+ }
+ });
+ }
+
+ /**
+ * Get the categories excluding their children.
+ *
+ * @param array|string $columns
+ * @return \Illuminate\Support\Collection
+ */
+ public function getWithoutChildren($columns = ['*'])
+ {
+ return parent::get($columns);
+ }
+
+ /**
+ * Paginate the given query.
+ *
+ * @param int|null $perPage
+ * @param array $columns
+ * @param string $pageName
+ * @param int|null $page
+ * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
+ *
+ * @throws \InvalidArgumentException
+ */
+ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
+ {
+ $page = $page ?: Paginator::resolveCurrentPage($pageName);
+
+ $perPage = $perPage ?: $this->model->getPerPage();
+
+ $results = ($total = $this->toBase()->getCountForPagination())
+ ? $this->forPage($page, $perPage)->getWithoutChildren($columns)
+ : $this->model->newCollection();
+
+ return $this->paginator($results, $total, $perPage, $page, [
+ 'path' => Paginator::resolveCurrentPath(),
+ 'pageName' => $pageName,
+ ]);
+ }
+}
diff --git a/app/BulkActions/Auth/Permissions.php b/app/BulkActions/Auth/Permissions.php
deleted file mode 100644
index 26c2b7bc6..000000000
--- a/app/BulkActions/Auth/Permissions.php
+++ /dev/null
@@ -1,19 +0,0 @@
- [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-auth-permissions',
- ],
- ];
-}
diff --git a/app/BulkActions/Auth/Roles.php b/app/BulkActions/Auth/Roles.php
deleted file mode 100644
index 6ece570de..000000000
--- a/app/BulkActions/Auth/Roles.php
+++ /dev/null
@@ -1,19 +0,0 @@
- [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-auth-roles',
- ],
- ];
-}
diff --git a/app/BulkActions/Auth/Users.php b/app/BulkActions/Auth/Users.php
index e4e778927..a19a2d515 100644
--- a/app/BulkActions/Auth/Users.php
+++ b/app/BulkActions/Auth/Users.php
@@ -11,21 +11,31 @@ class Users extends BulkAction
{
public $model = User::class;
+ public $text = 'general.users';
+
+ public $path = [
+ 'group' => 'auth',
+ 'type' => 'users',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-auth-users',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-auth-users',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-auth-users',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-auth-users',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-auth-users',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-auth-users',
],
];
diff --git a/app/BulkActions/Banking/Accounts.php b/app/BulkActions/Banking/Accounts.php
index da36ea671..33cc30319 100644
--- a/app/BulkActions/Banking/Accounts.php
+++ b/app/BulkActions/Banking/Accounts.php
@@ -11,21 +11,31 @@ class Accounts extends BulkAction
{
public $model = Account::class;
+ public $text = 'general.accounts';
+
+ public $path = [
+ 'group' => 'banking',
+ 'type' => 'accounts',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-banking-accounts',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-banking-accounts',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-banking-accounts',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-banking-accounts',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-banking-accounts',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-banking-accounts',
],
];
diff --git a/app/BulkActions/Banking/Reconciliations.php b/app/BulkActions/Banking/Reconciliations.php
index b8d3916bd..ad1e70c2a 100644
--- a/app/BulkActions/Banking/Reconciliations.php
+++ b/app/BulkActions/Banking/Reconciliations.php
@@ -10,21 +10,31 @@ class Reconciliations extends BulkAction
{
public $model = Reconciliation::class;
+ public $text = 'general.reconciliations';
+
+ public $path = [
+ 'group' => 'banking',
+ 'type' => 'reconciliations',
+ ];
+
public $actions = [
- 'reconcile' => [
- 'name' => 'reconciliations.reconcile',
- 'message' => 'bulk_actions.message.reconcile',
- 'permission' => 'update-banking-reconciliations',
+ 'reconcile' => [
+ 'icon' => 'published_with_changes',
+ 'name' => 'reconciliations.reconcile',
+ 'message' => 'bulk_actions.message.reconcile',
+ 'permission' => 'update-banking-reconciliations',
],
- 'unreconcile' => [
- 'name' => 'reconciliations.unreconcile',
- 'message' => 'bulk_actions.message.unreconcile',
- 'permission' => 'update-banking-reconciliations',
+ 'unreconcile' => [
+ 'icon' => 'layers_clear',
+ 'name' => 'reconciliations.unreconcile',
+ 'message' => 'bulk_actions.message.unreconcile',
+ 'permission' => 'update-banking-reconciliations',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-banking-reconciliations',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-banking-reconciliations',
],
];
diff --git a/app/BulkActions/Banking/Transactions.php b/app/BulkActions/Banking/Transactions.php
index eb53cc14d..64441b9a2 100644
--- a/app/BulkActions/Banking/Transactions.php
+++ b/app/BulkActions/Banking/Transactions.php
@@ -10,16 +10,25 @@ class Transactions extends BulkAction
{
public $model = Transaction::class;
+ public $text = 'general.transactions';
+
+ public $path = [
+ 'group' => 'banking',
+ 'type' => 'transactions',
+ ];
+
public $actions = [
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-banking-transactions',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-banking-transactions',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
],
];
diff --git a/app/BulkActions/Banking/Transfers.php b/app/BulkActions/Banking/Transfers.php
index d3c91c108..8c8f912e9 100644
--- a/app/BulkActions/Banking/Transfers.php
+++ b/app/BulkActions/Banking/Transfers.php
@@ -11,16 +11,25 @@ class Transfers extends BulkAction
{
public $model = Transfer::class;
+ public $text = 'general.transfers';
+
+ public $path = [
+ 'group' => 'banking',
+ 'type' => 'transfers',
+ ];
+
public $actions = [
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-banking-transfers',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-banking-transfers',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
],
];
diff --git a/app/BulkActions/Common/Companies.php b/app/BulkActions/Common/Companies.php
index 6c9b49981..437beab02 100644
--- a/app/BulkActions/Common/Companies.php
+++ b/app/BulkActions/Common/Companies.php
@@ -11,16 +11,25 @@ class Companies extends BulkAction
{
public $model = Company::class;
+ public $text = 'general.companies';
+
+ public $path = [
+ 'group' => 'common',
+ 'type' => 'companies',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-common-companies',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-common-companies',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-common-companies',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-common-companies',
],
];
diff --git a/app/BulkActions/Common/Dashboards.php b/app/BulkActions/Common/Dashboards.php
index 3967c121b..fbb288022 100644
--- a/app/BulkActions/Common/Dashboards.php
+++ b/app/BulkActions/Common/Dashboards.php
@@ -11,21 +11,31 @@ class Dashboards extends BulkAction
{
public $model = Dashboard::class;
+ public $text = 'general.dashboards';
+
+ public $path = [
+ 'group' => 'common',
+ 'type' => 'dashboards',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-common-dashboards',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-common-dashboards',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-common-dashboards',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-common-dashboards',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-common-dashboards',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-common-dashboards',
],
];
diff --git a/app/BulkActions/Common/Items.php b/app/BulkActions/Common/Items.php
index b2e704247..e4c419445 100644
--- a/app/BulkActions/Common/Items.php
+++ b/app/BulkActions/Common/Items.php
@@ -11,30 +11,41 @@ class Items extends BulkAction
{
public $model = Item::class;
+ public $text = 'general.items';
+
+ public $path = [
+ 'group' => 'common',
+ 'type' => 'items',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'path' => ['group' => 'common', 'type' => 'items'],
- 'type' => '*',
- 'permission' => 'update-common-items',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'path' => ['group' => 'common', 'type' => 'items'],
+ 'type' => '*',
+ 'permission' => 'update-common-items',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'path' => ['group' => 'common', 'type' => 'items'],
- 'type' => '*',
- 'permission' => 'update-common-items',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'path' => ['group' => 'common', 'type' => 'items'],
+ 'type' => '*',
+ 'permission' => 'update-common-items',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-common-items',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-common-items',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
],
];
diff --git a/app/BulkActions/Purchases/Bills.php b/app/BulkActions/Purchases/Bills.php
index e3f220692..7000eb289 100644
--- a/app/BulkActions/Purchases/Bills.php
+++ b/app/BulkActions/Purchases/Bills.php
@@ -15,46 +15,39 @@ class Bills extends BulkAction
{
public $model = Document::class;
- public $actions = [
- 'paid' => [
- 'name' => 'bills.mark_paid',
- 'message' => 'bulk_actions.message.paid',
- 'permission' => 'update-purchases-bills',
- ],
- 'received' => [
- 'name' => 'bills.mark_received',
- 'message' => 'bulk_actions.message.received',
- 'permission' => 'update-purchases-bills',
- ],
- 'cancelled' => [
- 'name' => 'general.cancel',
- 'message' => 'bulk_actions.message.cancelled',
- 'permission' => 'update-purchases-bills',
- ],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-purchases-bills',
- ],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
- ],
+ public $text = 'general.bills';
+
+ public $path = [
+ 'group' => 'purchases',
+ 'type' => 'bills',
];
- public function paid($request)
- {
- $bills = $this->getSelectedRecords($request);
-
- foreach ($bills as $bill) {
- if ($bill->status == 'paid') {
- continue;
- }
-
- $this->dispatch(new CreateBankingDocumentTransaction($bill, ['type' => 'expense']));
- }
- }
+ public $actions = [
+ 'received' => [
+ 'icon' => 'send',
+ 'name' => 'bills.mark_received',
+ 'message' => 'bulk_actions.message.received',
+ 'permission' => 'update-purchases-bills',
+ ],
+ 'cancelled' => [
+ 'icon' => 'cancel',
+ 'name' => 'general.cancel',
+ 'message' => 'bulk_actions.message.cancelled',
+ 'permission' => 'update-purchases-bills',
+ ],
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-purchases-bills',
+ ],
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
+ ],
+ ];
public function received($request)
{
diff --git a/app/BulkActions/Purchases/Payments.php b/app/BulkActions/Purchases/Payments.php
deleted file mode 100644
index 862f1cc30..000000000
--- a/app/BulkActions/Purchases/Payments.php
+++ /dev/null
@@ -1,37 +0,0 @@
- [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
- ],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-purchases-payments',
- ],
- ];
-
- public function destroy($request)
- {
- $this->deleteTransactions($request);
- }
-
- public function export($request)
- {
- $selected = $this->getSelectedInput($request);
-
- return $this->exportExcel(new Export($selected), trans_choice('general.payments', 2));
- }
-}
diff --git a/app/BulkActions/Purchases/Vendors.php b/app/BulkActions/Purchases/Vendors.php
index 92b39286a..8271347f5 100644
--- a/app/BulkActions/Purchases/Vendors.php
+++ b/app/BulkActions/Purchases/Vendors.php
@@ -10,26 +10,37 @@ class Vendors extends BulkAction
{
public $model = Contact::class;
+ public $text = 'general.vendors';
+
+ public $path = [
+ 'group' => 'purchases',
+ 'type' => 'vendors',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-purchases-vendors',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-purchases-vendors',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-purchases-vendors',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-purchases-vendors',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-purchases-vendors',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-purchases-vendors',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
],
];
diff --git a/app/BulkActions/Sales/Customers.php b/app/BulkActions/Sales/Customers.php
index 8e7f57ed5..acde4026e 100644
--- a/app/BulkActions/Sales/Customers.php
+++ b/app/BulkActions/Sales/Customers.php
@@ -10,26 +10,37 @@ class Customers extends BulkAction
{
public $model = Contact::class;
+ public $text = 'general.customers';
+
+ public $path = [
+ 'group' => 'sales',
+ 'type' => 'customers',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-sales-customers',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-sales-customers',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-sales-customers',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-sales-customers',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-sales-customers',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-sales-customers',
],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
],
];
diff --git a/app/BulkActions/Sales/Invoices.php b/app/BulkActions/Sales/Invoices.php
index 59c94814e..e70a04b53 100644
--- a/app/BulkActions/Sales/Invoices.php
+++ b/app/BulkActions/Sales/Invoices.php
@@ -15,46 +15,39 @@ class Invoices extends BulkAction
{
public $model = Document::class;
- public $actions = [
- 'paid' => [
- 'name' => 'invoices.mark_paid',
- 'message' => 'bulk_actions.message.paid',
- 'permission' => 'update-sales-invoices',
- ],
- 'sent' => [
- 'name' => 'invoices.mark_sent',
- 'message' => 'bulk_actions.message.sent',
- 'permission' => 'update-sales-invoices',
- ],
- 'cancelled' => [
- 'name' => 'general.cancel',
- 'message' => 'bulk_actions.message.cancelled',
- 'permission' => 'update-sales-invoices',
- ],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-sales-invoices',
- ],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
- ],
+ public $text = 'general.invoices';
+
+ public $path = [
+ 'group' => 'sales',
+ 'type' => 'invoices',
];
- public function paid($request)
- {
- $invoices = $this->getSelectedRecords($request);
-
- foreach ($invoices as $invoice) {
- if ($invoice->status == 'paid') {
- continue;
- }
-
- event(new PaymentReceived($invoice, ['type' => 'income']));
- }
- }
+ public $actions = [
+ 'sent' => [
+ 'icon' => 'send',
+ 'name' => 'invoices.mark_sent',
+ 'message' => 'bulk_actions.message.sent',
+ 'permission' => 'update-sales-invoices',
+ ],
+ 'cancelled' => [
+ 'icon' => 'cancel',
+ 'name' => 'general.cancel',
+ 'message' => 'bulk_actions.message.cancelled',
+ 'permission' => 'update-sales-invoices',
+ ],
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-sales-invoices',
+ ],
+ 'export' => [
+ 'icon' => 'file_download',
+ 'name' => 'general.export',
+ 'message' => 'bulk_actions.message.export',
+ 'type' => 'download',
+ ],
+ ];
public function sent($request)
{
diff --git a/app/BulkActions/Sales/Revenues.php b/app/BulkActions/Sales/Revenues.php
deleted file mode 100644
index 199ce6431..000000000
--- a/app/BulkActions/Sales/Revenues.php
+++ /dev/null
@@ -1,37 +0,0 @@
- [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-sales-revenues',
- ],
- 'export' => [
- 'name' => 'general.export',
- 'message' => 'bulk_actions.message.export',
- 'type' => 'download',
- ],
- ];
-
- public function destroy($request)
- {
- $this->deleteTransactions($request);
- }
-
- public function export($request)
- {
- $selected = $this->getSelectedInput($request);
-
- return $this->exportExcel(new Export($selected), trans_choice('general.revenues', 2));
- }
-}
diff --git a/app/BulkActions/Settings/Categories.php b/app/BulkActions/Settings/Categories.php
index 3e82cbdf2..ed63dd003 100644
--- a/app/BulkActions/Settings/Categories.php
+++ b/app/BulkActions/Settings/Categories.php
@@ -11,21 +11,31 @@ class Categories extends BulkAction
{
public $model = Category::class;
+ public $text = 'general.categories';
+
+ public $path = [
+ 'group' => 'settings',
+ 'type' => 'categories',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-settings-categories',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-settings-categories',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-settings-categories',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-settings-categories',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-settings-categories',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-settings-categories',
],
];
diff --git a/app/BulkActions/Settings/Currencies.php b/app/BulkActions/Settings/Currencies.php
index 8f0f11913..70cd976db 100644
--- a/app/BulkActions/Settings/Currencies.php
+++ b/app/BulkActions/Settings/Currencies.php
@@ -11,21 +11,31 @@ class Currencies extends BulkAction
{
public $model = Currency::class;
+ public $text = 'general.currencies';
+
+ public $path = [
+ 'group' => 'settings',
+ 'type' => 'currencies',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-settings-currencies',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-settings-currencies',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-settings-currencies',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-settings-currencies',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-settings-currencies',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-settings-currencies',
],
];
diff --git a/app/BulkActions/Settings/Taxes.php b/app/BulkActions/Settings/Taxes.php
index a3f21bf85..a6d699bf7 100644
--- a/app/BulkActions/Settings/Taxes.php
+++ b/app/BulkActions/Settings/Taxes.php
@@ -11,21 +11,31 @@ class Taxes extends BulkAction
{
public $model = Tax::class;
+ public $text = 'general.taxes';
+
+ public $path = [
+ 'group' => 'settings',
+ 'type' => 'taxes',
+ ];
+
public $actions = [
- 'enable' => [
- 'name' => 'general.enable',
- 'message' => 'bulk_actions.message.enable',
- 'permission' => 'update-settings-taxes',
+ 'enable' => [
+ 'icon' => 'check_circle',
+ 'name' => 'general.enable',
+ 'message' => 'bulk_actions.message.enable',
+ 'permission' => 'update-settings-taxes',
],
- 'disable' => [
- 'name' => 'general.disable',
- 'message' => 'bulk_actions.message.disable',
- 'permission' => 'update-settings-taxes',
+ 'disable' => [
+ 'icon' => 'hide_source',
+ 'name' => 'general.disable',
+ 'message' => 'bulk_actions.message.disable',
+ 'permission' => 'update-settings-taxes',
],
- 'delete' => [
- 'name' => 'general.delete',
- 'message' => 'bulk_actions.message.delete',
- 'permission' => 'delete-settings-taxes',
+ 'delete' => [
+ 'icon' => 'delete',
+ 'name' => 'general.delete',
+ 'message' => 'bulk_actions.message.delete',
+ 'permission' => 'delete-settings-taxes',
],
];
diff --git a/app/Console/Commands/BillReminder.php b/app/Console/Commands/BillReminder.php
index 8b6a78535..85c69e6e1 100644
--- a/app/Console/Commands/BillReminder.php
+++ b/app/Console/Commands/BillReminder.php
@@ -8,6 +8,7 @@ use App\Models\Document\Document;
use App\Notifications\Purchase\Bill as Notification;
use App\Utilities\Date;
use Illuminate\Console\Command;
+use Illuminate\Database\Eloquent\Builder;
class BillReminder extends Command
{
@@ -35,22 +36,29 @@ class BillReminder extends Command
// Disable model cache
config(['laravel-model-caching.enabled' => false]);
+ $today = Date::today();
+
+ $start_date = $today->copy()->subWeek()->toDateString() . ' 00:00:00';
+ $end_date = $today->copy()->addMonth()->toDateString() . ' 23:59:59';
+
// Get all companies
- $companies = Company::enabled()->with('bills')->cursor();
+ $companies = Company::whereHas('bills', function (Builder $query) use ($start_date, $end_date) {
+ $query->allCompanies();
+ $query->whereBetween('due_at', [$start_date, $end_date]);
+ $query->accrued();
+ $query->notPaid();
+ })
+ ->enabled()
+ ->cursor();
foreach ($companies as $company) {
- // Has company bills
- if (!$company->bills->count()) {
- continue;
- }
-
$this->info('Sending bill reminders for ' . $company->name . ' company.');
// Set company
$company->makeCurrent();
// Don't send reminders if disabled
- if (!setting('schedule.send_bill_reminder')) {
+ if (! setting('schedule.send_bill_reminder')) {
$this->info('Bill reminders disabled by ' . $company->name . '.');
continue;
@@ -74,9 +82,11 @@ class BillReminder extends Command
$date = Date::today()->addDays($day)->toDateString();
// Get upcoming bills
- $bills = Document::bill()->with('contact')->accrued()->notPaid()->due($date)->cursor();
+ $bills = Document::with('contact')->bill()->accrued()->notPaid()->due($date)->cursor();
foreach ($bills as $bill) {
+ $this->info($bill->document_number . ' bill reminded.');
+
try {
event(new DocumentReminded($bill, Notification::class));
} catch (\Throwable $e) {
diff --git a/app/Console/Commands/Install.php b/app/Console/Commands/Install.php
index f18bec765..a1d83e68a 100644
--- a/app/Console/Commands/Install.php
+++ b/app/Console/Commands/Install.php
@@ -2,9 +2,10 @@
namespace App\Console\Commands;
-use Session;
use App\Utilities\Installer;
use Illuminate\Console\Command;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Session;
class Install extends Command
{
@@ -74,15 +75,17 @@ class Install extends Command
Installer::createDefaultEnvFile();
$this->line('Creating database tables');
- if (!$this->createDatabaseTables()) {
+ if (! $this->createDatabaseTables()) {
return self::CMD_ERROR;
}
- $this->line('Creating company');
- Installer::createCompany($this->company_name, $this->company_email, $this->locale);
+ DB::transaction(function () {
+ $this->line('Creating company');
+ Installer::createCompany($this->company_name, $this->company_email, $this->locale);
- $this->line('Creating admin');
- Installer::createUser($this->admin_email, $this->admin_password, $this->locale);
+ $this->line('Creating admin');
+ Installer::createUser($this->admin_email, $this->admin_password, $this->locale);
+ });
$this->line('Applying the final touches');
Installer::finalTouches();
diff --git a/app/Console/Commands/InvoiceReminder.php b/app/Console/Commands/InvoiceReminder.php
index b068941de..283bd43f2 100644
--- a/app/Console/Commands/InvoiceReminder.php
+++ b/app/Console/Commands/InvoiceReminder.php
@@ -8,6 +8,7 @@ use App\Models\Document\Document;
use App\Notifications\Sale\Invoice as Notification;
use App\Utilities\Date;
use Illuminate\Console\Command;
+use Illuminate\Database\Eloquent\Builder;
class InvoiceReminder extends Command
{
@@ -35,22 +36,29 @@ class InvoiceReminder extends Command
// Disable model cache
config(['laravel-model-caching.enabled' => false]);
+ $today = Date::today();
+
+ $start_date = $today->copy()->subMonth()->toDateString() . ' 00:00:00';
+ $end_date = $today->copy()->addWeek()->toDateString() . ' 23:59:59';
+
// Get all companies
- $companies = Company::enabled()->with('invoices')->cursor();
+ $companies = Company::whereHas('invoices', function (Builder $query) use ($start_date, $end_date) {
+ $query->allCompanies();
+ $query->whereBetween('due_at', [$start_date, $end_date]);
+ $query->accrued();
+ $query->notPaid();
+ })
+ ->enabled()
+ ->cursor();
foreach ($companies as $company) {
- // Has company invoices
- if (!$company->invoices->count()) {
- continue;
- }
-
$this->info('Sending invoice reminders for ' . $company->name . ' company.');
// Set company
$company->makeCurrent();
// Don't send reminders if disabled
- if (!setting('schedule.send_invoice_reminder')) {
+ if (! setting('schedule.send_invoice_reminder')) {
$this->info('Invoice reminders disabled by ' . $company->name . '.');
continue;
@@ -74,9 +82,11 @@ class InvoiceReminder extends Command
$date = Date::today()->subDays($day)->toDateString();
// Get upcoming invoices
- $invoices = Document::invoice()->with('contact')->accrued()->notPaid()->due($date)->cursor();
+ $invoices = Document::with('contact')->invoice()->accrued()->notPaid()->due($date)->cursor();
foreach ($invoices as $invoice) {
+ $this->info($invoice->document_number . ' invoice reminded.');
+
try {
event(new DocumentReminded($invoice, Notification::class));
} catch (\Throwable $e) {
diff --git a/app/Console/Commands/RecurringCheck.php b/app/Console/Commands/RecurringCheck.php
index 297e5d4ee..54edd5ddb 100644
--- a/app/Console/Commands/RecurringCheck.php
+++ b/app/Console/Commands/RecurringCheck.php
@@ -12,6 +12,9 @@ use App\Models\Common\Recurring;
use App\Models\Document\Document;
use App\Utilities\Date;
use Illuminate\Console\Command;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Str;
class RecurringCheck extends Command
{
@@ -36,25 +39,40 @@ class RecurringCheck extends Command
*/
public function handle()
{
+ // Bind to container
+ app()->instance(static::class, $this);
+
// Disable model cache
config(['laravel-model-caching.enabled' => false]);
// Get all recurring
- $recurring = Recurring::allCompanies()->with('company')->get();
+ $recurring = Recurring::with('company')
+ /*->whereHas('recurable', function (Builder $query) {
+ $query->allCompanies();
+ })*/
+ ->active()
+ ->allCompanies()
+ ->cursor();
- $this->info('Creating recurring records ' . $recurring->count());
+ //$this->info('Total recurring: ' . $recurring->count());
+
+ $today = Date::today();
foreach ($recurring as $recur) {
if (empty($recur->company)) {
+ $this->info('Missing company.');
+
+ $recur->delete();
+
continue;
}
+ $this->info('Creating records for ' . $recur->id . ' recurring...');
+
$company_name = !empty($recur->company->name) ? $recur->company->name : 'Missing Company Name : ' . $recur->company->id;
- $this->info('Creating recurring records for ' . $company_name . ' company...');
-
// Check if company is disabled
- if (!$recur->company->enabled) {
+ if (! $recur->company->enabled) {
$this->info($company_name . ' company is disabled. Skipping...');
if (Date::parse($recur->company->updated_at)->format('Y-m-d') > Date::now()->subMonth(3)->format('Y-m-d')) {
@@ -75,7 +93,7 @@ class RecurringCheck extends Command
}
}
- if (!$has_active_users) {
+ if (! $has_active_users) {
$this->info('No active users for ' . $company_name . ' company. Skipping...');
$recur->delete();
@@ -85,31 +103,46 @@ class RecurringCheck extends Command
company($recur->company_id)->makeCurrent();
- $today = Date::today();
+ if (! $model = $recur->recurable) {
+ $this->info('Missing model.');
+
+ $recur->delete();
- if (!$model = $recur->recurable) {
continue;
}
- $schedules = $recur->getRecurringSchedule();
-
$children_count = $this->getChildrenCount($model);
+
+ $schedules = $recur->getRecurringSchedule();
$schedule_count = $schedules->count();
// All recurring created, including today
if ($children_count > ($schedule_count - 1)) {
+ $this->info('All recurring created.');
+
+ $recur->update(['status' => Recurring::COMPLETE_STATUS]);
+
continue;
}
// Recur only today
if ($children_count == ($schedule_count - 1)) {
+ $this->info('Recur only today.');
+
$this->recur($model, $recur->recurable_type, $today);
+ $recur->update(['status' => Recurring::COMPLETE_STATUS]);
+
continue;
}
- // Recur all schedules, previously failed
+ // Don't create records for the future
+ $schedules = $schedules->endsBefore($recur->getRecurringRuleTomorrowDate());
+
+ // Recur all schedules, including the previously failed ones
foreach ($schedules as $schedule) {
+ $this->info('Recur all schedules.');
+
$schedule_date = Date::parse($schedule->getStart()->format('Y-m-d'));
$this->recur($model, $recur->recurable_type, $schedule_date);
@@ -117,13 +150,16 @@ class RecurringCheck extends Command
}
Company::forgetCurrent();
+
+ // Remove from container
+ app()->forgetInstance(static::class);
}
protected function recur($model, $type, $schedule_date)
{
- \DB::transaction(function () use ($model, $type, $schedule_date) {
- /** @var Document $clone */
- if (!$clone = $this->getClone($model, $schedule_date)) {
+ DB::transaction(function () use ($model, $type, $schedule_date) {
+ /** @var Document|Transaction $clone */
+ if (! $clone = $this->getClone($model, $schedule_date)) {
return;
}
@@ -185,13 +221,12 @@ class RecurringCheck extends Command
$clone = $model->duplicate();
- $date_field = $this->getDateField($model);
-
// Days between issued and due date
- $diff_days = Date::parse($clone->due_at)->diffInDays(Date::parse($clone->$date_field));
+ $diff_days = Date::parse($model->due_at)->diffInDays(Date::parse($model->issued_at));
+ $clone->type = $this->getRealType($clone->type);
$clone->parent_id = $model->id;
- $clone->$date_field = $schedule_date->format('Y-m-d');
+ $clone->issued_at = $schedule_date->format('Y-m-d');
$clone->due_at = $schedule_date->copy()->addDays($diff_days)->format('Y-m-d');
$clone->created_from = 'core::recurring';
$clone->save();
@@ -213,6 +248,7 @@ class RecurringCheck extends Command
$clone = $model->duplicate();
+ $clone->type = $this->getRealType($clone->type);
$clone->parent_id = $model->id;
$clone->paid_at = $schedule_date->format('Y-m-d');
$clone->created_from = 'core::recurring';
@@ -230,9 +266,7 @@ class RecurringCheck extends Command
return true;
}
- $table = $this->getTable($model);
-
- $already_cloned = \DB::table($table)
+ $already_cloned = DB::table($model->getTable())
->where('parent_id', $model->id)
->whereDate($date_field, $schedule_date)
->value('id');
@@ -247,9 +281,7 @@ class RecurringCheck extends Command
protected function getChildrenCount($model)
{
- $table = $this->getTable($model);
-
- return \DB::table($table)
+ return DB::table($model->getTable())
->where('parent_id', $model->id)
->count();
}
@@ -265,14 +297,8 @@ class RecurringCheck extends Command
}
}
- protected function getTable($model)
+ public function getRealType(string $recurring_type): string
{
- if ($model instanceof Transaction) {
- return 'transactions';
- }
-
- if ($model instanceof Document) {
- return 'documents';
- }
+ return Str::replace('-recurring', '', $recurring_type);
}
}
diff --git a/app/Console/Commands/ReportCache.php b/app/Console/Commands/ReportCache.php
deleted file mode 100644
index c11dffc0e..000000000
--- a/app/Console/Commands/ReportCache.php
+++ /dev/null
@@ -1,83 +0,0 @@
- false]);
-
- // Get all companies
- $companies = Company::enabled()->withCount('reports')->cursor();
-
- foreach ($companies as $company) {
- // Has company reports
- if (!$company->reports_count) {
- continue;
- }
-
- $this->info('Calculating reports for ' . $company->name . ' company.');
-
- // Set company
- $company->makeCurrent();
-
- $this->cacheReportsOfCurrentCompany();
- }
-
- Company::forgetCurrent();
- }
-
- protected function cacheReportsOfCurrentCompany()
- {
- $reports = Report::orderBy('name')->get();
-
- foreach ($reports as $report) {
- try {
- $class = Utility::getClassInstance($report, false);
-
- if (empty($class)) {
- continue;
- }
-
- $ttl = 3600 * 6; // 6 hours
-
- Cache::forget('reports.totals.' . $report->id);
-
- Cache::remember('reports.totals.' . $report->id, $ttl, function () use ($class) {
- return $class->getGrandTotal();
- });
- } catch (\Throwable $e) {
- $this->error($e->getMessage());
-
- report($e);
- }
- }
- }
-}
diff --git a/app/Console/Commands/SampleData.php b/app/Console/Commands/SampleData.php
old mode 100755
new mode 100644
index 43cf3d266..37e26387f
--- a/app/Console/Commands/SampleData.php
+++ b/app/Console/Commands/SampleData.php
@@ -12,7 +12,7 @@ class SampleData extends Command
*
* @var string
*/
- protected $signature = 'sample-data:seed {--count=100 : total records for each item}';
+ protected $signature = 'sample-data:seed {--count=100 : total records for each item} {--company=1 : the company id}';
/**
* The console command description.
diff --git a/app/Console/Commands/UpdateDb.php b/app/Console/Commands/UpdateDb.php
new file mode 100644
index 000000000..3ed805318
--- /dev/null
+++ b/app/Console/Commands/UpdateDb.php
@@ -0,0 +1,43 @@
+argument('alias');
+ $company_id = $this->argument('company');
+ $new = $this->argument('new');
+ $old = $this->argument('old');
+
+ company($company_id)->makeCurrent();
+
+ // Disable model cache during update
+ config(['laravel-model-caching.enabled' => false]);
+
+ event(new UpdateFinished($alias, $new, $old));
+ }
+}
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index aaf88ec16..88648f393 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -29,7 +29,6 @@ class Kernel extends ConsoleKernel
$schedule_time = config('app.schedule_time');
- $schedule->command('report:cache')->everySixHours();
$schedule->command('reminder:invoice')->dailyAt($schedule_time);
$schedule->command('reminder:bill')->dailyAt($schedule_time);
$schedule->command('recurring:check')->dailyAt($schedule_time);
diff --git a/app/Console/Stubs/Modules/component.stub b/app/Console/Stubs/Modules/component.stub
index 916f91861..a5100a344 100644
--- a/app/Console/Stubs/Modules/component.stub
+++ b/app/Console/Stubs/Modules/component.stub
@@ -2,7 +2,7 @@
namespace $NAMESPACE$;
-use Illuminate\View\Component;
+use App\Abstracts\View\Component;
class $CLASS$ extends Component
{
diff --git a/app/Console/Stubs/Modules/package.stub b/app/Console/Stubs/Modules/package.stub
index d3cc7469b..bbbc4984d 100644
--- a/app/Console/Stubs/Modules/package.stub
+++ b/app/Console/Stubs/Modules/package.stub
@@ -2,16 +2,16 @@
"private": true,
"scripts": {
"dev": "npm run development",
- "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
- "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
- "watch-poll": "npm run watch -- --watch-poll",
- "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
+ "development": "mix",
+ "watch": "mix watch",
+ "watch-poll": "mix watch -- --watch-options-poll=1000",
+ "hot": "mix watch --hot",
"prod": "npm run production",
- "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
+ "production": "mix --production"
},
"devDependencies": {
"cross-env": "^5.2.1",
- "laravel-mix": "^4.1.4",
- "laravel-mix-merge-manifest": "^0.1.2"
+ "laravel-mix": "^6.0.39",
+ "resolve-url-loader": "^5.0.0"
}
}
diff --git a/app/Console/Stubs/Modules/scaffold/provider.stub b/app/Console/Stubs/Modules/scaffold/provider.stub
index ed514d200..da0ecbc97 100644
--- a/app/Console/Stubs/Modules/scaffold/provider.stub
+++ b/app/Console/Stubs/Modules/scaffold/provider.stub
@@ -14,6 +14,7 @@ class $NAME$ extends Provider
*/
public function register()
{
+ //$this->loadConfig();
$this->loadRoutes();
}
@@ -28,7 +29,6 @@ class $NAME$ extends Provider
$this->loadViewComponents();
$this->loadTranslations();
$this->loadMigrations();
- //$this->loadConfig();
}
/**
diff --git a/app/Console/Stubs/Modules/views/index.stub b/app/Console/Stubs/Modules/views/index.stub
index 048aef542..ad091aa34 100644
--- a/app/Console/Stubs/Modules/views/index.stub
+++ b/app/Console/Stubs/Modules/views/index.stub
@@ -1,9 +1,9 @@
-@extends('layouts.admin')
+
- This view is loaded from module: {!! config('$ALIAS$.name') !!}
-
+ This view is loaded from module: {!! config('$ALIAS$.name') !!}
+ Hello World
-@section('content')
- Hello World
-
-