PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/chronique/includes/PDFPaymentRun_PymtFooter.php

http://chronique.googlecode.com/
PHP | 244 lines | 201 code | 33 blank | 10 comment | 19 complexity | 3416d70d55413e0b2dd7dd71e934b937 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* $Id: PDFPaymentRun_PymtFooter.php 4744 2011-11-12 09:42:34Z daintree $*/
  3. /*Code to print footer details for each supplier being paid and process payment total for each supplier
  4. as necessary an include file used since the same code is used twice */
  5. $YPos -= (0.5*$line_height);
  6. $pdf->line($Left_Margin, $YPos+$line_height,$Page_Width-$Right_Margin, $YPos+$line_height);
  7. $LeftOvers = $pdf->addTextWrap($Left_Margin+10,$YPos,340-$Left_Margin,$FontSize,_('Total Due For') . ' ' . $SupplierName, 'left');
  8. $TotalPayments += $AccumBalance;
  9. $TotalAccumDiffOnExch += $AccumDiffOnExch;
  10. $LeftOvers = $pdf->addTextWrap(340,$YPos,60,$FontSize,locale_number_format($AccumBalance,$CurrDecimalPlaces), 'right');
  11. $LeftOvers = $pdf->addTextWrap(405,$YPos,60,$FontSize,locale_number_format($AccumDiffOnExch,$CurrDecimalPlaces), 'right');
  12. if (isset($_POST['PrintPDFAndProcess'])){
  13. if (is_numeric(filter_number_format($_POST['Ref']))) {
  14. $PaytReference = filter_number_format($_POST['Ref']) + $RefCounter;
  15. } else {
  16. $PaytReference = $_POST['Ref'] . ($RefCounter + 1);
  17. }
  18. $RefCounter++;
  19. /*Do the inserts for the payment transaction into the Supp Trans table*/
  20. $SQL = "INSERT INTO supptrans (type,
  21. transno,
  22. suppreference,
  23. supplierno,
  24. trandate,
  25. duedate,
  26. inputdate,
  27. settled,
  28. rate,
  29. ovamount,
  30. diffonexch,
  31. alloc)
  32. VALUES (22,
  33. '" . $SuppPaymentNo . "',
  34. '" . $PaytReference . "',
  35. '" . $SupplierID . "',
  36. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  37. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  38. '" . date('Y-m-d H-i-s') . "',
  39. 1,
  40. '" . filter_number_format($_POST['ExRate']) . "',
  41. '" . -$AccumBalance . "',
  42. '" . -$AccumDiffOnExch . "',
  43. '" . -$AccumBalance . "')";
  44. $ProcessResult = DB_query($SQL,$db,'','',false,false);
  45. if (DB_error_no($db) !=0) {
  46. $title = _('Payment Processing - Problem Report');
  47. include('header.inc');
  48. prnMsg(_('None of the payments will be processed because the payment record for') . ' ' . $SupplierName . ' ' . _('could not be inserted because') . ' - ' . DB_error_msg($db),'error');
  49. echo '<br>
  50. <a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  51. if ($debug==1){
  52. prnMsg(_('The SQL that failed was') . ' ' . $SQL,'error');
  53. }
  54. $ProcessResult = DB_Txn_Rollback($db);
  55. include('footer.inc');
  56. exit;
  57. }
  58. $PaymentTransID = DB_Last_Insert_ID($db,'supptrans','id');
  59. /*Do the inserts for the allocation record against the payment for this charge */
  60. foreach ($Allocs AS $AllocTrans){ /*loop through the array of allocations */
  61. $SQL = "INSERT INTO suppallocs (amt,
  62. datealloc,
  63. transid_allocfrom,
  64. transid_allocto)
  65. VALUES (
  66. '" . $AllocTrans->Amount . "',
  67. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  68. '" . $PaymentTransID . "',
  69. '" . $AllocTrans->TransID . "')";
  70. $ProcessResult = DB_query($SQL,$db);
  71. if (DB_error_no($db) !=0) {
  72. $title = _('Payment Processing - Problem Report') . '.... ';
  73. include('header.inc');
  74. prnMsg(_('None of the payments will be processed since an allocation record for') . $SupplierName . _('could not be inserted because') . ' - ' . DB_error_msg($db),'error');
  75. echo '<br><a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  76. if ($debug==1){
  77. prnMsg(_('The SQL that failed was') . $SQL,'error');
  78. }
  79. $ProcessResult = DB_Txn_Rollback($db);
  80. include('footer.inc');
  81. exit;
  82. }
  83. } /*end of the loop to insert the allocation records */
  84. /*Do the inserts for the payment transaction into the BankTrans table*/
  85. $SQL="INSERT INTO banktrans (bankact,
  86. ref,
  87. exrate,
  88. transdate,
  89. banktranstype,
  90. amount) ";
  91. $SQL = $SQL . "VALUES ( " . $_POST['BankAccount'] . ",
  92. '" . $PaytReference . " " . $SupplierID . "',
  93. " . filter_number_format($_POST['ExRate']) . ",
  94. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  95. '" . $_POST['PaytType'] . "',
  96. " . -$AccumBalance . ")";
  97. $ProcessResult = DB_query($SQL,$db,'','',false,false);
  98. if (DB_error_no($db) !=0) {
  99. $title = _('Payment Processing - Problem Report');
  100. include('header.inc');
  101. prnMsg(_('None of the payments will be processed because the bank account payment record for') . ' ' . $SupplierName . ' ' . _('could not be inserted because') . ' - ' . DB_error_msg($db),'error');
  102. echo '<br />
  103. <a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  104. if ($debug==1){
  105. prnMsg(_('The SQL that failed was') . ' ' . $SQL,'error');
  106. }
  107. $ProcessResult = DB_Txn_Rollback($db);
  108. include('footer.inc');
  109. exit;
  110. }
  111. /*If the General Ledger Link is activated */
  112. if ($_SESSION['CompanyRecord']['gllink_creditors']==1){
  113. $PeriodNo = GetPeriod($_POST['AmountsDueBy'],$db);
  114. /*Do the GL trans for the payment CR bank */
  115. $SQL = "INSERT INTO gltrans (type,
  116. typeno,
  117. trandate,
  118. periodno,
  119. account,
  120. narrative,
  121. amount )
  122. VALUES (22,
  123. '" . $SuppPaymentNo . "',
  124. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  125. '" . $PeriodNo . "',
  126. '" . $_POST['BankAccount'] . "',
  127. '" . $SupplierID . " - " . $SupplierName . ' ' . _('payment run on') . ' ' . Date($_SESSION['DefaultDateFormat']) . ' - ' . $PaytReference . "',
  128. '" . (-$AccumBalance/ filter_number_format($_POST['ExRate'])) . "')";
  129. $ProcessResult = DB_query($SQL,$db,'','',false,false);
  130. if (DB_error_no($db) !=0) {
  131. $title = _('Payment Processing') . ' - ' . _('Problem Report') . '.... ';
  132. include('header.inc');
  133. prnMsg(_('None of the payments will be processed since the general ledger posting for the payment to') . ' ' . $SupplierName . ' ' . _('could not be inserted because') . ' - ' . DB_error_msg($db),'error');
  134. echo '<br />
  135. <a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  136. if ($debug==1){
  137. prnMsg(_('The SQL that failed was') . ':<br />' . $SQL, 'error');
  138. }
  139. $ProcessResult = DB_Txn_Rollback($db);
  140. include('footer.inc');
  141. exit;
  142. }
  143. /*Do the GL trans for the payment DR creditors */
  144. $SQL = "INSERT INTO gltrans (type,
  145. typeno,
  146. trandate,
  147. periodno,
  148. account,
  149. narrative,
  150. amount )
  151. VALUES (22,
  152. '" . $SuppPaymentNo . "',
  153. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  154. '" . $PeriodNo . "',
  155. '" . $_SESSION['CompanyRecord']['creditorsact'] . "',
  156. '" . $SupplierID . ' - ' . $SupplierName . ' ' . _('payment run on') . ' ' . Date($_SESSION['DefaultDateFormat']) . ' - ' . $PaytReference . "',
  157. '" . ($AccumBalance/ filter_number_format($_POST['ExRate']) + $AccumDiffOnExch) . "')";
  158. $ProcessResult = DB_query($SQL,$db,'','',false,false);
  159. if (DB_error_no($db) !=0) {
  160. $title = _('Payment Processing - Problem Report');
  161. include('header.inc');
  162. prnMsg(_('None of the payments will be processed since the general ledger posting for the payment to') . ' ' . $SupplierName . ' ' . _('could not be inserted because') . ' - ' . DB_error_msg($db),'error');
  163. echo '<br /><a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  164. if ($debug==1){
  165. prnMsg(_('The SQL that failed was') . ':<BR>' . $SQL,'error');
  166. }
  167. $ProcessResult = DB_Txn_Rollback($db);
  168. include('footer.inc');
  169. exit;
  170. }
  171. /*Do the GL trans for the exch diff */
  172. if ($AccumDiffOnExch != 0){
  173. $SQL = "INSERT INTO gltrans (type,
  174. typeno,
  175. trandate,
  176. periodno,
  177. account,
  178. narrative,
  179. amount )
  180. VALUES (22,
  181. '" . $SuppPaymentNo . "',
  182. '" . FormatDateForSQL($_POST['AmountsDueBy']) . "',
  183. '" . $PeriodNo . "',
  184. '" . $_SESSION['CompanyRecord']['purchasesexchangediffact'] . "',
  185. '" . $SupplierID . ' - ' . $SupplierName . ' ' . _('payment run on') . ' ' . Date($_SESSION['DefaultDateFormat']) . " - " . $PaytReference . "',
  186. '" . (-$AccumDiffOnExch) . "')";
  187. $ProcessResult = DB_query($SQL,$db,'','',false,false);
  188. if (DB_error_no($db) !=0) {
  189. $title = _('Payment Processing - Problem Report');
  190. include('header.inc');
  191. prnMsg(_('None of the payments will be processed since the general ledger posting for the exchange difference on') . ' ' . $SupplierName . ' ' . _('could not be inserted because') .' - ' . DB_error_msg($db),'error');
  192. echo '<br /><a href="' . $rootpath . '/index.php">' . _('Back to the menu') . '</a>';
  193. if ($debug==1){
  194. prnMsg(_('The SQL that failed was: ') . '<br />' . $SQL,'error');
  195. }
  196. $ProcessResult = DB_Txn_Rollback($db);
  197. include('footer.inc');
  198. exit;
  199. }
  200. }
  201. EnsureGLEntriesBalance(22,$SuppPaymentNo,$db);
  202. } /*end if GL linked to creditors */
  203. }
  204. $YPos -= (1.5*$line_height);
  205. $pdf->line($Left_Margin, $YPos+$line_height,$Page_Width-$Right_Margin, $YPos+$line_height);
  206. $YPos -= $line_height;
  207. if ($YPos < $Bottom_Margin + $line_height){
  208. $PageNumber++;
  209. include('PDFPaymentRunPageHeader.inc');
  210. }
  211. ?>