/** * * @ WHMCS FULL DECODED & NULLED * * @ Version : 5.2.15 * @ Author : MTIMER * @ Release on : 2013-12-24 * @ Website : http://www.mtimer.cn * **/ function SumUpPackageUpgradeOrder($id, $newproductid, $newproductbillingcycle, $promocode, $paymentmethod = "", $checkout = "") { global $CONFIG; global $_LANG; global $currency; global $upgradeslist; global $orderamount; global $orderdescription; global $applytax; $_SESSION['upgradeids'] = ""; $result = select_query("tblhosting", "tblproducts.name,tblproducts.id,tblhosting.nextduedate,tblhosting.billingcycle,tblhosting.amount,tblhosting.firstpaymentamount,tblhosting.domain", array("userid" => $_SESSION['uid'], "tblhosting.id" => $id), "", "", "", "tblproducts ON tblproducts.id=tblhosting.packageid"); $data = mysql_fetch_array($result); $oldproductid = $data['id']; $oldproductname = $data['name']; $domain = $data['domain']; $nextduedate = $data['nextduedate']; $billingcycle = $data['billingcycle']; $oldamount = $data['amount']; if ($billingcycle == "One Time") { $oldamount = $data['firstpaymentamount']; } $newproductbillingcycleraw = $newproductbillingcycle; $newproductbillingcyclenice = ucfirst($newproductbillingcycle); if ($newproductbillingcyclenice == "Semiannually") { $newproductbillingcyclenice = "Semi-Annually"; } $configoptionspricingarray = getCartConfigOptions($newproductid, "", $newproductbillingcyclenice, $id); if ($configoptionspricingarray) { foreach ($configoptionspricingarray as $configoptionkey => $configoptionvalues) { $configoptionsamount += $configoptionvalues['selectedrecurring'] . "<br>"; } } $result = select_query("tblproducts", "id,name,tax,paytype", array("id" => $newproductid)); $data = mysql_fetch_array($result); $newproductid = $data['id']; $newproductname = $data['name']; $applytax = $data['tax']; $paytype = $data['paytype']; if (!$newproductid) { exit("Invalid New Product ID"); } if (!$newproductbillingcycle) { exit("Invalid New Billing Cycle"); } $newproductbillingcycle = strtolower($newproductbillingcycle); $newproductbillingcycle = str_replace("-", "", $newproductbillingcycle); if ($newproductbillingcycle == "onetime") { $newproductbillingcycle = "monthly"; } $result = select_query("tblpricing", $newproductbillingcycle, array("type" => "product", "currency" => $currency['id'], "relid" => $newproductid)); $data = mysql_fetch_array($result); $newamount = $data[$newproductbillingcycle]; if (($paytype == "onetime" || $paytype == "recurring") && $newamount < 0) { exit("Invalid New Billing Cycle"); } $newamount += $configoptionsamount; $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); $cyclemonths = getBillingCycleMonths($newproductbillingcyclenice); $prevduedate = date("Y-m-d", mktime(0, 0, 0, $month - $cyclemonths, $day, $year)); $newtotaldays = round((strtotime($nextduedate) - strtotime($prevduedate)) / 86400); if ($newproductbillingcyclenice == "Onetime") { $newtotaldays = $totaldays; } if ($billingcycle == "Free Account" || $billingcycle == "One Time") { $days = $newtotaldays = $totaldays = getBillingCycleDays($newproductbillingcyclenice); $totalmonths = getBillingCycleMonths($newproductbillingcyclenice); $nextduedate = date("Y-m-d", mktime(0, 0, 0, date("m") + $totalmonths, date("d"), date("Y"))); $amountdue = format_as_currency($newamount - $oldamount); $difference = $newamount; } else { $todaysdate = date("Ymd"); $nextduedatetime = strtotime($nextduedate); $todaysdate = strtotime($todaysdate); $days = round(($nextduedatetime - $todaysdate) / 86400); $daysnotused = $days / $totaldays; $refundamount = $oldamount * $daysnotused; $cyclemultiplier = $days / $newtotaldays; $amountdue = $newamount * $cyclemultiplier; $amountdue = $amountdue - $refundamount; if ($amountdue < 0 && !$CONFIG['CreditOnDowngrade']) { $amountdue = 0; } $amountdue = format_as_currency($amountdue); $difference = $newamount - $oldamount; } $discount = 0; $promoqualifies = true; if ($promocode) { $promodata = validateUpgradePromo($promocode); if (is_array($promodata)) { $appliesto = $promodata['appliesto']; $requires = $promodata['requires']; $cycles = $promodata['cycles']; $value = $promodata['value']; $type = $promodata['discounttype']; $promodesc = $promodata['desc']; if ($newproductbillingcycle == "free") { $billingcycle = "Free Account"; } else { if ($newproductbillingcycle == "onetime") { $billingcycle = "One Time"; } else { if ($newproductbillingcycle == "semiannually") { $billingcycle = "Semi-Annually"; } else { $billingcycle = ucfirst($newproductbillingcycle); } } } if (count($appliesto) && $appliesto[0] && !in_array($newproductid, $appliesto)) { $promoqualifies = false; } if (count($requires) && $requires[0] && !in_array($oldproductid, $requires)) { $promoqualifies = false; } if (count($cycles) && $cycles[0] && !in_array($billingcycle, $cycles)) { $promoqualifies = false; } if ($promoqualifies && 0 < $amountdue) { if ($type == "Percentage") { $percent = $value / 100; $discount = $amountdue * $percent; } else { $discount = $value; if ($amountdue < $discount) { $discount = $amountdue; } } } } if ($discount == 0) { $promodata = get_query_vals("tblpromotions", "type,value", array("lifetimepromo" => 1, "recurring" => 1, "code" => $promocode)); if (is_array($promodata)) { if ($promodata['type'] == "Percentage") { $percent = $promodata['value'] / 100; $discount = $amountdue * $percent; } else { $discount = $promodata['value']; if ($amountdue < $discount) { $discount = $amountdue; } } $promoqualifies = true; } } } $GLOBALS['subtotal'] = $amountdue; $GLOBALS['qualifies'] = $promoqualifies; $GLOBALS['discount'] = $discount; $upgradearray[] = array("oldproductid" => $oldproductid, "oldproductname" => $oldproductname, "newproductid" => $newproductid, "newproductname" => $newproductname, "daysuntilrenewal" => $days, "totaldays" => $totaldays, "newproductbillingcycle" => $newproductbillingcycleraw, "price" => formatCurrency($amountdue)); if ($checkout) { $orderdescription = $_LANG['upgradedowngradepackage'] . (": " . $oldproductname . " => " . $newproductname . "<br>\r\n") . $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($newproductbillingcycle))] . "<br>\r\n" . $_LANG['ordertotalduetoday'] . ": " . formatCurrency($amountdue); $amountwithdiscount = $amountdue - $discount; $upgradeid = insert_query("tblupgrades", array("type" => "package", "date" => "now()", "relid" => $id, "originalvalue" => $oldproductid, "newvalue" => "" . $newproductid . "," . $newproductbillingcycleraw, "amount" => $amountwithdiscount, "recurringchange" => $difference)); $upgradeslist .= $upgradeid . ","; $_SESSION['upgradeids'][] = $upgradeid; if (0 < $amountdue) { if ($domain) { $domain = " - " . $domain; } insert_query("tblinvoiceitems", array("userid" => $_SESSION['uid'], "type" => "Upgrade", "relid" => $upgradeid, "description" => $_LANG['upgradedowngradepackage'] . (": " . $oldproductname . $domain . "\r\n" . $oldproductname . " => " . $newproductname . " (") . getTodaysDate() . " - " . fromMySQLDate($nextduedate) . ")", "amount" => $amountdue, "taxed" => $applytax, "duedate" => "now()", "paymentmethod" => $paymentmethod)); if (0 < $discount) { insert_query("tblinvoiceitems", array("userid" => $_SESSION['uid'], "description" => $_LANG['orderpromotioncode'] . ": " . $promocode . " - " . $promodesc, "amount" => $discount * (0 - 1), "taxed" => $applytax, "duedate" => "now()", "paymentmethod" => $paymentmethod)); } $orderamount += $amountwithdiscount; } else { 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'])); } update_query("tblupgrades", array("paid" => "Y"), array("id" => $upgradeid)); doUpgrade($upgradeid); } } return $upgradearray; }
foreach ($seladdons as $aid) { $data = get_query_vals("tblhostingaddons", "hostingid,addonid,name,nextduedate,billingcycle,recurring,paymentmethod", array("id" => $aid)); $serviceid = $data['hostingid']; $addonid = $data['addonid']; $name = $data['name']; $existingnextduedate = $data['nextduedate']; $billingcycle = $data['billingcycle']; $price = $data['recurring']; if (!$paymentmethod) { $paymentmethod = $data['paymentmethod']; } $domain = get_query_val("tblhosting", "domain", array("id" => $serviceid)); if ($recurringamount) { $price = $recurringamount; } $totaldays = getBillingCycleDays($billingcycle); $timediff = strtotime($targetnextduedate) - strtotime($existingnextduedate); $timediff = ceil($timediff / (60 * 60 * 24)); $percent = $timediff / $totaldays; $amountdue = format_as_currency($price * $percent); if ($domain) { $domain = "(" . $domain . ") "; } $description = $_LANG['orderaddon'] . " " . $domain . "- "; if ($name) { $description .= $name; } else { $description .= get_query_val("tbladdons", "name", array("id" => $addonid)); } $description .= " (" . fromMySQLDate($existingnextduedate) . " - " . $nextduedate . ")"; $tax = $invdata['tax'];