From e970cfc9302bf8726339833bf10e89fbee314609 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Thu, 21 Sep 2017 11:02:31 +0200 Subject: [PATCH] Aggiornamento della stamoa del consuntivo dei contratti --- templates/contratti/body.php | 2 +- templates/contratti_cons/body.php | 583 ++++++++++++++++++ templates/contratti_cons/contratto.html | 18 - templates/contratti_cons/contratto_body.html | 27 - templates/contratti_cons/init.php | 11 + .../contratti_cons/pdfgen.contratti_cons.php | 341 ---------- templates/interventi/body.php | 4 +- templates/preventivi/body.php | 2 +- templates/preventivi_cons/body.php | 5 +- templates/preventivi_cons/init.php | 2 +- update/2_3.php | 3 + 11 files changed, 605 insertions(+), 393 deletions(-) create mode 100644 templates/contratti_cons/body.php delete mode 100644 templates/contratti_cons/contratto.html delete mode 100644 templates/contratti_cons/contratto_body.html create mode 100644 templates/contratti_cons/init.php delete mode 100644 templates/contratti_cons/pdfgen.contratti_cons.php diff --git a/templates/contratti/body.php b/templates/contratti/body.php index 8bb915561..2b2d248b0 100644 --- a/templates/contratti/body.php +++ b/templates/contratti/body.php @@ -16,7 +16,7 @@ echo '
- '.tr('Contratto Num. _NUM_ del _DATE_', [ + '.tr('Contratto num. _NUM_ del _DATE_', [ '_NUM_' => $records[0]['numero'], '_DATE_' => Translator::dateToLocale($records[0]['data_bozza']), ], ['upper' => true]).' diff --git a/templates/contratti_cons/body.php b/templates/contratti_cons/body.php new file mode 100644 index 000000000..7dfa34934 --- /dev/null +++ b/templates/contratti_cons/body.php @@ -0,0 +1,583 @@ + +
+
+

'.tr('Consuntivo', [], ['upper' => true]).'

+ '.tr('Contratto num. _NUM_ del _DATE_', [ + '_NUM_' => $records[0]['numero'], + '_DATE_' => Translator::dateToLocale($records[0]['data']), + ], ['upper' => true]).' +
+
+ +
+ + + + + + + + + + + + + + +
+

'.tr('Spett.le', [], ['upper' => true]).'

+

$c_ragionesociale$

+

$c_indirizzo$ $c_citta_full$

+
+

'.tr('Partita IVA', [], ['upper' => true]).'

+
+ $c_piva$ +
+

'.tr('Codice fiscale', [], ['upper' => true]).'

+
+ $c_codicefiscale$ +
+
+
'; + +// Descrizione +if (!empty($records[0]['descrizione'])) { + echo ' +

'.nl2br($records[0]['descrizione']).'

