Aggiornamento della stamoa del consuntivo dei contratti

This commit is contained in:
Thomas Zilio 2017-09-21 11:02:31 +02:00
parent 2b581ff303
commit e970cfc930
11 changed files with 605 additions and 393 deletions

View File

@ -16,7 +16,7 @@ echo '
<div class="row">
<div class="col-xs-6">
<div class="text-center" style="height:5mm;">
<b>'.tr('Contratto Num. _NUM_ del _DATE_', [
<b>'.tr('Contratto num. _NUM_ del _DATE_', [
'_NUM_' => $records[0]['numero'],
'_DATE_' => Translator::dateToLocale($records[0]['data_bozza']),
], ['upper' => true]).'</b>

View File

@ -0,0 +1,583 @@
<?php
include_once __DIR__.'/../../core.php';
include_once $docroot.'/modules/interventi/modutil.php';
$report_name = 'contratto_'.$idcontratto.'_cons.pdf';
echo '
<div class="row">
<div class="col-xs-6">
<div class="text-center">
<h4 class="text-bold">'.tr('Consuntivo', [], ['upper' => true]).'</h4>
<b>'.tr('Contratto num. _NUM_ del _DATE_', [
'_NUM_' => $records[0]['numero'],
'_DATE_' => Translator::dateToLocale($records[0]['data']),
], ['upper' => true]).'</b>
</div>
</div>
<div class="col-xs-5 col-xs-offset-1">
<table class="table" style="width:100%;margin-top:5mm;">
<tr>
<td colspan=2 class="border-full" style="height:16mm;">
<p class="small-bold">'.tr('Spett.le', [], ['upper' => true]).'</p>
<p>$c_ragionesociale$</p>
<p>$c_indirizzo$ $c_citta_full$</p>
</td>
</tr>
<tr>
<td class="border-bottom border-left">
<p class="small-bold">'.tr('Partita IVA', [], ['upper' => true]).'</p>
</td>
<td class="border-right border-bottom text-right">
<small>$c_piva$</small>
</td>
</tr>
<tr>
<td class="border-bottom border-left">
<p class="small-bold">'.tr('Codice fiscale', [], ['upper' => true]).'</p>
</td>
<td class="border-right border-bottom text-right">
<small>$c_codicefiscale$</small>
</td>
</tr>
</table>
</div>
</div>';
// Descrizione
if (!empty($records[0]['descrizione'])) {
echo '
<p>'.nl2br($records[0]['descrizione']).'</p>
<br>';
}
$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 "
<table class='table table-striped table-bordered' id='contents'>
<thead>
<tr>
<th class='text-center' style='width:50%'>".tr('Attività', [], ['upper' => true])."</th>
<th class='text-center' style='width:10%'>".tr('Ore', [], ['upper' => true])."</th>
<th class='text-center' style='width:15%'>".tr('Km', [], ['upper' => true])."</th>
<th class='text-center' style='width:15%'>".tr('Sconto', [], ['upper' => true])."</th>
<th class='text-center' style='width:10%'>".tr('Imponibile', [], ['upper' => true]).'</th>
</tr>
</thead>
<tbody>';
$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 '
<tr>
<td>
'.tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $int['codice'],
'_DATE_' => Translator::dateToLocale($int['inizio']),
]);
if (!empty($int['tecnici'])) {
echo '
<br><small class="text-muted">'.tr('Tecnici').': '.str_replace(',', ', ', $int['tecnici']).'.</small>';
}
echo '
</td>';
echo '
<td class="text-center">
'.Translator::numberToLocale($int['ore']).'
</td>
<td class="text-center">
'.Translator::numberToLocale($int['km']).'
</td>
<td class="text-center">
'.Translator::numberToLocale($int['sconto']).' &euro;
</td>
<td class="text-center">
'.Translator::numberToLocale($int['subtotale']).' &euro;
</td>
</tr>';
// 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 '
</tbody>';
// Totale interventi
echo '
<tr>
<td class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-center">
<b>'.Translator::numberToLocale($ore).'</b>
</td>
<td class="text-center">
<b>'.Translator::numberToLocale($km).'</b>
</td>
<td class="text-center">
<b>'.Translator::numberToLocale($sconto_int).' &euro;</b>
</td>
<th class="text-center">
<b>'.Translator::numberToLocale($totale_int).' &euro;</b>
</th>
</tr>';
echo '
</table>';
$count = $dbo->fetchArray('SELECT COUNT(*) FROM `mg_articoli_interventi` WHERE idintervento IN ('.implode(',', array_column($interventi, 'id')).')');
if (!empty($count)) {
echo '
<table class="table table-bordered">
<thead>
<tr>
<th colspan="4" class="text-center">
<b>'.tr('Materiale utilizzato', [], ['upper' => true]).'</b>
</th>
</tr>
<tr>
<th style="font-size:8pt;width:50%" class="text-center">
<b>'.tr('Descrizione').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Q.').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Prezzo').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Importo').'</b>
</th>
</tr>
</thead>
<tbody>';
$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 '
<tr>';
// Descrizione
echo '
<td>
'.$r['descrizione'];
// Codice
if (!empty($r['codice'])) {
echo '
<br><small class="text-muted">'.tr('COD. _COD_', [
'_COD_' => $r['codice'],
]).'</small>';
}
echo '
<br><small class="text-muted">'.tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $int['id'],
'_DATE_' => Translator::dateToLocale($int['inizio']),
]).'.</small>';
echo '
</td>';
// Quantità
echo '
<td class="text-center">
'.Translator::numberToLocale($r['qta']).' '.$r['um'].'
</td>';
// Prezzo unitario
echo "
<td class='text-center'>
".Translator::numberToLocale($r['prezzo_vendita']).' &euro;';
if ($r['sconto'] > 0) {
echo "
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator::numberToLocale($r['sconto_unitario']),
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '&euro;'),
]).'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
echo '
</td>';
// Netto
$netto = $r['prezzo_vendita'] * $r['qta'];
echo '
<td class="text-center">
'.Translator::numberToLocale($netto).' &euro;';
if ($r['sconto'] > 0) {
echo "
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator::numberToLocale($r['sconto']),
'_TYPE_' => '&euro;',
]).'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
echo '
</td>
</tr>';
$sconto_art[] = $r['sconto'];
$imponibile_art[] = $r['prezzo_vendita'] * $r['qta'];
}
}
echo '
</tbody>';
$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 '
<tr>
<td colspan="2" class="text-right">
<b>'.tr('Totale materiale utilizzato', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($totale_art).' &euro;</b>
</th>
</tr>';
echo '
</table>';
}
// 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 '
<table class="table table-bordered">
<thead>
<tr>
<th colspan="4" class="text-center">
<b>'.tr('Spese aggiuntive', [], ['upper' => true]).'</b>
</th>
</tr>
<tr>
<th style="font-size:8pt;width:50%" class="text-center">
<b>'.tr('Descrizione').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Q.').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Prezzo').'</b>
</th>
<th style="font-size:8pt;width:15%" class="text-center">
<b>'.tr('Importo').'</b>
</th>
</tr>
</thead>
<tbody>';
$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 '
<tr>';
// Descrizione
echo '
<td>
'.$r['descrizione'];
echo '
<br><small class="text-muted">'.tr('Intervento num. _NUM_ del _DATE_', [
'_NUM_' => $int['id'],
'_DATE_' => Translator::dateToLocale($int['inizio']),
]).'.</small>';
echo '
</td>';
// Quantità
echo '
<td class="text-center">
'.Translator::numberToLocale($r['qta']).' '.$r['um'].'
</td>';
// Prezzo unitario
echo "
<td class='text-center'>
".Translator::numberToLocale($r['prezzo_vendita']).' &euro;';
if ($r['sconto'] > 0) {
echo "
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator::numberToLocale($r['sconto_unitario']),
'_TYPE_' => ($r['tipo_sconto'] == 'PRC' ? '%' : '&euro;'),
]).'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
echo '
</td>';
// Netto
$netto = $r['prezzo_vendita'] * $r['qta'];
echo '
<td class="text-center">
'.Translator::numberToLocale($netto).' &euro;';
if ($r['sconto'] > 0) {
echo "
<br><small class='text-muted'>- ".tr('sconto _TOT_ _TYPE_', [
'_TOT_' => Translator::numberToLocale($r['sconto']),
'_TYPE_' => '&euro;',
]).'</small>';
if ($count <= 1) {
$count += 0.4;
}
}
echo '
</td>
</tr>';
$sconto_spese[] = $r['sconto'];
$imponibile_spese[] = $r['prezzo_vendita'] * $r['qta'];
}
}
echo '
</tbody>';
$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 '
<tr>
<td colspan="2" class="text-right">
<b>'.tr('Totale spese aggiuntive', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($totale_spese).' &euro;</b>
</th>
</tr>';
echo '
</table>';
}
}
// 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 '
<table class="table table-bordered">
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($imponibile).' &euro;</b>
</th>
</tr>';
// Eventuale sconto incondizionato
if (!empty($sconto)) {
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Sconto', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>-'.Translator::numberToLocale($sconto).' &euro;</b>
</th>
</tr>';
// Imponibile scontato
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Imponibile scontato', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($totale).' &euro;</b>
</th>
</tr>';
}
// 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 '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Iva (_PRC_%)', [
'_PRC_' => Translator::numberToLocale($percentuale_iva, 0),
], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($iva).' &euro;</b>
</th>
</tr>';
$totale = sum($totale, $iva);
// TOTALE
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Totale consuntivo', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($totale).' &euro;</b>
</th>
</tr>';
// BUDGET
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Budget (no IVA)', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($budget).' &euro;</b>
</th>
</tr>';
// RAPPORTO
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Rapporto budget/spesa (no IVA)', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($rapporto).' &euro;</b>
</th>
</tr>';
// ORE RESIDUE
if (!empty($totale_ore)) {
echo '
<tr>
<td colspan="3" class="text-right border-top">
<b>'.tr('Ore residue', [], ['upper' => true]).':</b>
</td>
<th colspan="2" class="text-center">
<b>'.Translator::numberToLocale($totale_ore - $totale_ore_impiegate).'</b><br>
<p>'.tr('Ore erogate').': '.Translator::numberToLocale($totale_ore_impiegate).'</p>
<p>'.tr('Ore in contratto').': '.Translator::numberToLocale($totale_ore).'</p>
</th>
</tr>';
}
echo'
</table>';

