2017-08-04 16:28:16 +02:00
< ? php
2018-06-26 14:30:26 +02:00
if ( file_exists ( __DIR__ . '/../../../core.php' )) {
include_once __DIR__ . '/../../../core.php' ;
} else {
include_once __DIR__ . '/../../core.php' ;
2018-06-18 15:56:00 +02:00
}
2017-08-04 16:28:16 +02:00
// Prezzo modificabile solo se l'utente loggato è un tecnico (+ può vedere i prezzi) o se è amministratore
2018-07-08 15:41:38 +02:00
$gruppi = Auth :: user ()[ 'gruppo' ];
2018-07-08 18:11:17 +02:00
$can_edit_prezzi = ( in_array ( 'Amministratori' , $gruppi )) || ( setting ( 'Mostra i prezzi al tecnico' ) == 1 && ( in_array ( 'Tecnici' , $gruppi )));
2017-08-04 16:28:16 +02:00
$idriga = get ( 'idriga' );
$idautomezzo = ( get ( 'idautomezzo' ) == 'undefined' ) ? '' : get ( 'idautomezzo' );
2017-09-11 11:28:39 +02:00
// Lettura idanagrafica cliente e percentuale di sconto/rincaro in base al listino
$rs = $dbo -> fetchArray ( 'SELECT idanagrafica FROM in_interventi WHERE id=' . prepare ( $id_record ));
$idanagrafica = $rs [ 0 ][ 'idanagrafica' ];
2018-11-23 16:08:23 +01:00
$_SESSION [ 'superselect' ][ 'idintervento' ] = get ( 'id_record' );
$_SESSION [ 'superselect' ][ 'dir' ] = 'entrata' ;
$_SESSION [ 'superselect' ][ 'idanagrafica' ] = $idanagrafica ;
2017-08-04 16:28:16 +02:00
if ( empty ( $idriga )) {
$op = 'addarticolo' ;
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
$idarticolo = '' ;
$descrizione = '' ;
$qta = 1 ;
$um = '' ;
2018-09-28 16:43:40 +02:00
$prezzo_acquisto = '0' ;
2017-08-04 16:28:16 +02:00
$prezzo_vendita = '0' ;
$sconto_unitario = 0 ;
$idimpianto = 0 ;
2019-04-15 16:45:54 +02:00
$idiva = setting ( 'Iva predefinita' );
2017-08-04 16:28:16 +02:00
} else {
$op = 'editarticolo' ;
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 *, (SELECT codice FROM mg_articoli WHERE id=mg_articoli_interventi.idarticolo) AS codice_articolo, (SELECT CONCAT(codice, ' - ', descrizione) FROM mg_articoli WHERE id=mg_articoli_interventi.idarticolo) AS descrizione_articolo FROM mg_articoli_interventi WHERE id= " . prepare ( $idriga );
$rsr = $dbo -> fetchArray ( $q );
$idarticolo = $rsr [ 0 ][ 'idarticolo' ];
$codice_articolo = $rsr [ 0 ][ 'codice_articolo' ];
$descrizione = $rsr [ 0 ][ 'descrizione' ];
$qta = $rsr [ 0 ][ 'qta' ];
$um = $rsr [ 0 ][ 'um' ];
2018-03-19 18:11:51 +01:00
$idiva = $rsr [ 0 ][ 'idiva' ];
2018-06-26 14:30:26 +02:00
2017-08-04 16:28:16 +02:00
$prezzo_vendita = $rsr [ 0 ][ 'prezzo_vendita' ];
2018-09-28 16:43:40 +02:00
$prezzo_acquisto = $rsr [ 0 ][ 'prezzo_acquisto' ];
2017-08-04 16:28:16 +02:00
$sconto_unitario = $rsr [ 0 ][ 'sconto_unitario' ];
$tipo_sconto = $rsr [ 0 ][ 'tipo_sconto' ];
$idautomezzo = $rsr [ 0 ][ 'idautomezzo' ];
$idimpianto = $rsr [ 0 ][ 'idimpianto' ];
}
/*
Form di inserimento
*/
echo '
< form id = " add_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 " id = " idautomezzo " name = " idautomezzo " value = " '. $idautomezzo .' " >
< input type = " hidden " name = " idriga " value = " '. $idriga .' " > ' ;
2017-12-20 14:05:14 +01:00
if ( ! empty ( $idarticolo )) {
2017-08-04 16:28:16 +02:00
echo '
< input type = " hidden " id = " idarticolo_originale " name = " idarticolo_originale " value = " '. $idarticolo .' " > ' ;
}
// Articolo
echo '
< div class = " row " >
2017-12-20 14:05:14 +01:00
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Articolo').' " , " name " : " idarticolo " , " required " : 1 , " value " : " '. $idarticolo .' " , " ajax-source " : " articoli " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Descrizione
echo '
< div class = " row " >
< div class = " col-md-12 " >
2017-09-28 10:16:18 +02:00
{[ " type " : " textarea " , " label " : " '.tr('Descrizione').' " , " name " : " descrizione " , " id " : " descrizione_articolo " , " required " : 1 , " value " : '.json_encode($descrizione).' ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-09-28 16:43:40 +02:00
</ div > ' ;
// Impianto
echo '
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " select " , " label " : " '.tr('Impianto su cui installare').' " , " name " : " idimpianto " , " value " : " '. $idimpianto .' " , " ajax-source " : " impianti-intervento " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-09-28 16:43:40 +02:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
// 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 " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
2018-09-28 16:43:40 +02:00
// Iva
2017-08-04 16:28:16 +02:00
echo '
< div class = " col-md-4 " >
2018-09-28 16:43:40 +02:00
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " value " : " '. $idiva .' " , " ajax-source " : " iva " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
2018-06-26 14:30:26 +02:00
2018-09-28 16:43:40 +02:00
// Prezzo di acquisto
2018-03-19 18:11:51 +01:00
echo '
< div class = " row " >
< div class = " col-md-4 " >
2019-04-13 00:09:48 +02:00
{[ " type " : " number " , " label " : " '.tr('Prezzo di acquisto (un.)').' " , " name " : " prezzo_acquisto " , " required " : 1 , " value " : " '. $prezzo_acquisto .' " , " icon-after " : " '.currency().' " ]}
2018-03-19 18:11:51 +01:00
</ div > ' ;
2017-08-04 16:28:16 +02:00
// Prezzo di vendita
echo '
2018-03-19 18:11:51 +01:00
< div class = " col-md-4 " >
2019-04-13 00:09:48 +02:00
{[ " type " : " number " , " label " : " '.tr('Prezzo di vendita (un.)').' " , " name " : " prezzo_vendita " , " required " : 1 , " value " : " '. $prezzo_vendita .' " , " icon-after " : " '.currency().' " ]}
2017-08-04 16:28:16 +02:00
</ div > ' ;
// Sconto
echo '
2018-03-19 18:11:51 +01:00
< 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 > ' ;
// Informazioni aggiuntive
echo '
< div class = " row " id = " prezzi_articolo " >
< div class = " col-md-4 text-center " >
2018-02-03 16:29:53 +01:00
< button type = " button " class = " btn btn-sm btn-info btn-block disabled " onclick = " $ ( \ '#prezzi \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezzi \ ').load( \ ''. $rootdir . " / ajax_complete . php ? module = Articoli & op = getprezzi & idarticolo = ' + $(' #idarticolo option:selected').val() + '&idanagrafica=".$idanagrafica.'\');" disabled>
2017-09-04 12:02:29 +02:00
< i class = " fa fa-search " ></ i > '.tr(' Visualizza ultimi prezzi ( cliente ) ').'
2017-08-04 16:28:16 +02:00
</ button >
< div id = " prezzi " class = " hide " ></ div >
</ div >
< div class = " col-md-4 text-center " >
2018-02-03 16:29:53 +01:00
< button type = " button " class = " btn btn-sm btn-info btn-block disabled " onclick = " $ ( \ '#prezziacquisto \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezziacquisto \ ').load( \ ''. $rootdir . " / ajax_complete . php ? module = Articoli & op = getprezziacquisto & idarticolo = ' + $(' #idarticolo option:selected').val() + '&idanagrafica=".$idanagrafica.'\');" disabled>
2017-09-04 12:02:29 +02:00
< i class = " fa fa-search " ></ i > '.tr(' Visualizza ultimi prezzi ( acquisto ) ').'
2017-08-04 16:28:16 +02:00
</ button >
< div id = " prezziacquisto " class = " hide " ></ div >
</ div >
< div class = " col-md-4 text-center " >
2018-02-03 16:29:53 +01:00
< button type = " button " class = " btn btn-sm btn-info btn-block disabled " onclick = " $ ( \ '#prezzivendita \ ').toggleClass( \ 'hide \ '); $ ( \ '#prezzivendita \ ').load( \ ''. $rootdir . " / ajax_complete . php ? module = Articoli & op = getprezzivendita & idarticolo = ' + $(' #idarticolo option:selected').val() + '&idanagrafica=".$idanagrafica.'\');" disabled>
2017-09-04 12:02:29 +02:00
< i class = " fa fa-search " ></ i > '.tr(' Visualizza ultimi prezzi ( vendita ) ').'
2017-08-04 16:28:16 +02:00
</ button >
< div id = " prezzivendita " class = " hide " ></ div >
</ div >
</ div >
< br > ' ;
echo '
< script >
$ ( document ) . ready ( function () {
$ ( " #idarticolo " ) . on ( " change " , function (){
$ ( " #prezzi_articolo button " ) . attr ( " disabled " , ! $ ( this ) . val ());
if ( $ ( this ) . val ()){
$ ( " #prezzi_articolo button " ) . removeClass ( " disabled " );
session_set ( " superselect,idarticolo " , $ ( this ) . val (), 0 );
$data = $ ( this ) . selectData ();
2017-09-25 10:49:10 +02:00
$ ( " #prezzo_vendita " ) . val ( $data . prezzo_vendita );
2018-09-28 16:43:40 +02:00
$ ( " #prezzo_acquisto " ) . val ( $data . prezzo_acquisto );
2017-09-25 10:49:10 +02:00
$ ( " #descrizione_articolo " ) . val ( $data . descrizione );
2018-09-28 16:43:40 +02:00
$ ( " #idiva " ) . selectSetNew ( $data . idiva_vendita , $data . iva_vendita );
2017-08-04 16:28:16 +02:00
$ ( " #um " ) . selectSetNew ( $data . um , $data . um );
} else {
$ ( " #prezzi_articolo button " ) . addClass ( " disabled " );
}
$ ( " #prezzi " ) . html ( " " );
$ ( " #prezzivendita " ) . html ( " " );
$ ( " #prezziacquisto " ) . html ( " " );
});
});
</ script > ' ;
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2018-05-16 12:50:59 +02:00
< button type = " submit " class = " btn btn-primary pull-right " > '.$button.' </ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;
?>
< script type = " text/javascript " >
$ ( document ) . ready ( function () {
$ ( '#add_form' ) . ajaxForm ({
success : function (){
$ ( '#bs-popup' ) . modal ( 'hide' );
2017-09-13 17:08:27 +02:00
// Ricarico gli articoli
2018-02-18 19:53:23 +01:00
$ ( '#articoli' ) . load ( globals . rootdir + '/modules/interventi/ajax_articoli.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-08-04 16:28:16 +02:00
}
});
});
</ script >