2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$idriga = get ( 'idriga' );
// Info preventivo
2017-09-11 11:28:39 +02:00
$q = 'SELECT numero, idanagrafica, (SELECT prc_guadagno FROM mg_listini WHERE id=(SELECT idlistino_vendite FROM an_anagrafiche WHERE idanagrafica=co_preventivi.idanagrafica)) AS prc_guadagno FROM co_preventivi WHERE id=' . prepare ( $id_record );
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
$idarticolo = '' ;
$descrizione = '' ;
$qta = 1 ;
$um = '' ;
$idiva = get_var ( 'Iva predefinita' );
$subtot = 0 ;
$sconto = 0 ;
2017-09-11 11:28:39 +02:00
if ( ! empty ( $rs [ 0 ][ 'prc_guadagno' ])) {
$sconto = $rs [ 0 ][ 'prc_guadagno' ];
$tipo_sconto = 'PRC' ;
}
2017-08-04 16:28:16 +02:00
} else {
$op = 'editriga' ;
2017-09-04 12:02:29 +02:00
$button = tr ( 'Modifica' );
2017-08-04 16:28:16 +02:00
// carico record da modificare
$q = 'SELECT * FROM co_righe_preventivi WHERE idpreventivo=' . prepare ( $id_record ) . ' AND id=' . prepare ( $idriga );
$rsr = $dbo -> fetchArray ( $q );
2017-08-04 16:38:34 +02:00
$idarticolo = ! empty ( $rsr [ 0 ][ 'idarticolo' ]) ? $rsr [ 0 ][ 'idarticolo' ] : '' ;
2017-08-04 16:28:16 +02:00
$descrizione = $rsr [ 0 ][ 'descrizione' ];
$qta = $rsr [ 0 ][ 'qta' ];
$um = $rsr [ 0 ][ 'um' ];
$idiva = $rsr [ 0 ][ 'idiva' ];
$subtot = $rsr [ 0 ][ 'subtotale' ] / $rsr [ 0 ][ 'qta' ];
$sconto = $rsr [ 0 ][ 'sconto_unitario' ];
$tipo_sconto = $rsr [ 0 ][ 'tipo_sconto' ];
}
/*
Form add / edit
*/
echo '
2017-09-10 14:35:41 +02:00
< p > '.tr(' Preventivo numero _NUM_ ' , [
'_NUM_' => $numero ,
]) . ' </ p >
2017-08-04 16:28:16 +02:00
< form id = " form " action = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .' " method = " post " >
< input type = " hidden " name = " op " value = " '. $op .' " >
< input type = " hidden " name = " idriga " value = " '. $idriga .' " >
< input type = " hidden " name = " backto " value = " record-edit " > ' ;
// Elenco articoli raggruppati per gruppi e sottogruppi
echo '
< div class = " row " >
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Articolo').' " , " name " : " idarticolo " , " value " : " '. $idarticolo .' " , " ajax-source " : " articoli " , " extra " : " onchange= \" session_set( \ 'superselect,idarticolo \ ', $ (this).val(), 0); $data = $ (this).selectData(); $ ( \ '#prezzo \ ').val( $data .prezzo_vendita); $ ( \ '#desc \ ').val( $data .descrizione); $ ( \ '#um \ ').selectSetNew( $data .um, $data .um); \" " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Descrizione
echo '
< div class = " row " >
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " name " : " descrizione " , " id " : " desc " , " value " : " '. $descrizione .' " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Quantità
echo '
< div class = " row " >
2017-09-07 16:51:14 +02:00
< 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 '
2017-09-07 16:51:14 +02:00
< 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 > ' ;
2017-09-07 16:51:14 +02:00
// Iva
2017-08-04 16:28:16 +02:00
echo '
2017-09-07 16:51:14 +02:00
< div class = " col-md-4 " >
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " value " : " '. $idiva .' " , " values " : " query=SELECT * FROM co_iva ORDER BY descrizione ASC " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
/*
if ( get_var ( 'Percentuale rivalsa INPS' ) != '' || get_var ( " Percentuale ritenuta d'acconto " ) != '' ) {
echo '
< div class = " row " > ' ;
// Rivalsa INPS
if ( get_var ( 'Percentuale rivalsa INPS' ) != '' ) {
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Rivalsa INPS').' " , " name " : " idrivalsainps " , " required " : 1 , " value " : " '.get_var('Percentuale rivalsa INPS').' " , " values " : " query=SELECT * FROM co_rivalsainps " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
}
// Ritenuta d'acconto
if ( get_var ( " Percentuale ritenuta d'acconto " ) != '' ) {
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr( " Ritenuta d 'acconto").' " , " name " : " idritenutaacconto " , " required " : 1, " value " : " '.get_var("Percentuale ritenuta d' acconto " ).' " , " values " : " query=SELECT * FROM co_ritenutaacconto " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
}
echo '
</ div > ' ;
}
*/
2017-09-07 16:51:14 +02:00
// Costo unitario
2017-08-04 16:28:16 +02:00
echo '
< div class = " row " >
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Costo unitario').' " , " name " : " prezzo " , " required " : 1 , " value " : " '. $subtot .' " , " icon-after " : " € " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Sconto unitario
echo '
2017-09-07 16:51:14 +02:00
< div class = " col-md-6 " >
2017-09-04 12:02:29 +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 >
</ 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 > ' ;