2017-08-04 16:28:16 +02:00
< ? php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager : il software gestionale open source per l ' assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright ( C ) DevCode s . r . l .
2020-09-07 15:04:06 +02:00
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*/
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2018-06-26 09:41:43 +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' ;
}
2018-07-18 14:50:46 +02:00
$info = $dbo -> fetchOne ( 'SELECT * FROM co_documenti WHERE id=' . prepare ( $id_record ));
$numero = ( $info [ 'numero_esterno' ] != '' ) ? $info [ 'numero_esterno' ] : $info [ 'numero' ];
$idanagrafica = $info [ 'idanagrafica' ];
2017-08-04 16:28:16 +02:00
2018-07-09 17:21:25 +02:00
$idconto = ( $dir == 'entrata' ) ? setting ( 'Conto predefinito fatture di vendita' ) : setting ( 'Conto predefinito fatture di acquisto' );
2017-08-04 16:28:16 +02:00
/*
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
2020-09-23 17:53:19 +02:00
< form action = " '.base_path().'/editor.php?id_module='. $id_module .'&id_record='. $id_record .' " method = " post " >
2019-07-24 15:29:03 +02:00
< input type = " hidden " name = " op " value = " add_intervento " >
2017-08-04 16:28:16 +02:00
< 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 ,
2018-07-02 18:01:39 +02:00
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\ ' ), " [ " , `in_statiintervento` . `descrizione` , " ] " ) AS descrizione ,
2020-03-12 23:37:43 +01:00
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 info ,
2018-03-06 09:52:27 +01:00
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).' )
2020-03-12 22:07:28 +01:00
AND in_statiintervento . is_completato = 1 AND in_statiintervento . is_fatturabile = 1
2018-03-06 09:52:27 +01:00
AND in_interventi . id NOT IN ( SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL )
2018-09-03 15:29:55 +02:00
AND in_interventi . id_preventivo IS NULL
2020-02-27 16:55:04 +01:00
AND in_interventi . id_contratto IS NULL
2018-08-31 11:39:38 +02:00
AND NOT in_interventi . id IN ( SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL ) ' );
2017-09-06 15:29:51 +02:00
foreach ( $rs as $key => $value ) {
2019-07-12 17:35:14 +02:00
$intervento = \Modules\Interventi\Intervento :: find ( $value [ 'id' ]);
$prezzo = $intervento -> totale ;
2019-07-08 17:11:48 +02:00
$rs [ $key ][ 'prezzo' ] = Translator :: numberToLocale ( $prezzo );
2019-06-29 11:01:26 +02:00
$rs [ $key ][ 'descrizione_intervento' ] = strip_tags ( $rs [ $key ][ 'descrizione_intervento' ]);
2017-09-06 15:29:51 +02:00
}
2017-08-04 16:28:16 +02:00
// Intervento
echo '
< div class = " row " >
< div class = " col-md-6 " >
2020-03-12 23:37:43 +01:00
{[ " type " : " select " , " label " : " '.tr('Intervento').' " , " name " : " idintervento " , " required " : 1 , " values " : '.json_encode($rs).' , " extra " : " onchange= \" $data = $ (this).selectData(); $ ( \ '#descrizione \ ').val( $data .info); if( $ ( \ '#copia_descrizione \ ').is( \ ':checked \ ')) { $ ( \ '#descrizione \ ').val( $data .info + $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 " >
2020-07-31 11:56:48 +02:00
{[ " type " : " checkbox " , " label " : " '.tr('Copia descrizione').' " , " name " : " copia_descrizione " , " placeholder " : " '.tr('Copia anche 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 > ' ;
2018-09-26 15:37:46 +02:00
$options = [
'action' => 'add' ,
'hide_conto' => true ,
'dir' => $dir ,
];
// Leggo la ritenuta d'acconto predefinita per l'anagrafica e se non c'è leggo quella predefinita generica
$ritenuta_acconto = $dbo -> fetchOne ( 'SELECT id_ritenuta_acconto_' . ( $dir == 'uscita' ? 'acquisti' : 'vendite' ) . ' AS id_ritenuta_acconto FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $idanagrafica ));
$options [ 'id_ritenuta_acconto_predefined' ] = $ritenuta_acconto [ 'id_ritenuta_acconto' ];
echo App :: internalLoad ( 'conti.php' , [], $options );
2017-08-04 16:28:16 +02:00
// Leggo l'iva predefinita dall'articolo e se non c'è leggo quella predefinita generica
2018-07-08 18:11:17 +02:00
$idiva = $idiva ? : setting ( 'Iva predefinita' );
2017-08-04 16:28:16 +02:00
// Iva
echo '
< div class = " row " >
< div class = " col-md-6 " >
2020-02-27 17:37:59 +01:00
{[ " type " : " select " , " label " : " '.tr('Iva').' " , " name " : " idiva " , " required " : 1 , " value " : " '. $idiva .' " , " ajax-source " : " iva " , " help " : " '.tr( " L 'aliquota IVA selezionata sovrascrive il valore predditivo presentato in Attività, modificando di conseguenza le sessioni di lavoro dei tecnici").' . '.tr(' Righe generiche , articoli e sconti non verranno influenzati ').' . " ]}
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 " >
2019-04-13 00:09:48 +02:00
{[ " type " : " number " , " label " : " '.tr('Costo unitario').' " , " name " : " prezzo " , " required " : 1 , " icon-after " : " '.currency().' " , " 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 '
2019-07-26 17:40:52 +02:00
< script > $ ( document ) . ready ( init ) </ script > ' ;