Each CSV converter can set the certainty of their conversion.

This commit is contained in:
James Cole
2016-07-29 21:40:58 +02:00
parent 7707c81b2d
commit 3682467ae3
24 changed files with 1009 additions and 28 deletions

View File

@@ -56,6 +56,8 @@ class Amount extends BasicConverter implements ConverterInterface
$value = str_replace($search, '', $value);
}
$this->setCertainty(90);
return round(floatval($value), 4);

View File

@@ -35,6 +35,8 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
Log::debug('Going to convert ', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
@@ -46,6 +48,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
Log::debug('Found account in mapping. Should exist.', ['value' => $value, 'map' => $this->mapping[$value]]);
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
$this->setCertainty(100);
Log::debug('Found account by ID', ['id' => $account->id]);
return $account;
@@ -56,6 +59,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
$account = $repository->findByIban($value, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found account by IBAN', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
@@ -65,6 +69,7 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
['name' => 'Account with IBAN ' . $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
'active' => true]
);
$this->setCertainty(100);
return $account;
}

View File

@@ -35,6 +35,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using AssetAccountName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
@@ -47,7 +48,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
@@ -65,6 +66,7 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
['name' => $value, 'iban' => null, 'openingBalance' => 0, 'user' => $this->user->id, 'accountType' => 'asset', 'virtualBalance' => 0,
'active' => true]
);
$this->setCertainty(100);
return $account;

View File

@@ -57,7 +57,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
$account = $repository->findByAccountNumber($value, [AccountType::ASSET]);
if (!is_null($account->id)) {
Log::debug('Found account by name', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
@@ -66,6 +66,7 @@ class AssetAccountNumber extends BasicConverter implements ConverterInterface
['name' => 'Account with number ' . $value, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'asset',
'virtualBalance' => 0, 'active' => true]
);
$this->setCertainty(100);
return $account;

View File

@@ -11,7 +11,6 @@ declare(strict_types = 1);
namespace FireflyIII\Import\Converter;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Log;
@@ -35,6 +34,8 @@ class BillId extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using BillId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Bill;
}
@@ -46,6 +47,7 @@ class BillId extends BasicConverter implements ConverterInterface
$bill = $repository->find(intval($this->mapping[$value]));
if (!is_null($bill->id)) {
Log::debug('Found bill by ID', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
@@ -55,11 +57,15 @@ class BillId extends BasicConverter implements ConverterInterface
$bill = $repository->find($value);
if (!is_null($bill->id)) {
Log::debug('Found bill by ID ', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
$this->setCertainty(0);
return new Bill;
}

View File

@@ -35,6 +35,7 @@ class BillName extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using BillName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Bill;
}
@@ -46,7 +47,7 @@ class BillName extends BasicConverter implements ConverterInterface
$bill = $repository->find(intval($this->mapping[$value]));
if (!is_null($bill->id)) {
Log::debug('Found bill by ID', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
}
@@ -55,7 +56,7 @@ class BillName extends BasicConverter implements ConverterInterface
$bill = $repository->findByName($value);
if (!is_null($bill->id)) {
Log::debug('Found bill by name ', ['id' => $bill->id]);
$this->setCertainty(100);
return $bill;
}
@@ -75,6 +76,7 @@ class BillName extends BasicConverter implements ConverterInterface
]
);
$this->setCertainty(100);
return $bill;

View File

@@ -35,6 +35,7 @@ class BudgetId extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using BudgetId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Budget;
}
@@ -46,6 +47,7 @@ class BudgetId extends BasicConverter implements ConverterInterface
$budget = $repository->find(intval($this->mapping[$value]));
if (!is_null($budget->id)) {
Log::debug('Found budget by ID', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
@@ -55,11 +57,12 @@ class BudgetId extends BasicConverter implements ConverterInterface
$budget = $repository->find($value);
if (!is_null($budget->id)) {
Log::debug('Found budget by ID ', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
$this->setCertainty(0);
return new Budget;
}

View File

@@ -35,6 +35,7 @@ class BudgetName extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using BudgetName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Budget;
}
@@ -46,7 +47,7 @@ class BudgetName extends BasicConverter implements ConverterInterface
$budget = $repository->find(intval($this->mapping[$value]));
if (!is_null($budget->id)) {
Log::debug('Found budget by ID', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
}
@@ -55,7 +56,7 @@ class BudgetName extends BasicConverter implements ConverterInterface
$budget = $repository->findByName($value);
if (!is_null($budget->id)) {
Log::debug('Found budget by name ', ['id' => $budget->id]);
$this->setCertainty(100);
return $budget;
}
@@ -66,6 +67,7 @@ class BudgetName extends BasicConverter implements ConverterInterface
'user_id' => $this->user->id,
]
);
$this->setCertainty(100);
return $budget;

View File

@@ -35,6 +35,7 @@ class CategoryId extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using CategoryId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new Category;
}
@@ -46,7 +47,7 @@ class CategoryId extends BasicConverter implements ConverterInterface
$category = $repository->find(intval($this->mapping[$value]));
if (!is_null($category->id)) {
Log::debug('Found category by ID', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
}
@@ -55,11 +56,12 @@ class CategoryId extends BasicConverter implements ConverterInterface
$category = $repository->find($value);
if (!is_null($category->id)) {
Log::debug('Found category by ID ', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
// should not really happen. If the ID does not match FF, what is FF supposed to do?
$this->setCertainty(0);
return new Category;
}

View File

@@ -35,6 +35,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using CategoryName', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Category;
}
@@ -46,7 +47,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
$category = $repository->find(intval($this->mapping[$value]));
if (!is_null($category->id)) {
Log::debug('Found category by ID', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
}
@@ -55,7 +56,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
$category = $repository->findByName($value);
if (!is_null($category->id)) {
Log::debug('Found category by name ', ['id' => $category->id]);
$this->setCertainty(100);
return $category;
}
@@ -66,6 +67,7 @@ class CategoryName extends BasicConverter implements ConverterInterface
'user_id' => $this->user->id,
]
);
$this->setCertainty(100);
return $category;

