2019-07-31 18:22:35 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-07-31 18:22:35 +02:00
|
|
|
|
|
|
|
include_once __DIR__.'/../../core.php';
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
use Modules\Fatture\Fattura;
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
function renderRiga($id, $riga)
|
|
|
|
{
|
2019-07-31 18:22:35 +02:00
|
|
|
// Conto
|
|
|
|
echo '
|
2019-11-22 17:15:17 +01:00
|
|
|
<tr>
|
2020-08-10 10:20:22 +02:00
|
|
|
<input type="hidden" name="id_documento['.$id.']" value="'.$riga['iddocumento'].'">
|
2019-11-22 17:15:17 +01:00
|
|
|
<input type="hidden" name="id_scadenza['.$id.']" value="'.$riga['id_scadenza'].'">
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
<td>
|
2022-03-28 11:28:14 +02:00
|
|
|
{[ "type": "select", "name": "idconto['.$id.']", "id": "conto'.$id.'", "value": "'.($riga['id_conto'] ?: '').'", "ajax-source": "conti", "icon-after": '.json_encode('<button type="button" onclick="visualizzaMovimenti(this)" class="btn btn-info '.($riga['id_conto'] ? '' : 'disabled').'"><i class="fa fa-eye"></i></button>').' ]}
|
2019-11-22 17:15:17 +01:00
|
|
|
</td>';
|
2019-07-31 18:22:35 +02:00
|
|
|
|
|
|
|
// Dare
|
|
|
|
echo '
|
2019-11-22 17:15:17 +01:00
|
|
|
<td>
|
|
|
|
{[ "type": "number", "name": "dare['.$id.']", "id": "dare'.$id.'", "value": "'.($riga['dare'] ?: 0).'" ]}
|
|
|
|
</td>';
|
2019-07-31 18:22:35 +02:00
|
|
|
|
|
|
|
// Avere
|
|
|
|
echo '
|
2019-11-22 17:15:17 +01:00
|
|
|
<td>
|
|
|
|
{[ "type": "number", "name": "avere['.$id.']", "id": "avere'.$id.'", "value": "'.($riga['avere'] ?: 0).'" ]}
|
|
|
|
</td>
|
|
|
|
</tr>';
|
2019-07-31 18:22:35 +02:00
|
|
|
}
|
|
|
|
|
2020-08-10 10:20:22 +02:00
|
|
|
function renderTabella($nome, $righe)
|
2019-11-22 17:15:17 +01:00
|
|
|
{
|
|
|
|
global $counter;
|
|
|
|
|
2020-08-10 10:20:22 +02:00
|
|
|
$prima_riga = $righe->first();
|
|
|
|
$id_documento = $prima_riga ? $prima_riga['iddocumento'] : null;
|
|
|
|
$id_scadenza = $prima_riga ? $prima_riga['id_scadenza'] : null;
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
echo '
|
2020-08-10 10:20:22 +02:00
|
|
|
<div class="raggruppamento_primanota" data-id_scadenza="'.$id_scadenza.'" data-id_documento="'.$id_documento.'">
|
2019-11-22 17:15:17 +01:00
|
|
|
<button class="btn btn-info btn-xs pull-right" type="button" onclick="addRiga(this)">
|
2019-11-25 19:30:50 +01:00
|
|
|
<i class="fa fa-plus"></i> '.tr('Aggiungi riga').'
|
2019-11-22 17:15:17 +01:00
|
|
|
</button>
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
<h4>'.$nome.'</h4>
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
<table class="table table-striped table-condensed table-hover table-bordered scadenze">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>'.tr('Conto').'</th>
|
|
|
|
<th width="20%">'.tr('Dare').'</th>
|
|
|
|
<th width="20%">'.tr('Avere').'</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
foreach ($righe as $riga) {
|
|
|
|
renderRiga($counter++, $riga);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Totale per controllare sbilancio
|
|
|
|
echo '
|
|
|
|
</tbody>
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
<tfoot>
|
2019-07-31 18:22:35 +02:00
|
|
|
<tr>
|
2020-07-06 13:19:20 +02:00
|
|
|
<td class="text-right"><b>'.tr('Totale').':</b></td>';
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Totale dare
|
|
|
|
echo '
|
2020-07-06 13:19:20 +02:00
|
|
|
<td class="text-right">
|
2019-11-22 17:15:17 +01:00
|
|
|
<span class="totale_dare"></span> '.currency().'
|
2019-07-31 18:22:35 +02:00
|
|
|
</td>';
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Totale avere
|
|
|
|
echo '
|
2020-07-06 13:19:20 +02:00
|
|
|
<td class="text-right">
|
2019-11-22 17:15:17 +01:00
|
|
|
<span class="totale_avere"></span> '.currency().'
|
2019-07-31 18:22:35 +02:00
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
echo '
|
|
|
|
</tfoot>
|
|
|
|
</table>';
|
|
|
|
|
|
|
|
// Verifica dello sbilancio
|
|
|
|
echo '
|
|
|
|
<div class="alert alert-warning hide sbilancio">
|
|
|
|
<i class="fa fa-warning"></i> '.tr('Sbilancio di _MONEY_', [
|
|
|
|
'_MONEY_' => '<span class="money"></span> '.currency(),
|
|
|
|
]).'
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$counter = 0;
|
2019-12-11 16:23:51 +01:00
|
|
|
$movimenti = collect($movimenti);
|
2019-11-22 17:15:17 +01:00
|
|
|
|
|
|
|
// Elenco per documenti
|
2019-12-11 16:23:51 +01:00
|
|
|
$scadenze = $movimenti
|
2022-06-14 12:30:36 +02:00
|
|
|
->where('iddocumento', '<>', '')
|
2019-11-22 17:15:17 +01:00
|
|
|
->groupBy('iddocumento');
|
|
|
|
foreach ($scadenze as $id_documento => $righe) {
|
|
|
|
$documento = Fattura::find($id_documento);
|
|
|
|
|
|
|
|
$nome = tr('Documento num. _NUM_', [
|
|
|
|
'_NUM_' => $documento['numero_esterno'] ?: $documento['numero'],
|
|
|
|
]);
|
|
|
|
|
2020-08-10 10:20:22 +02:00
|
|
|
renderTabella($nome, $righe);
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Elenco per scadenze
|
2019-12-11 16:23:51 +01:00
|
|
|
$scadenze = $movimenti
|
2022-06-14 12:30:36 +02:00
|
|
|
->where('iddocumento', '=', '')
|
2019-11-22 17:15:17 +01:00
|
|
|
->where('id_scadenza', '<>', '')
|
|
|
|
->groupBy('id_scadenza');
|
|
|
|
foreach ($scadenze as $id_scadenza => $righe) {
|
|
|
|
$nome = tr('Scadenza num. _ID_', [
|
|
|
|
'_ID_' => $id_scadenza,
|
|
|
|
]);
|
|
|
|
|
2020-08-10 10:20:22 +02:00
|
|
|
renderTabella($nome, $righe);
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Elenco generale
|
2019-12-11 16:23:51 +01:00
|
|
|
$movimenti_generali = $movimenti
|
2021-03-01 11:58:28 +01:00
|
|
|
->where('iddocumento', '=', '0')
|
2019-11-22 17:15:17 +01:00
|
|
|
->where('id_scadenza', '=', '');
|
2019-12-11 16:23:51 +01:00
|
|
|
if ($movimenti_generali->isEmpty()) {
|
|
|
|
$movimenti_generali->push([]);
|
|
|
|
$movimenti_generali->push([]);
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
$nome = tr('Generale');
|
|
|
|
|
2019-12-11 16:23:51 +01:00
|
|
|
renderTabella($nome, $movimenti_generali);
|
2019-11-22 17:15:17 +01:00
|
|
|
|
|
|
|
// Nuova riga
|
2019-07-31 18:22:35 +02:00
|
|
|
echo '
|
2019-11-22 17:15:17 +01:00
|
|
|
<table class="hide">
|
|
|
|
<tbody id="template">';
|
|
|
|
|
|
|
|
renderRiga('-id-', [
|
2020-08-10 10:20:22 +02:00
|
|
|
'iddocumento' => '-id_documento-',
|
2019-11-22 17:15:17 +01:00
|
|
|
'id_scadenza' => '-id_scadenza-',
|
|
|
|
]);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</tbody>
|
|
|
|
</table>';
|
2019-07-31 18:22:35 +02:00
|
|
|
|
|
|
|
echo '
|
|
|
|
<script>
|
2020-10-06 12:29:14 +02:00
|
|
|
var formatted_zero = "'.numberFormat(0).'";
|
2019-11-22 17:15:17 +01:00
|
|
|
var n = '.$counter.';
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
function addRiga(btn) {
|
|
|
|
var raggruppamento = $(btn).parent();
|
|
|
|
cleanup_inputs();
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
var tabella = raggruppamento.find("tbody");
|
|
|
|
var content = $("#template").html();
|
2020-08-10 10:20:22 +02:00
|
|
|
content = content.replace("-id_scadenza-", raggruppamento.data("id_scadenza"))
|
|
|
|
.replace("-id_documento-", raggruppamento.data("id_documento"));
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
var text = replaceAll(content, "-id-", "" + n);
|
|
|
|
tabella.append(text);
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
restart_inputs();
|
2020-02-16 16:45:45 +01:00
|
|
|
n++;
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Funzione per controllare lo stato dei conti della prima nota.
|
2020-07-06 13:19:20 +02:00
|
|
|
*
|
2019-11-22 17:15:17 +01:00
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function controllaConti() {
|
2020-10-06 12:29:14 +02:00
|
|
|
let continuare = true;
|
2019-11-22 17:15:17 +01:00
|
|
|
|
|
|
|
// Controlli sullo stato dei raggruppamenti
|
|
|
|
$(".raggruppamento_primanota").each(function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
let bilancio = calcolaBilancio(this);
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2020-10-06 12:29:14 +02:00
|
|
|
continuare &= bilancio === 0;
|
2019-07-31 18:22:35 +02:00
|
|
|
});
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Blocco degli input con valore non impostato
|
|
|
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
let conto_relativo = $(this).parent().parent().find("select").val();
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
if (!conto_relativo) {
|
|
|
|
$(this).prop("disabled", true);
|
2020-07-06 13:19:20 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
if ($(this).val().toEnglish()){
|
2020-10-06 12:29:14 +02:00
|
|
|
continuare &= !!conto_relativo;
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (continuare) {
|
2020-10-14 11:58:52 +02:00
|
|
|
$("#add-submit").prop("disabled", false);
|
|
|
|
$("#modello-button").prop("disabled", false);
|
2021-03-15 11:10:46 +01:00
|
|
|
$("#save, #save-close").removeAttr("disabled").removeClass("disabled");
|
2020-07-06 13:19:20 +02:00
|
|
|
} else {
|
2020-10-14 11:58:52 +02:00
|
|
|
$("#add-submit").prop("disabled", true);
|
|
|
|
$("#modello-button").prop("disabled", true);
|
2021-03-15 11:10:46 +01:00
|
|
|
$("#save, #save-close").attr("disabled", "true").addClass("disabled");
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return continuare;
|
|
|
|
}
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
/**
|
|
|
|
* Ad ogni modifica dell\'importo verifica che siano stati selezionati: il conto, la causale, la data.
|
|
|
|
* Inoltre aggiorna lo sbilancio.
|
2020-07-06 13:19:20 +02:00
|
|
|
*
|
2019-11-22 17:15:17 +01:00
|
|
|
* @param gruppo
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
function calcolaBilancio(gruppo) {
|
2020-10-06 12:29:14 +02:00
|
|
|
let raggruppamento = $(gruppo);
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2020-10-06 12:29:14 +02:00
|
|
|
let totale_dare = 0.00;
|
|
|
|
let totale_avere = 0.00;
|
2019-11-22 17:15:17 +01:00
|
|
|
|
|
|
|
// Calcolo il totale dare
|
|
|
|
raggruppamento.find("input[id*=dare]").each(function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
totale_dare += input(this).get();
|
2019-07-31 18:22:35 +02:00
|
|
|
});
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Calcolo il totale avere
|
|
|
|
raggruppamento.find("input[id*=avere]").each(function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
totale_avere += input(this).get();
|
2019-11-22 17:15:17 +01:00
|
|
|
});
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2020-10-06 12:29:14 +02:00
|
|
|
totale_dare = parseFloat(totale_dare);
|
|
|
|
totale_avere = parseFloat(totale_avere);
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Visualizzazione dei totali
|
|
|
|
raggruppamento.find(".totale_dare").text(totale_dare.toLocale());
|
|
|
|
raggruppamento.find(".totale_avere").text(totale_avere.toLocale());
|
|
|
|
|
|
|
|
// Calcolo il bilancio
|
2020-10-06 12:29:14 +02:00
|
|
|
let bilancio = totale_dare.toFixed(2) - totale_avere.toFixed(2);
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Visualizzazione dello sbilancio eventuale
|
2020-10-06 12:29:14 +02:00
|
|
|
let sbilancio = raggruppamento.find(".sbilancio");
|
|
|
|
let valore_sbilancio = sbilancio.find(".money");
|
2019-11-22 17:15:17 +01:00
|
|
|
valore_sbilancio.text(bilancio.toLocale());
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2020-10-06 12:29:14 +02:00
|
|
|
if (bilancio === 0) {
|
2019-11-22 17:15:17 +01:00
|
|
|
sbilancio.addClass("hide");
|
2019-07-31 18:22:35 +02:00
|
|
|
} else {
|
2019-11-22 17:15:17 +01:00
|
|
|
sbilancio.removeClass("hide");
|
2019-07-31 18:22:35 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
return bilancio;
|
2019-07-31 18:22:35 +02:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
$(document).ready(function() {
|
|
|
|
controllaConti();
|
2020-07-06 13:19:20 +02:00
|
|
|
|
|
|
|
// Fix per l\'inizializzazione degli input
|
2019-07-31 18:22:35 +02:00
|
|
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
if (input(this).get() === 0) {
|
2019-07-31 18:22:35 +02:00
|
|
|
$(this).prop("disabled", true);
|
|
|
|
} else {
|
|
|
|
$(this).prop("disabled", false);
|
|
|
|
}
|
|
|
|
});
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
// Trigger dell\'evento keyup() per la prima volta, per eseguire i dovuti controlli nel caso siano predisposte delle righe in prima nota
|
|
|
|
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
$("select[id*=idconto]").click(function() {
|
|
|
|
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
|
2019-07-31 18:22:35 +02:00
|
|
|
});
|
2019-11-22 17:15:17 +01:00
|
|
|
});
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
$(document).on("change", "select", function() {
|
2022-03-28 11:28:14 +02:00
|
|
|
let row = $(this).parent().parent().parent();
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2020-10-06 12:29:14 +02:00
|
|
|
if (row.find("input[disabled]").length > 1) {
|
|
|
|
row.find("input").prop("disabled", !$(this).val());
|
2019-11-22 17:15:17 +01:00
|
|
|
}
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
controllaConti();
|
2022-03-28 11:28:14 +02:00
|
|
|
|
|
|
|
let button = $(this).parent().find("button");
|
|
|
|
if ($(this).val()) {
|
|
|
|
button.removeClass("disabled");
|
|
|
|
} else {
|
|
|
|
button.addClass("disabled");
|
|
|
|
}
|
2019-11-22 17:15:17 +01:00
|
|
|
});
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
$(document).on("keyup change", "input[id*=dare]", function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
let row = $(this).parent().parent();
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
if (!$(this).prop("disabled")) {
|
2021-09-30 14:49:10 +02:00
|
|
|
row.find("input[id*=avere]").prop("disabled", $(this).val().toEnglish());
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
controllaConti();
|
|
|
|
}
|
|
|
|
});
|
2019-07-31 18:22:35 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
$(document).on("keyup change", "input[id*=avere]", function() {
|
2020-10-06 12:29:14 +02:00
|
|
|
let row = $(this).parent().parent();
|
2020-07-06 13:19:20 +02:00
|
|
|
|
2019-11-22 17:15:17 +01:00
|
|
|
if (!$(this).prop("disabled")) {
|
2021-09-30 14:49:10 +02:00
|
|
|
row.find("input[id*=dare]").prop("disabled", $(this).val().toEnglish());
|
2019-11-22 17:15:17 +01:00
|
|
|
|
|
|
|
controllaConti();
|
|
|
|
}
|
2019-07-31 18:22:35 +02:00
|
|
|
});
|
2022-03-28 11:28:14 +02:00
|
|
|
|
|
|
|
function visualizzaMovimenti(button) {
|
|
|
|
let id_conto = $(button).parent().parent().find("select").val();
|
|
|
|
openModal("'.tr('Ultimi 25 movimenti').'", "'.$module->fileurl('dettagli.php').'?id_module=" + globals.id_module + "&id_conto=" + id_conto);
|
|
|
|
}
|
2019-07-31 18:22:35 +02:00
|
|
|
</script>';
|