sourceAccounts = new Collection; $this->destinationAccounts = new Collection; } /** * @param TransactionJournal $journal * * @return Entry */ public static function fromJournal(TransactionJournal $journal) { $entry = new self; $entry->description = $journal->description; $entry->date = $journal->date->format('Y-m-d'); $entry->amount = TransactionJournal::amount($journal); $entry->budget = new EntryBudget($journal->budgets->first()); $entry->category = new EntryCategory($journal->categories->first()); $entry->bill = new EntryBill($journal->bill); $sources = TransactionJournal::sourceAccountList($journal); $destinations = TransactionJournal::destinationAccountList($journal); $entry->sourceAccount = new EntryAccount($sources->first()); $entry->destinationAccount = new EntryAccount($destinations->first()); foreach ($sources as $source) { $entry->sourceAccounts->push(new EntryAccount($source)); } foreach ($destinations as $destination) { $entry->destinationAccounts->push(new EntryAccount($destination)); } return $entry; } /** * @return array */ public static function getFieldsAndTypes(): array { // key = field name (see top of class) // value = field type (see csv.php under 'roles') return [ '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', ]; } }