query("select * from $tfornitori where idfornitori = $selFor") ; while ($db->next_record()) $nomefor = $db->f("Nome") ; $Fornitore = "$nomefor" ; } /************************* * filtro Clienti **************************/ if ((isset($selCli) and ($selCli != 'tutti') and ($selCli != '')) ) { $where .= " and O.idcliente = $selCli" ; $db->query("select * from $tclienti where idclienti = $selCli") ; while ($db->next_record()) $nomecli = $db->f("Nome") ; $Cliente = "$nomecli" ; } /************************* * filtro Inaccasate **************************/ if (isset($selInc) and ($selInc != 'tutti') and ($selInc != '')) $where .= " and O.SaldoFattura = $selInc" ; /*************************************** * controllo la colonna da ordinare ***************************************/ switch($ordinaper) { case 0: // numero ordine $order_by = "O.idordini $direction" ; break ; case 1: // numero fattura $order_by = "O.NumFattura $direction, O.idordini" ; break ; case 2: // data fattura $order_by = "O.DataSpedFattura $direction, O.NumFattura" ; break ; case 3: // data scadenza fattura $order_by = "O.DataScadFattura $direction, O.NumFattura" ; break ; case 4: // fornitore $order_by = "F.Nome $direction, O.NumFattura" ; break ; case 5: // cliente $order_by = "C.Nome $direction, O.DataScadFattura ASC, O.NumFattura" ; break ; case 6: // importo fattura $order_by = "O.ImportoFattura $direction, O.NumFattura" ; break ; case 7: // fattura incassata? $order_by = "O.SaldoFattura $direction, O.NumFattura" ; break ; } $arrParGen = array() ; $arrParGen = RecuperaParametriGenerali($arrParGen, $tparametri) ; $hTitle = $arrParGen['NomeAgenzia'] ; $hString = "Sede operativa: " . $arrParGen['IndirizzoAgenzia'] . "\n" ; $hString .= "Telefono: " . $arrParGen['TelefonoAgenzia'] . " Fax: " . $arrParGen['FaxAgenzia'] . " -- P.I. " . $arrParGen['PartitaIvaAgenzia'] ; $hString .= "-- Email: " . $arrParGen['MailAgenzia'] ; // eseguo la query $totImporto = 0 ; $totImponibile = 0 ; $totIncassato = 0 ; $query = " select O.*, P.Modalita as TipoPagamento, F.nome as NomeFornitore, C.nome as NomeCliente from ordini O inner join fornitori F on F.idfornitori = O.idfornitore inner join clienti C on C.idclienti = O.idcliente inner join pagamenti P on P.idpagamenti = O.idpagamento where O.Anno = $anno and O.dataspedfattura <> '' and O.dataspedfattura <> '0000-00-00' and O.NumFattura <> '9999' and $where order by $order_by " ; list($n, $d) = $db->RecuperaDati($query) ; class MYPDF extends TCPDF { //Page header public function Header() { $this->SetFillColor(224, 235, 255); $this->SetTextColor(0); // Set font $this->SetFont('helvetica', 'B', 8); // Title $this->Cell(10, 5, 'Cliente', "LTB", 0, 'L', 1) ; $this->SetFont('helvetica', 'B', 7); $this->Cell(55, 5, "Fornitore", "TB", 0, 'R', 1) ; $this->Cell(15, 5, "Num Fatt", "TB", 0, 'R', 1) ; $this->Cell(18, 5, "Pagamento", "TB", 0, 'R', 1) ; $this->Cell(13, 5, "Data Fatt", "TB", 0, 'R', 1) ; $this->Cell(16, 5, "Data Scad", "TB", 0, 'R', 1) ; $this->Cell(16, 5, "Importo", "TB", 0, 'R', 1) ; $this->Cell(15, 5, "Incassato", "TB", 0, 'R', 1) ; $this->Cell(20, 5, "Da avere", "TBR", 1, 'C', 1) ; $this->SetFillColor(255, 255, 255); $this->SetFont('helvetica', '', 7) ; $this->Cell(150, 5, "Lista Fatture in data " . Date("d/m/Y") , "T", 1, 'L', 1) ; $this->Cell(0, 0, "", "B", 1, '', 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("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // $pdf = new TCPDF("P", PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Fabrizio Curcio'); $pdf->SetTitle('Lista Agenti'); $pdf->SetSubject('Lista Agenti'); $pdf->SetKeywords('PDF, lista, agenti, totali'); // set default header data $pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, 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); // set default header data $pdf->SetHeaderData('', PDF_HEADER_LOGO_WIDTH, $hTitle, $hString); // set header and footer fonts $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, 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); // --------------------------------------------------------- // set font $pdf->SetFont('helvetica', '', 8); // add a page $pdf->AddPage(); // print a line using Cell() // $pdf->Cell(0, 0, $titolo, 0, 1, 'C') ; if ($Cliente != 'Tutti' and $Fornitore != "Tutti") { $pdf->SetFont('helvetica', '', 8); $pdf->Cell(20, 3, "Cliente: ", 0, 0, 'R') ; $pdf->SetFont('helvetica', 'B', 8); $pdf->Cell(0, 0, $Cliente, 0, 1, 'L') ; $pdf->SetFont('helvetica', '', 8); $pdf->Cell(20, 3, "Azienda: ", 0, 0, 'R') ; $pdf->SetFont('helvetica', 'B', 8); $pdf->Cell(0, 0, $Fornitore, 0, 1, 'L') ; $pdf->Ln(); $pdf->SetFont('helvetica', 'B', 8); $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0, 0, 0); $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.1); $pdf->Cell(25, 5, 'N. Ord.', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'N. Fattura', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Data Fattura', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Importo', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Imponibile', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Incassato', 1, 0, 'C', 1); $pdf->Ln(); for ($i=0; $i<$n; $i++) { $totImporto += $d['ImportoFattura'][$i] ; $imponibile = nfe((100 * $d['ImportoFattura'][$i]) / 120) ; $totImponibile += ((100 * $d['ImportoFattura'][$i]) / 120) ; if ($d['SaldoFattura'][$i]) $totIncassato += $d['ImportoFattura'][$i] ; $pdf->SetFont('helvetica', '', 8) ; $pdf->Cell(25, 5, $d['IdOrdini'][$i], 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $d['NumFattura'][$i], 1, 0, 'C', 1) ; $pdf->Cell(30, 5, ItaDate($d['DataSpedFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($d['ImportoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $imponibile, 1, 0, 'C', 1) ; $pdf->Cell(30, 5, SiNo($d['SaldoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Ln(); } $pdf->Ln(); $pdf->Cell(25, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $i, 1, 0, 'C', 1) ; $pdf->Cell(30, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImporto), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImponibile), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totIncassato), 1, 0, 'C', 1) ; } elseif ($Cliente != 'Tutti' and $Fornitore == "Tutti") { $pdf->SetFont('helvetica', '', 8); $pdf->Cell(20, 3, "Cliente: ", 0, 0, 'R') ; $pdf->SetFont('helvetica', 'B', 8); $pdf->Cell(0, 0, $Cliente, 0, 1, 'L') ; $pdf->Ln(); $pdf->SetFont('helvetica', 'B', 8); $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0, 0, 0); $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.1); $pdf->Cell(25, 5, 'N. Ord.', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'N. Fattura', 1, 0, 'C', 1); $pdf->Cell(90, 5, 'Fornitore', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Data Fattura', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Importo', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Imponibile', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Incassato', 1, 0, 'C', 1); $pdf->Ln(); for ($i=0; $i<$n; $i++) { $totImporto += $d['ImportoFattura'][$i] ; $imponibile = nfe((100 * $d['ImportoFattura'][$i]) / 120) ; $totImponibile += ((100 * $d['ImportoFattura'][$i]) / 120) ; if ($d['SaldoFattura'][$i]) $totIncassato += $d['ImportoFattura'][$i] ; $pdf->SetFont('helvetica', '', 8) ; $pdf->Cell(25, 5, $d['IdOrdini'][$i], 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $d['NumFattura'][$i], 1, 0, 'C', 1) ; $pdf->Cell(90, 5, $d['NomeFornitore'][$i], 1, 0, 'L', 1) ; $pdf->Cell(30, 5, ItaDate($d['DataSpedFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($d['ImportoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $imponibile, 1, 0, 'C', 1) ; $pdf->Cell(30, 5, SiNo($d['SaldoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Ln(); } $pdf->Ln(); $pdf->Cell(25, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $i, 1, 0, 'C', 1) ; $pdf->Cell(90, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImporto), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImponibile), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totIncassato), 1, 0, 'C', 1) ; } elseif ($Cliente == 'Tutti' and $Fornitore != "Tutti") { $pdf->SetFont('helvetica', '', 8); $pdf->Cell(20, 3, "Fornitore: ", 0, 0, 'R') ; $pdf->SetFont('helvetica', 'B', 8); $pdf->Cell(0, 0, $Fornitore, 0, 1, 'L') ; $pdf->Ln(); $pdf->SetFont('helvetica', 'B', 8); $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0, 0, 0); $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.1); $pdf->Cell(25, 5, 'N. Ord.', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'N. Fattura', 1, 0, 'C', 1); $pdf->Cell(90, 5, 'Cliente', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Data Fattura', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Importo', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Imponibile', 1, 0, 'C', 1); $pdf->Cell(30, 5, 'Incassato', 1, 0, 'C', 1); $pdf->Ln(); for ($i=0; $i<$n; $i++) { $totImporto += $d['ImportoFattura'][$i] ; $imponibile = nfe((100 * $d['ImportoFattura'][$i]) / 120) ; $totImponibile += ((100 * $d['ImportoFattura'][$i]) / 120) ; if ($d['SaldoFattura'][$i]) $totIncassato += $d['ImportoFattura'][$i] ; $pdf->SetFont('helvetica', '', 8) ; $pdf->Cell(25, 5, $d['IdOrdini'][$i], 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $d['NumFattura'][$i], 1, 0, 'C', 1) ; $pdf->Cell(90, 5, $d['NomeCliente'][$i], 1, 0, 'L', 1) ; $pdf->Cell(30, 5, ItaDate($d['DataSpedFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($d['ImportoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $imponibile, 1, 0, 'C', 1) ; $pdf->Cell(30, 5, SiNo($d['SaldoFattura'][$i]), 1, 0, 'C', 1) ; $pdf->Ln(); } $pdf->Ln(); $pdf->Cell(25, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, $i, 1, 0, 'C', 1) ; $pdf->Cell(90, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, "", 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImporto), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totImponibile), 1, 0, 'C', 1) ; $pdf->Cell(30, 5, nfe($totIncassato), 1, 0, 'C', 1) ; } else // caso Cliente = Tutti e Fornitori = Tutti { $pdf->SetFont('helvetica', 'B', 8); $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0, 0, 0); $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.1); // print_r($d) ; // exit ; for ($i=0; $i<$n; $i++) { $idC = $d['IdCliente'][$i] ; $idO = $d['IdOrdini'][$i] ; $nomeFornitore = str_replace("è", "e'", $d['NomeFornitore'][$i]) ; $nomeFornitore = str_replace("é", "e'", $nomeFornitore) ; $nomeFornitore = str_replace("à", "a'", $nomeFornitore) ; $nomeCliente = str_replace("è", "e'", $d['NomeCliente'][$i]) ; $nomeCliente = str_replace("é", "e'", $nomeCliente) ; $nomeCliente = str_replace("à", "a'", $nomeCliente) ; $nomeCliente = str_replace("ì", "i'", $nomeCliente) ; if (! array_key_exists($idC, $arrVal)) { $arrVal[$idC] = array('NomeCliente' => $nomeCliente, 'ListaOrdini' => array() ) ; $arrTotSinCliente[$idC] = array('Incassato' => 0, 'NonIncassato' => 0 ) ; } if (! array_key_exists($idO, $arrVal[$idC]['ListaOrdini'])) { $arrVal[$idC]['ListaOrdini'][$idO] = array('Fornitore' => $nomeFornitore, 'DataSpedFattura' => ItaDate($d['DataSpedFattura'][$i]), 'DataScadFattura' => ItaDate($d['DataScadFattura'][$i]), 'NumeroFattura' => $d['NumFattura'][$i], 'TipoPagamento' => $d['TipoPagamento'][$i], 'ImportoFattura' => nfe($d['ImportoFattura'][$i]), 'Incassata' => SiNo($d['SaldoFattura'][$i]), 'ImpIncassato' => nfe("0"), 'ImpNonIncassato' => nfe("0"), ) ; } if ($d['SaldoFattura'][$i]) { $arrVal[$idC]['ListaOrdini'][$idO]['ImpIncassato'] = nfe($d['ImportoFattura'][$i]) ; $arrTotSinCliente[$idC]['Incassato'] += $d['ImportoFattura'][$i] ; $totIncassato += $d['ImportoFattura'][$i] ; } else { $arrVal[$idC]['ListaOrdini'][$idO]['ImpNonIncassato'] = nfe($d['ImportoFattura'][$i]) ; $arrTotSinCliente[$idC]['NonIncassato'] += $d['ImportoFattura'][$i] ; $totNonIncassato += $d['ImportoFattura'][$i] ; } $totImporto += $d['ImportoFattura'][$i] ; $imponibile = nfe((100 * $d['ImportoFattura'][$i]) / 120) ; $totImponibile += ((100 * $d['ImportoFattura'][$i]) / 120) ; } } // print_r($arrVal) ; // print_r($arrTotSinCliente) ; // exit ; $pdf->SetDisplayMode('real') ; $pdf->SetFillColor(255, 255, 255); $pdf->SetTextColor(0, 0, 0); $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.1); @reset($arrVal) ; foreach($arrVal as $idCliente => $arrValori) // while(list($idCliente, $arrValori) = each($arrVal)) { $pdf->SetFont('helvetica', 'B', 8) ; $pdf->Cell(150, 5, $arrValori['NomeCliente'], 0, 1, 'L', 1) ; foreach($arrValori['ListaOrdini'] as $idOrdine => $arrValOrdini) // while(list($idOrdine, $arrValOrdini) = each($arrValori['ListaOrdini'])) { $pdf->SetFont('helvetica', '', 7) ; $pdf->Cell(70, 4, $arrValOrdini['Fornitore'], 0, 0, 'R', 0) ; $pdf->Cell(10, 4, $arrValOrdini['NumeroFattura'], 0, 0, 'R', 0) ; $pdf->Cell(18, 4, $arrValOrdini['TipoPagamento'], 0, 0, 'R', 0) ; $pdf->Cell(15, 4, $arrValOrdini['DataSpedFattura'], 0, 0, 'R', 0) ; $pdf->Cell(15, 4, $arrValOrdini['DataScadFattura'], 0, 0, 'R', 0) ; $pdf->Cell(15, 4, $arrValOrdini['ImportoFattura'], 0, 0, 'R', 0) ; $pdf->Cell(15, 4, $arrValOrdini['ImpIncassato'], 0, 0, 'R', 0) ; $pdf->Cell(15, 4, $arrValOrdini['ImpNonIncassato'], 0, 1, 'R', 0) ; } $pdf->Cell(80, 0, "", 0, 0, '', 1) ; $pdf->Cell(0, 0, "", "B", 1, '', 1) ; $pdf->SetFont('helvetica', 'B', 7) ; $pdf->Cell(80, 5, "", 0, 0, 'L', 0) ; $pdf->Cell(48, 5, "Saldo Totale Cliente (Euro)", 0, 0, 'L', 0) ; $pdf->Cell(15, 5, nfe($arrTotSinCliente[$idCliente]['Incassato'] + $arrTotSinCliente[$idCliente]['NonIncassato']), 0, 0, 'R', 0) ; $pdf->Cell(15, 5, nfe($arrTotSinCliente[$idCliente]['Incassato']), 0, 0, 'R', 0) ; $pdf->Cell(15, 5, nfe($arrTotSinCliente[$idCliente]['NonIncassato']), 0, 1, 'R', 0) ; $pdf->Cell(0, 0, "", "B", 1, '', 1) ; $pdf->Ln() ; } $pdf->SetFont('helvetica', 'B', 7) ; $pdf->Cell(80, 5, "", 0, 0, 'L', 0) ; $pdf->Cell(48, 5, "Totale Agenzia", 0, 0, 'L', 0) ; $pdf->Cell(15, 5, nfe($totIncassato + $totNonIncassato), 0, 0, 'R', 0) ; $pdf->Cell(15, 5, nfe($totIncassato), 0, 0, 'R', 0) ; $pdf->Cell(15, 5, nfe($totNonIncassato), 0, 1, 'R', 0) ; $pdf->Cell(0, 0, "", B, 1, '', 1) ; $pdf->Ln() ; //Close and output PDF document $pdf->Output('stampaListaAgentiPDF.pdf', 'I') ; ?>