More code for import.

This commit is contained in:
James Cole
2016-06-24 14:24:34 +02:00
parent 9ffc0936ee
commit 3d201db6fc
16 changed files with 416 additions and 80 deletions

View File

@@ -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
*/

View File

@@ -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.

View 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.';
}
}

View 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.';
}
}

View 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;
}