GlisWeb framework
_fatture.duplica.php
Vai alla documentazione di questo file.
1 <?php
2 
14  // inclusione del framework
15  require '../../../../../_src/_config.php';
16 
17 
18  // verifica dati
19  if( isset($_REQUEST['old']) && isset($_REQUEST['id_cliente']) && isset($_REQUEST['numero']) ){
20 
21  // log
22  logWrite( 'richiesta duplicazione fattura ' . $_REQUEST['old'] . ' id_cliente ' . $_REQUEST['id_cliente'], 'fatture', LOG_ERR );
23 
25 // die(print_r( $fattura ) );
26 
27  if(isset($fattura)){
28 
29  // duplico la fattura la fattura
30  $id = mysqlQuery($cf['mysql']['connection'],
31  'INSERT INTO documenti_amministrativi ( id_tipologia, numero, data, id_cliente, id_emittente ) VALUES ( ?, ?, ?, ?, ? ) ',
32  array(
33  array( 's' => '1' ),
34  array( 's' => $_REQUEST['numero'] ),
35  array( 's' => date('Y-m-d') ),
36  array( 's' => $_REQUEST['id_cliente'] ),
37  array( 's' => $fattura['righe'][0]['id_emittente'] )
38  ));
39 
40  // duplico le righe
41  if(isset($id)){
42  foreach($fattura['righe'] as $riga ){
43 
44  $idGenitore = mysqlQuery($cf['mysql']['connection'],
45  'INSERT INTO righe_documenti_amministrativi ( id_tipologia, id_documento, id_cliente, id_emittente, id_riferimento, id_articolo, id_udm, ordine,'.
46  ' quantita, data_lavorazione, data_fatturabile, id_listino, id_valuta, importo_netto_totale, id_iva, nome ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ',
47  array(
48  array( 's' => $riga['id_tipologia'] ),
49  array( 's' => $id ),
50  array( 's' => $_REQUEST['id_cliente'] ),
51  array( 's' => $riga['id_emittente'] ),
52  array( 's' => $riga['id_riferimento'] ),
53  array( 's' => $riga['id_articolo'] ),
54  array( 's' => $riga['id_udm'] ),
55  array( 's' => $riga['ordine'] ),
56  array( 's' => $riga['quantita'] ),
57  array( 's' => date('Y-m-d', strtotime($riga['data_lavorazione']) )),
58  array( 's' => $riga['data_fatturabile'] ),
59  array( 's' => $riga['id_listino'] ),
60  array( 's' => $riga['id_valuta'] ),
61  array( 's' => $riga['importo_netto_totale'] ),
62  array( 's' => $riga['id_iva'] ),
63  array( 's' => $riga['nome'] )
64  ));
65 
66  logWrite( 'duplicazione riga ' . $riga['id'].' -> '.$idGenitore, 'fatture', LOG_ERR );
67 
68 
69  if(isset($idGenitore) && sizeof($riga['aggregate']>0 )){
70  // duplico le aggregate se sono presente e se la riga รจ stata inserita con successo
71  foreach($riga['aggregate'] as $rigaA ){
72  $idAggregata = mysqlQuery($cf['mysql']['connection'],
73  'INSERT INTO righe_documenti_amministrativi ( id_genitore, id_tipologia, id_documento, id_cliente, id_emittente, id_riferimento, id_articolo, id_udm, ordine,'.
74  ' quantita, data_lavorazione, data_fatturabile, id_listino, id_valuta, importo_netto_totale, id_iva, nome ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) ',
75  array(
76  array( 's' => $idGenitore ),
77  array( 's' => $rigaA['id_tipologia'] ),
78  array( 's' => $id ),
79  array( 's' => $_REQUEST['id_cliente'] ),
80  array( 's' => $rigaA['id_emittente'] ),
81  array( 's' => $rigaA['id_riferimento'] ),
82  array( 's' => $rigaA['id_articolo'] ),
83  array( 's' => $rigaA['id_udm'] ),
84  array( 's' => $rigaA['ordine'] ),
85  array( 's' => $rigaA['quantita'] ),
86  array( 's' => date('Y-m-d', strtotime($riga['data_lavorazione']) )),
87  array( 's' => $rigaA['data_fatturabile'] ),
88  array( 's' => $rigaA['id_listino'] ),
89  array( 's' => $rigaA['id_valuta'] ),
90  array( 's' => $rigaA['importo_netto_totale'] ),
91  array( 's' => $rigaA['id_iva'] ),
92  array( 's' => $rigaA['nome'] )
93  ));
94 
95  logWrite( 'duplicazione riga aggregata ' . $rigaA['id'].' -> '.$idAggregata, 'fatture', LOG_ERR );
96 
97 
98  }}
99  }
100 
101  } else {buildJson( array( 'error' => true ) );}
102 
103 
104  // log
105  logWrite( 'inserita fattura '.$id, 'fatture', LOG_ERR );
106 
107 
108 
109  } else {buildJson( array( 'error' => true ) );}
110 
111 
112  } else {
113 
114  buildJson( array( 'error' => true ) );
115 
116  }
117 
118 ?>
docAmministrativiGetRighe( $id)
logWrite( $m, $f='site', $l=LOG_NOTICE, $d=DIRECTORY_LOG, $t=CURRENT_LOG_LEVEL, $s=SITE_STATUS)
scrive un messaggio nei log del sito
Definition: _log.utils.php:48
mysqlQuery( $c, $q, $p=false, &$e=array())
$cf['ricerca']['template']
Definition: _030.common.php:7
buildJson( $content, $encoding=ENCODING_UTF8, $headers=array())
$_REQUEST['__view__'][ $ct['view']['id']]['__restrict__']['id_progetto']['EQ']