Effettuato modifiche al report annuale e alla lista movimenti per problema ISSUE#3
This commit is contained in:
parent
9320ce76a1
commit
637763fafe
@ -34,13 +34,15 @@ class MovimentiController extends Controller
|
||||
public static function listMovimenti(){
|
||||
$categorie=Categorie::list();
|
||||
$tags=tag::getList();
|
||||
$contos=Conto::all();
|
||||
/* Query per visualizzare anche il totale dei documenti presenti per il record */
|
||||
$movimenti=Movimenti::getList();
|
||||
|
||||
|
||||
//dd($movimenti);
|
||||
return view('conti.movimenti.list',[
|
||||
'categorie'=>$categorie,
|
||||
'movimenti'=>$movimenti,
|
||||
'contos'=>$contos,
|
||||
'tags'=>$tags
|
||||
]);
|
||||
}
|
||||
@ -227,14 +229,32 @@ class MovimentiController extends Controller
|
||||
$ncategoria=$categoria->cat_name;
|
||||
for ($i=1;$i<=12;$i++)
|
||||
{
|
||||
$movrow=DB::table('movimentis')
|
||||
$importo_dare = DB::table('movimentis')
|
||||
->whereMonth('mov_data', '=', $i)
|
||||
->whereYear('mov_data', '=', $anno)
|
||||
->where('mov_fk_categoria', '=', $id)
|
||||
->sum('mov_importo');
|
||||
->sum('mov_importo_dare');
|
||||
|
||||
$importo_avere = DB::table('movimentis')
|
||||
->whereMonth('mov_data', '=', $i)
|
||||
->whereYear('mov_data', '=', $anno)
|
||||
->where('mov_fk_categoria', '=', $id)
|
||||
->sum('mov_importo_avere');
|
||||
|
||||
// $movrow=DB::table('movimentis')
|
||||
// ->whereMonth('mov_data','=',$i)
|
||||
// ->whereYear('mov_data','=',$anno)
|
||||
// ->where('mov_fk_categoria','=',$id)
|
||||
// ->sum('mov_importo_dare')
|
||||
// ->sum('mov_importo_avere');
|
||||
$movrow = $importo_avere - $importo_dare;
|
||||
|
||||
$coll[]=$movrow;
|
||||
$collx[]=$movrow;
|
||||
}
|
||||
//TEST
|
||||
// dd($movrow);
|
||||
// /TEST
|
||||
$totale[]=array_sum($collx);
|
||||
unset($collx);
|
||||
}
|
||||
|
@ -44,9 +44,14 @@ 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()
|
||||
public function ContoDa()
|
||||
{
|
||||
return $this->belongsTo(Conto::class);
|
||||
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,11 +386,18 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static function dateFormat($type,$string)
|
||||
|
@ -1,162 +1,87 @@
|
||||
|
||||
$(document).ready(function() {
|
||||
$('#listamovimenti').DataTable({
|
||||
"responsive": true,
|
||||
columnDefs: [
|
||||
{
|
||||
responsive: true,
|
||||
columnDefs: [{
|
||||
target: 0,
|
||||
render: DataTable.render.date(),
|
||||
}
|
||||
],
|
||||
"order": [[0, "desc"]]
|
||||
}],
|
||||
order: [[0, "desc"]]
|
||||
});
|
||||
|
||||
// $('.select2').select2();
|
||||
});
|
||||
|
||||
|
||||
$(".draggable").draggable();
|
||||
|
||||
var d = new Date();
|
||||
var month = d.getMonth() + 1;
|
||||
var day = d.getDate();
|
||||
var strDate = d.getFullYear() + '-' +
|
||||
(month<10 ? '0' : '') + month + '-' +
|
||||
(day<10 ? '0' : '') + day;
|
||||
var strDate = d.getFullYear() + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;
|
||||
|
||||
function fillSelect(url, selectName, selectedValue) {
|
||||
$(selectName).empty();
|
||||
$.getJSON(url, {}, function(items) {
|
||||
$.each(items, function(i, item) {
|
||||
var label = item.cat_name || item.tag_name || item.nomeConto;
|
||||
$(selectName).append(new Option(label, item.id));
|
||||
});
|
||||
if (selectedValue) {
|
||||
$(selectName).val(selectedValue).trigger('change');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function resetForm(formSelector, dateValue) {
|
||||
$(formSelector).find('input[type="text"], textarea, input[type="number"], input[type="date"], option').val('');
|
||||
$(formSelector).find('input[type="date"]').val(dateValue);
|
||||
}
|
||||
|
||||
function openModal(tipo, actionUrl, catUrl, tagUrl, contoUrl, modalTitle) {
|
||||
resetForm('#form', strDate);
|
||||
$('#myModal').modal('show');
|
||||
$('.modal-title').text(modalTitle);
|
||||
$('#form').attr('action', actionUrl);
|
||||
fillSelect(catUrl, "select[name='mov_fk_categoria']");
|
||||
fillSelect(tagUrl, "select[name='mov_fk_tags']");
|
||||
fillSelect(contoUrl, "select[name='conto_id']");
|
||||
}
|
||||
|
||||
|
||||
$(document).on('click', '.open_modal_spesa', function() {
|
||||
console.log(strDate);
|
||||
$("#categoria").empty();
|
||||
$("#tags").empty();
|
||||
$('#form').find('input[type="text"], textarea, input[type="number"],input[type="date"],option').val("");
|
||||
$('#form').find('input[type="date"]').val(strDate);
|
||||
$('#myModal').modal('show');
|
||||
$('.modal-title').text(' Nuovo movimento in uscita');
|
||||
$('#form').attr('action', '/admin/movimenti/spesa');
|
||||
$.getJSON("/admin/service/catlistSpesa", {}, function(cats) {
|
||||
$.each(cats, function(i, cat) {
|
||||
$("select[name='mov_fk_categoria']").append(
|
||||
new Option(cat.cat_name, cat.id)
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
$.getJSON("/admin/service/taglist", {}, function(tags) {
|
||||
$.each(tags, function(i, tag) {
|
||||
$("select[name='mov_fk_tags']").append(
|
||||
new Option(tag.tag_name, tag.id)
|
||||
)
|
||||
});
|
||||
});
|
||||
$.getJSON("/admin/service/contolist", {}, function(contis) {
|
||||
$.each(contis, function(i, conto) {
|
||||
$("select[name='conto_id']").append(
|
||||
new Option(conto.nomeConto, conto.id)
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
openModal('spesa', '/admin/movimenti/spesa', '/admin/service/catlistSpesa', '/admin/service/taglist', '/admin/service/contolist', 'Nuovo movimento in uscita');
|
||||
$('#importo').attr('name', 'mov_importo_dare');
|
||||
});
|
||||
|
||||
$(document).on('click', '.open_modal_entrata', function() {
|
||||
console.log(strDate);
|
||||
$("#categoria").empty();
|
||||
$("#tags").empty();
|
||||
$('#form').find('input[type="text"], textarea, input[type="number"],option').val("");
|
||||
$('#form').find('input[type="date"]').val(strDate);
|
||||
$('#myModal').modal('show');
|
||||
$('.modal-title').text('Nuovo movimento in entrata');
|
||||
$('#form').attr('action', '/admin/movimenti/entrata');
|
||||
$.getJSON("/admin/service/catlistEntrata", {}, function(data) {
|
||||
$.each(data, function(i, item) {
|
||||
$("select[name='mov_fk_categoria']").append(
|
||||
new Option(item.cat_name, item.id)
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
$.getJSON("/admin/service/taglist", {}, function(data) {
|
||||
$.each(data, function(i, item) {
|
||||
$("select[name='mov_fk_tags']").append(
|
||||
new Option(item.tag_name, item.id)
|
||||
)
|
||||
});
|
||||
});
|
||||
$.getJSON("/admin/service/contolist", {}, function(contis) {
|
||||
$.each(contis, function(i, conto) {
|
||||
$("select[name='conto_id']").append(
|
||||
new Option(conto.nomeConto, conto.id)
|
||||
)
|
||||
}
|
||||
);
|
||||
});
|
||||
openModal('entrata', '/admin/movimenti/entrata', '/admin/service/catlistEntrata', '/admin/service/taglist', '/admin/service/contolist', 'Nuovo movimento in entrata');
|
||||
$('#importo').attr('name', 'mov_importo_avere');
|
||||
});
|
||||
|
||||
// Modifica movimento
|
||||
|
||||
$(document).on('click', '.open_modal_modifica', function() {
|
||||
var url = "/admin/movimenti/modify";
|
||||
var riga_id = $(this).val();
|
||||
$("#categoria").empty();
|
||||
$("#tags").empty();
|
||||
$.getJSON(url + '/' + riga_id, function(data) {
|
||||
// success data
|
||||
console.log(data[0]);
|
||||
$.getJSON("/admin/service/taglist", {}, function(tags) {
|
||||
$.each(tags, function(i, tag) {
|
||||
$("select[name='mov_fk_tags']").append(
|
||||
new Option(tag.tag_name, tag.id)
|
||||
)
|
||||
$('#tags')
|
||||
.find('option:contains(' + data[0].tag_name + ')')
|
||||
.prop('selected', true)
|
||||
.trigger('change');
|
||||
});
|
||||
});
|
||||
$.getJSON("/admin/service/catlist", {}, function(cats) {
|
||||
$.each(cats, function(i, cat) {
|
||||
$("select[name='mov_fk_categoria']").append(
|
||||
new Option(cat.cat_name, cat.id)
|
||||
)
|
||||
$('#categoria')
|
||||
.find('option:contains(' + data[0].cat_name + ')')
|
||||
.prop('selected', true)
|
||||
.trigger('change');
|
||||
}
|
||||
);
|
||||
});
|
||||
$.getJSON("/admin/service/contolist", {}, function(contis) {
|
||||
$.each(contis, function(i, conto) {
|
||||
$("select[name='conto_id']").append(
|
||||
new Option(conto.nomeConto, conto.id)
|
||||
)
|
||||
$('#conto_id')
|
||||
.find('option:contains(' + data[0].nomeConto + ')')
|
||||
.prop('selected', true)
|
||||
.trigger('change');
|
||||
}
|
||||
);
|
||||
});
|
||||
$('.modal-title').text('Modifica movimento');
|
||||
$('#data').val(data[0].mov_data.substring(0,10));
|
||||
$.getJSON('/admin/movimenti/modify/' + riga_id, function(data) {
|
||||
resetForm('#form', data[0].mov_data.substring(0, 10));
|
||||
fillSelect('/admin/service/catlist', "select[name='mov_fk_categoria']", data[0].cat_name);
|
||||
fillSelect('/admin/service/taglist', "select[name='mov_fk_tags']", data[0].tag_name);
|
||||
fillSelect('/admin/service/contolist', "select[name='conto_id']", data[0].nomeConto);
|
||||
$('#descrizione').val(data[0].mov_descrizione);
|
||||
$('#importo').val(data[0].mov_importo_dare);
|
||||
|
||||
$('#myModal').modal('show');
|
||||
// $('.panel-heading').text('Modifica movimento');
|
||||
// Imposta importo e name in base a DARE/AVERE
|
||||
if (data[0].mov_importo_dare && parseFloat(data[0].mov_importo_dare) !== 0) {
|
||||
$('#importo').val(data[0].mov_importo_dare);
|
||||
$('#importo').attr('name', 'mov_importo_dare');
|
||||
} else if (data[0].mov_importo_avere && parseFloat(data[0].mov_importo_avere) !== 0) {
|
||||
$('#importo').val(data[0].mov_importo_avere);
|
||||
$('#importo').attr('name', 'mov_importo_avere');
|
||||
} else {
|
||||
$('#importo').val('');
|
||||
$('#importo').attr('name', 'mov_importo');
|
||||
}
|
||||
|
||||
$('.modal-title').text('Modifica movimento');
|
||||
$('#form').attr('action', '/admin/movimenti/modify');
|
||||
$('#form').append('<input type="hidden" name="id" value="' + riga_id + '">');
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
$.getJSON("/admin/service/taglist", {}, function(data) {
|
||||
$.each(data, function(i, item) {
|
||||
$("select[name='mov_fk_tags']").append(
|
||||
new Option(item.tag_name, item.id)
|
||||
)
|
||||
$('#myModal').modal('show');
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
|
@ -44,9 +44,11 @@
|
||||
@foreach( $movimenti as $movimento )
|
||||
<tr>
|
||||
<td>{{ $movimento->mov_data}}</td>
|
||||
<td>{{ $movimento->cat_name }}</td>
|
||||
<td>{{ $movimento->nomeContoDare ?? '' }}</td>
|
||||
<td>{{ $movimento->nomeContoAvere ?? '' }}</td>
|
||||
<td>{{ $movimento->Categorie->cat_name ?? ''}}</td>
|
||||
<!-- Uso l'operatore di coalescenza nulla per evitare errori se il conto non esiste -->
|
||||
<td>{{ $movimento->ContoDa->nomeConto ?? '' }}</td>
|
||||
<td>{{ $movimento->ContoA->nomeConto ?? '' }}</td>
|
||||
<!-- Uso l'operatore di coalescenza nulla per evitare errori se il tag non esiste -->
|
||||
<td>{{ $movimento->mov_descrizione }}</td>
|
||||
<td>{{ $movimento->mov_importo_dare ." €"}}</td>
|
||||
<td>{{ $movimento->mov_importo_avere." €"}}</td>
|
||||
|
@ -13,12 +13,14 @@
|
||||
<h3 class="card-title">Regole di Importazione</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<table class="table table-bordered">
|
||||
<table class="table table-bordered" id="importRulesTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Pattern</th>
|
||||
<th>Descrizione</th>
|
||||
<th>Categoria</th>
|
||||
|
||||
<th>Azioni</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -28,6 +30,7 @@
|
||||
<td>{{ $rule->id }}</td>
|
||||
<td>{{ $rule->pattern }}</td>
|
||||
<td>{{ $rule->description }}</td>
|
||||
<td>{{ \App\Models\Categorie::find($rule->category_id)->cat_name ?? 'N/A' }}</td>
|
||||
<td>
|
||||
<a href="{{ route('import_rules.edit', $rule->id) }}" class="btn btn-primary btn-sm">Modifica</a>
|
||||
<form action="{{ route('import_rules.destroy', $rule->id) }}" method="POST" style="display:inline;">
|
||||
@ -47,3 +50,16 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('js')
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#importRulesTable').DataTable({
|
||||
responsive: true,
|
||||
|
||||
order: [[0, "desc"]]
|
||||
});
|
||||
// $('.select2').select2();
|
||||
});
|
||||
</script>
|
||||
@endsection')
|
||||
|
Loading…
x
Reference in New Issue
Block a user