View File

@ -1,18 +0,0 @@
<style>
<!--
.table_values td{
border: 1px solid #888;
padding: 4px;
white-space: normal;
}
.table_values th{
background: #abbfcb;
padding: 4px;
}
-->
</style>
<page backcolor="#ffffff" backtop="55mm" backbottom="0mm" backleft="0mm" backright="0mm" footer="" style="font-size: $font_size$">
$body$
</page>

View File

@ -1,27 +0,0 @@
<page_header>
<table $body_table_params$>
<!-- Intestazione fornitore -->
<tr><td style="width:105mm; font-size:8pt; color:#555;">
<img src="$docroot$/templates/contratti/logo_azienda.jpg" alt="Logo" border="0" /><br/>
$f_ragionesociale$
$f_indirizzo$
$f_citta_full$
$f_piva$
$f_codicefiscale$
$f_capsoc$
$f_telefono$
$f_sitoweb$
$f_email$
</td>
<!-- Intestazione cliente -->
<td style="width:95mm; font-size:10pt">
Spett.le $c_ragionesociale$
$c_indirizzo$
$c_citta$
$c_piva$
</td></tr>
</table>
<br/>
</page_header>

View File

@ -0,0 +1,11 @@
<?php
include_once __DIR__.'/../../core.php';
$module_name = 'Contratti';
// Lettura info fattura
$records = $dbo->fetchArray('SELECT *, data_bozza AS data FROM co_contratti WHERE id='.prepare($idcontratto));
$id_cliente = $records[0]['idanagrafica'];
$id_sede = $records[0]['idsede'];

