Effettuato modifiche al report annuale e alla lista movimenti per problema ISSUE#3
This commit is contained in:
@@ -44,10 +44,15 @@ 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 function Conto()
|
||||
{
|
||||
return $this->belongsTo(Conto::class);
|
||||
}
|
||||
public function ContoDa()
|
||||
{
|
||||
return $this->belongsTo(Conto::class, 'conto_id_da');
|
||||
}
|
||||
|
||||
public function ContoA()
|
||||
{
|
||||
return $this->belongsTo(Conto::class, 'conto_id_a');
|
||||
}
|
||||
|
||||
public function User()
|
||||
{
|
||||
@@ -56,7 +61,7 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public function Categorie()
|
||||
{
|
||||
return $this->belongsTo(Categorie::class);
|
||||
return $this->belongsTo(Categorie::class, 'mov_fk_categoria');
|
||||
}
|
||||
|
||||
public function Tags()
|
||||
@@ -66,26 +71,10 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public static function getList() {
|
||||
|
||||
// ISSUE #3 - Aggiunta visualizzazione conto da e conto a nella lista dei movimenti
|
||||
// e risoluzione duplicazione movimenti.
|
||||
|
||||
$expression=DB::raw(
|
||||
'SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
a.mov_descrizione,
|
||||
c.cat_name,
|
||||
t.tag_name,
|
||||
co.nomeConto,
|
||||
(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
|
||||
JOIN contos as co ON a.conto_id_da=co.id'
|
||||
);
|
||||
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
return self::with(['Tags', 'Categorie', 'ContoDa', 'ContoA'])->orderBy('mov_data','desc')->get();
|
||||
}
|
||||
|
||||
public static function getSaldo($date) {
|
||||
@@ -182,17 +171,17 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
}
|
||||
|
||||
public static function updateMovimenti($request) {
|
||||
DB::table('movimentis')
|
||||
->where('id','=', $request['id'])
|
||||
->update([
|
||||
'mov_data' => $request['mov_data'],
|
||||
'mov_fk_categoria'=>$request['mov_fk_categoria'],
|
||||
'mov_descrizione'=>$request['mov_descrizione'],
|
||||
'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'],
|
||||
]);
|
||||
$updateData = [];
|
||||
if (isset($request['mov_data'])) $updateData['mov_data'] = $request['mov_data'];
|
||||
if (isset($request['mov_fk_categoria'])) $updateData['mov_fk_categoria'] = $request['mov_fk_categoria'];
|
||||
if (isset($request['mov_descrizione'])) $updateData['mov_descrizione'] = $request['mov_descrizione'];
|
||||
if (isset($request['mov_importo_dare'])) $updateData['mov_importo_dare'] = $request['mov_importo_dare'];
|
||||
if (isset($request['mov_importo_avere'])) $updateData['mov_importo_avere'] = $request['mov_importo_avere'];
|
||||
if (isset($request['mov_fk_tags'])) $updateData['mov_fk_tags'] = $request['mov_fk_tags'];
|
||||
if (isset($request['userid'])) $updateData['mov_inserito_da'] = $request['userid'];
|
||||
|
||||
self::where('id', $request['id'])->update($updateData);
|
||||
|
||||
}
|
||||
|
||||
public static function deleteMovimento($id) {
|
||||
@@ -203,23 +192,27 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
|
||||
public static function listByCatMonth($month,$cat,$year) {
|
||||
|
||||
$expression= DB::raw('SELECT
|
||||
a.id,
|
||||
a.mov_data,
|
||||
a.mov_importo_dare,
|
||||
a.mov_importo_avere,
|
||||
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
|
||||
);
|
||||
$query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
return DB::select($query);
|
||||
|
||||
// $expression= DB::raw('SELECT
|
||||
// a.id,
|
||||
// a.mov_data,
|
||||
// a.mov_importo_dare,
|
||||
// a.mov_importo_avere,
|
||||
// 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
|
||||
// );
|
||||
// $query = $expression->getValue(DB::connection()->getQueryGrammar());
|
||||
// return DB::select($query);
|
||||
return self::with(['Tags', 'Categorie'])
|
||||
->whereMonth('mov_data', $month)
|
||||
->whereYear('mov_data', $year)
|
||||
->where('mov_fk_categoria', $cat)
|
||||
->get();
|
||||
}
|
||||
|
||||
public static function listByCategory($cat) {
|
||||
@@ -393,10 +386,17 @@ JOIN categories as c ON a.mov_fk_categoria=c.id';
|
||||
// Ritorna gli anni presenti nei movimenti
|
||||
public static function getYearsFromMovimenti()
|
||||
{
|
||||
return self::selectRaw('YEAR(mov_data) as anno')
|
||||
if (env('DB_CONNECTION')=='mysql') {
|
||||
return self::selectRaw('DISTINCT YEAR(mov_data) as anno')
|
||||
->orderBy('anno', 'desc')
|
||||
->get();
|
||||
} else
|
||||
{
|
||||
return self::selectRaw("strftime('%Y', mov_data) as anno")
|
||||
->distinct()
|
||||
->orderBy('anno', 'desc')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user