+
'; +} + +$totale_ore_impiegate = 0; + +$sconto = []; +$imponibile = []; + +$interventi = $dbo->fetchArray('SELECT *, in_interventi.id, in_interventi.codice, (SELECT GROUP_CONCAT(DISTINCT ragione_sociale) FROM in_interventi_tecnici JOIN an_anagrafiche ON an_anagrafiche.idanagrafica = in_interventi_tecnici.idtecnico WHERE idintervento=in_interventi.id) AS tecnici, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS inizio, (SELECT SUM(ore) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS ore, (SELECT SUM(km) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS km FROM co_righe_contratti JOIN in_interventi ON co_righe_contratti.idintervento=in_interventi.id WHERE co_righe_contratti.idcontratto='.prepare($idcontratto).' ORDER BY inizio DESC'); + +if (!empty($interventi)) { + // Interventi + echo " + + + + + + + + + + + + '; + + $ore = []; + $km = []; + $sconto_int = []; + $imponibile_int = []; + + foreach ($interventi as $int) { + $int = array_merge($int, get_costi_intervento($int['id'])); + $int['sconto'] = ($int['manodopera_addebito'] - $int['manodopera_scontato']) + ($int['viaggio_addebito'] - $int['viaggio_scontato']); + $int['subtotale'] = $int['manodopera_scontato'] + $int['viaggio_scontato']; + + echo ' + + '; + + echo ' + + + + + + + + '; + + // Calcolo il totale delle ore lavorate + $tecnici = $dbo->fetchArray('SELECT orario_inizio, orario_fine FROM in_interventi_tecnici WHERE idintervento='.prepare($int['id'])); + foreach ($tecnici as $tecnico) { + $totale_ore_impiegate += datediff('n', $tecnico['orario_inizio'], $tecnico['orario_fine']) / 60; + } + + $ore[] = $int['ore']; + $km[] = $int['km']; + + $sconto_int[] = $sconto; + $imponibile_int[] = $int['subtotale']; + } + + $ore = sum($ore); + $km = sum($km); + + $sconto_int = sum($sconto_int); + $imponibile_int = sum($imponibile_int); + $totale_int = $imponibile_int - $sconto_int; + + $sconto[] = $sconto_int; + $imponibile[] = $imponibile_int; + + echo ' + '; + + // Totale interventi + echo ' + + + + + + + + + + + '; + + echo ' +
".tr('Attività', [], ['upper' => true])."".tr('Ore', [], ['upper' => true])."".tr('Km', [], ['upper' => true])."".tr('Sconto', [], ['upper' => true])."".tr('Imponibile', [], ['upper' => true]).'
+ '.tr('Intervento num. _NUM_ del _DATE_', [ + '_NUM_' => $int['codice'], + '_DATE_' => Translator::dateToLocale($int['inizio']), + ]); + + if (!empty($int['tecnici'])) { + echo ' +
'.tr('Tecnici').': '.str_replace(',', ', ', $int['tecnici']).'.'; + } + + echo ' +
+ '.Translator::numberToLocale($int['ore']).' + + '.Translator::numberToLocale($int['km']).' + + '.Translator::numberToLocale($int['sconto']).' € + + '.Translator::numberToLocale($int['subtotale']).' € +
+ '.tr('Totale', [], ['upper' => true]).': + + '.Translator::numberToLocale($ore).' + + '.Translator::numberToLocale($km).' + + '.Translator::numberToLocale($sconto_int).' € + + '.Translator::numberToLocale($totale_int).' € +
'; + + $count = $dbo->fetchArray('SELECT COUNT(*) FROM `mg_articoli_interventi` WHERE idintervento IN ('.implode(',', array_column($interventi, 'id')).')'); + if (!empty($count)) { + echo ' + + + + + + + + + + + + + + + + + + '; + + $sconto_art = []; + $imponibile_art = []; + + // Articoli per intervento + foreach ($interventi as $int) { + $righe = $dbo->fetchArray("SELECT *, (SELECT codice FROM mg_articoli WHERE id=idarticolo) AS codice, (SELECT CONCAT_WS(serial, 'SN: ', ', ') FROM mg_prodotti WHERE mg_articoli_interventi.idarticolo = mg_prodotti.id_articolo) AS serials FROM `mg_articoli_interventi` WHERE idintervento =".prepare($int['id']).' ORDER BY idarticolo ASC'); + + foreach ($righe as $r) { + echo ' + '; + + // Descrizione + echo ' + '; + + // Quantità + echo ' + '; + + // Prezzo unitario + echo " + '; + + // Netto + $netto = $r['prezzo_vendita'] * $r['qta']; + echo ' + + '; + + $sconto_art[] = $r['sconto']; + $imponibile_art[] = $r['prezzo_vendita'] * $r['qta']; + } + } + + echo ' + '; + + $sconto_art = sum($sconto_art); + $imponibile_art = sum($imponibile_art); + $totale_art = $imponibile_art - $sconto_art; + + $sconto[] = $sconto_art; + $imponibile[] = $imponibile_art; + + // Totale spesa articoli + echo ' + + + + + '; + + echo ' +
+ '.tr('Materiale utilizzato', [], ['upper' => true]).' +
+ '.tr('Descrizione').' + + '.tr('Q.tà').' + + '.tr('Prezzo').' + + '.tr('Importo').' +
+ '.$r['descrizione']; + + // Codice + if (!empty($r['codice'])) { + echo ' +
'.tr('COD. _COD_', [ + '_COD_' => $r['codice'], + ]).''; + } + + echo ' +
'.tr('Intervento num. _NUM_ del _DATE_', [ + '_NUM_' => $int['id'], + '_DATE_' => Translator::dateToLocale($int['inizio']), + ]).'.'; + + echo ' +
+ '.Translator::numberToLocale($r['qta']).' '.$r['um'].' + + ".Translator::numberToLocale($r['prezzo_vendita']).' €'; + + if ($r['sconto'] > 0) { + echo " +
- ".tr('sconto _TOT_ _TYPE_', [ + '_TOT_' => Translator::numberToLocale($r['sconto_unitario']), + '_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '€'), + ]).''; + + if ($count <= 1) { + $count += 0.4; + } + } + + echo ' +
+ '.Translator::numberToLocale($netto).' €'; + + if ($r['sconto'] > 0) { + echo " +
- ".tr('sconto _TOT_ _TYPE_', [ + '_TOT_' => Translator::numberToLocale($r['sconto']), + '_TYPE_' => '€', + ]).''; + + if ($count <= 1) { + $count += 0.4; + } + } + + echo ' +
+ '.tr('Totale materiale utilizzato', [], ['upper' => true]).': + + '.Translator::numberToLocale($totale_art).' € +
'; + } + + // Altre spese per intervento + $count = $dbo->fetchArray('SELECT COUNT(*) FROM `in_righe_interventi` WHERE idintervento IN ('.implode(',', array_column($interventi, 'id')).')'); + if (!empty($count)) { + echo ' + + + + + + + + + + + + + + + + + + '; + + $sconto_spese = []; + $imponibile_spese = []; + + // Articoli per intervento + foreach ($interventi as $int) { + $righe = $dbo->fetchArray('SELECT * FROM `in_righe_interventi` WHERE idintervento ='.prepare($int['id']).' ORDER BY id ASC'); + + foreach ($righe as $r) { + echo ' + '; + + // Descrizione + echo ' + '; + + // Quantità + echo ' + '; + + // Prezzo unitario + echo " + '; + + // Netto + $netto = $r['prezzo_vendita'] * $r['qta']; + echo ' + + '; + + $sconto_spese[] = $r['sconto']; + $imponibile_spese[] = $r['prezzo_vendita'] * $r['qta']; + } + } + + echo ' + '; + + $sconto_spese = sum($sconto_spese); + $imponibile_spese = sum($imponibile_spese); + $totale_spese = $imponibile_spese - $sconto_spese; + + $sconto[] = $sconto_spese; + $imponibile[] = $imponibile_spese; + + // Totale spese aggiuntive + echo ' + + + + + '; + + echo ' +
+ '.tr('Spese aggiuntive', [], ['upper' => true]).' +
+ '.tr('Descrizione').' + + '.tr('Q.tà').' + + '.tr('Prezzo').' + + '.tr('Importo').' +
+ '.$r['descrizione']; + + echo ' +
'.tr('Intervento num. _NUM_ del _DATE_', [ + '_NUM_' => $int['id'], + '_DATE_' => Translator::dateToLocale($int['inizio']), + ]).'.'; + + echo ' +
+ '.Translator::numberToLocale($r['qta']).' '.$r['um'].' + + ".Translator::numberToLocale($r['prezzo_vendita']).' €'; + + if ($r['sconto'] > 0) { + echo " +
- ".tr('sconto _TOT_ _TYPE_', [ + '_TOT_' => Translator::numberToLocale($r['sconto_unitario']), + '_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '€'), + ]).''; + + if ($count <= 1) { + $count += 0.4; + } + } + + echo ' +
+ '.Translator::numberToLocale($netto).' €'; + + if ($r['sconto'] > 0) { + echo " +
- ".tr('sconto _TOT_ _TYPE_', [ + '_TOT_' => Translator::numberToLocale($r['sconto']), + '_TYPE_' => '€', + ]).''; + + if ($count <= 1) { + $count += 0.4; + } + } + + echo ' +
+ '.tr('Totale spese aggiuntive', [], ['upper' => true]).': + + '.Translator::numberToLocale($totale_spese).' € +
'; + } +} + +// TOTALE COSTI FINALI +$sconto = sum($sconto); +$imponibile = sum($imponibile); + +$totale = $imponibile - $sconto; + +$rs = $dbo->fetchArray("SELECT SUM(subtotale) as budget FROM `co_righe2_contratti` WHERE idcontratto = ".prepare($idcontratto)); +$budget = $rs[0]['budget']; + +$rs = $dbo->fetchArray("SELECT SUM(qta) AS totale_ore FROM `co_righe2_contratti` WHERE um='ore' AND idcontratto = ".prepare($idcontratto)); +$totale_ore = $rs[0]['totale_ore']; + +$rapporto = $budget - $totale; + +// Totale imponibile +echo ' + + + + + + '; + +// Eventuale sconto incondizionato +if (!empty($sconto)) { + echo ' + + + + + '; + + // Imponibile scontato + echo ' + + + + + '; +} + +// IVA +$rs = $dbo->fetchArray('SELECT * FROM co_iva WHERE co_iva.id = '.prepare(get_var('Iva predefinita'))); +$percentuale_iva = $rs[0]['percentuale']; +$iva = $totale / 100 * $percentuale_iva; + +echo ' + + + + + '; + +$totale = sum($totale, $iva); + +// TOTALE +echo ' + + + + '; + +// BUDGET +echo ' + + + + '; + +// RAPPORTO +echo ' + + + + '; + +// ORE RESIDUE +if (!empty($totale_ore)) { + echo ' + + + +'; +} + +echo' +
+ '.tr('Imponibile', [], ['upper' => true]).': + + '.Translator::numberToLocale($imponibile).' € +
+ '.tr('Sconto', [], ['upper' => true]).': + + -'.Translator::numberToLocale($sconto).' € +
+ '.tr('Imponibile scontato', [], ['upper' => true]).': + + '.Translator::numberToLocale($totale).' € +
+ '.tr('Iva (_PRC_%)', [ + '_PRC_' => Translator::numberToLocale($percentuale_iva, 0), + ], ['upper' => true]).': + + '.Translator::numberToLocale($iva).' € +
+ '.tr('Totale consuntivo', [], ['upper' => true]).': + + '.Translator::numberToLocale($totale).' € +
+ '.tr('Budget (no IVA)', [], ['upper' => true]).': + + '.Translator::numberToLocale($budget).' € +
+ '.tr('Rapporto budget/spesa (no IVA)', [], ['upper' => true]).': + + '.Translator::numberToLocale($rapporto).' € +
+ '.tr('Ore residue', [], ['upper' => true]).': + + '.Translator::numberToLocale($totale_ore - $totale_ore_impiegate).'
+

'.tr('Ore erogate').': '.Translator::numberToLocale($totale_ore_impiegate).'

+

'.tr('Ore in contratto').': '.Translator::numberToLocale($totale_ore).'

+
'; diff --git a/templates/contratti_cons/contratto.html b/templates/contratti_cons/contratto.html deleted file mode 100644 index e6af48f35..000000000 --- a/templates/contratti_cons/contratto.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - $body$ - diff --git a/templates/contratti_cons/contratto_body.html b/templates/contratti_cons/contratto_body.html deleted file mode 100644 index bd3b55556..000000000 --- a/templates/contratti_cons/contratto_body.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - -
- Logo
- $f_ragionesociale$ - $f_indirizzo$ - $f_citta_full$ - $f_piva$ - $f_codicefiscale$ - $f_capsoc$ - $f_telefono$ - $f_sitoweb$ - $f_email$ -
- Spett.le $c_ragionesociale$ - $c_indirizzo$ - $c_citta$ - $c_piva$ -
-
-
diff --git a/templates/contratti_cons/init.php b/templates/contratti_cons/init.php new file mode 100644 index 000000000..16e31b68d --- /dev/null +++ b/templates/contratti_cons/init.php @@ -0,0 +1,11 @@ +fetchArray('SELECT *, data_bozza AS data FROM co_contratti WHERE id='.prepare($idcontratto)); + +$id_cliente = $records[0]['idanagrafica']; +$id_sede = $records[0]['idsede']; diff --git a/templates/contratti_cons/pdfgen.contratti_cons.php b/templates/contratti_cons/pdfgen.contratti_cons.php deleted file mode 100644 index 03036f4c6..000000000 --- a/templates/contratti_cons/pdfgen.contratti_cons.php +++ /dev/null @@ -1,341 +0,0 @@ -fetchArray($q); -$idcliente = $rscontratti[0]['idanagrafica']; - -$rs = $dbo->fetchArray("SELECT SUM(qta) AS totale_ore, SUM(subtotale) as totale_budget FROM `co_righe2_contratti` WHERE um='ore' AND idcontratto=\"".$idcontratto.'"'); -$contratto_tot_ore = $rs[0]['totale_ore']; -$contratto_tot_budget = $rs[0]['totale_budget']; - -// carica report html -$report = file_get_contents($docroot.'/templates/contratti_cons/contratto.html'); -$body = file_get_contents($docroot.'/templates/contratti_cons/contratto_body.html'); - -include_once $docroot.'/templates/pdfgen_variables.php'; - -$totale = 0; -$contratti = []; -$ore = []; -$totale_ore_impiegate = 0; - -$costo_orario = []; -$costo_km = []; -$diritto_chiamata = []; - -$tot_ore_consuntivo = []; -$tot_km_consuntivo = []; -$tot_dirittochiamata = []; - -$km = []; -$ntecnici = []; -$tecnici = []; -$costi_orari = []; -$costi_km = []; -$idinterventi = ["''"]; - -// Ciclo tra le righe degli interventi da programmare -$rs_righe = $dbo->fetchArray('SELECT * FROM co_righe_contratti WHERE idcontratto="'.$idcontratto.'" ORDER BY data_richiesta ASC'); -$totrows = sizeof($rs_righe); - -for ($r = 0; $r < sizeof($rs_righe); ++$r) { - if (!empty($rs_righe[$r]['id'])) { - $totale_ore = 0; - $totale_km = 0; - $totale_diritto_chiamata = 0; - - $q = 'SELECT id, codice, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento=in_interventi.id) AS data, (SELECT SUM(km) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.id) AS km, (SELECT SUM(prezzo_ore_consuntivo) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.id) AS `tot_ore_consuntivo`, (SELECT SUM(prezzo_km_consuntivo) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.id) AS `tot_km_consuntivo` FROM in_interventi WHERE id="'.$rs_righe[$r]['idintervento'].'"'; - $rscontrattii = $dbo->fetchArray($q); - - if (sizeof($rscontrattii) == 1) { - // Lettura numero tecnici collegati all'intervento - $query = 'SELECT an_anagrafiche.idanagrafica, prezzo_ore_consuntivo, prezzo_km_consuntivo, prezzo_ore_unitario, prezzo_km_unitario, prezzo_dirittochiamata, ragione_sociale, orario_inizio, orario_fine, in_interventi_tecnici.km FROM in_interventi_tecnici LEFT OUTER JOIN an_anagrafiche ON in_interventi_tecnici.idtecnico=an_anagrafiche.idanagrafica WHERE idintervento="'.$rscontrattii[0]['id'].'"'; - $rst = $dbo->fetchArray($query); - $n_tecnici = sizeof($rst); - $tecnici_full = ''; - - $t = 0; - - for ($j = 0; $j < $n_tecnici; ++$j) { - $t1 = datediff('n', $rst[$j]['orario_inizio'], $rst[$j]['orario_fine']); - - $orario = ''; - if (floatval($t1) > 0) { - $orario .= Translator::timestampToLocale($rst[$j]['orario_inizio']).' - '.Translator::timestampToLocale($rst[$j]['orario_fine']); - } - - $tecnici_full .= ''.$rst[$j]['ragione_sociale'].' ('.$orario.')
'.Translator::numberToLocale($t1 / 60).'h x '.Translator::numberToLocale($rst[$j]['prezzo_ore_unitario']).' €/h
'.Translator::numberToLocale($rst[$j]['km']).'km x '.Translator::numberToLocale($rst[$j]['prezzo_km_unitario']).' km/h
'.Translator::numberToLocale($rst[$j]['prezzo_dirittochiamata'])."€ d.c.

\n"; - - // Conteggio ore totali - $t += $t1 / 60; - - $totale_ore += $rst[$j]['prezzo_ore_consuntivo']; - $totale_km += $rst[$j]['prezzo_km_consuntivo']; - $totale_diritto_chiamata += $rst[$j]['prezzo_dirittochiamata']; - } - - $totale_ore_impiegate += $t; - - $desc = str_replace("\n", '
', $rscontratti[$i]['descrizione']); - $line = 'Intervento '.$rscontrattii[0]['codice'].' del '.Translator::dateToLocale($rscontrattii[0]['data']).'
'.$desc; - - array_push($contratti, $line); - array_push($tot_ore_consuntivo, $totale_ore); - array_push($tot_km_consuntivo, $totale_km); - array_push($tot_dirittochiamata, $totale_diritto_chiamata); - - array_push($ntecnici, $n_tecnici); - array_push($tecnici, $tecnici_full); - array_push($idinterventi, "'".$rscontrattii[0]['codice']."'"); - } - } - - // Visualizzo i dati degli interventi programmati - else { - $line = 'Da programmare entro il '.Translator::dateToLocale($rs_righe[$r]['data_richiesta']); - - array_push($contratti, $line); - array_push($km, 0); - array_push($ore, 0); - - array_push($costo_orario, 0); - array_push($costo_km, 0); - array_push($diritto_chiamata, 0); - - array_push($tot_ore_consuntivo, 0); - array_push($tot_km_consuntivo, 0); - - array_push($ntecnici, 0); - array_push($tecnici, '-'); - } -} - -$body .= '> CONSUNTIVO CONTRATTO: '.$rscontratti[0]['nome']."\n"; -$body .= ''.str_replace("\n", '
', $rscontratti[0]['cdescrizione'])."

\n"; - -// Sostituisco i valori tra | | con il valore del campo del db -$body .= preg_replace('/|(.+?)|/', $rscontratti[0]['${1}'], $body); - -if (sizeof($contratti) > 0) { - // Tabella con riepilogo interventi, km e ore - $body .= "\n"; - $body .= "\n"; - $body .= "\n"; - $body .= "\n"; - $body .= "\n"; - $body .= "\n"; - - $body .= "\n"; - - // Tabella con i dati - for ($j = 0; $j < sizeof($contratti); ++$j) { - // Intervento (+ tecnici) - $body .= "\n"; - - // Subtotale - $subtotale = $tot_ore_consuntivo[$j] + $km[$j] * $costo_km[$j] + $diritto_chiamata[$j]; - $body .= "\n"; - $totale += $subtotale; - $totale_consuntivo += $tot_ore_consuntivo[$j] + $tot_km_consuntivo[$j]; - } - - $body .= "\n"; - - $body .= "\n"; - $body .= "\n"; - $body .= "
InterventiTecniciSubtotale
\n"; - $body .= ' '.$contratti[$j]."".$tecnici[$j]."\n"; - $body .= "\n"; - $body .= ' '.Translator::numberToLocale($subtotale)."\n"; - $body .= "
\n"; - $body .= "Totale:\n"; - $body .= "\n"; - $body .= ''.Translator::numberToLocale($totale)." €\n"; - $body .= "
\n"; -} -$body .= "
\n"; - -if (!empty($idinterventi)) { - // Conteggio articoli utilizzati - $query = "SELECT *, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento=mg_articoli_interventi.idintervento) AS data_intervento, (SELECT percentuale FROM co_iva WHERE id=mg_articoli_interventi.idiva_vendita) AS prciva_vendita, (SELECT codice FROM mg_articoli WHERE id=idarticolo) AS codice_art, (SELECT prc_guadagno FROM mg_listini WHERE id=(SELECT idlistino_vendite FROM an_anagrafiche WHERE idanagrafica=(SELECT idanagrafica FROM in_interventi WHERE id=mg_articoli_interventi.idintervento) ) ) AS prc_guadagno, CONCAT_WS(serial, 'SN: ', ', ') AS codice, SUM(qta) AS sumqta FROM `mg_articoli_interventi` JOIN mg_prodotti ON mg_articoli_interventi.idarticolo = mg_prodotti.id_articolo GROUP BY idarticolo, idintervento, lotto HAVING idintervento IN(".implode(',', $idinterventi).") AND NOT idarticolo='0' ORDER BY idarticolo ASC"; - $rs2 = $dbo->fetchArray($query); - - if (sizeof($rs2) > 0) { - $body .= "\n"; - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $totale_articoli = 0.00; - - for ($i = 0; $i < sizeof($rs2); ++$i) { - // Articolo - $body .= "\n"; - - // Quantità - $qta = $rs2[$i]['sumqta']; - $body .= "\n"; - - // Prezzo unitario - $body .= "\n"; - - // Prezzo di vendita - $body .= "\n"; - $totale_articoli += $netto * $qta; - } - - // Totale spesa articoli - $body .= "\n"; - - $body .= "\n"; - $body .= "
Materiale utilizzato per gli interventi
\n"; - $body .= "Articolo\n"; - $body .= "\n"; - $body .= "Q.tà\n"; - $body .= "\n"; - $body .= "Prezzo unitario\n"; - $body .= "\n"; - $body .= "Subtot\n"; - $body .= "
\n"; - $body .= ''.nl2br($rs2[$i]['descrizione'])."\n"; - if ($rs2[$i]['codice'] != '' && $rs2[$i]['codice'] != 'Lotto: , SN: , Altro: ') { - $body .= '
'.$rs2[$i]['codice']."\n"; - } - - $body .= '
Intervento del '.Translator::dateToLocale($rs2[$i]['data_intervento'])."\n"; - $body .= "
\n"; - $body .= ''.$rs2[$i]['sumqta']."\n"; - $body .= "\n"; - $netto = $rs2[$i]['prezzo_vendita']; - $netto = $netto + $netto / 100 * $rs2[$i]['prc_guadagno']; - $iva = $netto / 100 * $rs2[$i]['prciva_vendita']; - $body .= ''.Translator::numberToLocale($netto)." €\n"; - $body .= "\n"; - $body .= "".Translator::numberToLocale($netto * $qta)."\n"; - $body .= "
\n"; - $body .= "TOTALE MATERIALE UTILIZZATO:\n"; - $body .= "\n"; - $body .= ''.Translator::numberToLocale($totale_articoli)." €\n"; - $body .= "

\n"; - } -} - -if (!empty($idinterventi)) { - // Conteggio spese aggiuntive - $query = 'SELECT *, (SELECT MIN(orario_inizio) FROM in_interventi_tecnici WHERE idintervento=in_righe_interventi.idintervento) AS data_intervento FROM in_righe_interventi WHERE idintervento IN('.implode(',', $idinterventi).') ORDER BY id ASC'; - $rs2 = $dbo->fetchArray($query); - - if (sizeof($rs2) > 0) { - $body .= "\n"; - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $body .= "\n"; - - $totale_spese = 0.00; - - for ($i = 0; $i < sizeof($rs2); ++$i) { - // Articolo - $body .= "\n"; - - // Quantità - $qta = $rs2[$i]['qta']; - $body .= "\n"; - - // Prezzo unitario - $body .= "\n"; - - // Prezzo di vendita - $body .= "\n"; - $totale_spese += $netto * $qta; - } - // Totale spese aggiuntive - $body .= "\n"; - - $body .= "\n"; - $body .= "
Spese aggiuntive
\n"; - $body .= "Descrizione\n"; - $body .= "\n"; - $body .= "Q.tà\n"; - $body .= "\n"; - $body .= "Prezzo unitario\n"; - $body .= "\n"; - $body .= "Subtot\n"; - $body .= "
\n"; - $body .= ''.$rs2[$i]['descrizione']."
\n"; - $body .= 'Intervento del '.Translator::dateToLocale($rs2[$i]['data_intervento'])."\n"; - $body .= "
\n"; - $body .= ''.Translator::numberToLocale($rs2[$i]['qta'])."\n"; - $body .= "\n"; - $netto = $rs2[$i]['prezzo']; - $body .= ''.Translator::numberToLocale($netto)." €\n"; - $body .= "\n"; - $body .= ''.Translator::numberToLocale($netto * $qta)." €\n"; - $body .= "
\n"; - $body .= "ALTRE SPESE:\n"; - $body .= "\n"; - $body .= ''.Translator::numberToLocale($totale_spese)." €\n"; - $body .= "

\n"; - } -} - -// Totale complessivo intervento -$body .= "\n"; - -$body .= "\n"; -$body .= "\n"; - -$body .= "\n"; - -$body .= "\n"; - -$body .= "\n"; - -$diff = Translator::numberToLocale($contratto_tot_budget - $totale_intervento_consuntivo); -$body .= "\n"; - -if (!empty($contratto_tot_ore)) { - $body .= "\n"; - - $body .= "\n"; -} - -$body .= "
\n"; -$body .= "TOTALE CONSUNTIVO:\n"; -$body .= "\n"; -$totale_intervento_consuntivo = Translator::numberToLocale($totale + $totale_articoli + $totale_spese); -$body .= ''.$totale_intervento_consuntivo." €\n"; -$body .= "
\n"; -$body .= "BUDGET TOTALE (NO IVA):\n"; -$body .= "\n"; -$contratto_tot_budget = Translator::numberToLocale($contratto_tot_budget); -$body .= ''.$contratto_tot_budget." €\n"; -$body .= "
\n"; -$body .= "RAPPORTO BUDGET/SPESA (NO IVA):\n"; -$body .= "\n"; -$body .= ''.$diff." €\n"; -$body .= "
\n"; - $body .= "ORE RESIDUE:\n"; - $body .= "\n"; - $diff2 = Translator::numberToLocale($contratto_tot_ore - $totale_ore_impiegate); - $body .= "$diff2  (ore erogate: ".Translator::numberToLocale($totale_ore_impiegate).' - ore in contratto: '.Translator::numberToLocale($contratto_tot_ore).")\n"; - $body .= "
\n"; - -$report_name = 'contratto_'.$idcontratto.'_cons.pdf'; diff --git a/templates/interventi/body.php b/templates/interventi/body.php index 3e6b4e216..88923256a 100644 --- a/templates/interventi/body.php +++ b/templates/interventi/body.php @@ -18,8 +18,8 @@ echo ' '.tr('Intervento numero').': '.$records[0]['codice'].' '.tr('Data').': '.Translator::dateToLocale($records[0]['data_richiesta']).' - '.tr('Preventivo Num.').': '.$records[0]['numero_preventivo'].' - '.tr('Contratto Num.').': '.$records[0]['numero_contratto'].' + '.tr('Preventivo num.').': '.$records[0]['numero_preventivo'].' + '.tr('Contratto num.').': '.$records[0]['numero_contratto'].' '; // Dati cliente diff --git a/templates/preventivi/body.php b/templates/preventivi/body.php index dac57f8b3..d8f36638b 100644 --- a/templates/preventivi/body.php +++ b/templates/preventivi/body.php @@ -16,7 +16,7 @@ echo '
- '.tr('Preventivo Num. _NUM_ del _DATE_', [ + '.tr('Preventivo num. _NUM_ del _DATE_', [ '_NUM_' => $records[0]['numero'], '_DATE_' => Translator::dateToLocale($records[0]['data']), ], ['upper' => true]).' diff --git a/templates/preventivi_cons/body.php b/templates/preventivi_cons/body.php index 02456c7fb..41791aa77 100644 --- a/templates/preventivi_cons/body.php +++ b/templates/preventivi_cons/body.php @@ -9,8 +9,9 @@ $report_name = 'preventivo_'.$idpreventivo.'_cons.pdf'; echo '
-
- '.tr('Preventivo Num. _NUM_ del _DATE_', [ +
+

'.tr('Consuntivo', [], ['upper' => true]).'

+ '.tr('Preventivo num. _NUM_ del _DATE_', [ '_NUM_' => $records[0]['numero'], '_DATE_' => Translator::dateToLocale($records[0]['data']), ], ['upper' => true]).' diff --git a/templates/preventivi_cons/init.php b/templates/preventivi_cons/init.php index fa3cbe657..beb880fec 100644 --- a/templates/preventivi_cons/init.php +++ b/templates/preventivi_cons/init.php @@ -5,7 +5,7 @@ include_once __DIR__.'/../../core.php'; $module_name = 'Preventivi'; // Lettura info fattura -$records = $dbo->fetchArray('SELECT *, data_bozza AS data FROM co_preventivi WHERE co_preventivi.id='.prepare($idpreventivo)); +$records = $dbo->fetchArray('SELECT *, data_bozza AS data FROM co_preventivi WHERE id='.prepare($idpreventivo)); $id_cliente = $records[0]['idanagrafica']; $id_sede = $records[0]['idsede']; diff --git a/update/2_3.php b/update/2_3.php index ae03d55e8..bf417a246 100644 --- a/update/2_3.php +++ b/update/2_3.php @@ -99,6 +99,9 @@ $files = [ 'templates/preventivi_cons/preventivo_body.html', 'templates/preventivi_cons/preventivo.html', 'templates/preventivi_cons/pdfgen.preventivi_cons.php', + 'templates/contratti_cons/contratto_body.html', + 'templates/contratti_cons/contratto.html', + 'templates/contratti_cons/pdfgen.contratti_cons.php', 'update/install_2.0.sql', 'update/update_2.1.sql', 'update/update_2.1.php',