invoices.php 7.3 KB

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