@ -22,12 +22,22 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
$items = [];
$payments = [];
$editing = false;
$returning = false;
if (isset($VARS['txid']) & & $database->has('transactions', ['txid' => $VARS['txid']])) {
$editing = true;
$items = $database->select('lines', ['lineid', 'amount', 'name', 'itemid', 'qty'], ['txid' => $VARS['txid']]);
$payments = $database->select('payments', ['[>]certificates' => 'certid', '[>]payment_types' => ['type' => 'typeid']], ['payments.amount', 'typename', 'icon', 'text', 'certcode'], ['txid' => $VARS['txid']]);
$tx = $database->get('transactions', ['[>]customers' => 'customerid'], ['txid', 'discountpercent', 'transactions.customerid', 'customers.name (customername)'], ['txid' => $VARS['txid']]);
echo "< input type = \"hidden\" id = \"txid\" value = \"$VARS[txid]\" > ";
$tx = $database->get('transactions', ['[>]customers' => 'customerid'], ['txid', 'discountpercent', 'transactions.customerid', 'customers.name (customername)', 'cashid', 'type'], ['txid' => $VARS['txid']]);
if ($tx['type'] != 1) {
header('Location: app.php?page=pos&msg=return_transaction_no_edit');
die();
}
$items = $database->select('lines', ['lineid', 'amount', 'name', 'itemid', 'qty'], ['txid' => $tx['txid']]);
if ($database->has('cash_drawer', ['AND' => ['cashid' => $tx['cashid'], 'open[!]' => null, 'close' => null]])) {
$editing = true;
$payments = $database->select('payments', ['[>]certificates' => 'certid', '[>]payment_types' => ['type' => 'typeid']], ['payments.amount', 'typename', 'icon', 'text', 'certcode'], ['txid' => $tx['txid']]);
echo "< input type = \"hidden\" id = \"txid\" value = \"$tx[txid]\" > ";
} else {
$returning = true;
echo "< input type = \"hidden\" id = \"return\" value = \"1\" > ";
}
}
?>
< div class = "modal fade" tabindex = "-1" role = "dialog" id = "receiptmodal" >
@ -40,11 +50,11 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< / button >
< / div >
< div class = "modal-body" >
< div class = "display-4 text-center" > <?php lang ( "change" ); ?> : $< span id = "receiptchange" > 0.00</ span ></ div >
< div class = "display-4 text-center" id = "receiptchangediv" > <?php lang ( "change" ); ?> : $< span id = "receiptchange" > 0.00</ span ></ div >
< iframe class = "w-100 shadow-lg" id = "receiptframe" > < / iframe >
< / div >
< div class = "modal-footer" >
< button type = "button" class = "btn btn-secondary" data-dismiss = "modal" > <?php lang ( " new sal e"); ?> </ button >
< button type = "button" class = "btn btn-secondary" data-dismiss = "modal" > <?php lang ( " clos e"); ?> </ button >
< button type = "button" class = "btn btn-primary" id = "receiptprintbtn" >< i class = "fas fa-print" ></ i > <?php lang ( "print" ); ?> </ button >
< / div >
< / div >
@ -141,13 +151,20 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< div class = "list-group list-group-flush" id = "pos-lines-box" >
<?php
foreach ($items as $i) {
$linetotal = $i['amount'] * $i['qty'];
$amount = $i['amount'];
// Include percentage discount for returns
if ($returning) {
$linetotal *= 1.0 - ($tx['discountpercent'] / 100.0);
$amount *= 1.0 - ($tx['discountpercent'] / 100);
}
?>
< div class = "list-group-item" data-itemid = " <?php echo $i [ 'itemid' ]; ?> " >
< div class = "d-flex w-100 justify-content-between mb-2" >
< h5 class = "item-name" > <?php echo $i [ 'name' ]; ?> </ h5 >
< h5 >
< span class = "badge badge-light" >
$< span class = "line-total" > <?php echo number_format ( $i [ 'amount' ] * $i [ 'qty' ], 2 ); ?> </ span >
$< span class = "line-total" > <?php echo number_format ( $ linetotal , 2 ); ?> </ span >
< / span >
< / h5 >
< / div >
@ -156,7 +173,7 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< div class = "input-group-prepend" >
< span class = "input-group-text pr-1" > < b > $< / b > < / span >
< / div >
< input type = "money" class = "form-control item-price" value = " <?php echo number_format ( $ i[ ' amount' ] , 2 ); ?> " />
< input type = "money" class = "form-control item-price" value = " <?php echo number_format ( $ amount , 2 ); ?> " />
< div class = "input-group-prepend" >
< span class = "input-group-text px-2" > < i class = "fas fa-times" > < / i > < / span >
< button class = "btn btn-red qty-minus" type = "button" >< i class = "fas <?php
@ -199,31 +216,47 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
?>< / span >
< span class = "sr-only" > <?php lang ( "customer" ); ?> </ span >
< / div >
< div class = "btn m-1" id = "discountpercentbtn" data-percent = " <?php
if ($editing & & isset($tx['discountpercent']) & & $tx['discountpercent'] != 0) {
echo (float) $tx['discountpercent'];
} else {
echo "0";
<?php
if (!$returning) {
?>
< div class = "btn m-1" id = "discountpercentbtn" data-percent = " <?php
if ($editing & & isset($tx['discountpercent']) & & $tx['discountpercent'] != 0) {
echo (float) $tx['discountpercent'];
} else {
echo "0";
}
?>">
< span id = "discountpercentbtnlabel" > <?php
if ($editing & & isset($tx['discountpercent']) & & $tx['discountpercent'] != 0) {
echo (float) $tx['discountpercent'];
}
?>< / span >
< i class = "fas fa-percent" > < / i >
< span class = "sr-only" > <?php lang ( "transaction discount" ); ?> </ span >
< / div >
<?php
}
?>">
< span id = "discountpercentbtnlabel" > <?php
if ($editing & & isset($tx['discountpercent']) & & $tx['discountpercent'] != 0) {
echo (float) $tx['discountpercent'];
}
?>< / span >
< i class = "fas fa-percent" > < / i >
< span class = "sr-only" > <?php lang ( "transaction discount" ); ?> </ span >
< / div >
?>
< / div >
< div class = "card-body" >
< span class = "btn btn-green btn-lg btn-block" id = "paymentbtn" >< i class = "fas fa-money-bill-wave" ></ i > <?php lang ( "enter payment" ); ?> </ span >
< span class = "btn btn-green btn-lg btn-block" id = "paymentbtn" >< i class = "fas fa-money-bill-wave" ></ i > <?php
if ($returning) {
lang("enter refund");
} else {
lang("enter payment");
}
?>< / span >
< / div >
< div class = "d-none" id = "paymentui" >
< div class = "card-body" >
< div class = "d-flex justify-content-around flex-wrap" >
<?php
$payment_methods = $database->select('payment_types', ['typeid (id)', 'typename (name)', 'icon', 'text']);
$hideforreturns = ['check', 'free'];
foreach ($payment_methods as $data) {
if ($returning & & in_array($data['name'], $hideforreturns)) {
continue;
}
?>
< div class = "card p-2 text-center m-1 payment-method-button" data-payment-method = " <?php echo $data [ 'name' ]; ?> " data-icon = " <?php echo $data [ 'icon' ]; ?> " data-text = " <?php lang ( $data [ 'text' ]); ?> " >
< i class = " <?php echo $data [ 'icon' ]; ?> fa-3x fa-fw" ></ i >
@ -236,57 +269,77 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< / div >
< hr / >
< div class = "row px-2 mb-3 text-center" >
< div class = "col-12 col-sm-4" >
<?php lang ( "paid" ); ?> $< span id = "paid-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "owed" ); ?> $< span id = "owed-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "change" ); ?> $< span id = "change-amount" > 0.00</ span >
< / div >
<?php
if ($returning) {
?>
< div class = "col-12 col-sm-4" >
<?php lang ( "refund" ); ?> $< span id = "paid-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "owed" ); ?> $< span id = "owed-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "change" ); ?> $< span id = "change-amount" > 0.00</ span >
< / div >
<?php
} else {
?>
< div class = "col-12 col-sm-4" >
<?php lang ( "paid" ); ?> $< span id = "paid-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "owed" ); ?> $< span id = "owed-amount" > 0.00</ span >
< / div >
< div class = "col-12 col-sm-4" >
<?php lang ( "change" ); ?> $< span id = "change-amount" > 0.00</ span >
< / div >
<?php
}
?>
< / div >
< div class = "list-group list-group-flush" id = "payment-lines" >
<?php
foreach ($payments as $p) {
if ($p['amount'] < = 0) {
continue;
}
?>
< div class = "list-group-item" >
< div class = "input-group" >
< div class = "input-group-prepend" >
< span class = "input-group-text" >
< i class = " <?php echo $p [ 'icon' ]; ?> fa-fw mr-1" ></ i >
<?php lang ( $p [ 'text' ]); ?>
< / span >
< / div >
< div class = "input-group-prepend" >
< span class = "input-group-text" >
$
< / span >
< / div >
< input class = "form-control payment-entry" type = "money" data-type = " <?php echo $p [ 'typename' ]; ?> " value = " <?php echo number_format ( $p [ 'amount' ], 2 ); ?> " />
<?php
if ($p['typename'] == 'giftcard') {
?>
< div class = "input-group-prepend input-group-append" >
if ($editing) {
foreach ($payments as $p) {
if ($p['amount'] < = 0) {
continue;
}
?>
< div class = "list-group-item" >
< div class = "input-group" >
< div class = "input-group-prepend" >
< span class = "input-group-text" >
< i class = " <?php echo $p [ 'icon' ]; ?> fa-fw mr-1" ></ i >
<?php lang ( $p [ 'text' ]); ?>
< / span >
< / div >
< div class = "input-group-prepend" >
< span class = "input-group-text" >
#
$
< / span >
< / div >
< input class = "form-control giftcard-number" type = "number" value = " <?php echo $p [ 'certcode' ] ; ?> " />
< input class = "form-control payment-entry" type = "money" data-type = " <?php echo $p [ 'typename' ]; ?> " value = " <?php echo number_format ( $p [ 'amount' ], 2 ); ?> " />
<?php
}
?>
< div class = "input-group-append" >
< span class = "btn btn-outline-danger remove-payment-btn" >
< i class = "fas fa-trash" > < / i >
< / span >
if ($p['typename'] == 'giftcard') {
?>
< div class = "input-group-prepend input-group-append" >
< span class = "input-group-text" >
#
< / span >
< / div >
< input class = "form-control giftcard-number" type = "number" value = " <?php echo $p [ 'certcode' ]; ?> " />
<?php
}
?>
< div class = "input-group-append" >
< span class = "btn btn-outline-danger remove-payment-btn" >
< i class = "fas fa-trash" > < / i >
< / span >
< / div >
< / div >
< / div >
< / div >
<?php
<?php
}
}
?>
<!-- Payments go here -->
@ -296,6 +349,8 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< span class = "btn btn-green btn-lg btn-block" id = "finishbtn" >< i class = "fas fa-receipt" ></ i > <?php
if ($editing) {
lang("update");
} else if ($returning) {
lang("return");
} else {
lang("finish");
}
@ -306,7 +361,7 @@ if (isset($_GET['switch']) || !isset($_SESSION['register']) || !$registeropen) {
< / div >
< / div >
< script nonce = " <?php echo $SECURE_NONCE ; ?> " >
var showgridbydefault = <?php echo $showgridbydefault === true && $editing !== true ? "true" : "false" ?> ;
var showgridbydefault = <?php echo $showgridbydefault === true && $editing !== true && $returning !== true ? "true" : "false" ?> ;
< / script >
<?php
}