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

/PDFRemittanceAdvice.php

http://kwamoja.codeplex.com
PHP | 321 lines | 240 code | 59 blank | 22 comment | 18 complexity | 985618e97f814fad07a4a523691fb21a MD5 | raw file
Possible License(s): LGPL-3.0, AGPL-1.0, GPL-2.0, LGPL-2.1
  1. <?php
  2. /* $Id$*/
  3. include('includes/session.inc');
  4. if ((isset($_POST['PrintPDF']))
  5. and isset($_POST['FromCriteria'])
  6. and mb_strlen($_POST['FromCriteria'])>=1
  7. and isset($_POST['ToCriteria'])
  8. and mb_strlen($_POST['ToCriteria'])>=1) {
  9. /*Now figure out the invoice less credits due for the Supplier range under review */
  10. $sql = "SELECT suppliers.supplierid,
  11. suppliers.suppname,
  12. suppliers.address1,
  13. suppliers.address2,
  14. suppliers.address3,
  15. suppliers.address4,
  16. suppliers.address5,
  17. suppliers.address6,
  18. suppliers.currcode,
  19. supptrans.id,
  20. currencies.decimalplaces AS currdecimalplaces
  21. FROM supptrans INNER JOIN suppliers ON supptrans.supplierno = suppliers.supplierid
  22. INNER JOIN paymentterms ON suppliers.paymentterms = paymentterms.termsindicator
  23. INNER JOIN currencies ON suppliers.currcode=currencies.currabrev
  24. WHERE supptrans.type=22
  25. AND trandate ='" . FormatDateForSQL($_POST['PaymentDate']) . "'
  26. AND supplierno >= '" . $_POST['FromCriteria'] . "'
  27. AND supplierno <= '" . $_POST['ToCriteria'] . "'
  28. AND suppliers.remittance=1
  29. ORDER BY supplierno";
  30. $SuppliersResult = DB_query($sql,$db);
  31. if (DB_num_rows($SuppliersResult)==0){
  32. //then there aint awt to print
  33. $Title = _('Print Remittance Advices Error');
  34. include('includes/header.inc');
  35. prnMsg(_('There were no remittance advices to print out for the supplier range and payment date specified'),'warn');
  36. echo '<br /><a href="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'. _('Back').'</a>';
  37. include('includes/footer.inc');
  38. exit;
  39. }
  40. /*then print the report */
  41. include('includes/PDFStarter.php');
  42. $pdf->addInfo('Title',_('Remmitance Advice'));
  43. $pdf->addInfo('Subject',_('Remittance Advice') . ' - ' . _('suppliers from') . ' ' . $_POST['FromCriteria'] . ' ' . _('to') . ' ' . $_POST['ToCriteria'] . ' ' . _('and Paid On') . ' ' . $_POST['PaymentDate']);
  44. $line_height=12;
  45. $SupplierID ='';
  46. $RemittanceAdviceCounter =0;
  47. while ($SuppliersPaid = DB_fetch_array($SuppliersResult)){
  48. $PageNumber=1;
  49. PageHeader();
  50. $RemittanceAdviceCounter++;
  51. $SupplierID = $SuppliersPaid['supplierid'];
  52. $SupplierName = $SuppliersPaid['suppname'];
  53. $AccumBalance = 0;
  54. /* Now get the transactions and amounts that the payment was allocated to */
  55. $sql = "SELECT systypes.typename,
  56. supptrans.suppreference,
  57. supptrans.trandate,
  58. supptrans.transno,
  59. suppallocs.amt,
  60. (supptrans.ovamount + supptrans.ovgst ) AS trantotal
  61. FROM supptrans
  62. INNER JOIN systypes ON systypes.typeid = supptrans.type
  63. INNER JOIN suppallocs ON suppallocs.transid_allocto=supptrans.id
  64. WHERE suppallocs.transid_allocfrom='" . $SuppliersPaid['id'] . "'
  65. ORDER BY supptrans.type,
  66. supptrans.transno";
  67. $TransResult = DB_query($sql,$db,'','',false,false);
  68. if (DB_error_no($db) !=0) {
  69. $Title = _('Remittance Advice Problem Report');
  70. include('includes/header.inc');
  71. prnMsg(_('The details of the payment to the supplier could not be retrieved because') . ' - ' . DB_error_msg($db),'error');
  72. echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
  73. if ($debug==1){
  74. echo '<br />' . _('The SQL that failed was') . ' ' . $sql;
  75. }
  76. include('includes/footer.inc');
  77. exit;
  78. }
  79. while ($DetailTrans = DB_fetch_array($TransResult)){
  80. $DisplayTranDate = ConvertSQLDate($DetailTrans['trandate']);
  81. $LeftOvers = $pdf->addTextWrap($Left_Margin+5, $YPos, 80,$FontSize,$DetailTrans['typename'], 'left');
  82. $LeftOvers = $pdf->addTextWrap($Left_Margin+95, $YPos, 80,$FontSize,$DisplayTranDate, 'left');
  83. $LeftOvers = $pdf->addTextWrap($Left_Margin+175, $YPos, 80,$FontSize,$DetailTrans['suppreference'], 'left');
  84. $LeftOvers = $pdf->addTextWrap($Left_Margin+255, $YPos, 80,$FontSize,locale_number_format($DetailTrans['trantotal'],$SuppliersPaid['currdecimalplaces']), 'right');
  85. $LeftOvers = $pdf->addTextWrap($Left_Margin+355, $YPos,80,$FontSize,locale_number_format($DetailTrans['amt'],$SuppliersPaid['currdecimalplaces']), 'right');
  86. $AccumBalance += $DetailTrans['amt'];
  87. $YPos -=$line_height;
  88. if ($YPos < $Bottom_Margin + $line_height){
  89. $PageNumber++;
  90. PageHeader();
  91. }
  92. } /*end while there are detail transactions to show */
  93. $YPos -= (0.5*$line_height);
  94. $pdf->line($Left_Margin, $YPos+$line_height,$Page_Width-$Right_Margin, $YPos+$line_height);
  95. $LeftOvers = $pdf->addTextWrap($Left_Margin+280,$YPos,75,$FontSize,_('Total Payment:'), 'right');
  96. $TotalPayments += $AccumBalance;
  97. $LeftOvers = $pdf->addTextWrap($Left_Margin+355,$YPos,80,$FontSize,locale_number_format($AccumBalance,$SuppliersPaid['currdecimalplaces']), 'right');
  98. $YPos -= (1.5*$line_height);
  99. $pdf->line($Left_Margin, $YPos+$line_height,$Page_Width-$Right_Margin, $YPos+$line_height);
  100. } /* end while there are supplier payments to retrieve allocations for */
  101. $FileName=$_SESSION['DatabaseName']. '_' . _('Remittance_Advices') . '_' . date('Y-m-d').'.pdf';
  102. $pdf->OutputD($FileName);
  103. $pdf->__destruct();
  104. } else { /*The option to print PDF was not hit */
  105. $Title=_('Remittance Advices');
  106. include('includes/header.inc');
  107. echo '<p class="page_title_text noPrint" ><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . $Title . '" alt="" />' . ' '
  108. . $Title . '</p>';
  109. /* show form to allow input */
  110. echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" class="noPrint">';
  111. echo '<div>';
  112. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  113. echo '<table>';
  114. if (!isset($_POST['FromCriteria']) or mb_strlen($_POST['FromCriteria'])<1){
  115. $DefaultFromCriteria = '1';
  116. } else {
  117. $DefaultFromCriteria = $_POST['FromCriteria'];
  118. }
  119. if (!isset($_POST['ToCriteria']) or mb_strlen($_POST['ToCriteria'])<1){
  120. $DefaultToCriteria = 'zzzzzzz';
  121. } else {
  122. $DefaultToCriteria = $_POST['ToCriteria'];
  123. }
  124. echo '<tr>
  125. <td>' . _('From Supplier Code') . ':</td>
  126. <td><input type="text" maxlength="6" size="7" name="FromCriteria" value="' . $DefaultFromCriteria . '" /></td>
  127. </tr>';
  128. echo '<tr>
  129. <td>' . _('To Supplier Code') . ':</td>
  130. <td><input type="text" maxlength="6" size="7" name="ToCriteria" value="' . $DefaultToCriteria . '" /></td>
  131. </tr>';
  132. if (!isset($_POST['PaymentDate'])){
  133. $DefaultDate = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m')+1,0 ,Date('y')));
  134. } else {
  135. $DefaultDate = $_POST['PaymentDate'];
  136. }
  137. echo '<tr>
  138. <td>' . _('Date Of Payment') . ':</td>
  139. <td><input type="text" class="date" alt="'.$_SESSION['DefaultDateFormat'].'" name="PaymentDate" maxlength="11" size="12" value="' . $DefaultDate . '" /></td>
  140. </tr>';
  141. echo '</table>
  142. <br />
  143. <div class="centre">
  144. <input type="submit" name="PrintPDF" value="' . _('Print PDF') . '" />
  145. </div>';
  146. echo '</div>
  147. </form>';
  148. include ('includes/footer.inc');
  149. } /*end of else not PrintPDF */
  150. function PageHeader(){
  151. global $pdf;
  152. global $PageNumber;
  153. global $YPos;
  154. global $Xpos;
  155. global $line_height;
  156. global $Page_Height;
  157. global $Top_Margin;
  158. global $Page_Width;
  159. global $Right_Margin;
  160. global $Left_Margin;
  161. global $Bottom_Margin;
  162. global $FontSize;
  163. global $SupplierName;
  164. global $AccumBalance;
  165. global $RemittanceAdviceCounter;
  166. global $SuppliersPaid;
  167. if ($RemittanceAdviceCounter>0){
  168. $pdf->newPage();
  169. }
  170. $YPos = $Page_Height - $Top_Margin;
  171. $pdf->addJpegFromFile($_SESSION['LogoFile'],$Page_Width/2 -50,$YPos-50,0,30);
  172. // Title
  173. $FontSize =15;
  174. $XPos = $Page_Width/2 - 110;
  175. $pdf->addText($XPos, $YPos,$FontSize, _('Remittance Advice') );
  176. $FontSize = 10;
  177. $pdf->addText($XPos + 150, $YPos,$FontSize, ' '. _('printed:').' ' . Date($_SESSION['DefaultDateFormat']));
  178. $pdf->addText($XPos + 280, $YPos,$FontSize, _('Page').': ' . $PageNumber);
  179. /*Now print out company info at the top left */
  180. $XPos = $Left_Margin;
  181. $YPos = $Page_Height - $Top_Margin - 20;
  182. $FontSize = 10;
  183. $LineHeight = 13;
  184. $LineCount = 0;
  185. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $_SESSION['CompanyRecord']['coyname']);
  186. $FontSize = 8;
  187. $LineHeight = 10;
  188. if ($_SESSION['CompanyRecord']['regoffice1'] <> '') {
  189. $LineCount += 1;
  190. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice1']);
  191. }
  192. if ($_SESSION['CompanyRecord']['regoffice2'] <> '') {
  193. $LineCount += 1;
  194. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice2']);
  195. }
  196. if (($_SESSION['CompanyRecord']['regoffice3'] <> '') or ($_SESSION['CompanyRecord']['regoffice4'] <> '') or ($_SESSION['CompanyRecord']['regoffice5'] <> '')) {
  197. $LineCount += 1;
  198. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice3'] . ' ' . $_SESSION['CompanyRecord']['regoffice4'] . ' ' . $_SESSION['CompanyRecord']['regoffice5']); // country in 6 not printed
  199. }
  200. $LineCount += 1;
  201. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Phone') . ':' . $_SESSION['CompanyRecord']['telephone']);
  202. $LineCount += 1;
  203. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, _('Fax') . ': ' . $_SESSION['CompanyRecord']['fax']);
  204. $LineCount += 1;
  205. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Email') . ': ' . $_SESSION['CompanyRecord']['email']);
  206. /*Now the supplier details and remittance advice address */
  207. $XPos = $Left_Margin+20;
  208. $YPos = $Page_Height - $Top_Margin - 120;
  209. $LineCount = 0;
  210. $FontSize = 10;
  211. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['suppname']);
  212. $LineCount ++;
  213. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address1']);
  214. $LineCount ++;
  215. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address2']);
  216. $LineCount ++;
  217. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address3'] . ' ' . $SuppliersPaid['address4'] . ' ' . $SuppliersPaid['address5'] . ' ' . $SuppliersPaid['address6']);
  218. $LineCount += 2;
  219. $pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Our Code:') . ' ' .$SuppliersPaid['supplierid']);
  220. $YPos = $Page_Height - $Top_Margin - 120;
  221. $FontSize=8;
  222. $XPos = $Page_Width/2 - 60;
  223. $pdf->addText($XPos, $YPos,$FontSize, _('All amounts stated in') . ' - ' . $SuppliersPaid['currcode']);
  224. $YPos -= $line_height;
  225. $pdf->addText($XPos, $YPos,$FontSize, $SuppliersPaid['terms']);
  226. $YPos = $Page_Height - $Top_Margin - 180;
  227. //$YPos -= $line_height;
  228. $XPos = $Left_Margin;
  229. /*draw a nice curved corner box around the statement details */
  230. /*from the top right */
  231. $pdf->partEllipse($Page_Width-$Right_Margin-10,$YPos-10,0,90,10,10);
  232. /*line to the top left */
  233. $pdf->line($Page_Width-$Right_Margin-10, $YPos,$Left_Margin+10, $YPos);
  234. /*Do top left corner */
  235. $pdf->partEllipse($Left_Margin+10, $YPos-10,90,180,10,10);
  236. /*Do a line to the bottom left corner */
  237. $pdf->line($Left_Margin, $YPos-10,$Left_Margin, $Bottom_Margin+10);
  238. /*Now do the bottom left corner 180 - 270 coming back west*/
  239. $pdf->partEllipse($Left_Margin+10, $Bottom_Margin+10,180,270,10,10);
  240. /*Now a line to the bottom right */
  241. $pdf->line($Left_Margin+10, $Bottom_Margin,$Page_Width-$Right_Margin-10, $Bottom_Margin);
  242. /*Now do the bottom right corner */
  243. $pdf->partEllipse($Page_Width-$Right_Margin-10, $Bottom_Margin+10,270,360,10,10);
  244. /*Finally join up to the top right corner where started */
  245. $pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+10,$Page_Width-$Right_Margin, $YPos-10);
  246. /*Finally join up to the top right corner where started */
  247. $pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+10,$Page_Width-$Right_Margin, $YPos-10);
  248. $YPos -= $line_height;
  249. $FontSize =10;
  250. /*Set up headings */
  251. $pdf->addText($Left_Margin+10, $YPos,$FontSize, _('Trans Type') );
  252. $pdf->addText($Left_Margin+100, $YPos,$FontSize, _('Date') );
  253. $pdf->addText($Left_Margin+180, $YPos,$FontSize, _('Reference') );
  254. $pdf->addText($Left_Margin+310, $YPos,$FontSize, _('Total') );
  255. $pdf->addText($Left_Margin+390, $YPos,$FontSize, _('This Payment') );
  256. $YPos -= $line_height;
  257. /*draw a line */
  258. $pdf->line($Page_Width-$Right_Margin, $YPos,$XPos, $YPos);
  259. $YPos -= $line_height;
  260. $XPos = $Left_Margin;
  261. }
  262. ?>