From 5a23918dadfe3c067ef8a9f17c16bcf2c63af67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 3 Dec 2024 18:18:48 +0000 Subject: [PATCH] Custom import page feature.. --- app/Events/Common/ImportViewCreated.php | 21 ++ app/Events/Common/ImportViewCreating.php | 21 ++ app/Http/Controllers/Common/Import.php | 38 +-- app/Traits/Import.php | 53 +++ config/import.php | 19 ++ resources/lang/en-GB/general.php | 4 + resources/lang/en-GB/import.php | 5 + .../banking/transactions/import.blade.php | 308 ++++++++++++++++++ 8 files changed, 436 insertions(+), 33 deletions(-) create mode 100644 app/Events/Common/ImportViewCreated.php create mode 100644 app/Events/Common/ImportViewCreating.php create mode 100644 config/import.php create mode 100644 resources/views/banking/transactions/import.blade.php 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..3b85a28f8 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; @@ -26,11 +28,62 @@ use App\Traits\Jobs; use App\Traits\Sources; use App\Utilities\Modules; use Illuminate\Support\Facades\Validator; +use Akaunting\Module\Module; trait Import { use Jobs, Sources; + public function getImportView($group, $type, $route = null) + { + $path = company_id() . '/' . $group . '/' . $type; + + $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/'; + + $view = 'common.import.create'; + + $import = new \stdClass(); + $import->view = 'common.import.create'; + $import->data = compact('group', 'type', 'path', 'route', 'form_params', 'title_type', 'sample_file', 'document_link'); + + event(new ImportViewCreating($import)); + + event(new ImportViewCreated($import)); + + return [ + $import->view, + $import->data + ]; + } + public function getAccountId($row) { $id = isset($row['account_id']) ? $row['account_id'] : null; diff --git a/config/import.php b/config/import.php new file mode 100644 index 000000000..9b20f5d02 --- /dev/null +++ b/config/import.php @@ -0,0 +1,19 @@ + [ + + // Type + 'transaction' => [ + + ], + ], + +]; 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..eb97cad7b 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 recording expenses, scanning receipts, and eliminate manual work', + 'ofx' => 'Import your bank transactions into Akaunting today.', + 'mt940' => 'This app allows you to import your bank transactions into Akaunting through the MT940 file provided by the bank.', + ]; diff --git a/resources/views/banking/transactions/import.blade.php b/resources/views/banking/transactions/import.blade.php new file mode 100644 index 000000000..eba873e9d --- /dev/null +++ b/resources/views/banking/transactions/import.blade.php @@ -0,0 +1,308 @@ + + + {{ trans('import.title', ['type' => $title_type]) }} + + + + + +
+
+
+

+ {{ trans_choice('general.bank_feeds', 2) }} +

+ +

+ {{ trans('import.bank_feeds') }} +

+
+ +
+ + + + + +
+
+
+ +
+ +
+ + + + +
+ + + +
+
+ +
+
+ @if (! empty($route)) + + {{ trans('general.cancel') }} + + @else + + {{ trans('general.cancel') }} + + @endif + + + + {{ trans('import.import') }} + + +
+
+
+
+ + +
+ + +
+