Some new converters.

This commit is contained in:
James Cole 2015-07-05 06:26:34 +02:00
parent 65122f0144
commit 1069db3c13
5 changed files with 71 additions and 17 deletions

View File

@ -11,10 +11,15 @@ class BasicConverter
{ {
/** @var array */ /** @var array */
protected $data; protected $data;
/** @var string */
protected $field;
/** @var int */
protected $index; protected $index;
/** @var array */ /** @var array */
protected $mapped; protected $mapped;
/** @var string */
protected $role; protected $role;
/** @var string */
protected $value; protected $value;
/** /**
@ -28,13 +33,29 @@ class BasicConverter
/** /**
* @param array $data * @param array $data
*/ */
public function setData($data) public function setData(array $data)
{ {
$this->data = $data; $this->data = $data;
} }
/** /**
* @return mixed * @return string
*/
public function getField()
{
return $this->field;
}
/**
* @param string $field
*/
public function setField($field)
{
$this->field = $field;
}
/**
* @return int
*/ */
public function getIndex() public function getIndex()
{ {
@ -42,7 +63,7 @@ class BasicConverter
} }
/** /**
* @param mixed $index * @param int $index
*/ */
public function setIndex($index) public function setIndex($index)
{ {
@ -66,7 +87,7 @@ class BasicConverter
} }
/** /**
* @return mixed * @return string
*/ */
public function getRole() public function getRole()
{ {
@ -74,7 +95,7 @@ class BasicConverter
} }
/** /**
* @param mixed $role * @param string $role
*/ */
public function setRole($role) public function setRole($role)
{ {
@ -82,7 +103,7 @@ class BasicConverter
} }
/** /**
* @return mixed * @return string
*/ */
public function getValue() public function getValue()
{ {
@ -90,7 +111,7 @@ class BasicConverter
} }
/** /**
* @param mixed $value * @param string $value
*/ */
public function setValue($value) public function setValue($value)
{ {

View File

@ -22,30 +22,34 @@ interface ConverterInterface
public function convert(); public function convert();
/** /**
* @param $index * @param int $index
*/ */
public function setIndex($index); public function setIndex($index);
/** /**
* @param $mapped * @param array $mapped
*/ */
public function setMapped($mapped); public function setMapped($mapped);
/** /**
* @param $role * @param string $role
*/ */
public function setRole($role); public function setRole($role);
/** /**
* @param $value * @param string $value
*/ */
public function setValue($value); public function setValue($value);
/** /**
* @param array $data * @param array $data
*
* @return mixed
*/ */
public function setData(array $data); public function setData(array $data);
/**
* @param string $field
*
*/
public function setField($field);
} }

View File

@ -0,0 +1,24 @@
<?php
namespace FireflyIII\Helpers\Csv\Converter;
/**
* Class OpposingName
*
* @package FireflyIII\Helpers\Csv\Converter
*/
class OpposingName extends BasicConverter implements ConverterInterface
{
/**
* This method cannot search yet for the correct account (Expense account or Revenue account) because simply put,
* Firefly doesn't know yet if this account needs to be an Expense account or a Revenue account. This depends
* on the amount which is in the current row and that's a big unknown.
*
* @return mixed
*/
public function convert()
{
return $this->value;
}
}

View File

@ -78,6 +78,7 @@ class Importer
/** @var ConverterInterface $converter */ /** @var ConverterInterface $converter */
$converter = App::make('FireflyIII\Helpers\Csv\Converter\\' . $class); $converter = App::make('FireflyIII\Helpers\Csv\Converter\\' . $class);
$converter->setData($data); // the complete array so far. $converter->setData($data); // the complete array so far.
$converter->setField($field);
$converter->setIndex($index); $converter->setIndex($index);
$converter->setValue($value); $converter->setValue($value);
$converter->setRole($role); $converter->setRole($role);

View File

@ -2,8 +2,8 @@
return [ return [
'roles' => [ 'roles' => [
'_ignore' => [ '_ignore' => [
'name' => '(ignore this column)', 'name' => '(ignore this column)',
'mappable' => false, 'mappable' => false,
'converter' => 'Ignore', 'converter' => 'Ignore',
'field' => 'ignored', 'field' => 'ignored',
], ],
@ -46,6 +46,8 @@ return [
'date-rent' => [ 'date-rent' => [
'name' => 'Rent calculation date', 'name' => 'Rent calculation date',
'mappable' => false, 'mappable' => false,
'converter' => 'Date',
'field' => 'date-rent',
], ],
'budget-id' => [ 'budget-id' => [
'name' => 'Budget ID (matching Firefly)', 'name' => 'Budget ID (matching Firefly)',
@ -96,8 +98,10 @@ return [
'mappable' => true, 'mappable' => true,
], ],
'opposing-name' => [ 'opposing-name' => [
'name' => 'Expense or revenue account name', 'name' => 'Expense or revenue account name',
'mappable' => true, 'mappable' => true,
'converter' => 'OpposingName',
'field' => 'opposing-account'
], ],
'opposing-iban' => [ 'opposing-iban' => [
'name' => 'Expense or revenue account IBAN', 'name' => 'Expense or revenue account IBAN',