Beispiel #1
0
function SumUpConfigOptionsOrder($id, $configoptions, $promocode, $paymentmethod = "", $checkout = "")
{
    global $CONFIG;
    global $_LANG;
    global $upgradeslist;
    global $orderamount;
    global $orderdescription;
    global $applytax;
    $_SESSION['upgradeids'] = array();
    $result = select_query("tblhosting", "packageid,domain,nextduedate,billingcycle", array("userid" => $_SESSION['uid'], "id" => $id));
    $data = mysql_fetch_array($result);
    $packageid = $data['packageid'];
    $domain = $data['domain'];
    $nextduedate = $data['nextduedate'];
    $billingcycle = $data['billingcycle'];
    $result = select_query("tblproducts", "name,tax", array("id" => $packageid));
    $data = mysql_fetch_array($result);
    $productname = $data['name'];
    $applytax = $data['tax'];
    if ($domain) {
        $productname .= " - " . $domain;
    }
    $year = substr($nextduedate, 0, 4);
    $month = substr($nextduedate, 5, 2);
    $day = substr($nextduedate, 8, 2);
    $cyclemonths = getBillingCycleMonths($billingcycle);
    $prevduedate = date("Y-m-d", mktime(0, 0, 0, $month - $cyclemonths, $day, $year));
    $totaldays = round((strtotime($nextduedate) - strtotime($prevduedate)) / 86400);
    $todaysdate = date("Ymd");
    $todaysdate = strtotime($todaysdate);
    $nextduedatetime = strtotime($nextduedate);
    $days = round(($nextduedatetime - $todaysdate) / 86400);
    if ($days < 0) {
        $days = $totaldays;
    }
    $percentage = $days / $totaldays;
    $discount = 0;
    $promoqualifies = true;
    if ($promocode) {
        $promodata = validateUpgradePromo($promocode);
        if (is_array($promodata)) {
            $appliesto = $promodata['appliesto'];
            $cycles = $promodata['cycles'];
            $promotype = $promodata['type'];
            $promovalue = $promodata['value'];
            $discounttype = $promodata['discounttype'];
            $upgradeconfigoptions = $promodata['configoptions'];
            $promodesc = $promodata['desc'];
            if ($promotype != "configoptions") {
                $promoqualifies = false;
            }
            if (count($appliesto) && $appliesto[0] && !in_array($packageid, $appliesto)) {
                $promoqualifies = false;
            }
            if (count($cycles) && $cycles[0] && !in_array($billingcycle, $cycles)) {
                $promoqualifies = false;
            }
            if ($discounttype == "Percentage") {
                $promovalue = $promovalue / 100;
            }
        }
        if ($promovalue == 0) {
            $promodata = get_query_vals("tblpromotions", "upgrades, upgradeconfig, type,value", array("lifetimepromo" => 1, "recurring" => 1, "code" => $promocode));
            if (is_array($promodata)) {
                if ($promodata['upgrades'] == 1) {
                    $upgradeconfig = unserialize($promodata['upgradeconfig']);
                    if ($upgradeconfig['type'] != "configoptions") {
                        $promoqualifies = false;
                    }
                    $promovalue = $upgradeconfig['value'];
                    $discounttype = $upgradeconfig['discounttype'];
                    if ($discounttype == "Percentage") {
                        $promovalue = $promovalue / 100;
                    }
                    $promoqualifies = true;
                } else {
                    $promoqualifies = false;
                }
            }
        }
    }
    $configoptions = getCartConfigOptions($packageid, $configoptions, $billingcycle);
    $oldconfigoptions = getCartConfigOptions($packageid, "", $billingcycle, $id);
    $subtotal = 0;
    foreach ($configoptions as $key => $configoption) {
        $configid = $configoption['id'];
        $configname = $configoption['optionname'];
        $optiontype = $configoption['optiontype'];
        $new_selectedvalue = $configoption['selectedvalue'];
        $new_selectedqty = $configoption['selectedqty'];
        $new_selectedname = $configoption['selectedname'];
        $new_selectedsetup = $configoption['selectedsetup'];
        $new_selectedrecurring = $configoption['selectedrecurring'];
        $old_selectedvalue = $oldconfigoptions[$key]['selectedvalue'];
        $old_selectedqty = $oldconfigoptions[$key]['selectedqty'];
        $old_selectedname = $oldconfigoptions[$key]['selectedname'];
        $old_selectedsetup = $oldconfigoptions[$key]['selectedsetup'];
        $old_selectedrecurring = $oldconfigoptions[$key]['selectedrecurring'];
        if (($optiontype == 1 || $optiontype == 2) && $new_selectedvalue != $old_selectedvalue || ($optiontype == 3 || $optiontype == 4) && $new_selectedqty != $old_selectedqty) {
            $difference = $new_selectedrecurring - $old_selectedrecurring;
            $amountdue = $difference * $percentage;
            $amountdue = format_as_currency($amountdue);
            if (!$CONFIG['CreditOnDowngrade'] && $amountdue < 0) {
                $amountdue = format_as_currency(0);
            }
            if ($optiontype == 1 || $optiontype == 2) {
                $db_orig_value = $old_selectedvalue;
                $db_new_value = $new_selectedvalue;
                $originalvalue = $old_selectedname;
                $newvalue = $new_selectedname;
            } else {
                if ($optiontype == 3) {
                    $db_orig_value = $old_selectedqty;
                    $db_new_value = $new_selectedqty;
                    if ($old_selectedqty) {
                        $originalvalue = $_LANG['yes'];
                        $newvalue = $_LANG['no'];
                    } else {
                        $originalvalue = $_LANG['no'];
                        $newvalue = $_LANG['yes'];
                    }
                } else {
                    if ($optiontype == 4) {
                        $new_selectedqty = (int) $new_selectedqty;
                        if ($new_selectedqty < 0) {
                            $new_selectedqty = 0;
                        }
                        $db_orig_value = $old_selectedqty;
                        $db_new_value = $new_selectedqty;
                        $originalvalue = $old_selectedqty;
                        $newvalue = $new_selectedqty . " x " . $configoption['options'][0]['nameonly'];
                    }
                }
            }
            $subtotal += $amountdue;
            $itemdiscount = 0;
            if ($promoqualifies && 0 < $amountdue && (!count($upgradeconfigoptions) || in_array($configid, $upgradeconfigoptions))) {
                $itemdiscount = $discounttype == "Percentage" ? round($amountdue * $promovalue, 2) : ($amountdue < $promovalue ? $amountdue : $promovalue);
            }
            $discount += $itemdiscount;
            $upgradearray[] = array("configname" => $configname, "originalvalue" => $originalvalue, "newvalue" => $newvalue, "price" => formatCurrency($amountdue));
            if ($checkout) {
                if ($orderdescription) {
                    $orderdescription .= "<br>\r\n<br>\r\n";
                }
                $orderdescription .= $_LANG['upgradedowngradeconfigoptions'] . (": " . $configname . " - " . $originalvalue . " => " . $newvalue . "<br>\r\nAmount Due: ") . formatCurrency($amountdue);
                $paid = "N";
                if ($amountdue <= 0) {
                    $paid = "Y";
                }
                $amountwithdiscount = $amountdue - $itemdiscount;
                $upgradeid = insert_query("tblupgrades", array("type" => "configoptions", "date" => "now()", "relid" => $id, "originalvalue" => "" . $configid . "=>" . $db_orig_value, "newvalue" => $db_new_value, "amount" => $amountwithdiscount, "recurringchange" => $difference, "status" => "Pending", "paid" => $paid));
                $_SESSION['upgradeids'][] = $upgradeid;
                if (0 < $amountdue) {
                    insert_query("tblinvoiceitems", array("userid" => $_SESSION['uid'], "type" => "Upgrade", "relid" => $upgradeid, "description" => $_LANG['upgradedowngradeconfigoptions'] . (": " . $productname . "\r\n" . $configname . ": " . $originalvalue . " => " . $newvalue . " (") . getTodaysDate() . " - " . fromMySQLDate($nextduedate) . ")", "amount" => $amountdue, "taxed" => $applytax, "duedate" => "now()", "paymentmethod" => $paymentmethod));
                    if (0 < $itemdiscount) {
                        insert_query("tblinvoiceitems", array("userid" => $_SESSION['uid'], "description" => $_LANG['orderpromotioncode'] . ": " . $promocode . " - " . $promodesc, "amount" => $itemdiscount * (0 - 1), "taxed" => $applytax, "duedate" => "now()", "paymentmethod" => $paymentmethod));
                    }
                    $orderamount += $amountwithdiscount;
                    continue;
                }
                if ($CONFIG['CreditOnDowngrade']) {
                    $creditamount = $amountdue * (0 - 1);
                    insert_query("tblcredit", array("clientid" => $_SESSION['uid'], "date" => "now()", "description" => "Upgrade/Downgrade Credit", "amount" => $creditamount));
                    update_query("tblclients", array("credit" => "+=" . $creditamount), array("id" => (int) $_SESSION['uid']));
                }
                doUpgrade($upgradeid);
                continue;
            }
            continue;
        }
    }
    if (!count($upgradearray)) {
        redir("type=configoptions&id=" . (int) $id, "upgrade.php");
    }
    $GLOBALS['subtotal'] = $subtotal;
    $GLOBALS['qualifies'] = $promoqualifies;
    $GLOBALS['discount'] = $discount;
    return $upgradearray;
}
Beispiel #2
0
                        continue;
                    }
                }
            }
            $smarty->assign("configoptions", $configoptions);
            $smarty->assign("errormessage", $errormessage);
        }
    }
} else {
    if ($step == "2") {
        $templatefile = "upgradesummary";
        $upgrades = array();
        $applytax = false;
        $serviceid = $_REQUEST['id'];
        if ($promocode && empty($_REQUEST['removepromo'])) {
            $promodata = validateUpgradePromo($promocode);
            if (!is_array($promodata)) {
                $promocode = "";
                $smartyvalues['promoerror'] = $promodata;
            } else {
                $smartyvalues['promocode'] = $promocode;
                if ($promodata['type'] == "configoptions" && count($promodata['configoptions'])) {
                    $promodata->desc .= " " . $_LANG['upgradeonselectedoptions'];
                }
                $smartyvalues['promodesc'] = $promodata['desc'];
                $smartyvalues['promorecurring'] = $promodata['recurringdesc'];
            }
        } else {
            $promodata = get_query_vals("tblpromotions", "code,type,value", array("lifetimepromo" => 1, "recurring" => 1, "id" => get_query_val("tblhosting", "promoid", array("id" => $serviceid))));
            if (is_array($promodata)) {
                $smartyvalues['promocode'] = $promocode = $promodata['code'];