<?php
	$iddocumento = save($_GET['iddocumento']);
	
	//Lettura tipo documento
	$q = "SELECT (SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id=\"".$iddocumento."\"";
	$rs = $dbo->fetchArray($q);

	
	$module_name = "Fatture di vendita";

	include_once( $docroot."/lib/permissions_check.php" );
	
	$additional_where[$module_name] = str_replace( "|idanagrafica|", "'".$user_idanagrafica."'", $additional_where[$module_name] );
	
	
	
	//Lettura info fattura
	$q = "SELECT *, (SELECT descrizione FROM co_tipidocumento WHERE id=idtipodocumento) AS tipo_doc, (SELECT descrizione FROM co_pagamenti WHERE id=idpagamento) AS tipo_pagamento, (SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id=\"".$iddocumento."\" ".$additional_where[$module_name];
	
	
	$q = "SELECT *, (SELECT descrizione FROM co_statidocumento WHERE id=idstatodocumento) AS stato_doc, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idvettore) AS vettore , (SELECT txt_suffisso FROM co_tipidocumento WHERE id=idtipodocumento) AS suffisso, (SELECT descrizione FROM co_tipidocumento WHERE id=idtipodocumento) AS tipo_doc, (SELECT descrizione FROM co_pagamenti WHERE id=idpagamento) AS tipo_pagamento, (SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id=\"".$iddocumento."\" ".$additional_where[$nome_modulo];		
	$rs = $dbo->fetchArray($q);
	$tipo_doc = $rs[0]['tipo_doc'];
	
