gest366/templates/interventi/pdfgen.interventi.php

513 lines
17 KiB
PHP
Raw Permalink Normal View History

2021-02-24 20:40:04 +00:00
<?php
$module_name = "Interventi";
// include_once( $docroot."/lib/permissions_check.php" );
include_once( $docroot."/modules/interventi/modutil.php" );
$additional_where['Interventi'] = str_replace( "|idtecnico|", "'".$user_idanagrafica."'", $additional_where['Interventi'] );
$additional_where['Interventi'] = str_replace( "|idanagrafica|", "'".$user_idanagrafica."'", $additional_where['Interventi'] );
#############mostro o nascondo i costi dell'intervento..#################
//true o false
$visualizza_costi = get_var("Visualizza i costi sulle stampe rapporti attivita");
//carica intervento
$idintervento = save($_GET['idintervento']);
$idriga = save($_GET['id_record']);
$query = "SELECT *,in_interventi.idsede as sedeop , (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idclientefinale) AS clientefinale,
(SELECT numero FROM co_preventivi WHERE id=(SELECT idpreventivo FROM co_preventivi_interventi
WHERE idintervento=in_interventi.idintervento ORDER BY idpreventivo DESC LIMIT 0,1)) AS numero_preventivo,
(SELECT SUM(prezzo_dirittochiamata) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.idintervento) AS `tot_dirittochiamata`,
(SELECT SUM(km) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.idintervento) AS `tot_km`,
(SELECT SUM(ore*prezzo_ore_unitario) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.idintervento) AS `tot_ore_consuntivo`,
(SELECT SUM(prezzo_km_consuntivo) FROM in_interventi_tecnici GROUP BY idintervento HAVING idintervento=in_interventi.idintervento) AS `tot_km_consuntivo`,
in_interventi.descrizione AS `descrizione_intervento`, richiesta FROM in_interventi INNER JOIN in_tipiintervento ON in_interventi.idtipointervento=in_tipiintervento.idtipointervento
WHERE idintervento=\"$idintervento\" ".$additional_where['Interventi'];
$rs = $dbo->fetchArray( $query );
$idanagrafica = $rs[0]['idanagrafica'];
$idcliente = $rs[0]['idanagrafica'];
$idsede = $rs[0]['sedeop'];
$str_cash = 0.00;
$quer_riga="Select * from in_interventi_tecnici WHERE id='".$idriga."'";
$rs_riga = $dbo->fetchArray( $quer_riga );
//Leggo il nome del referente se selezionato da menu a tendina
if( $rs[0]['idreferente'] != '0' ){
$rs2 = $dbo->fetchArray("SELECT * FROM an_referenti WHERE id=\"".$rs[0]['idreferente']."\"");
$referente = $rs2[0]['nome'];
} else {
$referente = $rs[0]['referente']." ".$rs[0]['telefono_referente'];
}
//carica report html
$report = file_get_contents ($docroot."/templates/interventi/intervento.html");
$body = file_get_contents ($docroot."/templates/interventi/intervento_body.html");
include_once( $docroot."/templates/pdfgen_variables.php" );
// imposta numerointervento-data-numerocommessa su intestazione
$body = str_replace( '$intervento_numero$', $rs[0]['idintervento'], $body );
$body = str_replace( '$intervento_data$', date( "d/m/Y", strtotime($rs[0]['data_richiesta']) ), $body );
if( $rs[0]['numero_preventivo'] )
$body = str_replace( '$commessa_numero$', $rs[0]['idintervento'], $body );
else
$body = str_replace( '$commessa_numero$', "&nbsp;", $body );
$body = str_replace( '$commessa_numero$', $rs[0]['idintervento'], $body );
/*
Dati intervento
*/
$body .= "<table class=\"table_values\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout:fixed;\">\n";
$body .= "<col width=\"400\"><col width=\"310\">\n";
$body .= "<tr>";
$body .= " <td align=\"left\">\n";
$body .= " Cliente: <b>".$c_codiceanagrafica." ".$c_ragionesociale."</b><br/>\n";
$body .= " Indirizzo: <b>".$c_indirizzo." - ".$c_cap." ".$c_citta." (".strtoupper ($c_provincia).")</b><br>\n";
if ( $idsede != "0" ){
$rs_sede = $dbo->fetchArray("SELECT * FROM an_sedi WHERE id='". $idsede."'");
$body .= " Sede: <b>".$rs_sede[0]['nomesede']."</b><br>\n";
$body .= " <b>".$rs_sede[0]['indirizzo']." - ".$rs_sede[0]['cap']." ".$rs_sede[0]['citta']."</b><br>\n";
}
$body .= " </td>\n";
$body .= " <td align=\"left\">\n";
$body .= " Ordine di Servizio: <b>".$rs[0]['idintervento']."</b><br>\n";
$body .= " Matricola Impianto: <b>".$rs_riga[0]['matricola_impianto']."</b><br>\n";
//$body .= " Referente: <b>".$referente."</b>\n";
if( $c_telefono!='' ) $body .= "Telefono azienda: <b>".$c_telefono."</b>\n";
if( $c_email!='' ) $body .= "<br/>Email: <b>".$c_email."</b>\n";
$body .= " </td>\n";
$body .= "</tr>\n";
// appunti
$body .= "<tr>\n";
$body .= " <td align=\"left\" colspan=\"2\" valign=\"top\"><b>Appunti:</b></td>\n";
$body .= "</tr>\n";
$body .= "<tr>\n";
$body .= " <td colspan=\"2\" align=\"left\" valign=\"top\" style=\"height:5mm;\">".nl2br($rs_riga[0]['descrizione_att'])."</td>\n";
$body .= "</tr>\n";
$body .= "</table>\n";
//Conteggio prezzi
$costo_orario = $rs[0]['costo_orario'];
$totale_ore_consuntivo = $rs[0]['tot_ore_consuntivo'] - $rs[0]['tot_dirittochiamata'];
$totale_km_consuntivo = $rs[0]['tot_km_consuntivo'];
$totale_dirittochiamata = $rs[0]['tot_dirittochiamata'];
$totale_intervento = $totale_ore_consuntivo + $totale_km_consuntivo + $totale_dirittochiamata;
//visualizzo costi?
if(( $totale_intervento != 0.00 ) and ($visualizza_costi==true)){
$colspan = 2;
if( $totale_ore_consuntivo != 0 ){
$colspan--;
}
if( $totale_km_consuntivo != 0 ){
$colspan--;
}
}
//MATERIALE UTILIZZATO
//Conteggio articoli utilizzati
$query = "SELECT *, (SELECT codice FROM mg_articoli WHERE id=idarticolo) AS codice_art, SUM(qta) AS sumqta FROM `mg_articoli_interventi`
where idintervento=\"".$idintervento."\" AND NOT idarticolo='0' and idriga_pianifica='".$idriga."'
GROUP BY idarticolo, idintervento, lotto
ORDER BY idarticolo ASC";
$rs2 = $dbo->fetchArray($query);
if( sizeof($rs2)>0 ){
$body .= "<table class=\"table_values\" cellspacing=\"0\" cellpadding=\"0\" style=\"font-size:11px; table-layout:fixed; border-color:#aaa;\">\n";
$body .= "<col width=\"90\"><col width=\"254\"><col width=\"54\"><col width=\"80\"><col width=\"80\"><col width=\"80\">\n";
$body .= "<tr><td align=\"center\" colspan=\"6\" valign=\"middle\" style=\"font-size:11pt;\" bgcolor=\"#cccccc\"><b>MATERIALE UTILIZZATO</b></td></tr>\n";
$body .= "<tr><td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Codice</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Descrizione</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Q.t&agrave;</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Prezzo listino</b>\n";
$body .= "<b> </b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
// $body .= "<b>Sconto</b>\n";
$body .= "<b> </b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Subtot. netto</b>\n";
$body .= "<b> </b>\n";
$body .= "</td></tr>\n";
$totale_articoli = 0.00;
for( $i=0; $i<sizeof($rs2); $i++ ){
$body .= "<tr>\n";
//Codice
$body .= "<td class='first_cell' valign='top'>\n";
$body .= "<span>".$rs2[$i]['codice_art']."</span>\n";
$body .= "</td>\n";
//Descrizione
$body .= "<td class='first_cell' valign='top'>\n";
$body .= "<span>".$rs2[$i]['descrizione']."</span>\n";
//if( $rs2[$i]['codice']!='' && $rs2[$i]['codice']!='Lotto: , SN: , Altro: ' ){ $body .= "<br/><small>".$rs2[$i]['codice']."</small>\n"; }
$body .= "</td>\n";
//Quantità
$qta = $rs2[$i]['sumqta'];
$body .= "<td class='table_cell' align='center' valign='top'>\n";
$body .= "<span>".number_format( $rs2[$i]['sumqta'], 2, ",", "." )." ".$rs2[$i]['um']."</span>\n";
$body .= "</td>\n";
//Prezzo unitario
$netto = $rs2[$i]['prezzo_vendita'];
$body .= "<td class='table_cell' align='right' valign='top'>\n";
if ($visualizza_costi==true){
$body .= "<span>".number_format( $netto, 2, ",", "" )." &euro;</span>\n";
} else {
$body .= "<span> </span>\n";
}
$body .= "</td>\n";
//Sconto unitario
if( $rs2[$i]['sconto_prc'] != 0 ){
$sconto = number_format( $rs2[$i]['sconto_prc'], 0, ",", "" )."%";
} elseif( $rs2[$i]['sconto'] != 0 ) {
$sconto = number_format( $rs2[$i]['sconto'], 2, ",", "" )." &euro";
$netto = $rs2[$i]['prezzo_vendita'];
} else {
$sconto = "-";
}
$body .= "<td class='table_cell' align='center' valign='top'>\n";
if ($visualizza_costi==true){
$body .= "<span>".$sconto."</span>\n";
} else {
$body .= "<span> </span>\n";
}
$body .= "</td>\n";
//Netto
$netto = ( $rs2[$i]['prezzo_vendita'] - $rs2[$i]['sconto'] ) * $rs2[$i]['sumqta'];
$body .= "<td class='table_cell' align='right' valign='top'>\n";
if ($visualizza_costi==true){
$body .= "<span>".number_format( $netto, 2, ",", "" )."</span>\n";
} else {
$body .= "<span> </span>\n";
}
$body .= "</td>\n";
//Totale
$totale_articoli += $netto;
$body .= "</tr>\n";
}
//TOTALE MATERIALE UTILIZZATO
if ($visualizza_costi==true){
//Totale spesa articoli
$body .= "<tr><td colspan=\"5\" align=\"right\">\n";
$body .= "<b>TOTALE MATERIALE UTILIZZATO:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"right\" bgcolor=\"#dddddd\">\n";
$body .= "<b>".number_format( $totale_articoli, 2, ",", ".")." &euro;</b>\n";
$body .= "</td></tr>\n";
}
$body .= "</table>\n";
}
//FINE MATERIALE UTILIZZATO
//Conteggio SPESE AGGIUNTIVE
$query = "SELECT * FROM in_righe_interventi WHERE idintervento='".$idintervento."' and idriga_pianifica='".$idriga."' ORDER BY id ASC";
$rs2 = $dbo->fetchArray($query);
if( sizeof($rs2)>0 ){
$body .= "<table class=\"table_values\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout:fixed; border-color:#aaa; font-size:11px;\">\n";
$body .= "<col width=\"90\"><col width=\"254\"><col width=\"54\"><col width=\"80\"><col width=\"80\"><col width=\"80\">\n";
$body .= "<tr><td align=\"center\" colspan=\"6\" valign=\"middle\" style=\"font-size:11pt;\" bgcolor=\"#cccccc\"><b>SPESE AGGIUNTIVE</b></td></tr>\n";
$body .= "<tr><td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b></b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Descrizione</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Q.t&agrave;</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Spesa</b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
// $body .= "<b>Sconto</b>\n";
$body .= "<b></b>\n";
$body .= "</td>\n";
$body .= "<td style=\"font-size:8pt;\" align=\"center\" bgcolor='#dedede'>\n";
$body .= "<b>Totale</b>\n";
$body .= "</td></tr>\n";
$totale_righe = 0.00;
for( $i=0; $i<sizeof($rs2); $i++ ){
//Articolo
$body .= "<tr><td></td><td class='first_cell'>\n";
$body .= "<span>".nl2br($rs2[$i]['descrizione'])."</span>\n";
$body .= "</td>\n";
//Quantità
$body .= "<td class='table_cell' align='center'>\n";
$body .= "<span>".number_format( $rs2[$i]['qta'], 2, ",", "" )."</span>\n";
$body .= "</td>\n";
//Prezzo unitario
$netto = $rs2[$i]['prezzo_vendita'];
$body .= "<td class='table_cell' align='right' valign='top'>\n";
if ($visualizza_costi==true){
$body .= "<span>".number_format( $netto, 2, ",", "" )." &euro;</span>\n";
} else {
$body .= "<span> - </span>\n";
}
$body .= "</td>\n";
//Sconto unitario
if( $rs2[$i]['sconto_prc'] != 0 ){
$sconto = number_format( $rs2[$i]['sconto_prc'], 0, ",", "" )."%";
} elseif( $rs2[$i]['sconto'] != 0 ) {
$sconto = number_format( $rs2[$i]['sconto'], 2, ",", "" )." &euro";
$netto = $rs2[$i]['prezzo_vendita'];
} else {
$sconto = "-";
}
$body .= "<td class='table_cell' align='center' valign='top'>\n";
if ($visualizza_costi==true){
$body .= "<span>".$sconto."</span>\n";
} else {
$body .= "<span> - </span>\n";
}
$body .= "</td>\n";
//Prezzo totale
$netto = ( $rs2[$i]['prezzo_vendita'] - $rs2[$i]['sconto'] ) * $rs2[$i]['qta'];
$body .= "<td class='table_cell' align='right' valign='top'>\n";
// if ($visualizza_costi==true){
$body .= "<span>".number_format( $netto, 2, ",", "" )." &euro;</span>\n";
// } else {
// $body .= "<span> - </span>\n";
// }
$body .= "</td></tr>\n";
//Subtot
$totale_righe += $netto;
}
if ($visualizza_costi==true){
//Totale spese aggiuntive
$body .= "<tr><td colspan=\"5\" align=\"right\">\n";
$body .= "<b>TOTALE SPESE AGGIUNTIVE:</b>\n";
$body .= "</td>\n";
$body .= "<td align=\"right\" bgcolor=\"#dddddd\">\n";
$body .= "<b>".number_format( $totale_righe, 2, ",", ".")." &euro;</b>\n";
$body .= "</td></tr>\n";
}
$body .= "</table>\n";
}
//FINE SPESE AGGIUNTIVE
//ORE TECNICI + FIRMA
$body .= "<table class=\"table_values\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout:fixed;\">\n";
$body .= "<col width=\"434\"><col width=\"80\"><col width=\"80\"><col width=\"80\">\n";
$body .= "<tr><td align=\"center\" colspan=\"4\" valign=\"middle\" style=\"font-size:11pt;\" bgcolor=\"#cccccc\"><b>PIANIFICAZIONE</b></td></tr>\n";
//INTESTAZIONE ELENCO TECNICI
$body .= "<tr><td align=\"center\" style=\"font-size:8pt;\" bgcolor='#dddddd'>";
$body .= "<b>Operatore</b>";
$body .= "</td>";
$body .= "<td align=\"center\" style=\"font-size:8pt;\" bgcolor='#dddddd'>";
$body .= "<b>Dalle</b>";
$body .= "</td>";
$body .= "<td align=\"center\" style=\"font-size:8pt;\" bgcolor='#dddddd'>";
$body .= "<b>Alle</b>";
$body .= "</td>";
$body .= "<td align=\"center\" style=\"font-size:8pt;\" bgcolor='#dddddd'>";
$body .= "<b>Data</b>";
$body .= "</td>";
$body .= "</tr>\n";
// sessioni di lavoro dei tecnici
$qt = "SELECT *, in_interventi_tecnici.km AS km_tecnico FROM in_interventi
INNER JOIN (in_interventi_tecnici INNER JOIN an_anagrafiche ON in_interventi_tecnici.idtecnico=an_anagrafiche.idanagrafica) ON in_interventi.idintervento=in_interventi_tecnici.idintervento
WHERE in_interventi.idintervento='$idintervento' and in_interventi_tecnici.id ='$idriga' ORDER BY in_interventi_tecnici.orario_inizio ";
$rst = $dbo->fetchArray( $qt );
$nt = sizeof($rst);
for( $t=0; $t<$nt; $t++ ){
$body .= "<tr>\n";
//nome tecnico
$body .= " <td align=\"left\">\n";
$body .= " ".$rst[$t]['ragione_sociale']."";
$body .= " </td>";
//ora inizio
$body .= " <td align=\"center\">";
if ($rst[$t]['orario_inizio']!='00:00:00'){
$body .= "".readDateTimePrint($rst[$t]['orario_inizio'], 'time')."";
}else{
$body .= " - ";
}
$body .= " </td>";
//ora fine
$body .= " <td align=\"center\">";
if ($rst[$t]['orario_fine']!='00:00:00'){
$body .= "".readDateTimePrint($rst[$t]['orario_fine'], 'time')."";
}else{
$body .= " - ";
}
$body .= " </td>";
//data
$body .= " <td align=\"center\">";
if ($rst[$t]['orario_inizio']!='00:00:00'){
$body .= "".readDateTimePrint($rst[$t]['orario_inizio'], 'date')."";
}else{
$body .= " - ";
}
$body .= " </td>";
$body .= "</tr>\n";
}
$body .= "</table>\n";
// timbro e firma
if( $rs_riga[0]['firma_file'] != '' ){
$firma = "<img src='".$docroot."/files/interventi/".$rs_riga[0]['firma_file']."' style='width:70mm;'>\n";
} else {
$firma = "";
}
$body .= "<br/><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"table-layout:fixed;\">\n";
$body .= "<col width=\"454\"><col width=\"280\">\n";
$body .= "<tr>\n";
$body .= " <td align=\"left\" valign=\"middle\">\n";
$body .= " </td>\n";
$body .= " <td align=\"center\" valign=\"bottom\" style=\"border:1px solid #888; height:20mm; font-size:8pt;\">";
$body .= " ".$firma."<br>\n";
$body .= " <i>(Timbro e firma leggibile.)</i>";
$body .= " </td>";
$body .= "</tr>\n";
$body .= "</table>\n";
$report_name = "intervento_".$idintervento.".pdf";
?>