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 />.
*/
2019-07-24 12:42:45 +02:00
2017-08-04 16:28:16 +02:00
include_once __DIR__ . '/../../core.php' ;
2024-03-05 16:01:45 +01:00
use Models\Module ;
2024-03-28 11:39:26 +01:00
use Modules\Ordini\Stato ;
2017-08-04 16:28:16 +02:00
2019-07-24 12:42:45 +02:00
$block_edit = $record [ 'flag_completato' ];
2024-03-05 16:01:45 +01:00
$module = Module :: find ( $id_module );
2019-07-24 12:42:45 +02:00
2024-04-18 17:44:05 +02:00
if ( $module -> getTranslation ( 'title' , Models\Locale :: getPredefined () -> id ) == 'Ordini cliente' ) {
2017-08-04 16:28:16 +02:00
$dir = 'entrata' ;
} else {
$dir = 'uscita' ;
}
2024-02-23 14:40:08 +01:00
$righe = $ordine -> getRighe ();
$righe_vuote = false ;
foreach ( $righe as $riga ) {
if ( $riga -> qta == 0 ) {
$righe_vuote = true ;
}
}
if ( $righe_vuote ) {
2024-03-22 15:52:24 +01:00
echo '
2024-02-23 14:40:08 +01:00
< div class = " alert alert-warning " id = " righe-vuote " >
2024-03-22 15:52:24 +01:00
< i class = " fa fa-warning " ></ i > '.tr(' Nel documento sono presenti delle righe con quantità a 0. ').' </ b >
2024-02-23 14:40:08 +01:00
</ div > ' ;
}
2024-05-24 09:17:38 +02:00
echo '
2024-05-23 12:25:09 +02:00
< form action = " " method = " post " id = " edit-form " >
2017-08-04 16:28:16 +02:00
< input type = " hidden " name = " backto " value = " record-edit " >
< input type = " hidden " name = " op " value = " update " >
2024-05-23 12:37:47 +02:00
< input type = " hidden " name = " id_record " value = " '. $id_record .' " >
2024-05-23 12:25:09 +02:00
< div class = " row " >
< div class = " col-md-2 offset-md-10 " > ' ;
2024-05-24 09:17:38 +02:00
if ( setting ( 'Cambia automaticamente stato ordini fatturati' )) {
2024-06-11 16:58:27 +02:00
$id_stato_evaso = Stato :: where ( 'name' , 'Evaso' ) -> first () -> id ;
$id_stato_parz_evaso = Stato :: where ( 'name' , 'Parzialmente evaso' ) -> first () -> id ;
$id_stato_fatt = Stato :: where ( 'name' , 'Fatturato' ) -> first () -> id ;
$id_stato_parz_fatt = Stato :: where ( 'name' , 'Parzialmente fatturato' ) -> first () -> id ;
$id_stato_accettato = Stato :: where ( 'name' , 'Accettato' ) -> first () -> id ;
2024-05-24 09:17:38 +02:00
if ( $ordine -> stato -> id == $id_stato_fatt || $ordine -> stato -> id == $id_stato_parz_fatt || $ordine -> stato -> id == $id_stato_evaso || $ordine -> stato -> id == $id_stato_parz_evaso ) {
?>
2024-05-23 12:25:09 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoordine " , " required " : 1 , " values " : " query=SELECT `or_statiordine`.*, `or_statiordine_lang`.`title` as descrizione, `colore` AS _bgcolor_ FROM `or_statiordine` LEFT JOIN `or_statiordine_lang` ON (`or_statiordine_lang`.`id_record` = `or_statiordine`.`id` AND `or_statiordine_lang`.`id_lang` = <?php echo prepare(Models \ Locale::getDefault()->id); ?>) ORDER BY `title` " , " value " : " $idstatoordine $ " , " extra " : " readonly " , " class " : " unblockable " ]}
< ? php
2024-05-24 09:17:38 +02:00
} else {
?>
2024-05-23 12:25:09 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoordine " , " required " : 1 , " values " : " query=SELECT `or_statiordine`.*, `or_statiordine_lang`.`title` as descrizione, `colore` AS _bgcolor_ FROM `or_statiordine` LEFT JOIN `or_statiordine_lang` ON (`or_statiordine_lang`.`id_record` = `or_statiordine`.`id` AND `or_statiordine_lang`.`id_lang` = <?php echo prepare(Models \ Locale::getDefault()->id); ?>) WHERE (`is_fatturabile` = 0 AND `or_statiordine`.`id` != <?php echo $id_stato_fatt ; ?> || `or_statiordine`.`id` = <?php echo $id_stato_accettato ; ?>) ORDER BY `title` " , " value " : " $idstatoordine $ " , " class " : " unblockable " ]}
< ? php
2024-05-24 09:17:38 +02:00
}
} else {
?>
2024-05-23 12:25:09 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoordine " , " required " : 1 , " values " : " query=SELECT `or_statiordine`.*, `colore` AS _bgcolor_, `or_statiordine_lang`.`title` as descrizione FROM `or_statiordine` LEFT JOIN `or_statiordine_lang` ON (`or_statiordine_lang`.`id_record` = `or_statiordine`.`id` AND `or_statiordine_lang`.`id_lang` = <?php echo prepare(Models \ Locale::getDefault()->id); ?>) ORDER BY `title` " , " value " : " $idstatoordine $ " , " class " : " unblockable " ]}
< ? php
2024-05-24 09:17:38 +02:00
}
2024-05-23 12:25:09 +02:00
2024-05-24 09:17:38 +02:00
echo '
2024-05-23 12:25:09 +02:00
</ div >
</ div >
<!-- DATI INTESTAZIONE -->
2024-08-27 14:12:30 +02:00
< div class = " card card-primary collapsable " >
2024-05-23 12:25:09 +02:00
< div class = " card-header with-border " >
2024-08-27 14:12:30 +02:00
< h3 class = " card-title " > '.($dir == ' entrata ' ? tr(' Dati cliente ') : tr(' Dati fornitore ')).' </ h3 >
2024-05-23 12:25:09 +02:00
< div class = " card-tools pull-right " >
2024-05-23 17:51:21 +02:00
< button type = " button " class = " btn btn-tool " data - card - widget = " collapse " >
2024-08-27 14:12:30 +02:00
< i class = " fa fa-minus " ></ i >
2024-05-23 12:25:09 +02:00
</ button >
</ div >
</ div >
< div class = " card-body " >
2024-10-25 09:42:39 +02:00
<!-- RIGA 1 -->
< div class = " row " >
< div class = " col-md-3 " > ' ;
2024-05-24 09:17:38 +02:00
echo Modules :: link ( 'Anagrafiche' , $record [ 'idanagrafica' ], null , null , 'class="pull-right"' );
2024-05-23 12:25:09 +02:00
if ( $dir == 'entrata' ) {
?>
2024-10-25 09:42:39 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Cliente'); ?> " , " name " : " idanagrafica " , " required " : 1 , " value " : " $idanagrafica $ " , " ajax-source " : " clienti " ]}
2024-05-23 12:25:09 +02:00
< ? php
} else {
?>
2024-10-25 09:42:39 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Fornitore'); ?> " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " fornitori " , " value " : " $idanagrafica $ " ]}
2024-05-23 12:25:09 +02:00
< ? php
}
2024-05-24 09:17:38 +02:00
echo '
2024-10-25 09:42:39 +02:00
</ div >
2024-05-23 12:25:09 +02:00
2024-10-25 09:42:39 +02:00
< div class = " col-md-3 " > ' ;
2024-05-24 09:17:38 +02:00
if ( ! empty ( $record [ 'idreferente' ])) {
echo Plugins :: link ( 'Referenti' , $record [ 'idanagrafica' ], null , null , 'class="pull-right"' );
}
echo '
2024-10-25 09:42:39 +02:00
{[ " type " : " select " , " label " : " '.tr('Referente').' " , " name " : " idreferente " , " value " : " $idreferente $ " , " ajax-source " : " referenti " , " select-options " : { " idanagrafica " : '.$record[' idanagrafica '].' , " idsede_destinazione " : '.$record[' idsede '].' } ]}
</ div >
2024-05-23 12:25:09 +02:00
2024-10-25 09:42:39 +02:00
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " '.tr('Sede').' " , " name " : " idsede " , " required " : 1 , " ajax-source " : " sedi " , " select-options " : { " idanagrafica " : '.$record[' idanagrafica '].' }, " value " : " '. $record['idsede'] .' " ]}
</ div > ' ;
2024-05-23 12:25:09 +02:00
2024-05-24 09:17:38 +02:00
if ( $dir == 'entrata' ) {
echo '
2024-10-25 09:42:39 +02:00
< div class = " col-md-3 " > ' ;
2024-05-24 09:17:38 +02:00
if ( $record [ 'idagente' ] != 0 ) {
echo Modules :: link ( 'Anagrafiche' , $record [ 'idagente' ], null , null , 'class="pull-right"' );
}
echo '
2024-10-25 09:42:39 +02:00
{[ " type " : " select " , " label " : " '.tr('Agente').' " , " name " : " idagente " , " ajax-source " : " agenti " , " select-options " : { " idanagrafica " : '.$record[' idanagrafica '].' }, " value " : " $idagente $ " ]}
</ div > ' ;
2024-05-24 09:17:38 +02:00
}
echo '
2024-05-23 12:25:09 +02:00
</ div >
</ div >
</ div > ' ;
?>
2017-08-04 16:28:16 +02:00
<!-- INTESTAZIONE -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " >< ? php echo tr ( 'Intestazione' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2017-08-04 16:28:16 +02:00
< div class = " row " >
2024-11-08 16:30:19 +01:00
< div class = " col-md-3 " < ? php echo ( $dir == 'entrata' ) ? 'hidden' : '' ; ?> >
2019-07-24 12:42:45 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Numero ordine'); ?> " , " name " : " numero " , " required " : 1 , " class " : " text-center " , " value " : " $numero $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2024-11-08 16:30:19 +01:00
< div class = " col-md-3 " >
2020-07-20 14:40:11 +02:00
{[ " type " : " text " , " label " : " <?php echo ( $dir == 'entrata') ? tr('Numero ordine') : tr('Numero ordine fornitore'); ?> " , " name " : " numero_esterno " , " class " : " text-center " , " value " : " $numero_esterno $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2024-11-08 16:30:19 +01:00
< div class = " col-md-3 " >
2019-07-24 12:42:45 +02:00
{[ " type " : " date " , " label " : " <?php echo tr('Data'); ?> " , " name " : " data " , " required " : 1 , " value " : " $data $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2024-11-08 16:30:19 +01:00
< div class = " col-md-3 " >
2024-05-23 12:25:09 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Pagamento'); ?> " , " name " : " idpagamento " , " required " : 0 , " ajax-source " : " pagamenti " , " value " : " $idpagamento $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2024-11-08 16:30:19 +01:00
</ div >
2018-01-15 20:28:36 +01:00
2024-11-08 16:30:19 +01:00
< div class = " row " >
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " <?php echo tr('Tipo di spedizione'); ?> " , " name " : " idspedizione " , " placeholder " : " - " , " values " : " query=SELECT `dt_spedizione`.`id`, `dt_spedizione_lang`.`title` as `descrizione`, `esterno` FROM `dt_spedizione` LEFT JOIN `dt_spedizione_lang` ON (`dt_spedizione_lang`.`id_record` = `dt_spedizione`.`id` AND `dt_spedizione_lang`.`id_lang` = <?php echo prepare(Models \ Locale::getDefault()->id); ?>) ORDER BY `title` ASC " , " value " : " $idspedizione $ " ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " <?php echo tr('Porto'); ?> " , " name " : " idporto " , " placeholder " : " - " , " help " : " <?php echo tr('<ul><li>Franco: pagamento del trasporto a carico del mittente</li> <li>Assegnato: pagamento del trasporto a carico del destinatario</li> </ul>'); ?> " , " values " : " query=SELECT `dt_porto`.`id`, `dt_porto_lang`.`title` as descrizione FROM `dt_porto` LEFT JOIN `dt_porto_lang` ON (`dt_porto`.`id` = `dt_porto_lang`.`id_record` AND `dt_porto_lang`.`id_lang` = <?php echo prepare(Models \ Locale::getDefault()->id); ?>) ORDER BY `title` ASC " , " value " : " $idporto $ " ]}
</ div >
< div class = " col-md-3 " >
< ? php
if ( ! empty ( $record [ 'idvettore' ])) {
echo Modules :: link ( 'Anagrafiche' , $record [ 'idvettore' ], null , null , 'class="pull-right"' );
}
$esterno = $dbo -> selectOne ( 'dt_spedizione' , 'esterno' , [
'id' => $record [ 'idspedizione' ],
])[ 'esterno' ];
?>
{[ " type " : " select " , " label " : " <?php echo tr('Vettore'); ?> " , " name " : " idvettore " , " ajax-source " : " vettori " , " value " : " $idvettore $ " , " disabled " : < ? php echo empty ( $esterno ) ? 1 : 0 ; ?> , "required": <?php echo !empty($esterno) ?: 0; ?>, "icon-after": "add|<?php echo Module::where('name', 'Anagrafiche')->first()->id; ?>|tipoanagrafica=Vettore&readonly_tipo=1|btn_idvettore|<?php echo ($esterno and (intval(!$record['flag_completato']) || empty($record['idvettore']))) ? '' : 'disabled'; ?>", "class": "<?php echo empty($record['idvettore']) ? 'unblockable' : ''; ?>" ]}
</ div >
< div class = " col-md-3 " >
2024-05-23 12:25:09 +02:00
{[ " type " : " number " , " label " : " <?php echo 'Sconto in fattura'; ?> " , " name " : " sconto_finale " , " value " : " <?php echo $ordine->sconto_finale_percentuale ?: $ordine->sconto_finale ; ?> " , " icon-after " : " choice|untprc|<?php echo empty( $ordine->sconto_finale ) ? 'PRC' : 'UNT'; ?> " , " help " : " <?php echo tr('Sconto in fattura, utilizzabile per applicare sconti sul netto a pagare del documento'); ?>. " ]}
2021-02-11 15:05:29 +01:00
</ div >
2024-05-23 12:25:09 +02:00
</ div >
2024-11-08 16:30:19 +01:00
< script >
$ ( " #idspedizione " ) . change ( function () {
if ( $ ( this ) . val ()){
if ( ! $ ( this ) . selectData () . esterno ) {
$ ( " #idvettore " ) . attr ( " required " , false );
input ( " idvettore " ) . disable ();
$ ( " label[for=idvettore] " ) . text ( " <?php echo tr('Vettore'); ?> " );
$ ( " #idvettore " ) . selectReset ( " <?php echo tr( " Seleziona un\ ' opzione " ); ?> " );
$ ( " .btn_idvettore " ) . prop ( " disabled " , true );
$ ( " .btn_idvettore " ) . addClass ( " disabled " );
} else {
$ ( " #idvettore " ) . attr ( " required " , true );
input ( " idvettore " ) . enable ();
$ ( " label[for=idvettore] " ) . text ( " <?php echo tr('Vettore'); ?>* " );
$ ( " .btn_idvettore " ) . prop ( " disabled " , false );
$ ( " .btn_idvettore " ) . removeClass ( " disabled " );
}
} else {
$ ( " #idvettore " ) . attr ( " required " , false );
input ( " idvettore " ) . disable ();
$ ( " label[for=idvettore] " ) . text ( " <?php echo tr('Vettore'); ?> " );
$ ( " #idvettore " ) . selectReset ( " <?php echo tr( " Seleziona un\ ' opzione " ); ?> " );
$ ( " .btn_idvettore " ) . prop ( " disabled " , true );
$ ( " .btn_idvettore " ) . addClass ( " disabled " );
}
});
</ script >
2024-05-23 12:25:09 +02:00
< ? php
2021-04-12 15:51:27 +02:00
2024-01-15 15:30:45 +01:00
if ( $dir == 'entrata' ) {
?>
2021-04-07 09:33:55 +02:00
< div class = " row " >
2024-05-23 12:25:09 +02:00
< div class = " col-md-2 " >
2021-02-22 14:48:50 +01:00
{[ " type " : " text " , " label " : " <?php echo tr('Numero ordine cliente'); ?> " , " name " : " numero_cliente " , " required " : 0 , " value " : " <?php echo $record['numero_cliente'] ; ?> " , " help " : " <?php echo tr('<span>Obbligatorio per valorizzare CIG/CUP. È possible inserire: </span><ul><li>N. determina</li><li>RDO</li><li>Ordine MEPA</li></ul>'); ?> " ]}
2019-09-12 17:13:53 +02:00
</ div >
2024-05-23 12:25:09 +02:00
< div class = " col-md-2 " >
2019-09-12 17:13:53 +02:00
{[ " type " : " date " , " label " : " <?php echo tr('Data ordine cliente'); ?> " , " name " : " data_cliente " , " value " : " <?php echo $record['data_cliente'] ; ?> " ]}
</ div >
2024-05-23 12:25:09 +02:00
2021-04-06 15:10:55 +02:00
</ div >
2021-04-07 09:33:55 +02:00
< ? php
2024-01-15 15:30:45 +01:00
}
?>
2022-10-27 15:08:33 +02:00
< div class = " row " >
< div class = " col-md-12 " >
2023-08-04 14:54:28 +02:00
< ? php echo input ([
2024-03-22 15:52:24 +01:00
'type' => 'ckeditor' ,
2024-07-02 15:13:14 +02:00
'use_full_ckeditor' => 0 ,
2024-03-22 15:52:24 +01:00
'label' => tr ( 'Condizioni generali di fornitura' ),
'name' => 'condizioni_fornitura' ,
'value' => $record [ 'condizioni_fornitura' ],
]);
2024-01-15 15:30:45 +01:00
?>
2023-02-24 13:36:37 +01:00
</ div >
2022-10-27 15:08:33 +02:00
</ div >
2021-04-07 09:33:55 +02:00
2017-08-04 16:28:16 +02:00
< div class = " row " >
2023-04-13 17:28:41 +02:00
< div class = " col-md-6 " >
2019-07-24 12:42:45 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note'); ?> " , " name " : " note " , " value " : " $note $ " ]}
2018-05-22 14:41:42 +02:00
</ div >
2023-04-13 17:28:41 +02:00
< div class = " col-md-6 " >
2020-07-17 00:22:20 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note interne'); ?> " , " name " : " note_aggiuntive " , " value " : " $note_aggiuntive $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
2019-10-14 18:30:34 +02:00
< ? php
2021-02-22 14:48:50 +01:00
if ( ! empty ( $record [ 'codice_commessa' ]) || ! empty ( $record [ 'num_item' ]) || ! empty ( $record [ 'codice_cig' ]) || ! empty ( $record [ 'codice_cup' ])) {
2019-10-14 18:30:34 +02:00
$collapsed = 'in' ;
2019-10-18 15:28:44 +02:00
} else {
2019-10-14 18:30:34 +02:00
$collapsed = '' ;
}
2024-01-15 15:30:45 +01:00
?>
2018-11-23 12:43:45 +01:00
2019-10-14 18:30:34 +02:00
<!-- Fatturazione Elettronica PA -->
2024-06-13 09:46:21 +02:00
< div class = " card card-primary collapsed-card <?php echo ( $record['tipo_anagrafica'] == 'Ente pubblico' || $record['tipo_anagrafica'] == 'Azienda') ? 'show' : 'hide'; ?> " >
< div class = " card-header " >
< h4 class = " card-title " >
< ? php echo tr ( 'Dati appalto' ); ?>
</ h4 >
< div class = " card-tools pull-right " >
< button type = " button " class = " btn btn-tool " data - card - widget = " collapse " >
< i class = " fa fa-plus " ></ i >
</ button >
2019-10-14 18:30:34 +02:00
</ div >
2024-06-13 09:46:21 +02:00
</ div >
< div class = " card-body " >
< div class = " row " >
< div class = " col-md-3 " >
{[ " type " : " text " , " label " : " <?php echo tr('Codice Commessa'); ?> " , " name " : " codice_commessa " , " required " : 0 , " value " : " $codice_commessa $ " , " maxlength " : 100 ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " text " , " label " : " <?php echo tr('Numero Riga'); ?> " , " name " : " num_item " , " required " : 0 , " value " : " $num_item $ " , " maxlength " : 15 ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " text " , " label " : " <?php echo tr('Codice CIG'); ?> " , " name " : " codice_cig " , " required " : 0 , " value " : " $codice_cig $ " , " maxlength " : 15 ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " text " , " label " : " <?php echo tr('Codice CUP'); ?> " , " name " : " codice_cup " , " required " : 0 , " value " : " $codice_cup $ " , " maxlength " : 15 ]}
2018-11-23 12:43:45 +01:00
</ div >
</ div >
</ div >
</ div >
</ form >
2017-08-04 16:28:16 +02:00
2020-07-08 09:15:14 +02:00
< ? php
echo '
2017-08-04 16:28:16 +02:00
<!-- RIGHE -->
2024-05-16 18:02:50 +02:00
< div class = " card card-primary " >
2024-05-17 12:11:00 +02:00
< div class = " card-header " >
2024-05-16 18:02:50 +02:00
< h3 class = " card-title " > '.tr(' Righe ').' </ h3 >
2017-08-04 16:28:16 +02:00
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " > ' ;
2018-02-19 11:50:42 +01:00
2019-07-24 12:42:45 +02:00
if ( ! $block_edit ) {
2024-02-26 10:50:43 +01:00
$prev_query = ' SELECT
COUNT ( * ) AS tot
FROM
`co_preventivi`
INNER JOIN `co_statipreventivi` ON `co_statipreventivi` . `id` = `co_preventivi` . `idstato`
INNER JOIN `co_righe_preventivi` ON `co_preventivi` . `id` = `co_righe_preventivi` . `idpreventivo`
WHERE
`idanagrafica` = '.prepare($record[' idanagrafica ']).' AND `co_statipreventivi` . `is_fatturabile` = 1 AND `default_revision` = 1 AND ( `co_righe_preventivi` . `qta` - `co_righe_preventivi` . `qta_evasa` > 0 ) ' ;
2023-08-04 14:54:28 +02:00
$preventivi = $dbo -> fetchArray ( $prev_query )[ 0 ][ 'tot' ];
echo '
2023-02-17 10:59:50 +01:00
< div class = " clearfix " ></ div > ' ;
2023-08-04 14:54:28 +02:00
// Form di inserimento riga documento
echo '
2023-02-17 10:59:50 +01:00
< form id = " link_form " action = " " method = " post " >
< input type = " hidden " name = " op " value = " add_articolo " >
< input type = " hidden " name = " backto " value = " record-edit " >
< div class = " row " >
2023-05-24 17:15:29 +02:00
< div class = " col-md-3 " >
2023-02-17 10:59:50 +01:00
{[ " type " : " text " , " label " : " '.tr('Aggiungi un articolo tramite barcode').' " , " name " : " barcode " , " extra " : " autocomplete= \" off \" " , " icon-before " : " <i class= \" fa fa-barcode \" ></i> " , " required " : 0 ]}
</ div >
2017-08-04 16:28:16 +02:00
2023-05-24 17:15:29 +02:00
< div class = " col-md-3 " >
2024-06-11 16:58:27 +02:00
{[ " type " : " select " , " label " : " '.tr('Articolo').' " , " name " : " id_articolo " , " value " : " " , " ajax-source " : " articoli " , " select-options " : { " permetti_movimento_a_zero " : 1 }, " icon-after " : " add|'.Module::where('name', 'Articoli')->first()->id.' " ]}
2023-02-17 10:59:50 +01:00
</ div >
< div class = " col-md-4 " style = " margin-top: 25px " >
< button title = " '.tr('Aggiungi articolo alla vendita').' " class = " btn btn-primary tip " type = " button " onclick = " salvaArticolo() " >
< i class = " fa fa-plus " ></ i > '.tr(' Aggiungi ').'
</ button >
< a class = " btn btn-primary " onclick = " gestioneRiga(this) " data - title = " '.tr('Aggiungi riga').' " >
< i class = " fa fa-plus " ></ i > '.tr(' Riga ').'
</ a >
2024-05-16 18:02:50 +02:00
< div class = " btn-group tip " data - card - widget = " tooltip " >
2024-05-22 17:16:50 +02:00
< button type = " button " class = " btn btn-primary dropdown-toggle " data - toggle = " dropdown " aria - haspopup = " true " aria - expanded = " true " >
2023-02-17 10:59:50 +01:00
< i class = " fa fa-list " ></ i > '.tr(' Altro ').'
< span class = " caret " ></ span >
</ button >
< ul class = " dropdown-menu dropdown-menu-right " >
2024-05-22 12:00:54 +02:00
< a class = " dropdown-item " style = " cursor:pointer " onclick = " gestioneDescrizione(this) " data - title = " '.tr('Aggiungi descrizione').' " >
< i class = " fa fa-plus " ></ i > '.tr(' Descrizione ').'
</ a >
< a class = " dropdown-item " style = " cursor:pointer " onclick = " gestioneSconto(this) " data - title = " '.tr('Aggiungi sconto/maggiorazione').' " >
< i class = " fa fa-plus " ></ i > '.tr(' Sconto / maggiorazione ').'
</ a > ' ;
2023-08-04 14:54:28 +02:00
if ( $dir == 'entrata' ) {
echo '
2024-05-22 12:00:54 +02:00
< a class = " '.(!empty( $preventivi ) ? '' : ' disabled').' dropdown-item " style = " cursor:pointer " data - href = " '. $structure->fileurl ('add_preventivo.php').'?id_module='. $id_module .'&id_record='. $id_record .' " data - card - widget = " modal " data - title = " '.tr('Aggiungi Preventivo').' " onclick = " saveForm() " >
< i class = " fa fa-plus " ></ i > '.tr(' Preventivo ').'
</ a > ' ;
2023-08-04 14:54:28 +02:00
}
echo '
2023-02-17 10:59:50 +01:00
</ ul >
</ div > ' ;
2023-08-04 14:54:28 +02:00
if ( $dir == 'entrata' ) {
echo '
2024-05-16 18:02:50 +02:00
< div class = " float-right d-none d-sm-inline " >
< a class = " btn btn-info " data - href = " '. $structure->fileurl ('quantita_impegnate.php').'?id_module='. $id_module .'&id_record='. $id_record .' " data - card - widget = " tooltip " data - title = " '.tr('Controllo sulle quantità impegnate').' " onclick = " saveForm() " >
2023-12-06 13:20:55 +01:00
< i class = " fa fa-question-circle " ></ i > '.tr(' Disponibilità ').'
2023-02-17 10:59:50 +01:00
</ a >
</ div > ' ;
2023-08-04 14:54:28 +02:00
}
echo '
2023-02-17 10:59:50 +01:00
</ div >
2023-05-24 17:15:29 +02:00
< div class = " col-md-2 " >
{[ " type " : " select " , " label " : " '.tr('Ordinamento').' " , " name " : " ordinamento " , " class " : " no-search " , " value " : " '.( $_SESSION['module_'.$id_module] ['order_row_desc'] ? 'desc' : 'manuale').' " , " values " : " list= \" desc \" : \" '.tr('Ultima riga inserita').' \" , \" manuale \" : \" '.tr('Manuale').' \" " ]}
</ div >
2023-02-17 10:59:50 +01:00
</ div >
</ form > ' ;
2020-07-08 09:15:14 +02:00
}
2017-08-04 16:28:16 +02:00
2020-07-08 09:15:14 +02:00
echo '
2017-08-04 16:28:16 +02:00
< div class = " row " >
2020-09-14 10:49:23 +02:00
< div class = " col-md-12 " id = " righe " ></ div >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
2018-09-28 16:17:10 +02:00
{( " name " : " filelist_and_upload " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
2020-08-03 12:08:52 +02:00
{( " name " : " log_email " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
< script >
2023-03-30 16:36:24 +02:00
async function saveForm () {
// Salvataggio via AJAX
await salvaForm ( " #edit-form " );
2020-08-03 12:08:52 +02:00
}
function gestioneSconto ( button ) {
2024-04-12 10:54:05 +02:00
gestioneRiga ( button , " is_sconto=1 " );
2020-08-03 12:08:52 +02:00
}
function gestioneDescrizione ( button ) {
2024-04-12 10:54:05 +02:00
gestioneRiga ( button , " is_descrizione=1 " );
2020-08-03 12:08:52 +02:00
}
async function gestioneRiga ( button , options ) {
// Salvataggio via AJAX
2021-03-29 18:31:23 +02:00
await salvaForm ( " #edit-form " , {}, button );
// Lettura titolo e chiusura tooltip
2023-02-17 10:59:50 +01:00
let title = $ ( button ) . attr ( " data-title " );
2020-08-03 12:08:52 +02:00
// Apertura modal
2024-04-12 10:54:05 +02:00
options = options ? options : " is_riga=1 " ;
2021-03-29 18:31:23 +02:00
openModal ( title , " '. $structure->fileurl ('row-add.php').'?id_module='. $id_module .'&id_record='. $id_record .'& " + options );
2020-08-03 12:08:52 +02:00
}
2020-09-14 10:49:23 +02:00
/**
* Funzione dedicata al caricamento dinamico via AJAX delle righe del documento .
*/
2023-02-17 10:59:50 +01:00
function caricaRighe ( id_riga ) {
2020-09-14 10:49:23 +02:00
let container = $ ( " #righe " );
localLoading ( container , true );
2020-09-14 11:06:35 +02:00
return $ . get ( " '. $structure->fileurl ('row-list.php').'?id_module='. $id_module .'&id_record='. $id_record .' " , function ( data ) {
container . html ( data );
2020-09-14 10:49:23 +02:00
localLoading ( container , false );
2023-02-17 10:59:50 +01:00
if ( id_riga != null ) {
$ ( " tr[data-id= " + id_riga + " ] " ) . effect ( " highlight " , 1000 );
}
2020-09-14 10:49:23 +02:00
});
}
2023-01-13 09:35:27 +01:00
$ ( " #idsede " ) . change ( function (){
updateSelectOption ( " idsede_destinazione " , $ ( this ) . val ());
$ ( " #idreferente " ) . selectReset ();
});
2020-08-03 12:08:52 +02:00
$ ( " #idanagrafica " ) . change ( function () {
updateSelectOption ( " idanagrafica " , $ ( this ) . val ());
session_set ( " superselect,idanagrafica " , $ ( this ) . val (), 0 );
$ ( " #idsede " ) . selectReset ();
2022-07-07 17:28:18 +02:00
$ ( " #idpagamento " ) . selectReset ();
let data = $ ( this ) . selectData ();
if ( data ) {
// Impostazione del tipo di pagamento da anagrafica
if ( data . id_pagamento ) {
input ( " idpagamento " ) . getElement ()
. selectSetNew ( data . id_pagamento , data . desc_pagamento );
}
}
2020-08-03 12:08:52 +02:00
});
$ ( document ) . ready ( function () {
2023-02-17 10:59:50 +01:00
caricaRighe ( null );
2020-08-03 12:08:52 +02:00
$ ( " #codice_cig, #codice_cup " ) . bind ( " keyup change " , function ( e ) {
if ( $ ( " #codice_cig " ) . val () == " " && $ ( " #codice_cup " ) . val () == " " ){
2021-02-22 14:48:50 +01:00
$ ( " #numero_cliente " ) . prop ( " required " , false );
2020-08-03 12:08:52 +02:00
} else {
2021-02-22 14:48:50 +01:00
$ ( " #numero_cliente " ) . prop ( " required " , true );
2020-08-03 12:08:52 +02:00
}
});
2023-02-17 10:59:50 +01:00
$ ( " #id_articolo " ) . on ( " change " , function ( e ) {
if ( $ ( this ) . val ()) {
var data = $ ( this ) . selectData ();
if ( data . barcode ) {
$ ( " #barcode " ) . val ( data . barcode );
} else {
$ ( " #barcode " ) . val ( " " );
}
}
e . preventDefault ();
setTimeout ( function (){
$ ( " #barcode " ) . focus ();
}, 100 );
});
$ ( " #barcode " ) . focus ();
});
2023-03-30 16:36:24 +02:00
async function salvaArticolo () {
// Salvataggio via AJAX
await salvaForm ( " #edit-form " );
2023-02-17 10:59:50 +01:00
$ ( " #link_form " ) . ajaxSubmit ({
url : globals . rootdir + " /actions.php " ,
data : {
id_module : globals . id_module ,
id_record : globals . id_record ,
ajax : true ,
},
type : " post " ,
beforeSubmit : function ( arr , $form , options ) {
return $form . parsley () . validate ();
},
success : function ( response ){
renderMessages ();
if ( response . length > 0 ){
response = JSON . parse ( response );
swal ({
type : " error " ,
title : " '.tr('Errore').' " ,
text : response . error ,
});
}
$ ( " #barcode " ) . val ( " " );
$ ( " #id_articolo " ) . selectReset ();
2023-04-06 13:11:38 +02:00
content_was_modified = false ;
2023-02-17 10:59:50 +01:00
caricaRighe ( null );
}
});
}
2023-02-27 12:09:59 +01:00
$ ( " #link_form " ) . bind ( " keypress " , function ( e ) {
2023-02-17 10:59:50 +01:00
if ( e . keyCode == 13 ) {
e . preventDefault ();
salvaArticolo ();
return false ;
}
2020-08-03 12:08:52 +02:00
});
2023-05-24 17:15:29 +02:00
input ( " ordinamento " ) . on ( " change " , function (){
if ( input ( this ) . get () == " desc " ) {
session_set ( " module_'. $id_module .',order_row_desc " , 1 , " " ) . then ( function () {
caricaRighe ( null );
});
} else {
session_set ( " module_'. $id_module .',order_row_desc " ) . then ( function () {
caricaRighe ( null );
});
}
});
2020-08-03 12:08:52 +02:00
</ script > ' ;
2017-09-14 10:27:49 +02:00
2018-09-05 10:05:23 +02:00
// Collegamenti diretti
// Fatture o ddt collegati a questo ordine
2024-04-02 12:32:38 +02:00
$elementi = $dbo -> fetchArray ( '
SELECT
`co_documenti` . `id` ,
`co_documenti` . `data` ,
`co_documenti` . `numero` ,
`co_documenti` . `numero_esterno` ,
2024-04-18 17:44:05 +02:00
`co_tipidocumento_lang` . `title` AS tipo_documento ,
2024-04-02 12:32:38 +02:00
`co_tipidocumento` . `dir`
FROM
`co_documenti`
INNER JOIN `co_tipidocumento` ON `co_tipidocumento` . `id` = `co_documenti` . `idtipodocumento`
LEFT JOIN `co_tipidocumento_lang` ON ( `co_tipidocumento_lang` . `id_record` = `co_tipidocumento` . `id` AND `co_tipidocumento_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
INNER JOIN `co_righe_documenti` ON `co_righe_documenti` . `iddocumento` = `co_documenti` . `id`
WHERE
`co_righe_documenti` . `idordine` = '.prepare($id_record).'
UNION
SELECT
`dt_ddt` . `id` ,
`dt_ddt` . `data` ,
`dt_ddt` . `numero` ,
`dt_ddt` . `numero_esterno` ,
2024-04-18 17:44:05 +02:00
`dt_tipiddt_lang` . `title` AS tipo_documento ,
2024-04-02 12:32:38 +02:00
`dt_tipiddt` . `dir`
FROM
`dt_ddt`
INNER JOIN `dt_tipiddt` ON `dt_tipiddt` . `id` = `dt_ddt` . `idtipoddt`
LEFT JOIN `dt_tipiddt_lang` ON ( `dt_tipiddt_lang` . `id_record` = `dt_tipiddt` . `id` AND `dt_tipiddt_lang` . `id_lang` = '.prepare(Models\Locale::getDefault()->id).' )
INNER JOIN `dt_righe_ddt` ON `dt_righe_ddt` . `idddt` = `dt_ddt` . `id`
WHERE
`dt_righe_ddt` . `idordine` = '.prepare($id_record).'
ORDER BY
`data` ' );
2018-09-05 10:05:23 +02:00
2017-09-14 10:27:49 +02:00
if ( ! empty ( $elementi )) {
echo '
2024-05-16 18:02:50 +02:00
< div class = " card card-warning collapsable collapsed-card " >
< div class = " card-header with-border " >
< h3 class = " card-title " >< i class = " fa fa-warning " ></ i > '.tr(' Documenti collegati : _NUM_ ' , [
2024-03-22 15:52:24 +01:00
'_NUM_' => count ( $elementi ),
]) . ' </ h3 >
2024-05-16 18:02:50 +02:00
< div class = " card-tools pull-right " >
2024-05-23 17:51:21 +02:00
< button type = " button " class = " btn btn-tool " data - card - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
2018-09-05 10:05:23 +02:00
</ div >
</ div >
2024-05-16 18:02:50 +02:00
< div class = " card-body " >
2018-09-05 10:05:23 +02:00
< ul > ' ;
2017-09-14 10:27:49 +02:00
foreach ( $elementi as $elemento ) {
$descrizione = tr ( '_DOC_ num. _NUM_ del _DATE_' , [
'_DOC_' => $elemento [ 'tipo_documento' ],
'_NUM_' => ! empty ( $elemento [ 'numero_esterno' ]) ? $elemento [ 'numero_esterno' ] : $elemento [ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $elemento [ 'data' ]),
]);
2019-02-11 19:18:17 +01:00
if ( ! in_array ( $elemento [ 'tipo_documento' ], [ 'Ddt in uscita' , 'Ddt in entrata' ])) {
2017-09-14 10:27:49 +02:00
$modulo = ( $elemento [ 'dir' ] == 'entrata' ) ? 'Fatture di vendita' : 'Fatture di acquisto' ;
} else {
2024-05-03 12:15:09 +02:00
$modulo = ( $elemento [ 'dir' ] == 'entrata' ) ? 'Ddt in uscita' : 'Ddt in entrata' ;
2017-09-14 10:27:49 +02:00
}
$id = $elemento [ 'id' ];
echo '
2018-09-05 10:05:23 +02:00
< li > '.Modules::link($modulo, $id, $descrizione).' </ li > ' ;
2017-09-14 10:27:49 +02:00
}
echo '
</ ul >
2018-09-05 10:05:23 +02:00
</ div >
</ div > ' ;
}
if ( ! empty ( $elementi )) {
echo '
< div class = " alert alert-error " >
'.tr(' Eliminando questo documento si potrebbero verificare problemi nelle altre sezioni del gestionale ').' .
</ div > ' ;
2017-09-14 10:27:49 +02:00
}
2017-11-16 14:27:43 +01:00
?>
< a class = " btn btn-danger ask " data - backto = " record-list " >
2023-09-28 16:08:45 +02:00
< i id = " elimina " class = " fa fa-trash " ></ i > < ? php echo tr ( 'Elimina' ); ?>
2017-11-16 14:27:43 +01:00
</ a >
2018-05-22 14:41:42 +02:00