mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Code cleanup and tests.
This commit is contained in:
@@ -180,8 +180,8 @@ class ImportBill
|
||||
|
||||
Log::debug('Finding a mapped bill based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$bill = $this->repository->find($search);
|
||||
$search = intval($array['mapped']);
|
||||
$bill = $this->repository->find($search);
|
||||
|
||||
if (is_null($bill->id)) {
|
||||
Log::error(sprintf('There is no bill with id #%d. Invalid mapping will be ignored!', $search));
|
||||
|
||||
@@ -180,7 +180,7 @@ class ImportBudget
|
||||
|
||||
Log::debug('Finding a mapped budget based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$search = intval($array['mapped']);
|
||||
$budget = $this->repository->find($search);
|
||||
|
||||
if (is_null($budget->id)) {
|
||||
|
||||
@@ -174,7 +174,7 @@ class ImportCategory
|
||||
|
||||
Log::debug('Finding a mapped category based on', $array);
|
||||
|
||||
$search = intval($array['mapped']);
|
||||
$search = intval($array['mapped']);
|
||||
$category = $this->repository->find($search);
|
||||
|
||||
if (is_null($category->id)) {
|
||||
|
||||
@@ -65,19 +65,6 @@ class ImportJournal
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if ($this->description === '') {
|
||||
return '(no description)';
|
||||
}
|
||||
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ImportEntry constructor.
|
||||
*/
|
||||
@@ -157,6 +144,18 @@ class ImportJournal
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
if ($this->description === '') {
|
||||
return '(no description)';
|
||||
}
|
||||
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $hash
|
||||
*/
|
||||
|
||||
@@ -474,31 +474,32 @@ class ImportStorage
|
||||
private function verifyDoubleTransfer(TransactionType $transactionType, ImportJournal $importJournal): bool
|
||||
{
|
||||
if ($transactionType->type === TransactionType::TRANSFER) {
|
||||
$amount = Steam::positive($importJournal->getAmount());
|
||||
$date = $importJournal->getDate($this->dateFormat);
|
||||
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin(
|
||||
'transactions AS source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where(
|
||||
'destination.amount', '>', 0
|
||||
);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id')
|
||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->where('destination.amount', $amount)
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name']
|
||||
);
|
||||
$amount = Steam::positive($importJournal->getAmount());
|
||||
$date = $importJournal->getDate($this->dateFormat);
|
||||
$set = TransactionJournal::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->leftJoin(
|
||||
'transactions AS source', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'source.transaction_journal_id')->where('source.amount', '<', 0);
|
||||
}
|
||||
)
|
||||
->leftJoin(
|
||||
'transactions AS destination', function (JoinClause $join) {
|
||||
$join->on('transaction_journals.id', '=', 'destination.transaction_journal_id')->where(
|
||||
'destination.amount', '>', 0
|
||||
);
|
||||
}
|
||||
)
|
||||
->leftJoin('accounts as source_accounts', 'source.account_id', '=', 'source_accounts.id')
|
||||
->leftJoin('accounts as destination_accounts', 'destination.account_id', '=', 'destination_accounts.id')
|
||||
->where('transaction_journals.user_id', $this->job->user_id)
|
||||
->where('transaction_types.type', TransactionType::TRANSFER)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->where('destination.amount', $amount)
|
||||
->get(
|
||||
['transaction_journals.id', 'transaction_journals.encrypted', 'transaction_journals.description',
|
||||
'source_accounts.name as source_name', 'destination_accounts.name as destination_name']
|
||||
);
|
||||
|
||||
return $this->filterTransferSet($set, $importJournal);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user