akaunting/app/Abstracts/View/Components/Transactions/Show.php

1128 lines
32 KiB
PHP
Raw Normal View History

2021-06-24 10:52:49 +00:00
<?php
2022-06-01 07:15:55 +00:00
namespace App\Abstracts\View\Components\Transactions;
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
use App\Abstracts\View\Component;
2021-06-24 10:52:49 +00:00
use App\Models\Common\Media;
use App\Traits\DateTime;
use App\Traits\Transactions;
use App\Utilities\Modules;
2022-06-01 07:15:55 +00:00
use Illuminate\Support\Facades\File;
2021-06-24 10:52:49 +00:00
use Illuminate\Support\Facades\Log;
2022-06-01 07:15:55 +00:00
use Illuminate\Support\Facades\Storage;
2021-06-24 10:52:49 +00:00
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
2022-06-01 07:15:55 +00:00
use Intervention\Image\Facades\Image;
2021-06-24 10:52:49 +00:00
use Intervention\Image\Exception\NotReadableException;
2022-06-01 07:15:55 +00:00
use App\Traits\ViewComponents;
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
abstract class Show extends Component
2021-06-24 10:52:49 +00:00
{
2022-06-01 07:15:55 +00:00
use DateTime, Transactions, ViewComponents;
public const OBJECT_TYPE = 'transaction';
public const DEFAULT_TYPE = 'transaction';
public const DEFAULT_PLURAL_TYPE = 'transactions';
2021-06-24 10:52:49 +00:00
public $type;
public $transaction;
/** @var string */
public $transactionTemplate;
/** @var string */
public $logo;
2021-06-25 06:44:30 +00:00
/** @var array */
public $payment_methods;
2021-06-24 10:52:49 +00:00
public $date_format;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonAddNew;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonMoreActions;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonEdit;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonDuplicate;
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
/** @var bool */
public $hideButtonConnect;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonPrint;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonShare;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonEmail;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonPdf;
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
/** @var bool */
public $hideButtonEnd;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideButtonDelete;
2021-06-24 10:52:49 +00:00
/** @var string */
2021-06-25 06:44:30 +00:00
public $checkButtonReconciled;
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideDivider1;
/** @var bool */
public $hideDivider2;
2021-06-25 06:44:30 +00:00
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideDivider3;
2021-06-25 06:44:30 +00:00
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideDivider4;
2021-06-24 10:52:49 +00:00
/** @var string */
public $permissionCreate;
/** @var string */
public $permissionUpdate;
/** @var string */
public $permissionDelete;
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonAddNew;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonEdit;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonDuplicate;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonPrint;
2021-06-24 10:52:49 +00:00
/** @var string */
public $routeContactShow;
2022-06-01 07:15:55 +00:00
/** @var string */
public $shareRoute;
2021-06-25 06:44:30 +00:00
/** @var string */
public $signedUrl;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonEmail;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeButtonPdf;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
2022-06-01 07:15:55 +00:00
public $routeButtonEnd;
2021-06-24 10:52:49 +00:00
/** @var string */
2022-06-01 07:15:55 +00:00
public $routeButtonDelete;
2021-06-24 10:52:49 +00:00
/** @var string */
2022-06-01 07:15:55 +00:00
public $textDeleteModal;
2021-06-24 10:52:49 +00:00
/** @var bool */
2021-06-25 06:44:30 +00:00
public $hideCompany;
2021-06-24 10:52:49 +00:00
/** @var bool */
public $hideCompanyLogo;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideCompanyDetails;
/** @var bool */
public $hideCompanyName;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideCompanyAddress;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideCompanyTaxNumber;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideCompanyPhone;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideCompanyEmail;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideContentTitle;
2022-06-01 07:15:55 +00:00
/** @var bool */
public $hideNumber;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hidePaidAt;
/** @var bool */
public $hideAccount;
/** @var bool */
public $hideCategory;
/** @var bool */
public $hidePaymentMethods;
/** @var bool */
public $hideReference;
/** @var bool */
public $hideDescription;
/** @var bool */
public $hideAmount;
2022-06-01 07:15:55 +00:00
/** @var string */
public $textButtonAddNew;
2021-06-25 06:44:30 +00:00
/** @var string */
public $textContentTitle;
2022-06-01 07:15:55 +00:00
/** @var string */
public $textNumber;
2021-06-25 06:44:30 +00:00
/** @var string */
public $textPaidAt;
/** @var string */
public $textAccount;
/** @var string */
public $textCategory;
/** @var string */
public $textPaymentMethods;
/** @var string */
public $textReference;
/** @var string */
public $textDescription;
/** @var string */
public $textAmount;
/** @var string */
public $textPaidBy;
/** @var bool */
public $hideContact;
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactInfo;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactName;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactAddress;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactTaxNumber;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactPhone;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-06-24 10:52:49 +00:00
public $hideContactEmail;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelated;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelatedDocumentNumber;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelatedContact;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelatedDocumentDate;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelatedDocumentAmount;
2021-06-25 06:44:30 +00:00
/** @var bool */
2021-11-22 20:09:01 +00:00
public $hideRelatedAmount;
2021-06-24 10:52:49 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedTransansaction;
2021-06-24 10:52:49 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedDocumentNumber;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedContact;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedDocumentDate;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedDocumentAmount;
2021-06-24 10:52:49 +00:00
/** @var string */
2021-11-22 20:09:01 +00:00
public $textRelatedAmount;
2021-06-25 06:44:30 +00:00
/** @var string */
public $routeDocumentShow;
2021-06-24 10:52:49 +00:00
/** @var string */
public $routeTransactionShow;
2021-06-24 10:52:49 +00:00
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideSchedule;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideChildren;
2021-06-25 06:44:30 +00:00
/** @var bool */
public $hideTransfer;
2021-06-25 06:44:30 +00:00
/** @var bool */
2022-06-01 07:15:55 +00:00
public $hideAttachment;
2021-06-25 06:44:30 +00:00
2022-06-01 07:15:55 +00:00
public $attachment;
2021-06-25 06:44:30 +00:00
2022-06-01 07:15:55 +00:00
/** @var array */
public $connectTranslations;
2021-06-24 10:52:49 +00:00
/** @var string */
public $textRecurringType;
/** @var bool */
public $hideRecurringMessage;
/** @var bool */
public $hideCreated;
2021-06-24 10:52:49 +00:00
/**
* Create a new component instance.
*
* @return void
*/
public function __construct(
2021-06-25 06:44:30 +00:00
$type, $transaction, $transactionTemplate = '', $logo = '', array $payment_methods = [],
2022-06-01 07:15:55 +00:00
bool $hideButtonAddNew = false, bool $hideButtonMoreActions = false, bool $hideButtonEdit = false, bool $hideButtonDuplicate = false, bool $hideButtonConnect = false, bool $hideButtonPrint = false, bool $hideButtonShare = false,
bool $hideButtonEmail = false, bool $hideButtonPdf = false, bool $hideButtonEnd = false, bool $hideButtonDelete = false, bool $checkButtonReconciled = true,
bool $hideDivider1 = false, bool $hideDivider2 = false, bool $hideDivider3 = false, bool $hideDivider4 = false,
2021-06-25 06:44:30 +00:00
string $permissionCreate = '', string $permissionUpdate = '', string $permissionDelete = '',
2022-06-01 07:15:55 +00:00
string $routeButtonAddNew = '', string $routeButtonEdit = '', string $routeButtonDuplicate = '', string $routeButtonPrint = '', string $shareRoute = '', string $signedUrl = '',
string $routeButtonEmail = '', string $routeButtonPdf = '', string $routeButtonEnd = '', string $routeButtonDelete = '', string $routeContactShow = '',
2021-06-25 06:44:30 +00:00
string $textDeleteModal = '',
bool $hideCompany = false, bool $hideCompanyLogo = false, bool $hideCompanyDetails = false, bool $hideCompanyName = false, bool $hideCompanyAddress = false,
2021-06-25 06:44:30 +00:00
bool $hideCompanyTaxNumber = false, bool $hideCompanyPhone = false, bool $hideCompanyEmail = false,
2022-06-01 07:15:55 +00:00
bool $hideContentTitle = false, bool $hideNumber = false, bool $hidePaidAt = false, bool $hideAccount = false, bool $hideCategory = false, bool $hidePaymentMethods = false, bool $hideReference = false,
bool $hideDescription = false, bool $hideAmount = false,
string $textContentTitle = '', string $textNumber = '', string $textPaidAt = '', string $textAccount = '', string $textCategory = '', string $textPaymentMethods = '', string $textReference = '', string $textDescription = '',
2021-06-25 06:44:30 +00:00
string $textAmount = '', string $textPaidBy = '',
bool $hideContact = false, bool $hideContactInfo = false, bool $hideContactName = false, bool $hideContactAddress = false, bool $hideContactTaxNumber = false,
bool $hideContactPhone = false, bool $hideContactEmail = false,
2021-11-22 20:09:01 +00:00
bool $hideRelated = false, bool $hideRelatedDocumentNumber = false, bool $hideRelatedContact = false, bool $hideRelatedDocumentDate = false, bool $hideRelatedDocumentAmount = false, bool $hideRelatedAmount = false,
string $textRelatedTransansaction = '', string $textRelatedDocumentNumber = '', string $textRelatedContact = '', string $textRelatedDocumentDate = '', string $textRelatedDocumentAmount = '', string $textRelatedAmount = '',
string $routeDocumentShow = '', string $routeTransactionShow = '', string $textButtonAddNew = '',
2021-06-25 06:44:30 +00:00
bool $hideSchedule = false, bool $hideChildren = false, bool $hideTransfer = false, bool $hideAttachment = false, $attachment = [],
array $connectTranslations = [], string $textRecurringType = '', bool $hideRecurringMessage = false, bool $hideCreated = false
2021-06-24 10:52:49 +00:00
) {
$this->type = $type;
$this->transaction = $transaction;
$this->transactionTemplate = $this->getTransactionTemplate($type, $transactionTemplate);
$this->logo = $this->getLogo($logo);
$this->payment_methods = ($payment_methods) ?: Modules::getPaymentMethods('all');
2021-06-24 10:52:49 +00:00
$this->date_format = $this->getCompanyDateFormat();
2021-06-25 06:44:30 +00:00
// Navbar Hide
$this->hideButtonAddNew = $hideButtonAddNew;
$this->hideButtonMoreActions = $hideButtonMoreActions;
$this->hideButtonEdit = $hideButtonEdit;
2022-06-01 07:15:55 +00:00
$this->hideButtonDuplicate = $hideButtonDuplicate;
$this->hideButtonConnect = $hideButtonConnect;
$this->hideButtonPrint = $hideButtonPrint;
2021-06-25 06:44:30 +00:00
$this->hideButtonShare = $hideButtonShare;
$this->hideButtonEmail = $hideButtonEmail;
2022-06-01 07:15:55 +00:00
$this->hideButtonPdf = $hideButtonPdf;
$this->hideButtonEnd = $hideButtonEnd;
2021-06-25 06:44:30 +00:00
$this->hideButtonDelete = $hideButtonDelete;
2021-06-24 10:52:49 +00:00
$this->checkButtonReconciled = $checkButtonReconciled;
2022-06-01 07:15:55 +00:00
$this->hideDivider1 = $hideDivider1;
$this->hideDivider2 = $hideDivider2;
$this->hideDivider3 = $hideDivider3;
$this->hideDivider4 = $hideDivider4;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
// Navbar Permission
$this->permissionCreate = $this->getPermissionCreate($type, $permissionCreate);
$this->permissionUpdate = $this->getPermissionUpdate($type, $permissionUpdate);
$this->permissionDelete = $this->getPermissionDelete($type, $permissionDelete);
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
// Navbar route
2021-06-24 10:52:49 +00:00
$this->routeButtonAddNew = $this->getRouteButtonAddNew($type, $routeButtonAddNew);
$this->routeButtonEdit = $this->getRouteButtonEdit($type, $routeButtonEdit);
$this->routeButtonDuplicate = $this->getRouteButtonDuplicate($type, $routeButtonDuplicate);
$this->routeButtonPrint = $this->getRouteButtonPrint($type, $routeButtonPrint);
2022-06-01 07:15:55 +00:00
$this->shareRoute = $this->getShareRoute($type, $shareRoute);
2021-06-25 06:44:30 +00:00
$this->signedUrl = $this->getSignedUrl($type, $signedUrl);
$this->routeButtonEmail = $this->getRouteButtonEmail($type, $routeButtonEmail);
2021-06-24 10:52:49 +00:00
$this->routeButtonPdf = $this->getRouteButtonPdf($type, $routeButtonPdf);
2022-06-01 07:15:55 +00:00
$this->routeButtonEnd = $this->getRouteButtonEnd($type, $routeButtonEnd);
2021-06-24 10:52:49 +00:00
$this->routeButtonDelete = $this->getRouteButtonDelete($type, $routeButtonDelete);
$this->routeContactShow = $this->getRouteContactShow($type, $routeContactShow);
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
// Navbar Text
2022-06-01 07:15:55 +00:00
$this->textButtonAddNew = $this->getTextButtonAddNew($type, $textButtonAddNew);
2021-06-25 06:44:30 +00:00
$this->textDeleteModal = $textDeleteModal;
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
// Hide Schedule
$this->hideSchedule = $hideSchedule;
// Hide Children
$this->hideChildren = $hideChildren;
2021-06-24 10:52:49 +00:00
// Hide Transfer
$this->hideTransfer = $hideTransfer;
2021-06-25 06:44:30 +00:00
// Hide Attachment
$this->hideAttachment = $hideAttachment;
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
// Company Information Hide checker
$this->hideCompany = $hideCompany;
2021-06-24 10:52:49 +00:00
$this->hideCompanyLogo = $hideCompanyLogo;
2021-06-25 06:44:30 +00:00
$this->hideCompanyDetails = $hideCompanyDetails;
2021-06-24 10:52:49 +00:00
$this->hideCompanyName = $hideCompanyName;
2021-06-25 06:44:30 +00:00
$this->hideCompanyAddress = $hideCompanyAddress;
$this->hideCompanyTaxNumber = $hideCompanyTaxNumber;
$this->hideCompanyPhone = $hideCompanyPhone;
$this->hideCompanyEmail = $hideCompanyEmail;
// Transaction Information Hide checker
$this->hideContentTitle = $hideContentTitle;
2022-06-01 07:15:55 +00:00
$this->hideNumber = $hideNumber;
2021-06-25 06:44:30 +00:00
$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);
2022-06-01 07:15:55 +00:00
$this->textNumber = $this->getTextNumber($type, $textNumber);
2021-06-25 06:44:30 +00:00
$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;
2021-06-24 10:52:49 +00:00
$this->hideContactAddress = $hideContactAddress;
$this->hideContactTaxNumber = $hideContactTaxNumber;
$this->hideContactPhone = $hideContactPhone;
$this->hideContactEmail = $hideContactEmail;
2021-11-22 20:09:01 +00:00
// 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);
2021-06-25 06:44:30 +00:00
$this->routeDocumentShow = $this->routeDocumentShow($type, $routeDocumentShow);
$this->routeTransactionShow = $this->routeTransactionShow($type, $routeTransactionShow);
2021-06-25 06:44:30 +00:00
// Attachment data..
2021-06-24 10:52:49 +00:00
$this->attachment = '';
if (!empty($attachment)) {
$this->attachment = $attachment;
} else if (!empty($transaction)) {
$this->attachment = $transaction->attachment;
}
2022-06-01 07:15:55 +00:00
// Connect translations
$this->connectTranslations = $this->getTranslationsForConnect($type);
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
$this->textRecurringType = $this->getTextRecurringType($type, $textRecurringType);
$this->hideRecurringMessage = $hideRecurringMessage;
$this->hideCreated = $hideCreated;
2021-06-24 10:52:49 +00:00
}
protected function getTransactionTemplate($type, $transactionTemplate)
{
if (!empty($transactionTemplate)) {
return $transactionTemplate;
}
2022-06-01 07:15:55 +00:00
if ($template = config('type.transaction.' . $type . '.template', false)) {
2021-06-24 10:52:49 +00:00
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);
2021-06-24 10:52:49 +00:00
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) {
2021-06-25 06:44:30 +00:00
Log::info('Company ID: ' . company_id() . ' components/transactionshow.php exception.');
Log::info($e->getMessage());
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
$path = base_path('public/img/company.png');
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
$image = Image::cache(function($image) use ($path) {
$width = setting('invoice.logo_size_width');
$height = setting('invoice.logo_size_height');
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
$image->make($path)->resize($width, $height)->encode();
});
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
if (empty($image)) {
return $logo;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
$extension = File::extension($path);
return 'data:image/' . $extension . ';base64,' . base64_encode($image);
2021-06-24 10:52:49 +00:00
}
protected function getRouteButtonAddNew($type, $routeButtonAddNew)
{
if (!empty($routeButtonAddNew)) {
return $routeButtonAddNew;
}
2022-06-01 07:15:55 +00:00
//example route parameter.
$parameter = 1;
$route = $this->getRouteFromConfig($type, 'create', $parameter);
2021-06-24 10:52:49 +00:00
if (!empty($route)) {
return $route;
}
2022-06-01 07:15:55 +00:00
return 'transactions.create';
2021-06-24 10:52:49 +00:00
}
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;
}
2022-06-01 07:15:55 +00:00
return 'transactions.edit';
2021-06-24 10:52:49 +00:00
}
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;
}
2022-06-01 07:15:55 +00:00
return 'transactions.duplicate';
2021-06-24 10:52:49 +00:00
}
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;
}
2022-06-01 07:15:55 +00:00
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';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getSignedUrl($type, $signedUrl)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($signedUrl)) {
return $signedUrl;
}
2022-06-01 07:15:55 +00:00
$page = config('type.transaction.' . $type . '.route.prefix');
$alias = config('type.transaction.' . $type . '.alias');
2021-06-25 06:44:30 +00:00
$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)
{
2022-06-01 07:15:55 +00:00
if (! empty($routeButtonEmail)) {
2021-06-25 06:44:30 +00:00
return $routeButtonEmail;
2021-06-24 10:52:49 +00:00
}
//example route parameter.
$parameter = 1;
2022-06-01 07:15:55 +00:00
$route = $this->getRouteFromConfig($type, 'emails.create', $parameter, true);
2021-06-24 10:52:49 +00:00
2022-06-01 07:15:55 +00:00
if (! empty($route)) {
2021-06-24 10:52:49 +00:00
return $route;
}
2022-06-01 07:15:55 +00:00
return 'modals.transactions.emails.create';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getRouteButtonPdf($type, $routeButtonPdf)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($routeButtonPdf)) {
return $routeButtonPdf;
2021-06-24 10:52:49 +00:00
}
//example route parameter.
$parameter = 1;
2021-06-25 06:44:30 +00:00
$route = $this->getRouteFromConfig($type, 'pdf', $parameter);
2021-06-24 10:52:49 +00:00
if (!empty($route)) {
return $route;
}
2022-06-01 07:15:55 +00:00
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';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getRouteButtonDelete($type, $routeButtonDelete)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($routeButtonDelete)) {
return $routeButtonDelete;
2021-06-24 10:52:49 +00:00
}
//example route parameter.
$parameter = 1;
2021-06-25 06:44:30 +00:00
$route = $this->getRouteFromConfig($type, 'destroy', $parameter);
2021-06-24 10:52:49 +00:00
if (!empty($route)) {
return $route;
}
2022-06-01 07:15:55 +00:00
return 'transactions.destroy';
2021-06-24 10:52:49 +00:00
}
protected function getRouteContactShow($type, $routeContactShow)
{
if (!empty($routeContactShow)) {
return $routeContactShow;
}
//example route parameter.
$parameter = 1;
2022-06-01 07:15:55 +00:00
$route = Str::plural(config('type.transaction.' . $type . '.contact_type'), 2) . '.show';
try {
2021-06-30 15:41:43 +00:00
route($route, $parameter);
} catch (\Exception $e) {
try {
$route = Str::plural($type, 2) . '.' . $config_key;
2021-06-30 15:41:43 +00:00
route($route, $parameter);
} catch (\Exception $e) {
$route = '';
}
}
if (!empty($route)) {
return $route;
}
return 'customers.show';
}
2022-06-01 07:15:55 +00:00
protected function getTextButtonAddNew($type, $textButtonAddNew)
2021-06-24 10:52:49 +00:00
{
2022-06-01 07:15:55 +00:00
if (!empty($textButtonAddNew)) {
return $textButtonAddNew;
2021-06-24 10:52:49 +00:00
}
2022-06-01 07:15:55 +00:00
$translation = $this->getTextFromConfig($type, 'transactions');
2021-06-24 10:52:49 +00:00
if (!empty($translation)) {
2022-06-01 07:15:55 +00:00
return trans('general.title.new', ['type' => trans_choice($translation, 1)]);
2021-06-24 10:52:49 +00:00
}
2022-06-01 07:15:55 +00:00
return trans('general.title.new', ['type' => trans_choice('general.' . Str::plural($type), 1)]);
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getTextContentTitle($type, $textContentTitle)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($textContentTitle)) {
return $textContentTitle;
2021-06-24 10:52:49 +00:00
}
2021-06-27 07:15:39 +00:00
switch ($type) {
case 'bill':
case 'expense':
case 'purchase':
$default_key = 'payment_made';
break;
default:
2022-06-01 07:15:55 +00:00
$default_key = 'receipts';
2021-06-27 07:15:39 +00:00
break;
}
$translation = $this->getTextFromConfig($type, $type . '_made', $default_key);
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
2021-06-24 10:52:49 +00:00
}
2022-06-01 07:15:55 +00:00
return 'general.receipts';
}
protected function getTextNumber($type, $textNumber)
{
if (!empty($textNumber)) {
return $textNumber;
}
return 'general.numbers';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getTextPaidAt($type, $textPaidAt)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($textPaidAt)) {
return $textPaidAt;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
$translation = $this->getTextFromConfig($type, 'paid_at', 'date');
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
return 'general.date';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function getTextAccount($type, $textAccount)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($textAccount)) {
return $textAccount;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
$translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice');
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
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;
}
2021-06-27 07:15:39 +00:00
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);
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
}
2022-06-01 07:15:55 +00:00
return 'transactions.paid_by';
2021-06-25 06:44:30 +00:00
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedTransansaction($type, $textRelatedTransansaction)
2021-06-25 06:44:30 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedTransansaction)) {
return $textRelatedTransansaction;
2021-06-25 06:44:30 +00:00
}
2021-06-27 07:15:39 +00:00
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);
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
}
2022-06-01 07:15:55 +00:00
return 'transactions.related_invoice';
2021-06-25 06:44:30 +00:00
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber)
2021-06-25 06:44:30 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedDocumentNumber)) {
return $textRelatedDocumentNumber;
2021-06-25 06:44:30 +00:00
}
$translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers');
if (!empty($translation)) {
return $translation;
}
return 'general.numbers';
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedContact($type, $textRelatedContact)
2021-06-25 06:44:30 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedContact)) {
return $textRelatedContact;
2021-06-25 06:44:30 +00:00
}
2022-06-01 07:15:55 +00:00
$default_key = Str::plural(config('type.transaction.' . $type . '.contact_type'), 2);
2021-06-27 07:15:39 +00:00
$translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice');
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
}
return 'general.customers';
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate)
2021-06-25 06:44:30 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedDocumentDate)) {
return $textRelatedDocumentDate;
2021-06-25 06:44:30 +00:00
}
2021-06-27 07:15:39 +00:00
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);
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
}
return 'invoices.invoice_date';
2021-06-24 10:52:49 +00:00
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount)
2021-06-24 10:52:49 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedDocumentAmount)) {
return $textRelatedDocumentAmount;
2021-06-25 06:44:30 +00:00
}
2021-06-27 07:15:39 +00:00
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);
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
return 'general.amount';
}
2021-11-22 20:09:01 +00:00
protected function getTextRelatedAmount($type, $textRelatedAmount)
2021-06-25 06:44:30 +00:00
{
2021-11-22 20:09:01 +00:00
if (!empty($textRelatedAmount)) {
return $textRelatedAmount;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
$translation = $this->getTextFromConfig($type, 'related_amount', 'amount');
2021-06-24 10:52:49 +00:00
2021-06-25 06:44:30 +00:00
if (!empty($translation)) {
return $translation;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
return 'general.amount';
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
protected function routeDocumentShow($type, $routeDocumentShow)
2021-06-24 10:52:49 +00:00
{
2021-06-25 06:44:30 +00:00
if (!empty($routeDocumentShow)) {
return $routeDocumentShow;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
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;
2021-06-24 10:52:49 +00:00
}
2021-06-25 06:44:30 +00:00
return 'invoices.show';
}
2021-06-24 10:52:49 +00:00
protected function routeTransactionShow($type, $routeTransactionShow)
{
if (! empty($routeTransactionShow)) {
return $routeTransactionShow;
}
//example route parameter.
$parameter = 1;
$route = $this->getRouteFromConfig($type, 'show', $parameter);
if (! empty($route)) {
return $route;
}
return 'transactions.show';
}
protected function getTextRecurringType($type, $textRecurringType)
{
2022-06-01 07:15:55 +00:00
if (! empty($textRecurringType)) {
return $textRecurringType;
}
2022-06-02 07:26:07 +00:00
$default_key = config('type.transaction.' . $type . '.translation.transactions');
2022-06-02 07:26:07 +00:00
$translation = $this->getTextFromConfig($type, 'recurring_type', $default_key);
2022-06-01 07:15:55 +00:00
if (! empty($translation)) {
return $translation;
}
2022-06-02 07:26:07 +00:00
return 'general.incomes';
}
}