View File

@@ -40,7 +40,7 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
@@ -49,7 +49,7 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
$currency = $repository->findByCode($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by code', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
$currency = $repository->store(
@@ -59,6 +59,7 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
'symbol' => $value,
]
);
$this->setCertainty(100);
return $currency;
}

View File

@@ -35,6 +35,7 @@ class CurrencyId extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using CurrencyId', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
@@ -46,7 +47,7 @@ class CurrencyId extends BasicConverter implements ConverterInterface
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
@@ -55,10 +56,10 @@ class CurrencyId extends BasicConverter implements ConverterInterface
$currency = $repository->find($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by ID ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
$this->setCertainty(0);
// should not really happen. If the ID does not match FF, what is FF supposed to do?
return new TransactionCurrency;

View File

@@ -34,6 +34,7 @@ class CurrencyName extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using CurrencyName', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
@@ -45,7 +46,7 @@ class CurrencyName extends BasicConverter implements ConverterInterface
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
@@ -54,7 +55,7 @@ class CurrencyName extends BasicConverter implements ConverterInterface
$currency = $repository->findByName($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by name ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
@@ -66,6 +67,7 @@ class CurrencyName extends BasicConverter implements ConverterInterface
'symbol' => strtoupper(substr($value, 0, 1)),
]
);
$this->setCertainty(100);
return $currency;

View File

@@ -34,6 +34,7 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using CurrencySymbol', ['value' => $value]);
if ($value === 0) {
$this->setCertainty(0);
return new TransactionCurrency;
}
@@ -45,7 +46,7 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
$currency = $repository->find(intval($this->mapping[$value]));
if (!is_null($currency->id)) {
Log::debug('Found currency by ID', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
}
@@ -54,7 +55,7 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
$currency = $repository->findBySymbol($value);
if (!is_null($currency->id)) {
Log::debug('Found currency by symbol ', ['id' => $currency->id]);
$this->setCertainty(100);
return $currency;
}
@@ -66,6 +67,7 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
'symbol' => $value,
]
);
$this->setCertainty(100);
return $currency;

View File

