PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/config/templates/report_template.php

http://gevion.googlecode.com/
PHP | 279 lines | 234 code | 12 blank | 33 comment | 27 complexity | 5c9ee76860a3d54ed9a89a7c96084e27 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /* $Id: report_template.php,v 1.14 2010/01/16 14:39:06 devincen Exp $
  3. --------------------------------------------------------------------------
  4. Gazie - Gestione Azienda
  5. Copyright (C) 2004-2010 - Antonio De Vincentiis Montesilvano (PE)
  6. (www.devincentiis.it)
  7. <http://gazie.sourceforge.net>
  8. --------------------------------------------------------------------------
  9. Questo programma e` free software; e` lecito redistribuirlo e/o
  10. modificarlo secondo i termini della Licenza Pubblica Generica GNU
  11. come e` pubblicata dalla Free Software Foundation; o la versione 2
  12. della licenza o (a propria scelta) una versione successiva.
  13. Questo programma e` distribuito nella speranza che sia utile, ma
  14. SENZA ALCUNA GARANZIA; senza neppure la garanzia implicita di
  15. NEGOZIABILITA` o di APPLICABILITA` PER UN PARTICOLARE SCOPO. Si
  16. veda la Licenza Pubblica Generica GNU per avere maggiori dettagli.
  17. Ognuno dovrebbe avere ricevuto una copia della Licenza Pubblica
  18. Generica GNU insieme a questo programma; in caso contrario, si
  19. scriva alla Free Software Foundation, Inc., 59
  20. Temple Place, Suite 330, Boston, MA 02111-1307 USA Stati Uniti.
  21. --------------------------------------------------------------------------
  22. */
  23. require('../../library/tcpdf/tcpdf.php');
  24. class Report_template extends TCPDF
  25. {
  26. function setVars($admin_aziend,$altri_dati='')
  27. {
  28. $this->logo=$admin_aziend['image'];
  29. $this->intesta1 = $admin_aziend['ragso1'].' '.$admin_aziend['ragso2'];
  30. $this->intesta2 = $admin_aziend['indspe'].' '.sprintf("%05d",$admin_aziend['capspe']).' '.$admin_aziend['citspe'].' ('.$admin_aziend['prospe'].')';
  31. $this->intesta3 = 'Tel.'.$admin_aziend['telefo'].' C.F.:'.$admin_aziend['codfis'].' P.I.:'.$admin_aziend['pariva'];
  32. $this->intesta4 = $admin_aziend['e_mail'];
  33. if (isset($altri_dati['luogo_data'])) { // se viene passata il valore di luogo_data
  34. $this->luogo = $altri_dati['luogo_data'];
  35. } else { // altrimenti uso quello di default
  36. $this->luogo = $admin_aziend['citspe'].", l?? ".date("d ").ucfirst(strftime("%B", mktime (0,0,0,date("m")))).date(" Y");
  37. }
  38. $this->SetCreator(PDF_CREATOR);
  39. if (isset($altri_dati['title'])) { // se viene passato il titolo
  40. $this->SetTitle($altri_dati['title']);
  41. }
  42. $this->SetAuthor($this->intesta1.' '.PDF_AUTHOR);
  43. $this->SetHeaderMargin(7);
  44. $this->SetTopMargin(44);
  45. $this->SetFooterMargin(23);
  46. $this->SetFillColor(hexdec(substr($admin_aziend['colore'],0,2)),hexdec(substr($admin_aziend['colore'],2,2)),hexdec(substr($admin_aziend['colore'],4,2)));
  47. $this->StartPageGroup();
  48. $this->altri_dati = $altri_dati;
  49. }
  50. function setRiporti($intesta_riporti='')
  51. {
  52. $this->intesta_riporti = $intesta_riporti;
  53. }
  54. function setFreeFooter($free_footer='')
  55. {
  56. $this->free_footer = $free_footer;
  57. }
  58. function setFreeHeader($free_header='')
  59. {
  60. $this->free_header = $free_header;
  61. }
  62. function setPageTitle($intesta_title='')
  63. {
  64. $this->altri_dati['title'] = $intesta_title;
  65. }
  66. function setItemGroup($intesta_item_group='',$item_group='')
  67. {
  68. $this->item_group = $item_group;
  69. $this->intesta_item_group = $intesta_item_group;
  70. }
  71. function Header()
  72. {
  73. if (isset($this->altri_dati['cover']) and !empty($this->altri_dati['cover']) ){ // ? stato passato il valore di pagina da stampare
  74. $this->descri_cover = $this->altri_dati['cover'];
  75. $this->printCover();
  76. } else {
  77. $this->SetFont('freesans','',9);
  78. $this->MemImage($this->logo,15,8,30,0);
  79. $this->Cell(40,4);
  80. $this->Cell(118,4,$this->intesta1,0,0,'L');
  81. if (isset($this->altri_dati['page'])){ // ? stato passato il valore di pagina da stampare
  82. $this->Cell(30,4,$this->altri_dati['page'].$this->GroupPageNo(),0,1,'R');
  83. } else {
  84. $this->Cell(30,4,'Pagina '.$this->getGroupPageNo().' di '.$this->getPageGroupAlias(),0,1,'R');
  85. }
  86. $this->Cell(40,4);
  87. $this->Cell(130,4,$this->intesta2,0,2,'L');
  88. $this->Cell(130,4,$this->intesta3,0,2,'L');
  89. $this->Cell(118,4,$this->intesta4,0,0,'L');
  90. $this->Cell(30,4,$this->luogo,0,1,'R');
  91. if (!empty($this->item_group)){ //C'? una immagine associata
  92. $this->MemImage($this->item_group,177,28,0,20);
  93. $this->Ln(4);
  94. }
  95. if (isset($this->intesta_item_group) and is_array($this->intesta_item_group)){ // c'? una descrizione dell'articolo
  96. $this->SetFont('freesans','',9);
  97. $this->Cell(40);
  98. foreach ($this->intesta_item_group['top'] as $key=>$value){
  99. $this->Cell($value['lun'],4,$value['nam'],1,0,'C',1);
  100. }
  101. $this->Cell(1,4,'',0,1);
  102. $this->Cell(40);
  103. foreach ($this->intesta_item_group['bot'] as $key=>$value){
  104. $this->Cell($value['lun'],4,$value['nam'],1,0,'C');
  105. }
  106. $this->Cell(1,4,'',0,1);
  107. $this->SetFont('freesans','',8);
  108. }
  109. if (is_array($this->altri_dati) and isset($this->altri_dati['title'])){ // ? una intestazione con titolo e testata tabella
  110. $this->Cell(40);
  111. $this->SetFont('freesans','',12);
  112. $this->Cell(130,12,$this->altri_dati['title'],0,1);
  113. $this->SetFont('freesans','',9);
  114. foreach ($this->altri_dati['hile'] as $key=>$value){
  115. $this->Cell($value['lun'],4,$value['nam'],1,0,'C',1);
  116. }
  117. $this->Cell(1,4,'',0,1);
  118. $this->SetFont('freesans','',8);
  119. } elseif (is_string($this->altri_dati) and !empty($this->altri_dati)) { //solo con titolo
  120. $this->Cell(40);
  121. $this->SetFont('freesans','',12);
  122. $this->Cell(130,12,$this->altri_dati,0,1);
  123. $this->SetFont('freesans','',8);
  124. }
  125. if (isset($this->intesta_riporti) and is_array($this->intesta_riporti)){ // c'? un riporto da pagina precedente
  126. $this->SetFont('freesans','B',8);
  127. foreach ($this->intesta_riporti['top'] as $key=>$value){
  128. $this->Cell($value['lun'],4,$value['nam'],1,0,'R');
  129. }
  130. $this->Cell(1,4,'',0,1);
  131. $this->SetFont('freesans','',8);
  132. }
  133. if (isset($this->free_header) and is_array($this->free_header)) {
  134. foreach ($this->free_header as $value){
  135. $this->Cell($value['lun'],4,$value['nam'],$value['con'],0,$value['ali'],$value['fil']);
  136. }
  137. }
  138. }
  139. }
  140. function Footer()
  141. {
  142. if (isset($this->altri_dati['cover']) and !empty($this->altri_dati['cover']) ){ // ? stato passato il valore di pagina da stampare
  143. $this->altri_dati['cover']='';
  144. } else {
  145. //Page footer
  146. if (isset($this->intesta_riporti) and is_array($this->intesta_riporti)){ // c'? un riporto da pagina precedente
  147. $this->SetFont('freesans','B',8);
  148. foreach ($this->intesta_riporti['bot'] as $key=>$value){
  149. $this->Cell($value['lun'],4,$value['nam'],1,0,'R');
  150. }
  151. $this->Cell(1,4,'',0,1);
  152. if (isset($this->free_footer) and is_array($this->free_footer)){
  153. foreach ($this->free_footer as $value){
  154. $this->Cell($value['lun'],4,$value['nam'],$value['con'],0,$value['ali'],$value['fil']);
  155. }
  156. }
  157. }
  158. $this->SetFont('freesans','',8);
  159. $this->MultiCell($this->getPageWidth()-15,4,$this->intesta1.' '.$this->intesta2.' '.$this->intesta3.' '.$this->intesta4,0,'C');
  160. }
  161. }
  162. function printCover()
  163. {
  164. $this->MemImage($this->logo,80,80,40,0);
  165. $this->SetFont('freesans','',18);
  166. $this->SetXY(10,130);
  167. $this->Cell(190,6,$this->intesta1,0,2,'C');
  168. $this->SetFont('freesans','',12);
  169. $this->Cell(190,6,$this->intesta2,0,2,'C');
  170. $this->Cell(190,6,$this->intesta3,0,2,'C');
  171. $this->SetXY(55,160);
  172. $this->SetFont('freesans','',30);
  173. $this->MultiCell(100,16,$this->descri_cover,1,'C',1);
  174. $this->AddPage();
  175. }
  176. // INIZIO funzioni per codice a barre by Olivier Platey
  177. function EAN13($x,$y,$barcode,$h=16,$w=.35)
  178. {
  179. $this->Barcode($x,$y,$barcode,$h,$w,13);
  180. }
  181. function UPC_A($x,$y,$barcode,$h=16,$w=.35)
  182. {
  183. $this->Barcode($x,$y,$barcode,$h,$w,12);
  184. }
  185. function GetCheckDigit($barcode)
  186. {
  187. //Compute the check digit
  188. $sum=0;
  189. for($i=1;$i<=11;$i+=2)
  190. $sum+=3*$barcode{$i};
  191. for($i=0;$i<=10;$i+=2)
  192. $sum+=$barcode{$i};
  193. $r=$sum%10;
  194. if($r>0)
  195. $r=10-$r;
  196. return $r;
  197. }
  198. function TestCheckDigit($barcode)
  199. {
  200. //Test validity of check digit
  201. $sum=0;
  202. for($i=1;$i<=11;$i+=2)
  203. $sum+=3*$barcode{$i};
  204. for($i=0;$i<=10;$i+=2)
  205. $sum+=$barcode{$i};
  206. return ($sum+$barcode{12})%10==0;
  207. }
  208. function Barcode($x,$y,$barcode,$h,$w,$len)
  209. {
  210. global $admin_aziend;
  211. //Padding
  212. $barcode=str_pad($barcode,$len-1,'0',STR_PAD_LEFT);
  213. if($len==12)
  214. $barcode='0'.$barcode;
  215. //Add or control the check digit
  216. if(strlen($barcode)==12)
  217. $barcode.=$this->GetCheckDigit($barcode);
  218. elseif(!$this->TestCheckDigit($barcode))
  219. $this->Error('Incorrect check digit');
  220. //Convert digits to bars
  221. $codes=array(
  222. 'A'=>array(
  223. '0'=>'0001101','1'=>'0011001','2'=>'0010011','3'=>'0111101','4'=>'0100011',
  224. '5'=>'0110001','6'=>'0101111','7'=>'0111011','8'=>'0110111','9'=>'0001011'),
  225. 'B'=>array(
  226. '0'=>'0100111','1'=>'0110011','2'=>'0011011','3'=>'0100001','4'=>'0011101',
  227. '5'=>'0111001','6'=>'0000101','7'=>'0010001','8'=>'0001001','9'=>'0010111'),
  228. 'C'=>array(
  229. '0'=>'1110010','1'=>'1100110','2'=>'1101100','3'=>'1000010','4'=>'1011100',
  230. '5'=>'1001110','6'=>'1010000','7'=>'1000100','8'=>'1001000','9'=>'1110100')
  231. );
  232. $parities=array(
  233. '0'=>array('A','A','A','A','A','A'),
  234. '1'=>array('A','A','B','A','B','B'),
  235. '2'=>array('A','A','B','B','A','B'),
  236. '3'=>array('A','A','B','B','B','A'),
  237. '4'=>array('A','B','A','A','B','B'),
  238. '5'=>array('A','B','B','A','A','B'),
  239. '6'=>array('A','B','B','B','A','A'),
  240. '7'=>array('A','B','A','B','A','B'),
  241. '8'=>array('A','B','A','B','B','A'),
  242. '9'=>array('A','B','B','A','B','A')
  243. );
  244. $code='101';
  245. $p=$parities[$barcode{0}];
  246. for($i=1;$i<=6;$i++)
  247. $code.=$codes[$p[$i-1]][$barcode{$i}];
  248. $code.='01010';
  249. for($i=7;$i<=12;$i++)
  250. $code.=$codes['C'][$barcode{$i}];
  251. $code.='101';
  252. $this->SetFillColor(0);
  253. //Draw bars
  254. for($i=0;$i<strlen($code);$i++)
  255. {
  256. if($code{$i}=='1')
  257. $this->Rect($x+$i*$w,$y,$w,$h,'F');
  258. }
  259. //Print text uder barcode
  260. $this->Text($x+5,$y+$h+11/$this->k,substr($barcode,-$len));
  261. $this->SetFillColor(hexdec(substr($admin_aziend['colore'],0,2)),hexdec(substr($admin_aziend['colore'],2,2)),hexdec(substr($admin_aziend['colore'],4,2)));
  262. }
  263. // FINE funzioni per codice a barre by Olivier Platey
  264. }
  265. ?>