function add_item_to_promotion()
{
    connect_and_select_db(DB_SERVER, DB_UN, DB_PWD, DB_NAME);
    $itemNumbers = $_POST['itemNumbers'];
    $promoCode = $_REQUEST['promoCode'];
    //echo "Item number = $itemNumber \nPromoCode = $promoCode";
    //Calculate sale price
    $promoType = getPromoType($promoCode);
    $amountOff = getAmountOff($promoCode);
    $message = "";
    if (empty($itemNumbers)) {
        $message .= "Error: No Items Selected.";
    } else {
        $count = count($itemNumbers);
        $message .= "{$count} Items selected to be added to Promotion.<br />";
        foreach ($itemNumbers as $itemNumber) {
            if (!itemExistsAlreadyInPromotion($itemNumber, $promoCode)) {
                $item_retail_price = getItemRetailPrice($itemNumber);
                //echo "retail price : $item_retail_price \n promotype: $promoType \n amount off: $amountOff";
                $salePrice = getSalePrice($item_retail_price, $promoType, $amountOff);
                $insertStmt = "INSERT INTO PromotionItem (PromoCode, ItemNumber, SalePrice) values ( '{$promoCode}','{$itemNumber}', '{$salePrice}')";
                $result = mysql_query($insertStmt);
                if (!$result) {
                    $message .= "Error adding Item to Promotion. <br />Promo Code: {$promoCode}<br />Item Number:\n                {$itemNumber}<br />Sale Price: {$salePrice}<br /><br />" . mysql_error() . "<br />";
                } else {
                    $message .= "Item added to Promotion successfully.<br />Promo Code: {$promoCode}<br />Item Number:\n                {$itemNumber}<br />Sale Price: {$salePrice}<br /><br />";
                }
            } else {
                $message .= "Item (Item Number: {$itemNumber}) already exists in Promotion (Promo Code: {$promoCode}).<br /><br />";
            }
        }
    }
    ui_show_promotion_item_insert_result($message);
}
예제 #2
0
function getNewSalePrice($item_retail_price, $promoCode)
{
    $promoType = getPromoType($promoCode);
    $amountOff = getAmountOff($promoCode);
    //echo "PromoType: $promoType\nAmount off: $amountOff\nRetail Price: $item_retail_price\n";
    if ($promoType == "Percent") {
        $result = $item_retail_price - $amountOff * $item_retail_price;
        //echo "Percent result: $result";
    } else {
        $result = $item_retail_price - $amountOff;
        //echo "Dollar result: $result";
    }
    $result = round($result, 2);
    return $result;
}