2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
echo '
< form action = " " method = " post " id = " edit-form " >
< input type = " hidden " name = " op " value = " update " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-04 12:02:29 +02:00
< h3 class = " panel-title " > '.tr(' Dettagli scadenza ').' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
< div class = " row " >
<!-- Info scadenza -->
< div class = " col-md-7 " >
< table class = " table table-striped table-hover table-condensed table-bordered " > ' ;
2018-07-18 15:20:10 +02:00
$rs = $dbo -> fetchArray ( 'SELECT * FROM (co_documenti INNER JOIN co_tipidocumento ON co_documenti.idtipodocumento=co_tipidocumento.id) INNER JOIN an_anagrafiche ON co_documenti.idanagrafica=an_anagrafiche.idanagrafica WHERE co_documenti.id=' . prepare ( $record [ 'iddocumento' ]));
2017-08-04 16:28:16 +02:00
$numero = ( ! empty ( $rs [ 0 ][ 'numero_esterno' ])) ? $rs [ 0 ][ 'numero_esterno' ] : $rs [ 0 ][ 'numero' ];
if ( $rs [ 0 ][ 'dir' ] == 'entrata' ) {
$dir = 'entrata' ;
$modulo = 'Fatture di vendita' ;
echo "
< tr >
2017-09-04 12:02:29 +02:00
< th width = '120' > " .tr('Cliente').':</th>
2017-08-04 16:28:16 +02:00
< td >
'.Modules::link(' Anagrafiche ', $rs[0][' idanagrafica '], $rs[0][' ragione_sociale ']).'
</ td >
</ tr > ' ;
} else {
$dir = 'uscita' ;
$modulo = 'Fatture di acquisto' ;
echo "
< tr >
2017-09-04 12:02:29 +02:00
< th width = '120' > " .tr('Fornitore').':</th>
2017-08-04 16:28:16 +02:00
< td > '.$rs[0][' ragione_sociale '].' </ td >
</ tr > ' ;
}
echo '
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Documento ').' :</ th >
2017-08-04 16:28:16 +02:00
< td > '.$rs[0][' descrizione '].' </ td >
</ tr > ' ;
echo '
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Numero ').' :</ th >
2017-08-04 16:28:16 +02:00
< td > '.$numero.' </ td >
</ tr > ' ;
echo '
< tr >
2017-09-04 12:02:29 +02:00
< th > '.tr(' Data ').' :</ th >
2017-08-04 16:28:16 +02:00
< td > '.Translator::dateToLocale($rs[0][' data ']).' </ td >
</ tr > ' ;
echo '
</ table >
2018-07-18 15:20:10 +02:00
'.Modules::link($modulo, $record[' iddocumento '], ' < i class = " fa fa-folder-open " ></ i > '.tr(' Apri documento '), null, ' class = " btn btn-primary " ').'
2017-08-04 16:28:16 +02:00
</ div >
<!-- Elenco scadenze -->
< div class = " col-md-5 " >
< table class = " table table-hover table-condensed table-bordered " >
< tr >
2018-11-14 17:35:53 +01:00
< th width = " 150 " > '.tr(' Data ').' </ th >
2017-09-04 12:02:29 +02:00
< th width = " 150 " > '.tr(' Importo ').' </ th >
< th width = " 150 " > '.tr(' Pagato ').' </ th >
2017-08-04 16:28:16 +02:00
</ tr > ' ;
$totale_da_pagare = 0 ;
$totale_pagato = 0 ;
$rs = $dbo -> fetchArray ( 'SELECT * FROM co_scadenziario WHERE iddocumento = (SELECT iddocumento FROM co_scadenziario s WHERE id=' . prepare ( $id_record ) . ') ORDER BY scadenza ASC' );
for ( $i = 0 ; $i < count ( $rs ); ++ $i ) {
if ( $rs [ $i ][ 'da_pagare' ] == $rs [ $i ][ 'pagato' ]) {
$class = 'success' ;
} elseif ( abs ( $rs [ $i ][ 'pagato' ]) == 0 ) {
$class = 'danger' ;
} elseif ( abs ( $rs [ $i ][ 'pagato' ]) <= abs ( $rs [ $i ][ 'da_pagare' ])) {
$class = 'warning' ;
} else {
$class = 'danger' ;
}
echo '
< tr class = " '. $class .' " >
< td align = " center " >
{[ " type " : " date " , " name " : " data['. $rs[$i] ['id'].'] " , " value " : " '. $rs[$i] ['scadenza'].' " ]}
</ td >
< td align = " right " >
2018-11-14 17:29:47 +01:00
{[ " type " : " number " , " name " : " scadenza['. $rs[$i] ['id'].'] " , " value " : " '.Translator::numberToLocale( $rs[$i] ['da_pagare']).' " ]}
2017-08-04 16:28:16 +02:00
</ td >
< td align = " right " >
2018-11-14 17:29:47 +01:00
{[ " type " : " number " , " name " : " pagato['. $rs[$i] ['id'].'] " , " value " : " '.Translator::numberToLocale( $rs[$i] ['pagato']).' " ]}
2017-08-04 16:28:16 +02:00
</ td >
</ tr > ' ;
}
2018-10-19 16:25:32 +02:00
$totale_da_pagare = sum ( array_column ( $rs , 'da_pagare' ));
$totale_pagato = sum ( array_column ( $rs , 'pagato' ));
2017-08-04 16:28:16 +02:00
2019-02-21 12:37:06 +01:00
if ( $totale_da_pagare == $totale_pagato ) {
echo '
< script >
$ ( document ) . ready ( function (){
$ ( " #pulsanti " ) . children () . find ( " a:nth-child(2) " ) . attr ( " disabled " , true ) . addClass ( " disabled " );
})
</ script > ' ;
}
2017-08-04 16:28:16 +02:00
echo '
< tr >
2017-09-04 12:02:29 +02:00
< td align = " right " >< b > '.tr(' Totale ').' </ b ></ td >
2017-08-04 16:28:16 +02:00
< td align = " right " id = " totale_utente " > '.Translator::numberToLocale($totale_da_pagare).' </ td >
< td align = " right " ></ td >
</ tr > ' ;
?>
</ table >
2019-04-11 16:04:08 +02:00
< div class = 'pull-right' >
< a onclick = " launch_modal( 'Aggiungi prima nota', '<?php echo $rootdir ; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&iddocumento=<?php echo $record['iddocumento'] ; ?>&dir=<?php echo $dir ; ?>', 1 ); " class = " btn btn-sm btn-primary " >< i class = " fa fa-euro " ></ i > < ? php echo tr ( 'Aggiungi prima nota...' ); ?> </a>
</ div >
2018-10-19 16:19:49 +02:00
< div class = " clearfix " ></ div >
2017-08-04 16:28:16 +02:00
2019-04-13 00:09:48 +02:00
< div class = " alert alert-error hide " id = " totale " >< ? php echo tr ( 'Il totale da pagare deve essere pari a _TOT_ _CURRENCY_' , [
'_TOT_' => '<b>' . Translator :: numberToLocale ( $totale_da_pagare ) . '</b>' ,
'_CURRENCY_' => currency (),
]); ?> .<br><?php echo tr('Differenza di _TOT_ _CURRENCY_', [
'_TOT_' => '<span id="diff"></span>' ,
'_CURRENCY_' => currency (),
]); ?> .
2018-10-19 16:19:49 +02:00
</ div >
2017-08-04 16:28:16 +02:00
2018-02-18 19:53:23 +01:00
< input type = " hidden " id = " totale_da_pagare " value = " <?php echo Translator::numberToLocale( $totale_da_pagare ); ?> " >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
< div class = " clearfix " ></ div >
</ form >
2019-02-21 12:24:57 +01:00
{( " name " : " log_email " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
2017-08-04 16:28:16 +02:00
< script >
$ ( document ) . ready ( function (){
totale_ok ();
$ ( 'input[name*=scadenza]' ) . keyup ( function (){ totale_ok (); } );
});
function totale_ok (){
2017-08-11 12:11:57 +02:00
totale_da_pagare = $ ( '#totale_da_pagare' ) . val () . toEnglish ();
2017-08-04 16:28:16 +02:00
totale_utente = 0 ;
$ ( 'input[name*=scadenza]' ) . each ( function (){
2018-10-19 16:19:49 +02:00
2017-08-11 12:11:57 +02:00
totale_utente += $ ( this ) . val () . toEnglish ();
2018-10-19 16:19:49 +02:00
2017-08-04 16:28:16 +02:00
});
if ( isNaN ( totale_utente ) ){
totale_utente = 0 ;
}
totale_utente = Math . round ( totale_utente * 100 ) / 100 ;
totale_da_pagare = Math . round ( totale_da_pagare * 100 ) / 100 ;
diff = Math . abs ( totale_da_pagare ) - Math . abs ( totale_utente );
if ( diff == 0 ){
$ ( '#btn-saves' ) . removeClass ( 'hide' );
$ ( '#totale' ) . addClass ( 'hide' );
}
else {
$ ( '#btn-saves' ) . addClass ( 'hide' );
$ ( '#totale' ) . removeClass ( 'hide' );
}
2017-09-19 16:50:01 +02:00
$ ( '#diff' ) . html ( diff . toLocale ());
$ ( '#totale_utente' ) . html ( totale_utente . toLocale ());
2017-08-04 16:28:16 +02:00
}
</ script >