diff --git a/app/Events/Common/ImportViewCreated.php b/app/Events/Common/ImportViewCreated.php new file mode 100644 index 000000000..64ab1a94b --- /dev/null +++ b/app/Events/Common/ImportViewCreated.php @@ -0,0 +1,21 @@ +view = $view; + } +} diff --git a/app/Events/Common/ImportViewCreating.php b/app/Events/Common/ImportViewCreating.php new file mode 100644 index 000000000..b184e46d9 --- /dev/null +++ b/app/Events/Common/ImportViewCreating.php @@ -0,0 +1,21 @@ +view = $view; + } +} diff --git a/app/Http/Controllers/Common/Import.php b/app/Http/Controllers/Common/Import.php index 5f8d32cc1..6dc4c2b37 100644 --- a/app/Http/Controllers/Common/Import.php +++ b/app/Http/Controllers/Common/Import.php @@ -3,10 +3,12 @@ namespace App\Http\Controllers\Common; use App\Abstracts\Http\Controller; -use Akaunting\Module\Module; +use App\Traits\Import as ImportTrait; class Import extends Controller { + use ImportTrait; + /** * Show the form for creating a new resource. * @@ -18,38 +20,8 @@ class Import extends Controller */ public function create($group, $type, $route = null) { - $path = company_id() . '/' . $group . '/' . $type; + list($view, $data) = $this->getImportView($group, $type, $route); - $module = module($group); - - if ($module instanceof Module) { - $title_type = trans_choice($group . '::general.' . str_replace('-', '_', $type), 2); - $sample_file = url('modules/' . $module->getStudlyName() . '/Resources/assets/' . $type . '.xlsx'); - } else { - $title_type = trans_choice('general.' . str_replace('-', '_', $type), 2); - $sample_file = url('public/files/import/' . $type . '.xlsx'); - } - - $form_params = [ - 'id' => 'import', - '@submit.prevent' => 'onSubmit', - '@keydown' => 'form.errors.clear($event.target.name)', - 'files' => true, - 'role' => 'form', - 'class' => 'form-loading-button', - 'novalidate' => true, - 'route' => '', - 'url' => '', - ]; - - if (! empty($route)) { - $form_params['route'] = $route; - } else { - $form_params['url'] = $path . '/import'; - } - - $document_link = 'https://akaunting.com/hc/docs/import-export/'; - - return view('common.import.create', compact('group', 'type', 'path', 'route', 'form_params', 'title_type', 'sample_file', 'document_link')); + return view($view, $data); } } diff --git a/app/Traits/Import.php b/app/Traits/Import.php index 07af25209..3cc125efe 100644 --- a/app/Traits/Import.php +++ b/app/Traits/Import.php @@ -2,6 +2,8 @@ namespace App\Traits; +use App\Events\Common\ImportViewCreating; +use App\Events\Common\ImportViewCreated; use App\Http\Requests\Banking\Account as AccountRequest; use App\Http\Requests\Common\Contact as ContactRequest; use App\Http\Requests\Common\Item as ItemRequest; @@ -24,12 +26,41 @@ use App\Models\Setting\Currency; use App\Models\Setting\Tax; use App\Traits\Jobs; use App\Traits\Sources; +use App\Traits\Translations; use App\Utilities\Modules; use Illuminate\Support\Facades\Validator; +use Akaunting\Module\Module; trait Import { - use Jobs, Sources; + use Jobs, Sources, Translations; + + public function getImportView($group, $type, $route = null) + { + // Get the view path + $view = $this->getImportViewPath($group, $type); + + // Get import blade variables + $path = $this->getImportPath($group, $type); + $title_type = $this->getImportTitleType($group, $type); + $sample_file = $this->getImportSampleFile($group, $type); + $form_params = $this->getImportFormParams($group, $type); + $document_link = $this->getImportDocumentLink($group, $type); + + // Create the import view + $import = new \stdClass(); + $import->view = $view; + $import->data = compact('group', 'type', 'route', 'path', 'title_type', 'sample_file', 'form_params', 'document_link'); + + event(new ImportViewCreating($import)); + + event(new ImportViewCreated($import)); + + return [ + $import->view, + $import->data + ]; + } public function getAccountId($row) { @@ -446,4 +477,108 @@ trait Import return $tax->id; } + + protected function getImportPath($group, $type) + { + $path = config('import.' . $group . '.' . $type . '.path'); + + if (! empty($path)) { + return str_replace('company_id', company_id(), $path); + } + + return company_id() . '/' . $group . '/' . $type; + } + + protected function getImportTitleType($group, $type) + { + $title_type = config('import.' . $group . '.' . $type . '.title_type'); + + if (! empty($title_type)) { + return $this->findTranslation($title_type); + } + + $module = module($group); + + $title_type = trans_choice('general.' . str_replace('-', '_', $type), 2); + + if ($module instanceof Module) { + $title_type = trans_choice($group . '::general.' . str_replace('-', '_', $type), 2); + } + + return $title_type; + } + + protected function getImportSampleFile($group, $type) + { + $sample_file = config('import.' . $group . '.' . $type . '.sample_file'); + + if (! empty($sample_file)) { + return url($sample_file); + } + + $module = module($group); + + $sample_file = url('public/files/import/' . $type . '.xlsx'); + + if ($module instanceof Module) { + $sample_file = url('modules/' . $module->getStudlyName() . '/Resources/assets/' . $type . '.xlsx'); + } + + return $sample_file; + } + + protected function getImportFormParams($group, $type, $path = null, $route = null) + { + $form_params = config('import.' . $group . '.' . $type . '.form_params'); + + if (! empty($form_params)) { + return $form_params; + } + + $form_params = [ + 'id' => 'import', + '@submit.prevent' => 'onSubmit', + '@keydown' => 'form.errors.clear($event.target.name)', + 'files' => true, + 'role' => 'form', + 'class' => 'form-loading-button', + 'novalidate' => true, + 'route' => '', + 'url' => '', + ]; + + if (! empty($route)) { + $form_params['route'] = $route; + } else { + $form_params['url'] = $path . '/import'; + } + + return $form_params; + } + + protected function getImportDocumentLink($group, $type) + { + $document_link = config('import.' . $group . '.' . $type . '.document_link'); + + if (! empty($document_link)) { + return $document_link; + } + + $document_link = 'https://akaunting.com/hc/docs/import-export/'; + + return $document_link; + } + + protected function getImportViewPath($group, $type) + { + $view = config('import.' . $group . '.' . $type . '.view'); + + if (! empty($view)) { + return $view; + } + + $view = 'common.import.create'; + + return $view; + } } diff --git a/config/import.php b/config/import.php new file mode 100644 index 000000000..3edbd858c --- /dev/null +++ b/config/import.php @@ -0,0 +1,36 @@ + [ + + // Type + 'transactions' => [ + + //'path' => 'banking/transactions', + //'title_type => 'transactions', + //'sample_file' => 'public/files/import/transactions.xlsx', + /*'form_params' => [ + 'id' => 'import', + '@submit.prevent' => 'onSubmit', + '@keydown' => 'form.errors.clear($event.target.name)', + 'files' => true, + 'role' => 'form', + 'class' => 'form-loading-button', + 'novalidate' => true, + 'route' => '', + 'url' => '', + ],*/ + 'document_link' => 'https://akaunting.com/hc/docs/import-export/importing-transactions/', + 'view' => 'banking.transactions.import', + + ], + ], + +]; diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php index 9176f52c4..bfe5c85a2 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -75,6 +75,10 @@ return [ 'your_notifications' => 'Your notification|Your notifications', 'employees' => 'Employee|Employees', 'contact_persons' => 'Contact Person|Contact Persons', + 'bank_feeds' => 'Bank Feed|Bank Feeds', + 'receipts' => 'Receipt|Receipts', + 'ofx' => 'OFX', + 'mt940' => 'MT940', 'welcome' => 'Welcome', 'banking' => 'Banking', diff --git a/resources/lang/en-GB/import.php b/resources/lang/en-GB/import.php index 13b6a1274..a61b649fb 100644 --- a/resources/lang/en-GB/import.php +++ b/resources/lang/en-GB/import.php @@ -10,4 +10,9 @@ return [ 'drop_file' => 'Upload a file or drag and drop', 'file_type_and_limitations' => ':extensions up to :row_limit rows', + 'bank_feeds' => 'Import transactions securely to automate bookkeeping by connecting bank accounts', + 'receipts' => 'Save time by uploading receipts, recording expenses, and eliminating manual work effortlessly!', + 'ofx' => 'Effortlessly import your bank transactions with the OFX App and automate your financial management!', + 'mt940' => 'Seamlessly upload your bank statements in MT940 format and take control of your finances with ease!', + ]; diff --git a/resources/views/banking/transactions/import.blade.php b/resources/views/banking/transactions/import.blade.php new file mode 100644 index 000000000..898ca76ff --- /dev/null +++ b/resources/views/banking/transactions/import.blade.php @@ -0,0 +1,154 @@ + + + {{ trans('import.title', ['type' => $title_type]) }} + + + + + + + + + + + + {{ trans_choice('general.bank_feeds', 2) }} + → + + + + + {{ trans('import.bank_feeds') }} + + + + + + + + + + + + {{ trans_choice('general.receipts', 2) }} + → + + + + + {{ trans('import.receipts') }} + + + + + + + + + + + + {{ trans_choice('general.ofx', 2) }} + → + + + + + {{ trans('import.ofx') }} + + + + + + + + + + + + {{ trans_choice('general.mt940', 2) }} + → + + + + + {{ trans('import.mt940') }} + + + + + + + + + + + + + + + + + + + + error_outline + + + {!! trans('import.sample_file_and_document', [ + 'download_link' => $sample_file, + 'document_link' => $document_link + ]) !!} + + + + + + + + + + + @if (! empty($route)) + + {{ trans('general.cancel') }} + + @else + + {{ trans('general.cancel') }} + + @endif + + + + {{ trans('import.import') }} + + + + + + + + + + +
+ {{ trans('import.bank_feeds') }} +
+ {{ trans('import.receipts') }} +
+ {{ trans('import.ofx') }} +
+ {{ trans('import.mt940') }} +