View File

@ -1,341 +0,0 @@
<?php
include_once __DIR__.'/../../core.php';
// carica intervento
$idcontratto = save($_GET['idcontratto']);
// Lettura dati contratto
$q = "SELECT * FROM co_contratti WHERE id='".$idcontratto."'";
$rscontratti = $dbo->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 .= '<b>'.$rst[$j]['ragione_sociale'].'</b> ('.$orario.')<br/>'.Translator::numberToLocale($t1 / 60).'h x '.Translator::numberToLocale($rst[$j]['prezzo_ore_unitario']).' &euro;/h<br>'.Translator::numberToLocale($rst[$j]['km']).'km x '.Translator::numberToLocale($rst[$j]['prezzo_km_unitario']).' km/h<br>'.Translator::numberToLocale($rst[$j]['prezzo_dirittochiamata'])."&euro; d.c.<br><br>\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", '<br>', $rscontratti[$i]['descrizione']);
$line = 'Intervento <b>'.$rscontrattii[0]['codice'].'</b> del <b>'.Translator::dateToLocale($rscontrattii[0]['data']).'</b><br>'.$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 .= '<big><b>&gt; CONSUNTIVO CONTRATTO: '.$rscontratti[0]['nome']."</b></big>\n";
$body .= '<span>'.str_replace("\n", '<br/>', $rscontratti[0]['cdescrizione'])."</span><br/>\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 .= "<table class=\"table_values\" width=\"100%\" border=\"0\">\n";
$body .= "<thead>\n";
$body .= "<tr><th width='200' align=\"left\">Interventi</th>\n";
$body .= "<th width='400' align=\"center\">Tecnici</th>\n";
$body .= "<th width='100' align=\"center\">Subtotale</th></tr>\n";
$body .= "</thead>\n";
$body .= "<tbody>\n";
// Tabella con i dati
for ($j = 0; $j < sizeof($contratti); ++$j) {
// Intervento (+ tecnici)
$body .= "<tr><td valign='top'>\n";
$body .= ' '.$contratti[$j]."</td><td><span style='color:#555; font-size:11px;'>".$tecnici[$j]."</span>\n";
$body .= "</td>\n";
// Subtotale
$subtotale = $tot_ore_consuntivo[$j] + $km[$j] * $costo_km[$j] + $diritto_chiamata[$j];
$body .= "<td valign=\"top\" align='right'>\n";
$body .= ' '.Translator::numberToLocale($subtotale)."\n";
$body .= "</td></tr>\n";
$totale += $subtotale;
$totale_consuntivo += $tot_ore_consuntivo[$j] + $tot_km_consuntivo[$j];
}
$body .= "<tr><td colspan='2' align=\"right\">\n";
$body .= "<span><b>Totale:</b></span>\n";
$body .= "</td>\n";
$body .= "<td align=\"right\" bgcolor=\"#dddddd\">\n";
$body .= '<span><b>'.Translator::numberToLocale($totale)." &euro;</b></span>\n";
$body .= "</td></tr>\n";
$body .= "</tbody>\n";
$body .= "</table>\n";
}
$body .= "<br/>\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 .= "<table style=\"width:100%;\" class=\"table_values\" cellspacing=\"2\" cellpadding=\"5\" style=\"border-color:#aaa;\">\n";
$body .= "<tr><th align='center' colspan='4'><b>Materiale utilizzato per gli interventi</b></th></tr>\n";
$body .= "<tr><th style=\"width:130mm;\">\n";
$body .= "<b>Articolo</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:10mm;\" align=\"center\">\n";
$body .= "<b>Q.tà</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:20mm;\" align=\"center\">\n";
$body .= "<b>Prezzo unitario</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:20mm;\" align=\"center\">\n";
$body .= "<b>Subtot</b>\n";
$body .= "</th></tr>\n";
$totale_articoli = 0.00;
for ($i = 0; $i < sizeof($rs2); ++$i) {
// Articolo
$body .= "<tr><td class='first_cell'>\n";
$body .= '<span>'.nl2br($rs2[$i]['descrizione'])."</span>\n";
if ($rs2[$i]['codice'] != '' && $rs2[$i]['codice'] != 'Lotto: , SN: , Altro: ') {
$body .= '<br/><small>'.$rs2[$i]['codice']."</small>\n";
}
$body .= '<br/><span><small style="color:#777;">Intervento del '.Translator::dateToLocale($rs2[$i]['data_intervento'])."</small></span>\n";
$body .= "</td>\n";
// Quantità
$qta = $rs2[$i]['sumqta'];
$body .= "<td class='table_cell' align='center'>\n";
$body .= '<span>'.$rs2[$i]['sumqta']."</span>\n";
$body .= "</td>\n";
// Prezzo unitario
$body .= "<td class='table_cell' align='center'>\n";
$netto = $rs2[$i]['prezzo_vendita'];
$netto = $netto + $netto / 100 * $rs2[$i]['prc_guadagno'];
$iva = $netto / 100 * $rs2[$i]['prciva_vendita'];
$body .= '<span>'.Translator::numberToLocale($netto)." &euro;</span>\n";
$body .= "</td>\n";
// Prezzo di vendita
$body .= "<td class='table_cell' align='center'>\n";
$body .= "<span><span class='prezzo_articolo'>".Translator::numberToLocale($netto * $qta)."</span> &euro;</span>\n";
$body .= "</td></tr>\n";
$totale_articoli += $netto * $qta;
}
// Totale spesa articoli
$body .= "<tr><td colspan=\"3\" align=\"right\">\n";
$body .= "<b>TOTALE MATERIALE UTILIZZATO:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"center\" bgcolor=\"#dddddd\">\n";
$body .= '<b>'.Translator::numberToLocale($totale_articoli)." &euro;</b>\n";
$body .= "</td></tr>\n";
$body .= "</table><br/>\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 .= "<table style=\"width:100%;\" class=\"table_values\" cellspacing=\"2\" cellpadding=\"5\" style=\"border-color:#aaa;\">\n";
$body .= "<tr><th align='center' colspan='4'><b>Spese aggiuntive</b></th></tr>\n";
$body .= "<tr><th style=\"width:130mm;\">\n";
$body .= "<b>Descrizione</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:10mm;\" align=\"center\">\n";
$body .= "<b>Q.tà</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:20mm;\" align=\"center\">\n";
$body .= "<b>Prezzo unitario</b>\n";
$body .= "</th>\n";
$body .= "<th style=\"width:20mm;\" align=\"center\">\n";
$body .= "<b>Subtot</b>\n";
$body .= "</th></tr>\n";
$totale_spese = 0.00;
for ($i = 0; $i < sizeof($rs2); ++$i) {
// Articolo
$body .= "<tr><td class='first_cell'>\n";
$body .= '<span>'.$rs2[$i]['descrizione']."</span><br/>\n";
$body .= '<span><small style="color:#777;">Intervento del '.Translator::dateToLocale($rs2[$i]['data_intervento'])."</small></span>\n";
$body .= "</td>\n";
// Quantità
$qta = $rs2[$i]['qta'];
$body .= "<td class='table_cell' align='center'>\n";
$body .= '<span>'.Translator::numberToLocale($rs2[$i]['qta'])."</span>\n";
$body .= "</td>\n";
// Prezzo unitario
$body .= "<td class='table_cell' align='center'>\n";
$netto = $rs2[$i]['prezzo'];
$body .= '<span>'.Translator::numberToLocale($netto)." &euro;</span>\n";
$body .= "</td>\n";
// Prezzo di vendita
$body .= "<td class='table_cell' align='center'>\n";
$body .= '<span>'.Translator::numberToLocale($netto * $qta)." &euro;</span>\n";
$body .= "</td></tr>\n";
$totale_spese += $netto * $qta;
}
// Totale spese aggiuntive
$body .= "<tr><td colspan=\"3\" align=\"right\">\n";
$body .= "<b>ALTRE SPESE:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"center\" bgcolor=\"#dddddd\">\n";
$body .= '<b>'.Translator::numberToLocale($totale_spese)." &euro;</b>\n";
$body .= "</td></tr>\n";
$body .= "</table><br/>\n";
}
}
// Totale complessivo intervento
$body .= "<table style=\"width:100%;\" class=\"table_values\" cellspacing=\"2\" cellpadding=\"5\">\n";
$body .= "<tr><td align=\"right\" width=\"131mm\">\n";
$body .= "<b>TOTALE CONSUNTIVO:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"left\" bgcolor=\"#cccccc\" width=\"24mm\">\n";
$totale_intervento_consuntivo = Translator::numberToLocale($totale + $totale_articoli + $totale_spese);
$body .= '<b>'.$totale_intervento_consuntivo." &euro;</b>\n";
$body .= "</td></tr>\n";
$body .= "<tr><td align=\"right\" width=\"131mm\">\n";
$body .= "<b>BUDGET TOTALE (NO IVA):</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"left\" bgcolor=\"#cccccc\" width=\"24mm\">\n";
$contratto_tot_budget = Translator::numberToLocale($contratto_tot_budget);
$body .= '<b>'.$contratto_tot_budget." &euro;</b>\n";
$body .= "</td></tr>\n";
$body .= "<tr><td align=\"right\" width=\"131mm\">\n";
$body .= "<b>RAPPORTO BUDGET/SPESA (NO IVA):</b>\n";
$body .= "</td>\n";
$diff = Translator::numberToLocale($contratto_tot_budget - $totale_intervento_consuntivo);
$body .= "<td align=\"left\" bgcolor=\"#cccccc\" width=\"24mm\">\n";
$body .= '<b>'.$diff." &euro;</b>\n";
$body .= "</td></tr>\n";
if (!empty($contratto_tot_ore)) {
$body .= "<tr><td align=\"right\" width=\"131mm\">\n";
$body .= "<b>ORE RESIDUE:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"center\" bgcolor=\"#cccccc\" width=\"24mm\">\n";
$diff2 = Translator::numberToLocale($contratto_tot_ore - $totale_ore_impiegate);
$body .= "<b>$diff2&nbsp;&nbsp;(ore erogate: ".Translator::numberToLocale($totale_ore_impiegate).'&nbsp;-&nbsp;ore in contratto: '.Translator::numberToLocale($contratto_tot_ore).")</b>\n";
$body .= "</td></tr>\n";
}
$body .= "</table>\n";
$report_name = 'contratto_'.$idcontratto.'_cons.pdf';

