invoice_items.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /* $Id$ */
  3. /*
  4. Copyright (C) 2008-2013 Mark J Crane
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  14. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  15. AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  16. AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
  17. OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  18. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  19. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  20. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  21. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  22. POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. //includes files
  25. require_once dirname(__DIR__, 2) . "/resources/require.php";
  26. require_once "resources/check_auth.php";
  27. //check permissions
  28. if (permission_exists('invoice_item_view')) {
  29. //access granted
  30. }
  31. else {
  32. echo "access denied";
  33. exit;
  34. }
  35. //get variables used to control the order
  36. $order_by = $_GET["order_by"];
  37. $order = $_GET["order"];
  38. //show the content
  39. echo "<table width='100%' cellpadding='0' cellspacing='0' border='0'>\n";
  40. echo " <tr>\n";
  41. echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-invoice_items']."</b><br><br></td>\n";
  42. echo " <td width='50%' align='right'>&nbsp;</td>\n";
  43. echo " </tr>\n";
  44. echo "</table>\n";
  45. //prepare to page the results
  46. $sql = "select count(*) as num_rows from v_invoice_items ";
  47. $sql .= "where domain_uuid = '$domain_uuid' ";
  48. $sql .= " and invoice_uuid = '$invoice_uuid' ";
  49. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  50. $prep_statement = $db->prepare($sql);
  51. if ($prep_statement) {
  52. $prep_statement->execute();
  53. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  54. if ($row['num_rows'] > 0) {
  55. $num_rows = $row['num_rows'];
  56. }
  57. else {
  58. $num_rows = '0';
  59. }
  60. }
  61. //prepare to page the results
  62. $rows_per_page = 10000;
  63. $param = "";
  64. $page = $_GET['page'];
  65. if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
  66. //list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page);
  67. $offset = $rows_per_page * $page;
  68. //get the list
  69. $sql = "select * from v_invoice_items ";
  70. $sql .= "where domain_uuid = '$domain_uuid' ";
  71. $sql .= " and invoice_uuid = '$invoice_uuid' ";
  72. if (strlen($order_by)> 0) { $sql .= "order by $order_by $order "; }
  73. $sql .= "limit $rows_per_page offset $offset ";
  74. $prep_statement = $db->prepare(check_sql($sql));
  75. $prep_statement->execute();
  76. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  77. $result_count = count($result);
  78. unset ($prep_statement, $sql);
  79. //set the row style
  80. $c = 0;
  81. $row_style["0"] = "row_style0";
  82. $row_style["1"] = "row_style1";
  83. //show the items
  84. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  85. echo "<tr>\n";
  86. echo th_order_by('item_qty', $text['label-item_qty'], $order_by, $order);
  87. echo th_order_by('item_unit_price', $text['label-item_unit_price'], $order_by, $order);
  88. echo th_order_by('item_desc', $text['label-item_desc'], $order_by, $order);
  89. echo "<th nowrap='nowrap'>".$text['label-item_amount']."</th>\n";
  90. echo "<td align='right' width='42'>\n";
  91. $back = ($back != '') ? "&back=".$back : null;
  92. if (permission_exists('invoice_item_add')) {
  93. echo " <a href='invoice_item_edit.php?invoice_uuid=".$_GET['id']."&contact_uuid=".escape($contact_uuid_to).escape($back)."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  94. }
  95. else {
  96. echo " &nbsp;\n";
  97. }
  98. echo "</td>\n";
  99. echo "<tr>\n";
  100. if ($result_count > 0) {
  101. foreach($result as $row) {
  102. $item_desc = $row['item_desc'];
  103. $item_desc = str_replace("\n", "<br />", $item_desc);
  104. $tr_link = (permission_exists('invoice_item_edit')) ? "href='invoice_item_edit.php?invoice_uuid=".escape($row['invoice_uuid'])."&id=".escape($row['invoice_item_uuid'])."&contact_uuid=".escape($contact_uuid_to).escape($back)."'" : null;
  105. echo "<tr ".$tr_link.">\n";
  106. echo " <td valign='top' class='".$row_style[$c]."'>".$row['item_qty']."&nbsp;</td>\n";
  107. echo " <td valign='top' class='".$row_style[$c]."'>".number_format($row['item_unit_price'], 2)."&nbsp;</td>\n";
  108. echo " <td valign='top' class='".$row_style[$c]."'>".$item_desc."&nbsp;</td>\n";
  109. echo " <td valign='top' class='".$row_style[$c]."'>".number_format(($row['item_qty'] * $row['item_unit_price']), 2)."&nbsp;</td>\n";
  110. echo " <td class='list_control_icons'>\n";
  111. if (permission_exists('invoice_item_edit')) {
  112. echo "<a href='invoice_item_edit.php?invoice_uuid=".escape($row['invoice_uuid'])."&id=".escape($row['invoice_item_uuid'])."&contact_uuid=".escape($contact_uuid_to).escape($back)."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  113. }
  114. if (permission_exists('invoice_item_delete')) {
  115. echo "<a href='invoice_item_delete.php?invoice_uuid=".escape($row['invoice_uuid'])."&id=".escape($row['invoice_item_uuid'])."&contact_uuid=".escape($contact_uuid_to).escape($back)."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
  116. }
  117. echo " </td>\n";
  118. echo "</tr>\n";
  119. if ($c==0) { $c=1; } else { $c=0; }
  120. } //end foreach
  121. unset($sql, $result, $row_count);
  122. } //end if results
  123. echo "<tr>\n";
  124. echo "<td colspan='6' align='left'>\n";
  125. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  126. echo " <tr>\n";
  127. echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
  128. echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
  129. echo " <td width='33.3%' align='right'>\n";
  130. if (permission_exists('invoice_item_add')) {
  131. echo " <a href='invoice_item_edit.php?invoice_uuid=".$_GET['id']."&contact_uuid=".escape($contact_uuid_to).escape($back)."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  132. }
  133. else {
  134. echo " &nbsp;\n";
  135. }
  136. echo " </td>\n";
  137. echo " </tr>\n";
  138. echo " </table>\n";
  139. echo "</td>\n";
  140. echo "</tr>\n";
  141. echo "</table>";
  142. echo "<br /><br />";
  143. //include the footer
  144. require_once "resources/footer.php";
  145. ?>