diff --git a/app/Livewire/TransactionImportWire.php b/app/Livewire/TransactionImportWire.php index 4ffcbd2..938f472 100644 --- a/app/Livewire/TransactionImportWire.php +++ b/app/Livewire/TransactionImportWire.php @@ -133,11 +133,12 @@ public function parseCSV() : void // normalize data foreach ($lineArray as $key => $cell){ // tests - $moneyTest = Regex::match('/([0-9]+),([0-9]{1,2})/', $cell); + $moneyTest = Regex::match('/(\-?)([0-9]+),([0-9]{1,2})/', $cell); // conversions if($moneyTest->hasMatch()){ - $lineArray[$key] = $moneyTest->group(1) . '.' . $moneyTest->group(2); + // group 1: sign, group 2: money before delimiter, group 3: cents after delimiter + $lineArray[$key] = $moneyTest->group(1) . $moneyTest->group(2) . '.' . $moneyTest->group(3); } } return $lineArray; diff --git a/app/Rules/CsvTransactionImport/BalanceRule.php b/app/Rules/CsvTransactionImport/BalanceRule.php index 6c720bb..eff7068 100644 --- a/app/Rules/CsvTransactionImport/BalanceRule.php +++ b/app/Rules/CsvTransactionImport/BalanceRule.php @@ -32,13 +32,17 @@ public function __construct(Collection $differences,Collection $balances,?string public function validate(string $attribute, mixed $value, Closure $fail): void { try { - // if there is no inital balance (no prior transaction) then make sure4 the first csv entry as correct + // if there is no initial balance (no prior transaction) then make sure the first csv entry as correct $currentBalance = $this->initalBalance ?? bcsub($this->balances[0], $this->differences[0],2); foreach ($this->differences as $id => $currentValue){ $currentBalance = bcadd($currentBalance, $currentValue, 2); $csvBalance = $this->balances->get($id); if($currentBalance !== $csvBalance){ - $fail(__('konto.csv-verify-balance-error')); + $fail(__('konto.csv-verify-balance-error', [ + 'error-in-row' => $id + 1, + 'calc-saldo' => $currentBalance, + 'csv-saldo' => $csvBalance, + ])); } } }catch (\ValueError $error){ diff --git a/lang/de/konto.php b/lang/de/konto.php index ac0192f..3e2e09d 100644 --- a/lang/de/konto.php +++ b/lang/de/konto.php @@ -50,6 +50,6 @@ 'csv-verify-iban-error' => 'Validierungs-Fehler: Enthält ungültige IBANs', 'csv-verify-money-error' => 'Validierungs-Fehler: Enthält nicht-numerische Daten', 'csv-verify-balance-error-wrong-datatype' => 'Validierungs-Fehler: Falscher Datentyp', - 'csv-verify-balance-error' => 'Validierungsfehler: Es besteht evtl. keine lückenlose Transaktionshistorie.' + 'csv-verify-balance-error' => 'Validierungsfehler: Es besteht keine lückenlose Transaktionshistorie in Zeile :error-in-row der CSV. Berechnetes Saldo :calc-saldo ≠ CSV-Saldo :csv-saldo' ];