firefly-iii/app/Export/Entry.php

464 lines
10 KiB
PHP
Raw Normal View History

2016-02-04 10:16:16 -06:00
<?php
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
2016-02-04 10:16:16 -06:00
/**
* Entry.php
2016-04-01 09:44:46 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-04 10:16:16 -06:00
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
namespace FireflyIII\Export;
2016-02-05 14:10:55 -06:00
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
2016-02-04 10:16:16 -06:00
use FireflyIII\Models\TransactionJournal;
/**
* To extend the exported object, in case of new features in Firefly III for example,
* do the following:
*
* - Add the field(s) to this class
* - Make sure the "fromJournal"-routine fills these fields.
* - Add them to the static function that returns its type (key=value. Remember that the only
* valid types can be found in config/csv.php (under "roles").
*
* These new entries should be should be strings and numbers as much as possible.
*
*
*
* Class Entry
*
* @package FireflyIII\Export
*/
class Entry
{
/** @var string */
public $amount;
2016-02-05 14:10:55 -06:00
/** @var int */
public $billId;
/** @var string */
public $billName;
/** @var int */
public $budgetId;
/** @var string */
public $budgetName;
/** @var int */
public $categoryId;
/** @var string */
public $categoryName;
2016-02-04 10:16:16 -06:00
/** @var string */
public $date;
/** @var string */
public $description;
2016-02-05 14:10:55 -06:00
/** @var string */
public $fromAccountIban;
/** @var int */
public $fromAccountId;
/** @var string */
public $fromAccountName;
2016-04-18 12:41:16 -05:00
/** @var int */
2016-03-12 00:16:42 -06:00
public $fromAccountNumber;
2016-02-05 14:10:55 -06:00
/** @var string */
public $fromAccountType;
/** @var string */
public $toAccountIban;
/** @var int */
public $toAccountId;
/** @var string */
public $toAccountName;
2016-03-12 00:16:42 -06:00
public $toAccountNumber;
2016-02-05 14:10:55 -06:00
/** @var string */
public $toAccountType;
2016-02-04 10:16:16 -06:00
/**
* @param TransactionJournal $journal
*
* @return Entry
*/
public static function fromJournal(TransactionJournal $journal)
{
$entry = new self;
$entry->setDescription($journal->description);
$entry->setDate($journal->date->format('Y-m-d'));
$entry->setAmount(TransactionJournal::amount($journal));
2016-02-04 10:16:16 -06:00
2016-02-05 14:10:55 -06:00
/** @var Budget $budget */
$budget = $journal->budgets->first();
if (!is_null($budget)) {
$entry->setBudgetId($budget->id);
$entry->setBudgetName($budget->name);
}
/** @var Category $category */
$category = $journal->categories->first();
if (!is_null($category)) {
$entry->setCategoryId($category->id);
$entry->setCategoryName($category->name);
}
if (!is_null($journal->bill_id)) {
$entry->setBillId($journal->bill_id);
$entry->setBillName($journal->bill->name);
}
/** @var Account $sourceAccount */
$sourceAccount = TransactionJournal::sourceAccount($journal);
2016-02-05 14:10:55 -06:00
$entry->setFromAccountId($sourceAccount->id);
$entry->setFromAccountName($sourceAccount->name);
2016-02-05 14:12:19 -06:00
$entry->setFromAccountIban($sourceAccount->iban);
2016-02-05 14:10:55 -06:00
$entry->setFromAccountType($sourceAccount->accountType->type);
2016-03-12 00:16:42 -06:00
$entry->setFromAccountNumber($sourceAccount->getMeta('accountNumber'));
2016-02-05 14:10:55 -06:00
/** @var Account $destination */
$destination = TransactionJournal::destinationAccount($journal);
2016-02-05 14:10:55 -06:00
$entry->setToAccountId($destination->id);
$entry->setToAccountName($destination->name);
2016-02-05 14:12:19 -06:00
$entry->setToAccountIban($destination->iban);
2016-02-05 14:10:55 -06:00
$entry->setToAccountType($destination->accountType->type);
2016-03-12 00:16:42 -06:00
$entry->setToAccountNumber($destination->getMeta('accountNumber'));
2016-02-05 14:10:55 -06:00
2016-02-04 10:16:16 -06:00
return $entry;
}
/**
* @return array
*/
2016-02-06 09:22:12 -06:00
public static function getTypes(): array
2016-02-04 10:16:16 -06:00
{
// key = field name (see top of class)
// value = field type (see csv.php under 'roles')
return [
2016-04-18 12:41:16 -05:00
'amount' => 'amount',
'date' => 'date-transaction',
'description' => 'description',
'billId' => 'bill-id',
'billName' => 'bill-name',
'budgetId' => 'budget-id',
'budgetName' => 'budget-name',
'categoryId' => 'category-id',
'categoryName' => 'category-name',
'fromAccountId' => 'account-id',
'fromAccountNumber' => 'account-number',
'fromAccountName' => 'account-name',
'fromAccountIban' => 'account-iban',
'fromAccountType' => '_ignore', // no, Firefly cannot import what it exports. I know :D
'toAccountId' => 'opposing-id',
'toAccountNumber' => 'account-number',
'toAccountName' => 'opposing-name',
'toAccountIban' => 'opposing-iban',
'toAccountType' => '_ignore',
2016-02-04 10:16:16 -06:00
];
}
/**
* @return string
*/
2016-02-06 09:22:12 -06:00
public function getAmount(): string
2016-02-04 10:16:16 -06:00
{
return $this->amount;
}
/**
* @param string $amount
*/
2016-02-05 02:25:15 -06:00
public function setAmount(string $amount)
2016-02-04 10:16:16 -06:00
{
$this->amount = $amount;
}
2016-02-05 14:10:55 -06:00
/**
* @return int
*/
2016-04-06 09:37:28 -05:00
public function getBillId(): int
2016-02-05 14:10:55 -06:00
{
return $this->billId;
}
/**
* @param int $billId
*/
2016-04-06 09:37:28 -05:00
public function setBillId(int $billId)
2016-02-05 14:10:55 -06:00
{
$this->billId = $billId;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getBillName(): string
2016-02-05 14:10:55 -06:00
{
return $this->billName;
}
/**
* @param string $billName
*/
2016-04-06 09:37:28 -05:00
public function setBillName(string $billName)
2016-02-05 14:10:55 -06:00
{
$this->billName = $billName;
}
/**
* @return int
*/
2016-04-06 09:37:28 -05:00
public function getBudgetId(): int
2016-02-05 14:10:55 -06:00
{
return $this->budgetId;
}
/**
* @param int $budgetId
*/
2016-04-06 09:37:28 -05:00
public function setBudgetId(int $budgetId)
2016-02-05 14:10:55 -06:00
{
$this->budgetId = $budgetId;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getBudgetName(): string
2016-02-05 14:10:55 -06:00
{
return $this->budgetName;
}
/**
* @param string $budgetName
*/
2016-04-06 09:37:28 -05:00
public function setBudgetName(string $budgetName)
2016-02-05 14:10:55 -06:00
{
$this->budgetName = $budgetName;
}
/**
* @return int
*/
2016-04-06 09:37:28 -05:00
public function getCategoryId(): int
2016-02-05 14:10:55 -06:00
{
return $this->categoryId;
}
/**
* @param int $categoryId
*/
2016-04-06 09:37:28 -05:00
public function setCategoryId(int $categoryId)
2016-02-05 14:10:55 -06:00
{
$this->categoryId = $categoryId;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getCategoryName(): string
2016-02-05 14:10:55 -06:00
{
return $this->categoryName;
}
/**
* @param string $categoryName
*/
2016-04-06 09:37:28 -05:00
public function setCategoryName(string $categoryName)
2016-02-05 14:10:55 -06:00
{
$this->categoryName = $categoryName;
}
2016-02-04 10:16:16 -06:00
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getDate(): string
2016-02-04 10:16:16 -06:00
{
return $this->date;
}
/**
* @param string $date
*/
2016-02-05 02:25:15 -06:00
public function setDate(string $date)
2016-02-04 10:16:16 -06:00
{
$this->date = $date;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getDescription(): string
2016-02-04 10:16:16 -06:00
{
return $this->description;
}
/**
* @param string $description
*/
2016-02-05 02:25:15 -06:00
public function setDescription(string $description)
2016-02-04 10:16:16 -06:00
{
$this->description = $description;
}
2016-02-05 14:10:55 -06:00
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getFromAccountIban(): string
2016-02-05 14:10:55 -06:00
{
return $this->fromAccountIban;
}
/**
* @param string $fromAccountIban
*/
2016-04-06 09:37:28 -05:00
public function setFromAccountIban(string $fromAccountIban)
2016-02-05 14:10:55 -06:00
{
$this->fromAccountIban = $fromAccountIban;
}
/**
* @return int
*/
2016-04-06 09:37:28 -05:00
public function getFromAccountId():int
2016-02-05 14:10:55 -06:00
{
return $this->fromAccountId;
}
/**
* @param int $fromAccountId
*/
2016-04-06 09:37:28 -05:00
public function setFromAccountId(int $fromAccountId)
2016-02-05 14:10:55 -06:00
{
$this->fromAccountId = $fromAccountId;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getFromAccountName(): string
2016-02-05 14:10:55 -06:00
{
return $this->fromAccountName;
}
/**
* @param string $fromAccountName
*/
2016-04-06 09:37:28 -05:00
public function setFromAccountName(string $fromAccountName)
2016-02-05 14:10:55 -06:00
{
$this->fromAccountName = $fromAccountName;
}
2016-03-12 00:16:42 -06:00
/**
2016-04-06 09:37:28 -05:00
* @return string
2016-03-12 00:16:42 -06:00
*/
2016-04-06 09:37:28 -05:00
public function getFromAccountNumber(): string
2016-03-12 00:16:42 -06:00
{
return $this->fromAccountNumber;
}
/**
2016-04-06 09:37:28 -05:00
* @param string $fromAccountNumber
2016-03-12 00:16:42 -06:00
*/
2016-04-06 09:37:28 -05:00
public function setFromAccountNumber(string $fromAccountNumber)
2016-03-12 00:16:42 -06:00
{
$this->fromAccountNumber = $fromAccountNumber;
}
2016-02-05 14:10:55 -06:00
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getFromAccountType(): string
2016-02-05 14:10:55 -06:00
{
return $this->fromAccountType;
}
/**
* @param string $fromAccountType
*/
2016-04-06 09:37:28 -05:00
public function setFromAccountType(string $fromAccountType)
2016-02-05 14:10:55 -06:00
{
$this->fromAccountType = $fromAccountType;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getToAccountIban(): string
2016-02-05 14:10:55 -06:00
{
return $this->toAccountIban;
}
/**
* @param string $toAccountIban
*/
2016-04-06 09:37:28 -05:00
public function setToAccountIban(string $toAccountIban)
2016-02-05 14:10:55 -06:00
{
$this->toAccountIban = $toAccountIban;
}
/**
* @return int
*/
2016-04-06 09:37:28 -05:00
public function getToAccountId(): int
2016-02-05 14:10:55 -06:00
{
return $this->toAccountId;
}
/**
* @param int $toAccountId
*/
2016-04-06 09:37:28 -05:00
public function setToAccountId(int $toAccountId)
2016-02-05 14:10:55 -06:00
{
$this->toAccountId = $toAccountId;
}
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getToAccountName(): string
2016-02-05 14:10:55 -06:00
{
return $this->toAccountName;
}
/**
* @param string $toAccountName
*/
2016-04-06 09:37:28 -05:00
public function setToAccountName(string $toAccountName)
2016-02-05 14:10:55 -06:00
{
$this->toAccountName = $toAccountName;
}
2016-03-12 00:16:42 -06:00
/**
2016-04-06 09:37:28 -05:00
* @return string
2016-03-12 00:16:42 -06:00
*/
2016-04-06 09:37:28 -05:00
public function getToAccountNumber(): string
2016-03-12 00:16:42 -06:00
{
return $this->toAccountNumber;
}
/**
2016-04-06 09:37:28 -05:00
* @param string $toAccountNumber
2016-03-12 00:16:42 -06:00
*/
2016-04-06 09:37:28 -05:00
public function setToAccountNumber(string $toAccountNumber)
2016-03-12 00:16:42 -06:00
{
$this->toAccountNumber = $toAccountNumber;
}
2016-02-05 14:10:55 -06:00
/**
* @return string
*/
2016-04-06 09:37:28 -05:00
public function getToAccountType(): string
2016-02-05 14:10:55 -06:00
{
return $this->toAccountType;
}
/**
* @param string $toAccountType
*/
2016-04-06 09:37:28 -05:00
public function setToAccountType(string $toAccountType)
2016-02-05 14:10:55 -06:00
{
$this->toAccountType = $toAccountType;
}
2016-02-04 10:16:16 -06:00
2016-02-10 09:01:18 -06:00
}