diff --git a/app/Models/Movimenti.php b/app/Models/Movimenti.php index 5b0d0e3..5f1d5d3 100644 --- a/app/Models/Movimenti.php +++ b/app/Models/Movimenti.php @@ -247,7 +247,22 @@ public function ContoA() return md5($data.$movimento_dare.$movimento_avere.$descrizione); } + public function importHashExists($hash) + { + return self::where('import_hash', $hash)->exists(); + } + public function importNoDuplicate($data, $movimento_dare, $movimento_avere, $descrizione) + { + $hash = $this->makeHash($data, $movimento_dare, $movimento_avere, $descrizione); + $exists = self::where('import_hash', $hash)->exists(); + if (!$exists) { + self::create([ + // TODO: ...altri campi... + 'import_hash' => $hash, + ]); + } + } public static function getByTag($tag) { $expression=DB::raw('SELECT