2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
$idriga = filter ( 'idriga' );
//Lettura idanagrafica cliente e percentuale di sconto/rincaro in base al listino
2017-09-11 11:28:39 +02:00
$rs = $dbo -> fetchArray ( 'SELECT idanagrafica, (SELECT prc_guadagno FROM mg_listini WHERE id=(SELECT idlistino_vendite FROM an_anagrafiche WHERE idanagrafica=.in_interventi.idanagrafica)) AS prc_sconto FROM in_interventi WHERE id=' . prepare ( $id_record ));
2017-08-04 16:28:16 +02:00
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
$prc_sconto = $rs [ 0 ][ 'prc_sconto' ];
if ( empty ( $idriga )) {
$op = 'addriga' ;
2017-09-04 12:02:29 +02:00
$button = '<i class="fa fa-plus"></i> ' . tr ( 'Aggiungi' );
2017-08-04 16:28:16 +02:00
// valori default
$descrizione = '' ;
$qta = 1 ;
$um = '' ;
$prezzo_vendita = '0' ;
$prezzo_acquisto = '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 = '<i class="fa fa-edit"></i> ' . tr ( 'Modifica' );
2017-08-04 16:28:16 +02:00
// carico record da modificare
$q = 'SELECT * FROM in_righe_interventi WHERE id=' . prepare ( $idriga );
$rsr = $dbo -> fetchArray ( $q );
$descrizione = $rsr [ 0 ][ 'descrizione' ];
$qta = $rsr [ 0 ][ 'qta' ];
$um = $rsr [ 0 ][ 'um' ];
$prezzo_vendita = $rsr [ 0 ][ 'prezzo_vendita' ];
$prezzo_acquisto = $rsr [ 0 ][ 'prezzo_acquisto' ];
$sconto_unitario = $rsr [ 0 ][ 'sconto_unitario' ];
$tipo_sconto = $rsr [ 0 ][ 'tipo_sconto' ];
}
/*
Form di inserimento
*/
echo '
< form id = " add-righe " 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 .' " > ' ;
// Descrizione
echo '
< div class = " row " >
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " id " : " descrizione_riga " , " name " : " descrizione " , " required " : 1 , " value " : " '. $descrizione .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< br > ' ;
// Quantità
echo '
< div class = " row " >
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Q.tà').' " , " name " : " qta " , " required " : 1 , " value " : " '. $qta .' " , " 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 >
</ div > ' ;
// Prezzo di acquisto
echo '
< div class = " row " >
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Prezzo di acquisto (un.)').' " , " name " : " prezzo_acquisto " , " required " : 1 , " value " : " '. $prezzo_acquisto .' " , " icon-after " : " € " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Prezzo di vendita
echo '
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Prezzo di vendita (un.)').' " , " name " : " prezzo_vendita " , " required " : 1 , " value " : " '. $prezzo_vendita .' " , " icon-after " : " € " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Sconto unitario
echo '
< div class = " col-md-4 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Sconto unitario').' " , " name " : " sconto " , " icon-after " : " choice|untprc|'. $tipo_sconto .' " , " value " : " '. $sconto_unitario .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
echo '
2017-09-11 13:08:50 +02:00
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
< button type = " submit " class = " btn btn-primary pull-right " > '.$button.' </ button >
</ div >
</ div >
2017-09-11 11:28:39 +02:00
</ form > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;
2017-08-04 16:28:16 +02:00
?>
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
2017-09-13 17:08:27 +02:00
$ ( '#add-righe' ) . ajaxForm ({
success : function (){
$ ( '#bs-popup' ) . modal ( 'hide' );
2017-08-04 16:28:16 +02:00
2017-09-13 17:08:27 +02:00
// Ricarico le righe
$ ( '#righe' ) . load ( globals . rootdir + '/modules/interventi/ajax_righe.php?id_module=<?php echo $id_module ?>&id_record=<?php echo $id_record ?>' );
2017-08-04 16:28:16 +02:00
2017-09-13 17:08:27 +02:00
// Ricarico la tabella dei costi
$ ( '#costi' ) . load ( globals . rootdir + '/modules/interventi/ajax_costi.php?id_module=<?php echo $id_module ?>&id_record=<?php echo $id_record ?>' );
}
});
2017-08-04 16:28:16 +02:00
});
</ script >