mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
More code for import.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace FireflyIII\Import\Importer;
|
||||
|
||||
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Crud\Account\AccountCrud;
|
||||
use FireflyIII\Import\Role\Map;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
@@ -50,12 +51,23 @@ class CsvImporter implements ImporterInterface
|
||||
'tab' => trans('form.csv_tab'),
|
||||
];
|
||||
|
||||
$specifics = [];
|
||||
|
||||
// collect specifics.
|
||||
foreach (config('firefly.csv_import_specifics') as $name => $className) {
|
||||
$specifics[$name] = [
|
||||
'name' => $className::getName(),
|
||||
'description' => $className::getDescription(),
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'accounts' => ExpandedForm::makeSelectList($accounts),
|
||||
'specifix' => [],
|
||||
'delimiters' => $delimiters,
|
||||
'upload_path' => storage_path('upload'),
|
||||
'is_upload_possible' => is_writable(storage_path('upload')),
|
||||
'specifics' => $specifics,
|
||||
];
|
||||
|
||||
return $data;
|
||||
@@ -73,6 +85,40 @@ class CsvImporter implements ImporterInterface
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function saveImportConfiguration(array $data): bool
|
||||
{
|
||||
/** @var AccountCrud $repository */
|
||||
$repository = app(AccountCrud::class);
|
||||
$account = $repository->find(intval($data['csv_import_account']));
|
||||
$configuration = [
|
||||
'date_format' => $data['date_format'],
|
||||
'csv_delimiter' => $data['csv_delimiter'],
|
||||
'csv_import_account' => 0,
|
||||
'specifics' => [],
|
||||
];
|
||||
|
||||
if (!is_null($account->id)) {
|
||||
$configuration['csv_import_account'] = $account->id;
|
||||
}
|
||||
// loop specifics.
|
||||
if (is_array($data['specifics'])) {
|
||||
foreach ($data['specifics'] as $name => $enabled) {
|
||||
$configuration['specifics'][] = $name;
|
||||
}
|
||||
}
|
||||
$this->job->configuration = $configuration;
|
||||
$this->job->save();
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
*/
|
||||
|
@@ -36,6 +36,13 @@ interface ImporterInterface
|
||||
*/
|
||||
public function getConfigurationData(): array;
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function saveImportConfiguration(array $data): bool;
|
||||
|
||||
/**
|
||||
* Returns a Map thing used to allow the user to
|
||||
* define roles for each entry.
|
||||
|
37
app/Import/Specifics/AbnAmroDescription.php
Normal file
37
app/Import/Specifics/AbnAmroDescription.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* AbnAmroDescription.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class AbnAmroDescription
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
*/
|
||||
class AbnAmroDescription implements SpecificInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getName(): string
|
||||
{
|
||||
return 'ABN Amro description';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getDescription(): string
|
||||
{
|
||||
return 'Fixes possible problems with ABN Amro descriptions.';
|
||||
}
|
||||
}
|
36
app/Import/Specifics/RabobankDescription.php
Normal file
36
app/Import/Specifics/RabobankDescription.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* RabobankDescription.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Class RabobankDescription
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
*/
|
||||
class RabobankDescription implements SpecificInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getName(): string
|
||||
{
|
||||
return 'Rabobank description';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getDescription(): string
|
||||
{
|
||||
return 'Fixes possible problems with Rabobank descriptions.';
|
||||
}
|
||||
}
|
31
app/Import/Specifics/SpecificInterface.php
Normal file
31
app/Import/Specifics/SpecificInterface.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* SpecificInterface.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Import\Specifics;
|
||||
|
||||
/**
|
||||
* Interface SpecificInterface
|
||||
*
|
||||
* @package FireflyIII\Import\Specifics
|
||||
*/
|
||||
interface SpecificInterface
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getName(): string;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
static public function getDescription(): string;
|
||||
|
||||
}
|
Reference in New Issue
Block a user