View File

@ -18,8 +18,8 @@ echo '
<tr>
<td class="text-center" style="width:40%">'.tr('Intervento numero').': <b>'.$records[0]['codice'].'</b></td>
<td class="text-center" style="width:20%">'.tr('Data').': <b>'.Translator::dateToLocale($records[0]['data_richiesta']).'</b></td>
<td class="text-center" style="width:20%">'.tr('Preventivo Num.').': <b>'.$records[0]['numero_preventivo'].'</b></td>
<td class="text-center" style="width:20%">'.tr('Contratto Num.').': <b>'.$records[0]['numero_contratto'].'</b></td>
<td class="text-center" style="width:20%">'.tr('Preventivo num.').': <b>'.$records[0]['numero_preventivo'].'</b></td>
<td class="text-center" style="width:20%">'.tr('Contratto num.').': <b>'.$records[0]['numero_contratto'].'</b></td>
</tr>';
// Dati cliente

View File

@ -16,7 +16,7 @@ echo '
<div class="row">
<div class="col-xs-6">
<div class="text-center" style="height:5mm;">
<b>'.tr('Preventivo Num. _NUM_ del _DATE_', [
<b>'.tr('Preventivo num. _NUM_ del _DATE_', [
'_NUM_' => $records[0]['numero'],
'_DATE_' => Translator::dateToLocale($records[0]['data']),
], ['upper' => true]).'</b>

View File

@ -9,8 +9,9 @@ $report_name = 'preventivo_'.$idpreventivo.'_cons.pdf';
echo '
<div class="row">
<div class="col-xs-6">
<div class="text-center" style="height:5mm;">
<b>'.tr('Preventivo Num. _NUM_ del _DATE_', [
<div class="text-center">
<h4 class="text-bold">'.tr('Consuntivo', [], ['upper' => true]).'</h4>
<b>'.tr('Preventivo num. _NUM_ del _DATE_', [
'_NUM_' => $records[0]['numero'],
'_DATE_' => Translator::dateToLocale($records[0]['data']),
], ['upper' => true]).'</b>

View File

@ -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'];

View File

@ -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',