invoices.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. $language = new text;
  35. $text = $language->get();
  36. //get variables used to control the order
  37. $order_by = $_GET["order_by"];
  38. $order = $_GET["order"];
  39. //get the contact id
  40. $contact_uuid = check_str($_REQUEST["id"]);
  41. //show the content
  42. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  43. echo " <tr>\n";
  44. echo " <td width='50%' align='left' valign='top' nowrap='nowrap'><b>".$text['title-invoices']."</b><br><br></td>\n";
  45. echo " <td width='50%' align=\"right\" valign='top'>\n";
  46. if ($contact_uuid != '') {
  47. echo " <input type='button' class='btn' name='' alt='back' onclick=\"history.go(-1);\" value='Back'>\n";
  48. }
  49. echo " </td>\n";
  50. echo " </tr>\n";
  51. echo "</table>\n";
  52. //prepare to page the results
  53. $sql = "SELECT count(*) as num_rows FROM v_invoices ";
  54. $sql .= "LEFT OUTER JOIN v_contacts ";
  55. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  56. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  57. if (strlen($contact_uuid) > 0) {
  58. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  59. }
  60. $prep_statement = $db->prepare($sql);
  61. if ($prep_statement) {
  62. $prep_statement->execute();
  63. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  64. if ($row['num_rows'] > 0) {
  65. $num_rows = $row['num_rows'];
  66. }
  67. else {
  68. $num_rows = '0';
  69. }
  70. }
  71. //prepare to page the results
  72. $rows_per_page = 150;
  73. $param = "";
  74. $page = $_GET['page'];
  75. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  76. list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
  77. $offset = $rows_per_page * $page;
  78. //get the list
  79. $sql = "SELECT * FROM v_invoices ";
  80. $sql .= "LEFT OUTER JOIN v_contacts ";
  81. $sql .= "ON v_invoices.contact_uuid_to = v_contacts.contact_uuid ";
  82. $sql .= "where v_invoices.domain_uuid = '$domain_uuid' ";
  83. if (strlen($contact_uuid) > 0) {
  84. $sql .= "and v_invoices.contact_uuid_to = '$contact_uuid' ";
  85. }
  86. if (strlen($order_by) == 0) {
  87. $sql .= "order by v_invoices.invoice_number asc ";
  88. }
  89. else {
  90. $sql .= "order by v_invoices.$order_by $order ";
  91. }
  92. $sql .= "limit $rows_per_page offset $offset ";
  93. $prep_statement = $db->prepare(check_sql($sql));
  94. $prep_statement->execute();
  95. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  96. $result_count = count($result);
  97. unset ($prep_statement, $sql);
  98. $c = 0;
  99. $row_style["0"] = "row_style0";
  100. $row_style["1"] = "row_style1";
  101. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  102. echo "<tr>\n";
  103. echo "<th>&nbsp;</th>\n";
  104. echo th_order_by('invoice_number', $text['label-invoice_number'], $order_by, $order);
  105. echo th_order_by('invoice_type', $text['label-invoice_type'], $order_by, $order);
  106. echo th_order_by('contact_organization', $text['label-contact_to_organization'], $order_by, $order);
  107. echo th_order_by('contact_name_given', $text['label-contact_to_given_name'], $order_by, $order);
  108. echo th_order_by('contact_name_family', $text['label-contact_to_family_name'], $order_by, $order);
  109. echo th_order_by('invoice_date', $text['label-invoice_date'], $order_by, $order);
  110. echo "<td align='right' width='42'>\n";
  111. if (permission_exists('invoice_add')) {
  112. echo " <a href='invoice_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  113. }
  114. else {
  115. echo " &nbsp;\n";
  116. }
  117. echo "</td>\n";
  118. echo "<tr>\n";
  119. if ($result_count > 0) {
  120. foreach($result as $row) {
  121. $back = ($contact_uuid != '') ? "&back=".urlencode("invoices.php?id=".$contact_uuid) : null;
  122. $tr_link = (permission_exists('invoice_edit')) ? "href='invoice_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid'].$back."'" : null;
  123. echo "<tr ".$tr_link.">\n";
  124. echo " <td align='center' valign='middle' class='".$row_style[$c]."' style='padding: 0px 0px 0px 5px;'>";
  125. if ($row['invoice_paid'] == 1) {
  126. echo "<img src='paid.png' style='width: 16px; height: 16px; border; none;'>";
  127. }
  128. else {
  129. echo "<img src='unpaid.png' style='width: 16px; height: 16px; border; none;'>";
  130. }
  131. echo " </td>\n";
  132. echo " <td valign='top' class='".$row_style[$c]."'><a href='invoice_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid'].$back."' alt='".$text['button-edit']."'>".$row['invoice_number']."</a>&nbsp;</td>\n";
  133. echo " <td valign='top' class='".$row_style[$c]."'>".$text['label-invoice_type_'.$row['invoice_type']]."&nbsp;</td>\n";
  134. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_organization']."&nbsp;</td>\n";
  135. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_name_given']."&nbsp;</td>\n";
  136. echo " <td valign='top' class='".$row_style[$c]."'>".$row['contact_name_family']."&nbsp;</td>\n";
  137. echo " <td valign='top' class='".$row_style[$c]."'>".$row['invoice_date']."&nbsp;</td>\n";
  138. echo " <td class='list_control_icons'>\n";
  139. if (permission_exists('invoice_edit')) {
  140. echo "<a href='invoice_edit.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid'].$back."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  141. }
  142. if (permission_exists('invoice_delete')) {
  143. echo "<a href='invoices_delete.php?contact_uuid=".$row['contact_uuid']."&id=".$row['invoice_uuid'].$back."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
  144. }
  145. echo "</td>\n";
  146. echo "</tr>\n";
  147. if ($c==0) { $c=1; } else { $c=0; }
  148. } //end foreach
  149. unset($sql, $result, $row_count);
  150. } //end if results
  151. echo "<tr>\n";
  152. echo "<td colspan='10' align='left'>\n";
  153. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  154. echo " <tr>\n";
  155. echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
  156. echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
  157. echo " <td width='33.3%' align='right'>\n";
  158. if (permission_exists('invoice_add')) {
  159. echo " <a href='invoice_edit.php?contact_uuid=".$_GET['id']."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  160. }
  161. else {
  162. echo " &nbsp;\n";
  163. }
  164. echo " </td>\n";
  165. echo " </tr>\n";
  166. echo " </table>\n";
  167. echo "</td>\n";
  168. echo "</tr>\n";
  169. echo "</table>";
  170. echo "<br /><br />";
  171. //include the footer
  172. require_once "resources/footer.php";
  173. ?>