PageRenderTime 62ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/bms/include/aritems.php

https://gitlab.com/nexxuz/phpBMS
PHP | 268 lines | 160 code | 67 blank | 41 comment | 22 complexity | 378c3e2375267e858a060e4e38d2cb41 MD5 | raw file
  1. <?php
  2. /*
  3. $Rev: 285 $ | $LastChangedBy: brieb $
  4. $LastChangedDate: 2007-08-27 14:05:27 -0600 (Mon, 27 Aug 2007) $
  5. +-------------------------------------------------------------------------+
  6. | Copyright (c) 2004 - 2010, Kreotek LLC |
  7. | All rights reserved. |
  8. +-------------------------------------------------------------------------+
  9. | |
  10. | Redistribution and use in source and binary forms, with or without |
  11. | modification, are permitted provided that the following conditions are |
  12. | met: |
  13. | |
  14. | - Redistributions of source code must retain the above copyright |
  15. | notice, this list of conditions and the following disclaimer. |
  16. | |
  17. | - Redistributions in binary form must reproduce the above copyright |
  18. | notice, this list of conditions and the following disclaimer in the |
  19. | documentation and/or other materials provided with the distribution. |
  20. | |
  21. | - Neither the name of Kreotek LLC nor the names of its contributore may |
  22. | be used to endorse or promote products derived from this software |
  23. | without specific prior written permission. |
  24. | |
  25. | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
  26. | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
  27. | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
  28. | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
  29. | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  30. | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
  31. | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  32. | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  33. | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
  34. | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  35. | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
  36. | |
  37. +-------------------------------------------------------------------------+
  38. */
  39. if(class_exists("phpbmsTable")){
  40. class aritems extends phpbmsTable{
  41. function getRecord($id, $useUuid = false){
  42. $therecord = parent::getRecord($id, $useUuid);
  43. /**
  44. * If type is credit, get the receipt id
  45. * else get the invoice id
  46. */
  47. if($therecord["type"] == "credit")
  48. $therecord["editrelatedid"] = getId($this->db, "tbld:43678406-be25-909b-c715-7e2afc7db601", $therecord["relatedid"]);
  49. else
  50. $therecord["editrelatedid"] = getId($this->db, "tbld:62fe599d-c18f-3674-9e54-b62c2d6b1883", $therecord["relatedid"]);
  51. return $therecord;
  52. }//end function --getRecord--
  53. }//end class
  54. }//end if
  55. class relatedClient{
  56. var $clientid = "";
  57. function relatedClient($db, $clientid){
  58. $this->db = $db;
  59. $this->clientid = $clientid;
  60. }//end method
  61. function getClientInfo(){
  62. $querystatement = "
  63. SELECT
  64. `id`,
  65. `firstname`,
  66. `lastname`,
  67. `company`
  68. FROM
  69. `clients`
  70. WHERE
  71. `uuid`='".$this->clientid."'
  72. ";
  73. $queryresult = $this->db->query($querystatement);
  74. $therecord = $this->db->fetchArray($queryresult);
  75. $thename = "";
  76. if($therecord["lastname"]){
  77. $thename = $therecord["lastname"];
  78. if($therecord["firstname"])
  79. $thename .= ", ".$therecord["firstname"];
  80. if($therecord["company"])
  81. $thename .= " (".$therecord["company"].")";
  82. } else
  83. $thename = $therecord["company"];
  84. $thereturn["name"] = $thename;
  85. $thereturn["id"] = $therecord["id"];
  86. return $thereturn;
  87. }//end method
  88. }//end class
  89. class aritemPayments{
  90. function aritemPayments($db, $aritem){
  91. $this->db = $db;
  92. $this->aritem = $aritem;
  93. $this->_get();
  94. }//end method
  95. function _get(){
  96. $querystatement = "
  97. SELECT
  98. receiptitems.applied,
  99. receiptitems.discount,
  100. receiptitems.taxadjustment,
  101. receipts.id,
  102. receipts.receiptdate,
  103. receipts.posted,
  104. paymentmethods.name,
  105. receipts.status
  106. FROM
  107. (receiptitems INNER JOIN receipts ON receiptitems.receiptid = receipts.uuid)
  108. LEFT JOIN paymentmethods ON receipts.paymentmethodid = paymentmethods.uuid
  109. WHERE
  110. receiptitems.aritemid = '".mysql_real_escape_string($this->aritem["uuid"])."'
  111. ";
  112. if($this->aritem["type"] == "credit")
  113. $querystatement.="
  114. AND receipts.uuid != '".mysql_real_escape_string($this->aritem["relatedid"])."'";
  115. $querystatement.=
  116. "
  117. ORDER BY
  118. receipts.posted,
  119. receipts.receiptdate,
  120. receipts.id";
  121. $this->queryresult = $this->db->query($querystatement);
  122. $querystatement = "
  123. SELECT
  124. SUM(receiptitems.applied) AS applied,
  125. SUM(receiptitems.discount) AS discount,
  126. SUM(receiptitems.taxadjustment) AS taxadjustment
  127. FROM
  128. receiptitems
  129. WHERE
  130. receiptitems.aritemid = '".mysql_real_escape_string($this->aritem["uuid"])."'
  131. ";
  132. $totalresult = $this->db->query($querystatement);
  133. $this->totals = $this->db->fetchArray($totalresult);
  134. if($this->aritem["type"] == "credit")
  135. $this->totals["applied"] = $this->totals["applied"] + $this->aritem["amount"];
  136. }//end method
  137. function show(){
  138. ?><table border="0" cellpadding="0" cellspacing="0" class="querytable" id="paymentTable">
  139. <thead>
  140. <tr>
  141. <th align="left">status</th>
  142. <th align="left" nowrap="nowrap">receipt id</th>
  143. <th align="left">date</th>
  144. <th align="right" width="100%">payment</th>
  145. <th align="right">applied</th>
  146. <th align="right">discount</th>
  147. <th align="right" nowrap="nowrap">tax adj.</th>
  148. </tr>
  149. </thead>
  150. <tfoot>
  151. <tr class="queryfooter">
  152. <td colspan="4" align="right">total: <strong><?php echo formatVariable($this->totals["applied"] + $this->totals["discount"] + $this->totals["taxadjustment"], "currency")?></strong> </td>
  153. <td align="right"><?php echo formatVariable($this->totals["applied"],"currency")?></td>
  154. <td align="right"><?php echo formatVariable($this->totals["discount"],"currency")?></td>
  155. <td align="right"><?php echo formatVariable($this->totals["taxadjustment"],"currency")?></td>
  156. </tr>
  157. </tfoot>
  158. <tbody>
  159. <?php
  160. if($this->db->numRows($this->queryresult)){
  161. $postedGroup = "";
  162. $row = 1;
  163. while($therecord = $this->db->fetchArray($this->queryresult)) {
  164. $row = ($row ==1)?2:1;
  165. if($postedGroup != $therecord["posted"]){
  166. $postedGroup = $therecord["posted"];
  167. $title = ($therecord["posted"] == 1)? "Posted Payments" : "Pending Payments (non-posted)";
  168. ?><tr class="queryGroup">
  169. <td colspan="7"><?php echo $title?></td>
  170. </tr><?php
  171. }//end if
  172. if(!$therecord["name"])
  173. $therecord["name"] = "other";
  174. if($therecord["id"] == $this->aritem["relatedid"] && $this->aritem["type"] == "credit")
  175. $therecord["applied"] = -1 * $therecord["applied"];
  176. ?><tr class="row<?php echo $row?>">
  177. <td><?php echo $therecord["status"]?></td>
  178. <td><?php echo $therecord["id"]?></td>
  179. <td><?php echo formatFromSQLDate($therecord["receiptdate"])?></td>
  180. <td align="right"><?php echo $therecord["name"]?></td>
  181. <td align="right"><?php echo formatVariable($therecord["applied"],"currency")?></td>
  182. <td align="right"><?php echo formatVariable($therecord["discount"],"currency")?></td>
  183. <td align="right"><?php echo formatVariable($therecord["taxadjustment"],"currency")?></td>
  184. </tr><?php
  185. }//end while
  186. } else {
  187. ?><tr class="norecords"><td colspan="7" >No payments recorded</td></tr><?php
  188. }//endif
  189. ?>
  190. </tbody>
  191. </table><?php
  192. }//end method
  193. }//end class
  194. if(class_exists("searchFunctions")){
  195. class aritemsSearchFunctions extends searchFunctions{
  196. function run_aging(){
  197. goURL("modules/bms/aritems_aging.php");
  198. }//end method
  199. }//end class
  200. }//end if
  201. ?>