2017-08-04 16:28:16 +02:00
< ? php
2018-06-18 15:56:00 +02:00
if ( file_exists ( __DIR__ . '/../../../core.php' )) {
include_once __DIR__ . '/../../../core.php' ;
} else {
include_once __DIR__ . '/../../core.php' ;
}
2017-08-04 16:28:16 +02:00
$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' ])) {
2017-12-20 14:05:14 +01:00
$sconto_unitario = $rs [ 0 ][ 'prc_guadagno' ];
2017-09-11 11:28:39 +02:00
$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' ];
2018-03-19 18:11:51 +01:00
$idiva = $rsr [ 0 ][ 'idiva' ];
2017-08-04 16:28:16 +02:00
$prezzo_vendita = $rsr [ 0 ][ 'prezzo_vendita' ];
$prezzo_acquisto = $rsr [ 0 ][ 'prezzo_acquisto' ];
2018-03-19 18:11:51 +01:00
2017-08-04 16:28:16 +02:00
$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-28 10:16:18 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " id " : " descrizione_riga " , " name " : " descrizione " , " required " : 1 , " value " : '.json_encode($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-22 15:19:59 +02:00
{[ " type " : " select " , " label " : " '.tr('Unità di misura').' " , " icon-after " : " add|'.Modules::get('Unità di misura')['id'].' " , " name " : " um " , " value " : " '. $um .' " , " ajax-source " : " misure " ]}
2018-03-19 18:11:51 +01:00
</ div > ' ;
// Iva
echo '
< 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 > ' ;
// 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
2018-02-18 19:53:23 +01:00
$ ( '#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
2018-02-18 19:53:23 +01:00
$ ( '#costi' ) . load ( globals . rootdir + '/modules/interventi/ajax_costi.php?id_module=<?php echo $id_module; ?>&id_record=<?php echo $id_record; ?>' );
2017-09-13 17:08:27 +02:00
}
});
2017-08-04 16:28:16 +02:00
});
</ script >