2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$idcontratto = $get [ 'idcontratto' ];
$idriga = $get [ 'idriga' ];
// Info contratto
2017-09-11 11:28:39 +02:00
$q = 'SELECT *, (SELECT prc_guadagno FROM mg_listini WHERE id=(SELECT idlistino_vendite FROM an_anagrafiche WHERE idanagrafica=co_contratti.idanagrafica)) AS prc_guadagno FROM co_contratti WHERE id=' . prepare ( $idcontratto );
2017-08-04 16:28:16 +02:00
$rs = $dbo -> fetchArray ( $q );
$numero = $rs [ 0 ][ 'numero' ];
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
if ( empty ( $idriga )) {
$op = 'addriga' ;
2017-09-04 12:02:29 +02:00
$button = tr ( 'Aggiungi' );
2017-08-04 16:28:16 +02:00
// valori default
$descrizione = '' ;
$qta = 1 ;
$um = '' ;
$prezzo = 0 ;
$sconto = 0 ;
2017-09-11 11:28:39 +02:00
$tipo_sconto = '' ;
if ( ! empty ( $rs [ 0 ][ 'prc_guadagno' ])) {
$sconto = $rs [ 0 ][ 'prc_guadagno' ];
$tipo_sconto = 'PRC' ;
}
2017-08-04 16:28:16 +02:00
// Leggo l'iva predefinita dall'anagrafica e se non c'è leggo quella predefinita generica
$rsa = $dbo -> fetchArray ( 'SELECT idiva FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $idanagrafica ));
$idiva = ( ! empty ( $rsa [ 0 ][ 'idiva' ])) ? $rsa [ 0 ][ 'idiva' ] : get_var ( 'Iva predefinita' );
} else {
$op = 'editriga' ;
2017-09-04 12:02:29 +02:00
$button = tr ( 'Modifica' );
2017-08-04 16:28:16 +02:00
$rsr = $dbo -> fetchArray ( 'SELECT * FROM co_righe2_contratti WHERE idcontratto=' . prepare ( $idcontratto ) . ' AND id=' . prepare ( $idriga ));
$descrizione = $rsr [ 0 ][ 'descrizione' ];
$qta = $rsr [ 0 ][ 'qta' ];
$um = $rsr [ 0 ][ 'um' ];
$idiva = $rsr [ 0 ][ 'idiva' ];
$prezzo = $rsr [ 0 ][ 'subtotale' ] / $rsr [ 0 ][ 'qta' ];
$sconto = $rsr [ 0 ][ 'sconto' ];
2017-09-11 11:28:39 +02:00
$tipo_sconto = $rsr [ 0 ][ 'tipo_sconto' ];
2017-08-04 16:28:16 +02:00
}
echo '
< form action = " '. $rootdir .'/editor.php?id_module='.Modules::getModule('Contratti')['id'].'&id_record='. $idcontratto .' " method = " post " >
< input type = " hidden " name = " op " value = " '. $op .' " >
< input type = " hidden " name = " idriga " value = " '. $idriga .' " >
< input type = " hidden " name = " backto " value = " record-edit " > ' ;
// Descrizione
echo '
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " name " : " descrizione " , " value " : " '. $descrizione .' " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Iva
echo '
< div class = " col-md-4 " >
2017-09-11 11:28:39 +02:00
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " values " : " query=SELECT id, descrizione FROM co_iva ORDER BY descrizione ASC " , " value " : " '. $idiva .' " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Quantità
echo '
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Q.tà').' " , " name " : " qta " , " value " : " '. $qta .' " , " required " : 1 , " decimals " : " qta " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Unità di misura
echo '
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Unità di misura').' " , " icon-after " : " add|'.Modules::getModule('Unità di misura')['id'].' " , " name " : " um " , " value " : " '. $um .' " , " ajax-source " : " misure " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
/*
if ( ! empty ( $idriga )) {
//Rivalsa INPS
if ( get_var ( " Percentuale rivalsa INPS " ) != " " ){
echo " <div class='col-md-3'> \n " ;
echo " <label>Rivalsa INPS:</label> \n " ;
echo " <select id='idrivalsainps' class='superselect' name= \" idrivalsainps \" > \n " ;
echo " <option value=''>-</option> \n " ;
$query = " SELECT * FROM co_rivalsainps " ;
$rs = $dbo -> fetchArray ( $query );
for ( $i = 0 ; $i < sizeof ( $rs ); $i ++ ){
( $rs [ $i ][ 'id' ] == $rsr [ $i ][ 'idrivalsainps' ] ) ? $attr = 'selected="true"' : $attr = '' ;
echo " <option value=' " . $rs [ $i ][ 'id' ] . " ' " . $attr . " > " . $rs [ $i ][ 'descrizione' ] . " </option> \n " ;
}
echo " </select> \n " ;
echo " </div> \n " ;
}
//Ritenuta d'acconto
if ( get_var ( " Percentuale ritenuta d'acconto " ) != " " ){
echo " <div class='col-md-3'> \n " ;
echo " <label>Ritenuta d'acconto:</label> \n " ;
echo " <select id='idritenutaacconto' class='superselect' name= \" idritenutaacconto \" > \n " ;
echo " <option value=''>-</option> \n " ;
$query = " SELECT * FROM co_ritenutaacconto " ;
$rs = $dbo -> fetchArray ( $query );
for ( $i = 0 ; $i < sizeof ( $rs ); $i ++ ){
( $rs [ $i ][ 'id' ] == $rsr [ $i ][ 'idritenutaacconto' ] ) ? $attr = 'selected="true"' : $attr = '' ;
echo " <option value=' " . $rs [ $i ][ 'id' ] . " ' " . $attr . " > " . $rs [ $i ][ 'descrizione' ] . " </option> \n " ;
}
echo " </select> \n " ;
echo " </div> \n " ;
}
}
*/
// Costo unitario
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Costo unitario').' " , " name " : " prezzo " , " required " : 1 , " value " : " '. $prezzo .' " , " icon-after " : " € " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Sconto unitario
echo '
< div class = " col-md-6 " >
2017-09-11 11:28:39 +02:00
{[ " type " : " number " , " label " : " '.tr('Sconto unitario').' " , " name " : " sconto " , " value " : " '. $sconto .' " , " icon-after " : " choice|untprc|'. $tipo_sconto .' " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< button type = " submit " class = " btn btn-primary pull-right " >< i class = " fa fa-plus " ></ i > '.$button.' </ button >
</ div >
</ div >
</ form > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;