mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-08 23:58:42 +01:00
* Correzioni previste da #265 * Correzioni visualizzazione mastrini * Correzioni visualizazzione stampa mastrino
This commit is contained in:
parent
b32a08d196
commit
88732984f3
@ -21,7 +21,7 @@ $(document).ready(function () {
|
|||||||
$list.parent().parent().find('i.fa-angle-left').removeClass('fa-angle-left').addClass('fa-angle-down');
|
$list.parent().parent().find('i.fa-angle-left').removeClass('fa-angle-left').addClass('fa-angle-down');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Menu ordinabile
|
// Menu ordinabile
|
||||||
$(".sidebar-menu").sortable({
|
$(".sidebar-menu").sortable({
|
||||||
cursor: 'move',
|
cursor: 'move',
|
||||||
|
|
||||||
|
@ -2,13 +2,21 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
$prima_nota = Modules::get('Prima nota');
|
||||||
|
|
||||||
$id_conto = get('id_conto');
|
$id_conto = get('id_conto');
|
||||||
|
|
||||||
// Calcolo totale conto da elenco movimenti di questo conto
|
// Calcolo totale conto da elenco movimenti di questo conto
|
||||||
$query = 'SELECT co_movimenti.*, dir FROM co_movimenti
|
$query = 'SELECT co_movimenti.*,
|
||||||
LEFT OUTER JOIN co_documenti ON co_movimenti.iddocumento = co_documenti.id
|
SUM(totale) AS totale,
|
||||||
LEFT OUTER JOIN co_tipidocumento ON co_documenti.idtipodocumento = co_tipidocumento.id
|
dir FROM co_movimenti
|
||||||
WHERE co_movimenti.idconto='.prepare($id_conto).' AND co_movimenti.data >= '.prepare($_SESSION['period_start']).' AND co_movimenti.data <= '.prepare($_SESSION['period_end']).' ORDER BY co_movimenti.data DESC';
|
LEFT OUTER JOIN co_documenti ON co_movimenti.iddocumento = co_documenti.id
|
||||||
|
LEFT OUTER JOIN co_tipidocumento ON co_documenti.idtipodocumento = co_tipidocumento.id
|
||||||
|
WHERE co_movimenti.idconto='.prepare($id_conto).' AND
|
||||||
|
co_movimenti.data >= '.prepare($_SESSION['period_start']).' AND
|
||||||
|
co_movimenti.data <= '.prepare($_SESSION['period_end']).'
|
||||||
|
GROUP BY co_movimenti.idmastrino
|
||||||
|
ORDER BY co_movimenti.data DESC';
|
||||||
$movimenti = $dbo->fetchArray($query);
|
$movimenti = $dbo->fetchArray($query);
|
||||||
|
|
||||||
if (!empty($movimenti)) {
|
if (!empty($movimenti)) {
|
||||||
@ -30,8 +38,7 @@ if (!empty($movimenti)) {
|
|||||||
if (!empty($movimento['iddocumento'])) {
|
if (!empty($movimento['iddocumento'])) {
|
||||||
$modulo_fattura = ($movimento['dir'] == 'entrata') ? Modules::get('Fatture di vendita')['id'] : Modules::get('Fatture di acquisto')['id'];
|
$modulo_fattura = ($movimento['dir'] == 'entrata') ? Modules::get('Fatture di vendita')['id'] : Modules::get('Fatture di acquisto')['id'];
|
||||||
|
|
||||||
echo '
|
echo Modules::link($prima_nota->id, $movimento['idmastrino'], $movimento['descrizione']);
|
||||||
<a class="clickable" onclick="open_movimento('.$movimento['id'].', '.$modulo_fattura.')">'.$movimento['descrizione'].'</a>';
|
|
||||||
} else {
|
} else {
|
||||||
echo '
|
echo '
|
||||||
<span>'.$movimento['descrizione'].'</span>';
|
<span>'.$movimento['descrizione'].'</span>';
|
||||||
@ -72,8 +79,8 @@ if (!empty($movimenti)) {
|
|||||||
</table>
|
</table>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function open_movimento(id_movimento, id_module){
|
function open_movimento(id_mastrino, id_module){
|
||||||
launch_modal("'.tr('Dettagli movimento').'", "'.$structure->fileurl('dettagli_movimento.php').'?id_movimento=" + id_movimento + "&id_module=" + id_module);
|
launch_modal("'.tr('Dettagli movimento').'", "'.$structure->fileurl('dettagli_movimento.php').'?id_mastrino=" + id_mastrino + "&id_module=" + id_module);
|
||||||
}
|
}
|
||||||
</script>';
|
</script>';
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
|
||||||
|
|
||||||
$id_movimento = get('id_movimento');
|
|
||||||
|
|
||||||
$query = 'SELECT *, (subtotale-sconto) AS imponibile, (co_movimenti.descrizione) AS desc_fatt, (co_righe_documenti.descrizione) AS desc_riga FROM co_movimenti INNER JOIN co_righe_documenti ON co_movimenti.iddocumento = co_righe_documenti.iddocumento WHERE co_movimenti.id = '.prepare($id_movimento);
|
|
||||||
$righe = $dbo->fetchArray($query);
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<table class="table table-striped table-hover table-condensed table-bordered">
|
|
||||||
<tr>
|
|
||||||
<th>'.tr('Descrizione riga').'</th>
|
|
||||||
<th width="100">'.tr('Imponibile').'</th>
|
|
||||||
</tr>';
|
|
||||||
|
|
||||||
foreach ($righe as $riga) {
|
|
||||||
echo '
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<span>'.$riga['desc_riga'].'</span>
|
|
||||||
</td>
|
|
||||||
|
|
||||||
<td class="text-right">
|
|
||||||
<span>'.moneyFormat($riga['imponibile']).' </span>
|
|
||||||
</td>
|
|
||||||
</tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$totale_imponibile = sum(array_column($righe, 'imponibile'));
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<tr>
|
|
||||||
<th class="text-right">'.tr('Totali').': </th>
|
|
||||||
<th width="100" class="text-right"><span>'.moneyFormat($totale_imponibile).'</span></th>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
|
|
||||||
'.Modules::link($id_module, $righe[0]['iddocumento'], $righe[0]['desc_fatt'], null, 'class="btn btn-info btn-block"');
|
|
@ -48,6 +48,7 @@ foreach ($id_scadenze as $id_scadenza) {
|
|||||||
|
|
||||||
$righe_documento = [];
|
$righe_documento = [];
|
||||||
$righe_documento[] = [
|
$righe_documento[] = [
|
||||||
|
'iddocumento' => null,
|
||||||
'id_scadenza' => $scadenza['id'],
|
'id_scadenza' => $scadenza['id'],
|
||||||
'id_conto' => null,
|
'id_conto' => null,
|
||||||
'dare' => ($dir == 'entrata') ? 0 : $scadenza['rata'],
|
'dare' => ($dir == 'entrata') ? 0 : $scadenza['rata'],
|
||||||
@ -55,6 +56,7 @@ foreach ($id_scadenze as $id_scadenza) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
$righe_documento[] = [
|
$righe_documento[] = [
|
||||||
|
'iddocumento' => null,
|
||||||
'id_scadenza' => $scadenza['id'],
|
'id_scadenza' => $scadenza['id'],
|
||||||
'id_conto' => $id_conto_controparte,
|
'id_conto' => $id_conto_controparte,
|
||||||
'dare' => ($dir == 'entrata') ? $scadenza['rata'] : 0,
|
'dare' => ($dir == 'entrata') ? $scadenza['rata'] : 0,
|
||||||
@ -78,9 +80,7 @@ $numeri = [];
|
|||||||
$counter = 0;
|
$counter = 0;
|
||||||
|
|
||||||
$id_documenti = array_unique($id_documenti);
|
$id_documenti = array_unique($id_documenti);
|
||||||
|
$id_anagrafica_movimenti = null;
|
||||||
$idanagrafica_mov = 0;
|
|
||||||
|
|
||||||
foreach ($id_documenti as $id_documento) {
|
foreach ($id_documenti as $id_documento) {
|
||||||
$fattura = Fattura::find($id_documento);
|
$fattura = Fattura::find($id_documento);
|
||||||
$tipo = $fattura->tipo;
|
$tipo = $fattura->tipo;
|
||||||
@ -92,10 +92,10 @@ foreach ($id_documenti as $id_documento) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fattura->idanagrafica != $idanagrafica_mov && $idanagrafica_mov != '') {
|
if(empty($id_anagrafica_movimenti)){
|
||||||
$idanagrafica_mov = 0;
|
$id_anagrafica_movimenti = $fattura->idanagrafica;
|
||||||
} else {
|
}elseif ($fattura->idanagrafica != $id_anagrafica_movimenti) {
|
||||||
$idanagrafica_mov = $fattura->idanagrafica;
|
$id_anagrafica_movimenti = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$numeri[] = !empty($fattura['numero_esterno']) ? $fattura['numero_esterno'] : $fattura['numero'];
|
$numeri[] = !empty($fattura['numero_esterno']) ? $fattura['numero_esterno'] : $fattura['numero'];
|
||||||
@ -111,11 +111,7 @@ foreach ($id_documenti as $id_documento) {
|
|||||||
$id_conto_controparte = $fattura->anagrafica[$conto_field];
|
$id_conto_controparte = $fattura->anagrafica[$conto_field];
|
||||||
|
|
||||||
// Lettura delle scadenza della fattura
|
// Lettura delle scadenza della fattura
|
||||||
if (sizeof($id_scadenze) > 0) {
|
$scadenze = $dbo->fetchArray('SELECT id, ABS(da_pagare - pagato) AS rata, iddocumento FROM co_scadenziario WHERE iddocumento='.prepare($id_documento).' AND ABS(da_pagare) > ABS(pagato) ORDER BY YEAR(scadenza) ASC, MONTH(scadenza) ASC');
|
||||||
$scadenze = $dbo->fetchArray('SELECT id, ABS(da_pagare - pagato) AS rata FROM co_scadenziario WHERE iddocumento='.prepare($id_documento).' AND ABS(da_pagare) > ABS(pagato) AND id IN("'.implode('","', $id_scadenze).'") ORDER BY YEAR(scadenza) ASC, MONTH(scadenza) ASC');
|
|
||||||
} else {
|
|
||||||
$scadenze = $dbo->fetchArray('SELECT id, ABS(da_pagare - pagato) AS rata FROM co_scadenziario WHERE iddocumento='.prepare($id_documento).' AND ABS(da_pagare) > ABS(pagato) ORDER BY YEAR(scadenza) ASC, MONTH(scadenza) ASC');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Selezione prima scadenza
|
// Selezione prima scadenza
|
||||||
if ($singola_scadenza && !empty($scadenze)) {
|
if ($singola_scadenza && !empty($scadenze)) {
|
||||||
@ -124,27 +120,10 @@ foreach ($id_documenti as $id_documento) {
|
|||||||
|
|
||||||
$righe_documento = [];
|
$righe_documento = [];
|
||||||
|
|
||||||
// Riga aziendale
|
|
||||||
$totale = sum(array_column($scadenze, 'rata'));
|
|
||||||
|
|
||||||
if ($totale != 0) {
|
|
||||||
if ($nota_credito) {
|
|
||||||
$totaleA = -$totale;
|
|
||||||
} else {
|
|
||||||
$totaleA = $totale;
|
|
||||||
}
|
|
||||||
|
|
||||||
$righe_azienda[] = [
|
|
||||||
'id_scadenza' => $scadenze[0]['id'],
|
|
||||||
'id_conto' => $id_conto_aziendale,
|
|
||||||
'dare' => ($dir == 'entrata') ? $totaleA : 0,
|
|
||||||
'avere' => ($dir == 'entrata') ? 0 : $totaleA,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Riga controparte
|
// Riga controparte
|
||||||
foreach ($scadenze as $scadenza) {
|
foreach ($scadenze as $scadenza) {
|
||||||
$righe_documento[] = [
|
$righe_documento[] = [
|
||||||
|
'iddocumento' => $scadenza['iddocumento'],
|
||||||
'id_scadenza' => $scadenza['id'],
|
'id_scadenza' => $scadenza['id'],
|
||||||
'id_conto' => $id_conto_controparte,
|
'id_conto' => $id_conto_controparte,
|
||||||
'dare' => ($dir == 'entrata' && !$nota_credito && !$is_insoluto) ? 0 : $scadenza['rata'],
|
'dare' => ($dir == 'entrata' && !$nota_credito && !$is_insoluto) ? 0 : $scadenza['rata'],
|
||||||
@ -152,37 +131,57 @@ foreach ($id_documenti as $id_documento) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Riga aziendale
|
||||||
|
$totale = sum(array_column($scadenze, 'rata'));
|
||||||
|
|
||||||
|
if ($totale != 0) {
|
||||||
|
if ($nota_credito) {
|
||||||
|
$totale_rata = -$totale;
|
||||||
|
} else {
|
||||||
|
$totale_rata = $totale;
|
||||||
|
}
|
||||||
|
|
||||||
|
$righe_documento[] = [
|
||||||
|
'iddocumento' => $scadenze[0]['iddocumento'],
|
||||||
|
'id_scadenza' => $scadenze[0]['id'],
|
||||||
|
'id_conto' => $id_conto_aziendale,
|
||||||
|
'dare' => ($dir == 'entrata') ? $totale_rata : 0,
|
||||||
|
'avere' => ($dir == 'entrata') ? 0 : $totale_rata,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$righe = array_merge($righe, $righe_documento);
|
$righe = array_merge($righe, $righe_documento);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
$k = 0;
|
$k = 0;
|
||||||
foreach ($righe_azienda as $key => $riga_azienda) {
|
foreach ($righe_azienda as $key => $riga_azienda) {
|
||||||
if ($righe_azienda[$key]['id_conto'] != $righe_azienda[$key - 1]['id_conto']) {
|
if ($righe_azienda[$key]['id_conto'] != $righe_azienda[$key - 1]['id_conto']) {
|
||||||
++$k;
|
++$k;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$riga_documento[$k]['iddocumento'] = $riga_azienda['iddocumento'];
|
||||||
|
$riga_documento[$k]['id_scadenza'] = $riga_azienda['id_scadenza'];
|
||||||
$riga_documento[$k]['id_conto'] = $riga_azienda['id_conto'];
|
$riga_documento[$k]['id_conto'] = $riga_azienda['id_conto'];
|
||||||
$riga_documento[$k]['dare'] += $riga_azienda['dare'];
|
$riga_documento[$k]['dare'] += $riga_azienda['dare'];
|
||||||
$riga_documento[$k]['avere'] += $riga_azienda['avere'];
|
$riga_documento[$k]['avere'] += $riga_azienda['avere'];
|
||||||
}
|
$righe = array_merge($righe, $righe_azienda);
|
||||||
|
}*/
|
||||||
|
|
||||||
foreach ($riga_documento as $key => $value) {
|
// Inverto dare e avere per importi negativi
|
||||||
//Inverto dare e avere per importi negativi
|
foreach ($righe as $key => $value) {
|
||||||
if ($riga_documento[$key]['dare'] < 0 || $riga_documento[$key]['avere'] < 0) {
|
if ($righe[$key]['dare'] < 0 || $righe[$key]['avere'] < 0) {
|
||||||
$tmp = abs($riga_documento[$key]['dare']);
|
$tmp = abs($righe[$key]['dare']);
|
||||||
$riga_documento[$key]['dare'] = abs($riga_documento[$key]['avere']);
|
$righe[$key]['dare'] = abs($righe[$key]['avere']);
|
||||||
$riga_documento[$key]['avere'] = $tmp;
|
$righe[$key]['avere'] = $tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$righe = array_merge($righe, $riga_documento);
|
|
||||||
|
|
||||||
// Descrizione
|
// Descrizione
|
||||||
$numero_scadenze = count($id_scadenze);
|
$numero_scadenze = count($id_scadenze);
|
||||||
$numero_documenti = count($id_documenti);
|
$numero_documenti = count($id_documenti);
|
||||||
if ($numero_documenti + $numero_scadenze > 1) {
|
if ($numero_documenti + $numero_scadenze > 1) {
|
||||||
if ($idanagrafica_mov != 0) {
|
if (!empty($id_anagrafica_movimenti)) {
|
||||||
$an = Anagrafica::find($idanagrafica_mov);
|
$an = Anagrafica::find($id_anagrafica_movimenti);
|
||||||
|
|
||||||
$descrizione = 'Pag. fatture '.$an->ragione_sociale.' num. '.implode(', ', $numeri);
|
$descrizione = 'Pag. fatture '.$an->ragione_sociale.' num. '.implode(', ', $numeri);
|
||||||
} else {
|
} else {
|
||||||
@ -280,7 +279,7 @@ include $structure->filepath('movimenti.php');
|
|||||||
|
|
||||||
$(document).ready(function(e) {
|
$(document).ready(function(e) {
|
||||||
$("#bs-popup #add-form").on("submit", function(e) {
|
$("#bs-popup #add-form").on("submit", function(e) {
|
||||||
return calcolaBilancio();
|
return controllaConti();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#bs-popup #modello_primanota').change(function() {
|
$('#bs-popup #modello_primanota').change(function() {
|
||||||
|
@ -66,7 +66,7 @@ include $structure->filepath('movimenti.php');
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
$("#edit-form").submit(function(e) {
|
$("#edit-form").submit(function(e) {
|
||||||
return calcolaBilancio();
|
return controllaConti();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -2,115 +2,262 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
echo '
|
use Modules\Fatture\Fattura;
|
||||||
<table class="table table-striped table-condensed table-hover table-bordered"
|
|
||||||
<tr>
|
|
||||||
<th>'.tr('Conto').'</th>
|
|
||||||
<th width="20%">'.tr('Dare').'</th>
|
|
||||||
<th width="20%">'.tr('Avere').'</th>
|
|
||||||
</tr>';
|
|
||||||
|
|
||||||
$max = max(count($righe), 10);
|
|
||||||
for ($i = 0; $i < $max; ++$i) {
|
|
||||||
$required = ($i <= 1);
|
|
||||||
$riga = $righe[$i];
|
|
||||||
|
|
||||||
|
function renderRiga($id, $riga)
|
||||||
|
{
|
||||||
// Conto
|
// Conto
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<input type="hidden" name="id_scadenza['.$i.']" value="'.$riga['id_scadenza'].'">
|
<input type="hidden" name="id_scadenza['.$id.']" value="'.$riga['id_scadenza'].'">
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
{[ "type": "select", "name": "idconto['.$i.']", "id": "conto'.$i.'", "value": "'.($riga['id_conto'] ?: '').'", "ajax-source": "conti", "required": "'.$required.'" ]}
|
{[ "type": "select", "name": "idconto['.$id.']", "id": "conto'.$id.'", "value": "'.($riga['id_conto'] ?: '').'", "ajax-source": "conti" ]}
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Dare
|
// Dare
|
||||||
echo '
|
echo '
|
||||||
<td>
|
<td>
|
||||||
{[ "type": "number", "name": "dare['.$i.']", "id": "dare'.$i.'", "value": "'.($riga['dare'] ?: 0).'" ]}
|
{[ "type": "number", "name": "dare['.$id.']", "id": "dare'.$id.'", "value": "'.($riga['dare'] ?: 0).'" ]}
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Avere
|
// Avere
|
||||||
echo '
|
echo '
|
||||||
<td>
|
<td>
|
||||||
{[ "type": "number", "name": "avere['.$i.']", "id": "avere'.$i.'", "value": "'.($riga['avere'] ?: 0).'" ]}
|
{[ "type": "number", "name": "avere['.$id.']", "id": "avere'.$id.'", "value": "'.($riga['avere'] ?: 0).'" ]}
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Totale per controllare sbilancio
|
function renderTabella($nome, $righe, $id_scadenza_default = null)
|
||||||
echo '
|
{
|
||||||
|
global $counter;
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<div class="raggruppamento_primanota" data-id_scadenza="'.$id_scadenza_default.'">
|
||||||
|
<button class="btn btn-info btn-xs pull-right" type="button" onclick="addRiga(this)">
|
||||||
|
<i class="fa fa-plus"></i> '.tr('Aggiungi').'
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<h4>'.$nome.'</h4>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<tbody>';
|
||||||
|
|
||||||
|
foreach ($righe as $riga) {
|
||||||
|
renderRiga($counter++, $riga);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Totale per controllare sbilancio
|
||||||
|
echo '
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td align="right"><b>'.tr('Totale').':</b></td>';
|
<td align="right"><b>'.tr('Totale').':</b></td>';
|
||||||
|
|
||||||
// Totale dare
|
// Totale dare
|
||||||
echo '
|
echo '
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<span><span id="totale_dare"></span> '.currency().'</span>
|
<span class="totale_dare"></span> '.currency().'
|
||||||
</td>';
|
</td>';
|
||||||
|
|
||||||
// Totale avere
|
// Totale avere
|
||||||
echo '
|
echo '
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<span><span id="totale_avere"></span> '.currency().'</span>
|
<span class="totale_avere"></span> '.currency().'
|
||||||
</td>
|
</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
// Verifica sbilancio
|
echo '
|
||||||
echo '
|
</tfoot>
|
||||||
<tr>
|
|
||||||
<td align="right"></td>
|
|
||||||
<td colspan="2" align="center">
|
|
||||||
<span id="testo_aggiuntivo"></span>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>';
|
</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;
|
||||||
|
$righe = collect($righe);
|
||||||
|
|
||||||
|
// Elenco per documenti
|
||||||
|
$scadenze = $righe
|
||||||
|
->where('iddocumento', '<>', '')
|
||||||
|
->groupBy('iddocumento');
|
||||||
|
foreach ($scadenze as $id_documento => $righe) {
|
||||||
|
$documento = Fattura::find($id_documento);
|
||||||
|
|
||||||
|
$nome = tr('Documento num. _NUM_', [
|
||||||
|
'_NUM_' => $documento['numero_esterno'] ?: $documento['numero'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
renderTabella($nome, $righe, $righe->first()['id_scadenza']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elenco per scadenze
|
||||||
|
$scadenze = $righe
|
||||||
|
->where('iddocumento', '=', '')
|
||||||
|
->where('id_scadenza', '<>', '')
|
||||||
|
->groupBy('id_scadenza');
|
||||||
|
foreach ($scadenze as $id_scadenza => $righe) {
|
||||||
|
$nome = tr('Scadenza num. _ID_', [
|
||||||
|
'_ID_' => $id_scadenza,
|
||||||
|
]);
|
||||||
|
|
||||||
|
renderTabella($nome, $righe, $righe->first()['id_scadenza']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elenco generale
|
||||||
|
$righe_generali = $righe
|
||||||
|
->where('iddocumento', '=', '')
|
||||||
|
->where('id_scadenza', '=', '');
|
||||||
|
if ($righe_generali->isEmpty()) {
|
||||||
|
$righe_generali->push([]);
|
||||||
|
$righe_generali->push([]);
|
||||||
|
}
|
||||||
|
$nome = tr('Generale');
|
||||||
|
|
||||||
|
renderTabella($nome, $righe_generali);
|
||||||
|
|
||||||
|
// Nuova riga
|
||||||
|
echo '
|
||||||
|
<table class="hide">
|
||||||
|
<tbody id="template">';
|
||||||
|
|
||||||
|
renderRiga('-id-', [
|
||||||
|
'id_scadenza' => '-id_scadenza-',
|
||||||
|
]);
|
||||||
|
|
||||||
|
echo '
|
||||||
|
</tbody>
|
||||||
|
</table>';
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
var formatted_zero = "'.Translator::numberToLocale(0).'";
|
var formatted_zero = "'.Translator::numberToLocale(0).'";
|
||||||
var sbilancio = "'.tr('sbilancio di _NUM_', [
|
var n = '.$counter.';
|
||||||
'_NUM_' => '|value| '.currency(),
|
|
||||||
]).'";
|
|
||||||
|
|
||||||
// Ad ogni modifica dell\'importo verifica che siano stati selezionati: il conto, la causale, la data. Inoltre aggiorna lo sbilancio
|
function addRiga(btn) {
|
||||||
function calcolaBilancio() {
|
var raggruppamento = $(btn).parent();
|
||||||
bilancio = 0.00;
|
console.log(raggruppamento)
|
||||||
totale_dare = 0.00;
|
n++;
|
||||||
totale_avere = 0.00;
|
cleanup_inputs();
|
||||||
|
|
||||||
// Calcolo il totale dare e totale avere
|
var tabella = raggruppamento.find("tbody");
|
||||||
$("input[id*=dare]").each(function() {
|
var content = $("#template").html();
|
||||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
content = content.replace("-id_scadenza-", raggruppamento.data("id_scadenza"));
|
||||||
|
|
||||||
totale_dare += Math.round(valore * 100) / 100;
|
var text = replaceAll(content, "-id-", "" + n);
|
||||||
|
tabella.append(text);
|
||||||
|
|
||||||
|
restart_inputs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Funzione per controllare lo stato dei conti della prima nota.
|
||||||
|
*
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
function controllaConti() {
|
||||||
|
var continuare = true;
|
||||||
|
|
||||||
|
// Controlli sullo stato dei raggruppamenti
|
||||||
|
$(".raggruppamento_primanota").each(function() {
|
||||||
|
var bilancio = calcolaBilancio(this);
|
||||||
|
|
||||||
|
continuare &= bilancio == 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("input[id*=avere]").each(function() {
|
// Blocco degli input con valore non impostato
|
||||||
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
||||||
|
var conto_relativo = $(this).parent().parent().find("select").val();
|
||||||
|
|
||||||
totale_avere += Math.round(valore * 100) / 100;
|
if (!conto_relativo) {
|
||||||
|
$(this).prop("disabled", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($(this).val().toEnglish()){
|
||||||
|
continuare &= conto_relativo ? true : false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#totale_dare").text(totale_dare.toLocale());
|
if (continuare) {
|
||||||
$("#totale_avere").text(totale_avere.toLocale());
|
|
||||||
|
|
||||||
bilancio = Math.round(totale_dare * 100) / 100 - Math.round(totale_avere * 100) / 100;
|
|
||||||
|
|
||||||
if (bilancio == 0) {
|
|
||||||
$("#testo_aggiuntivo").removeClass("text-danger").html(\'\');
|
|
||||||
$("#add-submit").removeClass("hide");
|
$("#add-submit").removeClass("hide");
|
||||||
$("#btn_crea_modello").removeClass("hide");
|
$("#btn_crea_modello").removeClass("hide");
|
||||||
} else {
|
} else {
|
||||||
$("#testo_aggiuntivo").addClass("text-danger").html(sbilancio.replace("|value|", bilancio.toLocale()));
|
|
||||||
$("#add-submit").addClass("hide");
|
$("#add-submit").addClass("hide");
|
||||||
$("#btn_crea_modello").addClass("hide");
|
$("#btn_crea_modello").addClass("hide");
|
||||||
}
|
}
|
||||||
|
|
||||||
return bilancio == 0;
|
return continuare;
|
||||||
}
|
}
|
||||||
|
|
||||||
function bloccaZeri(){
|
/**
|
||||||
|
* Ad ogni modifica dell\'importo verifica che siano stati selezionati: il conto, la causale, la data.
|
||||||
|
* Inoltre aggiorna lo sbilancio.
|
||||||
|
*
|
||||||
|
* @param gruppo
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
function calcolaBilancio(gruppo) {
|
||||||
|
var raggruppamento = $(gruppo);
|
||||||
|
|
||||||
|
var totale_dare = 0.00;
|
||||||
|
var totale_avere = 0.00;
|
||||||
|
|
||||||
|
// Calcolo il totale dare
|
||||||
|
raggruppamento.find("input[id*=dare]").each(function() {
|
||||||
|
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
||||||
|
|
||||||
|
totale_dare += valore;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Calcolo il totale avere
|
||||||
|
raggruppamento.find("input[id*=avere]").each(function() {
|
||||||
|
valore = $(this).val() ? $(this).val().toEnglish() : 0;
|
||||||
|
|
||||||
|
totale_avere += valore;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Visualizzazione dei totali
|
||||||
|
raggruppamento.find(".totale_dare").text(totale_dare.toLocale());
|
||||||
|
raggruppamento.find(".totale_avere").text(totale_avere.toLocale());
|
||||||
|
|
||||||
|
// Calcolo il bilancio
|
||||||
|
var bilancio = totale_dare - totale_avere;
|
||||||
|
|
||||||
|
// Visualizzazione dello sbilancio eventuale
|
||||||
|
var sbilancio = raggruppamento.find(".sbilancio");
|
||||||
|
var valore_sbilancio = sbilancio.find(".money");
|
||||||
|
valore_sbilancio.text(bilancio.toLocale());
|
||||||
|
|
||||||
|
if (bilancio == 0) {
|
||||||
|
sbilancio.addClass("hide");
|
||||||
|
} else {
|
||||||
|
sbilancio.removeClass("hide");
|
||||||
|
}
|
||||||
|
|
||||||
|
return bilancio;
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
controllaConti();
|
||||||
|
|
||||||
|
// Fix per l\'inizializzazione degli input
|
||||||
$("input[id*=dare], input[id*=avere]").each(function() {
|
$("input[id*=dare], input[id*=avere]").each(function() {
|
||||||
if ($(this).val() == formatted_zero) {
|
if ($(this).val() == formatted_zero) {
|
||||||
$(this).prop("disabled", true);
|
$(this).prop("disabled", true);
|
||||||
@ -118,52 +265,42 @@ function bloccaZeri(){
|
|||||||
$(this).prop("disabled", false);
|
$(this).prop("disabled", false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
$(document).ready(function() {
|
// Trigger dell\'evento keyup() per la prima volta, per eseguire i dovuti controlli nel caso siano predisposte delle righe in prima nota
|
||||||
calcolaBilancio();
|
|
||||||
bloccaZeri();
|
|
||||||
|
|
||||||
$("select").on("change", function() {
|
|
||||||
if ($(this).parent().parent().find("input[disabled]").length != 1) {
|
|
||||||
if ($(this).val()) {
|
|
||||||
$(this).parent().parent().find("input").prop("disabled", false);
|
|
||||||
} else {
|
|
||||||
$(this).parent().parent().find("input").prop("disabled", true);
|
|
||||||
$(this).parent().parent().find("input").val("0.00");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("input[id*=dare]").on("keyup change", function() {
|
|
||||||
if (!$(this).prop("disabled")) {
|
|
||||||
if ($(this).val()) {
|
|
||||||
$(this).parent().parent().find("input[id*=avere]").prop("disabled", true);
|
|
||||||
} else {
|
|
||||||
$(this).parent().parent().find("input[id*=avere]").prop("disabled", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
calcolaBilancio();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("input[id*=avere]").on("keyup change", function() {
|
|
||||||
if (!$(this).prop("disabled")) {
|
|
||||||
if ($(this).val()) {
|
|
||||||
$(this).parent().parent().find("input[id*=dare]").prop("disabled", true);
|
|
||||||
} else {
|
|
||||||
$(this).parent().parent().find("input[id*=dare]").prop("disabled", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
calcolaBilancio();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 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();
|
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
|
||||||
|
|
||||||
$("select[id*=idconto]").click(function() {
|
$("select[id*=idconto]").click(function() {
|
||||||
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
|
$("input[id*=dare][value!=\'\'], input[id*=avere][value!=\'\']").keyup();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on("change", "select", function() {
|
||||||
|
var row = $(this).parent().parent();
|
||||||
|
|
||||||
|
if ($(this).parent().parent().find("input[disabled]").length != 1) {
|
||||||
|
row.find("input").prop("disabled", $(this).val() ? false : true);
|
||||||
|
}
|
||||||
|
|
||||||
|
controllaConti();
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("keyup change", "input[id*=dare]", function() {
|
||||||
|
var row = $(this).parent().parent();
|
||||||
|
|
||||||
|
if (!$(this).prop("disabled")) {
|
||||||
|
row.find("input[id*=avere]").prop("disabled", $(this).val() ? true : false);
|
||||||
|
|
||||||
|
controllaConti();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(document).on("keyup change", "input[id*=avere]", function() {
|
||||||
|
var row = $(this).parent().parent();
|
||||||
|
|
||||||
|
if (!$(this).prop("disabled")) {
|
||||||
|
row.find("input[id*=dare]").prop("disabled", $(this).val() ? true : false);
|
||||||
|
|
||||||
|
controllaConti();
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>';
|
</script>';
|
||||||
|
@ -58,7 +58,7 @@ if ($_GET['lev'] == '3') {
|
|||||||
$saldo_finale = [];
|
$saldo_finale = [];
|
||||||
|
|
||||||
// Calcolo saldo iniziale
|
// Calcolo saldo iniziale
|
||||||
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$idconto.'" AND data < "'.$date_start.'"');
|
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$idconto.'" AND data < '.prepare($date_start).'');
|
||||||
$saldo_iniziale = $rs[0]['totale'];
|
$saldo_iniziale = $rs[0]['totale'];
|
||||||
$saldo_finale = $saldo_iniziale;
|
$saldo_finale = $saldo_iniziale;
|
||||||
|
|
||||||
@ -72,7 +72,14 @@ if ($_GET['lev'] == '3') {
|
|||||||
|
|
||||||
$body .= " <tr><td class='br bb padded'></td><td class='br bb padded'><b>SALDO INIZIALE</b></td><td class='br bb padded text-right'><b>".moneyFormat(abs($dare), 2)."</b></td><td class='bb padded text-right'><b>".moneyFormat(abs($avere), 2)."</b></td></tr>\n";
|
$body .= " <tr><td class='br bb padded'></td><td class='br bb padded'><b>SALDO INIZIALE</b></td><td class='br bb padded text-right'><b>".moneyFormat(abs($dare), 2)."</b></td><td class='bb padded text-right'><b>".moneyFormat(abs($avere), 2)."</b></td></tr>\n";
|
||||||
|
|
||||||
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$idconto.'" AND data >= "'.$date_start.'" AND data <= "'.$date_end.'" ORDER BY data ASC');
|
$rs = $dbo->fetchArray('SELECT *, SUM(totale) AS totale
|
||||||
|
FROM co_movimenti
|
||||||
|
WHERE idconto='.prepare($idconto).' AND
|
||||||
|
data >= '.prepare($date_start).' AND
|
||||||
|
data <= '.prepare($date_end).'
|
||||||
|
GROUP BY idmastrino
|
||||||
|
ORDER BY data ASC');
|
||||||
|
|
||||||
// Inizializzo saldo finale
|
// Inizializzo saldo finale
|
||||||
$saldo_finale2 = [];
|
$saldo_finale2 = [];
|
||||||
for ($i = 0; $i < sizeof($rs); ++$i) {
|
for ($i = 0; $i < sizeof($rs); ++$i) {
|
||||||
@ -121,7 +128,7 @@ elseif ($_GET['lev'] == '2') {
|
|||||||
$saldo_finale = [];
|
$saldo_finale = [];
|
||||||
|
|
||||||
// Calcolo saldo iniziale
|
// Calcolo saldo iniziale
|
||||||
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data < "'.$date_start.'"');
|
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data < '.prepare($date_start).'');
|
||||||
$saldo_iniziale = $rs[0]['totale'];
|
$saldo_iniziale = $rs[0]['totale'];
|
||||||
$saldo_finale[] = $saldo_iniziale;
|
$saldo_finale[] = $saldo_iniziale;
|
||||||
|
|
||||||
@ -131,7 +138,7 @@ elseif ($_GET['lev'] == '2') {
|
|||||||
$v_dare[] = abs($saldo_iniziale);
|
$v_dare[] = abs($saldo_iniziale);
|
||||||
}
|
}
|
||||||
|
|
||||||
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= "'.$date_start.'" AND data <= "'.$date_end.'" ORDER BY data ASC');
|
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= '.prepare($date_start).' AND data <= '.prepare($date_end).' ORDER BY data ASC');
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($rs); ++$i) {
|
for ($i = 0; $i < sizeof($rs); ++$i) {
|
||||||
if ($rs[$i]['totale'] >= 0) {
|
if ($rs[$i]['totale'] >= 0) {
|
||||||
@ -187,7 +194,7 @@ elseif (get('lev') == '1') {
|
|||||||
$v_dare = [];
|
$v_dare = [];
|
||||||
$v_avere = [];
|
$v_avere = [];
|
||||||
|
|
||||||
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= "'.$date_start.'" AND data <= "'.$date_end.'" ORDER BY data ASC');
|
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= '.prepare($date_start).' AND data <= '.prepare($date_end).' ORDER BY data ASC');
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($rs); ++$i) {
|
for ($i = 0; $i < sizeof($rs); ++$i) {
|
||||||
if ($rs[$i]['totale'] >= 0) {
|
if ($rs[$i]['totale'] >= 0) {
|
||||||
@ -245,11 +252,11 @@ elseif (get('lev') == '1') {
|
|||||||
$saldo_finale = [];
|
$saldo_finale = [];
|
||||||
|
|
||||||
// Calcolo saldo iniziale
|
// Calcolo saldo iniziale
|
||||||
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$rs2[$y]['id'].'" AND data < "'.$date_start.'"');
|
$rs = $dbo->fetchArray('SELECT SUM(totale) AS totale FROM co_movimenti WHERE idconto="'.$rs2[$y]['id'].'" AND data < '.prepare($date_start).'');
|
||||||
$dare = [];
|
$dare = [];
|
||||||
$avere = [];
|
$avere = [];
|
||||||
|
|
||||||
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= "'.$date_start.'" AND data <= "'.$date_end.'" ORDER BY data ASC');
|
$rs = $dbo->fetchArray('SELECT * FROM co_movimenti WHERE idconto="'.$rs3[$z]['id'].'" AND data >= '.prepare($date_start).' AND data <= '.prepare($date_end).' ORDER BY data ASC');
|
||||||
|
|
||||||
for ($i = 0; $i < sizeof($rs); ++$i) {
|
for ($i = 0; $i < sizeof($rs); ++$i) {
|
||||||
if ($rs[$i]['totale'] >= 0) {
|
if ($rs[$i]['totale'] >= 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user