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 ;
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' ) {
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-02-11 20:24:29 +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-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-03-22 15:04:26 +01:00
$label = tr ( 'Numero 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 " >
2018-03-20 00:57:36 +01:00
{[ " type " : " text " , " label " : " <?php echo $label ; ?> " , " name " : " numero_esterno " , " class " : " alphanumeric-mask text-center " , " value " : " $numero_esterno $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " date " , " label " : " <?php echo tr('Data emissione'); ?> " , " maxlength " : 10 , " 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 >
</ 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' ) {
?>
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Cliente'); ?> " , " name " : " idanagrafica " , " required " : 1 , " ajax-source " : " clienti " , " 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 >
< ? 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' ) {
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 '
2017-10-12 20:10:27 +02:00
< p > '.Translator::dateToLocale($scadenza[' scadenza ']).' : '.Translator::numberToLocale($scadenza[' da_pagare ']).' & euro ; </ p > ' ;
2017-08-04 16:28:16 +02:00
}
echo '
</ div > ' ;
}
?>
</ div >
< hr >
< div class = " row " >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02: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' ); ?> ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2018-07-16 17:38:47 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Pagamento'); ?> " , " name " : " idpagamento " , " required " : 1 , " values " : " query=SELECT id, 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-08-03 09:34:06 +02: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 $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< ? php
if ( $dir == 'uscita' ) {
?>
< div class = " row " >
< div class = " col-md-3 " >
2017-09-18 18:34:13 +02:00
{[ " 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_ €', [
2018-07-08 18:11:17 +02:00
'_TOT_' => Translator :: numberToLocale ( setting ( " Soglia minima per l'applicazione della marca da bollo " )),
2017-09-18 17:24:25 +02:00
]), '.' ; ?> " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< ? php
}
?>
< div class = " pull-right " >
< ? php
2018-09-27 15:50:03 +02:00
if ( ! empty ( $record [ 'is_fiscale' ])) {
2018-10-04 17:41:31 +02:00
// Aggiunta prima nota solo se non c'è già, se non si è in bozza o se il pagamento non è completo
2018-09-27 15:50:03 +02:00
$n2 = $dbo -> fetchNum ( 'SELECT id FROM co_movimenti WHERE iddocumento=' . prepare ( $id_record ) . ' AND primanota=1' );
2017-08-04 16:28:16 +02:00
2018-09-27 15:50:03 +02:00
$rs3 = $dbo -> fetchArray ( 'SELECT SUM(da_pagare-pagato) AS differenza, SUM(da_pagare) FROM co_scadenziario GROUP BY iddocumento HAVING iddocumento=' . prepare ( $id_record ));
$differenza = isset ( $rs3 [ 0 ]) ? $rs3 [ 0 ][ 'differenza' ] : null ;
$da_pagare = isset ( $rs3 [ 0 ]) ? $rs3 [ 0 ][ 'da_pagare' ] : null ;
2017-08-04 16:28:16 +02:00
2018-09-27 15:50:03 +02:00
if (( $n2 <= 0 && $record [ 'stato' ] == 'Emessa' ) || $differenza != 0 ) {
?>
2018-02-09 14:25:40 +01:00
< a class = " btn btn-sm btn-primary " href = " javascript:; " onclick = " launch_modal( 'Aggiungi prima nota', '<?php echo $rootdir ; ?>/add.php?id_module=<?php echo Modules::get('Prima nota')['id']; ?>&iddocumento=<?php echo $id_record ; ?>&dir=<?php echo $dir ; ?>', 1 ); " >< i class = " fa fa-euro " ></ i > < ? php echo tr ( 'Aggiungi prima nota' ); ?> ...</a><br><br>
2017-08-04 16:28:16 +02:00
< ? php
2018-09-27 15:50:03 +02:00
}
2017-08-04 16:28:16 +02:00
2018-09-27 15:50:03 +02:00
if ( $record [ 'stato' ] == 'Pagato' ) {
?>
2018-10-30 10:27:44 +01:00
< a class = " btn btn-sm btn-primary " href = " javascript:; " onclick = " if( confirm('Se riapri questa fattura verrà azzerato lo scadenzario e la prima nota. Continuare?') ) { $ .post( '<?php echo $rootdir ; ?>/editor.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>', { id_module: '<?php echo $id_module ; ?>', id_record: '<?php echo $id_record ; ?>', op: 'reopen' }, function() { location.href='<?php echo $rootdir ; ?>/editor.php?id_module=<?php echo $id_module ; ?>&id_record=<?php echo $id_record ; ?>'; } ); } " title = " Aggiungi prima nota " >< i class = " fa fa-folder-open " ></ i > < ? php echo tr ( 'Riapri fattura' ); ?> ...</a>
2017-08-04 16:28:16 +02:00
< ? php
2018-09-27 15:50:03 +02:00
}
2017-08-04 16:28:16 +02:00
}
?>
</ div >
< div class = " clearfix " ></ div >
< div class = " row " >
< div class = " col-md-3 " >
2018-02-09 14:25:40 +01:00
{[ " type " : " number " , " label " : " <?php echo tr('Sconto incondizionato'); ?> " , " name " : " sconto_generico " , " value " : " $sconto_globale $ " , " help " : " <?php echo tr('Sconto complessivo della fattura.'); ?> " , " icon-after " : " choice|untprc| $tipo_sconto_globale $ " < ? php
2018-07-18 15:20:10 +02:00
if ( $record [ 'stato' ] == 'Emessa' ) {
2017-08-28 15:01:02 +02:00
echo ', "disabled" : 1' ;
}
?> ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2017-09-18 18:34:13 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note'); ?> " , " name " : " note " , " help " : " <?php echo tr('Note visibili anche in stampa.'); ?> " , " value " : " $note $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
< div class = " row " >
< div class = " col-md-12 " >
2017-09-18 18:34:13 +02:00
{[ " type " : " textarea " , " label " : " <?php echo tr('Note aggiuntive'); ?> " , " name " : " note_aggiuntive " , " help " : " <?php echo tr('Note interne.'); ?> " , " value " : " $note_aggiuntive $ " ]}
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 " >
{[ " type " : " select " , " label " : " '.tr('Aspetto beni').' " , " name " : " idaspettobeni " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_aspettobeni ORDER BY descrizione ASC " , " value " : " $idaspettobeni $ " ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " '.tr('Causale trasporto').' " , " name " : " idcausalet " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_causalet ORDER BY descrizione ASC " , " value " : " $idcausalet $ " ]}
</ div >
< div class = " col-md-3 " >
{[ " type " : " select " , " label " : " '.tr('Porto').' " , " name " : " idporto " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_porto ORDER BY descrizione ASC " , " value " : " $idporto $ " ]}
</ 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-09-24 18:10:16 +02:00
{[ " type " : " select " , " label " : " '.tr('Vettore').' " , " name " : " idvettore " , " values " : " query=SELECT DISTINCT an_anagrafiche.idanagrafica AS id, an_anagrafiche.ragione_sociale AS descrizione FROM an_anagrafiche INNER JOIN an_tipianagrafiche_anagrafiche ON an_anagrafiche.idanagrafica=an_tipianagrafiche_anagrafiche.idanagrafica WHERE an_tipianagrafiche_anagrafiche.idtipoanagrafica=(SELECT idtipoanagrafica FROM an_tipianagrafiche WHERE descrizione= \ 'Vettore \ ') ORDER BY descrizione ASC " , " value " : " $idvettore $ " , " required " : 1 ]}
2018-09-24 11:24:48 +02:00
</ div >
</ 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
2018-10-30 10:27:44 +01:00
$prev_query = 'SELECT COUNT(*) AS tot FROM co_preventivi WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . " AND id NOT IN (SELECT idpreventivo FROM co_righe_documenti WHERE NOT idpreventivo=NULL) 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 " ;
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
2018-07-18 15:20:10 +02:00
$contr_query = 'SELECT COUNT(*) AS tot FROM co_contratti WHERE idanagrafica=' . prepare ( $record [ 'idanagrafica' ]) . ' AND id NOT IN (SELECT idcontratto FROM co_righe_documenti WHERE NOT idcontratto=NULL) AND idstato IN( SELECT id FROM co_staticontratti WHERE fatturabile = 1) AND NOT EXISTS (SELECT id FROM co_righe_documenti WHERE co_righe_documenti.idcontratto = co_contratti.id)' ;
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
< script type = " text/javascript " >
$ ( '#idanagrafica' ) . change ( function (){
session_set ( 'superselect,idanagrafica' , $ ( this ) . val (), 0 );
$ ( " #idsede " ) . selectReset ();
});
</ script >
2018-07-04 12:57:53 +02:00
< ? php
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 () {
if ( ! content_was_modified ) {
return ;
}
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-08-09 10:14:26 +02:00
// Procedo al salvataggio solo se tutti i campi obbligatori sono compilati, altimenti 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
?>