2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2017-09-22 15:19:59 +02:00
$module = Modules :: get ( $id_module );
2017-08-04 16:28:16 +02:00
if ( $module [ 'name' ] == 'Ddt di vendita' ) {
$dir = 'entrata' ;
} else {
$dir = 'uscita' ;
}
2018-11-22 10:05:45 +01:00
$_SESSION [ 'superselect' ][ 'idanagrafica' ] = $record [ 'idanagrafica' ];
2017-08-04 16:28:16 +02:00
?>
2018-02-23 16:04:50 +01: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 " >
2018-02-18 19:53:23 +01:00
< input type = " hidden " name = " id_record " value = " <?php echo $id_record ; ?> " >
2017-08-04 16:28:16 +02:00
<!-- INTESTAZIONE -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-04 12:02:29 +02:00
< h3 class = " panel-title " >< ? php echo tr ( 'Intestazione' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
2018-03-21 23:49:08 +01:00
< ? php
if ( $dir == 'entrata' ) {
2018-07-18 15:20:10 +02:00
$rs2 = $dbo -> fetchArray ( 'SELECT piva, codice_fiscale, citta, indirizzo, cap, provincia FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]));
2018-03-21 23:49:08 +01:00
$campi_mancanti = [];
if ( $rs2 [ 0 ][ 'piva' ] == '' ) {
if ( $rs2 [ 0 ][ 'codice_fiscale' ] == '' ) {
array_push ( $campi_mancanti , 'codice fiscale' );
}
}
if ( $rs2 [ 0 ][ 'citta' ] == '' ) {
array_push ( $campi_mancanti , 'citta' );
}
if ( $rs2 [ 0 ][ 'indirizzo' ] == '' ) {
array_push ( $campi_mancanti , 'indirizzo' );
}
if ( $rs2 [ 0 ][ 'cap' ] == '' ) {
array_push ( $campi_mancanti , 'C.A.P.' );
}
if ( sizeof ( $campi_mancanti ) > 0 ) {
echo " <div class='alert alert-warning'><i class='fa fa-warning'></i> Prima di procedere alla stampa completa i seguenti campi dell'anagrafica:<br/><b> " . implode ( ', ' , $campi_mancanti ) . ' </ b >< br />
2018-07-18 15:20:10 +02:00
'.Modules::link(' Anagrafiche ', $record[' idanagrafica '], tr(' Vai alla scheda anagrafica '), null).' </ div > ' ;
2018-03-21 23:49:08 +01:00
}
}
?>
2018-07-08 18:11:17 +02:00
2017-08-04 16:28:16 +02:00
< div class = " row " >
2018-03-21 23:49:08 +01:00
< ? php
2018-03-22 15:40:20 +01:00
if ( $dir == 'uscita' ) {
echo '
2018-03-21 23:49:08 +01:00
< div class = " col-md-3 " >
{[ " type " : " span " , " label " : " '.tr('Numero ddt').' " , " class " : " text-center " , " value " : " $numero $ " ]}
</ div > ' ;
2018-03-22 15:40:20 +01:00
}
?>
2017-08-04 16:28:16 +02:00
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Numero secondario'); ?> " , " name " : " numero_esterno " , " class " : " text-center " , " value " : " $numero_esterno $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-11-09 11:34:27 +01:00
{[ " type " : " date " , " label " : " <?php echo tr('Data'); ?> " , " name " : " data " , " required " : 1 , " value " : " $data $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-05-22 14:41:42 +02:00
< ? php
2018-07-08 18:11:17 +02:00
if ( setting ( 'Cambia automaticamente stato ddt fatturati' )) {
2018-07-18 15:20:10 +02:00
if ( $record [ 'stato' ] == 'Fatturato' || $record [ 'stato' ] == 'Parzialmente fatturato' ) {
2018-06-26 14:30:26 +02:00
?>
2018-05-22 14:41:42 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoddt " , " required " : 1 , " values " : " query=SELECT * FROM dt_statiddt " , " value " : " $idstatoddt $ " , " extra " : " readonly " ]}
2018-06-26 14:30:26 +02:00
< ? php
} else {
?>
2018-07-08 18:11:17 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoddt " , " required " : 1 , " values " : " query=SELECT * FROM dt_statiddt WHERE descrizione IN('Bozza', 'Evaso', 'Parzialmente evaso') " , " value " : " $idstatoddt $ " ]}
2018-05-22 14:41:42 +02:00
< ? php
}
2018-06-26 14:30:26 +02:00
} else {
?>
2018-05-22 14:41:42 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatoddt " , " required " : 1 , " values " : " query=SELECT * FROM dt_statiddt " , " value " : " $idstatoddt $ " ]}
< ? php
}
?>
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-3 " >
2018-12-17 10:22:11 +01:00
{[ " type " : " select " , " label " : " <?php echo ( $dir == 'uscita' ) ? tr('Fornitore') : tr('Destinatario'); ?> " , " name " : " idanagrafica " , " required " : 1 , " value " : " $idanagrafica $ " , " ajax-source " : " clienti_fornitori " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-12-17 10:22:11 +01:00
2017-08-04 16:28:16 +02:00
< div class = " col-md-3 " >
2018-12-17 10:22:11 +01:00
{[ " type " : " select " , " label " : " <?php echo ( $dir == 'uscita' ) ? tr('Partenza merce') : tr('Destinazione merce'); ?> " , " name " : " idsede " , " ajax-source " : " sedi " , " value " : " $idsede $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< hr >
< div class = " row " >
< div class = " col-md-3 " >
2018-11-30 16:10:15 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Aspetto beni'); ?> " , " name " : " idaspettobeni " , " value " : " $idaspettobeni $ " , " ajax-source " : " aspetto-beni " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " , " icon-after " : " add|<?php echo Modules::get('Aspetto beni')['id']; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-11-15 19:06:42 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Causale trasporto'); ?> " , " name " : " idcausalet " , " value " : " $idcausalet $ " , " ajax-source " : " causali " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " , " icon-after " : " add|<?php echo Modules::get('Causali')['id']; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Porto'); ?> " , " name " : " idporto " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_porto ORDER BY descrizione ASC " , " value " : " $idporto $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Num. colli'); ?> " , " name " : " n_colli " , " value " : " $n_colli $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Pagamento'); ?> " , " name " : " idpagamento " , " values " : " query=SELECT id, descrizione FROM co_pagamenti GROUP BY descrizione ORDER BY descrizione ASC " , " value " : " $idpagamento $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Tipo di spedizione'); ?> " , " name " : " idspedizione " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_spedizione ORDER BY descrizione ASC " , " value " : " $idspedizione $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-12-17 10:22:11 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Vettore'); ?> " , " name " : " idvettore " , " ajax-source " : " vettori " , " value " : " $idvettore $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " , " disabled " : < ? php echo intval ( $record [ 'idspedizione' ] == 3 ); ?> , "required": <?php echo (!empty($record['idspedizione'])) ? intval($record['idspedizione'] != 3) : 0; ?>, "icon-after": "add|<?php echo Modules::get('Anagrafiche')['id']; ?>|tipoanagrafica=Vettore|<?php echo (($record['idspedizione'] != 3 and intval(!$record['flag_completato']))) ? '' : 'disabled'; ?>" ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-11-28 01:21:22 +01:00
< script >
$ ( " #idspedizione " ) . change ( function (){
if ( $ ( this ) . val () == 3 ) {
$ ( " #idvettore " ) . attr ( " required " , false );
$ ( " #idvettore " ) . attr ( " disabled " , true );
2018-11-30 16:10:15 +01:00
$ ( " label[for=idvettore] " ) . text ( " <?php echo tr('Vettore'); ?> " );
2018-11-28 01:21:22 +01:00
$ ( " #idvettore " ) . selectReset ( " - Seleziona un'opzione - " );
$ ( " #idvettore " ) . next () . next () . find ( " button.bound:nth-child(1) " ) . prop ( " disabled " , true );
} else {
$ ( " #idvettore " ) . attr ( " required " , true );
$ ( " #idvettore " ) . attr ( " disabled " , false );
2018-11-30 16:10:15 +01:00
$ ( " label[for=idvettore] " ) . text ( " <?php echo tr('Vettore'); ?>* " );
2018-11-28 01:21:22 +01:00
$ ( " #idvettore " ) . next () . next () . find ( " button.bound:nth-child(1) " ) . prop ( " disabled " , false );
}
});
$ ( " #idcausalet " ) . change ( function (){
if ( $ ( this ) . val () == 3 ) {
$ ( " #tipo_resa " ) . attr ( " disabled " , false );
} else {
$ ( " #tipo_resa " ) . attr ( " disabled " , true );
}
});
</ script >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " row " >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " number " , " label " : " <?php echo tr('Sconto incondizionato'); ?> " , " name " : " sconto_generico " , " value " : " $sconto_globale $ " , " icon-after " : " choice|untprc| $tipo_sconto_globale $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note'); ?> " , " name " : " note " , " value " : " $note $ " , " readonly " : " <?php echo $record['flag_completato'] ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2018-07-08 18:11:17 +02:00
2018-05-22 14:41:42 +02:00
< div class = " row " >
< div class = " col-md-12 " >
{[ " type " : " textarea " , " label " : " <?php echo tr('Note aggiuntive'); ?> " , " name " : " note_aggiuntive " , " help " : " <?php echo tr('Note interne.'); ?> " , " value " : " $note_aggiuntive $ " ]}
</ div >
</ div >
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ form >
<!-- RIGHE -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
2017-09-04 12:02:29 +02:00
< h3 class = " panel-title " >< ? php echo tr ( 'Righe' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
< div class = " pull-left " >
< ? php
2018-07-18 15:20:10 +02:00
if ( $record [ 'flag_completato' ] == 0 ) {
2018-06-25 11:44:06 +02:00
// Lettura ordini
2018-07-18 15:20:10 +02:00
$ordini_query = 'SELECT COUNT(*) AS tot FROM or_ordini WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . ' AND idstatoordine IN (SELECT id FROM or_statiordine WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoordine=(SELECT id FROM or_tipiordine WHERE dir=' . prepare ( $dir ) . ') AND or_ordini.id IN (SELECT idordine FROM or_righe_ordini WHERE or_righe_ordini.idordine = or_ordini.id AND (qta - qta_evasa) > 0)' ;
2018-06-25 11:44:06 +02:00
$ordini = $dbo -> fetchArray ( $ordini_query )[ 0 ][ 'tot' ];
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-primary'.(!empty( $ordini ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/ddt/add_ordine.php?id_module='. $id_module .'&id_record='. $id_record .' " data - toggle = " modal " data - title = " Aggiungi ordine " >
2018-06-25 11:44:06 +02:00
< i class = " fa fa-plus " ></ i > '.tr(' Ordine ').'
2018-06-26 14:30:26 +02:00
</ a > ' ; ?>
2018-10-25 17:11:02 +02:00
< a class = " btn btn-primary " data - href = " <?php echo $rootdir ; ?>/modules/ddt/row-add.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>&is_articolo " data - toggle = " modal " data - title = " Aggiungi articolo " >
2018-03-15 17:41:09 +01:00
< i class = " fa fa-plus " ></ i > < ? php echo tr ( 'Articolo' ); ?>
</ a >
2018-02-19 17:48:04 +01:00
2018-10-25 17:11:02 +02:00
< a class = " btn btn-primary " data - href = " <?php echo $rootdir ; ?>/modules/ddt/row-add.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>&is_riga " data - toggle = " modal " data - title = " Aggiungi riga " >
2018-03-15 17:41:09 +01:00
< i class = " fa fa-plus " ></ i > < ? php echo tr ( 'Riga' ); ?>
</ a >
2018-02-19 17:48:04 +01:00
2018-10-25 17:11:02 +02:00
< a class = " btn btn-primary " data - href = " <?php echo $rootdir ; ?>/modules/ddt/row-add.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>&is_descrizione " data - toggle = " modal " data - title = " Aggiungi descrizione " >
2018-03-15 17:41:09 +01:00
< i class = " fa fa-plus " ></ i > < ? php echo tr ( 'Descrizione' ); ?>
</ a >
2017-08-04 16:28:16 +02:00
< ? php
}
?>
</ div >
< div class = " clearfix " ></ div >
< br >
< div class = " row " >
< div class = " col-md-12 " >
< ? php
include $docroot . '/modules/ddt/row-list.php' ;
?>
</ div >
</ div >
</ div >
</ div >
2018-09-28 16:17:10 +02:00
{( " name " : " filelist_and_upload " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
{( " name " : " log_email " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
2017-11-15 18:41:59 +01:00
2017-08-04 16:28:16 +02:00
< script >
$ ( '#idanagrafica' ) . change ( function (){
session_set ( 'superselect,idanagrafica' , $ ( this ) . val (), 0 );
$ ( " #idsede " ) . selectReset ();
});
</ script >
2017-11-16 14:27:43 +01:00
< ? php
2018-09-05 10:05:23 +02:00
// Collegamenti diretti
// Fatture collegate a questo ddt
$elementi = $dbo -> fetchArray ( 'SELECT `co_documenti`.*, `co_tipidocumento`.`descrizione` AS tipo_documento, `co_tipidocumento`.`dir` FROM `co_documenti` JOIN `co_tipidocumento` ON `co_tipidocumento`.`id` = `co_documenti`.`idtipodocumento` WHERE `co_documenti`.`id` IN (SELECT `iddocumento` FROM `co_righe_documenti` WHERE `idddt` = ' . prepare ( $id_record ) . ') ORDER BY `data`' );
if ( ! empty ( $elementi )) {
2017-09-14 10:27:49 +02:00
echo '
2018-09-05 10:05:23 +02:00
< div class = " box box-warning collapsable collapsed-box " >
< div class = " box-header with-border " >
< h3 class = " box-title " >< i class = " fa fa-warning " ></ i > '.tr(' Documenti collegati : _NUM_ ' , [
2018-09-19 09:57:30 +02:00
'_NUM_' => count ( $elementi ),
2018-09-05 10:05:23 +02:00
]) . ' </ h3 >
< div class = " box-tools pull-right " >
< button type = " button " class = " btn btn-box-tool " data - widget = " collapse " >< i class = " fa fa-plus " ></ i ></ button >
</ div >
</ div >
< div class = " box-body " >
< ul > ' ;
foreach ( $elementi as $fattura ) {
2017-09-14 10:27:49 +02:00
$descrizione = tr ( '_DOC_ num. _NUM_ del _DATE_' , [
'_DOC_' => $fattura [ 'tipo_documento' ],
'_NUM_' => ! empty ( $fattura [ 'numero_esterno' ]) ? $fattura [ 'numero_esterno' ] : $fattura [ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $fattura [ 'data' ]),
]);
$modulo = ( $fattura [ 'dir' ] == 'entrata' ) ? 'Fatture di vendita' : 'Fatture di acquisto' ;
$id = $fattura [ '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 " >
< i class = " fa fa-trash " ></ i > < ? php echo tr ( 'Elimina' ); ?>
</ a >
2018-05-22 14:41:42 +02:00
< script >
< ? php
2018-07-18 15:20:10 +02:00
if ( $record [ 'flag_completato' ]) {
2018-06-26 14:30:26 +02:00
?>
2018-05-22 14:41:42 +02:00
$ ( '#tipo_sconto_generico' ) . prop ( 'disabled' , true );
< ? php
}
?>
</ script >