@@ -42,7 +42,7 @@ class Date extends BasicConverter implements ConverterInterface
throw new FireflyException(sprintf('Cannot convert "%s" to a valid date using format "%s".', $value, $this->config['date-format']));
}
Log::debug('Converted date', ['converted' => $date->toAtomString()]);
$this->setCertainty(100);
return $date;
}
}

View File

@@ -29,6 +29,7 @@ class Description extends BasicConverter implements ConverterInterface
// this should replace all control characters
// but leave utf8 intact:
$value = preg_replace('/[\x00-\x1F\x80-\x9F]/u', '', $value);
$this->setCertainty(100);
return strval($value);

View File

@@ -33,9 +33,11 @@ class INGDebetCredit extends BasicConverter implements ConverterInterface
if ($value === 'Af') {
Log::debug('Return -1');
$this->setCertainty(100);
return -1;
}
$this->setCertainty(100);
Log::debug('Return 1');
return 1;

View File

@@ -34,6 +34,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
Log::debug('Going to convert ', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
@@ -46,7 +47,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
@@ -59,6 +60,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
'The match between IBAN and account is uncertain because the type of transactions may not have been determined.',
['id' => $account->id, 'iban' => $value]
);
$this->setCertainty(50);
return $account;
}
@@ -67,6 +69,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
['name' => $value, 'iban' => $value, 'user' => $this->user->id, 'accountType' => 'import', 'virtualBalance' => 0, 'active' => true,
'openingBalance' => 0]
);
$this->setCertainty(100);
return $account;
}

View File

@@ -46,7 +46,7 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
@@ -59,7 +59,7 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
'The match between name and account is uncertain because the type of transactions may not have been determined.',
['id' => $account->id, 'name' => $value]
);
$this->setCertainty(50);
return $account;
}
@@ -68,6 +68,7 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
'openingBalance' => 0,
]
);
$this->setCertainty(100);
return $account;
}

View File

@@ -35,6 +35,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using OpposingAccountNumber', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Account;
}
@@ -47,7 +48,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
$account = $repository->find(intval($this->mapping[$value]));
if (!is_null($account->id)) {
Log::debug('Found account by ID', ['id' => $account->id]);
$this->setCertainty(100);
return $account;
}
}
@@ -55,8 +56,8 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
// not mapped? Still try to find it first:
$account = $repository->findByAccountNumber($value, []);
if (!is_null($account->id)) {
Log::debug('Found account by name', ['id' => $account->id]);
Log::debug('Found account by number', ['id' => $account->id]);
$this->setCertainty(50);
return $account;
}
@@ -65,6 +66,7 @@ class OpposingAccountNumber extends BasicConverter implements ConverterInterface
['name' => 'Account with number ' . $value, 'openingBalance' => 0, 'iban' => null, 'user' => $this->user->id, 'accountType' => 'asset',
'virtualBalance' => 0, 'active' => true]
);
$this->setCertainty(100);
return $account;

View File

@@ -32,11 +32,13 @@ class RabobankDebetCredit extends BasicConverter implements ConverterInterface
if ($value === 'D') {
Log::debug('Return -1');
$this->setCertainty(100);
return -1;
}
Log::debug('Return 1');
$this->setCertainty(100);
return 1;
}

View File

@@ -34,6 +34,7 @@ class TagsComma extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using TagsComma', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Collection;
}
$parts = array_unique(explode(',', $value));
@@ -79,6 +80,8 @@ class TagsComma extends BasicConverter implements ConverterInterface
Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
$set->push($tag);
}
$this->setCertainty(100);
return $set;
}
}

View File

@@ -34,6 +34,7 @@ class TagsSpace extends BasicConverter implements ConverterInterface
Log::debug('Going to convert using TagsSpace', ['value' => $value]);
if (strlen($value) === 0) {
$this->setCertainty(0);
return new Collection;
}
$parts = array_unique(explode(' ', $value));
@@ -79,6 +80,7 @@ class TagsSpace extends BasicConverter implements ConverterInterface
Log::debug('Created new tag', ['name' => $part, 'id' => $tag->id]);
$set->push($tag);
}
$this->setCertainty(100);
return $set;