PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/chronique/SuppTransGLAnalysis.php

http://chronique.googlecode.com/
PHP | 211 lines | 170 code | 32 blank | 9 comment | 35 complexity | e21235d46ab81151f3125bc0ff26e8ad 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: SuppTransGLAnalysis.php 4734 2011-10-29 03:26:27Z daintree $*/
  3. /*The supplier transaction uses the SuppTrans class to hold the information about the invoice or credit note
  4. the SuppTrans class contains an array of GRNs objects - containing details of GRNs for invoicing/crediting and also
  5. an array of GLCodes objects - only used if the AP - GL link is effective */
  6. include('includes/DefineSuppTransClass.php');
  7. /* Session started in header.inc for password checking and authorisation level check */
  8. include('includes/session.inc');
  9. $title = _('Supplier Transaction General Ledger Analysis');
  10. include('includes/header.inc');
  11. if (!isset($_SESSION['SuppTrans'])){
  12. prnMsg(_('To enter a supplier invoice or credit note the supplier must first be selected from the supplier selection screen') . ', ' . _('then the link to enter a supplier invoice or supplier credit note must be clicked on'),'info');
  13. echo '<br /><a href="' . $rootpath . '/SelectSupplier.php">' . _('Select A Supplier') . '</a>';
  14. include('includes/footer.inc');
  15. exit;
  16. /*It all stops here if there aint no supplier selected and transaction initiated ie $_SESSION['SuppTrans'] started off*/
  17. }
  18. /*If the user hit the Add to transaction button then process this first before showing all GL codes on the transaction otherwise it wouldnt show the latest addition*/
  19. if (isset($_POST['AddGLCodeToTrans'])
  20. AND $_POST['AddGLCodeToTrans'] == _('Enter GL Line')){
  21. $InputError = False;
  22. if ($_POST['GLCode'] == ''){
  23. $_POST['GLCode'] = $_POST['AcctSelection'];
  24. }
  25. if ($_POST['GLCode'] == ''){
  26. prnMsg( _('You must select a general ledger code from the list below') ,'warn');
  27. $InputError = True;
  28. }
  29. $sql = "SELECT accountcode,
  30. accountname
  31. FROM chartmaster
  32. WHERE accountcode='" . $_POST['GLCode'] . "'";
  33. $result = DB_query($sql, $db);
  34. if (DB_num_rows($result) == 0 and $_POST['GLCode'] != ''){
  35. prnMsg(_('The account code entered is not a valid code') . '. ' . _('This line cannot be added to the transaction') . '.<br />' . _('You can use the selection box to select the account you want'),'error');
  36. $InputError = True;
  37. } else if ($_POST['GLCode'] != '') {
  38. $myrow = DB_fetch_row($result);
  39. $GLActName = $myrow[1];
  40. if (!is_numeric(filter_number_format($_POST['Amount']))){
  41. prnMsg( _('The amount entered is not numeric') . '. ' . _('This line cannot be added to the transaction'),'error');
  42. $InputError = True;
  43. } elseif ($_POST['JobRef'] != ''){
  44. $sql = "SELECT contractref FROM contracts WHERE contractref='" . $_POST['JobRef'] . "'";
  45. $result = DB_query($sql, $db);
  46. if (DB_num_rows($result) == 0){
  47. prnMsg( _('The contract reference entered is not a valid contract, this line cannot be added to the transaction'),'error');
  48. $InputError = True;
  49. }
  50. }
  51. }
  52. if ($InputError == False){
  53. $_SESSION['SuppTrans']->Add_GLCodes_To_Trans($_POST['GLCode'],
  54. $GLActName,
  55. filter_number_format($_POST['Amount']),
  56. $_POST['Narrative']);
  57. unset($_POST['GLCode']);
  58. unset($_POST['Amount']);
  59. unset($_POST['JobRef']);
  60. unset($_POST['Narrative']);
  61. unset($_POST['AcctSelection']);
  62. }
  63. }
  64. if (isset($_GET['Delete'])){
  65. $_SESSION['SuppTrans']->Remove_GLCodes_From_Trans($_GET['Delete']);
  66. }
  67. if (isset($_GET['Edit'])){
  68. $_POST['GLCode'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->GLCode;
  69. $_POST['AcctSelection']= $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->GLCode;
  70. $_POST['Amount'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Amount;
  71. $_POST['JobRef'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->JobRef;
  72. $_POST['Narrative'] = $_SESSION['SuppTrans']->GLCodes[$_GET['Edit']]->Narrative;
  73. $_SESSION['SuppTrans']->Remove_GLCodes_From_Trans($_GET['Edit']);
  74. }
  75. /*Show all the selected GLCodes so far from the SESSION['SuppInv']->GLCodes array */
  76. if ($_SESSION['SuppTrans']->InvoiceOrCredit == 'Invoice'){
  77. echo '<p class="page_title_text">
  78. <img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('General Ledger') . '" alt="" />' . ' ' . _('General Ledger Analysis of Invoice From') . ' ' . $_SESSION['SuppTrans']->SupplierName;
  79. } else {
  80. echo '<p class="page_title_text">
  81. <img src="'.$rootpath.'/css/'.$theme.'/images/transactions.png" title="' . _('General Ledger') . '" alt="" />' . ' ' . _('General Ledger Analysis of Credit Note From') . ' ' . $_SESSION['SuppTrans']->SupplierName;
  82. }
  83. echo '</p>
  84. <table class="selection">';
  85. $TableHeader = '<tr>
  86. <th>' . _('Account') . '</th>
  87. <th>' . _('Name') . '</th>
  88. <th>' . _('Amount') . '<br />' . _('in') . ' ' . $_SESSION['SuppTrans']->CurrCode . '</th>
  89. <th>' . _('Narrative') . '</th>
  90. </tr>';
  91. echo $TableHeader;
  92. $TotalGLValue=0;
  93. $i=0;
  94. foreach ( $_SESSION['SuppTrans']->GLCodes AS $EnteredGLCode){
  95. echo '<tr>
  96. <td>' . $EnteredGLCode->GLCode . '</td>
  97. <td>' . $EnteredGLCode->GLActName . '</td>
  98. <td class="number">' . locale_number_format($EnteredGLCode->Amount,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</td>
  99. <td>' . $EnteredGLCode->Narrative . '</td>
  100. <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?Edit=' . $EnteredGLCode->Counter . '">' . _('Edit') . '</a></td>
  101. <td><a href="' . htmlspecialchars($_SERVER['PHP_SELF']) . '?Delete=' . $EnteredGLCode->Counter . '">' . _('Delete') . '</a></td>
  102. </tr>';
  103. $TotalGLValue += $EnteredGLCode->Amount;
  104. $i++;
  105. if ($i>15){
  106. $i = 0;
  107. echo $TableHeader;
  108. }
  109. }
  110. echo '<tr>
  111. <td colspan="2" class="number"><font size="4" color="blue">' . _('Total') . ':</font></td>
  112. <td class="number"><font size="2" color="navy"><u>' . locale_number_format($TotalGLValue,$_SESSION['SuppTrans']->CurrDecimalPlaces) . '</u></font></td>
  113. </tr>
  114. </table>';
  115. if ($_SESSION['SuppTrans']->InvoiceOrCredit == 'Invoice'){
  116. echo '<br />
  117. <div class="centre">
  118. <a href="' . $rootpath . '/SupplierInvoice.php">' . _('Back to Invoice Entry') . '</a>
  119. </div>';
  120. } else {
  121. echo '<br />
  122. <div class="centre">
  123. <a href="' . $rootpath . '/SupplierCredit.php">' . _('Back to Credit Note Entry') . '</a>
  124. </div>';
  125. }
  126. /*Set up a form to allow input of new GL entries */
  127. echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF']) . '" method="post">';
  128. echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
  129. echo '<br />
  130. <table class="selection">';
  131. if (!isset($_POST['GLCode'])) {
  132. $_POST['GLCode']='';
  133. }
  134. echo '<tr>
  135. <td>' . _('Account Code') . ':</td>
  136. <td><input type="text" name="GLCode" size="12" maxlength="11" value="' . $_POST['GLCode'] . '" /></td>
  137. <input type="hidden" name="JobRef" value="" />
  138. </tr>';
  139. echo '<tr>
  140. <td>' . _('Account Selection') . ':
  141. <br />(' . _('If you know the code enter it above') . '
  142. <br />' . _('otherwise select the account from the list') . ')</td>
  143. <td><select name="AcctSelection">';
  144. $sql = "SELECT accountcode, accountname FROM chartmaster ORDER BY accountcode";
  145. $result = DB_query($sql, $db);
  146. echo '<option value=""></option>';
  147. while ($myrow = DB_fetch_array($result)) {
  148. if ($myrow['accountcode'] == $_POST['AcctSelection']) {
  149. echo '<option selected value="';
  150. } else {
  151. echo '<option value="';
  152. }
  153. echo $myrow['accountcode'] . '">' . $myrow['accountcode'] . ' - ' . $myrow['accountname'] . '</option>';
  154. }
  155. echo '</select>
  156. </td>
  157. </tr>';
  158. if (!isset($_POST['Amount'])) {
  159. $_POST['Amount']=0;
  160. }
  161. echo '<tr>
  162. <td>' . _('Amount') . ':</td>
  163. <td><input type="text" class="number" name="Amount" size="12" maxlength="11" value="' . locale_number_format($_POST['Amount'],$_SESSION['SuppTrans']->CurrDecimalPlaces) . '" /></td>
  164. </tr>';
  165. if (!isset($_POST['Narrative'])) {
  166. $_POST['Narrative']='';
  167. }
  168. echo '<tr>
  169. <td>' . _('Narrative') . ':</td>
  170. <td><textarea name="Narrative" cols=40 rows=2>' . $_POST['Narrative'] . '</textarea></td>
  171. </tr>
  172. </table>
  173. <br />';
  174. echo '<div class="centre">
  175. <input type="submit" name="AddGLCodeToTrans" value="' . _('Enter GL Line') . '" />
  176. </div>';
  177. echo '</form>';
  178. include('includes/footer.inc');
  179. ?>