|
|
@ -37,6 +37,7 @@ switch ($VARS['action']) {
|
|
|
|
$payments = $VARS['payments'];
|
|
|
|
$payments = $VARS['payments'];
|
|
|
|
$customer = $VARS['customer'];
|
|
|
|
$customer = $VARS['customer'];
|
|
|
|
$register = $VARS['register'];
|
|
|
|
$register = $VARS['register'];
|
|
|
|
|
|
|
|
$discountpercent = $VARS['discountpercent'];
|
|
|
|
|
|
|
|
|
|
|
|
if ($customer != "" && !$database->has('customers', ['customerid' => $customer])) {
|
|
|
|
if ($customer != "" && !$database->has('customers', ['customerid' => $customer])) {
|
|
|
|
exit(json_encode(["status" => "ERROR", "message" => lang("invalid customer", false)]));
|
|
|
|
exit(json_encode(["status" => "ERROR", "message" => lang("invalid customer", false)]));
|
|
|
@ -69,6 +70,13 @@ switch ($VARS['action']) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (is_numeric($discountpercent) && $discountpercent > 0 && $discountpercent < 100) {
|
|
|
|
|
|
|
|
$discountpercent = $discountpercent * 1.0;
|
|
|
|
|
|
|
|
$totalcharge *= 1.0 - ($discountpercent / 100.0);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$discountpercent = 0.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($totalcharge > $totalpaid) {
|
|
|
|
if ($totalcharge > $totalpaid) {
|
|
|
|
exit(json_encode(["status" => "ERROR", "message" => lang("insufficient payment", false)]));
|
|
|
|
exit(json_encode(["status" => "ERROR", "message" => lang("insufficient payment", false)]));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,7 +91,8 @@ switch ($VARS['action']) {
|
|
|
|
'customerid' => ($customer != "" ? $customer : null),
|
|
|
|
'customerid' => ($customer != "" ? $customer : null),
|
|
|
|
'type' => 1,
|
|
|
|
'type' => 1,
|
|
|
|
'cashier' => $_SESSION['uid'],
|
|
|
|
'cashier' => $_SESSION['uid'],
|
|
|
|
'cashid' => $cashid
|
|
|
|
'cashid' => $cashid,
|
|
|
|
|
|
|
|
'discountpercent' => $discountpercent
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
$txid = $database->id();
|
|
|
|
$txid = $database->id();
|
|
|
|
|
|
|
|
|
|
|
@ -128,7 +137,7 @@ switch ($VARS['action']) {
|
|
|
|
exit(json_encode(["status" => "ERROR", "txid" => null]));
|
|
|
|
exit(json_encode(["status" => "ERROR", "txid" => null]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$tx = $database->get('transactions', ['txid', 'txdate', 'customerid', 'type', 'cashier'], ['txid' => $VARS['txid']]);
|
|
|
|
$tx = $database->get('transactions', ['txid', 'txdate', 'customerid', 'type', 'cashier', 'discountpercent'], ['txid' => $VARS['txid']]);
|
|
|
|
|
|
|
|
|
|
|
|
$txid = $tx['txid'];
|
|
|
|
$txid = $tx['txid'];
|
|
|
|
$datetime = date(DATETIME_FORMAT, strtotime($tx['txdate']));
|
|
|
|
$datetime = date(DATETIME_FORMAT, strtotime($tx['txdate']));
|
|
|
@ -142,7 +151,7 @@ switch ($VARS['action']) {
|
|
|
|
|
|
|
|
|
|
|
|
$itemhtml = "";
|
|
|
|
$itemhtml = "";
|
|
|
|
$items = $database->select('lines', ['amount', 'name', 'itemid', 'qty'], ['txid' => $txid]);
|
|
|
|
$items = $database->select('lines', ['amount', 'name', 'itemid', 'qty'], ['txid' => $txid]);
|
|
|
|
$total = 0.0;
|
|
|
|
$subtotal = 0.0;
|
|
|
|
$paid = 0.0;
|
|
|
|
$paid = 0.0;
|
|
|
|
foreach ($items as $i) {
|
|
|
|
foreach ($items as $i) {
|
|
|
|
$itemhtml .= "\n";
|
|
|
|
$itemhtml .= "\n";
|
|
|
@ -152,9 +161,11 @@ switch ($VARS['action']) {
|
|
|
|
$itemhtml .= '<div>x' . (float) $i['qty'] . '</div>';
|
|
|
|
$itemhtml .= '<div>x' . (float) $i['qty'] . '</div>';
|
|
|
|
$itemhtml .= '<div>$' . number_format($i['qty'] * $i['amount'] * 1.0, 2) . '</div>';
|
|
|
|
$itemhtml .= '<div>$' . number_format($i['qty'] * $i['amount'] * 1.0, 2) . '</div>';
|
|
|
|
$itemhtml .= '</div>';
|
|
|
|
$itemhtml .= '</div>';
|
|
|
|
$total += $i['qty'] * $i['amount'] * 1.0;
|
|
|
|
$subtotal += $i['qty'] * $i['amount'] * 1.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$total = $subtotal * (1.0 - ((float) $tx['discountpercent'] / 100));
|
|
|
|
|
|
|
|
|
|
|
|
$paymenthtml = "";
|
|
|
|
$paymenthtml = "";
|
|
|
|
$payments = $database->select('payments', [
|
|
|
|
$payments = $database->select('payments', [
|
|
|
|
'[>]payment_types' => ['type' => 'typeid']
|
|
|
|
'[>]payment_types' => ['type' => 'typeid']
|
|
|
@ -177,9 +188,15 @@ switch ($VARS['action']) {
|
|
|
|
$change = 0.0;
|
|
|
|
$change = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$totalstr = number_format($total, 2);
|
|
|
|
$subtotalstr = number_format($subtotal, 2);
|
|
|
|
$paidstr = number_format($paid, 2);
|
|
|
|
$paidstr = number_format($paid, 2);
|
|
|
|
$changestr = number_format($change, 2);
|
|
|
|
$changestr = number_format($change, 2);
|
|
|
|
|
|
|
|
$totalstr = $subtotalstr;
|
|
|
|
|
|
|
|
$discountstr = "";
|
|
|
|
|
|
|
|
if ($tx['discountpercent'] > 0) {
|
|
|
|
|
|
|
|
$discountstr = '<div class="flexrow"><span>Discount: </span><span>' . (float) $tx['discountpercent'] . '% off</span></div>';
|
|
|
|
|
|
|
|
$totalstr = number_format($total, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$html = <<<END
|
|
|
|
$html = <<<END
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<!DOCTYPE html>
|
|
|
@ -203,6 +220,8 @@ $customerline
|
|
|
|
$itemhtml
|
|
|
|
$itemhtml
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
|
|
|
|
<div class="flexrow"><span>Subtotal: </span><span>$$subtotalstr</span></div>
|
|
|
|
|
|
|
|
$discountstr
|
|
|
|
<b class="flexrow"><span>Total: </span><span>$$totalstr</span></b>
|
|
|
|
<b class="flexrow"><span>Total: </span><span>$$totalstr</span></b>
|
|
|
|
<hr />
|
|
|
|
<hr />
|
|
|
|
<div id="payments">
|
|
|
|
<div id="payments">
|
|
|
|