mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
new export routine
This commit is contained in:
@@ -27,6 +27,7 @@ use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Preferences;
|
||||
use Schema;
|
||||
@@ -262,15 +263,23 @@ class UpgradeDatabase extends Command
|
||||
|
||||
$set->each(
|
||||
function (TransactionJournal $transfer) use ($repository) {
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $transfer->transactions()->where('amount', '<', 0)->first();
|
||||
$this->updateTransactionCurrency($transaction);
|
||||
$this->updateJournalCurrency($transaction);
|
||||
/** @var Collection $transactions */
|
||||
$transactions = $transfer->transactions()->where('amount', '<', 0)->get();
|
||||
$transactions->each(
|
||||
function (Transaction $transaction) {
|
||||
$this->updateTransactionCurrency($transaction);
|
||||
$this->updateJournalCurrency($transaction);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $transfer->transactions()->where('amount', '>', 0)->first();
|
||||
$this->updateTransactionCurrency($transaction);
|
||||
/** @var Collection $transactions */
|
||||
$transactions = $transfer->transactions()->where('amount', '>', 0)->get();
|
||||
$transactions->each(
|
||||
function (Transaction $transaction) {
|
||||
$this->updateTransactionCurrency($transaction);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@@ -148,13 +148,14 @@ final class Entry
|
||||
$entry->asset_account_iban = $transaction->account_iban;
|
||||
$entry->asset_account_number = $transaction->account_number;
|
||||
$entry->asset_account_bic = $transaction->account_bic;
|
||||
// asset_currency_code
|
||||
$entry->asset_currency_code = $transaction->account_currency_code;
|
||||
|
||||
$entry->opposing_account_id = $transaction->opposing_account_id;
|
||||
$entry->opposing_account_name = app('steam')->tryDecrypt($transaction->opposing_account_name);
|
||||
$entry->opposing_account_iban = $transaction->opposing_account_iban;
|
||||
$entry->opposing_account_number = $transaction->opposing_account_number;
|
||||
$entry->opposing_account_bic = $transaction->opposing_account_bic;
|
||||
// opposing currency code
|
||||
$entry->opposing_currency_code = $transaction->opposing_currency_code;
|
||||
|
||||
/** budget */
|
||||
$entry->budget_id = $transaction->transaction_budget_id;
|
||||
|
@@ -25,6 +25,7 @@ use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\ExportJob;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Storage;
|
||||
@@ -101,17 +102,22 @@ class ExpandedProcessor implements ProcessorInterface
|
||||
$notes = $this->getNotes($ids);
|
||||
$tags = $this->getTags($ids);
|
||||
$ibans = $this->getIbans($assetIds) + $this->getIbans($opposingIds);
|
||||
$currencies = $this->getAccountCurrencies($ibans);
|
||||
$transactions->each(
|
||||
function (Transaction $transaction) use ($notes, $tags, $ibans) {
|
||||
function (Transaction $transaction) use ($notes, $tags, $ibans, $currencies) {
|
||||
$journalId = intval($transaction->journal_id);
|
||||
$accountId = intval($transaction->account_id);
|
||||
$opposingId = intval($transaction->opposing_account_id);
|
||||
$currencyId = $ibans[$accountId]['currency_id'] ?? 0;
|
||||
$opposingCurrencyId = $ibans[$opposingId]['currency_id'] ?? 0;
|
||||
$transaction->notes = $notes[$journalId] ?? '';
|
||||
$transaction->tags = join(',', $tags[$journalId] ?? []);
|
||||
$transaction->account_number = $ibans[$accountId]['accountNumber'] ?? '';
|
||||
$transaction->account_bic = $ibans[$accountId]['BIC'] ?? '';
|
||||
$transaction->account_currency_code = $currencies[$currencyId] ?? '';
|
||||
$transaction->opposing_account_number = $ibans[$opposingId]['accountNumber'] ?? '';
|
||||
$transaction->opposing_account_bic = $ibans[$opposingId]['BIC'] ?? '';
|
||||
$transaction->opposing_currency_code = $currencies[$opposingCurrencyId] ?? '';
|
||||
|
||||
}
|
||||
);
|
||||
@@ -230,6 +236,31 @@ class ExpandedProcessor implements ProcessorInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getAccountCurrencies(array $array): array
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface $repository */
|
||||
$repository = app(CurrencyRepositoryInterface::class);
|
||||
$return = [];
|
||||
$ids = [];
|
||||
$repository->setUser($this->job->user);
|
||||
foreach ($array as $value) {
|
||||
$ids[] = $value['currency_id'] ?? 0;
|
||||
}
|
||||
$ids = array_unique($ids);
|
||||
$result = $repository->getByIds($ids);
|
||||
|
||||
foreach ($result as $currency) {
|
||||
$return[$currency->id] = $currency->code;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all IBAN / SWIFT / account numbers
|
||||
*
|
||||
|
@@ -34,12 +34,14 @@ use Watson\Validating\ValidatingTrait;
|
||||
* @property string $account_iban
|
||||
* @property string $account_number
|
||||
* @property string $account_bic
|
||||
* @property string $account_currency_code
|
||||
*
|
||||
* @property-read int $opposing_account_id
|
||||
* @property string $opposing_account_name
|
||||
* @property string $opposing_account_iban
|
||||
* @property string $opposing_account_number
|
||||
* @property string $opposing_account_bic
|
||||
* @property string $opposing_currency_code
|
||||
*
|
||||
*
|
||||
* @property-read int $transaction_budget_id
|
||||
|
@@ -166,6 +166,16 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
return TransactionCurrency::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $ids): Collection
|
||||
{
|
||||
return TransactionCurrency::whereIn('id', $ids)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
*
|
||||
|
@@ -90,6 +90,13 @@ interface CurrencyRepositoryInterface
|
||||
*/
|
||||
public function get(): Collection;
|
||||
|
||||
/**
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getByIds(array $ids): Collection;
|
||||
|
||||
/**
|
||||
* @param Preference $preference
|
||||
*
|
||||
|
Reference in New Issue
Block a user