invoices.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. require_once "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('invoice_view')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. require_once "resources/header.php";
  32. require_once "resources/paging.php";
  33. //add multi-lingual support
  34. require_once "app_languages.php";
  35. foreach($text as $key => $value) {
  36. $text[$key] = $value[$_SESSION['domain']['language']['code']];
  37. }
  38. //get variables used to control the order
  39. $order_by = $_GET["order_by"];
  40. $order = $_GET["order"];
  41. //get the contact id
  42. $contact_uuid = check_str($_REQUEST["id"]);
  43. //show the content
  44. echo "<div align='center'>";
  45. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  46. echo "<tr class='border'>\n";
  47. echo " <td align=\"center\">\n";
  48. echo " <br />";
  49. echo "<table width='100%' border='0'>\n";
  50. echo " <tr>\n";
  51. echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-invoices']."</b></td>\n";
  52. echo " <td width='50%' align=\"right\">\n";
  53. echo " <input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'>\n";
  54. echo " </td>\n";
  55. echo " </tr>\n";
  56. echo "</table>\n";
  57. //prepare to page the results
  58. $sql = "SELECT count(*) as num_rows FROM v_invoices ";
  59. $sql .= "LEFT OUTER JOIN v_contacts ";
  60. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  61. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  62. if (strlen($contact_uuid) > 0) {
  63. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  64. }
  65. $prep_statement = $db->prepare($sql);
  66. if ($prep_statement) {
  67. $prep_statement->execute();
  68. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  69. if ($row['num_rows'] > 0) {
  70. $num_rows = $row['num_rows'];
  71. }
  72. else {
  73. $num_rows = '0';
  74. }
  75. }
  76. //prepare to page the results
  77. $rows_per_page = 150;
  78. $param = "";
  79. $page = $_GET['page'];
  80. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  81. list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
  82. $offset = $rows_per_page * $page;
  83. //get the list
  84. $sql = "SELECT * FROM v_invoices ";
  85. $sql .= "LEFT OUTER JOIN v_contacts ";
  86. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  87. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  88. if (strlen($contact_uuid) > 0) {
  89. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  90. }
  91. if (strlen($order_by) == 0) {
  92. $sql .= "order by v_invoices.invoice_number asc ";
  93. }
  94. else {
  95. $sql .= "order by v_invoices.$order_by $order ";
  96. }
  97. $sql .= "limit $rows_per_page offset $offset ";
  98. $prep_statement = $db->prepare(check_sql($sql));
  99. $prep_statement->execute();
  100. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  101. $result_count = count($result);
  102. unset ($prep_statement, $sql);
  103. $c = 0;
  104. $row_style["0"] = "row_style0";
  105. $row_style["1"] = "row_style1";
  106. echo "<div align='center'>\n";
  107. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  108. echo "<tr>\n";
  109. echo th_order_by('invoice_number', $text['label-invoice_number'], $order_by, $order);
  110. echo th_order_by('contact_organization', $text['label-contact_to_organization'], $order_by, $order);
  111. echo th_order_by('contact_name_given', $text['label-contact_to_given_name'], $order_by, $order);
  112. echo th_order_by('contact_name_family', $text['label-contact_to_family_name'], $order_by, $order);
  113. echo th_order_by('invoice_date', $text['label-invoice_date'], $order_by, $order);
  114. echo "<td align='right' width='42'>\n";
  115. if (permission_exists('invoice_add')) {
  116. echo " <a href='invoice_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  117. }
  118. else {
  119. echo " &nbsp;\n";
  120. }
  121. echo "</td>\n";
  122. echo "<tr>\n";
  123. if ($result_count > 0) {
  124. foreach($result as $row) {
  125. echo "<tr >\n";
  126. echo " <td valign='top' class='".$row_style[$c]."'>".$row['invoice_number']."&nbsp;</td>\n";
  127. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_organization']."&nbsp;</td>\n";
  128. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_name_given']."&nbsp;</td>\n";
  129. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_name_family']."&nbsp;</td>\n";
  130. echo " <td valign='top' class='".$row_style[$c]."'>".$row['invoice_date']."&nbsp;</td>\n";
  131. echo " <td valign='top' align='right'>\n";
  132. if (permission_exists('invoice_edit')) {
  133. echo " <a href='invoice_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
  134. }
  135. if (permission_exists('invoice_delete')) {
  136. echo " <a href='invoices_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n";
  137. }
  138. echo " </td>\n";
  139. echo "</tr>\n";
  140. if ($c==0) { $c=1; } else { $c=0; }
  141. } //end foreach
  142. unset($sql, $result, $row_count);
  143. } //end if results
  144. echo "<tr>\n";
  145. echo "<td colspan='8' align='left'>\n";
  146. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  147. echo " <tr>\n";
  148. echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
  149. echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
  150. echo " <td width='33.3%' align='right'>\n";
  151. if (permission_exists('invoice_add')) {
  152. echo " <a href='invoice_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  153. }
  154. else {
  155. echo " &nbsp;\n";
  156. }
  157. echo " </td>\n";
  158. echo " </tr>\n";
  159. echo " </table>\n";
  160. echo "</td>\n";
  161. echo "</tr>\n";
  162. echo "</table>";
  163. echo "</div>";
  164. echo "<br /><br />";
  165. echo "</td>";
  166. echo "</tr>";
  167. echo "</table>";
  168. echo "</div>";
  169. echo "<br /><br />";
  170. //include the footer
  171. require_once "resources/footer.php";
  172. ?>