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 >
< div class = " col-md-3 " >
2018-07-18 15:20:10 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Stato'); ?> " , " name " : " idstatodocumento " , " required " : 1 , " values " : " query=SELECT * FROM co_statidocumento " , " value " : " $idstatodocumento $ " , " class " : " unblockable " , " extra " : " onchange = \" if ( $ ('#idstatodocumento option:selected').text()=='Pagato') { if( confirm('Sicuri di voler impostare manualmente la fattura come pagata senza aggiungerla 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 {
?>
2017-09-04 12:02:29 +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 " >
2017-09-18 18:34:13 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Riferimento sede'); ?> " , " name " : " idsede " , " ajax-source " : " sedi " , " 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-07-17 08:05:19 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Banca'); ?> " , " name " : " idbanca " , " required " : 0 , " 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 ( $tipodoc == 'Fattura accompagnatoria di vendita' ) {
2018-06-26 10:25:50 +02:00
?>
2017-08-04 16:28:16 +02:00
< div class = " row " >
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Aspetto beni'); ?> " , " name " : " idaspettobeni " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_aspettobeni ORDER BY descrizione ASC " , " value " : " $idaspettobeni $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Causale trasporto'); ?> " , " name " : " idcausalet " , " placeholder " : " - " , " values " : " query=SELECT id, descrizione FROM dt_causalet ORDER BY descrizione ASC " , " value " : " $idcausalet $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2017-09-04 12:02:29 +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 $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
< div class = " col-md-3 " >
2017-09-14 10:27:49 +02:00
{[ " type " : " text " , " label " : " <?php echo tr('Num. colli'); ?> " , " name " : " n_colli " , " value " : " $n_colli $ " ]}
2017-08-04 16:28:16 +02:00
</ div >
</ div >
2017-08-31 16:23:26 +02:00
< div class = " row " >
< div class = " col-md-3 " >
2017-09-04 12:02:29 +02:00
{[ " type " : " select " , " label " : " <?php echo tr('Tipo di spedizione'); ?> " , " name " : " idspedizione " , " values " : " query=SELECT id, descrizione FROM dt_spedizione ORDER BY descrizione ASC " , " value " : " $idspedizione $ " ]}
2017-08-31 16:23:26 +02:00
</ div >
< div class = " col-md-3 " >
2017-11-14 19:14:41 +01:00
{[ " type " : " select " , " label " : " <?php echo 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 $ " ]}
2017-08-31 16:23:26 +02:00
</ div >
</ div >
2017-08-04 16:28:16 +02:00
< ? php
2018-06-26 10:25:50 +02:00
}
2017-08-04 16:28:16 +02:00
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
2017-09-19 16:20:44 +02:00
// Aggiunta prima nota solo se non c'è già, se non si è in bozza o se il pagamento non è completo
2018-06-26 10:25:50 +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-06-26 10:25:50 +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-07-18 15:20:10 +02:00
if (( $n2 <= 0 && $record [ 'stato' ] == 'Emessa' ) || $differenza != 0 ) {
2017-08-04 16:28:16 +02:00
?>
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-07-18 15:20:10 +02:00
if ( $record [ 'stato' ] == 'Pagato' ) {
2017-08-04 16:28:16 +02:00
?>
2018-02-09 14:25:40 +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 Modules::get( $name )['id']; ?>&id_record=<?php echo $id_record ; ?>', { id_module: '<?php echo Modules::get( $name )['id']; ?>', id_record: '<?php echo $id_record ; ?>', op: 'reopen' }, function() { location.href='<?php echo $rootdir ; ?>/editor.php?id_module=<?php echo Modules::get( $name )['id']; ?>&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
}
?>
</ 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 >
</ 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-07-18 15:20:10 +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 NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND in_interventi.id NOT IN (SELECT idintervento FROM co_contratti_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-07-18 15:20:10 +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 NOT IN (SELECT idintervento FROM co_preventivi_interventi WHERE idintervento IS NOT NULL) AND in_interventi.id NOT IN (SELECT idintervento FROM co_contratti_promemoria WHERE idintervento IS NOT NULL)' ;
2018-07-03 17:28:02 +02:00
$interventi = $dbo -> fetchArray ( $int_query )[ 0 ][ 'tot' ];
}
echo '
2018-07-27 16:17:14 +02:00
< div class = " tip " data - toggle = " tooltip " title = " '.tr('Interventi non collegati a preventivi o contratti.').' " style = " display:inline; " >
< 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 " data - target = " #bs-popup " >
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-07-18 15:20:10 +02: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') " ;
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; " >
< 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 " data - target = " #bs-popup " >
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; " >
< 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 " data - target = " #bs-popup " >
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
$ddt_query = 'SELECT COUNT(*) AS tot FROM dt_ddt WHERE idanagrafica=' . prepare ( $records [ 0 ][ '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)' ;
$ddt = $dbo -> fetchArray ( $ddt_query )[ 0 ][ 'tot' ];
echo '
2018-07-26 10:35:48 +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 " data - target = " #bs-popup " >
< 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-06-25 11:44:06 +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 " data - target = " #bs-popup " >
< 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-06-15 15:57:32 +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 " data - target = " #bs-popup " >
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-06-15 15:57:32 +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 " data - target = " #bs-popup " >
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-06-15 15:57:32 +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 " data - target = " #bs-popup " >
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-02-09 14:25:40 +01:00
{( " name " : " filelist_and_upload " , " id_module " : " <?php echo $id_module ; ?> " , " id_record " : " <?php echo $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 '
< div class = " alert alert-info text-center " > '.tr(' Note di accredito 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
?>
< ? php
2018-07-10 16:19:38 +02:00
// Visualizzo il log delle operazioni di invio email
$operations = $dbo -> fetchArray ( 'SELECT created_at, (SELECT name FROM zz_emails WHERE id = id_email) AS email, (SELECT username FROM zz_users WHERE id = id_utente) AS user FROM zz_operations WHERE id_record = ' . prepare ( $id_record ) . ' AND op = "send-email" ORDER BY created_at DESC' );
// Se la mail è stata inviata, mostro la data
if ( ! empty ( $operations )) {
foreach ( $operations as $operation ) {
echo '
< span class = " label label-success pull-right " >
'.tr(' _EMAIL_ inviata il _DATE_ alle _HOUR_ da _USER_ . ' , [
'_EMAIL_' => $operation [ 'email' ],
'_DATE_' => Translator :: dateToLocale ( $operation [ 'data' ]),
'_HOUR_' => Translator :: timeToLocale ( $operation [ 'ora' ]),
'_USER_' => $operation [ 'user' ],
]) . '
</ span >< br > ' ;
}
} else {
echo '
< span class = " label label-warning pull-right " >
'.tr(' Nessuna email inviata al cliente . ').'
</ span > ' ;
}
2018-07-04 12:57:53 +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-07-26 16:19:34 +02:00
$ ( " .btn-sm[data-toggle= \" tooltip \" ] " ) . each ( function () {
2018-07-28 18:02:17 +02:00
2018-07-26 16:19:34 +02:00
$ ( this ) . on ( " click " , function (){
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
form = $ ( " #edit-form " );
2018-07-28 18:02:17 +02:00
btn = $ ( this );
2018-07-26 17:34:12 +02:00
prev_html = btn . html ();
prev_class = btn . attr ( " class " );
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
btn . html ( " <i class= \" fa fa-spinner fa-pulse fa-fw \" ></i> Attendere... " );
btn . addClass ( " btn-warning " );
btn . prop ( " disabled " , true );
function restore_btn ( btn , prev_html , prev_class ){
btn . attr ( " class " , " " );
btn . addClass ( prev_class );
btn . html ( prev_html );
btn . prop ( " disabled " , false );
}
//Procedo al salvataggio solo se tutti i campi obbligatori sono compilati, altimenti mostro avviso
if ( form . parsley () . isValid ()){
2018-07-28 18:02:17 +02:00
2018-07-26 16:19:34 +02:00
content_was_modified = false ;
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
form . find ( " input:disabled, select:disabled " ) . removeAttr ( " disabled " );
2018-07-28 18:02:17 +02:00
2018-07-26 16:19:34 +02:00
$ . ajax ({
url : " '.ROOTDIR.'/modules/fatture/actions.php?id_module= " + globals . id_module ,
cache : false ,
type : " POST " ,
processData : false ,
dataType : " html " ,
2018-07-26 17:34:12 +02:00
data : form . serialize (),
2018-07-26 16:19:34 +02:00
success : function ( data ) {
$ ( " #main_loading " ) . fadeOut ();
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
restore_btn ( btn , prev_html , prev_class );
2018-07-26 16:19:34 +02:00
},
error : function ( data ) {
$ ( " #main_loading " ) . fadeOut ();
2018-07-28 18:02:17 +02:00
2018-07-26 16:19:34 +02:00
swal ( " '.tr('Errore').' " , " '.tr('Errore durante il salvataggio').' " , " error " );
session_set ( " errors,0 " , 0 , 1 );
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
restore_btn ( btn , prev_html , prev_class );
2018-07-26 16:19:34 +02:00
}
2018-07-26 17:34:12 +02:00
});
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
} else {
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
swal ({
type : " error " ,
text : " '.tr('Alcuni campi obbligatori non sono stati compilati correttamente.').' " ,
2018-07-28 18:02:17 +02:00
title : " '.tr('Errore').' " ,
2018-07-26 17:34:12 +02:00
onClose : hide_popup
}) . then ( function () {
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
});
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
function hide_popup (){
$ ( " #bs-popup " ) . modal ( " hide " );
2018-07-28 18:02:17 +02:00
2018-07-26 17:34:12 +02:00
session_set ( " errors,0 " , 0 , 1 );
2018-07-28 18:02:17 +02:00
form . parsley () . validate ();
2018-07-26 17:34:12 +02:00
}
restore_btn ( btn , prev_html , prev_class );
}
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
?>