//	$rs = $dbo->fetchArray($q);
	$numero_doc = $rs[0]['numero'];
	$idcliente = $rs[0]['idanagrafica'];
	( $rs[0]['numero_esterno']!='' ) ? $numero=$rs[0]['numero_esterno'] : $numero=$rs[0]['numero'];
	$numero=$rs[0]['numero_documento'];
	
	$vedi_transazionepdf = get_var_tipodoc2($iddocumento,'vedi_transazionepdf');
	$stampa_prezzi = get_var_tipodoc2($iddocumento,'stampa_prezzi');
	
	
	//carica report html
	$report = file_get_contents ($docroot."/templates/ddt_2019/ddt.html");
	$body = file_get_contents ($docroot."/templates/ddt_2019/ddt_body.html");
	
	
	if( !($idcliente == $user_idanagrafica || isAdminAutenticated()) )
		die("Non hai i permessi per questa stampa!");
	
	include_once( "pdfgen_variables.php" );
	
	
	//Leggo i dati della destinazione (se 0=sede legale, se!=altra sede da leggere da tabella an_sedi)
	$destinazione = '';
	if( $rs[0]['idsede']==0 ){
		$queryd = "SELECT ragione_sociale, indirizzo, indirizzo2, cap, citta, provincia, piva, codice_fiscale FROM an_anagrafiche WHERE idanagrafica='".$idcliente."'";
		$rsd = $dbo->fetchArray($queryd);
		
		if( $rsd[0]['ragione_sociale']!='' )
			$destinazione .= $rsd[0]['ragione_sociale']."<br/>\n";
		if( $rsd[0]['indirizzo']!='' )
			$destinazione .= $rsd[0]['indirizzo']."<br/>\n";
		if( $rsd[0]['indirizzo2']!='' )
			$destinazione .= $rsd[0]['indirizzo2']."<br/>\n";
		if( $rsd[0]['cap']!='' )
			$destinazione .= $rsd[0]['cap']." ";
		if( $rsd[0]['citta']!='' )
			$destinazione .= $rsd[0]['citta'];
		if( $rsd[0]['provincia']!='' )
			$destinazione .= " (".$rsd[0]['provincia'].")<br/>\n";
		//if( $rsd[0]['piva']!='' )
		//	$destinazione .= "P.IVA: ".$rsd[0]['piva']."<br/>\n";
		//if( $rsd[0]['piva']=='' )
		//	$destinazione .= "C.F.: ".$rsd[0]['codice_fiscale']."<br/>\n";
		if( $rsd[0]['piva']!='' )
			$c_piva .= $rsd[0]['piva'];
	}

	else{
		$queryd = "SELECT (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=an_sedi.idanagrafica) AS ragione_sociale, indirizzo, indirizzo2, cap, citta, provincia, piva, codice_fiscale FROM an_sedi WHERE idanagrafica='".$idcliente."' AND id='".$rs[0]['idsede']."'";
		$rsd = $dbo->fetchArray($queryd);
		
		if( $rsd[0]['ragione_sociale']!='' )
			$destinazione .= $rsd[0]['ragione_sociale']."<br/>\n";
		if( $rsd[0]['indirizzo']!='' )
			$destinazione .= $rsd[0]['indirizzo']."<br/>\n";
		if( $rsd[0]['indirizzo2']!='' )
			$destinazione .= $rsd[0]['indirizzo2']."<br/>\n";
		if( $rsd[0]['cap']!='' )
			$destinazione .= $rsd[0]['cap']." ";
		if( $rsd[0]['citta']!='' )
			$destinazione .= $rsd[0]['citta'];
		if( $rsd[0]['provincia']!='' )
			$destinazione .= " (".$rsd[0]['provincia'].")<br/>\n";
		//if( $rsd[0]['piva']!='' )
		//	$destinazione .= "P.IVA: ".$rsd[0]['piva']."<br/>\n";
		//if( $rsd[0]['codice_fiscale']!='' )
		//	$destinazione .= "C.F.: ".$rsd[0]['codice_fiscale']."<br/>\n";
		if( $rsd[0]['piva']!='' )
			$c_piva .= $rsd[0]['piva'];
	}
	
	$body = str_replace( '$c_destinazione$', $destinazione, $body );
	$body = str_replace( '$c_numero$', $numero, $body );
	$body = str_replace( '$c_data$', date( "d/m/Y", strtotime($rs[0]['data']) ), $body );
	$body = str_replace( '$c_tipodoc$', $rs[0]['tipo_doc'], $body );
	$body = str_replace( '$c_pagamento$', $rs[0]['tipo_pagamento'], $body );
	$body = str_replace( '$c_piva$', $c_piva, $body );
	
	
	//Dati generici fattura
	if( $rs[0]['buono_ordine']!='' ){
		$width = '165';
	}
	else{
		$width = '228';
	}

	$body .= "<br/><br/>\n";
	
	
	
	//Intestazione tabella per righe
	$body .= "<table class='table_values' border='0' cellspacing='0' style='table-layout:fixed; border:1px solid #aaa; font-size:9pt; '>\n";
	$body .= "<col width='550'><col width='50'><col width='40'>\n";
	$body .= "<thead>\n";
	$body .= "<tr><th class='table_cell' style='border-left: 1px solid #aaa; border-bottom: 1px solid #aaa; border-top: 1px solid #aaa;' width='560'>Descrizione</th>\n";
	$body .= "<th class='table_cell' style='border-top: 1px solid #aaa; border-bottom: 1px solid #aaa; border-right: 1px solid #aaa;' width='50' align='center'>UM</th>\n";
	$body .= "<th class='table_cell' style='border-top: 1px solid #aaa; border-bottom: 1px solid #aaa; border-right: 1px solid #aaa;' width='50' align='center'>Q.T&Agrave;</th>\n";
	//$body .= "<th width='90' align='center'>Costo&nbsp;unitario</th>\n";
	//$body .= "<th width='60' align='center'>Iva</th>\n";
	//$body .= "<th width='98' align='center'>Imponibile</th></tr>\n";
	$body .= "</tr>\n";
	$body .= "</thead>\n";
	
	$body .= "<tbody>\n";

	//Mostro le righe del documento
	$totale_documento = 0.00;
	$totale_imponibile = 0.00;
	$totale_iva = 0.00;
	$sconto = 0.00;


	/*
		Righe fattura
	*/
	$qr = "SELECT * FROM `co_righe_documenti` WHERE iddocumento='$iddocumento'";
	$qr = "SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),'') AS codice_articolo, (SELECT percentuale FROM co_iva WHERE id=idiva) AS perc_iva FROM `co_righe_documenti` WHERE iddocumento='".$iddocumento."' ORDER BY ordine";

	$rsr = $dbo->fetchArray( $qr );
	$tot = sizeof($rsr);
	$imponibile_int = 0.00;
	$iva_int = 0.00;

	if( $tot>0 ){
		for( $i=0; $i<$tot; $i++ ){
			 if( $rsr[$i]['idarticolo'] != 0 ){
				$body .= "<tr><td class='first_cell' style='border-left: 1px solid #aaa; border-bottom: 1px solid #aaa; border-right: 1px solid #aaa;'>\n";
			
			
				//Immagine articolo
				$f = pathinfo($rsr[$i]['immagine01']);
				$img = $docroot."/modules/magazzino/articoli/images/".$f['filename']."_thumb100.".$f['extension'];
				//if( file_exists($img) )
					//$body .= "<img src=\"".$img."\" alt=\"\" border=\"0\" align=\"left\" style=\"margin:0px 4px 4px 0px; border:1px solid #ccc;\" />\n";
			
			
				//$body .= nl2br( $rsr[$i]['descrizione'] );  
				$body .= $rsr[$i]['codice_articolo'].": ".nl2br( $rsr[$i]['descrizione'] ); 				
				
				// cerco seriale
				// da fare
				
				// cerco riferimento transazione
				if( $vedi_transazionepdf != 0 ){								
					$query="SELECT iddocumento , numero_documento , data  FROM `co_righe_documenti` left join co_documenti on co_documenti.id = co_righe_documenti.iddocumento
					WHERE co_righe_documenti.id='".$rsr[$i]['id_riferimento']."'";
					$rs_rif = $dbo->fetchArray( $query );
					if ( sizeof($rs_rif) > 0 ) {
						$descrizione_documento = get_var_tipodoc2($rs_rif[0]['iddocumento'],'descrizione');												
						$body .= "<br/><small>Rif. ".$descrizione_documento." n<sup>o </sup>".$rs_rif[0]['numero_documento']." del ".date("d/m/Y", strtotime($rs_rif[0]['data']) )."</small>";			
					}
				}
			
				$body .= "</td>\n";

				//UM
				$body .= "<td class='table_cell center'>\n";
				$body .= $rsr[$i]['um'];
				$body .= "</td>\n";
		
				//Qta
				$body .= "<td class='table_cell center'>\n";
				$body .= number_format( $rsr[$i]['qta'], 1, ",", "." );
				$body .= "</td>\n";
			
				$body .= "</tr>\n";
				
				$imponibile_art += $rsr[$i]['subtotale'];
				$iva_art += $iva;
				$sconto += $rsr[$i]['sconto'];
			}
			
			
			//Righe generiche
			else{
				$body .= "<tr><td class='full_cell2'>\n";
				$body .= nl2br( $rsr[$i]['descrizione'] );
				// cerco riferimento transazione
				if( $vedi_transazionepdf != 0 ){								
					$query="SELECT iddocumento , numero_documento , data  FROM `co_righe_documenti` left join co_documenti on co_documenti.id = co_righe_documenti.iddocumento
					WHERE co_righe_documenti.id='".$rsr[$i]['id_riferimento']."'";
					$rs_rif = $dbo->fetchArray( $query );
					if ( sizeof($rs_rif) > 0 ) {
						$descrizione_documento = get_var_tipodoc2($rs_rif[0]['iddocumento'],'descrizione');												
						$body .= "<br/><small>Rif. ".$descrizione_documento." n<sup>o </sup>".$rs_rif[0]['numero_documento']." del ".date("d/m/Y", strtotime($rs_rif[0]['data']) )."</small>";			
					}
				}
				
				
				$body .= "</td>\n";

				$body .= "<td class='table_cell center'>\n";
				$body .= $rsr[$i]['um']."\n";
				$body .= "</td>\n";

				$body .= "<td class='table_cell center'>\n";
				$body .= number_format($rsr[$i]['qta'], 1, ",", "")."\n";
				$body .= "</td>\n";
				
				$body .= "</tr>\n";
		
				$imponibile_gen += $rsr[$i]['subtotale'];
				$iva_gen += $iva;
				$sconto += $rsr[$i]['sconto'];
			}
		}
		
		
		$imponibile_documento += $imponibile_int;
		$totale_iva += $iva_int;
		$totale_documento += $imponibile_int;
		
		$imponibile_documento += $imponibile_pre;
		$totale_iva += $iva_pre;
		$totale_documento += $imponibile_pre;
		
		$imponibile_documento += $imponibile_con;
		$totale_iva += $iva_con;
		$totale_documento += $imponibile_con;
		
		$imponibile_documento += $imponibile_art;
		$totale_iva += $iva_art;
		$totale_documento += $imponibile_art;
		
		$imponibile_documento += $imponibile_gen;
		$totale_iva += $iva_gen;
		$totale_documento += $imponibile_gen;
	}



	if ( $stampa_prezzi == '1' ) {	
		//Totale documento
		$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
		$body .= "<b>Subtot.:</b>";
		$body .= "</td>\n";

		//Imponibile
		$body .= "<td class='table_cell' align='right'>\n";
		$totale_documento = $imponibile_documento;
		$body .= number_format( $totale_documento, 2, ",", "." )." &euro;\n";
		$body .= "</td></tr>\n";

		//Mostra sconto se c'è
		if( abs($sconto)>0 ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Sconto:</b>";
			$body .= "</td>\n";

			//Sconto
			$body .= "<td class='table_cell' align='right'>\n";
			$body .= number_format( $sconto, 2, ",", "." )." &euro;\n";
			$body .= "</td></tr>";
		
		
			//Totale scontato
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Totale scontato:</b>";
			$body .= "</td>\n";

			//Sconto
			$body .= "<td class='table_cell' align='right'>\n";
			$totale_documento-=$sconto;
			$body .= number_format( $totale_documento, 2, ",", "." )." &euro;\n";
			$body .= "</td></tr>\n";
		}


		//Mostra INPS se c'è
		if( abs($rs[0]['rivalsainps'])>0 ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Rivalsa INPS:</b>";
			$body .= "</td>\n";

			//Rivalsa INPS
			$body .= "<td class='table_cell' align='right'>\n";
			$body .= number_format( $rs[0]['rivalsainps'], 2, ",", "." )." &euro;\n";
			$body .= "</td></tr>\n";
			$totale_documento += $rs[0]['rivalsainps'];
		}
		
		//Mostra iva se c'è
		$totale_iva += $rs[0]['iva_rivalsainps'];
		if( abs($totale_iva)>0 ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Iva:</b>";
			$body .= "</td>\n";
		
			//Iva
			$body .= "<td class='table_cell' align='right'>\n";
			$body .= number_format( $totale_iva, 2, ",", "." )." &euro;\n";
			$body .= "</td></tr>\n";
			$totale_documento += $totale_iva;
		}

		/*
			Totale documento
		*/
		
			
		
		
		$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
		$body .= "<b>Totale documento:</b>";
		$body .= "</td>\n";

		$body .= "<td class='table_cell' align='right'>\n";
		$body .= "<b>".number_format( $totale_documento, 2, ",", "." )." &euro;</b>\n";
		$body .= "</td></tr>\n";
		$netto_a_pagare = $totale_documento;


		//Mostra marca da bollo se c'è
		if( abs($rs[0]['bollo'])>0 ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Marca da bollo:</b>";
			$body .= "</td>\n";

			//Marca da bollo
			$body .= "<td class='table_cell' align='right'>\n";
			$marca_da_bollo = str_replace( ",", ".", $rs[0]['bollo'] );
			$body .= number_format( $marca_da_bollo, 2, ",", "." )." &euro;";
			$body .= "</td></tr>\n";
			$netto_a_pagare += $marca_da_bollo;
		}


		//Mostra ritenuta d'acconto se c'è
		if( abs($rs[0]['ritenutaacconto'])>0 ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Ritenuta d'acconto:</b>";
			$body .= "</td>\n";

			//Ritenuta d'acconto
			$body .= "<td class='table_cell' align='right'>\n";
			$body .= number_format( $rs[0]['ritenutaacconto'], 2, ",", "." )." &euro;";
			$body .= "</td></tr>\n";
			$netto_a_pagare -= $rs[0]['ritenutaacconto'];
		}

		/*
			Netto a pagare (se diverso dal totale)
		*/
		if( $totale_documento!=$netto_a_pagare ){
			$body .= "<tr><td class='first_cell' colspan='2' align='right'>\n";
			$body .= "<b>Netto a pagare:</b>";
			$body .= "</td>\n";

			$body .= "<td class='table_cell_h' align='right'>\n";
			$body .= "<b>".number_format( $netto_a_pagare, 2, ",", "." )." &euro;</b>\n";
			$body .= "</td></tr>\n";
		}
	}
	$body .= "</tbody>\n";
	$body .= "</table>\n";
	
	
	$body .= "<p>".nl2br($rs[0]['note'])."</p>\n";
	
	
	if( $rs[0]['vettore']!='' ) {
		$query_tmp="SELECT *, (SELECT indirizzo FROM an_anagrafiche WHERE idanagrafica=idvettore) AS ind_vettore1, (SELECT indirizzo2 FROM an_anagrafiche WHERE idanagrafica=idvettore) AS ind_vettore2, 
		(SELECT cap FROM an_anagrafiche WHERE idanagrafica=idvettore) AS cap_vettore, (SELECT citta FROM an_anagrafiche WHERE idanagrafica=idvettore) AS citta_vettore, (SELECT provincia FROM an_anagrafiche WHERE idanagrafica=idvettore) AS prov_vettore,
		(SELECT piva FROM an_anagrafiche WHERE idanagrafica=idvettore) AS piva_vettore, (SELECT note FROM an_anagrafiche WHERE idanagrafica=idvettore) AS albo_vettore,
		(SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id=\"".$iddocumento."\"";
		$rs_doc1 = $dbo->fetchArray($query_tmp);
		
		$vettore = " ".$rs[0]['vettore']."";
		$vettore1 = " ".$rs_doc1[0]['ind_vettore2']." - ".$rs_doc1[0]['ind_vettore1']." <br/>".$rs_doc1[0]['cap_vettore']." - ".$rs_doc1[0]['citta_vettore']." (".$rs_doc1[0]['prov_vettore'].")";
		$vettore2 = " Partita IVA: ".$rs_doc1[0]['piva_vettore']."<br/> ".$rs_doc1[0]['albo_vettore']."";
		$query_tmp= '';
	}
	else {
		$vettore = '';
		$vettore1 = '';
		$vettore2 = '';
	}
	
	// dati accompagnatori
	$query_tmp="SELECT *, (SELECT descrizione FROM co_tipidocumento WHERE id=idtipodocumento) AS tipo_doc, (SELECT descrizione FROM dt_aspettobeni WHERE id=idaspettobeni) AS aspettobeni, 
	(SELECT descrizione FROM dt_causalet WHERE id=idcausalet) AS causalet, (SELECT descrizione FROM dt_porto WHERE id=idporto) AS porto, 
	(SELECT descrizione FROM dt_spedizione WHERE id=idspedizione) AS spedizione, 
	(SELECT provincia FROM an_anagrafiche WHERE idanagrafica=idvettore) AS prov_vettore, (SELECT descrizione FROM co_pagamenti WHERE id=idpagamento) AS tipo_pagamento, 
	(SELECT dir FROM co_tipidocumento WHERE id=idtipodocumento) AS dir FROM co_documenti WHERE id=\"".$iddocumento."\"";
	
	$rs_doc = $dbo->fetchArray($query_tmp);
	
	
	//Dati footer ddt vecchio
	if( $rs[0]['vettore']=='VECCHIO' ) {
	$footer  = "<br/><br/><table style='width:200mm;' class='table_values' style='table-layout:fixed;' border='0' cellspacing='1'>\n";
	$footer .= "<col width='169'><col width='169'><col width='169'><col width='169'>\n";
	$footer .= "<tr><td width='169' height='25' class='center'><b>Colli:</b><br/>".$rs_doc[0]['n_colli']."&nbsp;</td>\n";
	$footer .= "<td width='169' class='center'><b>Aspetto beni:</b><br/>".$rs_doc[0]['aspettobeni']."&nbsp;</td>\n";
	$footer .= "<td width='169' class='center'><b>Causale trasporto:</b><br/>".$rs_doc[0]['causalet']."&nbsp;</td>\n";
	$footer .= "<td width='169' class='center'><b>Porto:</b><br/>".$rs_doc[0]['porto']."&nbsp;</td></tr>\n";
	$footer .= "</table>\n";
	
	$footer .= "<table style='width:200mm;' class='table_values' style='table-layout:fixed;' border='0' cellspacing='1'>\n";
	$footer .= "<col width='232'><col width='232'><col width='232'>\n";
	$footer .= "<tr><td width='232' height='25' class='center'><b>Tipo di spedizione:</b><br/>".$rs_doc[0]['spedizione'].$vettore."&nbsp;</td>\n";
	$footer .= "<td width='232' class='center'><b>Conducente:</b><br/>______________________</td>\n";
	$footer .= "<td width='233' class='center'><b>Destinatario:</b><br/>______________________</td></tr>\n";
	$footer .= "</table>\n";
	}
	
	//Dati footer ddt nuovo
	$footer .= "<br/><br/><table style='margin-left:7.5mm;' cellspacing='0'>\n";
	$footer .= "<tr>\n";
	$footer .= "<td>\n";
	$footer .= "<div style='text-align:center; width:200mm; height:5mm;'><br/></div>\n";
	
	// Riga N.1
	$footer .= "<table style='width:200mm; table-layout:fixed;' cellspacing='0'>\n";
	$footer .= "<col width='169'><col width='169'><col width='169'><col width='169'>\n";
	$footer .= "<tr>\n";
	$footer .= "<td class='full_cell1' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>ASPETTO EST. DEI BENI</td>\n";
	$footer .= "<td class='full_cell' style='width:15mm; background: #ddd; font-size:5pt; text-align: center;'>NUMERO COLLI</td>\n";
	$footer .= "<td class='full_cell' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>TRASPORTO A CURA</td>\n";
	$footer .= "<td class='full_cell' style='width:70mm; background: #ddd; font-size:5pt; text-align: center;'>VETTORE</td>\n";
	$footer .= "<td class='full_cell' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>FIRMA CEDENTE</td>\n";
	$footer .= "</tr>\n";

	$footer .= "<tr>\n";
	$footer .= "<td height='15' class='full_cell2' style='width:30mm; font-size:8pt; text-align: center;'>".$rs_doc[0]['aspettobeni']."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:15mm; font-size:8pt; text-align: center;'>".$rs_doc[0]['n_colli']."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; font-size:8pt; text-align: center;'>".$rs_doc[0]['idmezzo']."&nbsp;</td>\n";
	$footer .= "<td class='full_cell6' style='width:70mm; font-size:8pt; text-align: left;'>".$vettore."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm;  font-size:8pt; text-align: center;'></td>\n";
	$footer .= "</tr>\n";
	
	$footer .= "</table>\n";
	
	// Riga N.2
	$footer .= "<table style='width:200mm; table-layout:fixed;' cellspacing='0'>\n";
	$footer .= "<col width='169'><col width='169'><col width='169'><col width='169'>\n";
	$footer .= "<tr>\n";
	$footer .= "<td class='full_cell2' style='width:46.6mm; background: #ddd; font-size:5pt; text-align: center;'>PORTO</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>DATA INIZIO TRASPORTO</td>\n";
	$footer .= "<td class='full_cell6' style='width:70mm; font-size:5pt; text-align: center;'></td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>FIRMA VETTORE/CONDUCENTE</td>\n";
	$footer .= "</tr>\n";

	$footer .= "<tr>\n";
	$footer .= "<td height='15' class='full_cell2' style='font-size:8pt; text-align: center;'>".$rs_doc[0]['porto']."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; font-size:8pt; text-align: center;'>".date( "d/m/Y", strtotime($rs_doc[0]['datatrasporto']) )."&nbsp;</td>\n";
	$footer .= "<td class='full_cell6' style='width:70mm; font-size:8pt; text-align: left;'>".$vettore1."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm;  font-size:8pt; text-align: center;'></td>\n";
	$footer .= "</tr>\n";
	
	$footer .= "</table>\n";

	
	// Riga N.3
	$footer .= "<table style='width:200mm; table-layout:fixed;' cellspacing='0'>\n";
	$footer .= "<col width='169'><col width='169'><col width='169'><col width='169'>\n";
	$footer .= "<tr>\n";
	$footer .= "<td class='full_cell7' style='width:46.6mm; font-size:5pt; text-align: center;'></td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>ORA INIZIO TRASPORTO</td>\n";
	$footer .= "<td class='full_cell6' style='width:70mm; font-size:5pt; text-align: center;'></td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; background: #ddd; font-size:5pt; text-align: center;'>FIRMA DESTINATARIO</td>\n";
	$footer .= "</tr>\n";

	$footer .= "<tr>\n";
	$footer .= "<td height='15' class='full_cell2' style='font-size:8pt; text-align: center;'></td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm; font-size:8pt; text-align: center;'>".date( "H:i", strtotime($rs_doc[0]['oratrasporto']) )."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:60mm; font-size:8pt; text-align: left;'>".$vettore2."&nbsp;</td>\n";
	$footer .= "<td class='full_cell3' style='width:30mm;  font-size:8pt; text-align: center;'></td>\n";
	$footer .= "</tr>\n";
	
	$footer .= "</table>\n";
	
	
	$footer .= "</td>\n";
	$footer .= "</tr>\n";
	$footer .= "</table>\n";
	
	$body = str_replace( "|footer|", $footer, $body );
	$body = str_replace( '$c_causale$', $rs_doc[0]['causalet'], $body );
	
	$report_name = "fattura_".$numero_doc.".pdf";
?>