invoice.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. <?php
  2. require('fpdf.php');
  3. define('EURO', chr(128) );
  4. define('EURO_VAL', 6.55957 );
  5. // Xavier Nicolay 2004
  6. // Version 1.02
  7. //
  8. // Reste à faire :
  9. // + Multipage (gestion automatique sur plusieurs pages)
  10. // + Ajout de logo
  11. //
  12. //////////////////////////////////////
  13. // fonctions à utiliser (publiques) //
  14. //////////////////////////////////////
  15. // function sizeOfText( $texte, $larg )
  16. // function addSociete( $nom, $adresse )
  17. // function fact_dev( $libelle, $num )
  18. // function addDevis( $numdev )
  19. // function addFacture( $numfact )
  20. // function addDate( $date )
  21. // function addClient( $ref )
  22. // function addPageNumber( $page )
  23. // function addClientAdresse( $adresse )
  24. // function addReglement( $mode )
  25. // function addEcheance( $date )
  26. // function addNumTVA($tva)
  27. // function addReference($ref)
  28. // function addCols( $tab )
  29. // function addLineFormat( $tab )
  30. // function lineVert( $tab )
  31. // function addLine( $ligne, $tab )
  32. // function addRemarque($remarque)
  33. // function addCadreTVAs()
  34. // function addCadreEurosFrancs()
  35. // function addTVAs( $params, $tab_tva, $invoice )
  36. // function temporaire( $texte )
  37. class PDF_Invoice extends FPDF
  38. {
  39. // variables privées
  40. var $colonnes;
  41. var $format;
  42. var $angle=0;
  43. // fonctions privées
  44. function RoundedRect($x, $y, $w, $h, $r, $style = '')
  45. {
  46. $k = $this->k;
  47. $hp = $this->h;
  48. if($style=='F')
  49. $op='f';
  50. elseif($style=='FD' || $style=='DF')
  51. $op='B';
  52. else
  53. $op='S';
  54. $MyArc = 4/3 * (sqrt(2) - 1);
  55. $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k ));
  56. $xc = $x+$w-$r ;
  57. $yc = $y+$r;
  58. $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k ));
  59. $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
  60. $xc = $x+$w-$r ;
  61. $yc = $y+$h-$r;
  62. $this->_out(sprintf('%.2F %.2F l',($x+$w)*$k,($hp-$yc)*$k));
  63. $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
  64. $xc = $x+$r ;
  65. $yc = $y+$h-$r;
  66. $this->_out(sprintf('%.2F %.2F l',$xc*$k,($hp-($y+$h))*$k));
  67. $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
  68. $xc = $x+$r ;
  69. $yc = $y+$r;
  70. $this->_out(sprintf('%.2F %.2F l',($x)*$k,($hp-$yc)*$k ));
  71. $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
  72. $this->_out($op);
  73. }
  74. function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
  75. {
  76. $h = $this->h;
  77. $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k,
  78. $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
  79. }
  80. function Rotate($angle, $x=-1, $y=-1)
  81. {
  82. if($x==-1)
  83. $x=$this->x;
  84. if($y==-1)
  85. $y=$this->y;
  86. if($this->angle!=0)
  87. $this->_out('Q');
  88. $this->angle=$angle;
  89. if($angle!=0)
  90. {
  91. $angle*=M_PI/180;
  92. $c=cos($angle);
  93. $s=sin($angle);
  94. $cx=$x*$this->k;
  95. $cy=($this->h-$y)*$this->k;
  96. $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));
  97. }
  98. }
  99. function _endpage()
  100. {
  101. if($this->angle!=0)
  102. {
  103. $this->angle=0;
  104. $this->_out('Q');
  105. }
  106. parent::_endpage();
  107. }
  108. // fonctions publiques
  109. function sizeOfText( $texte, $largeur )
  110. {
  111. if (0 == $largeur) {
  112. return 1;
  113. }
  114. $index = 0;
  115. $nb_lines = 0;
  116. $loop = TRUE;
  117. while ( $loop )
  118. {
  119. $pos = strpos($texte, "\n");
  120. if (!$pos)
  121. {
  122. $loop = FALSE;
  123. $ligne = $texte;
  124. }
  125. else
  126. {
  127. $ligne = substr( $texte, $index, $pos);
  128. $texte = substr( $texte, $pos+1 );
  129. }
  130. $length = floor( $this->GetStringWidth( $ligne ) );
  131. $res = 1 + floor( $length / $largeur) ;
  132. $nb_lines += $res;
  133. }
  134. return $nb_lines;
  135. }
  136. // Cette fonction affiche en haut, a gauche,
  137. // le nom de la societe dans la police Arial-12-Bold
  138. // les coordonnees de la societe dans la police Arial-10
  139. function addSociete( $nom, $adresse, $period = '', $node = '', $orders = '' )
  140. {
  141. $this->Image(sfConfig::get('sf_web_dir') . '/images/logo.gif', 7, 5, 30, 37, 'gif', sfConfig::get('app_katao_frontend_url'));
  142. $x1 = 10 + 33;
  143. $y1 = 8;
  144. //Positionnement en bas
  145. $this->SetXY( $x1, $y1 );
  146. $this->SetFont('Arial','B',12);
  147. $length = $this->GetStringWidth( $nom );
  148. $this->Cell( $length, 2, $nom);
  149. $this->SetXY( $x1, $y1 + 4 );
  150. $this->SetFont('Arial','',10);
  151. $length = $this->GetStringWidth( $adresse );
  152. //Coordonnées de la société
  153. $lignes = $this->sizeOfText( $adresse, $length) ;
  154. $this->MultiCell($length, 4, $adresse);
  155. $data = "";
  156. if ("" != $period) {
  157. $data .= "Période : $period";
  158. }
  159. if ("" != $node) {
  160. if ("" != $data) {
  161. $data .= "\n";
  162. }
  163. $data .= "Noeud : $node";
  164. }
  165. if ("" != $orders) {
  166. if ("" != $data) {
  167. $data .= "\n";
  168. }
  169. $data .= "Commande(s) : $orders";
  170. }
  171. if ("" != $data) {
  172. $length = $this->GetStringWidth( $data );
  173. $this->SetXY( $x1-37, $y1+40 );
  174. $this->MultiCell($length, 4, $data);
  175. }
  176. }
  177. // Affiche en haut, a droite le libelle
  178. // (FACTURE, DEVIS, Bon de commande, etc...)
  179. // et son numero
  180. // La taille de la fonte est auto-adaptee au cadre
  181. function fact_dev( $libelle, $num )
  182. {
  183. $r1 = $this->w - 80;
  184. $r2 = $r1 + 68;
  185. $y1 = 6;
  186. $y2 = $y1 + 2;
  187. $mid = ($r1 + $r2 ) / 2;
  188. $texte = $libelle . " en " . EURO . " N° : " . $num;
  189. $szfont = 12;
  190. $loop = 0;
  191. while ( $loop == 0 )
  192. {
  193. $this->SetFont( "Arial", "B", $szfont );
  194. $sz = $this->GetStringWidth( $texte );
  195. if ( ($r1+$sz) > $r2 )
  196. $szfont --;
  197. else
  198. $loop ++;
  199. }
  200. $this->SetLineWidth(0.1);
  201. $this->SetFillColor(192);
  202. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 2.5, 'DF');
  203. $this->SetXY( $r1+1, $y1+2);
  204. $this->Cell($r2-$r1 -1,5, $texte, 0, 0, "C" );
  205. }
  206. // Genere automatiquement un numero de devis
  207. function addDevis( $numdev )
  208. {
  209. $string = sprintf("DEV%04d",$numdev);
  210. $this->fact_dev( "Devis", $string );
  211. }
  212. // Genere automatiquement un numero de facture
  213. function addFacture( $numfact )
  214. {
  215. $string = sprintf("FA%04d",$numfact);
  216. $this->fact_dev( "Facture", $string );
  217. }
  218. // Affiche un cadre avec la date de la facture / devis
  219. // (en haut, a droite)
  220. function addDate( $date )
  221. {
  222. $r1 = $this->w - 61;
  223. $r2 = $r1 + 30;
  224. $y1 = 17;
  225. $y2 = $y1 ;
  226. $mid = $y1 + ($y2 / 2);
  227. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D');
  228. $this->Line( $r1, $mid, $r2, $mid);
  229. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 );
  230. $this->SetFont( "Arial", "B", 10);
  231. $this->Cell(10,5, "DATE", 0, 0, "C");
  232. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+9 );
  233. $this->SetFont( "Arial", "", 10);
  234. $this->Cell(10,5,$date, 0,0, "C");
  235. }
  236. // Affiche un cadre avec les references du client
  237. // (en haut, a droite)
  238. function addClient( $ref )
  239. {
  240. $r1 = $this->w - 31;
  241. $r2 = $r1 + 19;
  242. $y1 = 17;
  243. $y2 = $y1;
  244. $mid = $y1 + ($y2 / 2);
  245. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D');
  246. $this->Line( $r1, $mid, $r2, $mid);
  247. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 );
  248. $this->SetFont( "Arial", "B", 10);
  249. $this->Cell(10,5, "REF", 0, 0, "C");
  250. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 );
  251. $this->SetFont( "Arial", "", 10);
  252. $this->Cell(10,5,$ref, 0,0, "C");
  253. }
  254. // Affiche un cadre avec un numero de page
  255. // (en haut, a droite)
  256. function addPageNumber( $page )
  257. {
  258. $r1 = $this->w - 80;
  259. $r2 = $r1 + 19;
  260. $y1 = 17;
  261. $y2 = $y1;
  262. $mid = $y1 + ($y2 / 2);
  263. $this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 3.5, 'D');
  264. $this->Line( $r1, $mid, $r2, $mid);
  265. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1+3 );
  266. $this->SetFont( "Arial", "B", 10);
  267. $this->Cell(10,5, "PAGE", 0, 0, "C");
  268. $this->SetXY( $r1 + ($r2-$r1)/2 - 5, $y1 + 9 );
  269. $this->SetFont( "Arial", "", 10);
  270. $this->Cell(10,5,$page, 0,0, "C");
  271. }
  272. // Affiche l'adresse du client
  273. // (en haut, a droite)
  274. function addClientAdresse( $adresse )
  275. {
  276. $r1 = $this->w - 80;
  277. $r2 = $r1 + 68;
  278. $y1 = 40;
  279. $this->SetXY( $r1, $y1);
  280. $this->MultiCell( 60, 4, $adresse);
  281. }
  282. // Affiche un cadre avec le règlement (chèque, etc...)
  283. // (en haut, a gauche)
  284. function addReglement( $mode )
  285. {
  286. $r1 = 10;
  287. $r2 = $r1 + 60;
  288. $y1 = 80;
  289. $y2 = $y1+10;
  290. $mid = $y1 + (($y2-$y1) / 2);
  291. $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
  292. $this->Line( $r1, $mid, $r2, $mid);
  293. $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1+1 );
  294. $this->SetFont( "Arial", "B", 10);
  295. $this->Cell(10,4, "MODE DE REGLEMENT", 0, 0, "C");
  296. $this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1 + 5 );
  297. $this->SetFont( "Arial", "", 10);
  298. $this->Cell(10,5,$mode, 0,0, "C");
  299. }
  300. // Affiche un cadre avec la date d'echeance
  301. // (en haut, au centre)
  302. function addEcheance( $date )
  303. {
  304. $r1 = 80;
  305. $r2 = $r1 + 40;
  306. $y1 = 80;
  307. $y2 = $y1+10;
  308. $mid = $y1 + (($y2-$y1) / 2);
  309. $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
  310. $this->Line( $r1, $mid, $r2, $mid);
  311. $this->SetXY( $r1 + ($r2 - $r1)/2 - 5 , $y1+1 );
  312. $this->SetFont( "Arial", "B", 10);
  313. $this->Cell(10,4, "DATE D'ECHEANCE", 0, 0, "C");
  314. $this->SetXY( $r1 + ($r2-$r1)/2 - 5 , $y1 + 5 );
  315. $this->SetFont( "Arial", "", 10);
  316. $this->Cell(10,5,$date, 0,0, "C");
  317. }
  318. // Affiche un cadre avec le numero de la TVA
  319. // (en haut, au droite)
  320. function addNumTVA($tva)
  321. {
  322. $this->SetFont( "Arial", "B", 10);
  323. $r1 = $this->w - 80;
  324. $r2 = $r1 + 70;
  325. $y1 = 80;
  326. $y2 = $y1+10;
  327. $mid = $y1 + (($y2-$y1) / 2);
  328. $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
  329. $this->Line( $r1, $mid, $r2, $mid);
  330. $this->SetXY( $r1 + 16 , $y1+1 );
  331. $this->Cell(40, 4, "TVA Intracommunautaire", '', '', "C");
  332. $this->SetFont( "Arial", "", 10);
  333. $this->SetXY( $r1 + 16 , $y1+5 );
  334. $this->Cell(40, 5, $tva, '', '', "C");
  335. }
  336. // Affiche une ligne avec des reference
  337. // (en haut, a gauche)
  338. function addReference($ref)
  339. {
  340. $this->SetFont( "Arial", "", 10);
  341. $length = $this->GetStringWidth( $ref );
  342. $r1 = 10;
  343. $r2 = $r1 + $length;
  344. $y1 = 92;
  345. $y2 = $y1+5;
  346. $this->SetXY( $r1 , $y1 );
  347. $this->Cell($length,4, $ref);
  348. }
  349. // trace le cadre des colonnes du devis/facture
  350. function addCols( $tab )
  351. {
  352. global $colonnes;
  353. $r1 = 10;
  354. $r2 = $this->w - ($r1 * 2) ;
  355. $y1 = 100;
  356. $y2 = $this->h - 50 - $y1;
  357. $this->SetXY( $r1, $y1 );
  358. $this->Rect( $r1, $y1, $r2, $y2, "D");
  359. $this->Line( $r1, $y1+6, $r1+$r2, $y1+6);
  360. $colX = $r1;
  361. $colonnes = $tab;
  362. while ( list( $lib, $pos ) = each ($tab) )
  363. {
  364. $this->SetXY( $colX, $y1+2 );
  365. $this->Cell( $pos, 1, $lib, 0, 0, "C");
  366. $colX += $pos;
  367. $this->Line( $colX, $y1, $colX, $y1+$y2);
  368. }
  369. }
  370. // mémorise le format (gauche, centre, droite) d'une colonne
  371. function addLineFormat( $tab )
  372. {
  373. global $format, $colonnes;
  374. while ( list( $lib, $pos ) = each ($colonnes) )
  375. {
  376. if ( isset( $tab["$lib"] ) )
  377. $format[ $lib ] = $tab["$lib"];
  378. }
  379. }
  380. function lineVert( $tab )
  381. {
  382. global $colonnes;
  383. reset( $colonnes );
  384. $maxSize=0;
  385. while ( list( $lib, $pos ) = each ($colonnes) )
  386. {
  387. $texte = $tab[ $lib ];
  388. $longCell = $pos -2;
  389. $size = $this->sizeOfText( $texte, $longCell );
  390. if ($size > $maxSize)
  391. $maxSize = $size;
  392. }
  393. return $maxSize;
  394. }
  395. // Affiche chaque "ligne" d'un devis / facture
  396. /* $ligne = array( "REFERENCE" => $prod["ref"],
  397. "DESIGNATION" => $libelle,
  398. "QUANTITE" => sprintf( "%.2F", $prod["qte"]) ,
  399. "P.U. HT" => sprintf( "%.2F", $prod["px_unit"]),
  400. "MONTANT H.T." => sprintf ( "%.2F", $prod["qte"] * $prod["px_unit"]) ,
  401. "TVA" => $prod["tva"] );
  402. */
  403. function addLine( $ligne, $tab )
  404. {
  405. global $colonnes, $format;
  406. $ordonnee = 10;
  407. $maxSize = $ligne;
  408. reset( $colonnes );
  409. while ( list( $lib, $pos ) = each ($colonnes) )
  410. {
  411. $longCell = $pos -2;
  412. $texte = $tab[ $lib ];
  413. $length = $this->GetStringWidth( $texte );
  414. $tailleTexte = $this->sizeOfText( $texte, $length );
  415. $formText = $format[ $lib ];
  416. $this->SetXY( $ordonnee, $ligne-1);
  417. $this->MultiCell( $longCell, 4 , $texte, 0, $formText);
  418. if ( $maxSize < ($this->GetY() ) )
  419. $maxSize = $this->GetY() ;
  420. $ordonnee += $pos;
  421. }
  422. return ( $maxSize - $ligne );
  423. }
  424. // Ajoute une remarque (en bas, a gauche)
  425. function addRemarque($remarque)
  426. {
  427. $this->SetFont( "Arial", "", 10);
  428. $length = $this->GetStringWidth( "Remarque : " . $remarque );
  429. $r1 = 10;
  430. $r2 = $r1 + $length;
  431. $y1 = $this->h - 45.5;
  432. $y2 = $y1+5;
  433. $this->SetXY( $r1 , $y1 );
  434. $this->Cell($length,4, "Remarque : " . $remarque);
  435. }
  436. // trace le cadre des TVA
  437. function addCadreTVAs()
  438. {
  439. $this->SetFont( "Arial", "B", 8);
  440. $r1 = 10;
  441. $r2 = $r1 + 120;
  442. $y1 = $this->h - 40;
  443. $y2 = $y1+20;
  444. $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
  445. $this->Line( $r1, $y1+4, $r2, $y1+4);
  446. $this->Line( $r1+5, $y1+4, $r1+5, $y2); // avant BASES HT
  447. $this->Line( $r1+27, $y1, $r1+27, $y2); // avant REMISE
  448. $this->Line( $r1+43, $y1, $r1+43, $y2); // avant MT TVA
  449. $this->Line( $r1+63, $y1, $r1+63, $y2); // avant % TVA
  450. $this->Line( $r1+75, $y1, $r1+75, $y2); // avant PORT
  451. $this->Line( $r1+91, $y1, $r1+91, $y2); // avant TOTAUX
  452. $this->SetXY( $r1+9, $y1);
  453. $this->Cell(10,4, "BASES HT");
  454. $this->SetX( $r1+29 );
  455. $this->Cell(10,4, "REMISE");
  456. $this->SetX( $r1+48 );
  457. $this->Cell(10,4, "MT TVA");
  458. $this->SetX( $r1+63 );
  459. $this->Cell(10,4, "% TVA");
  460. $this->SetX( $r1+78 );
  461. $this->Cell(10,4, "PORT");
  462. $this->SetX( $r1+100 );
  463. $this->Cell(10,4, "TOTAUX");
  464. $this->SetFont( "Arial", "B", 6);
  465. $this->SetXY( $r1+93, $y2 - 8 );
  466. $this->Cell(6,0, "H.T. :");
  467. $this->SetXY( $r1+93, $y2 - 3 );
  468. $this->Cell(6,0, "T.V.A. :");
  469. }
  470. // trace le cadre des totaux
  471. function addCadreEurosFrancs()
  472. {
  473. $r1 = $this->w - 50;
  474. $r2 = $r1 + 40;
  475. $y1 = $this->h - 40;
  476. $y2 = $y1+20;
  477. $this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
  478. $this->Line( $r1+20, $y1, $r1+20, $y2); // avant EUROS
  479. $this->Line( $r1+20, $y1+4, $r2, $y1+4); // Sous Euros
  480. $this->SetFont( "Arial", "B", 8);
  481. $this->SetXY( $r1+22, $y1 );
  482. $this->Cell(15,4, "EUROS", 0, 0, "R");
  483. $this->SetFont( "Arial", "B", 6);
  484. $this->SetXY( $r1, $y1+5 );
  485. $this->Cell(20,4, "TOTAL TTC", 0, 0, "C");
  486. $this->SetXY( $r1, $y1+10 );
  487. $this->Cell(20,4, "ACOMPTE", 0, 0, "C");
  488. $this->SetXY( $r1, $y1+15 );
  489. $this->Cell(20,4, "NET A PAYER", 0, 0, "C");
  490. }
  491. // remplit les cadres TVA / Totaux et la remarque
  492. // params = array( "RemiseGlobale" => [0|1],
  493. // "remise_tva" => [1|2...], // {la remise s'applique sur ce code TVA}
  494. // "remise" => value, // {montant de la remise}
  495. // "remise_percent" => percent, // {pourcentage de remise sur ce montant de TVA}
  496. // "FraisPort" => [0|1],
  497. // "portTTC" => value, // montant des frais de ports TTC
  498. // // par defaut la TVA = 20 %
  499. // "portHT" => value, // montant des frais de ports HT
  500. // "portTVA" => tva_value, // valeur de la TVA a appliquer sur le montant HT
  501. // "AccompteExige" => [0|1],
  502. // "accompte" => value // montant de l'acompte (TTC)
  503. // "accompte_percent" => percent // pourcentage d'acompte (TTC)
  504. // "Remarque" => "texte" // texte
  505. // tab_tva = array( "1" => 2020202020202020202020202020202020202020,
  506. // "2" => 5.5, ... );
  507. // invoice = array( "px_unit" => value,
  508. // "qte" => qte,
  509. // "tva" => code_tva );
  510. function addTVAs( $params, $tab_tva, $invoice, $katao_supplier_invoice = null )
  511. {
  512. $this->SetFont('Arial','',8);
  513. reset ($invoice);
  514. $px = array();
  515. while ( list( $k, $prod) = each( $invoice ) )
  516. {
  517. $tva = $prod["tva"];
  518. @ $px[$tva] += $prod["qte"] * $prod["px_unit"];
  519. }
  520. $prix = array();
  521. $totalHT = 0;
  522. $totalTTC = 0;
  523. $totalTVA = 0;
  524. $y = 261;
  525. reset ($px);
  526. natsort( $px );
  527. while ( list($code_tva, $articleHT) = each( $px ) )
  528. {
  529. $tva = $tab_tva[$code_tva];
  530. $this->SetXY(17, $y);
  531. $this->Cell( 19,4, Utils::formatCurrency($articleHT),'', '','R' );
  532. if ( $params["RemiseGlobale"]==1 )
  533. {
  534. if ( $params["remise_tva"] == $code_tva )
  535. {
  536. $this->SetXY( 37.5, $y );
  537. if ($params["remise"] > 0 )
  538. {
  539. if ( is_int( $params["remise"] ) )
  540. $l_remise = $param["remise"];
  541. else
  542. $l_remise = sprintf ("%0.2F", $params["remise"]);
  543. $this->Cell( 14.5,4, $l_remise, '', '', 'R' );
  544. $articleHT -= $params["remise"];
  545. }
  546. else if ( $params["remise_percent"] > 0 )
  547. {
  548. $rp = $params["remise_percent"];
  549. if ( $rp > 1 )
  550. $rp /= 100;
  551. $rabais = $articleHT * $rp;
  552. $articleHT -= $rabais;
  553. if ( is_int($rabais) )
  554. $l_remise = $rabais;
  555. else
  556. $l_remise = sprintf ("%0.2F", $rabais);
  557. $this->Cell( 14.5,4, $l_remise, '', '', 'R' );
  558. }
  559. else
  560. $this->Cell( 14.5,4, "ErrorRem", '', '', 'R' );
  561. }
  562. }
  563. $totalHT += $articleHT;
  564. $totalTTC += $articleHT * ( 1 + $tva/100 );
  565. $tmp_tva = $articleHT * $tva/100;
  566. /* Custom - Begin */
  567. if (!is_null($katao_supplier_invoice)) {
  568. $getTauxAmount = sprintf('getTaux%dAmount', $code_tva);
  569. $tmp_tva = $katao_supplier_invoice->$getTauxAmount();
  570. }
  571. /* Custom - End */
  572. $a_tva[ $code_tva ] = $tmp_tva;
  573. $totalTVA += $tmp_tva;
  574. $this->SetXY(11, $y);
  575. $this->Cell( 5,4, $code_tva);
  576. $this->SetXY(53, $y);
  577. $this->Cell( 19,4, Utils::formatCurrency($tmp_tva),'', '' ,'R');
  578. $this->SetXY(74, $y);
  579. $this->Cell( 10,4, Utils::formatCurrency($tva) ,'', '', 'R');
  580. $y+=4;
  581. }
  582. if ( $params["FraisPort"] == 1 )
  583. {
  584. if ( $params["portTTC"] > 0 )
  585. {
  586. $pTTC = sprintf("%0.2F", $params["portTTC"]);
  587. $pHT = sprintf("%0.2F", $pTTC / 1.2);
  588. $pTVA = sprintf("%0.2F", $pHT * 0.2);
  589. $this->SetFont('Arial','',6);
  590. $this->SetXY(85, 261 );
  591. $this->Cell( 6 ,4, "HT : ", '', '', '');
  592. $this->SetXY(92, 261 );
  593. $this->Cell( 9 ,4, $pHT, '', '', 'R');
  594. $this->SetXY(85, 265 );
  595. $this->Cell( 6 ,4, "TVA : ", '', '', '');
  596. $this->SetXY(92, 265 );
  597. $this->Cell( 9 ,4, $pTVA, '', '', 'R');
  598. $this->SetXY(85, 269 );
  599. $this->Cell( 6 ,4, "TTC : ", '', '', '');
  600. $this->SetXY(92, 269 );
  601. $this->Cell( 9 ,4, $pTTC, '', '', 'R');
  602. $this->SetFont('Arial','',8);
  603. $totalHT += $pHT;
  604. $totalTVA += $pTVA;
  605. $totalTTC += $pTTC;
  606. }
  607. else if ( $params["portHT"] > 0 )
  608. {
  609. $pHT = sprintf("%0.2F", $params["portHT"]);
  610. $pTVA = sprintf("%0.2F", $params["portTVA"] * $pHT / 100 );
  611. $pTTC = sprintf("%0.2F", $pHT + $pTVA);
  612. $this->SetFont('Arial','',6);
  613. $this->SetXY(85, 261 );
  614. $this->Cell( 6 ,4, "HT : ", '', '', '');
  615. $this->SetXY(92, 261 );
  616. $this->Cell( 9 ,4, $pHT, '', '', 'R');
  617. $this->SetXY(85, 265 );
  618. $this->Cell( 6 ,4, "TVA : ", '', '', '');
  619. $this->SetXY(92, 265 );
  620. $this->Cell( 9 ,4, $pTVA, '', '', 'R');
  621. $this->SetXY(85, 269 );
  622. $this->Cell( 6 ,4, "TTC : ", '', '', '');
  623. $this->SetXY(92, 269 );
  624. $this->Cell( 9 ,4, $pTTC, '', '', 'R');
  625. $this->SetFont('Arial','',8);
  626. $totalHT += $pHT;
  627. $totalTVA += $pTVA;
  628. $totalTTC += $pTTC;
  629. }
  630. }
  631. /* Custom - Begin */
  632. if (!is_null($katao_supplier_invoice)) {
  633. $totalHT = $katao_supplier_invoice->getTotalHt();
  634. $totalTVA = $katao_supplier_invoice->getTotalTva();
  635. }
  636. /* Custom - End */
  637. $this->SetXY(114,266.4);
  638. $this->Cell(15,4, Utils::formatCurrency($totalHT), '', '', 'R' );
  639. $this->SetXY(114,271.4);
  640. $this->Cell(15,4, Utils::formatCurrency($totalTVA), '', '', 'R' );
  641. $params["totalHT"] = $totalHT;
  642. $params["TVA"] = $totalTVA;
  643. $accompteTTC=0;
  644. if ( $params["AccompteExige"] == 1 )
  645. {
  646. if ( $params["accompte"] > 0 )
  647. {
  648. $accompteTTC=sprintf ("%.2F", $params["accompte"]);
  649. if ( strlen ($params["Remarque"]) == 0 )
  650. $this->addRemarque( "Acompte de $accompteTTC Euros exigé à la commande.");
  651. else
  652. $this->addRemarque( $params["Remarque"] );
  653. }
  654. else if ( $params["accompte_percent"] > 0 )
  655. {
  656. $percent = $params["accompte_percent"];
  657. if ( $percent > 1 )
  658. $percent /= 100;
  659. $accompteTTC=sprintf("%.2F", $totalTTC * $percent);
  660. $percent100 = $percent * 100;
  661. if ( strlen ($params["Remarque"]) == 0 )
  662. $this->addRemarque( "Acompte de $percent100 % (soit $accompteTTC Euros) exigé à la commande." );
  663. else
  664. $this->addRemarque( $params["Remarque"] );
  665. }
  666. else
  667. $this->addRemarque( "Drôle d'acompte !!! " . $params["Remarque"]);
  668. }
  669. else
  670. {
  671. if ( strlen ($params["Remarque"]) > 0 )
  672. $this->addRemarque( $params["Remarque"] );
  673. }
  674. /* Custom - Begin */
  675. if (!is_null($katao_supplier_invoice)) {
  676. $totalTTC = $totalHT+$totalTVA;
  677. }
  678. $totalTTC = round($totalTTC, 2);
  679. $accompteTTC = round($accompteTTC, 2);
  680. /* Custom - End */
  681. $re = $this->w - 29;
  682. $y1 = $this->h - 40;
  683. $this->SetFont( "Arial", "", 8);
  684. $this->SetXY( $re, $y1+5 );
  685. $this->Cell( 17,4, Utils::formatCurrency($totalTTC), '', '', 'R');
  686. $this->SetXY( $re, $y1+10 );
  687. $this->Cell( 17,4, Utils::formatCurrency($accompteTTC), '', '', 'R');
  688. $this->SetXY( $re, $y1+14.8 );
  689. $this->Cell( 17,4, Utils::formatCurrency($totalTTC - $accompteTTC), '', '', 'R');
  690. }
  691. // Permet de rajouter un commentaire (Devis temporaire, REGLE, DUPLICATA, ...)
  692. // en sous-impression
  693. // ATTENTION: APPELER CETTE FONCTION EN PREMIER
  694. function temporaire( $texte )
  695. {
  696. $this->SetFont('Arial','B',50);
  697. $this->SetTextColor(203,203,203);
  698. $this->Rotate(45,55,190);
  699. $this->Text(55,190,$texte);
  700. $this->Rotate(0);
  701. $this->SetTextColor(0,0,0);
  702. }
  703. /**
  704. * PDF_Invoice::addPageHeaderInvoice()
  705. *
  706. * @param int $page
  707. * @param KataoInvoice $katao_invoice
  708. * @param KataoMember $katao_member
  709. * @return
  710. */
  711. function addPageHeaderInvoice($page, $katao_invoice, $katao_member){
  712. $this->AddPage();
  713. $this->addSociete($katao_invoice->getKataoName(),
  714. $katao_invoice->getKataoAddress() . "\n" .
  715. "SIRET " . $katao_invoice->getKataoSiretNumber() . "\n" .
  716. "R.C.S. " . $katao_invoice->getKataoRcsNumber() . "\n" .
  717. "Capital : " . $katao_invoice->getKataoCapital() . " " . EURO, utf8_decode($katao_invoice->getKataoPeriod()->getName()), $katao_invoice->getKataoNode()->getCity());
  718. $this->fact_dev("Facture", $katao_invoice->getNumber());
  719. // $this->temporaire("Devis temporaire");
  720. $this->addDate($katao_invoice->getCreatedAt('d/m/Y'));
  721. $this->addClient($katao_member->getAccountingCode());
  722. $this->addPageNumber($page++);
  723. $this->addClientAdresse(utf8_decode(sprintf("%s %s\n%s%s\n%s%s", $katao_invoice->getMemberLastName(), $katao_invoice->getMemberFirstName(), $katao_invoice->getMemberAddress1(), $katao_invoice->getMemberAddress2()?sprintf("\n%s", $katao_invoice->getMemberAddress2()):'', $katao_invoice->getMemberZip()?sprintf("%s ", $katao_invoice->getMemberZip()):'', $katao_invoice->getMemberCity())));
  724. $this->addReglement("Payée");
  725. $this->addEcheance($katao_invoice->getCreatedAt('d/m/Y'));
  726. $this->addNumTVA(wpConfig::getTvaNumber());
  727. $this->addReference('Votre solde est désormais de ' . number_format($katao_member->getCurrentAmountEuro(), 2, ',', ' ') . ' ' . EURO . ' et ' . $katao_member->getCurrentAmountSolStr());
  728. $cols = array("REFERENCE" => 23,
  729. "DESIGNATION" => 78,
  730. "QUANTITE" => 22,
  731. "P.U. TTC" => 26,
  732. "MONTANT TTC" => 30,
  733. "TVA" => 11);
  734. $this->addCols($cols);
  735. $cols = array("REFERENCE" => "L",
  736. "DESIGNATION" => "L",
  737. "QUANTITE" => "C",
  738. "P.U. TTC" => "R",
  739. "MONTANT TTC" => "R",
  740. "TVA" => "C");
  741. $this->addLineFormat($cols);
  742. $this->addLineFormat($cols);
  743. return $page;
  744. }
  745. /**
  746. * PDF_Invoice::addPageHeaderOrder()
  747. *
  748. * @param int $page
  749. * @param KataoOrder $katao_order
  750. * @param KataoSupplier $katao_supplier
  751. * @return
  752. */
  753. function addPageHeaderOrder($page, $katao_order, $katao_supplier){
  754. $this->AddPage();
  755. $this->addSociete($katao_order->getKataoName(),
  756. $katao_order->getKataoAddress() . "\n" .
  757. "SIRET " . $katao_order->getKataoSiretNumber() . "\n" .
  758. "R.C.S. " . $katao_order->getKataoRcsNumber() . "\n" .
  759. "Capital : " . $katao_order->getKataoCapital() . " " . EURO, utf8_decode($katao_order->getKataoPeriod()->getName()), $katao_order->getKataoNode()->getCity());
  760. $this->fact_dev("Commande", $katao_order->getNumber());
  761. // $this->temporaire("Devis temporaire");
  762. $this->addDate($katao_order->getCreatedAt('d/m/Y'));
  763. $this->addClient($katao_supplier->getAccountingCode());
  764. $this->addPageNumber($page++);
  765. $this->addClientAdresse(utf8_decode(sprintf("%s\n%s%s\n%s%s", $katao_order->getSupplierName(), $katao_order->getSupplierAddress1(), $katao_order->getSupplierAddress2()?sprintf("\n%s", $katao_order->getSupplierAddress2()):'', $katao_order->getSupplierZip()?sprintf("%s ", $katao_order->getSupplierZip()):'', $katao_order->getSupplierCity())));
  766. //$this->addReglement("Payée");
  767. //$this->addEcheance($katao_order->getCreatedAt('d/m/Y'));
  768. $this->addNumTVA(wpConfig::getTvaNumber());
  769. if ('' != $katao_order->getDeliveryAddress()) {
  770. $this->addReference('Adresse de livraison : ' . str_replace("\n", ' - ', $katao_order->getDeliveryAddress()));
  771. }
  772. $cols = array("REFERENCE" => 23,
  773. "DESIGNATION" => 78,
  774. "QUANTITE" => 22,
  775. "P.U. TTC" => 26,
  776. "MONTANT TTC" => 30,
  777. "TVA" => 11);
  778. $this->addCols($cols);
  779. $cols = array("REFERENCE" => "L",
  780. "DESIGNATION" => "L",
  781. "QUANTITE" => "C",
  782. "P.U. TTC" => "R",
  783. "MONTANT TTC" => "R",
  784. "TVA" => "C");
  785. $this->addLineFormat($cols);
  786. $this->addLineFormat($cols);
  787. return $page;
  788. }
  789. /**
  790. * PDF_Invoice::addPageHeaderCart()
  791. *
  792. * @param int $page
  793. * @param KataoCart $katao_cart
  794. * @param KataoMember $katao_member
  795. * @param KataoUser $katao_user
  796. * @return
  797. */
  798. function addPageHeaderCart($page, $katao_cart, $katao_member, $katao_user){
  799. $this->AddPage();
  800. $this->addSociete(wpConfig::getName(),
  801. wpConfig::getAddress() . "\n" .
  802. "SIRET " . wpConfig::getSiretNumber() . "\n" .
  803. "R.C.S. " . wpConfig::getRcsNumber() . "\n" .
  804. "Capital : " . wpConfig::getCapital() . " " . EURO, utf8_decode($katao_cart->getKataoPeriod()->getName()), $katao_cart->getKataoNode()->getCity());
  805. $this->fact_dev("Demande", $katao_cart->getNumber());
  806. $this->temporaire("Demande");
  807. $this->addDate($katao_cart->getCreatedAt('d/m/Y'));
  808. $this->addClient($katao_member->getAccountingCode());
  809. $this->addPageNumber($page++);
  810. $this->addClientAdresse(utf8_decode(sprintf("%s %s\n%s%s\n%s%s", $katao_member->getLastName(), $katao_member->getFirstName(), $katao_user->getAddress1(), $katao_user->getAddress2()?sprintf("\n%s", $katao_user->getAddress2()):'', $katao_user->getZip()?sprintf("%s ", $katao_user->getZip()):'', $katao_user->getCity())));
  811. //$this->addReglement("Payée");
  812. //$this->addEcheance($katao_cart->getCreatedAt('d/m/Y'));
  813. $this->addNumTVA(wpConfig::getTvaNumber());
  814. //$this->addReference('Votre solde est actuellement de ' . number_format($katao_member->getCurrentAmountEuro(), 2, ',', ' ') . ' ' . EURO . ' et '.$katao_member->getCurrentAmountSol().' SOL');
  815. $cols = array("REFERENCE" => 23,
  816. "DESIGNATION" => 78,
  817. "QUANTITE" => 22,
  818. "P.U. TTC" => 26,
  819. "MONTANT TTC" => 30,
  820. "TVA" => 11);
  821. $this->addCols($cols);
  822. $cols = array("REFERENCE" => "L",
  823. "DESIGNATION" => "L",
  824. "QUANTITE" => "C",
  825. "P.U. TTC" => "R",
  826. "MONTANT TTC" => "R",
  827. "TVA" => "C");
  828. $this->addLineFormat($cols);
  829. $this->addLineFormat($cols);
  830. return $page;
  831. }
  832. /**
  833. * PDF_Invoice::addPageHeaderSupplierInvoice()
  834. *
  835. * @param int $page
  836. * @param KataoSupplierInvoice $katao_supplier_invoice
  837. * @param KataoSupplier $katao_supplier
  838. * @return
  839. */
  840. function addPageHeaderSupplierInvoice($page, $katao_supplier_invoice, $katao_supplier){
  841. $this->AddPage();
  842. $this->addSociete($katao_supplier_invoice->getKataoName(),
  843. $katao_supplier_invoice->getKataoAddress() . "\n" .
  844. "SIRET " . $katao_supplier_invoice->getKataoSiretNumber() . "\n" .
  845. "R.C.S. " . $katao_supplier_invoice->getKataoRcsNumber() . "\n" .
  846. "Capital : " . $katao_supplier_invoice->getKataoCapital() . " " . EURO, utf8_decode($katao_supplier_invoice->getKataoPeriod()->getName()), '', $katao_supplier_invoice->getOrdersStr());
  847. $this->fact_dev("Facture", $katao_supplier_invoice->getReference());
  848. // $this->temporaire("Devis temporaire");
  849. $this->addDate($katao_supplier_invoice->getInvoiceDate('d/m/Y'));
  850. $this->addClient($katao_supplier->getAccountingCode());
  851. $this->addPageNumber($page++);
  852. $this->addClientAdresse(utf8_decode(sprintf("%s\n%s%s\n%s%s", $katao_supplier_invoice->getSupplierName(), $katao_supplier_invoice->getSupplierAddress1(), $katao_supplier_invoice->getSupplierAddress2()?sprintf("\n%s", $katao_supplier_invoice->getSupplierAddress2()):'', $katao_supplier_invoice->getSupplierZip()?sprintf("%s ", $katao_supplier_invoice->getSupplierZip()):'', $katao_supplier_invoice->getSupplierCity())));
  853. //$this->addReglement("Payée");
  854. //$this->addEcheance($katao_order->getCreatedAt('d/m/Y'));
  855. $this->addNumTVA(wpConfig::getTvaNumber());
  856. $reference = wpConfig::getAdditionalCurrencyName() . ' utilisés : ' . $katao_supplier_invoice->getUsedSolTotal();
  857. if ('' != $comment = $katao_supplier_invoice->getComment()) {
  858. $reference .= " - Observations : " . $comment;
  859. }
  860. $this->addReference($reference);
  861. $cols = array("REFERENCE" => 23,
  862. "DESIGNATION" => 78,
  863. "QUANTITE" => 22,
  864. "P.U. TTC" => 26,
  865. "MONTANT TTC" => 30,
  866. "TVA" => 11);
  867. $this->addCols($cols);
  868. $cols = array("REFERENCE" => "L",
  869. "DESIGNATION" => "L",
  870. "QUANTITE" => "C",
  871. "P.U. TTC" => "R",
  872. "MONTANT TTC" => "R",
  873. "TVA" => "C");
  874. $this->addLineFormat($cols);
  875. $this->addLineFormat($cols);
  876. return $page;
  877. }
  878. }
  879. ?>