diff --git a/app/Abstracts/View/Components/Documents/Index.php b/app/Abstracts/View/Components/Documents/Index.php index 4a224c2ef..7671ca2f5 100644 --- a/app/Abstracts/View/Components/Documents/Index.php +++ b/app/Abstracts/View/Components/Documents/Index.php @@ -369,8 +369,8 @@ abstract class Index extends Component $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))]), + 'text' => trans('import.title', ['type' => trans_choice($this->textPage ?? 'general.' . $prefix, 2)]), + 'description' => trans('general.empty.actions.import', ['type' => strtolower(trans_choice($this->textPage ?? 'general.' . $prefix, 2))]), ]; } diff --git a/app/Abstracts/View/Components/Transactions/Show.php b/app/Abstracts/View/Components/Transactions/Show.php index fe7ca80a6..3abb1b785 100644 --- a/app/Abstracts/View/Components/Transactions/Show.php +++ b/app/Abstracts/View/Components/Transactions/Show.php @@ -459,9 +459,9 @@ abstract class Show extends Component // Attachment data.. $this->attachment = ''; - if (!empty($attachment)) { + if (! empty($attachment)) { $this->attachment = $attachment; - } else if (!empty($transaction)) { + } else if (! empty($transaction)) { $this->attachment = $transaction->attachment; } @@ -475,7 +475,7 @@ abstract class Show extends Component protected function getTransactionTemplate($type, $transactionTemplate) { - if (!empty($transactionTemplate)) { + if (! empty($transactionTemplate)) { return $transactionTemplate; } @@ -490,7 +490,7 @@ abstract class Show extends Component protected function getLogo($logo) { - if (!empty($logo)) { + if (! empty($logo)) { return $logo; } @@ -498,7 +498,7 @@ abstract class Show extends Component $media = Media::find($media_id); - if (!empty($media)) { + if (! empty($media)) { $path = $media->getDiskPath(); if (Storage::missing($path)) { @@ -544,7 +544,7 @@ abstract class Show extends Component protected function getRouteButtonAddNew($type, $routeButtonAddNew) { - if (!empty($routeButtonAddNew)) { + if (! empty($routeButtonAddNew)) { return $routeButtonAddNew; } @@ -553,7 +553,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'create', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -562,7 +562,7 @@ abstract class Show extends Component protected function getRouteButtonEdit($type, $routeButtonEdit) { - if (!empty($routeButtonEdit)) { + if (! empty($routeButtonEdit)) { return $routeButtonEdit; } @@ -571,7 +571,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'edit', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -580,7 +580,7 @@ abstract class Show extends Component protected function getRouteButtonDuplicate($type, $routeButtonDuplicate) { - if (!empty($routeButtonDuplicate)) { + if (! empty($routeButtonDuplicate)) { return $routeButtonDuplicate; } @@ -589,7 +589,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'duplicate', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -598,7 +598,7 @@ abstract class Show extends Component protected function getRouteButtonPrint($type, $routeButtonPrint) { - if (!empty($routeButtonPrint)) { + if (! empty($routeButtonPrint)) { return $routeButtonPrint; } @@ -607,7 +607,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'print', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -634,7 +634,7 @@ abstract class Show extends Component protected function getSignedUrl($type, $signedUrl) { - if (!empty($signedUrl)) { + if (! empty($signedUrl)) { return $signedUrl; } @@ -643,7 +643,7 @@ abstract class Show extends Component $route = ''; - if (!empty($alias)) { + if (! empty($alias)) { $route .= $alias . '.'; } @@ -662,7 +662,7 @@ abstract class Show extends Component protected function getRouteButtonEmail($type, $routeButtonEmail) { - if (! empty($routeButtonEmail)) { + if (! empty($routeButtonEmail)) { return $routeButtonEmail; } @@ -680,7 +680,7 @@ abstract class Show extends Component protected function getRouteButtonPdf($type, $routeButtonPdf) { - if (!empty($routeButtonPdf)) { + if (! empty($routeButtonPdf)) { return $routeButtonPdf; } @@ -689,7 +689,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'pdf', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -698,7 +698,7 @@ abstract class Show extends Component protected function getRouteButtonEnd($type, $routeButtonEnd) { - if (!empty($routeButtonEnd)) { + if (! empty($routeButtonEnd)) { return $routeButtonEnd; } @@ -707,7 +707,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'end', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -716,7 +716,7 @@ abstract class Show extends Component protected function getRouteButtonDelete($type, $routeButtonDelete) { - if (!empty($routeButtonDelete)) { + if (! empty($routeButtonDelete)) { return $routeButtonDelete; } @@ -725,7 +725,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($type, 'destroy', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -734,7 +734,7 @@ abstract class Show extends Component protected function getRouteContactShow($type, $routeContactShow) { - if (!empty($routeContactShow)) { + if (! empty($routeContactShow)) { return $routeContactShow; } @@ -755,7 +755,7 @@ abstract class Show extends Component } } - if (!empty($route)) { + if (! empty($route)) { return $route; } @@ -764,13 +764,13 @@ abstract class Show extends Component protected function getTextButtonAddNew($type, $textButtonAddNew) { - if (!empty($textButtonAddNew)) { + if (! empty($textButtonAddNew)) { return $textButtonAddNew; } $translation = $this->getTextFromConfig($type, 'transactions'); - if (!empty($translation)) { + if (! empty($translation)) { return trans('general.title.new', ['type' => trans_choice($translation, 1)]); } @@ -779,7 +779,7 @@ abstract class Show extends Component protected function getTextContentTitle($type, $textContentTitle) { - if (!empty($textContentTitle)) { + if (! empty($textContentTitle)) { return $textContentTitle; } @@ -796,7 +796,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, $type . '_made', $default_key); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -805,7 +805,7 @@ abstract class Show extends Component protected function getTextNumber($type, $textNumber) { - if (!empty($textNumber)) { + if (! empty($textNumber)) { return $textNumber; } @@ -814,13 +814,13 @@ abstract class Show extends Component protected function getTextPaidAt($type, $textPaidAt) { - if (!empty($textPaidAt)) { + if (! empty($textPaidAt)) { return $textPaidAt; } $translation = $this->getTextFromConfig($type, 'paid_at', 'date'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -829,13 +829,13 @@ abstract class Show extends Component protected function getTextAccount($type, $textAccount) { - if (!empty($textAccount)) { + if (! empty($textAccount)) { return $textAccount; } $translation = $this->getTextFromConfig($type, 'accounts', 'accounts', 'trans_choice'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -844,13 +844,13 @@ abstract class Show extends Component protected function getTextCategory($type, $textCategory) { - if (!empty($textCategory)) { + if (! empty($textCategory)) { return $textCategory; } $translation = $this->getTextFromConfig($type, 'categories', 'categories', 'trans_choice'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -859,13 +859,13 @@ abstract class Show extends Component protected function getTextPaymentMethods($type, $textPaymentMethods) { - if (!empty($textPaymentMethods)) { + if (! empty($textPaymentMethods)) { return $textPaymentMethods; } $translation = $this->getTextFromConfig($type, 'payment_methods', 'payment_methods', 'trans_choice'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -874,13 +874,13 @@ abstract class Show extends Component protected function getTextReference($type, $textReference) { - if (!empty($textReference)) { + if (! empty($textReference)) { return $textReference; } $translation = $this->getTextFromConfig($type, 'reference', 'reference'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -889,13 +889,13 @@ abstract class Show extends Component protected function getTextDescription($type, $textDescription) { - if (!empty($textDescription)) { + if (! empty($textDescription)) { return $textDescription; } $translation = $this->getTextFromConfig($type, 'description', 'description'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -904,13 +904,13 @@ abstract class Show extends Component protected function getTextAmount($type, $textAmount) { - if (!empty($textAmount)) { + if (! empty($textAmount)) { return $textAmount; } $translation = $this->getTextFromConfig($type, 'amount', 'amount'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -919,7 +919,7 @@ abstract class Show extends Component protected function getTextPaidBy($type, $textPaidBy) { - if (!empty($textPaidBy)) { + if (! empty($textPaidBy)) { return $textPaidBy; } @@ -936,7 +936,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, 'paid_to_by', $default_key); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -945,7 +945,7 @@ abstract class Show extends Component protected function getTextRelatedTransansaction($type, $textRelatedTransansaction) { - if (!empty($textRelatedTransansaction)) { + if (! empty($textRelatedTransansaction)) { return $textRelatedTransansaction; } @@ -962,7 +962,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, 'related_type', $default_key); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -971,13 +971,13 @@ abstract class Show extends Component protected function getTextRelatedDocumentNumber($type, $textRelatedDocumentNumber) { - if (!empty($textRelatedDocumentNumber)) { + if (! empty($textRelatedDocumentNumber)) { return $textRelatedDocumentNumber; } $translation = $this->getTextFromConfig($type, 'related_document_number', 'numbers'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -986,7 +986,7 @@ abstract class Show extends Component protected function getTextRelatedContact($type, $textRelatedContact) { - if (!empty($textRelatedContact)) { + if (! empty($textRelatedContact)) { return $textRelatedContact; } @@ -994,7 +994,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, 'related_contact', $default_key, 'trans_choice'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -1003,7 +1003,7 @@ abstract class Show extends Component protected function getTextRelatedDocumentDate($type, $textRelatedDocumentDate) { - if (!empty($textRelatedDocumentDate)) { + if (! empty($textRelatedDocumentDate)) { return $textRelatedDocumentDate; } @@ -1020,7 +1020,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, 'related_document_date', $default_key); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -1029,7 +1029,7 @@ abstract class Show extends Component protected function getTextRelatedDocumentAmount($type, $textRelatedDocumentAmount) { - if (!empty($textRelatedDocumentAmount)) { + if (! empty($textRelatedDocumentAmount)) { return $textRelatedDocumentAmount; } @@ -1046,7 +1046,7 @@ abstract class Show extends Component $translation = $this->getTextFromConfig($type, 'related_document_amount', $default_key); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -1055,13 +1055,13 @@ abstract class Show extends Component protected function getTextRelatedAmount($type, $textRelatedAmount) { - if (!empty($textRelatedAmount)) { + if (! empty($textRelatedAmount)) { return $textRelatedAmount; } $translation = $this->getTextFromConfig($type, 'related_amount', 'amount'); - if (!empty($translation)) { + if (! empty($translation)) { return $translation; } @@ -1070,11 +1070,11 @@ abstract class Show extends Component protected function routeDocumentShow($type, $routeDocumentShow) { - if (!empty($routeDocumentShow)) { + if (! empty($routeDocumentShow)) { return $routeDocumentShow; } - if (!$this->transaction->document) { + if (! $this->transaction->document) { return $routeDocumentShow; } @@ -1083,7 +1083,7 @@ abstract class Show extends Component $route = $this->getRouteFromConfig($this->transaction->document->type, 'show', $parameter); - if (!empty($route)) { + if (! empty($route)) { return $route; } diff --git a/app/Http/Controllers/Auth/Users.php b/app/Http/Controllers/Auth/Users.php index 65ede27f9..d810e1202 100644 --- a/app/Http/Controllers/Auth/Users.php +++ b/app/Http/Controllers/Auth/Users.php @@ -119,6 +119,7 @@ class Users extends Controller } $u = new \stdClass(); + $u->role = $user->roles()->first(); $u->landing_pages = []; event(new LandingPageShowing($u)); @@ -354,4 +355,35 @@ class Users extends Controller return response()->json($response); } + + /** + * Process request for reinviting the specified resource. + * + * @param Role $role + * + * @return Response + */ + public function landingPages(BaseRequest $request) + { + $role = false; + + if ($request->has('role_id')) { + $role = Role::find($request->get('role_id')); + } + + $u = new \stdClass(); + $u->role = $role; + $u->landing_pages = []; + + event(new LandingPageShowing($u)); + + $landing_pages = $u->landing_pages; + + return response()->json([ + 'success' => true, + 'error' => false, + 'data' => $landing_pages, + 'message' => 'Get role by landing pages..', + ]); + } } diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index b74a2fe8a..4a8f72829 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -86,8 +86,9 @@ class Transactions extends Controller public function show(Transaction $transaction) { $title = $transaction->isIncome() ? trans_choice('general.receipts', 1) : trans('transactions.payment_made'); + $real_type = $this->getRealTypeTransaction($transaction->type); - return view('banking.transactions.show', compact('transaction', 'title')); + return view('banking.transactions.show', compact('transaction', 'title', 'real_type')); } /** @@ -98,6 +99,7 @@ class Transactions extends Controller public function create() { $type = request()->get('type', 'income'); + $real_type = $this->getRealTypeTransaction($type); $number = $this->getNextTransactionNumber(); @@ -109,6 +111,7 @@ class Transactions extends Controller return view('banking.transactions.create', compact( 'type', + 'real_type', 'number', 'contact_type', 'account_currency_code', diff --git a/app/Http/Middleware/Dropzone.php b/app/Http/Middleware/Dropzone.php index 50c36b3ee..7654fa048 100644 --- a/app/Http/Middleware/Dropzone.php +++ b/app/Http/Middleware/Dropzone.php @@ -16,14 +16,14 @@ class Dropzone */ public function handle($request, Closure $next) { - if (!in_array($request->method(), ['POST', 'PATCH'])) { + if (! in_array($request->method(), ['POST', 'PATCH'])) { return $next($request); } $multiple = false; foreach ($request->all() as $key => $value) { - if (!is_array($value)) { + if (! is_array($value)) { continue; } @@ -36,8 +36,8 @@ class Dropzone foreach ($value as $index => $parameter) { // single file uploaded.. - if (!is_array($parameter) && !$multiple) { - if (!Arr::has($value, 'dropzone')) { + if (! is_array($parameter) && !$multiple) { + if (! Arr::has($value, 'dropzone')) { continue; } @@ -49,15 +49,15 @@ class Dropzone // multiple file uploaded.. if (is_array($parameter)) { - if (!Arr::has($parameter, 'dropzone')) { + if (! Arr::has($parameter, 'dropzone')) { $files[] = $parameter; - + continue; } } else if (is_object($parameter)) { if (empty($parameter->dropzone)) { $files[] = $parameter; - + continue; } } diff --git a/app/Jobs/Auth/UpdateUser.php b/app/Jobs/Auth/UpdateUser.php index 3ebc4dc41..cd0c62255 100644 --- a/app/Jobs/Auth/UpdateUser.php +++ b/app/Jobs/Auth/UpdateUser.php @@ -30,9 +30,13 @@ class UpdateUser extends Job implements ShouldUpdate // Upload picture if ($this->request->file('picture')) { + $this->deleteMediaModel($this->model, 'picture', $this->request); + $media = $this->getMedia($this->request->file('picture'), 'users'); $this->model->attachMedia($media, 'picture'); + } elseif (! $this->request->file('picture') && $this->model->picture) { + $this->deleteMediaModel($this->model, 'picture', $this->request); } if ($this->request->has('roles')) { diff --git a/app/Jobs/Banking/UpdateTransfer.php b/app/Jobs/Banking/UpdateTransfer.php index 6836c8574..7cd7f23b0 100644 --- a/app/Jobs/Banking/UpdateTransfer.php +++ b/app/Jobs/Banking/UpdateTransfer.php @@ -26,7 +26,7 @@ class UpdateTransfer extends Job implements ShouldUpdate $this->model->attachMedia($media, 'attachment'); } - } elseif (!$this->request->file('attachment') && $this->model->attachment) { + } elseif (! $this->request->file('attachment') && $this->model->attachment) { $this->deleteMediaModel($this->model, 'attachment', $this->request); } diff --git a/app/Jobs/Document/UpdateDocument.php b/app/Jobs/Document/UpdateDocument.php index 44655d036..ba000a3ca 100644 --- a/app/Jobs/Document/UpdateDocument.php +++ b/app/Jobs/Document/UpdateDocument.php @@ -34,7 +34,7 @@ class UpdateDocument extends Job implements ShouldUpdate $this->model->attachMedia($media, 'attachment'); } - } elseif (!$this->request->file('attachment') && $this->model->attachment) { + } elseif (! $this->request->file('attachment') && $this->model->attachment) { $this->deleteMediaModel($this->model, 'attachment', $this->request); } diff --git a/app/Listeners/Auth/AddLandingPages.php b/app/Listeners/Auth/AddLandingPages.php index 2ae15319b..f83d0013b 100644 --- a/app/Listeners/Auth/AddLandingPages.php +++ b/app/Listeners/Auth/AddLandingPages.php @@ -15,6 +15,8 @@ class AddLandingPages public function handle(Event $event) { $user = user(); + $role = ! empty($event->user->role) ? $event->user->role : false; + $routes = [ 'dashboard' => [ 'permission' => 'read-common-dashboards', @@ -79,7 +81,9 @@ class AddLandingPages ]; foreach($routes as $key => $route) { - if (!$user->can($route['permission'])) { + if ($role && ! $role->hasPermission($route['permission'])) { + continue; + } else if (! $user->can($route['permission'])) { continue; } diff --git a/app/Listeners/Document/SettingFieldCreated.php b/app/Listeners/Document/SettingFieldCreated.php index e0e304ff2..9b7b3b7a5 100644 --- a/app/Listeners/Document/SettingFieldCreated.php +++ b/app/Listeners/Document/SettingFieldCreated.php @@ -24,13 +24,18 @@ class SettingFieldCreated $request = $event->request; $document = $event->document; - if (!$request->has('setting')) { + if (! $request->has('setting')) { return; } $type = $request->get('type'); $fields = $request->get('setting', []); + // remove company logo + if (! in_array('company_logo', $fields)) { + setting()->forget('company.logo'); + } + foreach ($fields as $key => $value) { if ($key == 'company_logo') { if (Arr::has($value, 'dropzone')) { diff --git a/app/Listeners/Document/SettingFieldUpdated.php b/app/Listeners/Document/SettingFieldUpdated.php index 681d4e02e..fed0714f4 100644 --- a/app/Listeners/Document/SettingFieldUpdated.php +++ b/app/Listeners/Document/SettingFieldUpdated.php @@ -24,13 +24,18 @@ class SettingFieldUpdated $request = $event->request; $document = $event->document; - if (!$request->has('setting')) { + if (! $request->has('setting')) { return; } $type = $request->get('type'); $fields = $request->get('setting', []); + // remove company logo + if (! in_array('company_logo', $fields)) { + setting()->forget('company.logo'); + } + foreach ($fields as $key => $value) { if ($key == 'company_logo') { if (Arr::has($value, 'dropzone')) { diff --git a/app/Listeners/Update/V30/Version309.php b/app/Listeners/Update/V30/Version309.php new file mode 100644 index 000000000..07202609a --- /dev/null +++ b/app/Listeners/Update/V30/Version309.php @@ -0,0 +1,63 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.0.9 version...'); + + $this->updatePermissions(); + + Log::channel('stdout')->info('Done!'); + } + + public function updatePermissions(): void + { + Log::channel('stdout')->info('Updating permissions...'); + + $rows = [ + 'accountant' => [ + 'auth-profile' => 'r,u', + 'common-reports' => 'r', + 'widgets-account-balance' => 'r', + 'widgets-bank-feeds' => 'r', + 'widgets-cash-flow' => 'r', + 'widgets-currencies' => 'r', + 'widgets-expenses-by-category' => 'r', + 'widgets-payables' => 'r', + 'widgets-profit-loss' => 'r', + 'widgets-receivables' => 'r', + ], + ]; + + Log::channel('stdout')->info('Attaching new permissions...'); + + // c=create, r=read, u=update, d=delete + $this->attachPermissionsByRoleNames($rows); + + Log::channel('stdout')->info('Permissions updated.'); + } +} diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index e8485b688..c6bd702d1 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -134,7 +134,7 @@ class User extends Authenticatable implements HasLocalePreference if (!empty($value)) { return $value; - } elseif (!$this->hasMedia('picture')) { + } elseif (! $this->hasMedia('picture')) { return false; } diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 0c4cf8e33..07aadff7b 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -364,6 +364,7 @@ class Transaction extends Model { $type = $this->getRealTypeOfRecurringTransaction($this->type); $type = $this->getRealTypeOfTransferTransaction($type); + $type = $this->getRealTypeOfSplitTransaction($type); $type = str_replace('-', '_', $type); diff --git a/app/Providers/Event.php b/app/Providers/Event.php index b3ccb7d31..5b4a64535 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -20,6 +20,7 @@ class Event extends Provider 'App\Listeners\Update\V30\Version304', 'App\Listeners\Update\V30\Version305', 'App\Listeners\Update\V30\Version307', + 'App\Listeners\Update\V30\Version309', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/app/Traits/Transactions.php b/app/Traits/Transactions.php index bc40b37f8..d36e23802 100644 --- a/app/Traits/Transactions.php +++ b/app/Traits/Transactions.php @@ -51,6 +51,23 @@ trait Transactions return Str::endsWith($type, '-transfer'); } + public function isNotTransferTransaction(): bool + { + return ! $this->isTransferTransaction(); + } + + public function isSplitTransaction(): bool + { + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::INCOME_TYPE; + + return Str::endsWith($type, '-split'); + } + + public function isNotSplitTransaction(): bool + { + return ! $this->isSplitTransaction(); + } + public function isDocumentTransaction(): bool { $document_id = $this->document_id ?? $this->transaction->document_id ?? $this->model->document_id ?? null; @@ -63,11 +80,6 @@ trait Transactions return ! $this->isDocumentTransaction(); } - public function isNotTransferTransaction(): bool - { - return ! $this->isTransferTransaction(); - } - public function getIncomeTypes(string $return = 'array'): string|array { return $this->getTransactionTypes(Transaction::INCOME_TYPE, $return); @@ -192,6 +204,15 @@ trait Transactions ]; } + public function getRealTypeTransaction(string $type): string + { + $type = $this->getRealTypeOfRecurringTransaction($type); + $type = $this->getRealTypeOfTransferTransaction($type); + $type = $this->getRealTypeOfSplitTransaction($type); + + return $type; + } + public function getRealTypeOfRecurringTransaction(string $recurring_type): string { return Str::replace('-recurring', '', $recurring_type); @@ -202,6 +223,11 @@ trait Transactions return Str::replace('-transfer', '', $transfer_type); } + public function getRealTypeOfSplitTransaction(string $transfer_type): string + { + return Str::replace('-split', '', $transfer_type); + } + public function getNextTransactionNumber($suffix = ''): string { $prefix = setting('transaction' . $suffix . '.number_prefix'); diff --git a/app/Traits/Uploads.php b/app/Traits/Uploads.php index fcc1d60f3..574273526 100644 --- a/app/Traits/Uploads.php +++ b/app/Traits/Uploads.php @@ -14,7 +14,7 @@ trait Uploads { $path = ''; - if (!$file || !$file->isValid()) { + if (! $file || ! $file->isValid()) { return $path; } @@ -38,7 +38,7 @@ trait Uploads { $path = ''; - if (!$disk) { + if (! $disk) { $disk = config('mediable.default_disk'); } @@ -61,10 +61,18 @@ trait Uploads return; } + $multiple = true; + + if ($medias instanceof \App\Models\Common\Media) { + $multiple = false; + + $medias = [$medias]; + } + $already_uploaded = []; if ($request && isset($request['uploaded_' . $parameter])) { - $uploaded = $request['uploaded_' . $parameter]; + $uploaded = ($multiple) ? $request['uploaded_' . $parameter] : [$request['uploaded_' . $parameter]]; if (count($medias) == count($uploaded)) { return; diff --git a/app/View/Components/EmptyPage.php b/app/View/Components/EmptyPage.php index f73a07a9c..86534234b 100644 --- a/app/View/Components/EmptyPage.php +++ b/app/View/Components/EmptyPage.php @@ -26,6 +26,12 @@ class EmptyPage extends Component /** @var string */ public $title; + /** @var string */ + public $createButtonTitle; + + /** @var string */ + public $importButtonTitle; + /** @var string */ public $description; @@ -75,9 +81,9 @@ class EmptyPage extends Component */ public function __construct( string $alias = '', string $group = '', string $page = '', - string $title = '', string $description = '', string $docsCategory = 'accounting', - string $image = '', string $imageEmptyPage = '', - bool $checkPermissionCreate = true, string $permissionCreate = '', + string $title = '', string $createButtonTitle = '', string $importButtonTitle = '', + string $description = '', string $docsCategory = 'accounting', string $image = '', + string $imageEmptyPage = '', bool $checkPermissionCreate = true, string $permissionCreate = '', array $buttons = [], bool $hideButtonCreate = false, bool $hideButtonImport = false, bool $hideDocsDescription = false, string $importRoute = '', array $importRouteParameters = [] ) { @@ -91,6 +97,9 @@ class EmptyPage extends Component $this->docsCategory = $docsCategory; $this->title = $this->getTitle($title); + $this->createButtonTitle = $createButtonTitle; + $this->importButtonTitle = $importButtonTitle; + $this->description = $this->getDescription($description); $this->imageEmptyPage = $imageEmptyPage; @@ -276,7 +285,11 @@ class EmptyPage extends Component $route = route($page . '.create'); } - $title = $this->getTitle(null, 1); + $title = $this->createButtonTitle; + + if (! $title) { + $title = $this->getTitle(null, 1); + } return [ 'url' => $route, @@ -292,7 +305,11 @@ class EmptyPage extends Component $importRoute = $this->getImportRoute($this->importRoute); $importRouteParameters = $this->getImportRouteParameters($this->importRouteParameters); - $title = $this->getTitle(); + $title = $this->importButtonTitle; + + if (! $title) { + $title = $this->getTitle(); + } return [ 'url' => route($importRoute, $importRouteParameters), diff --git a/app/View/Components/Form/Group/Country.php b/app/View/Components/Form/Group/Country.php index b54a86b17..76f600bda 100644 --- a/app/View/Components/Form/Group/Country.php +++ b/app/View/Components/Form/Group/Country.php @@ -15,6 +15,14 @@ class Country extends Form */ public function render() { + if (empty($this->name)) { + $this->name = 'country'; + } + + if (empty($this->selected) && empty($this->getParentData('model'))) { + $this->selected = setting('company.country'); + } + return view('components.form.group.country'); } } diff --git a/app/View/Components/Form/Group/File.php b/app/View/Components/Form/Group/File.php index a9f34754d..46e4dea91 100644 --- a/app/View/Components/Form/Group/File.php +++ b/app/View/Components/Form/Group/File.php @@ -11,7 +11,7 @@ class File extends Form public $formGroupClass = 'sm:col-span-3'; public $custom_attributes = [ - 'dropzone-class' => 'form-file dropzone-column w-1/2 h-32.5', + 'dropzone-class' => 'form-file dropzone-column sm:w-1/2 h-32.5', ]; /** diff --git a/app/View/Components/Form/Group/PaymentMethod.php b/app/View/Components/Form/Group/PaymentMethod.php index 6675f145f..9fc45a1b3 100644 --- a/app/View/Components/Form/Group/PaymentMethod.php +++ b/app/View/Components/Form/Group/PaymentMethod.php @@ -18,6 +18,10 @@ class PaymentMethod extends Form */ public function render() { + if (empty($this->name)) { + $this->name = 'payment_method'; + } + $this->payment_methods = Modules::getPaymentMethods(); if (empty($this->selected) && empty($this->getParentData('model'))) { diff --git a/app/View/Components/Suggestions.php b/app/View/Components/Suggestions.php index 269d00a0a..efe0b9b46 100644 --- a/app/View/Components/Suggestions.php +++ b/app/View/Components/Suggestions.php @@ -5,6 +5,7 @@ namespace App\View\Components; use App\Abstracts\View\Component; use App\Traits\Modules; use Illuminate\Support\Facades\Route; +use Illuminate\Support\Arr; use Illuminate\Support\Str; class Suggestions extends Component @@ -71,6 +72,10 @@ class Suggestions extends Component return []; } - return $modules; + if (count($modules) < 3) { + return $modules; + } + + return Arr::random($modules, 2); } } diff --git a/app/View/Components/Tips.php b/app/View/Components/Tips.php index e474cd493..2d6504f8e 100644 --- a/app/View/Components/Tips.php +++ b/app/View/Components/Tips.php @@ -52,35 +52,53 @@ class Tips extends Component $view = 'components.tips.relative'; } + if ($this->tips->count() > 1) { + $view = 'components.tips.relative'; + } + return view($view); } protected function setTips($tips) { - if (!empty($tips)) { + if (! empty($tips)) { $this->tips = $tips; } - if (!$path = Route::current()->uri()) { + if (! $path = Route::current()->uri()) { return; } $path = Str::replace('{company_id}/', '', $path); - if (!$tips = $this->getTips($path)) { + if (! $tips = $this->getTips($path)) { return; } + $rows = collect(); + + shuffle($tips); + foreach ($tips as $tip) { if ($tip->position != $this->position) { continue; } - if (!empty($tip->alias) && $this->moduleIsEnabled($tip->alias)) { + if (! empty($tip->alias) && $this->moduleIsEnabled($tip->alias)) { continue; } - $this->tips->push($tip); + if (Str::contains($tip->action, '{company_id}')) { + $tip->action = Str::replace('{company_id}', company_id(), $tip->action); + } + + $rows->push($tip); + } + + if ($rows->count()) { + $row = $rows->shuffle()->first(); + + $this->tips->push($row); } } } diff --git a/app/View/Presenters/Menu.php b/app/View/Presenters/Menu.php index 1d0faf2a7..2d87b555d 100644 --- a/app/View/Presenters/Menu.php +++ b/app/View/Presenters/Menu.php @@ -14,7 +14,7 @@ class Menu extends Presenter { return PHP_EOL . '