Sistemazione query per liste movimenti
This commit is contained in:
parent
0e777445e9
commit
98b58b5bf7
@ -13,27 +13,21 @@ class Movimenti extends Model
|
||||
protected $dates = ['mov_data'];
|
||||
protected $casts = [ 'mov_data'=>'datetime'];
|
||||
|
||||
public static $query='SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public static function getList() {
|
||||
$query='SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
/* return DB::table('movimentis')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->leftJoin('gen_docs', 'entity_id','=','movimentis.id')
|
||||
// ->leftJoin('documentis', 'movimenti_id','=','movimentis.id') // #issue 5
|
||||
// ->where('gen_docs.entity','=',0)
|
||||
// ->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(entity_id) as quanti'))
|
||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')*/
|
||||
|
||||
|
||||
return DB::select(DB::raw(
|
||||
'SELECT
|
||||
a.id,
|
||||
@ -140,38 +134,51 @@ class Movimenti extends Model
|
||||
}
|
||||
|
||||
public static function listByCatMonth($month,$cat,$year) {
|
||||
return DB::table('movimentis')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->where('movimentis.mov_fk_categoria','=',$cat)
|
||||
->whereMonth('mov_data','=',$month)
|
||||
->whereYear('mov_data', '=' , $year)
|
||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
||||
->get();
|
||||
return DB::select(DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE Month(a.mov_data)='.$month.' AND Year(a.mov_data)='.$year.' AND a.mov_fk_categoria='.$cat
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
public static function listByCategory($cat) {
|
||||
return DB::table('movimentis')
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->where('movimentis.mov_fk_categoria','=',$cat)
|
||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
||||
->get();
|
||||
return DB::select(DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE a.mov_fk_categoria = '.$cat ));
|
||||
|
||||
}
|
||||
|
||||
public static function getByTag($tag) {
|
||||
return DB::table('movimentis')
|
||||
->where('mov_fk_tags','=',$tag)
|
||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
||||
->get();
|
||||
return DB::select(DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||
FROM movimentis as a
|
||||
JOIN tags as t ON a.mov_fk_tags=t.id
|
||||
JOIN categories as c ON a.mov_fk_categoria=c.id
|
||||
WHERE a.mov_fk_tags = '.$tag ));
|
||||
}
|
||||
|
||||
public static function importEstrattoIng($filename)
|
||||
|
Loading…
Reference in New Issue
Block a user