mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-27 11:20:39 -06:00
Changes to the CSV importer because I ran into small bugs.
This commit is contained in:
parent
569e8b6180
commit
4cd7976f63
@ -32,7 +32,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
||||
|
||||
if (is_null($account)) {
|
||||
// create it if doesn't exist.
|
||||
$account = Account::firstOrCreateEncrypted(
|
||||
$account = Account::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'name' => $this->value,
|
||||
'iban' => $this->value,
|
||||
|
@ -36,7 +36,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
||||
}
|
||||
|
||||
// create it if doesnt exist.
|
||||
$account = Account::firstOrCreateEncrypted(
|
||||
$account = Account::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'name' => $this->value,
|
||||
'iban' => '',
|
||||
|
@ -22,7 +22,7 @@ class BudgetName extends BasicConverter implements ConverterInterface
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$budget = Budget::firstOrCreateEncrypted(
|
||||
$budget = Budget::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'name' => $this->value,
|
||||
'user_id' => Auth::user()->id,
|
||||
|
@ -22,7 +22,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
|
||||
if (isset($this->mapped[$this->index][$this->value])) {
|
||||
$category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);
|
||||
} else {
|
||||
$category = Category::firstOrCreateEncrypted(
|
||||
$category = Category::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'name' => $this->value,
|
||||
'user_id' => Auth::user()->id,
|
||||
|
@ -16,6 +16,8 @@ class Description extends BasicConverter implements ConverterInterface
|
||||
*/
|
||||
public function convert()
|
||||
{
|
||||
return trim($this->data['description'] . ' ' . $this->value);
|
||||
$description = $this->data['description'] ?? '';
|
||||
|
||||
return trim($description . ' ' . $this->value);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class TagsComma extends BasicConverter implements ConverterInterface
|
||||
|
||||
$strings = explode(',', $this->value);
|
||||
foreach ($strings as $string) {
|
||||
$tag = Tag::firstOrCreateEncrypted(
|
||||
$tag = Tag::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'tag' => $string,
|
||||
'tagMode' => 'nothing',
|
||||
|
@ -23,7 +23,7 @@ class TagsSpace extends BasicConverter implements ConverterInterface
|
||||
|
||||
$strings = explode(' ', $this->value);
|
||||
foreach ($strings as $string) {
|
||||
$tag = Tag::firstOrCreateEncrypted(
|
||||
$tag = Tag::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'tag' => $string,
|
||||
'tagMode' => 'nothing',
|
||||
|
@ -169,7 +169,7 @@ class Importer
|
||||
|
||||
// second transaction
|
||||
$accountId = $this->importData['opposing-account-object']->id; // create second transaction:
|
||||
$amount = bcmul($this->importData['amount'], -1);
|
||||
$amount = bcmul($this->importData['amount'], '-1');
|
||||
$transaction = Transaction::create(['transaction_journal_id' => $journal->id, 'account_id' => $accountId, 'amount' => $amount]);
|
||||
$errors = $transaction->getErrors()->merge($errors);
|
||||
}
|
||||
@ -195,7 +195,7 @@ class Importer
|
||||
|
||||
Log::info('Created journal #' . $journalId . ' of type ' . $type . '!');
|
||||
Log::info('Asset account #' . $asset->id . ' lost/gained: ' . $this->importData['amount']);
|
||||
Log::info($opposing->accountType->type . ' #' . $opposing->id . ' lost/gained: ' . bcmul($this->importData['amount'], -1));
|
||||
Log::info($opposing->accountType->type . ' #' . $opposing->id . ' lost/gained: ' . bcmul($this->importData['amount'], '-1'));
|
||||
|
||||
return $journal;
|
||||
}
|
||||
@ -296,7 +296,8 @@ class Importer
|
||||
foreach ($set as $className) {
|
||||
/** @var PostProcessorInterface $postProcessor */
|
||||
$postProcessor = app('FireflyIII\Helpers\Csv\PostProcessing\\' . $className);
|
||||
$postProcessor->setData($this->importData);
|
||||
$array = $this->importData ?? [];
|
||||
$postProcessor->setData($array);
|
||||
Log::debug('Now post-process processor named ' . $className . ':');
|
||||
$this->importData = $postProcessor->process();
|
||||
}
|
||||
@ -343,7 +344,9 @@ class Importer
|
||||
*/
|
||||
protected function validateData()
|
||||
{
|
||||
if (is_null($this->importData['date']) && is_null($this->importData['date-rent'])) {
|
||||
$date = $this->importData['date'] ?? null;
|
||||
$rentDate = $this->importData['date-rent'] ?? null;
|
||||
if (is_null($date) && is_null($rentDate)) {
|
||||
return 'No date value for this row.';
|
||||
}
|
||||
if (is_null($this->importData['opposing-account-object'])) {
|
||||
|
@ -20,7 +20,9 @@ class Amount implements PostProcessorInterface
|
||||
public function process()
|
||||
{
|
||||
bcscale(2);
|
||||
$this->data['amount'] = bcmul($this->data['amount'], $this->data['amount-modifier']);
|
||||
$amount = $this->data['amount'] ?? '0';
|
||||
$modifier = strval($this->data['amount-modifier']);
|
||||
$this->data['amount'] = bcmul($amount, $modifier);
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
|
@ -18,7 +18,8 @@ class Description implements PostProcessorInterface
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$this->data['description'] = trim($this->data['description']);
|
||||
$description = $this->data['description'] ?? '';
|
||||
$this->data['description'] = trim($description);
|
||||
if (strlen($this->data['description']) == 0) {
|
||||
$this->data['description'] = trans('firefly.csv_empty_description');
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ class OpposingAccount implements PostProcessorInterface
|
||||
// create if not exists:
|
||||
$name = is_string($this->data['opposing-account-name']) && strlen($this->data['opposing-account-name']) > 0 ? $this->data['opposing-account-name']
|
||||
: $this->data['opposing-account-iban'];
|
||||
$account = Account::firstOrCreateEncrypted(
|
||||
$account = Account::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'user_id' => Auth::user()->id,
|
||||
'account_type_id' => $accountType->id,
|
||||
@ -195,7 +195,7 @@ class OpposingAccount implements PostProcessorInterface
|
||||
}
|
||||
}
|
||||
// create if not exists:
|
||||
$account = Account::firstOrCreateEncrypted(
|
||||
$account = Account::firstOrCreateEncrypted( // TODO use repository
|
||||
[
|
||||
'user_id' => Auth::user()->id,
|
||||
'account_type_id' => $accountType->id,
|
||||
|
@ -141,7 +141,7 @@ class Wizard implements WizardInterface
|
||||
/** @var MapperInterface $mapObject */
|
||||
$mapObject = app($class);
|
||||
} catch (ReflectionException $e) {
|
||||
throw new FireflyException('Column "' . $columnRole . '" cannot be mapped because class ' . $mapper . ' does not exist.');
|
||||
throw new FireflyException('Column "' . $columnRole . '" cannot be mapped because mapper class ' . $mapper . ' does not exist.');
|
||||
}
|
||||
$set = $mapObject->getMap();
|
||||
$options[$index] = $set;
|
||||
|
@ -219,8 +219,9 @@ class CsvController extends Controller
|
||||
}
|
||||
|
||||
// process given roles and mapping:
|
||||
$inputMap = Input::get('map') ?? [];
|
||||
$roles = $this->wizard->processSelectedRoles(Input::get('role'));
|
||||
$maps = $this->wizard->processSelectedMapping($roles, Input::get('map'));
|
||||
$maps = $this->wizard->processSelectedMapping($roles, $inputMap);
|
||||
|
||||
Session::put('csv-map', $maps);
|
||||
Session::put('csv-roles', $roles);
|
||||
|
Loading…
Reference in New Issue
Block a user