RecuperaDati($query) ; if ($n == 0) { /************************************************************* * se non ci sono ordini per questo cliente, allora recupero * solo il nome del cliente **************************************************************/ $query = " SELECT C.Nome as NomeCliente FROM clienti C WHERE IdClienti = $id_cliente " ; list($n, $d) = $db->RecuperaDati($query) ; $nomeC = $d['NomeCliente'][0] ; $noOrdini = "Non ci sono ordini per questo cliente nell'anno $annoReport" ; } else { for ($i=0; $i<$n; $i++) { $nomeC = $d['NomeCliente'][$i] ; $idO = $d['IdOrdine'][$i] ; $nomeF = $d['NomeFornitore'][$i] ; $idF = $d['IdFornitore'][$i] ; $dataO = $d['DataOrdine'][$i] ; $arrF[$nomeF]['DataOrdini'][] = $dataO ; /************************ * recupero i prodotti ************************/ if ($idF != $idsarzi) $qSM = " select * from scontomerce SM, prodotti P where SM.IdOrdine = $idO and SM.Anno = $annoReport and SM.IdProdotto = P.IdProdotti order by P.nome" ; else $qSM = " select * from scontomerce_$annoReport, sarzi_$annoReport where IdOrdine = $idO and scontomerce_$annoReport.idprodotto = CONCAT('SA',idprodotti) order by sarzi_$annoReport.nome" ; list($nSM, $dSM) = $dbSM->RecuperaDati($qSM) ; if ($nSM > 0) { for ($sm=0 ; $sm<$nSM; $sm++) { $nomeP = $dSM["Nome"][$sm] ; $nBott = $dSM["NumCartoni"][$sm] * $dSM["ConfezioniDa"][$sm] ; debug (0, "$idO ; NOME P = $nomeP ; numBott = $nBott") ; $arrF[$nomeF]['Prodotti'][$nomeP][$dataO]['SM'] = $nBott ; } } if ($idF != $idsarzi) $qPR = " select * from dettagli D, prodotti P where D.IdOrdine = $idO and D.Anno = $annoReport and D.IdProdotto = P.IdProdotti order by P.nome" ; else $qPR = " select * from dettagli_$annoReport, sarzi_$annoReport where IdOrdine = $idO and dettagli_$annoReport.idprodotto = CONCAT('SA',idprodotti) order by sarzi_$annoReport.nome" ; list($nPR, $dPR) = $dbSM->RecuperaDati($qPR) ; if ($nPR > 0) { for ($pr=0 ; $pr<$nPR; $pr++) { $nomeP = $dPR["Nome"][$pr] ; $nBott = $dPR["NumCartoni"][$pr] * $dPR["ConfezioniDa"][$pr] ; debug (0, "$idO ; NOME P = $nomeP ; numBott = $nBott") ; $arrF[$nomeF]['Prodotti'][$nomeP][$dataO]['PR'] = $nBott ; } } } } // print_r($arrF) ; exit ; class MYPDF extends TCPDF { public function Header() { global $nomeC ; global $annoReport ; $this->SetFillColor(255, 255, 255); $this->SetTextColor(0); $this->SetFont('helvetica', '', 9); $this->Cell(110, 6, PreparaStringaPerPDF($nomeC), "LTRB", 0, 'L', 1) ; $this->Cell(40, 6, " Acquisti anno: $annoReport", "LTRB", 0, 'L', 1) ; $this->Cell(40, 6, " Data Report: " . date("d-m-Y"), "LTRB", 0, 'L', 1) ; } // Page footer public function Footer() { // Position at 15 mm from bottom $this->SetY(-15); // Set font $this->SetFont('helvetica', 'I', 8); // Page number $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M'); } } // create new PDF document $pdf = new MYPDF("L", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Fabrizio Curcio'); $pdf->SetTitle('Report Cliente'); $pdf->SetSubject('Report Cliente'); $pdf->SetKeywords('PDF'); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 60, PDF_MARGIN_RIGHT); $pdf->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); //set auto page breaks $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); //set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set some language-dependent strings $pdf->setLanguageArray($l); $pdf->AddPage(); $pdf->SetLineWidth(0.1); $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0); $pdf->SetXY(15, 20) ; @reset($arrF) ; $pdf->SetFont('helvetica', '', 7); if (count($arrF) > 0) { foreach($arrF as $nomeF => $arrDO) { $pdf->Cell(60, 6, PreparaStringaPerPDF($nomeF), "LTRB", 0, 'L', 0) ; foreach($arrDO['DataOrdini'] as $id => $dataO) { if ($dataO != "") $pdf->Cell(14, 6, ItaDate_2($dataO), "LTRB", 0, 'C', 0) ; } $pdf->Cell(14, 6, "Totale", "LTRB", 1, 'C', 0) ; $arrDate = $arrDO['DataOrdini'] ; // print_r($arrDate) ; foreach($arrDO['Prodotti'] as $nomeP => $arrDOP) { $nomeP = substr($nomeP, 0, 40) ; $pdf->Cell(60, 6, PreparaStringaPerPDF($nomeP), "LTRB", 0, 'R', 0) ; // print_r($arrDOP) ; $dataTrovata = false ; foreach ($arrDate as $indice => $data) { // echo "INDICE = $indice , DATA = $data ;\n" ; foreach($arrDOP as $dataOP => $arrQ) { // echo("DATAOP: $dataOP\n") ; if ($dataOP == $data) { $dataTrovata = true ; $numBott = $arrQ['PR'] + $arrQ['SM'] ; $numBottTot += $numBott ; // echo "TROVATA\n" ; break ; } else { // echo "NON TROVATA\n" ; } } if ($dataTrovata) { $dataTrovata = false ; $pdf->Cell(14, 6, $arrQ['SM'] + $arrQ['PR'], "LTRB", 0, 'C', 0) ; } else $pdf->Cell(14, 6, "", "LTRB", 0, 'C', 0) ; // $pdf->Cell(14, 6, "", "", 1, 'L', 0) ; @reset($arrDOP) ; } $pdf->Cell(14, 6, "$numBottTot", "LTRB", 1, 'C', 0) ; $numBottTot = 0 ; } $pdf->Cell(14, 6, "", "", 1, 'L', 0) ; } } else { $pdf->SetFont('helvetica', '', 10); $pdf->Cell(190, 6, $noOrdini, "LTRB", 0, 'C', 0) ; } $pdf->SetDisplayMode('real') ; //Close and output PDF document $fileName = Date("Y-m-d ") . $nomeCliente . ".pdf" ; // $pdf->Output($fileName, 'D') ; $pdf->Output($fileName, 'I') ; // exit ; ?>