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