sistemato alcuni riferimenti ad importo e modifica per sole spese. Vedere anche per entrate
This commit is contained in:
@@ -10,7 +10,8 @@ use Rap2hpoutre\FastExcel\FastExcel;
|
||||
use App\Models\Categorie;
|
||||
use App\Models\Conto;
|
||||
use App\Models\User;
|
||||
//use Illuminate\Support\Facades\Schema;
|
||||
use App\Models\ImportRule;
|
||||
|
||||
|
||||
class Movimenti extends Model
|
||||
{
|
||||
@@ -33,7 +34,8 @@ class Movimenti extends Model
|
||||
public static $query= 'SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
@@ -186,7 +188,8 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
'mov_data' => $request['mov_data'],
|
||||
'mov_fk_categoria'=>$request['mov_fk_categoria'],
|
||||
'mov_descrizione'=>$request['mov_descrizione'],
|
||||
'mov_importo'=>$request['mov_importo'],
|
||||
'mov_importo_dare' => $request['mov_importo_dare'],
|
||||
'mov_importo_avere' => $request['mov_importo_avere'],
|
||||
'mov_fk_tags'=>$request['mov_fk_tags'],
|
||||
'mov_inserito_da'=>$request['userid'],
|
||||
]);
|
||||
@@ -203,7 +206,8 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
$expression= DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
@@ -222,7 +226,8 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
$expression=DB::raw(' SELECT a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
@@ -241,7 +246,8 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
$expression=DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
@@ -357,25 +363,9 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
];
|
||||
}
|
||||
|
||||
// Test applicazione regole
|
||||
public function setCategoriaMovimento($movimento)
|
||||
{
|
||||
$rules= \App\Models\ImportRule::all();
|
||||
|
||||
foreach ($rules as $role)
|
||||
{
|
||||
if (preg_match("/$role->parola/i","$movimento->descrizione"))
|
||||
{
|
||||
$movimento->catemov_fk_categoria=$role->categoria_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$movimento->catemov_fk_categoria=1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Ritorna la categoria suggerita in base alla descrizione del movimento da utilizzare sul db
|
||||
public static function getSuggestedCategory($descrizione)
|
||||
{
|
||||
$rule = ImportRule::whereRaw('? LIKE CONCAT("%", pattern, "%")', [$descrizione])->first();
|
||||
@@ -384,7 +374,7 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public static function setCategoriesFromCsv($descrizione)
|
||||
{
|
||||
$rules = \App\Models\ImportRule::all();
|
||||
$rules = ImportRule::all();
|
||||
$categoria = 1; // Default category
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
@@ -400,12 +390,13 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
|
||||
|
||||
|
||||
// Ritorna gli anni presenti nei movimenti
|
||||
public static function getYearsFromMovimenti()
|
||||
{
|
||||
$anni=DB::table('movimentis')->select(DB::raw('DISTINCT YEAR(mov_data) as anno'))->get();
|
||||
// dd($anni); // for test purposes
|
||||
return $anni;
|
||||
return self::selectRaw('YEAR(mov_data) as anno')
|
||||
->distinct()
|
||||
->orderBy('anno', 'desc')
|
||||
->get();
|
||||
}
|
||||
|
||||
|
||||
@@ -424,24 +415,27 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
}
|
||||
}
|
||||
|
||||
// Ritorna la somma delle entrate per un anno specifico
|
||||
public static function getEntrate($year)
|
||||
{
|
||||
$entrate_anno=DB::table('movimentis')
|
||||
->where('mov_importo','>',0)
|
||||
->whereYear('mov_data', '=' , $year)
|
||||
->sum('mov_importo');
|
||||
//->get();
|
||||
return $entrate_anno;
|
||||
return self::whereYear('mov_data', $year)
|
||||
->sum('mov_importo_avere');
|
||||
}
|
||||
|
||||
// Ritorna la somma delle uscite per un anno specifico
|
||||
public static function getUscite($year)
|
||||
{
|
||||
$uscite_anno=DB::table('movimentis')
|
||||
->where('mov_importo','<',0)
|
||||
->whereYear('mov_data', '=' , $year)
|
||||
->sum('mov_importo');
|
||||
//->get();
|
||||
return ($uscite_anno);
|
||||
return self::whereYear('mov_data', $year)
|
||||
->sum('mov_importo_dare');
|
||||
}
|
||||
|
||||
public static function cleanImporto($importo){
|
||||
// Rimuove i punti e sostituisce la virgola con un punto
|
||||
$importo = str_replace('.', '', $importo);
|
||||
$importo = str_replace(',', '.', $importo);
|
||||
$importo = str_replace('-', '', $importo);
|
||||
$importo = str_replace('+', '', $importo);
|
||||
return $importo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user