2017-08-04 16:28:16 +02:00
< ? php
include_once __DIR__ . '/../../core.php' ;
2018-07-18 15:20:10 +02:00
$block_edit = ! empty ( $note_accredito ) || $record [ 'stato' ] == 'Emessa' ;
2018-07-04 12:57:53 +02:00
2017-08-04 16:28:16 +02:00
$rs = $dbo -> fetchArray ( 'SELECT co_tipidocumento.descrizione, dir FROM co_tipidocumento INNER JOIN co_documenti ON co_tipidocumento.id=co_documenti.idtipodocumento WHERE co_documenti.id=' . prepare ( $id_record ));
$dir = $rs [ 0 ][ 'dir' ];
$tipodoc = $rs [ 0 ][ 'descrizione' ];
2018-07-18 15:20:10 +02:00
$_SESSION [ 'superselect' ][ 'idanagrafica' ] = $record [ 'idanagrafica' ];
2018-02-09 14:25:40 +01:00
$_SESSION [ 'superselect' ][ 'ddt' ] = $dir ;
2018-12-28 19:06:53 +01:00
$_SESSION [ 'superselect' ][ 'split_payment' ] = $record [ 'split_payment' ];
2017-08-31 16:23:26 +02:00
2018-05-24 18:29:37 +02:00
if ( $dir == 'entrata' ) {
2018-06-26 10:25:50 +02:00
$conto = 'vendite' ;
2018-05-24 18:29:37 +02:00
} else {
2018-06-26 10:25:50 +02:00
$conto = 'acquisti' ;
2018-05-24 18:29:37 +02:00
}
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-09 14:25:40 +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 " >
2018-02-09 14:25:40 +01:00
< h3 class = " panel-title " >< ? php echo tr ( 'Intestazione' ); ?> </h3>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " panel-body " >
2018-02-11 20:24:29 +01:00
2018-02-09 15:43:51 +01:00
< ? php
2018-07-03 17:28:02 +02:00
2018-02-11 20:24:29 +01:00
if ( $dir == 'entrata' ) {
2019-01-10 18:41:25 +01:00
$rs2 = $dbo -> fetchArray ( 'SELECT piva, codice_fiscale, citta, indirizzo, cap, provincia, id_nazione, tipo FROM an_anagrafiche WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]));
2018-02-11 20:24:29 +01:00
$campi_mancanti = [];
2019-02-12 11:42:48 +01:00
//di default è un azienda e chiedo la partita iva
if ( empty ( $rs2 [ 0 ][ 'piva' ]) and ( empty ( $rs2 [ 0 ][ 'tipo' ]) or $rs2 [ 0 ][ 'tipo' ] == 'Azienda' )) {
2019-01-10 18:41:25 +01:00
array_push ( $campi_mancanti , 'Partita IVA' );
2019-01-10 18:06:15 +01:00
}
2019-02-12 11:42:48 +01:00
//se è un privato o un ente pubblico controllo il codice fiscale
2019-02-07 19:19:11 +01:00
if (( $rs2 [ 0 ][ 'tipo' ] == 'Privato' or $rs2 [ 0 ][ 'tipo' ] == 'Ente pubblico' ) and empty ( $rs2 [ 0 ][ 'codice_fiscale' ])) {
array_push ( $campi_mancanti , 'Codice fiscale' );
}
2019-02-12 11:42:48 +01:00
2018-02-11 20:24:29 +01:00
if ( $rs2 [ 0 ][ 'citta' ] == '' ) {
2018-12-27 23:07:19 +01:00
array_push ( $campi_mancanti , 'Città' );
2018-02-11 20:24:29 +01:00
}
if ( $rs2 [ 0 ][ 'indirizzo' ] == '' ) {
2018-12-27 23:07:19 +01:00
array_push ( $campi_mancanti , 'Indirizzo' );
2018-02-11 20:24:29 +01:00
}
if ( $rs2 [ 0 ][ 'cap' ] == '' ) {
array_push ( $campi_mancanti , 'C.A.P.' );
}
2019-01-03 18:54:09 +01:00
if ( empty ( $rs2 [ 0 ][ 'id_nazione' ])) {
2018-12-27 23:07:19 +01:00
array_push ( $campi_mancanti , 'Nazione' );
}
2018-02-11 20:24:29 +01:00
if ( sizeof ( $campi_mancanti ) > 0 ) {
2018-12-27 23:07:19 +01:00
echo " <div class='alert alert-warning'><i class='fa fa-warning'></i> Prima di procedere alla stampa completa i seguenti campi dell'anagrafica Cliente: <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-02-11 20:24:29 +01:00
}
}
?>
2017-08-04 16:28:16 +02:00
< div class = " row " >
2017-11-07 19:19:52 +01:00
< ? php
if ( $dir == 'uscita' ) {
echo '
< div class = " col-md-3 " >
2018-03-22 13:32:04 +01:00
{[ " type " : " text " , " label " : " '.tr('Numero fattura/protocollo').' " , " required " : 1 , " name " : " numero " , " class " : " text-center alphanumeric-mask " , " value " : " $numero $ " ]}
2017-11-07 19:19:52 +01:00
</ div > ' ;
2018-12-07 12:10:55 +01:00
$label = tr ( 'Numero fattura del fornitore' );
2017-11-07 19:19:52 +01:00
} else {
2018-02-04 17:26:25 +01:00
$label = tr ( 'Numero fattura' );
2017-11-07 19:19:52 +01:00
}
?>
2018-06-26 10:25:50 +02:00
2018-04-03 12:30:12 +02:00
<!-- id_segment -->
{[ " type " : " hidden " , " label " : " Segmento " , " name " : " id_segment " , " class " : " text-center " , " value " : " $id_segment $ " ]}
2018-06-26 10:25:50 +02:00
2017-08-04 16:28:16 +02:00
< div class = " col-md-3 " >
2019-03-08 15:43:36 +01:00
{[ " type " : " text " , " label " : " <?php echo $label ; ?> " , " name " : " numero_esterno " , " class " : " text-center " , " value " : " $numero_esterno $ " ]}
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 emissione'); ?> " , " name " : " data " , " required " : 1 , " value " : " $data $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-09-27 15:50:03 +02:00
< ? php
$query = 'SELECT * FROM co_statidocumento' ;
if ( empty ( $record [ 'is_fiscale' ])) {
$query .= " WHERE descrizione = 'Bozza' " ;
2018-09-28 09:30:46 +02:00
$plugin = $dbo -> fetchArray ( " SELECT id FROM zz_plugins WHERE name='Fatturazione Elettronica' AND idmodule_to = " . prepare ( $id_module ));
echo '<script>$("#link-tab_' . $plugin [ 0 ][ 'id' ] . '").addClass("disabled");</script>' ;
2018-09-27 15:50:03 +02:00
}
?>
2017-08-04 16:28:16 +02:00
< div class = " col-md-3 " >
2018-08-27 18:06:50 +02:00
<!-- TODO : Rimuovere possibilità di selezionare lo stato pagato obbligando l ' utente ad aggiungere il movimento in prima nota -->
2018-09-27 15:50:03 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatodocumento " , " required " : 1 , " values " : " query=<?php echo $query ; ?> " , " value " : " $idstatodocumento $ " , " class " : " unblockable " , " extra " : " onchange = \" if ( $ ('#idstatodocumento option:selected').text()=='Pagato' || $ ('#idstatodocumento option:selected').text()=='Parzialmente pagato' ) { if( confirm('<?php echo tr('Sicuro di voler impostare manualmente la fattura come pagata senza aggiungere il movimento in prima nota?'); ?>') ) { return true; }else { $ ('#idstatodocumento').selectSet(<?php echo $record['idstatodocumento'] ; ?>); }} \" " ]}
2017-08-04 16:28:16 +02:00
</ div >
2018-12-14 12:50:44 +01:00
< div class = " col-md-3 " >
2018-12-28 18:03:38 +01:00
< ? php
2018-12-29 12:03:22 +01:00
if ( $dir == 'entrata' ) {
?>
2019-03-12 17:00:05 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato FE'); ?> " , " name " : " codice_stato_fe " , " required " : 0 , " values " : " query=SELECT codice as id, CONCAT_WS(' - ',codice,descrizione) as text FROM fe_stati_documento " , " value " : " $codice_stato_fe $ " , " disabled " : < ? php echo intval ( Plugins\ExportFE\Connection :: isEnabled ()); ?> , "class": "unblockable", "help": "<?php echo ((!empty($record['data_stato_fe'])) ? Translator::timestampToLocale($record['data_stato_fe']) : '' ); ?>" ]}
2018-12-29 12:03:22 +01:00
< ? php
}
?>
2018-12-14 12:50:44 +01:00
</ div >
2017-08-04 16:28:16 +02:00
</ div >
< div class = " row " >
< div class = " col-md-3 " >
< ? php
2018-01-15 20:28:36 +01:00
2018-07-18 15:20:10 +02:00
echo Modules :: link ( 'Anagrafiche' , $record [ 'idanagrafica' ], null , null , 'class="pull-right"' );
2018-01-15 20:28:36 +01:00
2017-08-04 16:28:16 +02:00
if ( $dir == 'entrata' ) {
?>
2019-02-27 12:19:07 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Cliente'); ?> " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " clienti " , " help " : " <?php echo tr( " In caso di autofattura indicare l 'azienda: ").stripslashes($database->fetchOne(' SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica = '.prepare(setting(' Azienda predefinita ')))[' ragione_sociale ' ]); ?> ", "value": "$idanagrafica$" ]}
2017-08-04 16:28:16 +02:00
< ? php
} else {
?>
2018-08-11 15:49:46 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Fornitore'); ?> " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " fornitori " , " value " : " $idanagrafica $ " ]}
2017-08-04 16:28:16 +02:00
< ? php
}
?>
</ div >
< div class = " col-md-3 " >
2018-08-11 15:49:46 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Riferimento sede'); ?> " , " name " : " idsede " , " ajax-source " : " sedi " , " placeholder " : " Sede legale " , " value " : " $idsede $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
2019-03-12 17:00:05 +01:00
< ? php if ( $dir == 'uscita' ) { ?>
< div class = " col-md-3 " >
{[ " type " : " date " , " label " : " <?php echo tr('Data ricezione'); ?> " , " name " : " data_ricezione " , " required " : 0 , " value " : " $data_ricezione $ " ]}
</ div >
< ? php } ?>
2017-08-04 16:28:16 +02:00
< ? php if ( $dir == 'entrata' ) {
?>
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Agente di riferimento'); ?> " , " name " : " idagente " , " ajax-source " : " agenti " , " value " : " $idagente_fattura $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
< ? php
} ?>
< ? php
2018-07-18 15:20:10 +02:00
if ( $record [ 'stato' ] != 'Bozza' && $record [ 'stato' ] != 'Annullata' ) {
2019-03-08 16:59:55 +01:00
$ricalcola = true ;
2017-08-04 16:28:16 +02:00
$scadenze = $dbo -> fetchArray ( 'SELECT * FROM co_scadenziario WHERE iddocumento = ' . prepare ( $id_record ));
echo '
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
< p >< strong > '.tr(' Scadenze ').' </ strong ></ p > ' ;
2017-08-04 16:28:16 +02:00
foreach ( $scadenze as $scadenza ) {
echo '
2019-03-08 16:59:55 +01:00
< p > '.Translator::dateToLocale($scadenza[' scadenza ']).' : ' ;
if ( $scadenza [ 'pagato' ] == $scadenza [ 'da_pagare' ]) {
echo '
< strike > ' ;
}
echo Translator :: numberToLocale ( $scadenza [ 'da_pagare' ]) . '€' ;
if ( $scadenza [ 'pagato' ] == $scadenza [ 'da_pagare' ]) {
echo '
</ strike > ' ;
}
echo '
</ p > ' ;
$ricalcola = empty ( floatval ( $scadenza [ 'pagato' ])) && $ricalcola ;
}
if ( $fattura -> isFE () && $ricalcola && $module [ 'name' ] == 'Fatture di acquisto' ) {
echo '
< button type = " button " class = " btn btn-info btn-xs pull-right tip " title = " '.tr('Ricalcola le scadenze').'. '.tr('Per ricalcolare correttamente le scadenze, imposta la fattura in stato \ ' \ 'Bozza \ ' \ ' e correggi il metodo di come desiderato, poi re-imposta lo stato \ ' \ 'Emessa \ ' \ ' e utilizza questa funzione').'. " id = " ricalcola_scadenze " >
< i class = " fa fa-calculator " aria - hidden = " true " ></ i >
</ button > ' ;
2017-08-04 16:28:16 +02:00
}
2019-03-08 16:59:55 +01:00
2017-08-04 16:28:16 +02:00
echo '
</ div > ' ;
}
?>
</ div >
< hr >
< div class = " row " >
< div class = " col-md-3 " >
2019-01-30 16:42:28 +01:00
<!-- Nella realtà la fattura accompagnatoria non può esistere per la fatturazione elettronica , in quanto la risposta dal SDI potrebbe non essere immediata e le merci in viaggio . Dunque si può emettere una documento di viaggio valido per le merci ed eventualmente una fattura pro - forma per l ' incasso della stessa , emettendo infine la fattura elettronica differita . -->
2019-03-08 16:59:55 +01:00
2019-01-30 16:42:28 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Tipo fattura'); ?> " , " name " : " idtipodocumento " , " required " : 1 , " values " : " query=SELECT id, descrizione FROM co_tipidocumento WHERE dir='<?php echo $dir ; ?>' AND (reversed = 0 OR id = <?php echo $record['idtipodocumento'] ; ?>) " , " value " : " $idtipodocumento $ " , " readonly " : < ? php echo intval ( $record [ 'stato' ] != 'Bozza' && $record [ 'stato' ] != 'Annullata' ); ?> , "help": "<?php echo ($database->fetchOne('SELECT tipo FROM an_anagrafiche WHERE idanagrafica = '.prepare($record['idanagrafica']))['tipo'] == 'Ente pubblico') ? 'FPA12 - fattura verso PA' : 'FPR12 - fattura verso privati'; ?>" ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2019-01-30 16:42:28 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Pagamento'); ?> " , " name " : " idpagamento " , " required " : 1 , " values " : " query=SELECT id, CONCAT_WS(' - ', codice_modalita_pagamento_fe, descrizione) AS descrizione, (SELECT id FROM co_banche WHERE id_pianodeiconti3 = co_pagamenti.idconto_<?php echo $conto ; ?> LIMIT 0,1) AS idbanca FROM co_pagamenti GROUP BY descrizione ORDER BY descrizione ASC " , " value " : " $idpagamento $ " , " extra " : " onchange= \" $ ('#idbanca').val( $ (this).find('option:selected').data('idbanca') ).change(); \" " ]}
2018-03-28 19:09:28 +02:00
</ div >
2018-06-26 10:25:50 +02:00
2018-03-28 19:09:28 +02:00
< div class = " col-md-3 " >
2018-12-29 12:03:22 +01:00
{[ " type " : " select " , " label " : " <?php echo tr('Banca'); ?> " , " name " : " idbanca " , " values " : " query=SELECT id, CONCAT (nome, ' - ' , iban) AS descrizione FROM co_banche WHERE deleted_at IS NULL ORDER BY nome ASC " , " value " : " $idbanca $ " , " icon-after " : " add|<?php echo Modules::get('Banche')['id']; ?>|| " , " extra " : " <?php echo ( $record['stato'] == 'Bozza') ? '' : 'disabled'; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2018-12-28 18:03:38 +01:00
< ? php
if ( $dir == 'uscita' ) {
?>
< div class = " row " >
< div class = " col-md-3 " >
{[ " type " : " number " , " label " : " <?php echo tr('Marca da bollo'); ?> " , " name " : " bollo " , " value " : " $bollo $ " , " help " : " <?php echo tr('Applicato solo se il totale della fattura è maggiore di _TOT_ €', [
'_TOT_' => Translator :: numberToLocale ( setting ( " Soglia minima per l'applicazione della marca da bollo " )),
]), '.' ; ?> " ]}
</ div >
</ div >
< ? php
}
?>
2019-03-08 16:59:55 +01:00
2017-08-04 16:28:16 +02:00
< div class = " row " >
2019-03-08 16:59:55 +01:00
2017-08-04 16:28:16 +02:00
< div class = " col-md-3 " >
2019-02-15 10:14:48 +01:00
{[ " type " : " number " , " label " : " <?php echo tr('Sconto incondizionato'); ?> " , " name " : " sconto_generico " , " value " : " $sconto_globale $ " , " help " : " <?php echo tr('Sconto complessivo della fattura. Il valore positivo indica uno sconto. Per applicare un rincaro inserire un valore negativo.'); ?> " , " icon-after " : " choice|untprc| $tipo_sconto_globale $ " < ? php echo ( $record [ 'stato' ] == 'Emessa' ) ? ', "disabled" : 1' : '' ; ?> ]}
2017-08-04 16:28:16 +02:00
</ div >
2019-03-08 16:59:55 +01:00
2018-12-28 18:03:38 +01:00
< div class = " col-md-3 " >
2019-01-03 18:54:09 +01:00
{[ " type " : " checkbox " , " label " : " <?php echo tr('Split payment'); ?> " , " name " : " split_payment " , " value " : " $split_payment $ " , " help " : " <?php echo tr('Abilita lo split payment per questo documento.'); ?> " , " placeholder " : " <?php echo tr('Split payment'); ?> " ]}
2018-12-28 18:03:38 +01:00
</ div >
2019-03-08 16:59:55 +01:00
2019-01-10 15:19:17 +01:00
< ? php
2019-01-10 18:41:25 +01:00
//TODO: Fattura per conto del fornitore (es. cooperative agricole che emettono la fattura per conto dei propri soci produttori agricoli conferenti)
if ( $dir == 'entrata' ) {
?>
2019-01-10 15:19:17 +01:00
< div class = " col-md-3 " >
2019-02-27 12:19:07 +01:00
{[ " type " : " checkbox " , " label " : " <?php echo tr('Fattura per conto terzi'); ?> " , " name " : " is_fattura_conto_terzi " , " value " : " $is_fattura_conto_terzi $ " , " help " : " <?php echo tr('Nell \ 'xml della FE imposta il fornitore ('.stripslashes( $database->fetchOne ('SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica = '.prepare(setting('Azienda predefinita')))['ragione_sociale']).') come cessionario e il cliente come cedente/prestatore.'); ?> " , " placeholder " : " <?php echo tr('Fattura per conto terzi'); ?> " ]}
2019-01-10 15:19:17 +01:00
</ div >
2019-03-08 16:59:55 +01:00
2019-01-10 15:19:17 +01:00
< ? php
2019-01-10 18:41:25 +01:00
}
?>
2019-02-15 12:12:44 +01:00
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " <?php echo tr('Ritenuta contributi'); ?> " , " name " : " id_ritenuta_contributi " , " value " : " $id_ritenuta_contributi $ " , " values " : " query=SELECT * FROM co_ritenuta_contributi " ]}
</ div >
2019-03-08 16:59:55 +01:00
2017-08-04 16:28:16 +02:00
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2019-02-26 11:01:35 +01:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note'); ?> " , " name " : " note " , " help " : " <?php echo tr('Note visibili anche in fattura.'); ?> " , " value " : " $note $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2019-02-12 11:42:48 +01:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note aggiuntive'); ?> " , " name " : " note_aggiuntive " , " help " : " <?php echo tr('Note interne.'); ?> " , " value " : " $note_aggiuntive $ " , " class " : " unblockable " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
</ div >
</ div >
2018-09-24 11:24:48 +02:00
< ? php
if ( $tipodoc == 'Fattura accompagnatoria di vendita' ) {
echo '
< div class = " box box-info " >
< div class = " box-header with-border " >
< h3 class = " box-title " >< i class = " fa fa-edit " ></ i > '.tr(' Dati Fattura accompagnatoria ').' </ h3 >
</ div >
< div class = " box-body " >
< div class = " row " >
< div class = " col-md-3 " >
2018-11-30 16:10:15 +01:00
{[ " type " : " select " , " label " : " '.tr('Aspetto beni').' " , " name " : " idaspettobeni " , " placeholder " : " " , " ajax-source " : " aspetto-beni " , " value " : " $idaspettobeni $ " , " icon-after " : " add|'.Modules::get('Aspetto beni')['id'].'||'.(( $record['stato'] != 'Bozza') ? 'disabled' : '').' " ]}
2018-09-24 11:24:48 +02:00
</ div >
< div class = " col-md-3 " >
2018-11-30 16:10:15 +01:00
{[ " type " : " select " , " label " : " '.tr('Causale trasporto').' " , " name " : " idcausalet " , " placeholder " : " " , " ajax-source " : " causali " , " value " : " $idcausalet $ " , " icon-after " : " add|'.Modules::get('Causali')['id'].'||'.(( $record['stato'] != 'Bozza') ? 'disabled' : '').' " ]}
2018-09-24 11:24:48 +02:00
</ div >
< div class = " col-md-3 " >
2018-11-28 02:10:12 +01:00
{[ " type " : " select " , " label " : " '.tr('Porto').' " , " name " : " idporto " , " placeholder " : " " , " values " : " query=SELECT id, descrizione FROM dt_porto ORDER BY descrizione ASC " , " value " : " $idporto $ " ]}
2018-09-24 11:24:48 +02:00
</ div >
< div class = " col-md-3 " >
{[ " type " : " text " , " label " : " '.tr('Num. colli').' " , " name " : " n_colli " , " value " : " $n_colli $ " ]}
</ div >
</ div >
< div class = " row " >
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " '.tr('Tipo di spedizione').' " , " name " : " idspedizione " , " values " : " query=SELECT id, descrizione FROM dt_spedizione ORDER BY descrizione ASC " , " value " : " $idspedizione $ " ]}
</ div >
< div class = " col-md-3 " >
2018-11-30 16:10:15 +01:00
{[ " type " : " select " , " label " : " '.tr('Vettore').' " , " name " : " idvettore " , " ajax-source " : " vettori " , " value " : " $idvettore $ " , " icon-after " : " add|'.Modules::get('Anagrafiche')['id'].'|tipoanagrafica=Vettore|'.((( $record['idspedizione'] != 3) and ( $record['stato'] == 'Bozza')) ? '' : 'disabled').' " , " disabled " : '.intval($record[' idspedizione '] == 3).' , " required " : '.intval($record[' idspedizione '] != 3).' ]}
2018-09-24 11:24:48 +02:00
</ div >
2018-11-23 16:48:30 +01:00
< script >
$ ( " #idspedizione " ) . change ( function (){
if ( $ ( this ) . val () == 3 ) {
$ ( " #idvettore " ) . attr ( " required " , false );
2018-11-27 01:00:48 +01:00
$ ( " #idvettore " ) . attr ( " disabled " , true );
2018-11-27 11:43:22 +01:00
$ ( " label[for=idvettore] " ) . text ( " '.tr('Vettore').' " );
$ ( " #idvettore " ) . selectReset ( " - Seleziona un \ 'opzione - " );
$ ( " #idvettore " ) . next () . next () . find ( " button.bound:nth-child(1) " ) . prop ( " disabled " , true );
2018-11-23 16:48:30 +01:00
} else {
$ ( " #idvettore " ) . attr ( " required " , true );
2018-11-27 01:00:48 +01:00
$ ( " #idvettore " ) . attr ( " disabled " , false );
2018-11-27 11:43:22 +01:00
$ ( " label[for=idvettore] " ) . text ( " '.tr('Vettore').'* " );
$ ( " #idvettore " ) . next () . next () . find ( " button.bound:nth-child(1) " ) . prop ( " disabled " , false );
}
});
2018-12-07 09:39:42 +01:00
2018-11-27 11:43:22 +01:00
$ ( " #idcausalet " ) . change ( function (){
if ( $ ( this ) . val () == 3 ) {
$ ( " #tipo_resa " ) . attr ( " disabled " , false );
} else {
$ ( " #tipo_resa " ) . attr ( " disabled " , true );
2018-11-23 16:48:30 +01:00
}
});
</ script > ' ;
$tipo_resa = [
[
'id' => 'EXW' ,
'text' => 'EXW' ,
],
[
'id' => 'FCA' ,
'text' => 'FCA' ,
],
[
'id' => 'FAS' ,
'text' => 'FAS' ,
],
[
'id' => 'FOB' ,
'text' => 'FOB' ,
],
[
'id' => 'CFR' ,
'text' => 'CFR' ,
],
[
'id' => 'CIF' ,
'text' => 'CIF' ,
],
[
'id' => 'CPT' ,
'text' => 'CPT' ,
],
[
'id' => 'CIP' ,
'text' => 'CIP' ,
],
[
'id' => 'DAF' ,
'text' => 'DAF' ,
],
[
'id' => 'DES' ,
'text' => 'DES' ,
],
[
'id' => 'DEQ' ,
'text' => 'DEQ' ,
],
[
'id' => 'DDU' ,
'text' => 'DDU' ,
],
[
'id' => 'DDP' ,
'text' => 'DDP' ,
2018-11-30 16:10:15 +01:00
],
2018-11-23 16:48:30 +01:00
];
echo '
< div class = " col-md-3 " >
2018-11-27 01:00:48 +01:00
{[ " type " : " select " , " label " : " '.tr('Tipo Resa').' " , " name " : " tipo_resa " , " value " : " $tipo_resa $ " , " values " : '.json_encode($tipo_resa).' , " readonly " : '.intval($record[' causale_desc '] != ' Reso ').' ]}
2018-11-23 16:48:30 +01:00
</ div >
2018-09-24 11:24:48 +02:00
</ div >
</ div >
</ div > ' ;
}
?>
2017-08-04 16:28:16 +02:00
</ form >
<!-- RIGHE -->
< div class = " panel panel-primary " >
< div class = " panel-heading " >
< h3 class = " panel-title " > Righe </ h3 >
</ div >
< div class = " panel-body " >
< div class = " row " >
< div class = " col-md-12 " >
< div class = " pull-left " >
< ? php
2018-07-18 15:20:10 +02:00
if ( $record [ 'stato' ] != 'Pagato' && $record [ 'stato' ] != 'Emessa' ) {
if ( empty ( $record [ 'ref_documento' ])) {
2018-07-03 17:28:02 +02:00
if ( $dir == 'entrata' ) {
// Lettura interventi non rifiutati, non fatturati e non collegati a preventivi o contratti
2018-09-03 15:29:55 +02:00
$int_query = 'SELECT COUNT(*) AS tot FROM in_interventi INNER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . ' AND in_statiintervento.completato=1 AND in_interventi.id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND in_interventi.id_preventivo IS NULL AND in_interventi.id NOT IN (SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL)' ;
2018-02-09 14:25:40 +01:00
$interventi = $dbo -> fetchArray ( $int_query )[ 0 ][ 'tot' ];
2017-08-04 16:28:16 +02:00
2018-07-03 17:28:02 +02:00
// Se non trovo niente provo a vedere se ce ne sono per clienti terzi
if ( empty ( $interventi )) {
// Lettura interventi non rifiutati, non fatturati e non collegati a preventivi o contratti (clienti terzi)
2018-09-03 15:29:55 +02:00
$int_query = 'SELECT COUNT(*) AS tot FROM in_interventi INNER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento WHERE idclientefinale=' . prepare ( $record [ 'idanagrafica' ]) . ' AND in_statiintervento.completato=1 AND in_interventi.id NOT IN (SELECT idintervento FROM co_righe_documenti WHERE idintervento IS NOT NULL) AND in_interventi.id_preventivo IS NULL AND in_interventi.id NOT IN (SELECT idintervento FROM co_promemoria WHERE idintervento IS NOT NULL)' ;
2018-07-03 17:28:02 +02:00
$interventi = $dbo -> fetchArray ( $int_query )[ 0 ][ 'tot' ];
}
echo '
2018-08-30 13:06:59 +02:00
< div class = " tip " data - toggle = " tooltip " title = " '.tr('Interventi completati non collegati a preventivi o contratti e che non siano già stati fatturati.').' " style = " display:inline; " >
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary '.(!empty( $interventi ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/add_intervento.php?id_module='. $id_module .'&id_record='. $id_record .' " data - title = " Aggiungi intervento " >
2017-09-19 17:27:31 +02:00
< i class = " fa fa-plus " ></ i > Intervento
2018-07-27 16:17:14 +02:00
</ a >
</ div > ' ;
2017-09-19 17:27:31 +02:00
2018-07-03 17:28:02 +02:00
// Lettura preventivi accettati, in attesa di conferma o in lavorazione
2019-02-14 17:49:58 +01:00
$prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . " AND idstato IN(SELECT id FROM co_statipreventivi WHERE descrizione='Accettato' OR descrizione='In lavorazione' OR descrizione='In attesa di conferma') AND default_revision=1 AND co_preventivi.id IN (SELECT idpreventivo FROM co_righe_preventivi WHERE co_righe_preventivi.idpreventivo = co_preventivi.id AND (qta - qta_evasa) > 0) " ;
2018-07-03 17:28:02 +02:00
$preventivi = $dbo -> fetchArray ( $prev_query )[ 0 ][ 'tot' ];
echo '
2018-07-27 16:17:14 +02:00
< div class = " tip " data - toggle = " tooltip " title = " '.tr('Preventivi accettati, in attesa di conferma o in lavorazione.').' " style = " display:inline; " >
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary '.(!empty( $preventivi ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/add_preventivo.php?id_module='. $id_module .'&id_record='. $id_record .' " data - title = " Aggiungi preventivo " >
2017-09-19 17:27:31 +02:00
< i class = " fa fa-plus " ></ i > Preventivo
2018-07-27 16:17:14 +02:00
</ a >
</ div > ' ;
2017-08-04 16:28:16 +02:00
2018-07-03 17:28:02 +02:00
// Lettura contratti accettati, in attesa di conferma o in lavorazione
2019-02-14 17:49:58 +01:00
$contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . ' AND idstato IN( SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND co_contratti.id IN (SELECT idcontratto FROM co_righe_contratti WHERE co_righe_contratti.idcontratto = co_contratti.id AND (qta - qta_evasa) > 0)' ;
2018-07-03 17:28:02 +02:00
$contratti = $dbo -> fetchArray ( $contr_query )[ 0 ][ 'tot' ];
echo '
2018-07-27 16:17:14 +02:00
< div class = " tip " data - toggle = " tooltip " title = " '.tr('Contratti accettati, in attesa di conferma o in lavorazione.').' " style = " display:inline; " >
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary '.(!empty( $contratti ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/add_contratto.php?id_module='. $id_module .'&id_record='. $id_record .' " data - title = " Aggiungi contratto " >
2017-09-19 17:27:31 +02:00
< i class = " fa fa-plus " ></ i > Contratto
2018-07-27 16:17:14 +02:00
</ a >
</ div > ' ;
2018-07-03 17:28:02 +02:00
}
2018-06-26 10:25:50 +02:00
2018-07-28 18:02:17 +02:00
// Lettura ddt
2018-08-03 09:34:06 +02:00
$ddt_query = 'SELECT COUNT(*) AS tot FROM dt_ddt WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . ' AND idstatoddt IN (SELECT id FROM dt_statiddt WHERE descrizione IN(\'Bozza\', \'Evaso\', \'Parzialmente evaso\', \'Parzialmente fatturato\')) AND idtipoddt IN (SELECT id FROM dt_tipiddt WHERE dir=' . prepare ( $dir ) . ') AND dt_ddt.id IN (SELECT idddt FROM dt_righe_ddt WHERE dt_righe_ddt.idddt = dt_ddt.id AND (qta - qta_evasa) > 0)' ;
2018-07-28 18:02:17 +02:00
$ddt = $dbo -> fetchArray ( $ddt_query )[ 0 ][ 'tot' ];
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary'.(!empty( $ddt ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/add_ddt.php?id_module='. $id_module .'&id_record='. $id_record .' " data - toggle = " tooltip " data - title = " Aggiungi ddt " >
2018-07-26 10:35:48 +02:00
< i class = " fa fa-plus " ></ i > Ddt
</ a > ' ;
2018-06-26 10:25:50 +02:00
2018-07-03 17:28:02 +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-07-03 17:28:02 +02:00
$ordini = $dbo -> fetchArray ( $ordini_query )[ 0 ][ 'tot' ];
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary'.(!empty( $ordini ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/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 > Ordine
2018-07-03 17:28:02 +02:00
</ a > ' ;
}
2017-08-04 16:28:16 +02:00
2017-09-19 17:27:31 +02:00
// Lettura articoli
2018-02-09 14:25:40 +01:00
$art_query = 'SELECT COUNT(*) AS tot FROM mg_articoli WHERE attivo = 1' ;
if ( $dir == 'entrata' ) {
$art_query .= ' AND (qta > 0 OR servizio = 1)' ;
}
$articoli = $dbo -> fetchArray ( $art_query )[ 0 ][ 'tot' ];
2017-09-19 17:27:31 +02:00
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary'.(!empty( $articoli ) ? '' : ' disabled').' " data - href = " '. $rootdir .'/modules/fatture/row-add.php?id_module='. $id_module .'&id_record='. $id_record .'&is_articolo " data - toggle = " tooltip " data - title = " Aggiungi articolo " >
2018-02-19 17:57:27 +01:00
< i class = " fa fa-plus " ></ i > '.tr(' Articolo ').'
2017-09-19 17:27:31 +02:00
</ a > ' ;
2017-09-19 16:20:44 +02:00
2017-09-19 17:27:31 +02:00
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary " data - href = " '. $rootdir .'/modules/fatture/row-add.php?id_module='. $id_module .'&id_record='. $id_record .'&is_riga " data - toggle = " tooltip " data - title = " Aggiungi riga " >
2018-02-19 17:57:27 +01:00
< i class = " fa fa-plus " ></ i > '.tr(' Riga ').'
2017-09-19 17:27:31 +02:00
</ a > ' ;
2018-02-04 17:26:25 +01:00
2018-01-18 19:03:06 +01:00
echo '
2018-10-25 17:11:02 +02:00
< a class = " btn btn-sm btn-primary " data - href = " '. $rootdir .'/modules/fatture/row-add.php?id_module='. $id_module .'&id_record='. $id_record .'&is_descrizione " data - toggle = " tooltip " data - title = " Aggiungi descrizione " >
2018-02-19 17:57:27 +01:00
< i class = " fa fa-plus " ></ i > '.tr(' Descrizione ').'
2018-01-18 19:03:06 +01:00
</ a > ' ;
2017-08-04 16:28:16 +02:00
}
2017-09-19 17:27:31 +02:00
?>
2017-08-04 16:28:16 +02:00
</ div >
< div class = " pull-right " >
<!-- Stampe -->
< ? php
2018-02-09 15:43:51 +01:00
//stampa solo per fatture di vendita
2017-08-04 16:28:16 +02:00
if ( $dir == 'entrata' ) {
2018-02-11 20:24:29 +01:00
if ( sizeof ( $campi_mancanti ) > 0 ) {
2018-02-27 00:12:11 +01:00
//echo '{( "name": "button", "type": "print", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "class": "btn-info disabled" )}';
2018-02-11 20:24:29 +01:00
} else {
2018-02-27 00:12:11 +01:00
//echo '{( "name": "button", "type": "print", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}';
2017-08-04 16:28:16 +02:00
}
}
?>
</ div >
</ div >
</ div >
< div class = " clearfix " ></ div >
< br >
< div class = " row " >
< div class = " col-md-12 " >
< ? php
include $docroot . '/modules/fatture/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 $ " )}
2017-08-04 16:28:16 +02:00
2019-01-11 15:57:46 +01:00
< ? php
2019-03-08 16:59:55 +01:00
if ( $dir == 'entrata' ) {
echo '
2019-02-26 12:13:51 +01:00
< div class = " alert alert-info text-center " > '.tr(' Per allegare un documento alla fattura elettronica caricare il file PDF specificando come categoria " Fattura Elettronica " ').' .</ div > ' ;
2019-03-08 16:59:55 +01:00
}
2019-01-11 15:57:46 +01:00
2019-03-08 16:59:55 +01:00
echo '
2017-08-04 16:28:16 +02:00
< script type = " text/javascript " >
2019-03-08 16:59:55 +01:00
$ ( " #idanagrafica " ) . change ( function (){
session_set ( " superselect,idanagrafica " , $ ( this ) . val (), 0 );
2017-08-04 16:28:16 +02:00
$ ( " #idsede " ) . selectReset ();
});
2019-03-08 16:59:55 +01:00
$ ( " #ricalcola_scadenze " ) . click ( function (){
swal ({
title : " '.tr('Desideri ricalcolare le scadenze?').' " ,
type : " warning " ,
showCancelButton : true ,
confirmButtonText : " '.tr('Sì').' "
}) . then ( function ( result ) {
redirect ( globals . rootdir + " /editor.php " , {
id_module : globals . id_module ,
id_record : globals . id_record ,
op : " ricalcola_scadenze " ,
backto : " record-edit " ,
}, " post " )
})
});
</ script > ' ;
2018-07-04 12:57:53 +02:00
2018-07-04 17:56:51 +02:00
if ( ! empty ( $note_accredito )) {
2018-07-04 12:57:53 +02:00
echo '
2018-09-28 17:29:59 +02:00
< div class = " alert alert-info text-center " > '.tr(' Note di credito collegate ').' : ' ;
2018-07-04 17:56:51 +02:00
foreach ( $note_accredito as $nota ) {
2018-07-04 12:57:53 +02:00
$text = tr ( 'Rif. fattura _NUM_ del _DATE_' , [
'_NUM_' => $nota [ 'numero' ],
'_DATE_' => Translator :: dateToLocale ( $nota [ 'data' ]),
]);
echo '
< br > '.Modules::link(' Fatture di vendita ', $nota[' id ' ], $text , $text );
}
echo '
</ div > ' ;
}
2018-07-10 16:01:28 +02:00
?>
2018-09-28 16:17:10 +02:00
{( " name " : " log_email " , " id_module " : " $id_module $ " , " id_record " : " $id_record $ " )}
2018-07-10 16:19:38 +02:00
2017-08-04 16:28:16 +02:00
< a class = " btn btn-danger ask " data - backto = " record-list " >
2017-09-04 12:02:29 +02:00
< i class = " fa fa-trash " ></ i > < ? php echo tr ( 'Elimina' ); ?>
2017-08-04 16:28:16 +02:00
</ a >
2018-07-26 16:19:34 +02:00
< ? php
2018-07-28 18:02:17 +02:00
echo '
2018-07-26 16:19:34 +02:00
< script >
2018-07-26 17:34:12 +02:00
2018-09-19 09:57:30 +02:00
$ ( " .btn-sm[data-toggle= \" tooltip \" ] " ) . each ( function () {
2018-07-28 18:02:17 +02:00
2018-10-04 17:25:42 +02:00
$ ( this ) . on ( " click " , function () {
2018-08-09 10:14:26 +02:00
form = $ ( " #edit-form " );
btn = $ ( this );
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
var restore = buttonLoading ( btn );
2018-07-26 17:34:12 +02:00
2018-11-12 16:00:57 +01:00
// Procedo al salvataggio solo se tutti i campi obbligatori sono compilati, altrimenti mostro avviso
2018-09-19 09:57:30 +02:00
if ( form . parsley () . isValid ()) {
content_was_modified = false ;
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
form . find ( " input:disabled, select:disabled " ) . removeAttr ( " disabled " );
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
$ . ajax ({
2018-09-19 10:44:32 +02:00
url : globals . rootdir + " /actions.php?id_module= " + globals . id_module ,
2018-09-19 09:57:30 +02:00
cache : false ,
type : " POST " ,
processData : false ,
dataType : " html " ,
data : form . serialize (),
success : function ( data ) {
$ ( " #main_loading " ) . fadeOut ();
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
buttonRestore ( btn , restore );
},
error : function ( data ) {
$ ( " #main_loading " ) . fadeOut ();
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
swal ( " '.tr('Errore').' " , " '.tr('Errore durante il salvataggio').' " , " error " );
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
buttonRestore ( btn , restore );
}
});
2018-07-28 18:02:17 +02:00
2018-09-19 09:57:30 +02:00
} else {
2018-07-26 17:34:12 +02:00
swal ({
2018-08-09 10:14:26 +02:00
type : " error " ,
title : " '.tr('Errore').' " ,
2018-10-04 17:25:42 +02:00
text : " '.tr('Alcuni campi obbligatori non sono stati compilati correttamente').'. " ,
2018-08-09 10:14:26 +02:00
});
2018-07-28 18:02:17 +02:00
2018-10-04 17:25:42 +02:00
$ ( " #bs-popup " ) . one ( " show.bs.modal " , function ( e ) {
return e . preventDefault ();
});
2018-07-26 17:34:12 +02:00
2018-09-19 09:57:30 +02:00
buttonRestore ( btn , restore );
2018-07-26 17:34:12 +02:00
}
2018-07-28 18:02:17 +02:00
2018-07-26 16:19:34 +02:00
});
});
</ script > ' ;
2018-07-28 18:02:17 +02:00
?>