Files
firefly-iii/app/Support/Request/GetRecurrenceData.php

91 lines
3.1 KiB
PHP
Raw Normal View History

2018-02-10 09:57:31 +01:00
<?php
/**
* GetRecurrenceData.php
* Copyright (c) 2020 james@firefly-iii.org
2018-02-10 09:57:31 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-02-10 09:57:31 +01:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-02-10 09:57:31 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-02-10 09:57:31 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-02-10 09:57:31 +01:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-02-10 09:57:31 +01:00
*/
2018-05-11 10:08:34 +02:00
declare(strict_types=1);
namespace FireflyIII\Support\Request;
2018-03-10 22:38:20 +01:00
2018-02-10 09:57:31 +01:00
/**
* Trait GetRecurrenceData
2018-02-10 09:57:31 +01:00
*/
trait GetRecurrenceData
2018-02-10 09:57:31 +01:00
{
2020-03-19 14:33:41 +01:00
/**
* @param array $transaction
*
* @return array
*/
2021-03-14 16:08:49 +01:00
protected function getSingleTransactionData(array $transaction): array
2020-03-19 14:33:41 +01:00
{
2021-03-14 16:08:49 +01:00
$return = [];
// amount + currency
if (array_key_exists('amount', $transaction)) {
$return['amount'] = $transaction['amount'];
}
if (array_key_exists('currency_id', $transaction)) {
$return['currency_id'] = (int)$transaction['currency_id'];
}
if (array_key_exists('currency_code', $transaction)) {
$return['currency_code'] = $transaction['currency_code'];
}
// foreign amount + currency
if (array_key_exists('foreign_amount', $transaction)) {
$return['foreign_amount'] = $transaction['foreign_amount'];
}
if (array_key_exists('foreign_currency_id', $transaction)) {
$return['foreign_currency_id'] = (int)$transaction['foreign_currency_id'];
}
if (array_key_exists('foreign_currency_code', $transaction)) {
$return['foreign_currency_code'] = $transaction['foreign_currency_code'];
}
// source + dest
if (array_key_exists('source_id', $transaction)) {
$return['source_id'] = (int)$transaction['source_id'];
}
if (array_key_exists('destination_id', $transaction)) {
$return['destination_id'] = (int)$transaction['destination_id'];
}
// description
if (array_key_exists('description', $transaction)) {
$return['description'] = $transaction['description'];
}
if (array_key_exists('piggy_bank_id', $transaction)) {
$return['piggy_bank_id'] = (int)$transaction['piggy_bank_id'];
}
if (array_key_exists('tags', $transaction)) {
$return['tags'] = $transaction['tags'];
}
if (array_key_exists('budget_id', $transaction)) {
$return['budget_id'] = (int)$transaction['budget_id'];
}
if (array_key_exists('category_id', $transaction)) {
$return['category_id'] = (int)$transaction['category_id'];
}
return $return;
2020-03-19 14:33:41 +01:00
}
2020-03-14 07:30:55 +01:00
2018-02-10 09:57:31 +01:00
}