Files
firefly-iii/app/Export/Entry/Entry.php

100 lines
3.1 KiB
PHP
Raw Normal View History

2016-02-04 17:16:16 +01:00
<?php
/**
* Entry.php
2016-04-01 16:44:46 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-04 17:16:16 +01:00
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
2016-02-04 17:16:16 +01:00
*/
declare(strict_types=1);
2016-04-26 12:39:29 +02:00
namespace FireflyIII\Export\Entry;
2016-02-04 17:16:16 +01:00
2017-02-19 07:34:39 +01:00
use Steam;
2016-02-04 17:16:16 +01:00
/**
* To extend the exported object, in case of new features in Firefly III for example,
* do the following:
*
2016-04-26 20:49:22 +02:00
* - Add the field(s) to this class. If you add more than one related field, add a new object.
2016-02-04 17:16:16 +01:00
* - 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
2016-12-27 19:59:56 +01:00
* @SuppressWarnings(PHPMD.LongVariable)
2016-02-04 17:16:16 +01:00
*
2016-04-26 12:39:29 +02:00
* @package FireflyIII\Export\Entry
2016-02-04 17:16:16 +01:00
*/
2016-05-20 08:00:35 +02:00
final class Entry
2016-02-04 17:16:16 +01:00
{
2016-10-23 14:58:39 +02:00
// @formatter:off
2016-10-23 09:44:14 +02:00
public $journal_id;
2016-02-04 17:16:16 +01:00
public $date;
public $description;
2016-10-23 09:44:14 +02:00
public $currency_code;
public $amount;
public $transaction_type;
public $source_account_id;
public $source_account_name;
public $destination_account_id;
public $destination_account_name;
public $budget_id;
public $budget_name;
public $category_id;
public $category_name;
2016-10-23 14:58:39 +02:00
// @formatter:on
/**
* Entry constructor.
*/
private function __construct()
{
}
2016-02-04 17:16:16 +01:00
/**
2016-10-23 09:44:14 +02:00
* @param $object
2016-02-04 17:16:16 +01:00
*
* @return Entry
*/
2016-10-23 09:44:14 +02:00
public static function fromObject($object): Entry
2016-02-04 17:16:16 +01:00
{
2016-12-27 19:59:56 +01:00
$entry = new self;
$entry->journal_id = $object->transaction_journal_id;
2017-02-19 07:34:39 +01:00
$entry->description = Steam::decrypt(intval($object->journal_encrypted), $object->journal_description);
$entry->amount = $object->amount;
2016-12-27 19:59:56 +01:00
$entry->date = $object->date;
$entry->transaction_type = $object->transaction_type;
$entry->currency_code = $object->transaction_currency_code;
$entry->source_account_id = $object->account_id;
2017-02-19 07:34:39 +01:00
$entry->source_account_name = Steam::decrypt(intval($object->account_name_encrypted), $object->account_name);
2016-10-23 09:44:14 +02:00
$entry->destination_account_id = $object->opposing_account_id;
2017-02-19 07:34:39 +01:00
$entry->destination_account_name = Steam::decrypt(intval($object->opposing_account_encrypted), $object->opposing_account_name);
2016-12-27 19:59:56 +01:00
$entry->category_id = $object->category_id ?? '';
$entry->category_name = $object->category_name ?? '';
$entry->budget_id = $object->budget_id ?? '';
$entry->budget_name = $object->budget_name ?? '';
2016-02-04 17:16:16 +01:00
2016-10-23 09:44:14 +02:00
// update description when transaction description is different:
2017-07-15 16:41:07 +02:00
if (!is_null($object->description) && $object->description !== $entry->description) {
2016-10-23 09:44:14 +02:00
$entry->description = $entry->description . ' (' . $object->description . ')';
}
return $entry;
2016-02-04 17:16:16 +01:00
}
2016-12-27 19:59:56 +01:00
2016-02-10 16:01:18 +01:00
}