Example #1
0
function couponcode($upc)
{
    $man_id = substr($upc, 3, 5);
    $fam = substr($upc, 8, 3);
    $val = substr($upc, -2);
    $db = pDataConnect();
    $query = "select * from couponcodes where code = '" . $val . "'";
    $result = sql_query($query, $db);
    $num_rows = sql_num_rows($result);
    if ($num_rows == 0) {
        boxMsg("coupon type unknown<br>please enter coupon<br>manually");
    } else {
        $row = sql_fetch_array($result);
        $value = $row["Value"];
        $qty = $row["Qty"];
        if ($fam == "992") {
            $value = truncate2($value);
            $_SESSION["couponupc"] = $upc;
            $_SESSION["couponamt"] = $value;
            maindisplay("coupondeptsearch.php");
        } else {
            sql_close($db);
            $fam = substr($fam, 0, 2);
            $query = "select " . "max(unitPrice) as total, " . "max(department) as department, " . "sum(ItemQtty) as qty, " . "sum(case when trans_status = 'C' then -1 else quantity end) as couponqtty " . "from localtemptrans where substring(upc, 4, 5) = '" . $man_id . "' " . "group by substring(upc, 4, 5)";
            $db = tDataConnect();
            $result = sql_query($query, $db);
            $num_rows = sql_num_rows($result);
            if ($num_rows > 0) {
                $row = sql_fetch_array($result);
                if ($row["couponqtty"] < 1) {
                    boxMsg("Coupon already applied<BR>for this item");
                } else {
                    $dept = $row["department"];
                    $act_qty = $row["qty"];
                    if ($qty <= $act_qty) {
                        if ($value == 0) {
                            $value = -1 * $row["total"];
                        }
                        $value = truncate2($value);
                        addcoupon($upc, $dept, $value);
                        lastpage();
                    } else {
                        boxMsg("coupon requires " . $qty . "items<BR>there are only " . $act_qty . " item(s)<BR>in this transaction");
                    }
                }
            } else {
                boxMsg("product not found<BR>in transaction");
            }
            // sql_close($db);
        }
    }
}
Example #2
0
    include_once "connect.php";
}
// apbw 5/3/05 BlueSkyFix
if (!function_exists("addcoupon")) {
    include_once "additem.php";
}
// apbw 5/3/05 BlueSkyFix
$dept = strtoupper(trim($_POST["dept"]));
$dept = str_replace(".", "", $dept);
if ($dept == "CL") {
    gohome();
} elseif (is_numeric(substr($dept, 2))) {
    // apbw 5/3/05 BlueSkyFix
    $dept = substr($dept, 2);
    // apbw 5/3/05 BlueSkyFix
    $upc = $_SESSION["couponupc"];
    $val = $_SESSION["couponamt"];
    $query = "select * from departments where dept_no = '" . $dept . "'";
    $db = pDataConnect();
    $result = sql_query($query, $db);
    $num_rows = sql_num_rows($result);
    if ($num_rows != 0) {
        addcoupon($upc, $dept, $val);
        gohome();
    } else {
        header("Location:coupondeptinvalid.php");
    }
    sql_close($db);
} else {
    header("Location:coupondeptinvalid.php");
}