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