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

112 lines
3.6 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.
*/
2016-04-26 05:39:29 -05:00
namespace FireflyIII\Export\Entry;
2016-02-04 10:16:16 -06:00
2016-02-05 14:10:55 -06:00
use FireflyIII\Models\Account;
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:
*
2016-04-26 13:49:22 -05:00
* - Add the field(s) to this class. If you add more than one related field, add a new object.
2016-02-04 10:16:16 -06: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-04-26 05:39:29 -05:00
* @package FireflyIII\Export\Entry
2016-02-04 10:16:16 -06:00
*/
class Entry
{
/** @var string */
public $amount;
2016-04-26 13:49:22 -05:00
/** @var EntryBill */
public $bill;
/** @var EntryBudget */
public $budget;
/** @var EntryCategory */
public $category;
2016-02-04 10:16:16 -06:00
/** @var string */
public $date;
/** @var string */
public $description;
2016-04-26 13:49:22 -05:00
/** @var EntryAccount */
public $destinationAccount;
/** @var EntryAccount */
public $sourceAccount;
2016-02-04 10:16:16 -06:00
/**
* @param TransactionJournal $journal
*
* @return Entry
*/
public static function fromJournal(TransactionJournal $journal)
{
2016-04-26 13:49:22 -05:00
$entry = new self;
$entry->description = $journal->description;
$entry->date = $journal->date->format('Y-m-d');
$entry->amount = TransactionJournal::amount($journal);
2016-02-05 14:10:55 -06:00
2016-04-26 13:49:22 -05:00
$entry->budget = new EntryBudget($journal->budgets->first());
$entry->category = new EntryCategory($journal->categories->first());
$entry->bill = new EntryBill($journal->bill);
2016-02-05 14:10:55 -06:00
/** @var Account $sourceAccount */
2016-04-26 13:49:22 -05:00
$sourceAccount = TransactionJournal::sourceAccount($journal);
$entry->sourceAccount = new EntryAccount($sourceAccount);
2016-02-05 14:10:55 -06:00
/** @var Account $destination */
2016-04-26 13:49:22 -05:00
$destination = TransactionJournal::destinationAccount($journal);
$entry->destinationAccount = new EntryAccount($destination);
2016-02-05 14:10:55 -06:00
2016-02-04 10:16:16 -06:00
return $entry;
}
/**
* @return array
*/
2016-04-26 13:49:22 -05:00
public static function getFieldsAndTypes(): 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-26 13:49:22 -05:00
'description' => 'description',
'amount' => 'amount',
'date' => 'date-transaction',
'source_account_id' => 'account-id',
'source_account_name' => 'account-name',
'source_account_iban' => 'account-iban',
'source_account_type' => '_ignore',
'source_account_number' => 'account-number',
'destination_account_id' => 'opposing-id',
'destination_account_name' => 'opposing-name',
'destination_account_iban' => 'opposing-iban',
'destination_account_type' => '_ignore',
'destination_account_number' => 'account-number',
'budget_id' => 'budget-id',
'budget_name' => 'budget-name',
'category_id' => 'category-id',
'category_name' => 'category-name',
'bill_id' => 'bill-id',
'bill_name' => 'bill-name',
2016-02-04 10:16:16 -06:00
];
}
2016-02-10 09:01:18 -06:00
}