Codice PHP:
<?php require_once('../../Connections/connStudio.php'); ?>
<?php require('../../include/vars.php'); ?>
<?php
$colname_RecPreventivo = "-1";
if (isset($_GET['id'])) {
$colname_RecPreventivo = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_connStudio, $connStudio);
$query_RecPreventivo = sprintf("SELECT * FROM st_preventivi WHERE id = %s", $colname_RecPreventivo);
$RecPreventivo = mysql_query($query_RecPreventivo, $connStudio) or die(mysql_error());
$row_RecPreventivo = mysql_fetch_assoc($RecPreventivo);
$totalRows_RecPreventivo = mysql_num_rows($RecPreventivo);
$id_resp = $row_RecPreventivo['id_resp'];
mysql_select_db($database_connStudio, $connStudio);
$query_RecResponsabile = "SELECT * FROM st_responsabili WHERE id = '$id_resp'";
$RecResponsabile = mysql_query($query_RecResponsabile, $connStudio) or die(mysql_error());
$row_RecResponsabile = mysql_fetch_assoc($RecResponsabile);
$totalRows_RecResponsabile = mysql_num_rows($RecResponsabile);
$id = $row_RecPreventivo['id_clifor'];
mysql_select_db($database_connStudio, $connStudio);
$query_RecCliente = "SELECT * FROM clientifornitori WHERE id ='$id'";
$RecCliente = mysql_query($query_RecCliente, $connStudio) or die(mysql_error());
$row_RecCliente = mysql_fetch_assoc($RecCliente);
$totalRows_RecCliente = mysql_num_rows($RecCliente);
$colname_RecVociInterne = "-1";
if (isset($_GET['id'])) {
$colname_RecVociInterne = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_connStudio, $connStudio);
$query_RecVociInterne = sprintf("SELECT * FROM st_voci_interne WHERE id_prev = %s ORDER BY posizione ASC", $colname_RecVociInterne);
$RecVociInterne = mysql_query($query_RecVociInterne, $connStudio) or die(mysql_error());
$row_RecVociInterne = mysql_fetch_assoc($RecVociInterne);
$totalRows_RecVociInterne = mysql_num_rows($RecVociInterne);
$colname_RecVociEsterne = "-1";
if (isset($_GET['id'])) {
$colname_RecVociEsterne = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_connStudio, $connStudio);
$query_RecVociEsterne = sprintf("SELECT * FROM st_voci_esterne WHERE id_prev = %s ORDER BY posizione ASC", $colname_RecVociEsterne);
$RecVociEsterne = mysql_query($query_RecVociEsterne, $connStudio) or die(mysql_error());
$row_RecVociEsterne = mysql_fetch_assoc($RecVociEsterne);
$totalRows_RecVociEsterne = mysql_num_rows($RecVociEsterne);
?><?php
require('../../include/fpdf/fpdf.php');
class PDF extends FPDF
{
//Page header
function Header()
{
//Logo
//$this->Image('../../immagini/briefing.png',10,8,33);
//Arial bold 15
$this->Image('../../immagini/preventivo.jpg',0,0,210);
$this->SetFont('Arial','B',12);
//Move to the right
//$this->Cell(80);
//Title
//$this->SetXY(80,10);
//$this->WRITE(5,$_st_privacy_intesta1);
//$this->SetFont('Arial','',10);
//$this->SetXY(80,10);
//$this->WRITE(5,$_st_privacy_intesta1);
//Line break
/*
require('../../include/vars.php');
$this->SetX(10);
$this->Cell(180,5,$st_privacy_intesta1,0,1,"C");
$this->SetFont('Arial','',10);
$this->Cell(180,5,$st_privacy_intesta2,0,1,"C");
$this->Cell(180,5,$st_privacy_intesta3,0,1,"C");
*/
$this->Ln(25);
}
//Page footer
function Footer()
{
//Position at 1.5 cm from bottom
$this->SetY(-15);
//Arial italic 8
$this->SetFont('Arial','I',8);
//Page number
$this->Cell(0,10,'Pagina '.$this->PageNo().'/{nb}',0,0,'C');
}
}
$data = $row_RecPreventivo['data'];
$numprev = $row_RecPreventivo['id'];
$prodotto = $row_RecPreventivo['lineaprodotto'];
//Instanciation of inherited class
$pdf=new PDF();
//$pdf->SetRightMargin(1);
$pdf->AliasNbPages();
$pdf->AddPage();
//$pdf->SetFont('Times','',10);
//$pdf->Write(5,"Preventivo n. $numprev \n\n");
$pdf->SetFont('Times','IB',10);
$pdf->Cell(175,5,"Spettabile",0,0,'R');
$pdf->Ln(5);
$pdf->Cell(175,5,$row_RecCliente['insegna'],0,0,'R');
$pdf->Ln(5);
$pdf->Cell(175,5,$row_RecCliente['indirizzo'],0,0,'R');
$pdf->Ln(5);
$pdf->Cell(175,5,$row_RecCliente['cap']." ".$row_RecCliente['citta']." (".$row_RecCliente['prov'].")",0,0,'R');
$pdf->Ln(10);
$contatto = $row_RecResponsabile['responsabile'];
$pdf->Cell(175,5,"Alla Cortese Attenzione",0,0,'R');
$pdf->Ln(5);
$pdf->Cell(175,5,"Sig. $contatto",0,0,'R');
$pdf->Ln(10);
$pdf->SetXY(30,80);
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"$st_privacy_citta, $data \n\n");
$pdf->SetFont('Times','BU',10);
$pdf->SetX(30);
$pdf->Write(5,"Oggetto: Preventivo per $prodotto \n\n");
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"Lavorazioni:\n\n");
// inserisco voci interne
do {
$descrizione = $row_RecVociInterne['descrizione'];
$importo = number_format($row_RecVociInterne['preventivo'], 2, ',', '.');
$pdf->SetX(30);
$pdf->Write(5,"$descrizione");
$pdf->SetX(150);
if (($_GET['tipo'] == 1) || ($_GET['tipo'] == 3) || ($_GET['tipo'] == 4)){
$pdf->Cell(20,5,"$importo €\n",0,0,'R');}
if ($row_RecVociInterne['pubblica'] == 'S'){
$note = $row_RecVociInterne['note'];
$pdf->SetX(40);
$y = $pdf->GetY() + 5;
$pdf->SetY($y);
$pdf->Write(5," $note");
}
$totale = $totale + $row_RecVociInterne['preventivo'];
$pdf->SetX(40);
$y = $pdf->GetY() + 5;
$pdf->SetY($y);
} while ($row_RecVociInterne = mysql_fetch_assoc($RecVociInterne));
if (($_GET['tipo'] == 1) || ($_GET['tipo'] == 2) || ($_GET['tipo'] == 4)){
$y = $pdf->GetY() + 10;
$pdf->SetY($y);
$pdf->SetX(30);
$pdf->Write(5,"Totale preventivo iva esclusa:");
$pdf->SetX(150);
$pdf->Cell(20,5,number_format($totale, 2, ',', '.'),0,0,'R');
}
$pdf->SetX(40);
$y = $pdf->GetY() + 5;
$pdf->SetY($y);
/*
$pdf->Write(5,"\n\nLavori fatturati direttamente da terze parti:\n\n");
// inserisco voci esterne
do {
$descrizione = $row_RecVociEsterne['descrizione'];
$importo = number_format($row_RecVociEsterne['previsione'], 2, ',', '.');
$pdf->Write(5,"$descrizione");
$pdf->SetX(150);
$pdf->Cell(20,5,"$importo\n",0,0,'R');
$totale = $totale + importo;
$pdf->SetX(10);
$y = $pdf->GetY() + 5;
$pdf->SetY($y);
} while ($row_RecVociEsterne = mysql_fetch_assoc($RecVociEsterne));
*/
//Stampo dati finali
$pagamento = $row_RecPreventivo['pagamento'];
$consegna_prevista = $row_RecPreventivo['consegna_prevista'];
$conferma_ordine = $row_RecPreventivo['conferma_ordine'];
$validita_preventivo = $row_RecPreventivo['validita_preventivo'];
$pdf->SetFont('Times','B',10);
$y = $pdf->GetY() + 10;
$pdf->SetY($y);
$pdf->SetX(30);
$pdf->Write(5,"Metodo di pagamento:\n");
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"$pagamento\n\n");
$pdf->SetFont('Times','B',10);
$pdf->SetX(30);
$pdf->Write(5,"Consegna prevista:\n");
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"$consegna_prevista\n\n");
$pdf->SetFont('Times','B',10);
$pdf->SetX(30);
$pdf->Write(5,"Conferma ordine:\n");
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"$conferma_ordine\n\n");
$pdf->SetFont('Times','B',10);
$pdf->SetX(30);
$pdf->Write(5,"Validità preventivo:\n");
$pdf->SetFont('Times','',10);
$pdf->SetX(30);
$pdf->Write(5,"$validita_preventivo\n\n\n\n");
$pdf->SetX(30);
$pdf->Write(5,"Timbro e firma per accettazione\n\n");
$pdf->SetX(30);
$pdf->Write(5,"...................................................");
//$pdf->SetX(120);
//$pdf->Cell(50,5,$st_privacy_titolare_fisico,0,1,"C");
//$pdf->SetX(120);
//$pdf->Cell(50,5,$st_privacy_titolare_giuridico,0,1,"C");
$updateSQL = sprintf("UPDATE st_preventivi SET stato='GENERATO' WHERE id=%s",
$_GET['id'], "int");
mysql_select_db($database_connStudio, $connStudio);
$Result1 = mysql_query($updateSQL, $connStudio) or die(mysql_error());
list($gg, $mm, $aa) = split("/", $row_RecPreventivo['data']);
$pdf->Output("../../documenti/preventivi/".$numprev."-".$aa."-".$row_RecCliente['insegna'].".pdf");
if ($_GET['dest'] == "EMAIL"){
?>
<HTML>
<HEAD>
<TITLE>Redirect...</TITLE>
<META HTTP-EQUIV="REFRESH" CONTENT="0; URL=mailto:<?php echo $row_RecResponsabile['email']; ?>?subject=Preventivo <?php echo $numprev."-".$aa."-".$row_RecCliente['insegna'].".pdf";?>&body=Spett.le <?php echo $row_RecCliente['insegna']; ?>,%0A%0Ainviamo il preventivo come da accordi.%0ACordiali saluti.%0A%0A<?php echo $st_privacy_titolare_fisico."%0A".$st_privacy_titola//re_giuridico;?>&attachment=<?php echo "//localhost/studio/documenti/preventivi/".$numprev."-".$aa."-".$row_RecCliente['insegna'].".pdf";?>">
</HEAD>
<BODY>
Invio al client di posta in corso...
[url="javascript:window.close();"]Clicca qui per chiudere[/url]
</BODY>
</HTML>
<?
}elseif($_GET['dest'] == "PDF"){
$pdf->Output();
}
?>
<?php
mysql_free_result($RecCliente);
mysql_free_result($RecVociInterne);
?>