import trait and config file updated..

This commit is contained in:
Cüneyt Şentürk 2024-12-04 16:52:47 +00:00
parent 5a23918dad
commit 5f65d8d33a
2 changed files with 136 additions and 37 deletions

View File

@ -26,53 +26,31 @@ 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)
{
$path = company_id() . '/' . $group . '/' . $type;
// Get the view path
$view = $this->getImportViewPath($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';
// 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 = 'common.import.create';
$import->data = compact('group', 'type', 'path', 'route', 'form_params', 'title_type', 'sample_file', 'document_link');
$import->view = $view;
$import->data = compact('group', 'type', 'route', 'path', 'title_type', 'sample_file', 'form_params', 'document_link');
event(new ImportViewCreating($import));
@ -499,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;
}
}

View File

@ -11,8 +11,25 @@ return [
'banking' => [
// Type
'transaction' => [
'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',
],
],