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 $dates = ['mov_data'];
|
||||||
protected $casts = [ 'mov_data'=>'datetime'];
|
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() {
|
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(
|
return DB::select(DB::raw(
|
||||||
'SELECT
|
'SELECT
|
||||||
a.id,
|
a.id,
|
||||||
@ -140,38 +134,51 @@ class Movimenti extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static function listByCatMonth($month,$cat,$year) {
|
public static function listByCatMonth($month,$cat,$year) {
|
||||||
return DB::table('movimentis')
|
return DB::select(DB::raw('SELECT
|
||||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
a.id,
|
||||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
a.mov_data,
|
||||||
->where('movimentis.mov_fk_categoria','=',$cat)
|
a.mov_importo,
|
||||||
->whereMonth('mov_data','=',$month)
|
a.mov_descrizione,
|
||||||
->whereYear('mov_data', '=' , $year)
|
c.cat_name,
|
||||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
t.tag_name,
|
||||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
(SELECT Count(entity_id) as quanti FROM gen_docs WHERE entity=0 AND entity_id = a.id) as quanti
|
||||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
FROM movimentis as a
|
||||||
->get();
|
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) {
|
public static function listByCategory($cat) {
|
||||||
return DB::table('movimentis')
|
return DB::select(DB::raw('SELECT
|
||||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
a.id,
|
||||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
a.mov_data,
|
||||||
->where('movimentis.mov_fk_categoria','=',$cat)
|
a.mov_importo,
|
||||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
a.mov_descrizione,
|
||||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
c.cat_name,
|
||||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
t.tag_name,
|
||||||
->get();
|
(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) {
|
public static function getByTag($tag) {
|
||||||
return DB::table('movimentis')
|
return DB::select(DB::raw('SELECT
|
||||||
->where('mov_fk_tags','=',$tag)
|
a.id,
|
||||||
->join('categories','movimentis.mov_fk_categoria','=','categories.id')
|
a.mov_data,
|
||||||
->join('tags','movimentis.mov_fk_tags','=','tags.id')
|
a.mov_importo,
|
||||||
->leftJoin('documentis', 'movimenti_id','=','movimentis.id')
|
a.mov_descrizione,
|
||||||
->select('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name', DB::raw('Count(movimenti_id) as quanti'))
|
c.cat_name,
|
||||||
->groupBy('movimentis.id','mov_data','mov_descrizione','mov_importo','cat_name','tag_name')
|
t.tag_name,
|
||||||
->get();
|
(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)
|
public static function importEstrattoIng($filename)
|
||||||
|
Loading…
Reference in New Issue
Block a user