2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2017-09-06 15:29:51 +02:00
include_once $docroot . '/modules/interventi/modutil.php' ;
2017-08-04 16:28:16 +02:00
2017-09-22 15:19:59 +02:00
$module = Modules :: get ( $id_module );
2017-08-04 16:28:16 +02:00
if ( $module [ 'name' ] == 'Fatture di vendita' ) {
$dir = 'entrata' ;
$conti = 'conti-vendite' ;
} else {
$dir = 'uscita' ;
$conti = 'conti-acquisti' ;
}
$record = $dbo -> fetchArray ( 'SELECT * FROM co_documenti WHERE id=' . prepare ( $id_record ));
$numero = ( $record [ 0 ][ 'numero_esterno' ] != '' ) ? $record [ 0 ][ 'numero_esterno' ] : $record [ 0 ][ 'numero' ];
$idconto = $record [ 0 ][ 'idconto' ];
$idanagrafica = $record [ 0 ][ 'idanagrafica' ];
/*
Form di inserimento riga documento
*/
echo '
2017-09-10 14:35:41 +02:00
< p > '.tr(' Documento numero _NUM_ ' , [
'_NUM_' => $numero ,
]) . ' </ p >
2017-08-04 16:28:16 +02:00
< form action = " '. $rootdir .'/editor.php?id_module='. $id_module .'&id_record='. $id_record .' " method = " post " >
< input type = " hidden " name = " op " value = " addintervento " >
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " dir " value = " '. $dir .' " > ' ;
2018-03-06 09:52:27 +01:00
$rs = $dbo -> fetchArray ( ' SELECT
in_interventi . id ,
CONCAT ( \ ' Intervento numero \ ' , in_interventi . codice , \ ' del \ ' , DATE_FORMAT ( IFNULL (( SELECT MIN ( orario_inizio ) FROM in_interventi_tecnici WHERE in_interventi_tecnici . idintervento = in_interventi . id ), in_interventi . data_richiesta ), \ ' % d /% m /% Y\ ' )) AS descrizione ,
CONCAT ( \ ' \n\ ' , in_interventi . descrizione ) AS descrizione_intervento ,
IF ( idclientefinale = '.prepare($idanagrafica).' , \ ' Interventi conto terzi\ ' , \ ' Interventi diretti\ ' ) AS `optgroup`
FROM
in_interventi INNER JOIN in_statiintervento ON in_interventi . idstatointervento = in_statiintervento . idstatointervento
WHERE
( in_interventi . idanagrafica = '.prepare($idanagrafica).' OR in_interventi . idclientefinale = '.prepare($idanagrafica).' )
AND in_statiintervento . completato = 1
AND in_interventi . id NOT IN ( SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL )
AND NOT in_interventi . id IN ( SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL )
AND NOT in_interventi . id IN ( SELECT idintervento FROM co_righe_contratti WHERE idintervento IS NOT NULL ) ' );
2017-09-06 15:29:51 +02:00
foreach ( $rs as $key => $value ) {
2017-09-11 13:08:50 +02:00
$rs [ $key ][ 'prezzo' ] = get_costi_intervento ( $value [ 'id' ])[ 'totale' ];
2017-09-06 15:29:51 +02:00
}
2017-08-04 16:28:16 +02:00
// Intervento
echo '
< div class = " row " >
2018-05-11 15:56:08 +02:00
2017-08-04 16:28:16 +02:00
< div class = " col-md-6 " >
2018-02-16 11:56:08 +01:00
{[ " type " : " select " , " label " : " '.tr('Intervento').' " , " name " : " idintervento " , " required " : 1 , " values " : '.json_encode($rs).' , " extra " : " onchange= \" $data = $ (this).selectData(); $ ( \ '#descrizione \ ').val( $data .descrizione); if( $ ( \ '#copia_descrizione \ ').is( \ ':checked \ ')) { $ ( \ '#descrizione \ ').val( $data .descrizione + $data .descrizione_intervento); }; $ ( \ '#prezzo \ ').val( $data .prezzo); \" " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-05-11 15:56:08 +02:00
2018-02-16 10:08:30 +01:00
< div class = " col-md-6 " >
2018-05-11 15:56:08 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Copia descrizione').' " , " name " : " copia_descrizione " , " required " : 0 , " values " : " " , " help " : " " , " placeholder " : " '.tr('In fase di selezione copia la descrizione dell \ 'intervento').'. " ]}
2018-02-16 10:08:30 +01:00
</ div >
2017-08-04 16:28:16 +02:00
</ 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 " , " required " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Leggo l'iva predefinita dall'articolo e se non c'è leggo quella predefinita generica
$idiva = $idiva ? : get_var ( 'Iva predefinita' );
// Iva
echo '
< div class = " row " >
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " 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 > ' ;
echo '
< div class = " col-md-6 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " '.tr('Conto').' " , " name " : " idconto " , " required " : 1 , " value " : " '. $idconto .' " , " ajax-source " : " '. $conti .' " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
// Costo unitario
echo '
< div class = " row " >
2017-09-11 11:28:39 +02:00
< div class = " col-md-12 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " number " , " label " : " '.tr('Costo unitario').' " , " name " : " prezzo " , " required " : 1 , " icon-after " : " € " , " disabled " : 1 ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div > ' ;
echo '
<!-- PULSANTI -->
< div class = " row " >
< div class = " col-md-12 text-right " >
2017-09-04 12:02:29 +02:00
< button type = " submit " class = " btn btn-primary pull-right " >< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').' </ button >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form > ' ;
echo '
< script src = " '. $rootdir .'/lib/init.js " ></ script > ' ;