forked from frankludriks/ocPOS25-Responsive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.php
211 lines (168 loc) · 8.63 KB
/
action.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<?php
// action.php
include("includes/db.php");
include("includes/functions.php");
include("includes/session.php");
if($_REQUEST['Action']=="SelectOrder" && $_REQUEST['OrderID']) {
header("Location: order.php?OrderID=" . $_REQUEST['OrderID'] . "&PopReceipt=true");
}
if($_REQUEST['Action']=="SelectOrder" && $_REQUEST['OrderIndex'] > -1 && $_REQUEST['OrderIndex']!="xxx") {
if(substr($_REQUEST['OrderIndex'],0,2)=="a_") {
$_REQUEST['OrderIndex'] = str_replace("a_","",$_REQUEST['OrderIndex']);
GetArchivedOrder($_REQUEST['OrderIndex']);
}else{
$_SESSION['CurrentOrderIndex'] = $_REQUEST['OrderIndex'];
}
}
if($_REQUEST['Action']=="ArchiveOrder") {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Archive();
RemoveOrder();
}
if($_REQUEST['Action']=="NewOrder") {
NewOrder($_REQUEST['CustomerID']);
}
if($_REQUEST['Action']=="ItemNewOrder") {
ItemNewOrder($_REQUEST['CustomerID'], $_REQUEST['ProductID']);
}
if($_REQUEST['Action']=="AssignCustomer" && $_REQUEST['CustomerID']) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->AssignCustomer($_REQUEST['CustomerID']);
}
if($_REQUEST['Action']=="RemoveCustomer") {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->CustomerID = NULL;
}
if($_REQUEST['Action']=="RemoveOrder") {
RemoveOrder();
}
if($_REQUEST['Action']=="ReturnOrder") {
NewOrder($_REQUEST['CustomerID']);
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->ReturnOrder = 1;
}
if($_REQUEST['Action']=="ProcessOrder") {
if ($_GET['payment_method']=='Cash') {
$Total = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Total;
if(!$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->TaxExempt) {
$Total += ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Tax);
}
// is this a partial payment (less than order total)
if ( ( ($Total - ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash)) >= 0.0045) // not enough money - using 0.0045 to overcome math rounding problem
|| (!is_numeric($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash)) ) {
//header("Location: checkout.php?Error=Invalid%20Cash%20Amount");
// are there any existing partial payments?
$RemainingTotal = $Total;
if (isset($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments[0]['PaymentMethod'])) {
while(list ($key, $val) = each ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments)) {
$RemainingTotal -= $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments[$key]['PaymentAmount'];
}
}
// if partial payment is insufficient, apply new partial payment
if ($RemainingTotal > $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->ApplySplitPayment('Cash', $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash);
header("Location: checkout.php?split=cash&amount=" . $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash);
exit();
}
}
$CashChange = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Cash - $Total;
$Change = number_format($CashChange,2, '.', '');
}
if ($_GET['payment_method']=='Check') {
$Total = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Total;
if(!$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->TaxExempt) {
$Total += ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Tax);
}
// is this a partial payment (less than order total)
if ( ( ($Total - ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check)) >= 0.0045) // not enough money - using 0.0045 to overcome math rounding problem
|| (!is_numeric($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check)) ) {
//header("Location: checkout.php?Error=Invalid%20Check%20Amount");
// are there any existing partial payments?
$RemainingTotal = $Total;
if (isset($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments[0]['PaymentMethod'])) {
while(list ($key, $val) = each ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments)) {
$RemainingTotal -= $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->SplitPayments[$key]['PaymentAmount'];
}
}
// if partial payment is insufficient, apply new partial payment
if ($RemainingTotal > $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->ApplySplitPayment('Check', $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check);
header("Location: checkout.php?split=check&amount=" . $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check);
exit();
}
}
$CheckChange = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Check - $Total;
$Change = number_format($CheckChange,2, '.', '');
}
if ($_GET['payment_method']=='CreditCard') {
$Total = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Total;
if(!$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->TaxExempt) {
$Total += ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Tax);
}
if (!is_numeric($_GET['ccnum'])) { // check for numeric last 4 digits of cc number
header("Location: checkout.php?Error=Invalid%20Credit%20Card%20Number");
exit();
}
}
if ($_GET['payment_method']=='Authorize.Net AIM') {
/* we do this stuff in the Authorize.Net module
$Total = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Total;
if(!$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->TaxExempt){
$Total += ($_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Tax);
}
*/
}
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->Process($session);
$OrderID = $_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->OrderID;
RemoveOrder();
if ($_GET['payment_method']=='CreditCard') { // if credit card, they don't need any change
header("Location: order.php?OrderID=$OrderID&PopReceipt=True");
exit();
}
header("Location: order.php?OrderID=$OrderID&PopReceipt=True&Change=$Change");
exit();
}
if($_REQUEST['Action']=="TaxExempt") {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->TaxExempt();
}
if($_REQUEST['Action']=="AddItem" && $_REQUEST['ProductQuery'] && $_REQUEST['Quantity']) {
$Q_Product_query = ("SELECT p.products_id FROM
" . PRODUCTS . " p, " . PRODUCTS_DESCRIPTION . " pd WHERE
(p.products_model LIKE '%" . $_REQUEST['ProductQuery'] . "%' OR
pd.products_name LIKE '%" . $_REQUEST['ProductQuery'] . "%') AND
pd.products_id = p.products_id");
if (ALLOW_SOLDOUT_PRODUCTS == '0') {
$Q_Product_query .= " AND p.products_quantity > 0 ";
}
$Q_Product_query .= " GROUP BY p.products_id";
$Q_Product = mysql_query($Q_Product_query);
if(mysql_num_rows($Q_Product)==1) {
$R_Product = mysql_fetch_assoc($Q_Product);
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->AddItem($R_Product['products_id'], $_REQUEST['Quantity'], IN_STORE_PRICING);
}else{
header("Location: product_search.php?Query=" . $_REQUEST['ProductQuery'] . "");
exit();
}
}
if($_REQUEST['Action']=="AddItem" && $_REQUEST['ProductID'] && $_REQUEST['Quantity']) {
$Q_Product_query = ("SELECT products_id FROM " . PRODUCTS . " WHERE products_id = '" . $_REQUEST['ProductID'] . "'");
if (ALLOW_SOLDOUT_PRODUCTS == '0') {
$Q_Product_query .= " AND products_quantity > 0 ";
}
$Q_Product = mysql_query($Q_Product_query);
if(mysql_num_rows($Q_Product)==1) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->AddItem($_REQUEST['ProductID'], $_REQUEST['Quantity'], IN_STORE_PRICING, $_REQUEST['product_stock_attributes']);
}elseif($_REQUEST['ProductID'] > 1000000000) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->AddItem($_REQUEST['ProductID'], $_REQUEST['Quantity'], IN_STORE_PRICING, $_REQUEST['product_stock_attributes']);
}
}
if($_REQUEST['Action']=="RemoveItem" && $_REQUEST['ProductID'] && $_REQUEST['Quantity']) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->RemoveItem($_REQUEST['ProductID'], $_REQUEST['Quantity']);
}
if($_REQUEST['Action']=="AddCartItem" && $_REQUEST['Quantity']) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->AddCartItem($_REQUEST['Index'], $_REQUEST['Quantity']);
}
if($_REQUEST['Action']=="RemoveItem" && $_REQUEST['Quantity']) {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->RemoveItem($_REQUEST['Index'], $_REQUEST['Quantity']);
}
if($_REQUEST['Action']=="DeleteItem") {
$_SESSION['Orders'][$_SESSION['CurrentOrderIndex']]->DeleteItem($_REQUEST['Index']);
}
header("Location: index.php?PHPSESSID=".session_id());
?>