2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
?> <form action="" method="post" id="edit-form">
< input type = " hidden " name = " op " value = " editriga " >
< input type = " hidden " name = " backto " value = " record-edit " >
2018-02-18 19:53:23 +01:00
< input type = " hidden " name = " id_record " value = " <?php echo $id_record ; ?> " >
2018-07-18 15:20:10 +02:00
< input type = " hidden " name = " idmastrino " value = " <?php echo $record['idmastrino'] ; ?> " >
< input type = " hidden " name = " iddocumento " value = " <?php echo $record['iddocumento'] ; ?> " >
2017-08-04 16:28:16 +02:00
2018-04-04 01:04:55 +02:00
< div class = " row " >
2017-08-04 16:28:16 +02:00
< ? php
2019-04-12 09:20:23 +02:00
2019-04-15 11:35:09 +02:00
$rs_doc = $dbo -> fetchArray ( 'SELECT DISTINCT iddocumento, (SELECT IFNULL(numero_esterno, numero) FROM co_documenti WHERE id=co_movimenti.iddocumento) AS numero FROM co_movimenti WHERE idmastrino=' . prepare ( $record [ 'idmastrino' ]) . ' AND iddocumento!=0' );
2019-04-12 09:20:23 +02:00
2019-04-15 11:35:09 +02:00
if ( sizeof ( $rs_doc ) > 0 ) {
if ( sizeof ( $rs_doc ) == 1 ) {
$rs = $dbo -> fetchArray ( 'SELECT dir FROM co_tipidocumento INNER JOIN co_documenti ON co_tipidocumento.id=co_documenti.idtipodocumento WHERE co_documenti.id=' . prepare ( $rs_doc [ 0 ][ 'iddocumento' ]));
$modulo = ( $rs [ 0 ][ 'dir' ] == 'entrata' ) ? 'Fatture di vendita' : 'Fatture di acquisto' ; ?>
< div class = " col-md-2 " >
< br >
< a href = " <?php echo $rootdir ; ?>/editor.php?id_module=<?php echo Modules::get( $modulo )['id']; ?>&id_record=<?php echo $rs_doc[0] ['iddocumento']; ?> " class = " btn btn-info " >< i class = " fa fa-chevron-left " ></ i > < ? php echo tr ( 'Vai alla fattura' ); ?> </a>
2019-04-12 09:20:23 +02:00
</ div >
2019-04-15 11:35:09 +02:00
< ? php
} else {
?>
< div class = " col-md-2 " >
< br >
< div class = " dropdown " >
< button class = " btn btn-primary dropdown-toggle " type = " button " data - toggle = " dropdown " style = " width:100%; " > Fatture collegate
< span class = " caret " ></ span ></ button >
< ul class = " dropdown-menu " >
< ? php
for ( $i = 0 ; $i < sizeof ( $rs_doc ); ++ $i ) {
$rs = $dbo -> fetchArray ( 'SELECT dir FROM co_tipidocumento INNER JOIN co_documenti ON co_tipidocumento.id=co_documenti.idtipodocumento WHERE co_documenti.id=' . prepare ( $rs_doc [ $i ][ 'iddocumento' ]));
$modulo = ( $rs [ 0 ][ 'dir' ] == 'entrata' ) ? 'Fatture di vendita' : 'Fatture di acquisto' ; ?>
< li >< a href = " <?php echo $rootdir ; ?>/editor.php?id_module=<?php echo Modules::get( $modulo )['id']; ?>&id_record=<?php echo $rs_doc[$i] ['iddocumento']; ?> " class = " dropdown-item " >< ? php echo tr ( 'Vai alla fattura n. ' . $rs_doc [ $i ][ 'numero' ]); ?> </a></li>
< ? php
} ?>
</ ul >
</ div >
</ div >
< ? php
}
2017-08-04 16:28:16 +02:00
}
?>
2018-04-04 01:04:55 +02:00
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " date " , " label " : " <?php echo tr('Data movimento'); ?> " , " name " : " data " , " required " : 1 , " value " : " $data $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-04-04 01:04:55 +02:00
< div class = " col-md-7 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Causale'); ?> " , " name " : " descrizione " , " required " : 1 , " value " : " $descrizione $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< ? php
$conti3 = []; // contenitore conti di terzo livello
$totale_dare = 0.00 ;
$totale_avere = 0.00 ;
2018-07-18 15:20:10 +02:00
$idmastrino = $record [ 'idmastrino' ];
2017-08-04 16:28:16 +02:00
// Salvo l'elenco conti in un array (per non fare il ciclo ad ogni riga)
$query2 = 'SELECT * FROM co_pianodeiconti2' ;
$conti2 = $dbo -> fetchArray ( $query2 );
for ( $x = 0 ; $x < sizeof ( $conti2 ); ++ $x ) {
$query3 = 'SELECT * FROM co_pianodeiconti3 WHERE idpianodeiconti2=' . prepare ( $conti2 [ $x ][ 'id' ]);
$rs3 = $dbo -> fetchArray ( $query3 );
for ( $y = 0 ; $y < sizeof ( $rs3 ); ++ $y ) {
// Creo un array con le descrizioni dei conti di livello 3 che ha come indice l'id del livello2 e del livello3
$conti3 [ $rs3 [ $y ][ 'idpianodeiconti2' ]][ $y ][ 'id' ] = $rs3 [ $y ][ 'id' ];
$conti3 [ $rs3 [ $y ][ 'idpianodeiconti2' ]][ $y ][ 'descrizione' ] = $conti2 [ $x ][ 'numero' ] . '.' . $rs3 [ $y ][ 'numero' ] . ' ' . $rs3 [ $y ][ 'descrizione' ];
}
}
/*
Form di modifica riga movimento
*/
// Lettura movimenti del mastrino selezionato
2019-04-12 09:20:23 +02:00
$query = 'SELECT * FROM co_movimenti WHERE idmastrino=' . prepare ( $record [ 'idmastrino' ]) . ' AND primanota=' . prepare ( $record [ 'primanota' ]);
2017-08-04 16:28:16 +02:00
$rs = $dbo -> fetchArray ( $query );
$n = sizeof ( $rs );
$iddocumento = $rs [ 0 ][ 'iddocumento' ];
echo '
< table class = " table table-striped table-condensed table-hover table-bordered "
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Conto ').' </ th >
< th width = " 20% " > '.tr(' Dare ').' </ th >
< th width = " 20% " > '.tr(' Avere ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
2019-04-13 00:09:48 +02:00
if ( sizeof ( $rs ) >= 10 ) {
$rows = sizeof ( $rs ) + 2 ;
} else {
2019-04-12 09:20:23 +02:00
$rows = 10 ;
}
2017-08-04 16:28:16 +02:00
2019-04-12 09:20:23 +02:00
for ( $i = 0 ; $i < $rows ; ++ $i ) {
2018-06-26 14:30:26 +02:00
( $i <= 1 ) ? $required = 1 : $required = 0 ;
2017-08-04 16:28:16 +02:00
// Conto
echo '
< tr >
2019-04-12 09:20:23 +02:00
< td >
< input type = " hidden " name = " iddocumento['. $i .'] " value = " '. $rs[$i] ['iddocumento'].' " >
2018-04-17 19:09:19 +02:00
{[ " type " : " select " , " name " : " idconto['. $i .'] " , " value " : " '. $rs[$i] ['idconto'].' " , " ajax-source " : " conti " , " required " : " '. $required .' " ]}
2017-08-04 16:28:16 +02:00
</ td > ' ;
// Importo dare e avere
if ( $rs [ $i ][ 'totale' ] > 0 ) {
$value_dare = $rs [ $i ][ 'totale' ];
$value_avere = '' ;
} elseif ( $rs [ $i ][ 'totale' ] < 0 ) {
$value_dare = '' ;
$value_avere = - $rs [ $i ][ 'totale' ];
} else {
$value_dare = '' ;
$value_avere = '' ;
}
// Dare
echo '
< td >
{[ " type " : " number " , " name " : " dare['. $i .'] " , " value " : " '. $value_dare .' " , " disabled " : 1 ]}
</ td > ' ;
// Avere
echo '
< td >
{[ " type " : " number " , " name " : " avere['. $i .'] " , " value " : " '. $value_avere .' " , " disabled " : 1 ]}
</ td >
</ tr > ' ;
}
// Totale per controllare sbilancio
echo '
< tr >
< td align = " right " >< b > Totale :</ b ></ td > ' ;
if ( $totale_dare != $totale_avere ) {
$class = 'text-danger' ;
2019-04-13 02:56:39 +02:00
$txt = 'sbilancio di ' . moneyFormat ( $totale_dare - $totale_avere );
2017-08-04 16:28:16 +02:00
} else {
$class = '' ;
$txt = '' ;
}
// Totale dare
echo '
< td align = " right " >
2019-04-13 00:09:48 +02:00
< span >< span class = " '. $class .' " id = " totale_dare " > '.Translator::numberToLocale($totale_dare).' </ span > '.currency().' </ span >
2017-08-04 16:28:16 +02:00
</ td > ' ;
// Totale avere
echo '
< td align = " right " >
2019-04-13 00:09:48 +02:00
< span >< span class = " '. $class .' " id = " totale_avere " > '.Translator::numberToLocale($totale_avere).' </ span > '.currency().' </ span >
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
// Verifica sbilancio
echo '
< tr >
< td align = " right " ></ td >
< td colspan = " 2 " align = " center " >
< span id = " testo_aggiuntivo " > '.$txt.' </ span >
</ td >
</ tr >
</ table > ' ;
?>
< script type = " text/javascript " >
$ ( document ) . ready ( function (){
$ ( 'input[id*=dare], input[id*=avere]' ) . each ( function (){
2018-02-18 19:53:23 +01:00
if ( $ ( this ) . val () != " <?php echo Translator::numberToLocale(0); ?> " ) $ ( this ) . prop ( " disabled " , false );
2017-08-04 16:28:16 +02:00
});
$ ( '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 ( " " );
}
}
});
$ ( '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 ();
}
});
// Ad ogni modifica dell'importo verifica che siano stati selezionati: il conto, la causale, la data. Inoltre aggiorna lo sbilancio
function calcolaBilancio (){
bilancio = 0.00 ;
totale_dare = 0.00 ;
totale_avere = 0.00 ;
// Calcolo il totale dare e totale avere
$ ( 'input[id*=dare]' ) . each ( function (){
if ( $ ( this ) . val () == '' ) valore = 0 ;
2017-08-11 12:11:57 +02:00
else valore = $ ( this ) . val () . toEnglish ();
2018-05-15 12:36:27 +02:00
totale_dare += Math . round ( valore * 100 ) / 100 ;
2017-08-04 16:28:16 +02:00
});
$ ( 'input[id*=avere]' ) . each ( function (){
if ( $ ( this ) . val () == '' ) valore = 0 ;
2017-08-11 12:11:57 +02:00
else valore = $ ( this ) . val () . toEnglish ();
2018-05-15 12:36:27 +02:00
totale_avere += Math . round ( valore * 100 ) / 100 ;
2017-08-04 16:28:16 +02:00
});
2017-09-19 16:50:01 +02:00
$ ( '#totale_dare' ) . text ( totale_dare . toLocale ());
$ ( '#totale_avere' ) . text ( totale_avere . toLocale ());
2017-08-04 16:28:16 +02:00
2018-05-15 12:36:27 +02:00
bilancio = Math . round ( totale_dare * 100 ) / 100 - Math . round ( totale_avere * 100 ) / 100 ;
2017-08-04 16:28:16 +02:00
if ( bilancio == 0 ){
$ ( " #testo_aggiuntivo " ) . removeClass ( 'text-danger' ) . html ( " " );
2018-04-04 01:04:55 +02:00
//$("button[type=submit]").removeClass('hide');
$ ( " #save " ) . removeClass ( 'hide' );
2018-07-18 15:20:10 +02:00
2017-08-04 16:28:16 +02:00
}
else {
2019-04-13 00:09:48 +02:00
$ ( " #testo_aggiuntivo " ) . addClass ( 'text-danger' ) . html ( " sbilancio di " + bilancio . toLocale () + " " + globals . currency );
2017-08-04 16:28:16 +02:00
2018-04-04 01:04:55 +02:00
//$("button[type=submit]").addClass('hide');
$ ( " #save " ) . addClass ( 'hide' );
2017-08-04 16:28:16 +02: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 ();
$ ( " select[id*=idconto] " ) . click ( function (){
$ ( " input[id*=dare][value!=''], input[id*=avere][value!=''] " ) . keyup ();
});
});
</ script >
</ form >
2018-07-18 15:20:10 +02:00
< a class = " btn btn-danger ask " data - backto = " record-list " data - idmastrino = " <?php echo $record['idmastrino'] ; ?> " >
2017-09-04 12:02:29 +02:00
< i class = " fa fa-trash " ></ i > < ? php echo tr ( 'Elimina' ); ?>
2017-08-04 16:28:16 +02:00
</ a >