Created
November 4, 2010 20:23
-
-
Save jdpurdyvi/663125 to your computer and use it in GitHub Desktop.
Wedge Co-op's upcscanned.php 2010-11-04
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/******************************************************************************* | |
Copyright 2001, 2004 Wedge Community Co-op | |
This file is part of IS4C. | |
IS4C is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
IS4C is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
in the file license.txt along with IS4C; if not, write to the Free Software | |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*********************************************************************************/ | |
require_once("./additem.php"); // addItem(),adddiscount() | |
require_once("./listitems.php"); | |
require_once("./loadProduct.php"); // loadProduct(),getItemQuantity(),makeItemList(),parseUPC() | |
require_once("./maindisplay.php"); // topdisplay() | |
//require_once("./mcoupon.php"); // couponcode() | |
require_once("./refundContactCheck.php"); // refundContactCheck() | |
require_once("./session.php"); // lineFlagReset() | |
require_once("./tender.php"); // ttl() | |
require_once("./couponSpecial.php"); // couponspecial($upc) for NCGA holiday pie coupons apbw 10/16/09 | |
function upcscanned($entered) { | |
// load the product row, applying any toggles, returning any errors | |
$product = loadProduct($entered, true, false); | |
if (!$product) | |
return trim($entered)."<br><b>is not a valid item</b>"; | |
if (!is_array($product)) | |
return $product; | |
// hard coded for Wedge -- NCGA holiday pie coupons apbw 10/16/2009 (turn off after 1/03/2010) | |
if( true ) { // TODO: do we still need this? | |
if (in_array($product["upc"], array("0051234599276","0051234699276","0051234799276"))) { | |
return couponspecial($product["upc"]); | |
} | |
} | |
// get the quantity from session vars | |
$quantity = getItemQuantity($product["scale"]); | |
// check for coupon | |
if ($product["trans_subtype"] == "CP") { | |
/* for testing: | |
0009396651245 -- item (dept 4, ref groc) | |
0059396600075 -- -$.75 coupon | |
0059396600001 -- free item coupon | |
0059396600013 -- -$1.00 on 4 items coupon | |
0000787923028 -- item (dept 4, ref groc) | |
0050787900075 -- -$.75 coupon | |
0050787900013 -- -$1.00 on 4 items coupon | |
0050000099275 | |
0050000099201 | |
*/ | |
// parse coupon barcode components | |
$mfr = substr($product["upc"],3,5); | |
$fam = substr($product["upc"],8,3); | |
$val = substr($product["upc"],11); | |
// check for 992-bypass coupons | |
if ($fam == "992") { | |
if (!$_SESSION["couponDept"]) { | |
maindisplay("couponDept.php"); | |
return true; | |
} | |
$product["department"] = $_SESSION["couponDept"]; | |
} else { | |
// count coupons, voided coupons and items (excluding or limiting to refunds, depending) | |
$tdb = tDataConnect(); | |
if (!$tdb) | |
return "Database error"; | |
$query = " | |
SELECT | |
MAX(ABS(CASE | |
WHEN trans_subtype = 'CP' THEN NULL | |
ELSE unitPrice | |
END)) AS unitPrice, | |
MAX(department) AS department, | |
SUM(CASE | |
WHEN trans_subtype = 'CP' THEN 0 | |
ELSE ItemQtty | |
END) AS ItemQtty, | |
SUM(CASE | |
WHEN trans_subtype = 'CP' THEN -quantity | |
ELSE quantity | |
END) AS quantity | |
FROM localtemptrans | |
WHERE | |
SUBSTRING(upc,4,5) = '".$mfr."' | |
AND ".($_SESSION["refund"] ? "" : "NOT")." ( | |
trans_status = 'R' | |
OR (trans_status = 'C' AND quantity < 0) | |
OR (trans_status = 'V' AND quantity > 0) | |
) | |
AND trans_status NOT IN ('M','S','J','D') | |
GROUP BY SUBSTRING(upc,4,5)"; | |
$result = sql_query($query, $tdb); | |
if (!$result) | |
return "Could not query couponable items"; | |
$row = sql_fetch_array($result); | |
if (!$row) | |
return "No applicable product found in transaction"; | |
// validate quantity | |
if ($_SESSION["refund"]) | |
$row["quantity"] = -$row["quantity"]; | |
if ($row["quantity"] < 1) | |
return "Coupon already applied for this item"; | |
if ($product["quantity"] > $row["ItemQtty"]) | |
return "Coupon requires ".$product["quantity"]." items, but only ".$row["ItemQtty"]." item(s) found"; | |
// set coupon department and value | |
$product["department"] = $row["department"]; | |
if ($product["groupprice"] == 0) | |
$product["groupprice"] = number_format(-$row["unitPrice"], 2, '.', ''); | |
} | |
} else { | |
// validate department | |
if (isset($_SESSION["limitToDept"]) && $_SESSION["limitToDept"] != 0) { | |
if (!in_array($product["department"], explode(',',$_SESSION["limitToDept"]))) { | |
return "Items from that department may not be rung at this register"; | |
} | |
} | |
// validate weight or quantity | |
if ($product["scale"] == 1) { | |
// don't check $quantity, it might be negative with a tare and negative is a different error, we want to know if | |
// there was any weight/qty *before* the tare | |
if ($_SESSION["quantity"] == 0) { | |
if ($_SESSION["weight"] == 0) { | |
// this weighed item has no weight or quantity specified | |
if ($_SESSION["wgtRequested"] == 0) { | |
// first try polling the scale for the current weight | |
// and set a timer to re-ring this item in .7 seconds | |
$_SESSION["wgtRequested"] = 1; | |
echo "<SCRIPT type='text/javascript'>\n" | |
."lockScreen = setTimeout('document.forms[0].elements[0].value = \"".$_SESSION["strEntered"] | |
."\"; document.forms[0].submit();', 700)\n" | |
."</SCRIPT>"; | |
return true; | |
} | |
// if we already tried polling, then prompt the cashier | |
$_SESSION["SNR"] = 1; | |
$_SESSION["wgtRequested"] = 0; | |
return "Please put item on scale"; | |
} else if ($_SESSION["scale"] == 0) { | |
$_SESSION["SNR"] = 1; | |
$_SESSION["waitforScale"] = 1; | |
return true; | |
} | |
} | |
} else { | |
if ((int)$quantity != $quantity && $product["upc"] != "0000000008006") { // hardcode wedge stock payment plu | |
return "Fractional quantity cannot be accepted for this item"; | |
/* we might need this after all, for by-each priced items | |
} else if ($product["scaleprice"] != null && $quantity != 1) { | |
return "Cannot ring multiples of scale labeled items; please scan each label separately"; | |
*/ | |
} | |
} | |
if ($product["qttyEnforced"] == 1 && $_SESSION["quantity"] == 0) { | |
if ($_SESSION["qttyvalid"] != 1) { | |
if ($_SESSION["msgrepeat"] == 0) { | |
qttyscreen(); | |
return true; | |
} | |
// set msgrepeat back to 0 to allow further prompts/endorsements below, | |
// but also set qttyvalid to remember that we already did this one | |
$_SESSION["qttyvalid"] = 1; | |
$_SESSION["msgrepeat"] = 0; | |
} | |
} else { | |
$_SESSION["qttyvalid"] = 1; | |
} | |
if ($quantity <= 0) { | |
if ($product["scale"] == 1 && $_SESSION["tare"] > 0) { | |
addtare(0); // since additem wasn't called, enter the new 0 tare in localtemptrans; otherwise the receipt prints the previous tare and there's no record of it being reset to 0. apbw 2/11/2008 | |
return "Item weight must be greater than tare weight"; | |
} | |
return "Item quantity must be positive"; | |
} | |
// validate special items | |
if ($product["upc"] == "0000000008005") { // hardcode wedge member discount coupon | |
$used = couponsused(); | |
if ($_SESSION["memberID"] == "0") { | |
maindisplay("memsearch.php"); | |
return true; | |
} else if ($_SESSION["isMember"] == 0) { | |
return "Member discount not applicable"; | |
} else if ($quantity + $used > 3) { // hardcode coupon limit 3 | |
return "Number of coupons exceeds maximum allowable"; | |
} else if ($_SESSION["percentDiscount"] > 0) { | |
return $_SESSION["percentDiscount"]."% discount already applied"; | |
} else if ((str_replace(',','',$_SESSION["discountableSubtotal"])) < (($quantity + $used) * 25)) { | |
return "Discount exceeds discountable purchase total"; | |
} | |
} else if ($product["upc"] == "0000000008006") { // hardcode wedge stock payment | |
if ($_SESSION["memberID"] == "0") { | |
maindisplay("memsearch.php"); | |
return true; | |
} else if (strlen($_SESSION["memberID"]) < 6) { // hardcode wedge non-staff member id length | |
return "Cannot accept Stock Payment from Customer No. ".$_SESSION["memberID"]; | |
} | |
} else if ($product["upc"] == "0000000008011") { // hardcode class registration plu | |
if ($_SESSION["quantity"] == 0) { | |
// if ($_SESSION["refund"] != 0) | |
// return "Integrated class refunds not supported; please refund the amount manually"; | |
maindisplay("classreg_1class.php"); | |
return true; | |
} | |
} | |
// get refund details | |
if ($_SESSION["refundModule"] == 1 && $_SESSION["refund"] == 1 | |
&& empty($_SESSION["refundInfo"]["reason"]) | |
&& empty($_SESSION["refundInfo"]["action"]) | |
) { // require the refund form to be completed before adding the item | |
echo "<SCRIPT type='text/javascript'>window.top.location='./refundForm.php';</script>"; // refund module upgrade 12/11/08 apbw | |
return true; | |
} | |
} // coupon? | |
// generate item rows (including volume discount rows, if applicable) | |
$list = makeItemList($product, $quantity, $_SESSION["refund"], false); | |
if (!$list) | |
return "Invalid item"; | |
if (!is_array($list)) | |
return $list; | |
// tally totals for all item rows to be added | |
$total = 0.00; | |
$discount = 0.00; | |
$memDiscount = 0.00; | |
foreach ($list as $i) { | |
if ($i && is_array($i)) { | |
$total += $i["total"]; | |
$discount += $i["discount"]; | |
$memDiscount += $i["memDiscount"]; | |
} | |
} | |
$total = number_format($total, 2, '.', ''); | |
// show endorsement/confirmation prompts | |
if ($_SESSION["msgrepeat"] == 0) { | |
if ($product["trans_subtype"] == "CP") { | |
if ($_SESSION["refund"] == 1) { | |
$_SESSION["boxMsg"] = "To refund a coupon you must return the physical coupon to the customer." | |
."<FONT size='-1'><p>[enter] to continue<br>[clear] to cancel</FONT>"; | |
boxMsgscreen(); | |
return true; | |
} | |
} else if ($_SESSION["refund"] != 1) { | |
// non-coupon, non-refund | |
if ($product["scale"] == 1 && $_SESSION["weight"] != 0 && $_SESSION["weight"] == $_SESSION["lastWeight"]) { | |
//$_SESSION["keepTare"] = 1; // no longer needed | |
$_SESSION["screset"] = "rePoll"; | |
$_SESSION["boxMsg"] = "<b>identical scale readings</b><p><font size=-1>[clear] to cancel<br>[enter] to continue</font>"; | |
boxMsgscreen(); | |
return true; | |
} | |
// TODO: review procedures for REFUNDING misc pay-ins that require endorsement | |
switch ($product["upc"]) { | |
case "0000000008006": // hardcode stock payment plu | |
if ($total > 80.00) { | |
return "$80.00 limit exceeded"; | |
} | |
$_SESSION["tenderamt"] = $total; | |
if ($_SESSION["newMember"] == 0) { // apbw 11/04/09 print stock slips for payments on account (don't endorse new member form) | |
$_SESSION["endorseType"] = "stockSlip"; | |
$_SESSION["boxMsg"] = "<B>".$total." stock payment for ".$_SESSION["memberID"]." ".$_SESSION["lastName"]."?</B><BR>press [enter] to print slip<P><FONT size='-1'>[clear] to cancel</FONT>"; | |
} else { | |
$_SESSION["endorseType"] = "stock"; | |
$_SESSION["boxMsg"] = "<B>".$total." stock payment</B><BR>press [enter] to endorse<P><FONT size='-1'>[clear] to cancel</FONT>"; | |
} | |
boxMsgscreen(); | |
return true; | |
case "0000000008010": // hardcode gift cert plu | |
$_SESSION["endorseType"] = "giftcert"; | |
$_SESSION["tenderamt"] = $total; | |
$_SESSION["boxMsg"] = "<B>".$total." gift certificate</B><BR>insert document<BR>press [enter] to endorse<P><FONT size='-1'>[clear] to cancel</FONT>"; | |
boxMsgscreen(); | |
return true; | |
case "0000000008011": // hardcode class registration plu | |
$_SESSION["endorseType"] = "classreg"; | |
$_SESSION["tenderamt"] = $total; | |
$_SESSION["boxMsg"] = "<B>".$total." class registration</B><BR>insert form<BR>press [enter] to endorse<P><FONT size='-1'>[clear] to cancel</FONT>"; | |
boxMsgscreen(); | |
return true; | |
case "0000000008012": | |
case "0000000008015": | |
case "0000000008016": | |
case "0000000008017": | |
case "0000000008018": | |
$_SESSION["endorseType"] = "specorderdeposit"; | |
$_SESSION["tenderamt"] = $total; | |
$_SESSION["boxMsg"] = "<B>".$total." HBC Deposit </B><BR>insert form<BR>press [enter] to endorse<P><FONT size='-1'>[clear] to cancel</FONT>"; | |
boxMsgscreen(); | |
return true; | |
} | |
} | |
} | |
// add all necessary lines | |
$n = 0; | |
foreach ($list as $x => $i) { | |
if ($i && is_array($i) && $i["quantity"] != 0) { | |
if ($x == 3 && $i["discounttype"] == 3) { // case discount doesn't apply to voldisc lines | |
addcdnotify(); | |
} | |
addItem( | |
$i['upc'], $i['description'], | |
$i['trans_type'], $i['trans_subtype'], $i['trans_status'], | |
$i['department'], $i['cost'], | |
$i['quantity'], $i['unitPrice'], $i['total'], $i['regPrice'], | |
$i['scale'], $i['tax'], $i['foodstamp'], | |
$i['discount'], $i['memDiscount'], $i['discountable'], $i['discounttype'], | |
$i['ItemQtty'], $i['volDiscType'], $i['volume'], $i['VolSpecial'], | |
$i['mixMatch'], $i['matched'], $i['voided'], | |
$i['numflag'], '', | |
0, 0, 0, 0, | |
'', 0, 0 | |
); | |
$n++; | |
} | |
} | |
if (!$n) | |
error_log("upcscanned(".$entered.") added no items"); | |
// reset everything | |
$_SESSION["msgrepeat"] = 0; | |
$_SESSION["tare"] = 0; | |
if ($product["scale"] == 1) | |
$_SESSION["lastWeight"] = $_SESSION["weight"]; | |
lineFlagReset(); | |
unset($_SESSION["refundInfo"]); | |
$_SESSION["ttlflag"] = 0; | |
$_SESSION["ttlrequested"] = 0; | |
$_SESSION["fntlflag"] = 0; | |
setglobalflags(0); | |
// add discount notifications | |
if ($product["discounttype"] == 1) { | |
adddiscount($discount, $product["department"]); | |
} else if ($product["discounttype"] == 2 && $_SESSION["isMember"] != 0) { | |
adddiscount($memDiscount, $product["department"]); | |
} else if ($product["discounttype"] == 4 && $_SESSION["isStaff"] != 0) { | |
adddiscount($memDiscount, $product["department"]); | |
} | |
// jqh 04/07/06 hardcode, if member is inactive because stock pmt due, and they buy stock, then ttl() transaction to update isMember and give discounts | |
if (strpos($_SESSION["memMsg"],"INACTIVE - STOCK PMT DUE") && $product["upc"] == "0000000008006") { | |
ttl(); | |
// if refund module is turned on, check for contact info -- apbw 1/19/08 | |
if ($_SESSION["refundModule"] == 1 && $_SESSION["refundTotal"] != 0) { | |
$page = refundContactCheck(true); | |
if ($page) | |
topdisplay("./".$page); | |
} | |
} | |
return true; | |
} // upcscanned() | |
//--------------------------------------------------------------------- | |
function couponsused() { | |
$db = tDataConnect(); | |
$query = "select sum(ItemQtty) as couponsused from localtemptrans where upc = '0000000008005' group by upc"; | |
$result = sql_query($query, $db); | |
$num_rows = sql_num_rows($result); | |
if ($num_rows > 0) { | |
$row = sql_fetch_array($result); | |
$couponsused = nullwrap($row["couponsused"]); | |
} | |
else $couponsused = 0; | |
sql_close($db); | |
return $couponsused; | |
} // couponsused() | |
//---------------------------------------------- | |
/* not used --atf 2010-02-25 | |
function couponTotal() { | |
$db = tDataConnect(); | |
$query = "select sum(total) as couponTotal from localtemptrans where upc = '0000000008005'"; | |
$result = sql_query($query, $db); | |
$num_rows = sql_num_rows($result); | |
if ($num_rows > 0) { | |
$row = sql_fetch_array($result); | |
$couponTotal = (-1 * 10) * nullwrap($row["couponTotal"]); | |
} | |
else $couponTotal = 0; | |
sql_close($db); | |
return $couponTotal; | |
} // couponTotal() | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment