function gate2shop_link($params) { $shipping = 4; $discount = 4; $total_tax = 4; $totalAmount = $params['amount']; $sTimestamp = date("Y-m-d.h:i:s"); $sCheckString = $params['SecretKey']; $sCheckString .= $params['MerchantID']; $sCheckString .= $params['currency']; $sCheckString .= $totalAmount; $sCheckString .= $params['description'] . $totalAmount . "1"; $sCheckString .= $sTimestamp; $checksum = md5($sCheckString); $sMerchantLocale = "en_US"; $numberOfItems = 5; $code = "<form action=\"https://secure.gate2shop.com/ppp/purchase.do\" method=\"post\">\n<input type=\"hidden\" name=\"encoding\" value=\"utf-8\">\n<input type=\"hidden\" name=\"customField1\" value=\"" . $params['invoiceid'] . "\">\n<input type=\"hidden\" name=\"merchant_id\" value=\"" . $params['MerchantID'] . "\">\n<input type=\"hidden\" name=\"merchant_site_id\" value=\"" . $params['MerchantSiteID'] . "\">\n<input type=\"hidden\" name=\"merchantLocale\" value=\"" . $sMerchantLocale . "\">\n<input type=\"hidden\" name=\"first_name\" value=\"" . $params['clientdetails']['firstname'] . "\">\n<input type=\"hidden\" name=\"last_name\" value=\"" . $params['clientdetails']['lastname'] . "\">\n<input type=\"hidden\" name=\"email\" value=\"" . $params['clientdetails']['email'] . "\">\n<input type=\"hidden\" name=\"address1\" value=\"" . $params['clientdetails']['address1'] . "\">\n<input type=\"hidden\" name=\"address2\" value=\"" . $params['clientdetails']['address2'] . "\">\n<input type=\"hidden\" name=\"city\" value=\"" . $params['clientdetails']['city'] . "\">\n<input type=\"hidden\" name=\"country\" value=\"" . $params['clientdetails']['country'] . "\">\n<input type=\"hidden\" name=\"zip\" value=\"" . $params['clientdetails']['postcode'] . "\">\n<input type=\"hidden\" name=\"phone1\" value=\"" . $params['clientdetails']['phonenumber'] . "\">\n<input type=\"hidden\" name=\"version\" value=\"3.0.0\">\n<input type=\"hidden\" name=\"currency\" value=\"" . $params['currency'] . "\">\n<input type=\"hidden\" name=\"time_stamp\" value=\"" . $sTimestamp . "\">\n<input type=\"hidden\" name=\"item_name_1\" value=\"" . $params['description'] . "\" />\n<input type=\"hidden\" name=\"item_amount_1\" value=\"" . format_as_currency($totalAmount - $shipping) . "\" />\n<input type=\"hidden\" name=\"item_quantity_1\" value=1 />\n<input type=\"hidden\" name=\"numberofitems\" value=\"" . $numberOfItems . "\">\n<input type=\"hidden\" name=\"discount\" value=\"" . $discount . "\">\n<input type=\"hidden\" name=\"total_tax\" value=\"" . $total_tax . "\">\n<input type=\"hidden\" name=\"total_amount\" value=\"" . $totalAmount . "\">\n<input type=\"hidden\" name=\"checksum\" value=\"" . $checksum . "\">\n<input type=\"submit\" value=\"" . $params['langpaynow'] . "\">\n</form>"; return $code; }
function convertQuotetoInvoice($id, $invoicetype, $invoiceduedate, $depositpercent, $depositduedate, $finalduedate, $sendemail) { global $CONFIG; global $_LANG; $result = select_query("tblquotes", "", array("id" => $id)); $data = mysql_fetch_array($result); $userid = $data['userid']; $firstname = $data['firstname']; $lastname = $data['lastname']; $companyname = $data['companyname']; $email = $data['email']; $address1 = $data['address1']; $address2 = $data['address2']; $city = $data['city']; $state = $data['state']; $postcode = $data['postcode']; $country = $data['country']; $phonenumber = $data['phonenumber']; $currency = $data['currency']; if ($userid) { getUsersLang($userid); $clientsdetails = getClientsDetails($userid); $state = $clientsdetails['state']; $country = $clientsdetails['country']; } else { if (!function_exists("addClient")) { require ROOTDIR . "/clientfunctions.php"; } $_SESSION['currency'] = $currency; $userid = addClient($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, substr(md5($id), 0, 10), 0, "", "on"); } if ($CONFIG['TaxEnabled'] == "on") { $taxlevel1 = getTaxRate(1, $state, $country); $taxlevel2 = getTaxRate(2, $state, $country); $taxrate = $taxlevel1['rate']; $taxrate2 = $taxlevel2['rate']; } $subtotal = $data['subtotal']; $tax1 = $data['tax1']; $tax2 = $data['tax2']; $total = $data['total']; $result = select_query("tblpaymentgateways", "gateway", array("setting" => "name"), "order", "ASC"); $data = mysql_fetch_array($result); $gateway = $data['gateway']; $duedate = $finaldate = ""; if ($invoicetype == "deposit") { if ($depositduedate) { $duedate = toMySQLDate($depositduedate); } $finaldate = $finalduedate ? toMySQLDate($finalduedate) : date("Y-m-d"); } else { if ($invoiceduedate) { $duedate = toMySQLDate($invoiceduedate); } } if (!$duedate) { $duedate = date("Y-m-d"); } $invoiceid = insert_query("tblinvoices", array("date" => "now()", "duedate" => $duedate, "userid" => $userid, "status" => "Unpaid", "paymentmethod" => $gateway, "taxrate" => $taxrate, "taxrate2" => $taxrate2, "subtotal" => $subtotal, "tax" => $tax1, "tax2" => $tax2, "total" => $total, "notes" => $_LANG['quoteref'] . $id)); if ($finaldate) { $finalinvoiceid = insert_query("tblinvoices", array("date" => "now()", "duedate" => $finaldate, "userid" => $userid, "status" => "Unpaid", "paymentmethod" => $gateway, "taxrate" => $taxrate, "taxrate2" => $taxrate2, "subtotal" => $subtotal, "tax" => $tax1, "tax2" => $tax2, "total" => $total, "notes" => $_LANG['quoteref'] . $id)); } $result = select_query("tblquoteitems", "", array("quoteid" => $id), "id", "ASC"); while ($data = mysql_fetch_array($result)) { $line_id = $data['id']; $line_desc = $data['description']; $line_qty = $data['quantity']; $line_unitprice = $data['unitprice']; $line_discount = $data['discount']; $line_taxable = $data['taxable']; $line_total = format_as_currency($line_qty * $line_unitprice * (1 - $line_discount / 100)); $lineitemdesc = "" . $line_qty . " x " . $line_desc . " @ " . $line_unitprice; if (0 < $line_discount) { $lineitemdesc .= " - " . $line_discount . "% " . $_LANG['orderdiscount']; } if ($finalinvoiceid) { $originalamount = $line_total; $line_total = $originalamount * ($depositpercent / 100); $final_amount = $originalamount - $line_total; insert_query("tblinvoiceitems", array("invoiceid" => $finalinvoiceid, "userid" => $userid, "description" => $lineitemdesc . " (" . (100 - $depositpercent) . "% " . $_LANG['quotefinalpayment'] . ")", "amount" => $final_amount, "taxed" => $line_taxable)); $lineitemdesc .= " (" . $depositpercent . "% " . $_LANG['quotedeposit'] . ")"; } insert_query("tblinvoiceitems", array("invoiceid" => $invoiceid, "userid" => $userid, "description" => $lineitemdesc, "amount" => $line_total, "taxed" => $line_taxable)); } if (!function_exists("updateInvoiceTotal")) { require ROOTDIR . "/includes/invoicefunctions.php"; } updateInvoiceTotal($invoiceid); if ($finalinvoiceid) { updateInvoiceTotal($finalinvoiceid); } run_hook("InvoiceCreationPreEmail", array("invoiceid" => $invoiceid)); if ($finalinvoiceid) { run_hook("InvoiceCreationPreEmail", array("invoiceid" => $finalinvoiceid)); } if ($sendemail) { sendMessage("Invoice Created", $invoiceid); if ($finalinvoiceid) { sendMessage("Invoice Created", $finalinvoiceid); } } run_hook("InvoiceCreated", array("invoiceid" => $invoiceid)); if ($finalinvoiceid) { run_hook("InvoiceCreated", array("invoiceid" => $finalinvoiceid)); } if (1 < $CONFIG['InvoiceIncrement']) { $invoiceincrement = $CONFIG['InvoiceIncrement'] - 1; $counter = 1; while ($counter <= $invoiceincrement) { $tempinvoiceid = insert_query("tblinvoices", array("date" => "now()")); delete_query("tblinvoices", array("id" => $tempinvoiceid)); $counter += 1; } } update_query("tblquotes", array("userid" => $userid, "stage" => "Accepted"), array("id" => $id)); return $invoiceid; }
* @ Author : MTIMER * @ Release on : 2013-12-24 * @ Website : http://www.mtimer.cn * **/ if (!defined("WHMCS")) { exit("This file cannot be accessed directly"); } $PMRoleID = get_query_val("tbladmins", "roleid", array("id" => $_SESSION['adminid'])); if (!$vars["masteradmin" . $PMRoleID]) { echo $headeroutput . "\n<h2>Access Denied</h2>\n<p>You must be granted Master Admin User status in the Project Management Addon Configuration area within <strong><a href=\"configaddonmods.php#project_management\">Setup > Addon Modules</a></strong> before you are allowed to access this page.</p>"; return false; } if ($_POST['save']) { delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "hourlyrate")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "hourlyrate", "value" => format_as_currency($_POST['hourlyrate']))); delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "statusvalues")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "statusvalues", "value" => $_POST['statusvalues'])); delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "completedstatuses")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "completedstatuses", "value" => implode(",", $_POST['completestatus']))); delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "perms")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "perms", "value" => serialize($_POST['perms']))); delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "clientenable")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "clientenable", "value" => $_POST['clientenable'])); delete_query("tbladdonmodules", array("module" => "project_management", "setting" => "clientfeatures")); insert_query("tbladdonmodules", array("module" => "project_management", "setting" => "clientfeatures", "value" => implode(",", $_POST['clfeat']))); redir("module=project_management&m=settings"); } $adminroles = array(); $result = select_query("tbladminroles", "", "", "name", "ASC"); while ($data = mysql_fetch_array($result)) {
if (!$language) { $language = "english"; } if (!$template) { $template = "default"; } $acceptedcardtypes = $acceptedcctypes ? implode(",", $acceptedcctypes) : ""; $clientsprofoptional = $clientsprofoptional ? implode(",", $clientsprofoptional) : ""; $clientsprofuneditable = $clientsprofuneditable ? implode(",", $clientsprofuneditable) : ""; if ($tcpdffont != "helvetica" && $tcpdffont != "freesans" && $tcpdffontcustom) { $tcpdffont = $tcpdffontcustom; } $addfundsminimum = format_as_currency($addfundsminimum); $addfundsmaximum = format_as_currency($addfundsmaximum); $addfundsmaximumbalance = format_as_currency($addfundsmaximumbalance); $latefeeminimum = format_as_currency($latefeeminimum); $bulkchecktldsstring = $bulkchecktlds ? implode(",", $bulkchecktlds) : ""; if (!$whmcs->get_config("CCNeverStore") && $ccneverstore) { update_query("tblclients", array("cardtype" => "", "cardlastfour" => "", "cardnum" => "", "expdate" => "", "startdate" => "", "issuenumber" => "", "gatewayid" => ""), ""); } $domain = cleanSystemURL($domain); $systemurl = cleanSystemURL($systemurl); $systemsslurl = cleanSystemURL($systemsslurl, true, true); if (current(parse_url(cleanSystemURL($systemurl))) == current(parse_url(cleanSystemURL($systemsslurl)))) { $systemsslurl = ""; } $save_arr = array("CompanyName" => html_entity_decode($companyname), "Email" => $email, "Domain" => $domain, "LogoURL" => $logourl, "SystemURL" => $systemurl, "SystemSSLURL" => $systemsslurl, "Template" => $template, "MaintenanceModeURL" => $maintenancemodeurl, "ClientDateFormat" => $clientdateformat, "FreeDomainAutoRenewRequiresProduct" => $freedomainautorenewrequiresproduct, "DomainToDoListEntries" => $domaintodolistentries, "AllowIDNDomains" => $allowidndomains, "BulkCheckTLDs" => $bulkchecktldsstring, "DomainSyncEnabled" => $domainsyncenabled, "DomainSyncNextDueDate" => $domainsyncnextduedate, "DomainSyncNextDueDateDays" => $domainsyncnextduedatedays, "DomainSyncNotifyOnly" => $domainsyncnotifyonly, "DefaultNameserver1" => $ns1, "DefaultNameserver2" => $ns2, "DefaultNameserver3" => $ns3, "DefaultNameserver4" => $ns4, "DefaultNameserver5" => $ns5, "RegistrarAdminFirstName" => $domfirstname, "RegistrarAdminLastName" => $domlastname, "RegistrarAdminCompanyName" => $domcompanyname, "RegistrarAdminEmailAddress" => $domemail, "RegistrarAdminAddress1" => $domaddress1, "RegistrarAdminAddress2" => $domaddress2, "RegistrarAdminCity" => $domcity, "RegistrarAdminStateProvince" => $domstate, "RegistrarAdminPostalCode" => $dompostcode, "RegistrarAdminCountry" => $domcountry, "RegistrarAdminPhone" => $domphone, "RegistrarAdminUseClientDetails" => $domuseclientsdetails, "SMTPHost" => $smtphost, "SMTPUsername" => $smtpusername, "SMTPPassword" => encrypt(html_entity_decode($smtppassword)), "SMTPPort" => $smtpport, "SMTPSSL" => $smtpssl, "EmailGlobalHeader" => $emailglobalheader, "EmailGlobalFooter" => $emailglobalfooter, "BCCMessages" => $bccmessages, "ContactFormTo" => $contactformto, "ShowClientOnlyDepts" => $showclientonlydepts, "TicketFeedback" => $ticketfeedback, "TicketMask" => $ticketmask, "AttachmentThumbnails" => $attachmentthumbnails, "DownloadsIncludeProductLinked" => $dlinclproductdl, "CancelInvoiceOnCancellation" => $cancelinvoiceoncancel, "TCPDFFont" => $tcpdffont, "AddFundsEnabled" => $addfundsenabled, "AddFundsMinimum" => $addfundsminimum, "AddFundsMaximum" => $addfundsmaximum, "AddFundsMaximumBalance" => $addfundsmaximumbalance, "LateFeeMinimum" => $latefeeminimum, "AffiliateEnabled" => $affiliateenabled, "AffiliateEarningPercent" => $affiliateearningpercent, "AffiliateDepartment" => $affiliatedepartment, "AffiliateBonusDeposit" => $affiliatebonusdeposit, "AffiliatePayout" => $affiliatepayout, "AffiliatesDelayCommission" => $affiliatesdelaycommission, "AffiliateLinks" => $affiliatelinks, "CaptchaType" => $captchatype, "ReCAPTCHAPrivateKey" => $recaptchaprivatekey, "ReCAPTCHAPublicKey" => $recaptchapublickey, "AdminForceSSL" => $adminforcessl, "DisableAdminPWReset" => $disableadminpwreset, "CCNeverStore" => $ccneverstore, "TwitterUsername" => $twitterusername, "AnnouncementsTweet" => $announcementstweet, "AnnouncementsFBRecommend" => $announcementsfbrecommend, "AnnouncementsFBComments" => $announcementsfbcomments, "GooglePlus1" => $googleplus1, "ClientsProfileOptionalFields" => $clientsprofoptional, "ClientsProfileUneditableFields" => $clientsprofuneditable, "DefaultToClientArea" => $defaulttoclientarea, "AllowClientsEmailOptOut" => $allowclientsemailoptout, "BannedSubdomainPrefixes" => $bannedsubdomainprefixes, "DisplayErrors" => $displayerrors, "SQLErrorReporting" => $sqlerrorreporting); foreach ($save_arr as $k => $v) { $whmcs->set_config($k, trim($v)); } update_query("tblconfiguration", array("value" => $activitylimit), array("setting" => "ActivityLimit"));
$date = $data['date']; $duedate = $data['duedate']; $datepaid = $data['datepaid']; $subtotal = $data['subtotal']; $credit = $data['credit']; $tax = $data['tax']; $tax2 = $data['tax2']; $total = $data['total']; $taxrate = $data['taxrate']; $taxrate2 = $data['taxrate2']; $status = $data['status']; $paymentmethod = $data['paymentmethod']; $notes = $data['notes']; $result = select_query("tblaccounts", "SUM(amountin)-SUM(amountout)", array("invoiceid" => $invoiceid)); $data = mysql_fetch_array($result); $amountpaid = $data[0]; $balance = $total - $amountpaid; $balance = format_as_currency($balance); $gatewaytype = get_query_val("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "type")); $ccgateway = $gatewaytype == "CC" || $gatewaytype == "OfflineCC" ? true : false; $apiresults = array("result" => "success", "invoiceid" => $invoiceid, "invoicenum" => $invoicenum, "userid" => $userid, "date" => $date, "duedate" => $duedate, "datepaid" => $datepaid, "subtotal" => $subtotal, "credit" => $credit, "tax" => $tax, "tax2" => $tax2, "total" => $total, "balance" => $balance, "taxrate" => $taxrate, "taxrate2" => $taxrate2, "status" => $status, "paymentmethod" => $paymentmethod, "notes" => $notes, "ccgateway" => $ccgateway); $result = select_query("tblinvoiceitems", "", array("invoiceid" => $invoiceid)); while ($data = mysql_fetch_array($result)) { $apiresults['items']['item'][] = array("id" => $data['id'], "type" => $data['type'], "relid" => $data['relid'], "description" => $data['description'], "amount" => $data['amount'], "taxed" => $data['taxed']); } $apiresults['transactions'] = ""; $result = select_query("tblaccounts", "", array("invoiceid" => $invoiceid)); while ($data = mysql_fetch_assoc($result)) { $apiresults['transactions']['transaction'][] = $data; } $responsetype = "xml";
$tableformbuttons = "<input type=\"submit\" name=\"invoice\" value=\"" . $aInt->lang("billableitems", "invoicenextcronrun") . "\" onclick=\"return confirm('" . $aInt->lang("billableitems", "invoicenextcronrunconfirm", "1") . "')\" /> <input type=\"submit\" name=\"delete\" value=\"" . $aInt->lang("global", "delete") . "\" class=\"btn-danger\" onclick=\"return confirm('" . $aInt->lang("global", "deleteconfirm", "1") . "')\" />"; echo $aInt->sortableTable(array("checkall", array("id", $aInt->lang("fields", "id")), $aInt->lang("fields", "clientname"), array("description", $aInt->lang("fields", "description")), array("hours", $aInt->lang("billableitems", "hours")), array("amount", $aInt->lang("fields", "amount")), array("invoiceaction", $aInt->lang("billableitems", "invoiceaction")), array("invoicecount", $aInt->lang("status", "invoiced")), "", ""), $tabledata, $tableformurl, $tableformbuttons); } else { if ($action == "manage") { $jquery = ""; if ($id) { $pagetitle = $aInt->lang("billableitems", "edititem"); $result = select_query("tblbillableitems", "", array("id" => $id)); $data = mysql_fetch_array($result); $id = $data['id']; $userid = $data['userid']; $description = $data['description']; $hours = $data['hours']; $amount = $data['amount']; if ($hours != 0) { $amount = format_as_currency($amount / $hours); } $recur = $data['recur']; $recurcycle = $data['recurcycle']; $recurfor = $data['recurfor']; $invoiceaction = $data['invoiceaction']; $invoicecount = $data['invoicecount']; $duedate = fromMySQLDate($data['duedate']); } else { $pagetitle = $aInt->lang("billableitems", "additem"); $clientcheck = get_query_val("tblclients", "id", ""); if (!$clientcheck) { $aInt->gracefulExit($aInt->lang("billableitems", "noclientsmsg")); } $invoiceaction = 0; $recur = 0;
function InvoiceTotal($id) { global $CONFIG; $result = select_query("tblinvoiceitems", "", array("invoiceid" => $id)); while ($data = mysql_fetch_array($result)) { if ($data['taxed'] == "1") { $taxsubtotal += $data['amount']; } else { $nontaxsubtotal += $data['amount']; } } $subtotal = $total = $nontaxsubtotal + $taxsubtotal; $result = select_query("tblinvoices", "userid,credit,taxrate,taxrate2", array("id" => $id)); $data = mysql_fetch_array($result); $userid = $data['userid']; $credit = $data['credit']; $taxrate = $data['taxrate']; $taxrate2 = $data['taxrate2']; if (!function_exists("getClientsDetails")) { require_once dirname(__FILE__) . "/clientfunctions.php"; } $clientsdetails = getClientsDetails($userid); $tax = $tax2 = 0; if ($CONFIG['TaxEnabled'] == "on" && !$clientsdetails['taxexempt']) { if ($taxrate != "0.00") { if ($CONFIG['TaxType'] == "Inclusive") { $taxrate = $taxrate / 100 + 1; $calc1 = $taxsubtotal / $taxrate; $tax = $taxsubtotal - $calc1; } else { $taxrate = $taxrate / 100; $tax = $taxsubtotal * $taxrate; } } if ($taxrate2 != "0.00") { if ($CONFIG['TaxL2Compound']) { $taxsubtotal += $tax; } if ($CONFIG['TaxType'] == "Inclusive") { $taxrate2 = $taxrate2 / 100 + 1; $calc1 = $taxsubtotal / $taxrate2; $tax2 = $taxsubtotal - $calc1; } else { $taxrate2 = $taxrate2 / 100; $tax2 = $taxsubtotal * $taxrate2; } } $tax = round($tax, 2); $tax2 = round($tax2, 2); } if ($CONFIG['TaxType'] == "Inclusive") { $subtotal = $subtotal - $tax - $tax2; } else { $total = $subtotal + $tax + $tax2; } if (0 < $credit) { if ($total < $credit) { $total = 0; $remainingcredit = $total - $credit; } else { $total -= $credit; } } $subtotal = format_as_currency($subtotal); $tax = format_as_currency($tax); $total = format_as_currency($total); return $total; }
} if ($action == "deletereferral") { check_token("WHMCS.admin.default"); delete_query("tblaffiliatesaccounts", array("id" => $affaccid)); redir("action=edit&id=" . $id); exit; } if ($action == "deletewithdrawal") { check_token("WHMCS.admin.default"); delete_query("tblaffiliateswithdrawals", array("id" => $wid)); redir("action=edit&id=" . $id); exit; } if ($action == "addcomm") { check_token("WHMCS.admin.default"); $amount = format_as_currency($amount); insert_query("tblaffiliateshistory", array("affiliateid" => $id, "date" => toMySQLDate($date), "affaccid" => $refid, "description" => $description, "amount" => $amount)); update_query("tblaffiliates", array("balance" => "+=" . $amount), array("id" => (int) $id)); redir("action=edit&id=" . $id); exit; } if ($action == "withdraw") { check_token("WHMCS.admin.default"); insert_query("tblaffiliateswithdrawals", array("affiliateid" => $id, "date" => "now()", "amount" => $amount)); update_query("tblaffiliates", array("balance" => "-=" . $amount, "withdrawn" => "+=" . $amount), array("id" => (int) $id)); if ($payouttype == "1") { $result = select_query("tblaffiliates", "", array("id" => (int) $id)); $data = mysql_fetch_array($result); $id = (int) $data['id']; $clientid = (int) $data['clientid']; addTransaction($clientid, "", "Affiliate Commissions Withdrawal Payout", "0", "0", $amount, $paymentmethod, $transid);
$str = substr($str, 0, $randomnum) . substr($str, $randomnum + 1); ++$i; } echo $password; exit; } if ($action == "save") { check_token("WHMCS.admin.default"); checkPermission("Create/Edit Promotions"); $code = trim($code); $startdate = $startdate == "" ? "00000000" : toMySQLDate($startdate); $expirationdate = $expirationdate == "" ? "00000000" : toMySQLDate($expirationdate); $cycles = is_array($cycles) ? implode(",", $cycles) : ""; $appliesto = is_array($appliesto) ? implode(",", $appliesto) : ""; $requires = is_array($requires) ? implode(",", $requires) : ""; $upgradeconfig = serialize(array("value" => format_as_currency($upgradevalue), "type" => $upgradetype, "discounttype" => $upgradediscounttype, "configoptions" => $configoptionupgrades)); if ($id) { update_query("tblpromotions", array("code" => $code, "type" => $type, "recurring" => $recurring, "value" => $pvalue, "cycles" => $cycles, "appliesto" => $appliesto, "requires" => $requires, "requiresexisting" => $requiresexisting, "startdate" => $startdate, "expirationdate" => $expirationdate, "maxuses" => $maxuses, "lifetimepromo" => $lifetimepromo, "applyonce" => $applyonce, "newsignups" => $newsignups, "existingclient" => $existingclient, "onceperclient" => $onceperclient, "recurfor" => $recurfor, "upgrades" => $upgrades, "upgradeconfig" => $upgradeconfig, "notes" => $notes), array("id" => $id)); redir("updated=true"); } else { $result = select_query("tblpromotions", "COUNT(*)", array("code" => $code)); $data = mysql_fetch_array($result); $duplicates = $data[0]; $newid = insert_query("tblpromotions", array("code" => $code, "type" => $type, "recurring" => $recurring, "value" => $pvalue, "cycles" => $cycles, "appliesto" => $appliesto, "requires" => $requires, "requiresexisting" => $requiresexisting, "startdate" => $startdate, "expirationdate" => $expirationdate, "maxuses" => $maxuses, "lifetimepromo" => $lifetimepromo, "applyonce" => $applyonce, "newsignups" => $newsignups, "existingclient" => $existingclient, "onceperclient" => $onceperclient, "recurfor" => $recurfor, "upgrades" => $upgrades, "upgradeconfig" => $upgradeconfig, "notes" => $notes)); if ($duplicates) { redir("action=manage&id=" . $newid); } else { redir("created=true"); } } exit;
function calcCartTotals($checkout = "", $ignorenoconfig = "") { global $CONFIG; global $_LANG; global $remote_ip; global $currency; global $promo_data; $cart_total = $cart_discount = $cart_tax = 0; run_hook("PreCalculateCartTotals", $_SESSION['cart']); if (!$ignorenoconfig) { if (array_key_exists("products", $_SESSION['cart'])) { foreach ($_SESSION['cart']['products'] as $key => $productdata) { if ($productdata['noconfig']) { unset($_SESSION['cart']['products'][$key]); continue; } } } $bundlewarnings = bundlesValidateCheckout(); if (array_key_exists("products", $_SESSION['cart'])) { $_SESSION['cart']['products'] = array_values($_SESSION['cart']['products']); } } if ($checkout) { if (!$_SESSION['cart']) { return false; } run_hook("PreShoppingCartCheckout", $_SESSION['cart']); $order_number = generateUniqueID(); $paymentmethod = $_SESSION['cart']['paymentmethod']; $availablegateways = getAvailableOrderPaymentGateways(); if (!array_key_exists($paymentmethod, $availablegateways)) { foreach ($availablegateways as $k => $v) { $paymentmethod = $k; break; } } $userid = $_SESSION['uid']; $ordernotes = ""; if ($_SESSION['cart']['notes'] && $_SESSION['cart']['notes'] != $_LANG['ordernotesdescription']) { $ordernotes = $_SESSION['cart']['notes']; } $cartitems = count($_SESSION['cart']['products']) + count($_SESSION['cart']['addons']) + count($_SESSION['cart']['domains']) + count($_SESSION['cart']['renewals']); if (!$cartitems) { return false; } $orderid = insert_query("tblorders", array("ordernum" => $order_number, "userid" => $userid, "contactid" => $_SESSION['cart']['contact'], "date" => "now()", "status" => "Pending", "paymentmethod" => $paymentmethod, "ipaddress" => $remote_ip, "notes" => $ordernotes)); logActivity("New Order Placed - Order ID: " . $orderid . " - User ID: " . $userid); $domaineppcodes = array(); } $promotioncode = array_key_exists("promo", $_SESSION['cart']) ? $_SESSION['cart']['promo'] : ""; if ($promotioncode) { $result = select_query("tblpromotions", "", array("code" => $promotioncode)); $promo_data = mysql_fetch_array($result); } if (!isset($_SESSION['uid'])) { if (!$_SESSION['cart']['user']['country']) { $_SESSION['cart']['user']['country'] = $CONFIG['DefaultCountry']; } $state = $_SESSION['cart']['user']['state']; $country = $_SESSION['cart']['user']['country']; } else { $clientsdetails = getClientsDetails($_SESSION['uid']); $state = $clientsdetails['state']; $country = $clientsdetails['country']; } if ($CONFIG['TaxEnabled']) { $taxdata = getTaxRate(1, $state, $country); $taxname = $taxdata['name']; $taxrate = $taxdata['rate']; $rawtaxrate = $taxrate; $inctaxrate = $taxrate / 100 + 1; $taxrate /= 100; $taxdata = getTaxRate(2, $state, $country); $taxname2 = $taxdata['name']; $taxrate2 = $taxdata['rate']; $rawtaxrate2 = $taxrate2; $inctaxrate2 = $taxrate2 / 100 + 1; $taxrate2 /= 100; } if ($CONFIG['TaxInclusiveDeduct'] && (!$taxrate && !$taxrate2 || $clientsdetails['taxexempt'])) { $result = select_query("tbltax", "", ""); $data = mysql_fetch_array($result); $excltaxrate = 1 + $data['taxrate'] / 100; } else { $CONFIG['TaxInclusiveDeduct'] = 0; } $cartdata = $productsarray = $tempdomains = $orderproductids = $orderdomainids = $orderaddonids = $orderrenewalids = $freedomains = array(); $recurring_cycles_total = array("monthly" => 0, "quarterly" => 0, "semiannually" => 0, "annually" => 0, "biennially" => 0, "triennially" => 0); if (array_key_exists("products", $_SESSION['cart']) && is_array($_SESSION['cart']['products'])) { foreach ($_SESSION['cart']['products'] as $key => $productdata) { $result = select_query("tblproducts", "tblproducts.id,tblproducts.gid,tblproductgroups.name AS groupname,tblproducts.name,tblproducts.paytype,tblproducts.allowqty,tblproducts.proratabilling,tblproducts.proratadate,tblproducts.proratachargenextmonth,tblproducts.tax,tblproducts.servertype,tblproducts.servergroup,tblproducts.stockcontrol,tblproducts.freedomain,tblproducts.freedomainpaymentterms,tblproducts.freedomaintlds", array("tblproducts.id" => $productdata['pid']), "", "", "", "tblproductgroups ON tblproductgroups.id=tblproducts.gid"); $data = mysql_fetch_array($result); $pid = $data['id']; $gid = $data['gid']; $groupname = $data['groupname']; $productname = $data['name']; $paytype = $data['paytype']; $allowqty = $data['allowqty']; $proratabilling = $data['proratabilling']; $proratadate = $data['proratadate']; $proratachargenextmonth = $data['proratachargenextmonth']; $tax = $data['tax']; $servertype = $data['servertype']; $servergroup = $data['servergroup']; $stockcontrol = $data['stockcontrol']; $freedomain = $data['freedomain']; if ($freedomain) { $freedomainpaymentterms = $data['freedomainpaymentterms']; $freedomaintlds = $data['freedomaintlds']; $freedomainpaymentterms = explode(",", $freedomainpaymentterms); $freedomaintlds = explode(",", $freedomaintlds); } else { $freedomainpaymentterms = $freedomaintlds = array(); } $productinfo = getProductInfo($pid); $productdata['productinfo'] = $productinfo; if (!function_exists("getCustomFields")) { require ROOTDIR . "/includes/customfieldfunctions.php"; } $customfields = getCustomFields("product", $pid, "", true, "", $productdata['customfields']); $productdata['customfields'] = $customfields; $pricing = getPricingInfo($pid); $qty = $productdata['qty']; if (!$allowqty || !$qty) { $qty = 1; } $productdata['allowqty'] = $allowqty; $productdata['qty'] = $qty; if ($pricing['type'] == "recurring") { $billingcycle = strtolower($productdata['billingcycle']); if (!in_array($billingcycle, array("monthly", "quarterly", "semiannually", "annually", "biennially", "triennially"))) { $billingcycle = ""; } if ($pricing['rawpricing'][$billingcycle] < 0) { $billingcycle = ""; } if (!$billingcycle) { if (0 <= $pricing['rawpricing']['monthly']) { $billingcycle = "monthly"; } else { if (0 <= $pricing['rawpricing']['quarterly']) { $billingcycle = "quarterly"; } else { if (0 <= $pricing['rawpricing']['semiannually']) { $billingcycle = "semiannually"; } else { if (0 <= $pricing['rawpricing']['annually']) { $billingcycle = "annually"; } else { if (0 <= $pricing['rawpricing']['biennially']) { $billingcycle = "biennially"; } else { if (0 <= $pricing['rawpricing']['triennially']) { $billingcycle = "triennially"; } } } } } } } } else { if ($pricing['type'] == "onetime") { $billingcycle = "onetime"; } else { $billingcycle = "free"; } } $productdata['billingcycle'] = $billingcycle; if ($billingcycle == "free") { $product_setup = $product_onetime = $product_recurring = "0"; $databasecycle = "Free Account"; } else { if ($billingcycle == "onetime") { $product_setup = $pricing['rawpricing']['msetupfee']; $product_onetime = $pricing['rawpricing']['monthly']; $product_recurring = 0; $databasecycle = "One Time"; } else { $product_setup = $pricing['rawpricing'][substr($billingcycle, 0, 1) . "setupfee"]; $product_onetime = $product_recurring = $pricing['rawpricing'][$billingcycle]; $databasecycle = ucfirst($billingcycle); if ($databasecycle == "Semiannually") { $databasecycle = "Semi-Annually"; } } } $before_priceoverride_value = ""; if ($bundleoverride = bundlesGetProductPriceOverride("product", $key)) { $before_priceoverride_value = $product_setup + $product_onetime; $product_setup = 0; $product_onetime = $product_recurring = $bundleoverride; } $hookret = run_hook("OrderProductPricingOverride", array("key" => $key, "pid" => $pid, "proddata" => $productdata)); foreach ($hookret as $hookret2) { if (is_array($hookret2)) { if ($hookret2['setup']) { $product_setup = $hookret2['setup']; } if ($hookret2['recurring']) { $product_onetime = $product_recurring = $hookret2['recurring']; continue; } continue; } } $productdata['pricing']['baseprice'] = formatCurrency($product_onetime); $configurableoptions = array(); $configurableoptions = getCartConfigOptions($pid, $productdata['configoptions'], $billingcycle); $configoptions = ""; if ($configurableoptions) { foreach ($configurableoptions as $confkey => $value) { $configoptions[] = array("name" => $value['optionname'], "type" => $value['optiontype'], "option" => $value['selectedoption'], "optionname" => $value['selectedname'], "setup" => 0 < $value['selectedsetup'] ? formatCurrency($value['selectedsetup']) : "", "recurring" => formatCurrency($value['selectedrecurring']), "qty" => $value['selectedqty']); $configoptionsdb[$value['id']] = array("value" => $value['selectedvalue'], "qty" => $value['selectedqty']); $product_setup += $value['selectedsetup']; $product_onetime += $value['selectedrecurring']; if (strlen($before_priceoverride_value)) { $before_priceoverride_value += $value['selectedrecurring']; } if ($billingcycle != "onetime") { $product_recurring += $value['selectedrecurring']; continue; } } } $productdata['configoptions'] = $configoptions; if (in_array($billingcycle, $freedomainpaymentterms)) { $domain = $productdata['domain']; $domainparts = explode(".", $domain, 2); $tld = "." . $domainparts[1]; if (in_array($tld, $freedomaintlds)) { $freedomains[$domain] = $freedomain; } } if ($proratabilling) { $proratavalues = getProrataValues($billingcycle, $product_onetime, $proratadate, $proratachargenextmonth, date("d"), date("m"), date("Y"), $_SESSION['uid']); $product_onetime = $proratavalues['amount']; $productdata['proratadate'] = fromMySQLDate($proratavalues['date']); } if ($CONFIG['TaxInclusiveDeduct']) { $product_setup = format_as_currency($product_setup / $excltaxrate); $product_onetime = format_as_currency($product_onetime / $excltaxrate); $product_recurring = format_as_currency($product_recurring / $excltaxrate); } $product_total_today_db = $product_setup + $product_onetime; $product_recurring_db = $product_recurring; $productdata['pricing']['setup'] = $product_setup * $qty; $productdata['pricing']['recurring'][$billingcycle] = $product_recurring * $qty; $productdata['pricing']['totaltoday'] = $product_total_today_db * $qty; if ($product_onetime == 0 && $product_recurring == 0) { $pricing_text = $_LANG['orderfree']; } else { $pricing_text = ""; if (strlen($before_priceoverride_value)) { $pricing_text .= "<strike>" . formatCurrency($before_priceoverride_value) . "</strike> "; } $pricing_text .= formatCurrency($product_onetime); if (0 < $product_setup) { $pricing_text .= " + " . formatCurrency($product_setup) . " " . $_LANG['ordersetupfee']; } if ($allowqty && 1 < $qty) { $pricing_text .= $_LANG['invoiceqtyeach'] . "<br />" . $_LANG['invoicestotal'] . ": " . formatCurrency($productdata['pricing']['totaltoday']); } } $productdata['pricingtext'] = $pricing_text; if ($promotioncode) { $onetimediscount = $recurringdiscount = $promoid = 0; if ($promocalc = CalcPromoDiscount($pid, $databasecycle, $product_total_today_db, $product_recurring_db, $product_setup)) { $onetimediscount = $promocalc['onetimediscount']; $recurringdiscount = $promocalc['recurringdiscount']; $product_total_today_db -= $onetimediscount; $product_recurring_db -= $recurringdiscount; $cart_discount += $onetimediscount * $qty; $promoid = $promo_data['id']; } } if (isset($productdata['priceoverride'])) { $product_total_today_db = $product_recurring_db = $product_onetime = $productdata['priceoverride']; $product_setup = 0; } $cart_total += $product_total_today_db * $qty; $product_total_qty_recurring = $product_recurring_db * $qty; if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt']) { $cart_tax += $product_total_today_db * $qty; if ($CONFIG['TaxType'] == "Exclusive") { if ($CONFIG['TaxL2Compound']) { $product_total_qty_recurring += $product_total_qty_recurring * $taxrate; $product_total_qty_recurring += $product_total_qty_recurring * $taxrate2; } else { $product_total_qty_recurring += $product_total_qty_recurring * $taxrate + $product_total_qty_recurring * $taxrate2; } } } $recurring_cycles_total[$billingcycle] += $product_total_qty_recurring; $domain = $productdata['domain']; $serverhostname = $productdata['server']['hostname']; $serverns1prefix = $productdata['server']['ns1prefix']; $serverns2prefix = $productdata['server']['ns2prefix']; $serverrootpw = encrypt($productdata['server']['rootpw']); if ($serverns1prefix && $domain) { $serverns1prefix = $serverns1prefix . "." . $domain; } if ($serverns2prefix && $domain) { $serverns2prefix = $serverns2prefix . "." . $domain; } if ($serverhostname) { $domain = $domain ? $serverhostname . "." . $domain : $serverhostname; } $productdata['domain'] = $domain; if ($checkout) { $multiqtyids = array(); $qtycount = 1; while ($qtycount <= $qty) { $serverid = $servertype ? getServerID($servertype, $servergroup) : "0"; $hostingquerydates = $databasecycle == "Free Account" ? "0000-00-00" : date("Y-m-d"); $serviceid = insert_query("tblhosting", array("userid" => $userid, "orderid" => $orderid, "packageid" => $pid, "server" => $serverid, "regdate" => "now()", "domain" => $domain, "paymentmethod" => $paymentmethod, "firstpaymentamount" => $product_total_today_db, "amount" => $product_recurring_db, "billingcycle" => $databasecycle, "nextduedate" => $hostingquerydates, "nextinvoicedate" => $hostingquerydates, "domainstatus" => "Pending", "ns1" => $serverns1prefix, "ns2" => $serverns2prefix, "password" => $serverrootpw, "promoid" => $promoid)); $multiqtyids[$qtycount] = $serviceid; $orderproductids[] = $serviceid; if ($stockcontrol) { full_query("UPDATE tblproducts SET qty=qty-1 WHERE id='" . mysql_real_escape_string($pid) . "'"); } if ($configoptionsdb) { foreach ($configoptionsdb as $key => $value) { insert_query("tblhostingconfigoptions", array("relid" => $serviceid, "configid" => $key, "optionid" => $value['value'], "qty" => $value['qty'])); } } foreach ($productdata['customfields'] as $key => $value) { insert_query("tblcustomfieldsvalues", array("fieldid" => $value['id'], "relid" => $serviceid, "value" => $value['rawvalue'])); } $productdetails = getInvoiceProductDetails($serviceid, $pid, date("Y-m-d"), $hostingquerydates, $databasecycle, $domain); $invoice_description = $productdetails['description']; $invoice_tax = $productdetails['tax']; if (!$_SESSION['cart']['geninvoicedisabled']) { $prodinvoicearray = array(); $prodinvoicearray['userid'] = $userid; $prodinvoicearray['type'] = "Hosting"; $prodinvoicearray['relid'] = $serviceid; $prodinvoicearray['taxed'] = $invoice_tax; $prodinvoicearray['duedate'] = $hostingquerydates; $prodinvoicearray['paymentmethod'] = $paymentmethod; if (0 < $product_setup) { $prodinvoicearray['description'] = $productname . " " . $_LANG['ordersetupfee']; $prodinvoicearray['amount'] = $product_setup; insert_query("tblinvoiceitems", $prodinvoicearray); $prodinvoicearray['type'] = ""; $prodinvoicearray['relid'] = 0; } if (0 < $product_onetime) { $prodinvoicearray['description'] = $invoice_description; $prodinvoicearray['amount'] = $product_onetime; insert_query("tblinvoiceitems", $prodinvoicearray); } $promovals = getInvoiceProductPromo($product_total_today_db, $promoid, $userid, $serviceid, $product_setup + $product_onetime); if ($promovals['description']) { $prodinvoicearray['type'] = "PromoHosting"; $prodinvoicearray['description'] = $promovals['description']; $prodinvoicearray['amount'] = $promovals['amount']; insert_query("tblinvoiceitems", $prodinvoicearray); } } $adminemailitems .= $_LANG['orderproduct'] . (": " . $groupname . " - " . $productname . "<br>\r\n"); if ($domain) { $adminemailitems .= $_LANG['orderdomain'] . (": " . $domain . "<br>\r\n"); } foreach ($configurableoptions as $confkey => $value) { $adminemailitems .= $value['optionname'] . ": " . $value['selectedname'] . "<br />\r\n"; } foreach ($customfields as $customfield) { if (!$customfield['adminonly']) { $adminemailitems .= "" . $customfield['name'] . ": " . $customfield['value'] . "<br />\r\n"; continue; } } $adminemailitems .= $_LANG['firstpaymentamount'] . ": " . formatCurrency($product_total_today_db) . "<br>\r\n"; if ($product_recurring_db) { $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($product_recurring_db) . "<br>\r\n"; } $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($databasecycle))] . "<br>\r\n"; if ($allowqty && 1 < $qty) { $adminemailitems .= $_LANG['quantity'] . (": " . $qty . "<br>\r\n") . $_LANG['invoicestotal'] . ": " . $productdata['pricing']['totaltoday'] . "<br>\r\n"; } $adminemailitems .= "<br>\r\n"; ++$qtycount; } } $addonsarray = array(); $addons = $productdata['addons']; if ($addons) { foreach ($addons as $addonid) { $result = select_query("tbladdons", "name,description,billingcycle,tax", array("id" => $addonid)); $data = mysql_fetch_array($result); $addon_name = $data['name']; $addon_description = $data['description']; $addon_billingcycle = $data['billingcycle']; $addon_tax = $data['tax']; if (!$CONFIG['TaxEnabled']) { $addon_tax = ""; } $result = select_query("tblpricing", "msetupfee,monthly", array("type" => "addon", "currency" => $currency['id'], "relid" => $addonid)); $data = mysql_fetch_array($result); $addon_setupfee = $data['msetupfee']; $addon_recurring = $data['monthly']; $hookret = run_hook("OrderAddonPricingOverride", array("key" => $key, "pid" => $pid, "addonid" => $addonid, "proddata" => $productdata)); foreach ($hookret as $hookret2) { if (is_array($hookret2)) { if ($hookret2['setup']) { $addon_setupfee = $hookret2['setup']; } if ($hookret2['recurring']) { $addon_recurring = $hookret2['recurring']; continue; } continue; } } $addon_total_today_db = $addon_setupfee + $addon_recurring; $addon_recurring_db = $addon_recurring; $addon_total_today = $addon_total_today_db * $qty; if ($CONFIG['TaxInclusiveDeduct']) { $addon_total_today_db = round($addon_total_today_db / $excltaxrate, 2); $addon_recurring_db = round($addon_recurring_db / $excltaxrate, 2); } if ($promotioncode) { $onetimediscount = $recurringdiscount = $promoid = 0; if ($promocalc = CalcPromoDiscount("A" . $addonid, $addon_billingcycle, $addon_total_today_db, $addon_recurring_db, $addon_setupfee)) { $onetimediscount = $promocalc['onetimediscount']; $recurringdiscount = $promocalc['recurringdiscount']; $addon_total_today_db -= $onetimediscount; $addon_recurring_db -= $recurringdiscount; $cart_discount += $onetimediscount * $qty; } } if ($checkout) { $qtycount = 1; while ($qtycount <= $qty) { $serviceid = $multiqtyids[$qtycount]; $addonsetupfee = $addon_total_today_db - $addon_recurring_db; $aid = insert_query("tblhostingaddons", array("hostingid" => $serviceid, "addonid" => $addonid, "orderid" => $orderid, "regdate" => "now()", "name" => "", "setupfee" => $addonsetupfee, "recurring" => $addon_recurring_db, "billingcycle" => $addon_billingcycle, "status" => "Pending", "nextduedate" => "now()", "nextinvoicedate" => "now()", "paymentmethod" => $paymentmethod, "tax" => $addon_tax)); $orderaddonids[] = $aid; $adminemailitems .= $_LANG['clientareaaddon'] . (": " . $addon_name . "<br>\r\n") . $_LANG['ordersetupfee'] . ": " . formatCurrency($addonsetupfee) . "<br>\r\n"; if ($addon_recurring_db) { $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($addon_recurring_db) . "<br>\r\n"; } $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($addon_billingcycle))] . "<br>\r\n<br>\r\n"; ++$qtycount; } } $addon_total_today_db *= $qty; $cart_total += $addon_total_today_db; $addon_recurring_db *= $qty; if ($addon_tax && !$clientsdetails['taxexempt']) { $cart_tax += $addon_total_today_db; if ($CONFIG['TaxType'] == "Exclusive") { if ($CONFIG['TaxL2Compound']) { $addon_recurring_db += $addon_recurring_db * $taxrate; $addon_recurring_db += $addon_recurring_db * $taxrate2; } else { $addon_recurring_db += $addon_recurring_db * $taxrate + $addon_recurring_db * $taxrate2; } } } $addon_billingcycle = str_replace(array("-", " "), "", strtolower($addon_billingcycle)); $recurring_cycles_total[$addon_billingcycle] += $addon_recurring_db; if ($addon_setupfee == "0" && $addon_recurring == "0") { $pricing_text = $_LANG['orderfree']; } else { $pricing_text = formatCurrency($addon_recurring); if ($addon_setupfee != "0.00") { $pricing_text .= " + " . formatCurrency($addon_setupfee) . " " . $_LANG['ordersetupfee']; } if ($allowqty && 1 < $qty) { $pricing_text .= $_LANG['invoiceqtyeach'] . "<br />" . $_LANG['invoicestotal'] . ": " . formatCurrency($addon_total_today); } } $addonsarray[] = array("name" => $addon_name, "pricingtext" => $pricing_text, "setup" => formatCurrency($addon_setupfee), "recurring" => formatCurrency($addon_recurring), "totaltoday" => formatCurrency($addon_total_today)); $productdata['pricing']['setup'] += $addon_setupfee * $qty; $productdata['pricing']['addons'] += $addon_recurring * $qty; $productdata['pricing']['recurring'][$addon_billingcycle] += $addon_recurring * $qty; $productdata['pricing']['totaltoday'] += $addon_total_today; } } $productdata['addons'] = $addonsarray; $totaltaxrates = 1; if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt']) { $product_tax = $productdata['pricing']['totaltoday']; if ($CONFIG['TaxType'] == "Inclusive") { $totaltaxrates = 1 + ($taxrate + $taxrate2); $total_without_tax = $productdata['pricing']['totaltoday'] = $product_tax / $totaltaxrates; $total_tax_1 = $total_without_tax * $taxrate; $total_tax_2 = $total_without_tax * $taxrate2; } else { $total_tax_1 = $product_tax * $taxrate; if ($CONFIG['TaxL2Compound']) { $total_tax_2 = ($product_tax + $total_tax_1) * $taxrate2; } else { $total_tax_2 = $product_tax * $taxrate2; } } $total_tax_1 = round($total_tax_1, 2); $total_tax_2 = round($total_tax_2, 2); $productdata['pricing']['totaltoday'] += $total_tax_1 + $total_tax_2; if (0 < $total_tax_1) { $productdata['pricing']['tax1'] = formatCurrency($total_tax_1); } if (0 < $total_tax_2) { $productdata['pricing']['tax2'] = formatCurrency($total_tax_2); } } $productdata['pricing']['setup'] = formatCurrency($productdata['pricing']['setup']); foreach ($productdata['pricing']['recurring'] as $cycle => $recurring) { unset($productdata['pricing']['recurring'][$cycle]); if (0 < $recurring) { $recurringwithtax = $recurring; if ($CONFIG['TaxEnabled'] && $tax && !$clientsdetails['taxexempt'] && $CONFIG['TaxType'] == "Exclusive") { $rectax = $recurringwithtax * $taxrate; if ($CONFIG['TaxL2Compound']) { $rectax += ($recurringwithtax + $rectax) * $taxrate2; } else { $rectax += $recurringwithtax * $taxrate2; } $recurringwithtax += $rectax; } $productdata['pricing']['recurring'][$_LANG["orderpaymentterm" . $cycle]] = formatCurrency($recurringwithtax); $productdata['pricing']['recurringexcltax'][$_LANG["orderpaymentterm" . $cycle]] = formatCurrency($recurring / $totaltaxrates); continue; } } if (0 < $productdata['pricing']['addons']) { $productdata['pricing']['addons'] = formatCurrency($productdata['pricing']['addons']); } $productdata['pricing']['totaltoday'] = formatCurrency($productdata['pricing']['totaltoday']); $productsarray[$key] = $productdata; } } $cartdata['products'] = $productsarray; $addonsarray = array(); if (array_key_exists("addons", $_SESSION['cart']) && is_array($_SESSION['cart']['addons'])) { foreach ($_SESSION['cart']['addons'] as $key => $addon) { $addonid = $addon['id']; $serviceid = $addon['productid']; $result = select_query("tbladdons", "name,description,billingcycle,tax", array("id" => $addonid)); $data = mysql_fetch_array($result); $addon_name = $data['name']; $addon_description = $data['description']; $addon_billingcycle = $data['billingcycle']; $addon_tax = $data['tax']; if (!$CONFIG['TaxEnabled']) { $addon_tax = ""; } $result = select_query("tblpricing", "msetupfee,monthly", array("type" => "addon", "currency" => $currency['id'], "relid" => $addonid)); $data = mysql_fetch_array($result); $addon_setupfee = $data['msetupfee']; $addon_recurring = $data['monthly']; $hookret = run_hook("OrderAddonPricingOverride", array("key" => $key, "addonid" => $addonid, "serviceid" => $serviceid)); foreach ($hookret as $hookret2) { if (strlen($hookret2)) { if ($hookret2['setup']) { $addon_setupfee = $hookret2['setup']; } if ($hookret2['recurring']) { $addon_recurring = $hookret2['recurring']; continue; } continue; } } $addon_total_today_db = $addon_setupfee + $addon_recurring; $addon_recurring_db = $addon_recurring; if ($CONFIG['TaxInclusiveDeduct']) { $addon_total_today_db = round($addon_total_today_db / $excltaxrate, 2); $addon_recurring_db = round($addon_recurring_db / $excltaxrate, 2); } if ($promotioncode) { $onetimediscount = $recurringdiscount = $promoid = 0; if ($promocalc = CalcPromoDiscount("A" . $addonid, $addon_billingcycle, $addon_total_today_db, $addon_recurring_db, $addon_setupfee)) { $onetimediscount = $promocalc['onetimediscount']; $recurringdiscount = $promocalc['recurringdiscount']; $addon_total_today_db -= $onetimediscount; $addon_recurring_db -= $recurringdiscount; $cart_discount += $onetimediscount; } } if ($checkout) { $addonsetupfee = $addon_total_today_db - $addon_recurring_db; $aid = insert_query("tblhostingaddons", array("hostingid" => $serviceid, "addonid" => $addonid, "orderid" => $orderid, "regdate" => "now()", "name" => "", "setupfee" => $addonsetupfee, "recurring" => $addon_recurring_db, "billingcycle" => $addon_billingcycle, "status" => "Pending", "nextduedate" => "now()", "nextinvoicedate" => "now()", "paymentmethod" => $paymentmethod, "tax" => $addon_tax)); $orderaddonids[] = $aid; $adminemailitems .= $_LANG['clientareaaddon'] . (": " . $addon_name . "<br>\r\n") . $_LANG['ordersetupfee'] . ": " . formatCurrency($addonsetupfee) . "<br>\r\n"; if ($addon_recurring_db) { $adminemailitems .= $_LANG['recurringamount'] . ": " . formatCurrency($addon_recurring_db) . "<br>\r\n"; } $adminemailitems .= $_LANG['orderbillingcycle'] . ": " . $_LANG["orderpaymentterm" . str_replace(array("-", " "), "", strtolower($addon_billingcycle))] . "<br>\r\n<br>\r\n"; } $cart_total += $addon_total_today_db; if ($addon_tax && !$clientsdetails['taxexempt']) { $cart_tax += $addon_total_today_db; if ($CONFIG['TaxType'] == "Exclusive") { if ($CONFIG['TaxL2Compound']) { $addon_recurring_db += $addon_recurring_db * $taxrate; $addon_recurring_db += $addon_recurring_db * $taxrate2; } else { $addon_recurring_db = $addon_recurring_db + $addon_recurring_db * $taxrate + $addon_recurring_db * $taxrate2; } } } $addon_billingcycle = str_replace(array("-", " "), "", strtolower($addon_billingcycle)); $recurring_cycles_total[$addon_billingcycle] += $addon_recurring_db; if ($addon_setupfee == "0" && $addon_recurring == "0") { $pricing_text = $_LANG['orderfree']; } else { $pricing_text = formatCurrency($addon_recurring); if ($addon_setupfee != "0.00") { $pricing_text .= " + " . formatCurrency($addon_setupfee) . " " . $_LANG['ordersetupfee']; } } $result = select_query("tblhosting", "tblproducts.name,tblhosting.domain", array("tblhosting.id" => $serviceid), "", "", "", "tblproducts ON tblproducts.id=tblhosting.packageid"); $data = mysql_fetch_array($result); $productname = $data['name']; $domainname = $data['domain']; $addonsarray[] = array("name" => $addon_name, "productname" => $productname, "domainname" => $domainname, "pricingtext" => $pricing_text); } $cartdata['addons'] = $addonsarray; } include ROOTDIR . "/includes/additionaldomainfields.php"; $totaldomainprice = 0; if (array_key_exists("domains", $_SESSION['cart']) && is_array($_SESSION['cart']['domains'])) { $result = select_query("tblpricing", "", array("type" => "domainaddons", "currency" => $currency['id'], "relid" => 0)); $data = mysql_fetch_array($result); $domaindnsmanagementprice = $data['msetupfee']; $domainemailforwardingprice = $data['qsetupfee']; $domainidprotectionprice = $data['ssetupfee']; foreach ($_SESSION['cart']['domains'] as $key => $domain) { $domaintype = $domain['type']; $domainname = $domain['domain']; $regperiod = $domain['regperiod']; $domainparts = explode(".", $domainname, 2); $sld = $domainparts[0]; $tld = $domainparts[1]; $temppricelist = getTLDPriceList("." . $tld); if (!isset($temppricelist[$regperiod][$domaintype])) { $tldyears = array_keys($temppricelist); $regperiod = $tldyears[0]; } if (!isset($temppricelist[$regperiod][$domaintype])) { exit("Invalid TLD/Registration Period Supplied for Domain Registration"); } if (array_key_exists($domainname, $freedomains)) { $tldyears = array_keys($temppricelist); $regperiod = $tldyears[0]; $domainprice = "0.00"; $renewprice = $freedomains[$domainname] == "once" ? $temppricelist[$regperiod]['renew'] : ($renewprice = "0.00"); } else { $domainprice = $temppricelist[$regperiod][$domaintype]; $renewprice = $temppricelist[$regperiod]['renew']; } $before_priceoverride_value = ""; if ($bundleoverride = bundlesGetProductPriceOverride("domain", $key)) { $before_priceoverride_value = $domainprice; $domainprice = $renewprice = $bundleoverride; } $hookret = run_hook("OrderDomainPricingOverride", array("type" => $domaintype, "domain" => $domainname, "regperiod" => $regperiod, "dnsmanagement" => $domain['dnsmanagement'], "emailforwarding" => $domain['emailforwarding'], "idprotection" => $domain['idprotection'], "eppcode" => html_entity_decode($domain['eppcode']))); foreach ($hookret as $hookret2) { if (strlen($hookret2)) { $before_priceoverride_value = $domainprice; $domainprice = $hookret2; continue; } } if ($domain['dnsmanagement']) { $dnsmanagement = true; $domainprice += $domaindnsmanagementprice * $regperiod; $renewprice += $domaindnsmanagementprice * $regperiod; if (strlen($before_priceoverride_value)) { $before_priceoverride_value += $domaindnsmanagementprice * $regperiod; } } else { $dnsmanagement = false; } if ($domain['emailforwarding']) { $emailforwarding = true; $domainprice += $domainemailforwardingprice * $regperiod; $renewprice += $domainemailforwardingprice * $regperiod; if (strlen($before_priceoverride_value)) { $before_priceoverride_value += $domainemailforwardingprice * $regperiod; } } else { $emailforwarding = false; } if ($domain['idprotection']) { $idprotection = true; $domainprice += $domainidprotectionprice * $regperiod; $renewprice += $domainidprotectionprice * $regperiod; if (strlen($before_priceoverride_value)) { $before_priceoverride_value += $domainidprotectionprice * $regperiod; } } else { $idprotection = false; } if ($CONFIG['TaxInclusiveDeduct']) { $domainprice = round($domainprice / $excltaxrate, 2); $renewprice = round($renewprice / $excltaxrate, 2); } $domain_price_db = $domainprice; $domain_renew_price_db = $renewprice; if ($promotioncode) { $onetimediscount = $recurringdiscount = $promoid = 0; if ($promocalc = CalcPromoDiscount("D." . $tld, $regperiod . "Years", $domain_price_db, $domain_renew_price_db)) { $onetimediscount = $promocalc['onetimediscount']; $recurringdiscount = $promocalc['recurringdiscount']; $domain_price_db -= $onetimediscount; $domain_renew_price_db -= $recurringdiscount; $cart_discount += $onetimediscount; $promoid = $promo_data['id']; } } if ($regperiod == "1") { $domain_billing_cycle = "annually"; } else { if ($regperiod == "2") { $domain_billing_cycle = "biennially"; } else { if ($regperiod == "3") { $domain_billing_cycle = "triennially"; } } } $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db; if ($CONFIG['TaxEnabled'] && $CONFIG['TaxDomains'] && $CONFIG['TaxType'] == "Exclusive" && !$clientsdetails['taxexempt']) { if ($CONFIG['TaxL2Compound']) { $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db * $taxrate + ($domain_renew_price_db + $domain_renew_price_db * $taxrate) * $taxrate2; } else { $recurring_cycles_total[$domain_billing_cycle] += $domain_renew_price_db * $taxrate + $domain_renew_price_db * $taxrate2; } } if ($checkout) { $donotrenew = $CONFIG['DomainAutoRenewDefault'] ? "" : "on"; $domainid = insert_query("tbldomains", array("userid" => $userid, "orderid" => $orderid, "type" => $domaintype, "registrationdate" => "now()", "domain" => $domainname, "firstpaymentamount" => $domain_price_db, "recurringamount" => $domain_renew_price_db, "registrationperiod" => $regperiod, "status" => "Pending", "paymentmethod" => $paymentmethod, "expirydate" => "00000000", "nextduedate" => "now()", "nextinvoicedate" => "now()", "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection, "donotrenew" => $donotrenew, "promoid" => $promoid)); $orderdomainids[] = $domainid; $adminemailitems .= $_LANG['orderdomainregistration'] . ": " . ucfirst($domaintype) . "<br>\r\n" . $_LANG['orderdomain'] . (": " . $domainname . "<br>\r\n") . $_LANG['firstpaymentamount'] . ": " . formatCurrency($domain_price_db) . "<br>\r\n" . $_LANG['recurringamount'] . ": " . formatCurrency($domain_renew_price_db) . "<br>\r\n" . $_LANG['orderregperiod'] . (": " . $regperiod . " ") . $_LANG['orderyears'] . "<br>\r\n"; if ($dnsmanagement) { $adminemailitems .= " + " . $_LANG['domaindnsmanagement'] . "<br>\r\n"; } if ($emailforwarding) { $adminemailitems .= " + " . $_LANG['domainemailforwarding'] . "<br>\r\n"; } if ($idprotection) { $adminemailitems .= " + " . $_LANG['domainidprotection'] . "<br>\r\n"; } $adminemailitems .= "<br>\r\n"; if ($domaintype == "register") { unset($tempdomainfields); $tempdomainfields = $additionaldomainfields["." . $tld]; if ($tempdomainfields) { foreach ($tempdomainfields as $fieldkey => $value) { $storedvalue = $domain['fields'][$fieldkey]; insert_query("tbldomainsadditionalfields", array("domainid" => $domainid, "name" => $value['Name'], "value" => $storedvalue)); } } } if ($domaintype == "transfer" && $domain['eppcode']) { $domaineppcodes[$domainname] = html_entity_decode($domain['eppcode']); } } $pricing_text = ""; if (strlen($before_priceoverride_value)) { $pricing_text .= "<strike>" . formatCurrency($before_priceoverride_value) . "</strike> "; } $pricing_text .= formatCurrency($domainprice); $tempdomains[$key] = array("type" => $domaintype, "domain" => $domainname, "regperiod" => $regperiod, "price" => $pricing_text, "renewprice" => formatCurrency($renewprice), "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection, "eppvalue" => $domain['eppcode']); $totaldomainprice += $domain_price_db; } } $cartdata['domains'] = $tempdomains; $cart_total += $totaldomainprice; if ($CONFIG['TaxDomains']) { $cart_tax += $totaldomainprice; } $orderrenewals = ""; if (array_key_exists("renewals", $_SESSION['cart']) && is_array($_SESSION['cart']['renewals'])) { $result = select_query("tblpricing", "", array("type" => "domainaddons", "currency" => $currency['id'], "relid" => 0)); $data = mysql_fetch_array($result); $domaindnsmanagementprice = $data['msetupfee']; $domainemailforwardingprice = $data['qsetupfee']; $domainidprotectionprice = $data['ssetupfee']; foreach ($_SESSION['cart']['renewals'] as $domainid => $regperiod) { $result = select_query("tbldomains", "", array("id" => $domainid)); $data = mysql_fetch_array($result); $domainname = $data['domain']; $expirydate = $data['expirydate']; if ($expirydate == "0000-00-00") { $expirydate = $data['nextduedate']; } $dnsmanagement = $data['dnsmanagement']; $emailforwarding = $data['emailforwarding']; $idprotection = $data['idprotection']; $domainparts = explode(".", $domainname, 2); $sld = $domainparts[0]; $tld = "." . $domainparts[1]; $temppricelist = getTLDPriceList($tld, "", true); if (!isset($temppricelist[$regperiod]['renew'])) { exit("Invalid TLD/Registration Period Supplied for Domain Renewal"); } $renewprice = $temppricelist[$regperiod]['renew']; if ($dnsmanagement) { $renewprice += $domaindnsmanagementprice * $regperiod; } if ($emailforwarding) { $renewprice += $domainemailforwardingprice * $regperiod; } if ($idprotection) { $renewprice += $domainidprotectionprice * $regperiod; } if ($CONFIG['TaxInclusiveDeduct']) { $renewprice = round($renewprice / $excltaxrate, 2); } $domain_renew_price_db = $renewprice; if ($promotioncode) { $onetimediscount = $recurringdiscount = $promoid = 0; if ($promocalc = CalcPromoDiscount("D" . $tld, $regperiod . "Years", $domain_renew_price_db, $domain_renew_price_db)) { $onetimediscount = $promocalc['onetimediscount']; $domain_renew_price_db -= $onetimediscount; $cart_discount += $onetimediscount; } } $cart_total += $domain_renew_price_db; if ($CONFIG['TaxDomains']) { $cart_tax += $domain_renew_price_db; } if ($checkout) { $domain_renew_price_db = format_as_currency($domain_renew_price_db); $orderrenewalids[] = $domainid; $orderrenewals .= "" . $domainid . "=" . $regperiod . ","; $adminemailitems .= $_LANG['domainrenewal'] . (": " . $domainname . " - " . $regperiod . " ") . $_LANG['orderyears'] . "<br>\r\n"; $domaindesc = $_LANG['domainrenewal'] . (" - " . $domainname . " - " . $regperiod . " ") . $_LANG['orderyears'] . " (" . fromMySQLDate($expirydate) . " - " . fromMySQLDate(getInvoicePayUntilDate($expirydate, $regperiod)) . ")"; if ($dnsmanagement) { $adminemailitems .= " + " . $_LANG['domaindnsmanagement'] . "<br>\r\n"; $domaindesc .= "\r\n + " . $_LANG['domaindnsmanagement']; } if ($emailforwarding) { $adminemailitems .= " + " . $_LANG['domainemailforwarding'] . "<br>\r\n"; $domaindesc .= "\r\n + " . $_LANG['domainemailforwarding']; } if ($idprotection) { $adminemailitems .= " + " . $_LANG['domainidprotection'] . "<br>\r\n"; $domaindesc .= "\r\n + " . $_LANG['domainidprotection']; } $adminemailitems .= "<br>\r\n"; $tax = $CONFIG['TaxDomains'] ? "1" : "0"; update_query("tbldomains", array("registrationperiod" => $regperiod, "recurringamount" => $domain_renew_price_db), array("id" => $domainid)); insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Domain", "relid" => $domainid, "description" => $domaindesc, "amount" => $domain_renew_price_db, "taxed" => $tax, "duedate" => "now()", "paymentmethod" => $paymentmethod)); $result = select_query("tblinvoiceitems", "tblinvoiceitems.id,tblinvoiceitems.invoiceid", array("type" => "Domain", "relid" => $domainid, "status" => "Unpaid", "tblinvoices.userid" => $_SESSION['uid']), "", "", "", "tblinvoices ON tblinvoices.id=tblinvoiceitems.invoiceid"); while ($data = mysql_fetch_array($result)) { $itemid = $data['id']; $invoiceid = $data['invoiceid']; $result2 = select_query("tblinvoiceitems", "COUNT(*)", array("invoiceid" => $invoiceid)); $data = mysql_fetch_array($result2); $itemcount = $data[0]; if ($itemcount == 1) { update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $invoiceid)); logActivity("Cancelled Previous Domain Renewal Invoice - Invoice ID: " . $invoiceid . " - Domain: " . $domainname); } delete_query("tblinvoiceitems", array("id" => $itemid)); updateInvoiceTotal($invoiceid); logActivity("Removed Previous Domain Renewal Line Item - Invoice ID: " . $invoiceid . " - Domain: " . $domainname); } } $cartdata['renewals'][$domainid] = array("domain" => $domainname, "regperiod" => $regperiod, "price" => formatCurrency($renewprice), "dnsmanagement" => $dnsmanagement, "emailforwarding" => $emailforwarding, "idprotection" => $idprotection); } } $cart_adjustments = 0; $adjustments = run_hook("CartTotalAdjustment", $_SESSION['cart']); foreach ($adjustments as $k => $adjvals) { if ($checkout) { insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "", "relid" => "", "description" => $adjvals['description'], "amount" => $adjvals['amount'], "taxed" => $adjvals['taxed'], "duedate" => "now()", "paymentmethod" => $paymentmethod)); } $adjustments[$k]['amount'] = formatCurrency($adjvals['amount']); $cart_adjustments += $adjvals['amount']; if ($adjvals['taxed']) { $cart_tax += $adjvals['amount']; continue; } } if ($CONFIG['TaxEnabled'] && !$clientsdetails['taxexempt']) { if ($CONFIG['TaxType'] == "Inclusive") { $totaltaxrates = 1 + ($taxrate + $taxrate2); $total_without_tax = $cart_tax / $totaltaxrates; $total_tax_1 = $total_without_tax * $taxrate; $total_tax_2 = $total_without_tax * $taxrate2; } else { $total_tax_1 = $cart_tax * $taxrate; if ($CONFIG['TaxL2Compound']) { $total_tax_2 = ($cart_tax + $total_tax_1) * $taxrate2; } else { $total_tax_2 = $cart_tax * $taxrate2; } } $total_tax_1 = round($total_tax_1, 2); $total_tax_2 = round($total_tax_2, 2); if ($CONFIG['TaxType'] == "Inclusive") { $cart_total -= $total_tax_1 + $total_tax_2; } } else { $total_tax_1 = $total_tax_2 = 0; } $cart_subtotal = $cart_total + $cart_discount; $cart_total += $total_tax_1 + $total_tax_2 + $cart_adjustments; $cart_subtotal = format_as_currency($cart_subtotal); $cart_discount = format_as_currency($cart_discount); $cart_adjustments = format_as_currency($cart_adjustments); $total_tax_1 = format_as_currency($total_tax_1); $total_tax_2 = format_as_currency($total_tax_2); $cart_total = format_as_currency($cart_total); if ($checkout) { $adminemailitems .= $_LANG['ordertotalduetoday'] . ": " . formatCurrency($cart_total); if ($promotioncode && $promo_data['promoapplied']) { update_query("tblpromotions", array("uses" => "+1"), array("code" => $promotioncode)); $promo_recurring = $promo_data['recurring'] ? "Recurring" : "One Time"; update_query("tblorders", array("promocode" => $promo_data['code'], "promotype" => $promo_recurring . " " . $promo_data['type'], "promovalue" => $promo_data['value']), array("id" => $orderid)); } if ($_SESSION['cart']['ns1'] && $_SESSION['cart']['ns1']) { $ordernameservers = $_SESSION['cart']['ns1'] . "," . $_SESSION['cart']['ns2']; if ($_SESSION['cart']['ns3']) { $ordernameservers .= "," . $_SESSION['cart']['ns3']; } if ($_SESSION['cart']['ns4']) { $ordernameservers .= "," . $_SESSION['cart']['ns4']; } if ($_SESSION['cart']['ns5']) { $ordernameservers .= "," . $_SESSION['cart']['ns5']; } } $domaineppcodes = count($domaineppcodes) ? serialize($domaineppcodes) : ""; $orderdata = array(); if (is_array($_SESSION['cart']['bundle'])) { foreach ($_SESSION['cart']['bundle'] as $bvals) { $orderdata['bundleids'][] = $bvals['bid']; } } update_query("tblorders", array("amount" => $cart_total, "nameservers" => $ordernameservers, "transfersecret" => $domaineppcodes, "renewals" => substr($orderrenewals, 0, 0 - 1), "orderdata" => serialize($orderdata)), array("id" => $orderid)); $invoiceid = 0; if (!$_SESSION['cart']['geninvoicedisabled']) { if (!$userid) { exit("An Error Occurred"); } $invoiceid = createInvoices($userid, true, "", array("products" => $orderproductids, "addons" => $orderaddonids, "domains" => $orderdomainids)); if ($CONFIG['OrderDaysGrace']) { $new_time = mktime(0, 0, 0, date("m"), date("d") + $CONFIG['OrderDaysGrace'], date("Y")); $duedate = date("Y-m-d", $new_time); update_query("tblinvoices", array("duedate" => $duedate), array("id" => $invoiceid)); } if (!$CONFIG['NoInvoiceEmailOnOrder']) { sendMessage("Invoice Created", $invoiceid); } } if ($invoiceid) { update_query("tblorders", array("invoiceid" => $invoiceid), array("id" => $orderid)); $result = select_query("tblinvoices", "status", array("id" => $invoiceid)); $data = mysql_fetch_array($result); $status = $data['status']; if ($status == "Paid") { $invoiceid = ""; } } if (!$_SESSION['adminid']) { if (isset($_COOKIE['WHMCSAffiliateID'])) { $result = select_query("tblaffiliates", "clientid", array("id" => (int) $_COOKIE['WHMCSAffiliateID'])); $data = mysql_fetch_array($result); $clientid = $data['clientid']; if ($clientid && $_SESSION['uid'] != $clientid) { foreach ($orderproductids as $orderproductid) { insert_query("tblaffiliatesaccounts", array("affiliateid" => (int) $_COOKIE['WHMCSAffiliateID'], "relid" => $orderproductid)); } } } if (isset($_COOKIE['WHMCSLinkID'])) { update_query("tbllinks", array("conversions" => "+1"), array("id" => $_COOKIE['WHMCSLinkID'])); } } $result = select_query("tblclients", "firstname, lastname, companyname, email, address1, address2, city, state, postcode, country, phonenumber, ip, host", array("id" => $userid)); $data = mysql_fetch_array($result); list($firstname, $lastname, $companyname, $email, $address1, $address2, $city, $state, $postcode, $country, $phonenumber, $ip, $host) = $data; $customfields = getCustomFields("client", "", $userid, "", true); $clientcustomfields = ""; foreach ($customfields as $customfield) { $clientcustomfields .= "" . $customfield['name'] . ": " . $customfield['value'] . "<br />\r\n"; } $result = select_query("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "name")); $data = mysql_fetch_array($result); $nicegatewayname = $data['value']; sendAdminMessage("New Order Notification", array("order_id" => $orderid, "order_number" => $order_number, "order_date" => fromMySQLDate(date("Y-m-d H:i:s"), true), "invoice_id" => $invoiceid, "order_payment_method" => $nicegatewayname, "order_total" => formatCurrency($cart_total), "client_id" => $userid, "client_first_name" => $firstname, "client_last_name" => $lastname, "client_email" => $email, "client_company_name" => $companyname, "client_address1" => $address1, "client_address2" => $address2, "client_city" => $city, "client_state" => $state, "client_postcode" => $postcode, "client_country" => $country, "client_phonenumber" => $phonenumber, "client_customfields" => $clientcustomfields, "order_items" => $adminemailitems, "order_notes" => nl2br($ordernotes), "client_ip" => $ip, "client_hostname" => $host), "account"); if (!$_SESSION['cart']['orderconfdisabled']) { sendMessage("Order Confirmation", $userid, array("order_id" => $orderid, "order_number" => $order_number, "order_details" => $adminemailitems)); } $_SESSION['cart'] = array(); $_SESSION['orderdetails'] = array("OrderID" => $orderid, "OrderNumber" => $order_number, "ServiceIDs" => $orderproductids, "DomainIDs" => $orderdomainids, "AddonIDs" => $orderaddonids, "RenewalIDs" => $orderrenewalids, "PaymentMethod" => $paymentmethod, "InvoiceID" => $invoiceid, "TotalDue" => $cart_total, "Products" => $orderproductids, "Domains" => $orderdomainids, "Addons" => $orderaddonids, "Renewals" => $orderrenewalids); run_hook("AfterShoppingCartCheckout", $_SESSION['orderdetails']); } $total_recurringmonthly = $recurring_cycles_total['monthly'] <= 0 ? "" : formatCurrency($recurring_cycles_total['monthly']); $total_recurringquarterly = $recurring_cycles_total['quarterly'] <= 0 ? "" : formatCurrency($recurring_cycles_total['quarterly']); $total_recurringsemiannually = $recurring_cycles_total['semiannually'] <= 0 ? "" : formatCurrency($recurring_cycles_total['semiannually']); $total_recurringannually = $recurring_cycles_total['annually'] <= 0 ? "" : formatCurrency($recurring_cycles_total['annually']); $total_recurringbiennially = $recurring_cycles_total['biennially'] <= 0 ? "" : formatCurrency($recurring_cycles_total['biennially']); $total_recurringtriennially = $recurring_cycles_total['triennially'] <= 0 ? "" : formatCurrency($recurring_cycles_total['triennially']); $cartdata['bundlewarnings'] = $bundlewarnings; $cartdata['rawdiscount'] = $cart_discount; $cartdata['subtotal'] = formatCurrency($cart_subtotal); $cartdata['discount'] = formatCurrency($cart_discount); $cartdata['promotype'] = $promo_data['type']; $cartdata['promovalue'] = $promo_data['type'] == "Fixed Amount" || $promo_data['type'] == "Price Override" ? formatCurrency($promo_data['value']) : round($promo_data['value'], 2); $cartdata['promorecurring'] = $promo_data['recurring'] ? $_LANG['recurring'] : $_LANG['orderpaymenttermonetime']; $cartdata['taxrate'] = $rawtaxrate; $cartdata['taxrate2'] = $rawtaxrate2; $cartdata['taxname'] = $taxname; $cartdata['taxname2'] = $taxname2; $cartdata['taxtotal'] = formatCurrency($total_tax_1); $cartdata['taxtotal2'] = formatCurrency($total_tax_2); $cartdata['adjustments'] = $adjustments; $cartdata['adjustmentstotal'] = formatCurrency($cart_adjustments); $cartdata['rawtotal'] = $cart_total; $cartdata['total'] = formatCurrency($cart_total); $cartdata['totalrecurringmonthly'] = $total_recurringmonthly; $cartdata['totalrecurringquarterly'] = $total_recurringquarterly; $cartdata['totalrecurringsemiannually'] = $total_recurringsemiannually; $cartdata['totalrecurringannually'] = $total_recurringannually; $cartdata['totalrecurringbiennially'] = $total_recurringbiennially; $cartdata['totalrecurringtriennially'] = $total_recurringtriennially; return $cartdata; }
foreach ($coopval as $cid => $opid) { if (!in_array($cid, $coprestrict)) { unset($coopval[$cid]); continue; } } foreach ($coprestrict as $cid) { if (!array_key_exists($cid, $coopval)) { $coopval[$cid] = ""; continue; } } $vals = array("type" => "product", "pid" => $pid, "billingcycle" => $billingcycle, "priceoverride" => $priceoverride, "price" => format_as_currency($price), "configoption" => $coopval, "addons" => $addons, "tlds" => $tlds, "regperiod" => $regperiod, "dompriceoverride" => $dompriceoverride, "domprice" => format_as_currency($domprice), "domaddons" => $domaddons); } else { if ($type == "domain") { $vals = array("type" => "domain", "tlds" => $tlds2, "regperiod" => $regperiod2, "dompriceoverride" => $dompriceoverride2, "domprice" => format_as_currency($domprice2), "addons" => $domaddons2); } } if (strlen($i)) { $itemdata[$i] = $vals; } else { $itemdata[] = $vals; } update_query("tblbundles", array("itemdata" => serialize($itemdata)), array("id" => $id)); redir("action=manage&id=" . $id); exit; } if ($action == "deleteitem") { check_token("WHMCS.admin.default"); $result = select_query("tblbundles", "", array("id" => $id)); $data = mysql_fetch_array($result);
function getRecurringBillingValues($invoiceid) { global $CONFIG; $firstcycleperiod = $firstcycleunits = ""; $invoiceid = (int) $invoiceid; $result = select_query("tblinvoiceitems", "tblinvoiceitems.relid,tblinvoiceitems.taxed,tblhosting.userid,tblhosting.amount,tblhosting.billingcycle,tblhosting.packageid,tblhosting.regdate,tblhosting.nextduedate", array("invoiceid" => $invoiceid, "type" => "Hosting"), "tblinvoiceitems`.`id", "ASC", "", "tblhosting ON tblhosting.id=tblinvoiceitems.relid"); $data = mysql_fetch_array($result); $relid = $data['relid']; $taxed = $data['taxed']; $userid = $data['userid']; $recurringamount = $data['amount']; $billingcycle = $data['billingcycle']; $packageid = $data['packageid']; $regdate = $data['regdate']; $nextduedate = $data['nextduedate']; if (!$relid || $billingcycle == "One Time" || $billingcycle == "Free Account") { return false; } $result = select_query("tblinvoices", "total,taxrate,taxrate2,paymentmethod,(SELECT SUM(amountin)-SUM(amountout) FROM tblaccounts WHERE invoiceid=tblinvoices.id) AS amountpaid", array("id" => $invoiceid)); $data = mysql_fetch_array($result); $total = $data['total']; $taxrate = $data['taxrate']; $taxrate2 = $data['taxrate2']; $paymentmethod = $data['paymentmethod']; $amountpaid = $data['amountpaid']; $firstpaymentamount = $total - $amountpaid; $recurringcycleperiod = getBillingCycleMonths($billingcycle); $recurringcycleunits = "Months"; if (12 <= $recurringcycleperiod) { $recurringcycleperiod = $recurringcycleperiod / 12; $recurringcycleunits = "Years"; } $recurringamount = 0; $query = "SELECT tblhosting.amount,tblinvoiceitems.taxed FROM tblinvoiceitems INNER JOIN tblhosting ON tblhosting.id=tblinvoiceitems.relid WHERE tblinvoiceitems.invoiceid='" . (int) $invoiceid . "' AND tblinvoiceitems.type='Hosting' AND tblhosting.billingcycle='" . db_escape_string($billingcycle) . "'"; $result = full_query($query); while ($data = mysql_fetch_array($result)) { $prodamount = $data[0]; $taxed = $data[1]; if ($CONFIG['TaxType'] == "Exclusive" && $taxed) { if ($CONFIG['TaxL2Compound']) { $prodamount = $prodamount + $prodamount * ($taxrate / 100); $prodamount = $prodamount + $prodamount * ($taxrate2 / 100); } else { $prodamount = $prodamount + $prodamount * ($taxrate / 100) + $prodamount * ($taxrate2 / 100); } } $recurringamount += $prodamount; } $query = "SELECT tblhostingaddons.recurring,tblhostingaddons.tax FROM tblinvoiceitems INNER JOIN tblhostingaddons ON tblhostingaddons.id=tblinvoiceitems.relid WHERE tblinvoiceitems.invoiceid='" . (int) $invoiceid . "' AND tblinvoiceitems.type='Addon' AND tblhostingaddons.billingcycle='" . db_escape_string($billingcycle) . "'"; $result = full_query($query); while ($data = mysql_fetch_array($result)) { $addonamount = $data[0]; $addontax = $data[1]; if ($CONFIG['TaxType'] == "Exclusive" && $addontax) { if ($CONFIG['TaxL2Compound']) { $addonamount = $addonamount + $addonamount * ($taxrate / 100); $addonamount = $addonamount + $addonamount * ($taxrate2 / 100); } else { $addonamount = $addonamount + $addonamount * ($taxrate / 100) + $addonamount * ($taxrate2 / 100); } } $recurringamount += $addonamount; } if (in_array($billingcycle, array("Annually", "Biennially", "Triennially"))) { $cycleregperiods = array("Annually" => "1", "Biennially" => "2", "Triennially" => "3"); $query = "SELECT SUM(tbldomains.recurringamount) FROM tblinvoiceitems INNER JOIN tbldomains ON tbldomains.id=tblinvoiceitems.relid WHERE tblinvoiceitems.invoiceid='" . (int) $invoiceid . "' AND tblinvoiceitems.type IN ('DomainRegister','DomainTransfer','Domain') AND tbldomains.registrationperiod='" . db_escape_string($cycleregperiods[$billingcycle]) . "'"; $result = full_query($query); $data = mysql_fetch_array($result); $domainamount = $data[0]; if ($CONFIG['TaxType'] == "Exclusive" && $CONFIG['TaxDomains']) { if ($CONFIG['TaxL2Compound']) { $domainamount = $domainamount + $domainamount * ($taxrate / 100); $domainamount = $domainamount + $domainamount * ($taxrate2 / 100); } else { $domainamount = $domainamount + $domainamount * ($taxrate / 100) + $domainamount * ($taxrate2 / 100); } } $recurringamount += $domainamount; } $result = select_query("tblinvoices", "duedate", array("id" => $invoiceid)); $data = mysql_fetch_array($result); $invoiceduedate = $data['duedate']; $invoiceduedate = str_replace("-", "", $invoiceduedate); $overdue = $invoiceduedate < date("Ymd") ? true : false; $result = select_query("tblproducts", "proratabilling,proratadate,proratachargenextmonth", array("id" => $packageid)); $data = mysql_fetch_array($result); $proratabilling = $data['proratabilling']; $proratadate = $data['proratadate']; $proratachargenextmonth = $data['proratachargenextmonth']; if ($regdate == $nextduedate && $proratabilling) { $orderyear = substr($regdate, 0, 4); $ordermonth = substr($regdate, 5, 2); $orderday = substr($regdate, 8, 2); if (!function_exists("getProrataValues")) { require ROOTDIR . "/includes/invoicefunctions.php"; } $proratavals = getProrataValues($billingcycle, 0, $proratadate, $proratachargenextmonth, $orderday, $ordermonth, $orderyear); $firstcycleperiod = $proratavals['days']; $firstcycleunits = "Days"; } if (!$firstcycleperiod) { $firstcycleperiod = $recurringcycleperiod; } if (!$firstcycleunits) { $firstcycleunits = $recurringcycleunits; } $result = select_query("tblpaymentgateways", "value", array("gateway" => $paymentmethod, "setting" => "convertto")); $data = mysql_fetch_array($result); $convertto = $data[0]; if ($convertto) { $currency = getCurrency($userid); $firstpaymentamount = convertCurrency($firstpaymentamount, $currency['id'], $convertto); $recurringamount = convertCurrency($recurringamount, $currency['id'], $convertto); } $firstpaymentamount = format_as_currency($firstpaymentamount); $recurringamount = format_as_currency($recurringamount); $returndata = array(); $returndata['primaryserviceid'] = $relid; if ($firstpaymentamount != $recurringamount) { $returndata['firstpaymentamount'] = $firstpaymentamount; $returndata['firstcycleperiod'] = $firstcycleperiod; $returndata['firstcycleunits'] = $firstcycleunits; } $returndata['recurringamount'] = $recurringamount; $returndata['recurringcycleperiod'] = $recurringcycleperiod; $returndata['recurringcycleunits'] = $recurringcycleunits; $returndata['overdue'] = $overdue; return $returndata; }
$ca->assign("message", $_LANG['forwardingtogateway']); $ca->assign("code", $paymentbutton); $ca->assign("invoiceid", $id); $ca->output(); exit; } } else { $amount = $addfundsmin; } } } $ca->setTemplate("clientareaaddfunds"); $ca->assign("minimumamount", formatCurrency($addfundsmin)); $ca->assign("maximumamount", formatCurrency($addfundsmax)); $ca->assign("maximumbalance", formatCurrency($addfundsmaxbal)); $ca->assign("amount", format_as_currency($amount)); $gatewayslist = showPaymentGatewaysList(); $ca->assign("gateways", $gatewayslist); } else { if ($action == "masspay") { checkContactPermission("invoices"); $ca->setTemplate("masspay"); if (!$CONFIG['EnableMassPay']) { redir(); exit; } if ($all) { $invoiceids = array(); $result = select_query("tblinvoices", "id", array("userid" => $client->getID(), "status" => "Unpaid", "(select count(id) from tblinvoiceitems where invoiceid=tblinvoices.id and type='Invoice')" => array("sqltype" => "<=", "value" => 0)), "id", "DESC"); while ($data = mysql_fetch_array($result)) { $invoiceids[] = $data['id'];
public function calcConfigOptionsUpgradeDue() { global $whmcs; $pid = $this->getProductInfo("pid"); $domain = $this->getProductInfo("domain"); $nextduedate = $this->getProductInfo("nextduedate"); $billingcycle = $this->getProductInfo("billingcycle"); $productname = $this->getProductInfo("productname"); $applytax = $this->getProductInfo("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("Y-m-d"); $todaysdate = strtotime($todaysdate); $nextduedatetime = strtotime($nextduedate); $days = round(($nextduedatetime - $todaysdate) / 86400); if ($days < 0) { $days = $totaldays; } $percentage = $days / $totaldays; $newconfigoptions = getCartConfigOptions($pid, $this->newconfigoptions, $billingcycle); $oldconfigoptions = getCartConfigOptions($pid, "", $billingcycle, $id); foreach ($newconfigoptions 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 = $whmcs->get_lang("yes"); $newvalue = $whmcs->get_lang("no"); } else { $originalvalue = $whmcs->get_lang("no"); $newvalue = $whmcs->get_lang("yes"); } } else { if ($optiontype == 4) { $new_selectedqty = (int) $new_selectedqty; if ($new_selectedqty < 0) { $new_selectedqty = 11; } $db_orig_value = $old_selectedqty; $db_new_value = $new_selectedqty; $originalvalue = $old_selectedqty; $newvalue = $new_selectedqty . " " . $configoption['options'][0]['nameonly']; } } } $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; $description = $productname . "\r\n" . $configname . ": " . (0 < $amountdue ? "Upgrade" : "Downgrade") . " from " . $originalvalue . " to " . $newvalue . " (" . getTodaysDate() . " - " . fromMySQLDate($nextduedate) . ")" . "\r\n" . "Regular Recurring Amount Increase: " . formatCurrency($difference) . ""; $this->addLineItem($description, $amountdue); $upgradearray[] = array("configname" => $configname, "originalvalue" => $originalvalue, "newvalue" => $newvalue, "price" => formatCurrency($amountdue)); continue; } } return $upgradearray; }
if ($a == "gettimesheethead") { echo "<link href=\"../includes/jscript/css/ui.all.css\" type=\"text/css /><script src=\"../includes/jscript/jquery.js\"></script><script src=\"../includes/jscript/jqueryui.js\"></script>"; exit; } else { if ($a == "gettimesheet") { if (project_management_checkperm("Bill Tasks")) { echo "<form method=\"post\" action=\"" . $modulelink . "&a=dynamicinvoicegenerate\">\n<div class=\"box\">\n<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\" class=\"tasks\" id=\"tasks\"><tr bgcolor=\"#efefef\">\n\t<th width=\"60%\">" . $vars['_lang']['description'] . "</th><th width=\"10%\">" . $vars['_lang']['hours'] . "</th><th width=\"14%\">" . $vars['_lang']['rate'] . "</th><th width=\"15%\">" . $vars['_lang']['amount'] . "</th><th width=\"20\"></th></tr>"; $dti = 0; $tasksresult = select_query("mod_projecttasks", "id,task", array("projectid" => $projectid, "billed" => "0")); while ($tasksdata = mysql_fetch_assoc($tasksresult)) { $dynamictimes[$dti]['seconds'] = get_query_val("mod_projecttimes", "SUM(end-start)", array("taskid" => $tasksdata['id'], "donotbill" => 0)); $dynamictimes[$dti]['description'] = $tasksdata['task']; $dynamictimes[$dti]['rate'] = $vars['hourlyrate']; $dynamictimes[$dti]['amount'] = $dynamictimes[$dti]['rate'] * ($dynamictimes[$dti]['seconds'] / 3600); if (0 < $dynamictimes[$dti]['seconds']) { echo "<tr id=\"dynamictaskinvoiceitemholder" . $dti . "\">\n\t\t\t<td><input type=\"hidden\" name=\"taskid[" . $dti . "]\" value=\"" . $tasksdata['id'] . "\" /><input style=\"width:99%\" type=\"text\" name=\"description[" . $dti . "]\" value=\"" . $dynamictimes[$dti]['description'] . "\" /></td>\n\t\t\t<td><input type=\"hidden\" id=\"dynamicbillhours" . $dti . "\" name=\"hours[" . $dti . "]\" value=\"" . round($dynamictimes[$dti]['seconds'] / 3600, 2) . "\" /><input type=\"text\" name=\"displayhours[" . $dti . "]\" class=\"dynamicbilldisplayhours\" id=\"dynamicbilldisplayhours" . $dti . "\" name=\"hours[" . $dti . "]\" value=\"" . project_management_sec2hms($dynamictimes[$dti]['seconds']) . "\" /></td>\n\t\t\t<td><input type=\"text\" class=\"dynamicbillrate\" id=\"dynamicbillrate" . $dti . "\" name=\"rate[" . $dti . "]\" value=\"" . format_as_currency($dynamictimes[$dti]['rate']) . "\" /></td>\n\t\t\t<td><input type=\"text\" id=\"dynamicbillamount" . $dti . "\" name=\"amount[" . $dti . "]\" value=\"" . format_as_currency($dynamictimes[$dti]['amount'], 2) . "\" /></td>\n\t\t\t<td><a class=\"deldynamictaskinvoice\" id=\"deldynamictaskinvoice" . $dti . "\"><img src=\"images/delete.gif\"></a></td></tr>"; } ++$dti; } echo "</table></div><p align=\"center\"><input type=\"submit\" value=\"" . $vars['_lang']['generatenow'] . "\" /> <input type=\"submit\" onClick=\"form.action='" . $modulelink . "&a=dynamicinvoicegenerate&sendinvoicegenemail=true'\" value=\"" . $vars['_lang']['generatenowandemail'] . "\" /> <input type=\"button\" id=\"dynamictasksinvoicecancel\" value=\"" . $vars['_lang']['cancel'] . "\" /></p>\n\t\t</form>"; } exit; } else { if ($a == "dynamicinvoicegenerate") { if (!project_management_checkperm("Bill Tasks")) { redir("module=project_management"); } $userid = get_query_val("mod_project", "userid", array("id" => $projectid)); $gateway = function_exists("getClientsPaymentMethod") ? getClientsPaymentMethod($userid) : "paypal"; if ($CONFIG['TaxEnabled'] == "on") { $clientsdetails = getClientsDetails($userid);
function bulkpricingupdater_output($vars) { $modulelink = $vars['modulelink']; $step = isset($_REQUEST['step']) ? $_REQUEST['step'] : ""; if (!$step) { echo "\n<p>By default, changing the pricing of products & services in the product configuration area will not affect existing clients. They remain at the prices they agreed to at the time of signing up. However, if you want to apply price increases to your existing clients too, then this addon utility allows you to do that.</p>\n<p>(Use Ctrl+Click to select more than one criteria in any of the fields)</p>\n"; echo "\n<form method=\"post\" action=\""; echo $modulelink; echo "&step=2\">\n\n<p><b>Conditions</b></p>\n\n<table class=\"form\" width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">\n<tr><td width=\"15%\" class=\"fieldlabel\">Product</td><td class=\"fieldarea\" colspan=\"3\">"; echo "<s"; echo "elect name=\"productids[]\" size=\"10\" multiple=\"true\" style=\"width:600px;\">"; $result = select_query("tblproducts", "tblproducts.id,tblproducts.gid,tblproducts.name,tblproductgroups.name AS groupname", "", "tblproductgroups`.`order` ASC,`tblproducts`.`order` ASC,`name", "ASC", "", "tblproductgroups ON tblproducts.gid=tblproductgroups.id"); while ($data = mysql_fetch_array($result)) { $pid = $data['id']; $pname = $data['name']; $ptype = $data['groupname']; echo "<option value=\"" . $pid . "\">" . $ptype . " - " . $pname . "</option>"; } $result = select_query("tbladdons", "", "", "name", "ASC"); while ($data = mysql_fetch_array($result)) { $id = $data['id']; $name = $data['name']; $description = $data['description']; echo "<option value=\"A" . $id . "\">Addon - " . $name . "</option>"; } $result = select_query("tbldomainpricing", "DISTINCT extension", "", "extension", "ASC"); while ($data = mysql_fetch_array($result)) { $tld = $data['extension']; echo "<option value=\"D" . $tld . "\">Domain - " . $tld . "</option>"; } echo "</select></td></tr>\n<tr><td class=\"fieldlabel\">Status</td><td class=\"fieldarea\">"; echo "<s"; echo "elect name=\"status[]\" size=\"5\" multiple=\"true\">\n<option>Pending</option>\n<option>Pending Transfer</option>\n<option selected>Active</option>\n<option selected>Suspended</option>\n<option>Terminated</option>\n<option>Cancelled</option>\n<option>Expired</option>\n<option>Fraud</option>\n</select></td><td width=\"15%\" class=\"fieldlabel\">Billing Cycle</td><td class=\"fieldarea\">"; echo "<s"; echo "elect name=\"billingcycle[]\" size=\"8\" multiple=\"true\">\n<option>Monthly</option>\n<option>Quarterly</option>\n<option>Semi-Annually</option>\n<option>Annually</option>\n<option>Biennially</option>\n<option>Triennially</option>\n"; $domainyears = 1; while ($domainyears <= 10) { echo "<option value=\"" . $domainyears . "\">Domain: " . $domainyears . " Year</option>"; ++$domainyears; } echo "</select></td></tr>\n<tr><td class=\"fieldlabel\">Currency</td><td class=\"fieldarea\">"; echo "<s"; echo "elect name=\"currid\">"; $result = select_query("tblcurrencies", "id,code", "", "code", "ASC"); while ($data = mysql_fetch_array($result)) { echo "<option value=\"" . $data['id'] . "\""; if ($data['id'] == $currency) { echo " selected"; } echo ">" . $data['code'] . "</option>"; } echo "</select></td><td class=\"fieldlabel\">Current Price</td><td class=\"fieldarea\"><input type=\"text\" name=\"currentprice\" size=\"10\" value=\"\" /> (Optional)</td></tr>\n</table>\n\n<p><b>Price</b></p>\n\n<table class=\"form\" width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">\n<tr><td width=\"20%\" class=\"fieldlabel\">New Recurring Price</td><td class=\"fieldarea\"><input type=\"text\" name=\"newprice\" size=\"10\" value=\"0.00\" /></"; echo "td></tr>\n</table>\n\n<p align=\"center\"><input type=\"submit\" value=\"Update Pricing\" class=\"button\" /></p>\n\n</form>\n\n"; return null; } check_token(); $productids = $_REQUEST['productids']; $status = $_REQUEST['status']; $billingcycle = $_REQUEST['billingcycle']; $currid = (int) $_REQUEST['currid']; $currentprice = $_REQUEST['currentprice']; $newprice = $_REQUEST['newprice']; $statusmatches = db_build_in_array($status); $billingcyclematches = db_build_in_array($billingcycle); if ($currentprice) { $currentprice = format_as_currency($currentprice); } $newprice = format_as_currency($newprice); echo "<p><b>Conditions</b></p><p>Statuses: " . $statusmatches . "<br />Billing Cycles: " . $billingcyclematches; if ($currentprice) { echo "<br />Current Price: " . $currentprice; } echo "</p><p><b>Pricing Update Results</b></p><ul>"; $currentprice = db_escape_string($currentprice); $newprice = db_escape_string($newprice); foreach ($productids as $pid) { $prodfirstletter = substr($pid, 0, 1); $prodrest = (int) substr($pid, 1); echo "<li>"; if ($prodfirstletter == "A") { $query = "UPDATE tblhostingaddons,tblhosting SET tblhostingaddons.recurring='" . $newprice . "' WHERE tblhostingaddons.addonid='" . $prodrest . "' AND tblhostingaddons.status IN (" . $statusmatches . ") AND tblhostingaddons.billingcycle IN (" . $billingcyclematches . ") AND tblhosting.id=tblhostingaddons.hostingid AND tblhosting.userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')"; if ($currentprice) { $query .= " AND tblhostingaddons.recurring='" . $currentprice . "'"; } echo "Updated Addon ID " . $prodrest; } else { if ($prodfirstletter == "D") { $query = "UPDATE tbldomains SET recurringamount='" . $newprice . "' WHERE domain LIKE '%" . $prodrest . "' AND status IN (" . $statusmatches . ") AND registrationperiod IN (" . $billingcyclematches . ") AND userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')"; if ($currentprice) { $query .= " AND recurringamount='" . $currentprice . "'"; } echo "Updated Domains with TLD " . $prodrest; } else { $pid = (int) $pid; $query = "UPDATE tblhosting SET amount='" . $newprice . "' WHERE packageid='" . $pid . "' AND domainstatus IN (" . $statusmatches . ") AND billingcycle IN (" . $billingcyclematches . ") AND userid IN (SELECT id FROM tblclients WHERE currency='" . $currid . "')"; if ($currentprice) { $query .= " AND amount='" . $currentprice . "'"; } echo "Updated Product ID " . $pid; } } $result = full_query($query); $numaffected = mysql_affected_rows(); echo " - " . $numaffected . " Affected"; echo "</li>"; } }
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; }
function InvoicesAddLateFee() { global $CONFIG; global $_LANG; global $cron; if ($CONFIG['TaxLateFee']) { $taxlatefee = "1"; } $invoiceids = array(); if ($CONFIG['InvoiceLateFeeAmount'] != "0.00") { if ($CONFIG['AddLateFeeDays'] == "") { $CONFIG['AddLateFeeDays'] = "0"; } $adddate = date("Ymd", mktime(0, 0, 0, date("m"), date("d") - $CONFIG['AddLateFeeDays'], date("Y"))); $query = "SELECT tblinvoices.* FROM tblinvoices INNER JOIN tblclients ON tblclients.id=tblinvoices.userid WHERE duedate<'" . $adddate . "' AND tblinvoices.status='Unpaid' AND duedate!=date AND latefeeoveride=''"; $result = full_query($query); while ($data = mysql_fetch_array($result)) { $userid = $data['userid']; $invoiceid = $data['id']; $duedate = $data['duedate']; $paymentmethod = $data['paymentmethod']; $total = $data['total']; if (!get_query_val("tblinvoiceitems", "COUNT(id)", array("type" => "LateFee", "invoiceid" => $invoiceid))) { if ($CONFIG['LateFeeType'] == "Percentage") { $amountpaid = get_query_val("tblaccounts", "SUM(amountin)-SUM(amountout)", array("invoiceid" => $invoiceid)); $balance = round($total - $amountpaid, 2); $latefeeamount = format_as_currency($balance * ($CONFIG['InvoiceLateFeeAmount'] / 100)); } else { $latefeeamount = $CONFIG['InvoiceLateFeeAmount']; } if (0 < $CONFIG['LateFeeMinimum'] && $latefeeamount < $CONFIG['LateFeeMinimum']) { $latefeeamount = $CONFIG['LateFeeMinimum']; } getUsersLang($userid); insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "LateFee", "invoiceid" => $invoiceid, "description" => $_LANG['latefee'] . " (" . $_LANG['latefeeadded'] . " " . fromMySQLDate(date("Y-m-d")) . ")", "amount" => $latefeeamount, "duedate" => $duedate, "paymentmethod" => $paymentmethod, "taxed" => $taxlatefee)); if (!function_exists("updateInvoiceTotal")) { require dirname(__FILE__) . "/invoicefunctions.php"; } updateInvoiceTotal($invoiceid); run_hook("AddInvoiceLateFee", array("invoiceid" => $invoiceid)); $invoiceids[] = $invoiceid; } } } if (is_object($cron)) { $cron->logActivity("Late Invoice Fees added to " . count($invoiceids) . " Invoices" . (count($invoiceids) ? " (Invoice Numbers: " . implode(",", $invoiceids) . ")" : ""), true); $cron->emailLog(count($invoiceids) . " Late Fees Added" . (count($invoiceids) ? " to Invoice Numbers " . implode(",", $invoiceids) : "")); } }
function refundInvoicePayment($transid, $amount, $sendtogateway, $addascredit = "", $sendemail = true, $refundtransid = "") { $result = select_query("tblaccounts", "", array("id" => $transid)); $data = mysql_fetch_array($result); $transid = $data['id']; if (!$transid) { return "amounterror"; } $userid = $data['userid']; $invoiceid = $data['invoiceid']; $gateway = $data['gateway']; $fullamount = $data['amountin']; $fees = $data['fees']; $gatewaytransid = $data['transid']; $rate = $data['rate']; $gateway = WHMCS_Gateways::makesafename($gateway); $result = select_query("tblaccounts", "SUM(amountout),SUM(fees)", array("refundid" => $transid)); $data = mysql_fetch_array($result); $alreadyrefunded = $data[0]; $alreadyrefundedfees = $data[1]; $fullamount -= $alreadyrefunded; $fees -= $alreadyrefundedfees * (0 - 1); if ($fees <= 0) { $fees = 0; } $result = select_query("tblaccounts", "SUM(amountin),SUM(amountout)", array("invoiceid" => $invoiceid)); $data = mysql_fetch_array($result); $invoicetotalpaid = $data[0]; $invoicetotalrefunded = $data[1]; if (!$amount) { $amount = $fullamount; } if (!$amount || $fullamount < $amount) { return "amounterror"; } $amount = format_as_currency($amount); if ($addascredit) { addTransaction($userid, 0, "Refund of Transaction ID " . $gatewaytransid . " to Credit Balance", 0, $fees * (0 - 1), $amount, "", "", $invoiceid, "", $transid, $rate); addTransaction($userid, 0, "Credit from Refund of Invoice ID " . $invoiceid, $amount, $fees, 0, "", "", "", "", "", ""); logActivity("Refunded Invoice Payment to Credit Balance - Invoice ID: " . $invoiceid, $userid); insert_query("tblcredit", array("clientid" => $userid, "date" => "now()", "description" => "Credit from Refund of Invoice ID " . $invoiceid, "amount" => $amount)); update_query("tblclients", array("credit" => "+=" . $amount), array("id" => (int) $userid)); if ($invoicetotalpaid - $invoicetotalrefunded - $amount <= 0) { update_query("tblinvoices", array("status" => "Refunded"), array("id" => $invoiceid)); run_hook("InvoiceRefunded", array("invoiceid" => $invoiceid)); } if ($sendemail) { sendMessage("Invoice Refund Confirmation", $invoiceid, array("invoice_refund_type" => "credit")); } return "creditsuccess"; } $result = select_query("tblpaymentgateways", "value", array("gateway" => $gateway, "setting" => "convertto")); $data = mysql_fetch_array($result); $convertto = $data['value']; if ($convertto) { $result = select_query("tblclients", "currency", array("id" => $userid)); $data = mysql_fetch_array($result); $fromcurrencyid = $data['currency']; $convertedamount = convertCurrency($amount, $fromcurrencyid, $convertto, $rate); } if ($gateway) { $params = getCCVariables($invoiceid); } if ($sendtogateway && function_exists($gateway . "_refund")) { $params['amount'] = $convertedamount ? $convertedamount : $amount; $params['transid'] = $gatewaytransid; $params['paymentmethod'] = $gateway; $gatewayresult = call_user_func($gateway . "_refund", $params); $refundtransid = $gatewayresult['transid']; $rawdata = $gatewayresult['rawdata']; if (isset($gatewayresult['fees'])) { $fees = $gatewayresult['fees']; } $gatewayresult = $gatewayresult['status']; $result = select_query("tblpaymentgateways", "value", array("gateway" => $gateway, "setting" => "name")); $data = mysql_fetch_array($result); $gatewayname = $data['value']; logTransaction($gatewayname . " Refund", $rawdata, ucfirst($gatewayresult)); } else { $gatewayresult = "manual"; run_hook("ManualRefund", array("transid" => $transid, "amount" => $amount)); } if ($gatewayresult == "success" || $gatewayresult == "manual") { addTransaction($userid, 0, "Refund of Transaction ID " . $gatewaytransid, 0, $fees * (0 - 1), $amount, $gateway, $refundtransid, $invoiceid, "", $transid, $rate); logActivity("Refunded Invoice Payment - Invoice ID: " . $invoiceid . " - Transaction ID: " . $transid, $userid); $result = select_query("tblinvoices", "total", array("id" => $invoiceid)); $data = mysql_fetch_array($result); $invoicetotal = $data[0]; if ($invoicetotalpaid - $invoicetotalrefunded - $amount <= 0) { update_query("tblinvoices", array("status" => "Refunded"), array("id" => $invoiceid)); run_hook("InvoiceRefunded", array("invoiceid" => $invoiceid)); } if ($sendemail) { sendMessage("Invoice Refund Confirmation", $invoiceid, array("invoice_refund_type" => "gateway")); } } return $gatewayresult; }
function convertCurrency($amount, $from, $to, $base_currency_exchange_rate = "") { if (!$base_currency_exchange_rate) { $result = select_query("tblcurrencies", "rate", array("id" => $from)); $data = mysql_fetch_array($result); $base_currency_exchange_rate = $data['rate']; } $result = select_query("tblcurrencies", "rate", array("id" => $to)); $data = mysql_fetch_array($result); $convertto_currency_exchange_rate = $data['rate']; if (!$base_currency_exchange_rate) { $base_currency_exchange_rate = 1; } if (!$convertto_currency_exchange_rate) { $convertto_currency_exchange_rate = 1; } $convertto_amount = format_as_currency($amount / $base_currency_exchange_rate * $convertto_currency_exchange_rate); return $convertto_amount; }
<form method="post" action="reports.php?report={$report}"> <table align="center"> <tr><td>Date From:</td><td><input type="text" name="datefrom" value="{$datefrom}" class="datepick" /></td><td width="20"></td><td>Date To:</td><td><input type="text" name="dateto" value="{$dateto}" class="datepick" /></td><td width="20"></td><td><input type="submit" value="Submit" /></tr> </table> </form> EOF; $reportdata["tableheadings"] = array("Coupon Code", "Discount Type", "Value", "Recurring", "Notes", "Usage Count", "Total Revenue"); $i = 0; $result = select_query("tblpromotions", "", "", "code", "ASC"); while ($data = mysql_fetch_array($result)) { $code = $data["code"]; $type = $data["type"]; $value = $data["value"]; $recurring = $data["recurring"]; $notes = $data["notes"]; $rowcount = $rowtotal = 0; $reportdata["drilldown"][$i]["tableheadings"] = array("Order ID", "Order Date", "Order Number", "Order Total", "Order Status"); $result2 = select_query("tblorders", "", "promocode='" . db_escape_string($code) . "' AND date>='" . db_make_safe_human_date($datefrom) . "' AND date<='" . db_make_safe_human_date($dateto) . "'", "id", "ASC"); while ($data = mysql_fetch_array($result2)) { $orderid = $data['id']; $ordernum = $data['ordernum']; $orderdate = $data['date']; $ordertotal = $data['amount']; $orderstatus = $data['status']; $rowcount++; $rowtotal += $ordertotal; $reportdata["drilldown"][$i]["tablevalues"][] = array('<a href="orders.php?action=view&id=' . $orderid . '">' . $orderid . '</a>', fromMySQLDate($orderdate), $ordernum, $ordertotal, $orderstatus); } $reportdata["tablevalues"][$i] = array($code, $type, $value, $recurring, $notes, $rowcount, format_as_currency($rowtotal)); $i++; }
$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']; insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "ProrataProduct" . $targetnextduedate, "relid" => $aid, "description" => $description, "amount" => $amountdue, "taxed" => $tax, "duedate" => "now()", "paymentmethod" => $paymentmethod)); } createInvoices($userid); }
} else { $client = "None"; } $ticketinvoicelinks = array(); foreach ($ticketids as $i => $ticketnum) { if ($ticketnum) { $ticketnum = get_query_val("tbltickets", "tid", array("tid" => $ticketnum)); $ticketinvoicelinks[] = "description LIKE '%Ticket #" . $ticketnum . "%'"; continue; } } $ticketinvoicesquery = !empty($ticketinvoicelinks) ? "(\".implode(' AND '," . $ticketinvoicelinks . ").\") OR " : ""; $totalinvoiced = get_query_val("tblinvoices", "SUM(subtotal+tax+tax2)", "id IN (SELECT invoiceid FROM tblinvoiceitems WHERE description LIKE '%Project #" . $projectid . "%' OR " . $ticketinvoicesquery . " (type='Project' AND relid='" . $projectid . "'))"); $totalinvoiced = $userid ? formatCurrency($totalinvoiced) : format_as_currency($totalinvoiced); $totalpaid = get_query_val("tblinvoices", "SUM(subtotal+tax+tax2)", "id IN (SELECT invoiceid FROM tblinvoiceitems WHERE description LIKE '%Project #" . $projectid . "%' OR " . $ticketinvoicesquery . " (type='Project' AND relid='" . $projectid . "')) AND status='Paid'"); $totalpaid = $userid ? formatCurrency($totalpaid) : format_as_currency($totalpaid); $reportdata['drilldown'][$i]['tableheadings'] = array("Task Name", "Start Time", "Stop Time", "Duration", "Task Status"); $timerresult = select_query("mod_projecttimes", "mod_projecttimes.start,mod_projecttimes.end,mod_projecttasks.task,mod_projecttasks.completed", array("mod_projecttimes.projectid" => $projectid), "", "", "", "mod_projecttasks ON mod_projecttimes.taskid = mod_projecttasks.id"); while ($data2 = mysql_fetch_assoc($timerresult)) { $rowcount = $rowtotal = 0; $taskid = $data2['id']; $task = $data2['task']; $taskadminid = $data2['adminid']; $timerstart = $data2['start']; $timerend = $data2['end']; $duration = $timerend ? $timerend - $timerstart : 0; $taskadmin = getAdminName($taskadminid); $starttime = date("d/m/Y H:i:s ", $timerstart); $stoptime = date("d/m/Y H:i:s ", $timerend); $taskstatus = $data2['completed'] ? "Completed" : "Open"; $totalprojectstime += $duration;
if ($CONFIG['TaxL2Compound']) { $tempsubtotal += $tax; } if ($CONFIG['TaxType'] == "Inclusive") { $inctaxrate = 1 + $taxrate / 100; $subtotal = $tempsubtotal / $inctaxrate; $tax2 = $tempsubtotal - $subtotal; } else { $tax2 = $tempsubtotal * ($taxrate2 / 100); } } $tax = round($tax, 2); $tax2 = round($tax2, 2); } $tax = format_as_currency($tax); $tax2 = format_as_currency($tax2); $smarty->assign("taxenabled", $CONFIG['TaxEnabled']); $smarty->assign("taxname", $taxname); $smarty->assign("taxrate", $taxrate); $smarty->assign("tax", formatCurrency($tax)); $smarty->assign("taxname2", $taxname2); $smarty->assign("taxrate2", $taxrate2); $smarty->assign("tax2", formatCurrency($tax2)); $total = $subtotal + $tax + $tax2; $total = formatCurrency($total); $smarty->assign("total", $total); } else { if ($step == "3") { check_token(); $orderdescription = ""; $serviceid = $_POST['id'];