mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 09:52:20 +00:00
Fix #893
This commit is contained in:
@@ -212,37 +212,47 @@ class ImportStorage
|
|||||||
*/
|
*/
|
||||||
private function isDoubleTransfer(array $parameters): bool
|
private function isDoubleTransfer(array $parameters): bool
|
||||||
{
|
{
|
||||||
|
Log::debug('Check if is a double transfer.');
|
||||||
if ($parameters['type'] !== TransactionType::TRANSFER) {
|
if ($parameters['type'] !== TransactionType::TRANSFER) {
|
||||||
|
Log::debug(sprintf('Is a %s, not a transfer so no.' . $parameters['type']));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$amount = app('steam')->positive($parameters['amount']);
|
$amount = app('steam')->positive($parameters['amount']);
|
||||||
$names = [$parameters['asset'], $parameters['opposing']];
|
$names = [$parameters['asset'], $parameters['opposing']];
|
||||||
$transfer = [];
|
$transfer = [];
|
||||||
$hits = 0;
|
|
||||||
sort($names);
|
sort($names);
|
||||||
|
|
||||||
foreach ($this->transfers as $transfer) {
|
foreach ($this->transfers as $transfer) {
|
||||||
|
$hits = 0;
|
||||||
if ($parameters['description'] === $transfer['description']) {
|
if ($parameters['description'] === $transfer['description']) {
|
||||||
$hits++;
|
$hits++;
|
||||||
|
Log::debug(sprintf('Description "%s" equals "%s", hits = %d', $parameters['description'], $transfer['description'], $hits));
|
||||||
}
|
}
|
||||||
if ($names === $transfer['names']) {
|
if ($names === $transfer['names']) {
|
||||||
$hits++;
|
$hits++;
|
||||||
|
Log::debug(sprintf('Involved accounts, "%s" equals "%s", hits = %d', join(',', $names), join(',', $transfer['names']), $hits));
|
||||||
}
|
}
|
||||||
if (bccomp($amount, $transfer['amount']) === 0) {
|
if (bccomp($amount, $transfer['amount']) === 0) {
|
||||||
$hits++;
|
$hits++;
|
||||||
|
Log::debug(sprintf('Amount %s equals %s, hits = %d', $amount, $transfer['amount'], $hits));
|
||||||
}
|
}
|
||||||
if ($parameters['date'] === $transfer['date']) {
|
if ($parameters['date'] === $transfer['date']) {
|
||||||
$hits++;
|
$hits++;
|
||||||
|
Log::debug(sprintf('Date %s equals %s, hits = %d', $parameters['date'], $transfer['date'], $hits));
|
||||||
|
}
|
||||||
|
// number of hits is 4? Then it's a match
|
||||||
|
if ($hits === 4) {
|
||||||
|
Log::error(
|
||||||
|
'There already is a transfer imported with these properties. Compare existing with new. ', ['existing' => $transfer, 'new' => $parameters]
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($hits === 4) {
|
|
||||||
Log::error(
|
|
||||||
'There already is a transfer imported with these properties. Compare existing with new. ', ['existing' => $transfer, 'new' => $parameters]
|
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user