TCPDF(); $this->angle=0; define('EURO', chr(128) ); define('EURO_VAL', 84.27 ); } // private functions function RoundedRect($x, $y, $w, $h, $r, $style = '') { $k = $this->k; $hp = $this->h; if($style=='F') $op='f'; elseif($style=='FD' or $style=='DF') $op='B'; else $op='S'; $MyArc = 4/3 * (sqrt(2) - 1); $this->_out(sprintf('%.2f %.2f m',($x+$r)*$k,($hp-$y)*$k )); $xc = $x+$w-$r ; $yc = $y+$r; $this->_out(sprintf('%.2f %.2f l', $xc*$k,($hp-$y)*$k )); $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc); $xc = $x+$w-$r ; $yc = $y+$h-$r; $this->_out(sprintf('%.2f %.2f l',($x+$w)*$k,($hp-$yc)*$k)); $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r); $xc = $x+$r ; $yc = $y+$h-$r; $this->_out(sprintf('%.2f %.2f l',$xc*$k,($hp-($y+$h))*$k)); $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc); $xc = $x+$r ; $yc = $y+$r; $this->_out(sprintf('%.2f %.2f l',($x)*$k,($hp-$yc)*$k )); $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r); $this->_out($op); } function _Arc($x1, $y1, $x2, $y2, $x3, $y3) { $h = $this->h; $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $x1*$this->k, ($h-$y1)*$this->k, $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k)); } function Rotate($angle,$x=-1,$y=-1) { if($x==-1) $x=$this->x; if($y==-1) $y=$this->y; if($this->angle!=0) $this->_out('Q'); $this->angle=$angle; if($angle!=0) { $angle*=M_PI/180; $c=cos($angle); $s=sin($angle); $cx=$x*$this->k; $cy=($this->h-$y)*$this->k; $this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy)); } } function _endpage() { if($this->angle!=0) { $this->angle=0; $this->_out('Q'); } parent::_endpage(); } // public functions function sizeOfText( $texte, $largeur ) { $index = 0; $nb_lines = 0; $loop = TRUE; while ( $loop ) { $pos = strpos($texte, "\n"); if (!$pos) { $loop = FALSE; $ligne = $texte; } else { $ligne = substr( $texte, $index, $pos); $texte = substr( $texte, $pos+1 ); } $length = floor( $this->GetStringWidth( $ligne ) ); $res = 1 + floor( $length / $largeur) ; $nb_lines += $res; } return $nb_lines; } // Company function addSociete( $nom, $adresse ) { $x1 = 10; $y1 = 8; //Positionnement en bas $this->SetXY( $x1, $y1 ); $this->SetFont('arial','',12); $length = $this->GetStringWidth( $nom ); $this->Cell( $length, 2, $nom); $this->SetXY( $x1, $y1 + 4 ); $this->SetFont('Arial','',10); $length = $this->GetStringWidth( $adresse ); //Coordonnées de la société $lignes = $this->sizeOfText( $adresse, $length) ; $this->MultiCell($length, 4, $adresse); } function dodajNaslovDokumenta($naslov) { $x1 = 10; $y1 = 40; //Positionnement en bas $this->SetXY( $x1, $y1 ); $this->SetFont('arial','',26); $this->SetTextColor(203,203,203); $length = $this->GetStringWidth( $naslov ); $this->Cell( $length, 10, $naslov); } // Label and number of invoice/estimate function fact_dev( $libelle, $num ) { $r1 = $this->w - 80; $r2 = $r1 + 68; $y1 = 6; $y2 = $y1 + 2; $mid = ($r1 + $r2 ) / 2; $texte = $libelle . " U " . 'Din' . " N° : " . $num; $szfont = 12; $loop = 0; while ( $loop == 0 ) { $this->SetFont( "Helvetica", "B", $szfont ); $this->SetTextColor(255,255,255); $sz = $this->GetStringWidth( $texte ); if ( ($r1+$sz) > $r2 ) $szfont --; else $loop ++; } $this->SetLineWidth(0.1); $this->SetFillColor(192); $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 2.5, 'DF'); $this->SetXY( $r1+1, $y1+2); $this->Cell($r2-$r1 -1,5, $texte, 0, 0, "C" ); } // Estimate function addDevis( $numdev ) { $string = sprintf("DEV%04d",$numdev); $this->fact_dev( "Devis", $string ); } // Invoice function addFacture( $numfact ) { $string = sprintf("FA%04d",$numfact); $this->fact_dev( "Facture", $string ); } function addDate( $date ) { $r1 = $this->w - 61; $r2 = $r1 + 30; $y1 = 17; $y2 = $y1 ; $mid = $y1 + ($y2 / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 ); $this->SetFont( "Helvetica", "B", 10); $this->Cell(10,5, "DATUM", 0, 0, "C"); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+9 ); $this->SetFont( "Helvetica", "", 10); $this->Cell(10,5,$date, 0,0, "C"); } function addClient( $ref ) { $r1 = $this->w - 31; $r2 = $r1 + 19; $y1 = 17; $y2 = $y1; $mid = $y1 + ($y2 / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 ); $this->SetFont( "arial", "", 10); $this->Cell(10,5, "KLIJENT", 0, 0, "C"); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 ); $this->SetFont( "arial", "", 10); $this->Cell(10,5,$ref, 0,0, "C"); } function addPageNumber( $page ) { $r1 = $this->w - 80; $r2 = $r1 + 19; $y1 = 17; $y2 = $y1; $mid = $y1 + ($y2 / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 ); $this->SetFont( "Helvetica", "B", 10); $this->Cell(10,5, "STRANICA", 0, 0, "C"); $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 ); $this->SetFont( "Helvetica", "", 10); $this->Cell(10,5,$page, 0,0, "C"); } // Client address function addClientAdresse( $adresse ) { $r1 = $this->w - 80; $r2 = $r1 + 68; $y1 = 40; $this->SetXY( $r1, $y1); $this->MultiCell( 60, 4, $adresse); } // Mode of payment function addReglement( $mode ) { $r1 = 10; $r2 = $r1 + 60; $y1 = 80; $y2 = $y1+10; $mid = $y1 + (($y2-$y1) / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1+1 ); $this->SetFont( "Helvetica", "B", 10); $this->Cell(10,4, "NACIN PLACANJA", 0, 0, "C"); $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1 + 5 ); $this->SetFont( "Helvetica", "", 10); $this->Cell(10,5,$mode, 0,0, "C"); } // Expiry date function addEcheance( $date ) { $r1 = 80; $r2 = $r1 + 40; $y1 = 80; $y2 = $y1+10; $mid = $y1 + (($y2-$y1) / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + ($r2 - $r1)/2 - 5 , $y1+1 ); $this->SetFont( "Helvetica", "B", 10); $this->Cell(10,4, "DATUM VALUTE", 0, 0, "C"); $this->SetXY( $r1 + ($r2-$r1)/2 - 5 , $y1 + 5 ); $this->SetFont( "Helvetica", "", 10); $this->Cell(10,5,$date, 0,0, "C"); } // VAT number function addNumPDV($PDV) { $this->SetFont( "Helvetica", "B", 10); $r1 = $this->w - 80; $r2 = $r1 + 70; $y1 = 80; $y2 = $y1+10; $mid = $y1 + (($y2-$y1) / 2); $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); $this->Line( $r1, $mid, $r2, $mid); $this->SetXY( $r1 + 16 , $y1+1 ); $this->Cell(40, 4, "PIB broj", '', '', "C"); $this->SetFont( "Helvetica", "", 10); $this->SetXY( $r1 + 16 , $y1+5 ); $this->Cell(40, 5, $PDV, '', '', "C"); } function addReference($ref) { $this->SetFont( "Helvetica", "", 10); $length = $this->GetStringWidth( "Referenca : " . $ref ); $r1 = 10; $r2 = $r1 + $length; $y1 = 92; $y2 = $y1+5; $this->SetXY( $r1 , $y1 ); $this->Cell($length,4, "Referenca : " . $ref); } function addCols( $tab ,$Naslovi) { global $colonnes; $this->SetFont('arial','',8); $r1 = 10; $r2 = $this->w - ($r1 * 2) ; $y1 = 100; $y2 = $this->h - 50 - $y1; $this->SetXY( $r1, $y1 ); $this->Rect( $r1, $y1, $r2, $y2, "D"); $this->Line( $r1, $y1+6, $r1+$r2, $y1+6); $colX = $r1; $colonnes = $tab; while ( list( $lib, $pos ) = each ($tab) ) { $this->SetXY( $colX, $y1+2 ); $this->Cell( $pos, 1,$Naslovi["$lib"], 0, 0, "C"); $colX += $pos; $this->Line( $colX, $y1, $colX, $y1+$y2); } } function addLineFormat( $tab ) { global $format, $colonnes; while ( list( $lib, $pos ) = each ($colonnes) ) { if ( isset( $tab["$lib"] ) ) $format[ $lib ] = $tab["$lib"]; } } function lineVert( $tab ) { global $colonnes; reset( $colonnes ); $maxSize=0; while ( list( $lib, $pos ) = each ($colonnes) ) { $texte = $tab[ $lib ]; $longCell = $pos -2; $size = $this->sizeOfText( $texte, $longCell ); if ($size > $maxSize) $maxSize = $size; } return $maxSize; } // add a line to the invoice/estimate /* $ligne = array( "REFERENCE" => $prod["ref"], "DESIGNATION" => $libelle, "QUANTITE" => sprintf( "%.2f", $prod["qte"]) , "P.U. HT" => sprintf( "%.2f", $prod["px_unit"]), "VREDNOST" => sprintf ( "%.2f", $prod["qte"] * $prod["px_unit"]) , "PDV" => $prod["PDV"] ); */ function addLine( $ligne, $tab ) { global $colonnes, $format; $this->SetFont('arial','',7); $ordonnee = 10; $maxSize = $ligne; reset( $colonnes ); while ( list( $lib, $pos ) = each ($colonnes) ) { $longCell = $pos -2; $texte = $tab[ $lib ]; $length = $this->GetStringWidth( $texte ); $tailleTexte = $this->sizeOfText( $texte, $length ); $formText = $format[ $lib ]; $this->SetXY( $ordonnee, $ligne-1); $this->MultiCell( $longCell, 4 , $texte, 0, $formText); if ( $maxSize < ($this->GetY() ) ) $maxSize = $this->GetY() ; $ordonnee += $pos; } return ( $maxSize - $ligne ); } function addRemarque($remarque) { $this->SetFont( "Helvetica", "", 10); $length = $this->GetStringWidth( "Napomena : " . $remarque ); $r1 = 10; $r2 = $r1 + $length; $y1 = $this->h - 45.5; $y2 = $y1+5; $this->SetXY( $r1 , $y1 ); $this->Cell($length,4, "Napomena : " . $remarque); } function addCadrePDVs() { $this->SetFont( "Arial", "B", 8); $r1 = 70; $r2 = $r1 + 130; $y1 = $this->h - 40; $y2 = $y1+10; $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); $this->Line( $r1, $y1+4, $r2, $y1+4); $this->Line( $r1+5, $y1+4, $r1+5, $y2); // avant BASES HT $this->Line( $r1+32, $y1, $r1+32, $y2); // avant REMISE $this->Line( $r1+50, $y1, $r1+50, $y2); // avant MT PDV $this->Line( $r1+75, $y1, $r1+75, $y2); // avant % PDV $this->Line( $r1+95, $y1, $r1+95, $y2); // avant PORT $this->SetXY( $r1+7, $y1); $this->Cell(5,4, "Vrednost robe"); $this->SetX( $r1+32 ); $this->Cell(10,4, "Iznos rabata"); $this->SetX( $r1+50 ); $this->Cell(10,4, "Poreska snovica"); $this->SetX( $r1+75 ); $this->Cell(10,4, "Iznos P.D.V."); $this->SetX( $r1+100 ); $this->Cell(10,4, "Iznos za uplatu"); $this->SetFont( "Arial", "B", 6); } function addCadreEurosFrancs() { $r1 = $this->w - 70; $r2 = $r1 + 60; $y1 = $this->h - 40; $y2 = $y1+20; $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D'); $this->Line( $r1+20, $y1, $r1+20, $y2); // avant EUROS $this->Line( $r1+20, $y1+4, $r2, $y1+4); // Sous Euros & Francs $this->Line( $r1+38, $y1, $r1+38, $y2); // Entre Euros & Francs $this->SetFont( "Arial", "B", 8); $this->SetXY( $r1+22, $y1 ); $this->Cell(15,4, "EURO", 0, 0, "C"); $this->SetFont( "Arial", "", 8); $this->SetXY( $r1+42, $y1 ); $this->Cell(15,4, "DINARI", 0, 0, "C"); $this->SetFont( "Arial", "B", 6); $this->SetXY( $r1, $y1+5 ); $this->Cell(20,4, "Total", 0, 0, "C"); $this->SetXY( $r1, $y1+10 ); $this->Cell(20,4, "Avans", 0, 0, "C"); $this->SetXY( $r1, $y1+15 ); $this->Cell(20,4, "Neto", 0, 0, "C"); } function addPDVs($napomena,$suma,$sumaRabata,$Pdv) { $this->SetFont('arial','',7); $y = 261; $r1=60; //vrednost robe $this->SetXY($r1+17, $y); $this->Cell( 25,4, number_format($suma,2,',','.'),'','','R'); //ukupan iznos svih rabata $this->SetXY($r1+40, $y); $this->Cell( 20,4, number_format($sumaRabata,2,',','.'),'','','R'); //osnovica a obracun poreza $this->SetXY($r1+60, $y); $this->Cell( 25,4, number_format($suma-$sumaRabata,2,',','.'),'','','R'); //iznos poreza $this->SetXY($r1+85, $y); $this->Cell( 20,4, number_format(($suma-$sumaRabata)*0.18,2 ,',','.'),'','','R'); //iznos za placanje $this->SetXY($r1+110, $y); $this->Cell( 30,4, number_format(($suma-$sumaRabata)*1.18,2 ,',','.').' Din','','','R'); } // add a watermark (temporary estimate, DUPLICATA...) // call this method first function temporaire( $texte ) { $this->SetFont('arial','',50); $this->SetTextColor(203,203,203); $this->Rotate(45,55,190); $this->Text(55,190,$texte); $this->Rotate(0); $this->SetTextColor(0,0,0); } } $idk=$this->KParametri["Get"]["idk"]; $this->DklasaDetail->dodeliParametre($this->KParametri); $this->DklasaDetail->dodeliStranicenje=0; $Detalji=$this->DklasaDetail->VratiDetalje($idk); $brojOtpremnice=1;//$Zaglavlje["Podaci"][0]["broj"]; $brojKupca=11;//$Zaglavlje["Podaci"][0]["idKupac"]; $datum='2015-09-30';//$Zaglavlje["Podaci"][0]["datumKreiranja"]; $pdf = new INVOICE(); $pdf->Open(); $pdf->AddFont('arial','','arial.php'); $pdf->AddPage(); $pdf->addSociete( "Tutorić doo", "Matije Gupca 8\n" . "24000 SUBOTICA\n". "Tel:00 381 24 556 550\n"."Fax:00 381 63 518 269"); $pdf->dodajNaslovDokumenta("Račun - faktura"); $pdf->fact_dev( " ", "$brojOtpremnice" ); $pdf->temporaire( "Tutorić doo Subotica" ); $pdf->addDate( "$datum"); $pdf->addClient("$brojKupca"); $pdf->addPageNumber("1"); $pdf->DodajSpecifikacijuFakture("Subotica","09.08.2006","12.08.2006"); $pdf->addClientAdresse("Kulska banaka a.d.\nBulevar oslobođenja 80\n21000 Novi Sad\nFilijala Sombor\nVenac Stepe Stepanovića 30\nKontakt:Božidar Hinić"); //$pdf->addReglement("Virman"); //$pdf->addEcheance("21.06.2006"); //$pdf->addNumPDV("FR888777666"); $pdf->addReference("Otpremnica br:OT123"); $Naslovi=array( "Rb" => "Rb", "Sifra"=>"Šifra", "Opis" => "Opis", "Jdm"=>"Jdm", "Kolicina" =>"Količina", "Cena" =>"Cena", "Rabat"=>"Rabat %", "Osnovica"=>"Osnovica", "PDV"=>"PDV %", "UkupnaNaknada" => "Vrednost+PDV" ); $cols=array( "Rb" => 9, "Sifra"=>14, "Opis" => 51, "Jdm"=>12, "Kolicina" => 12, "Cena" => 22, "Rabat"=>15, "Osnovica"=>22, "PDV"=>11, "UkupnaNaknada" => 22 ); $pdf->addCols( $cols,$Naslovi); $cols=array( "Rb" => "C", "Sifra"=>"R", "Opis" => "L", "Jdm"=>"C", "Kolicina" => "R", "Cena" => "R", "Rabat"=>"C", "Osnovica"=>"R", "PDV"=>"l", "UkupnaNaknada" => "R"); $pdf->addLineFormat( $cols); $pdf->addLineFormat($cols); $y = 109; /*for ($i=0;$i "$redniBroj", "Sifra"=>"$sifra", "Opis" => "$naziv", "Jdm"=>"Kom", "Kolicina" => "$kolicina", "Cena" => "$cena", "Rabat"=>"$procenatRabata", "Osnovica"=>"$osnovica", "PDV"=>"l8%", "UkupnaNaknada" => "$ukupnaNaknada" ); $size = $pdf->addLine( $y, $line ); $y += $size + 2; }*/ $pdf->addCadrePDVs(); $suma=11;//$Detalji["suma"]; $sumaRabata=11;//$Detalji["sumaRabata"]; $params = array(); $pdf->addPDVs( $params,$suma,$sumaRabata,$Pdv); // $pdf->addCadreEurosFrancs(); $pdf->Output(); ?>