invoices.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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-2018
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('invoice_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //additional includes
  34. require_once "resources/header.php";
  35. require_once "resources/paging.php";
  36. //add multi-lingual support
  37. $language = new text;
  38. $text = $language->get();
  39. //get variables used to control the order
  40. $order_by = $_GET["order_by"];
  41. $order = $_GET["order"];
  42. //get the contact id
  43. $contact_uuid = check_str($_REQUEST["id"]);
  44. //show the content
  45. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  46. echo " <tr>\n";
  47. echo " <td width='50%' align='left' valign='top' nowrap='nowrap'><b>".$text['title-invoices']."</b><br><br></td>\n";
  48. echo " <td width='50%' align=\"right\" valign='top'>\n";
  49. if ($contact_uuid != '') {
  50. echo " <input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'>\n";
  51. }
  52. echo " </td>\n";
  53. echo " </tr>\n";
  54. echo "</table>\n";
  55. //prepare to page the results
  56. $sql = "SELECT count(*) as num_rows FROM v_invoices ";
  57. $sql .= "LEFT OUTER JOIN v_contacts ";
  58. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  59. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  60. if (strlen($contact_uuid) > 0) {
  61. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  62. }
  63. $prep_statement = $db->prepare($sql);
  64. if ($prep_statement) {
  65. $prep_statement->execute();
  66. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  67. if ($row['num_rows'] > 0) {
  68. $num_rows = $row['num_rows'];
  69. }
  70. else {
  71. $num_rows = '0';
  72. }
  73. }
  74. //prepare to page the results
  75. $rows_per_page = 150;
  76. $param = "";
  77. $page = $_GET['page'];
  78. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  79. list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
  80. $offset = $rows_per_page * $page;
  81. //get the list
  82. $sql = "SELECT * FROM v_invoices ";
  83. $sql .= "LEFT OUTER JOIN v_contacts ";
  84. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  85. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  86. if (strlen($contact_uuid) > 0) {
  87. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  88. }
  89. if (strlen($order_by) == 0) {
  90. $sql .= "order by v_invoices.invoice_number desc ";
  91. }
  92. else {
  93. $sql .= "order by v_invoices.$order_by $order ";
  94. }
  95. $sql .= "limit $rows_per_page offset $offset ";
  96. $prep_statement = $db->prepare(check_sql($sql));
  97. $prep_statement->execute();
  98. $invoices = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  99. unset ($prep_statement, $sql);
  100. //set the row style
  101. $c = 0;
  102. $row_style["0"] = "row_style0";
  103. $row_style["1"] = "row_style1";
  104. //show the invoices
  105. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  106. echo "<tr>\n";
  107. echo "<th>&nbsp;</th>\n";
  108. echo th_order_by('invoice_number', $text['label-invoice_number'], $order_by, $order);
  109. echo th_order_by('invoice_type', $text['label-invoice_type'], $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 (is_array($invoices)) {
  124. foreach($invoices as $row) {
  125. $back = ($contact_uuid != '') ? "&back=".urlencode("invoices.php?id=".$contact_uuid) : null;
  126. $tr_link = (permission_exists('invoice_edit')) ? "href='invoice_edit.php?contact_uuid=".escape($row['contact_uuid'])."&id=".escape($row['invoice_uuid']).escape($back)."'" : null;
  127. echo "<tr ".$tr_link.">\n";
  128. echo " <td align='center' valign='middle' class='".$row_style[$c]."' style='padding: 0px 0px 0px 5px;'>";
  129. if ($row['invoice_paid'] == 1) {
  130. echo "<img src='paid.png' style='width: 16px; height: 16px; border; none;'>";
  131. }
  132. else {
  133. echo "<img src='unpaid.png' style='width: 16px; height: 16px; border; none;'>";
  134. }
  135. echo " </td>\n";
  136. echo " <td valign='top' class='".$row_style[$c]."'><a href='invoice_edit.php?contact_uuid=".escape($row['contact_uuid'])."&id=".escape($row['invoice_uuid']).escape($back)."' alt='".$text['button-edit']."'>".escape($row['invoice_number'])."</a>&nbsp;</td>\n";
  137. echo " <td valign='top' class='".$row_style[$c]."'>".$text['label-invoice_type_'.escape($row['invoice_type'])]."&nbsp;</td>\n";
  138. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_organization'])."&nbsp;</td>\n";
  139. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_name_given'])."&nbsp;</td>\n";
  140. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['contact_name_family'])."&nbsp;</td>\n";
  141. echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['invoice_date'])."&nbsp;</td>\n";
  142. echo " <td class='list_control_icons'>\n";
  143. if (permission_exists('invoice_edit')) {
  144. echo "<a href='invoice_edit.php?contact_uuid=".escape($row['contact_uuid'])."&id=".escape($row['invoice_uuid']).escape($back)."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  145. }
  146. if (permission_exists('invoice_delete')) {
  147. echo "<a href='invoices_delete.php?contact_uuid=".escape($row['contact_uuid'])."&id=".escape($row['invoice_uuid']).escape($back)."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
  148. }
  149. echo "</td>\n";
  150. echo "</tr>\n";
  151. if ($c==0) { $c=1; } else { $c=0; }
  152. } //end foreach
  153. unset($invoices);
  154. } //end if results
  155. echo "<tr>\n";
  156. echo "<td colspan='10' align='left'>\n";
  157. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  158. echo " <tr>\n";
  159. echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
  160. echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
  161. echo " <td width='33.3%' align='right'>\n";
  162. if (permission_exists('invoice_add')) {
  163. echo " <a href='invoice_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  164. }
  165. else {
  166. echo " &nbsp;\n";
  167. }
  168. echo " </td>\n";
  169. echo " </tr>\n";
  170. echo " </table>\n";
  171. echo "</td>\n";
  172. echo "</tr>\n";
  173. echo "</table>";
  174. echo "<br /><br />";
  175. //include the footer
  176. require_once "resources/footer.php";
  177. ?>