Merge pull request #3244 from cuneytsenturk/master
Modify the Transactions import page template and add a dynamic import page feature
This commit is contained in:
commit
593a3228f2
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ImportViewCreated extends Event
|
||||
{
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $view
|
||||
*
|
||||
*/
|
||||
public function __construct($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ImportViewCreating extends Event
|
||||
{
|
||||
public $view;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $view
|
||||
*
|
||||
*/
|
||||
public function __construct($view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Banking\Transaction;
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Document\Document;
|
||||
use App\Models\Setting\Category;
|
||||
|
||||
return [
|
||||
|
||||
// Group
|
||||
'banking' => [
|
||||
|
||||
// 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',
|
||||
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -10,4 +10,9 @@ return [
|
|||
'drop_file' => '<span style="color: #006EA6;">Upload a file</span> 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!',
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,154 @@
|
|||
<x-layouts.admin>
|
||||
<x-slot name="title">
|
||||
{{ trans('import.title', ['type' => $title_type]) }}
|
||||
</x-slot>
|
||||
|
||||
<x-slot name="favorite"
|
||||
title="{{ trans('import.title', ['type' => $title_type]) }}"
|
||||
icon="import_export"
|
||||
url="{{ route('import.create', ['group' => $group, 'type' => $type]) }}"
|
||||
></x-slot>
|
||||
|
||||
<x-slot name="content">
|
||||
<div class="pt-6">
|
||||
<div class="relative -m-2 flex items-center space-x-4 rounded-xl p-4 focus-within:ring-2 focus-within:ring-gray-500 hover:bg-gray-100">
|
||||
<div>
|
||||
<h2 class="text-base font-semibold text-gray-900">
|
||||
<a href="{{ module_is_enabled('bank-feeds') ? route('bank-feeds.bank-connections.create') : route('apps.app.show', 'bank-feeds') }}" class="focus:outline-none">
|
||||
<span class="absolute inset-0" aria-hidden="true"></span>
|
||||
<span>{{ trans_choice('general.bank_feeds', 2) }}</span>
|
||||
<span aria-hidden="true"> →</span>
|
||||
</a>
|
||||
</h2>
|
||||
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
{{ trans('import.bank_feeds') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul role="list" class="mt-6 grid grid-cols-1 gap-x-8 gap-y-16 border-b border-t border-gray-200 py-6 sm:grid-cols-3">
|
||||
<li class="flow-root">
|
||||
<div class="relative -m-2 flex items-center space-x-4 rounded-xl p-4 focus-within:ring-2 focus-within:ring-gray-500 hover:bg-gray-100">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-900">
|
||||
<a href="{{ module_is_enabled('receipt') ? route('receipt.receipts.create') : route('apps.app.show', 'receipt') }}" class="focus:outline-none">
|
||||
<span class="absolute inset-0" aria-hidden="true"></span>
|
||||
<span>{{ trans_choice('general.receipts', 2) }}</span>
|
||||
<span aria-hidden="true"> →</span>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
{{ trans('import.receipts') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="flow-root">
|
||||
<div class="relative -m-2 flex items-center space-x-4 rounded-xl p-4 focus-within:ring-2 focus-within:ring-gray-500 hover:bg-gray-100">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-900">
|
||||
<a href="{{ module_is_enabled('ofx') ? route('ofx.ofx.create') : route('apps.app.show', 'ofx') }}" class="focus:outline-none">
|
||||
<span class="absolute inset-0" aria-hidden="true"></span>
|
||||
<span>{{ trans_choice('general.ofx', 2) }}</span>
|
||||
<span aria-hidden="true"> →</span>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
{{ trans('import.ofx') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li class="flow-root">
|
||||
<div class="relative -m-2 flex items-center space-x-4 rounded-xl p-4 focus-within:ring-2 focus-within:ring-gray-500 hover:bg-gray-100">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-gray-900">
|
||||
<a href="{{ module_is_enabled('mt940') ? route('mt940.create') : route('apps.app.show', 'mt940') }}" class="focus:outline-none">
|
||||
<span class="absolute inset-0" aria-hidden="true"></span>
|
||||
<span>{{ trans_choice('general.mt940', 2) }}</span>
|
||||
<span aria-hidden="true"> →</span>
|
||||
</a>
|
||||
</h3>
|
||||
|
||||
<p class="mt-1 text-sm text-gray-500">
|
||||
{{ trans('import.mt940') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<x-form id="import" :route="$form_params['route']" :url="$form_params['url']">
|
||||
<div class="flex flex-col lg:flex-row">
|
||||
<div class="hidden lg:flex w-4/12 ltr:-ml-10 rtl:-mr-10 ltr:mr-10 rtl:ml-10">
|
||||
<img src="{{ asset('public/img/import.png') }}" alt="{{ trans('import.title', ['type' => $title_type]) }}">
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class="hidden lg:flex w-4/12 mt-18 mr-14">
|
||||
<iframe width="560" height="244" src="https://www.youtube.com/embed/p98z142g2yY" frameborder="0" title="{{ trans('import.title', ['type' => $title_type]) }}" class="rounded-lg"></iframe>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<div class="card-body mt-8 lg:w-8/12 w-full">
|
||||
<div class="w-full mt-8 bg-blue-100 rounded-lg text-blue-700 px-4 py-2" role="alert">
|
||||
<div class="flex">
|
||||
<span class="material-icons ltr:mr-3 rtl:ml-3">error_outline</span>
|
||||
|
||||
<div class="font-semibold text-sm mt-1">
|
||||
{!! trans('import.sample_file_and_document', [
|
||||
'download_link' => $sample_file,
|
||||
'document_link' => $document_link
|
||||
]) !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<x-form.group.import
|
||||
name="import"
|
||||
dropzone-class="form-file"
|
||||
singleWidthClasses
|
||||
:options="['acceptedFiles' => '.xls,.xlsx']"
|
||||
form-group-class="mt-8"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<div class="sm:col-span-6 flex items-center justify-end">
|
||||
@if (! empty($route))
|
||||
<x-link href="{{ route(\Str::replaceFirst('.import', '.index', $route)) }}" class="px-6 py-1.5 mr-2 hover:bg-gray-200 rounded-lg" override="class">
|
||||
{{ trans('general.cancel') }}
|
||||
</x-link>
|
||||
@else
|
||||
<x-link href="{{ url($path) }}" class="px-6 py-1.5 hover:bg-gray-200 rounded-lg ltr:mr-2 rtl:ml-2" override="class">
|
||||
{{ trans('general.cancel') }}
|
||||
</x-link>
|
||||
@endif
|
||||
|
||||
<x-button
|
||||
type="submit"
|
||||
class="relative flex items-center justify-center bg-green hover:bg-green-700 text-white px-6 py-1.5 text-base rounded-lg disabled:bg-green-100"
|
||||
::disabled="form.loading"
|
||||
override="class"
|
||||
>
|
||||
<x-button.loading>
|
||||
{{ trans('import.import') }}
|
||||
</x-button.loading>
|
||||
</x-button>
|
||||
</div>
|
||||
</div>
|
||||
</x-form>
|
||||
</div>
|
||||
</x-slot>
|
||||
|
||||
<x-script folder="common" file="imports" />
|
||||
</x-layouts.admin>
|
||||
|
||||
Loading…
Reference in New Issue