query($query) ; while ($db->next_record()) { $dataProvv = $db->f("Data") ; $Iva = CalcolaQualeIva($dataProvv) ; $dataProvvVis = ItaDate($db->f("Data")) ; $numCarNomeFornitore = strlen(strtoupper(PreparaStringaPerPDF($db->f("NomeFornitore")))) ; if (($numCarNomeFornitore) > 40) $togli = 3 ; else $togli = 0 ; // create new PDF document $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Fabrizio Curcio'); $pdf->SetTitle('Fattura Provvigionale'); $pdf->SetSubject('Fattura Provvigionale'); $pdf->SetKeywords('PDF'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); // remove default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default monospaced font $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); //set margins $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP - 10, PDF_MARGIN_RIGHT); //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 // add a page $pdf->AddPage(); $pdf->SetFont('dejavusans', '', 10) ; $pdf->Cell(180, 4, strtoupper($arrParGen["NomeAgenzia"]), "", 1, 'C', 0) ; $pdf->SetFont('dejavusans', '', 8); $pdf->Cell(180, 2, $arrParGen["IndirizzoAgenzia"], "", 1, 'C', 0) ; $pdf->Cell(180, 2, "Tel " . $arrParGen['TelefonoAgenzia'] . " - Fax " . $arrParGen['FaxAgenzia'], "", 1, 'C', 0) ; $pdf->Cell(180, 2, "C.F. " . $arrParGen['CodiceFiscaleAgenzia'] . " - P.I. " . $arrParGen['PartitaIvaAgenzia'], "", 1, 'C', 0) ; $pdf->SetLineWidth(0.4) ; $pdf->SetDrawColor(0,128,255) ; $pdf->setCellHeightRatio(6) ; $pdf->SetXY(15, 35) ; $pdf->Cell(25, 0, '', "T", $ln=0, 'C', 0, '', 0, false, 'T', 'C'); $pdf->SetFont('dejavusans', 'I', 14); $pdf->SetFillColor(0,128,255); $pdf->SetTextColor(255, 255, 255) ; $pdf->Cell(30, 6, 'FATTURA', 1, $ln=0, 'C', 1, '', 4, true, 'C', 'C'); $pdf->Cell(125, 0, '', "T", $ln=0, 'C', 0, '', 0, false, 'T', 'C'); // BOX DITTA $pdf->setCellHeightRatio(3) ; $pdf->SetLineWidth(0.3) ; $pdf->SetDrawColor(0, 0, 0) ; $pdf->SetXY(90, 45) ; $pdf->SetFillColor(255, 255, 180) ; $pdf->Cell(5, 0, '', "TL", $ln=0, 'C', 1, '', 0, false, 'T', 'C'); $pdf->SetFont('dejavusans', 'I', 8); $pdf->SetTextColor(0,128,255) ; $pdf->Cell(10, 6, 'Ditta', 0, $ln=0, 'C', 1, '', 4, true, 'C', 'C'); $pdf->Cell(90, 0, '', "TR", $ln=1, 'C', 1, '', 0, false, 'T', 'C'); $pdf->setCellHeightRatio(1) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->SetXY(90, 50) ; $pdf->SetTextColor(0,0,0) ; $pdf->Cell(15, 5, 'Nome:', "L", $ln=0, 'R', 1, '', 0, true, 'C', 'B'); $pdf->SetFont('dejavusans', '', 10-$togli); $pdf->SetLineWidth(0.2) ; $pdf->Cell(75, 4, strtoupper(PreparaStringaPerPDF($db->f("NomeFornitore"))), "B", $ln=1, 'L', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(90, 55) ; $pdf->SetLineWidth(0.3) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(15, 5, 'Indirizzo:', "L", $ln=0, 'R', 1, '', 0, true, 'C', 'B'); $indirizzo = PreparaStringaPerPDF($db->f("Indirizzo")) ; $pdf->SetFont('dejavusans', '', 10-$togli); $pdf->SetLineWidth(0.2) ; $pdf->Cell(85, 5, $indirizzo, "B", $ln=0, 'L', 1, '', 0, true, 'C', 'C') ; $pdf->SetLineWidth(0.3) ; $pdf->Cell(5, 7, "", "R", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $localita = $db->f("Cap") . " " . PreparaStringaPerPDF($db->f("Citta")) . " (" . $db->f("Provincia") . ")" ; $pdf->SetXY(90, 60) ; $pdf->SetLineWidth(0.3) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(15, 5, "Localita':", "L", $ln=0, 'R', 1, '', 0, true, 'C', 'B'); $pdf->SetFont('dejavusans', '', 10-$togli); $pdf->SetLineWidth(0.2) ; $pdf->Cell(85, 4, $localita, "B", $ln=0, 'L', 1, '', 0, true, 'C', 'C') ; $pdf->SetLineWidth(0.3) ; $pdf->Cell(5, 7, "", "R", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(90, 65) ; $pdf->SetLineWidth(0.3) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(2, 6, "", "L", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(13, 6, "Cod. Fisc.", "", $ln=0, 'R', 1, '', 0, true, 'C', 'B'); $codFisc = $db->f("CodFisc") ; $pdf->SetFont('dejavusans', '', 10-$togli); $pdf->SetLineWidth(0.2) ; $pdf->Cell(40, 5, $codFisc, "B", $ln=0, 'L', 1, '', 0, true, 'C', 'B') ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(12, 5, "P. IVA", "", $ln=0, 'R', 1, '', 0, true, 'C', 'B'); $pdf->SetFont('dejavusans', '', 10-$togli); $pdf->SetLineWidth(0.2) ; $pdf->Cell(34, 5, $db->f("PIva"), "B", $ln=0, 'L', 1, '', 0, true, 'C', 'B') ; $pdf->SetLineWidth(0.3) ; $pdf->Cell(4, 7, "", "R", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(90, 70) ; $pdf->Cell(105, 4, "", "LBR", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, 50) ; $pdf->SetFillColor(255, 255, 180) ; $pdf->SetFont('dejavusans', 'I', 8) ; $pdf->SetTextColor(0, 0, 0) ; $pdf->Cell(5, 6, "N.", "LTB", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', 'I', 10); $pdf->SetTextColor(0, 0, 160) ; $pdf->Cell(16, 6, "$id/$anno", "TB", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->SetTextColor(0, 0, 0) ; $pdf->Cell(7, 6, "del:", "TB", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', 'I', 10); $pdf->SetTextColor(0, 0, 160) ; $pdf->Cell(24, 6, $dataProvvVis, "TBR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; if ($db->f('Iva')) { $iva = $db->f("SommaLire") * $Iva / 100 ; $rimborsoBollo = "0,00" ; } else $iva = 0; $totale = $db->f("SommaLire") + $iva ; if ($db->f("Enasarco")) { if ($db->f("CifraEna") > 0) $ena = $db->f("CifraEna") ; elseif ($db->f("SommaLireEna") != 0.00) $ena = $db->f("SommaLireEna") * $percena / 100 ; else $ena = $db->f("SommaLire") * $percena / 100 ; } else $ena = 0 ; if ($db->f("Ritenuta")) $rit = $db->f("SommaLire") * $percrit / 100 ; else $rit = 0 ; $dapagare = round($totale, 2) - round($ena, 2) - round($rit, 2) + $rimborsoBollo; $pdf->SetXY(15, 80) ; $pdf->SetFillColor(255, 255, 255) ; $pdf->SetTextColor(0, 0, 0) ; $pdf->SetFont('dejavusans', '', 10); $pdf->Cell(140, 6, "DESCRIZIONE", "TBLR", $ln=0, 'C', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "COMPETENZE", "TBLR", $ln=1, 'C', 1, '', 0, true, 'C', 'C') ; /* controllo la lunghezza del testo per sapere se spezzarlo in pił parole */ $testo = $db->f("Testo") ; $lunTesto = strlen($testo) ; $ciclo = true ; $i = 0 ; $piuRighe = false ; if ($lunTesto > 60) { debug (0, "LUN = $lunTesto") ; $piuRighe = true ; $out = substr($testo, 0, 60) ; debug (0, "OUT = $out") ; while ($ciclo) { $x = substr($testo, 60 + $i, 1) ; debug (0, "X = $x") ; if ($x <> ' ') { $out .= $x ; debug (0, "OUT = $out") ; $i++ ; } else { $ciclo = false ; $out2 = substr($testo, 61 + $i, strlen($testo)) ; debug (0, "OUT2 = $out2") ; } if (strlen($out) >= $lunTesto) break ; } } $pdf->SetXY(15, 86) ; if ($piuRighe) { if ($out2 != "") { $pdf->Cell(140, 6, PreparaStringaPerPDF($out), "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "", "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, 92) ; $pdf->Cell(140, 6, PreparaStringaPerPDF($out2), "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($db->f("SommaLire")), "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, 98) ; } else { $pdf->Cell(140, 6, PreparaStringaPerPDF($out), "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($db->f("SommaLire")), "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, 92) ; } // $pdf->SetXY(15, 98) ; for ($i=0; $i<=23; $i++) { $pdf->Cell(140, 6, "", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "", "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; } $pdf->Cell(140, 6, "", "BLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "", "BLR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; } else { $pdf->Cell(140, 6, PreparaStringaPerPDF($db->f("Testo")), "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($db->f("SommaLire")), "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, 92) ; for ($i=0; $i<=25; $i++) { $pdf->Cell(140, 6, "", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "", "LR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; } $pdf->Cell(140, 6, "", "BLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, "", "BLR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; } $y = 170 ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(105, $y + 6) ; $pdf->Cell(50, 6, "TOTALE IMPONIBILE", "TLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($db->f("SommaLire")), "TLR", $ln=1, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(105, $y + 12) ; $pdf->Cell(50, 6, "Iva " . $Iva . "%", "TLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($iva), "TLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(105, $y + 18) ; $pdf->Cell(50, 6, "TOTALE FATTURA", "TLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->Cell(40, 6, nfp($totale), "TLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 8); $pdf->SetXY(105, $y + 24) ; $pdf->Cell(50, 6, "Ritenuta d'Acconto 23% sul 50%", "TLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->Cell(40, 6, nfp($rit), "TLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 8); $pdf->SetXY(105, $y + 30) ; $pdf->Cell(50, 6, "Ritenuta Enasarco " . $percenavis . "%", "TLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->Cell(40, 6, nfp($ena), "TLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; // Rimborso bollo se non viene calcolata l'iva if ($rimborsoBollo != "0,00") { $pdf->SetFont('dejavusans', '', 8); $pdf->SetXY(105, $y + 36) ; $pdf->Cell(50, 6, "Rimborso bollo", "TBLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->Cell(40, 6, $rimborsoBollo, "TBLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; // Totale Da Pagare $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(105, $y + 42) ; $pdf->Cell(50, 6, "TOTALE DA PAGARE", "TBLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetFillColor(255, 255, 160) ; $pdf->SetTextColor(0, 0, 160) ; $pdf->Cell(40, 6, nfp($dapagare), "TBLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; } else { // Totale Da Pagare $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(105, $y + 36) ; $pdf->Cell(50, 6, "TOTALE DA PAGARE", "TBLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetFillColor(255, 255, 160) ; $pdf->SetTextColor(0, 0, 160) ; $pdf->Cell(40, 6, nfp($dapagare), "TBLR", $ln=0, 'R', 1, '', 0, true, 'C', 'C') ; } // COORDINATE BANCARIE: $pdf->SetXY(15, $y + 16) ; $pdf->SetTextColor(0, 0, 0) ; $pdf->SetFillColor(255, 255, 255) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(80, 6, "Coordinate Bancarie:", "TLR", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 10); $pdf->SetXY(15, $y + 22) ; $pdf->Cell(80, 6, "MONTE DEI PASCHI DI SIENA", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 8); $pdf->SetXY(15, $y + 28) ; $pdf->Cell(80, 6, "Agenzia di Citta' 146, via dei Galla e Sidama 23, ROMA", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, $y + 34) ; $pdf->Cell(80, 6, "IBAN: IT95E0103003314000000787930", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, $y + 38) ; $pdf->Cell(80, 6, "", "BLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; // NOTE $pdf->SetXY(15, $y + 75) ; $pdf->SetTextColor(0, 0, 0) ; $pdf->SetFillColor(255, 255, 255) ; $pdf->SetFont('dejavusans', 'I', 8); $pdf->Cell(180, 6, "Note:", "TLR", $ln=1, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetFont('dejavusans', '', 8); if ($rimborsoBollo > 0) { $pdf->SetXY(15, $y + 82) ; $pdf->Cell(180, 8, "Operazione effettuata ai sensi dell'articolo 1, commi da 54 a 89, della Legge n. 190/2014 cosi' come modificato dalla Legge", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, $y + 89) ; $pdf->Cell(180, 8, "numero 208/2015 e dalla Legge n. 145/2018", "BLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; } else { $pdf->SetXY(15, $y + 79) ; $pdf->Cell(180, 6, "", "LR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; $pdf->SetXY(15, $y + 83) ; $pdf->Cell(180, 6, "", "BLR", $ln=0, '', 1, '', 0, true, 'C', 'C') ; } } $pdf->SetDisplayMode('real') ; // Per visualizzare l'Apri: // $pdf->Output("Fattura Provvigioni.pdf", 'D') ; // Altrimenti per aprirlo direttamente: $pdf->Output('FatturaProvvigioni.pdf', 'I') ; ?>