/** * Change the quantity of an item */ function changeqty($VAR) { if (empty($this->account_id)) { $this->account_id = SESS_ACCOUNT; } if (empty($this->session_id)) { $this->session_id = SESS; } @($id = $VAR['id']); @($qty = $VAR['qty']); if ($id <= 0) { return; } $db =& DB(); if ($qty == '0') { # Product Plugin Level deletion $cartid =& $db->Execute($sql = sqlSelect($db, "cart", "*", "id=::{$id}:: AND session_id = ::{$this->session_id}::")); if ($cartid) { $product =& $db->Execute($sql = sqlSelect($db, "product", "*", "id=::{$cartid->fields['product_id']}::")); } if (!empty($product->fields['prod_plugin']) && !empty($product->fields['prod_plugin_data'])) { $prodplgfile = PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php'; if (is_file($prodplgfile)) { include_once PATH_PLUGINS . 'product/' . $product->fields['prod_plugin_file'] . '.php'; eval('$prodplg = new plgn_prov_' . $product->fields['prod_plugin_file'] . ';'); if (is_object($prodplg)) { if (is_callable(array($prodplg, 'delete_cart'))) { $prodplg->delete_cart($VAR, $cartid->fields); } } } } # delete main cart items & subitems: $sql = ''; if (empty($this->admin)) { $sql = "AND session_id = ::{$this->session_id}::"; } $rs =& $db->Execute($sql = sqlDelete($db, "cart", "(id=::{$id}:: OR cart_parent_id=::{$id}:: ) {$sql}")); global $smarty; $smarty->assign('js', false); return false; } # update the quantity: if (!eregi("^[0-9]{1,5}\$", $qty)) { $qty = 1; } if ($qty < 1) { $qty = 1; } if (!$this->admin) { $sql_extra = " AND session_id=::{$this->session_id}::"; } else { $sql_extra = ''; } if ($VAR["type"] == 1) { $fields = array('quantity' => $qty); $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}")); } else { if ($VAR["type"] == 2) { $fields = array('recurr_schedule' => $VAR["schedule"]); $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}")); } else { if ($VAR["type"] == 3) { # change domain term $fields = array('domain_term' => $VAR["term"]); $db->Execute($sql = sqlUpdate($db, "cart", $fields, "id=::{$id}:: {$sql_extra}")); } } } # get the product id: $result = $db->Execute(sqlSelect($db, "cart", "*", "id={$id} {$sql_extra}", "cart_type,date_orig")); # get the product details: $product = $db->Execute(sqlSelect($db, "product", "*", "id={$result->fields["product_id"]}")); if ($result->fields["cart_type"] == "2") { # domain name, get pricing include_once PATH_MODULES . 'host_tld/host_tld.inc.php'; $tldObj = new host_tld(); $tldprice = $tldObj->price_tld_arr($result->fields["domain_tld"], $result->fields["host_type"], false, false, false, $this->account_id); $qty = $result->fields["domain_term"]; $base_price = $tldprice[$qty]; $setup_price = 0; } else { if ($result->fields["cart_type"] == "3") { # ad-hoc, get price $base_price = $result->fields["ad_hoc_amount"] * $result->fields["quantity"]; $setup_price = $result->fields["ad_hoc_setup"] * $result->fields["quantity"]; } else { include_once PATH_MODULES . 'product/product.inc.php'; $productObj = new product(); # get pricing for this product: $prod_price = $productObj->price_prod($product->fields, $result->fields["recurr_schedule"], $this->account); $setup_price = $prod_price["setup"] * $result->fields["quantity"]; $base_price = $prod_price["base"] * $result->fields["quantity"]; # get pricing for any attributes: $attr_price = $productObj->price_attr($product->fields, $result->fields["product_attr"], $result->fields["recurr_schedule"], $this->account); $setup_price += $attr_price["setup"] * $result->fields["quantity"]; $base_price += $attr_price["base"] * $result->fields["quantity"]; # get the qty $qty = $result->fields["quantity"]; } } # set the smarty fields: global $smarty; $smarty->assign('qty', $qty); $smarty->assign('base', $base_price); $smarty->assign('setup', $setup_price); $smarty->assign('js', true); return; }
/** Invoice expiring domains p2 */ function generatedomaininvoice($VAR) { include_once PATH_MODULES . 'tax/tax.inc.php'; $taxObj = new tax(); $db =& DB(); if (is_array($VAR)) { $expire = time(); $rs = $db->Execute(sqlSelect($db, 'service', '*', " id = ::{$VAR['id']}:: AND active=1\n\t \t\t\t\tAND type = 'domain' AND queue = 'none' AND\n\t \t\t\t\t( domain_type = 'register' OR domain_type = 'transfer' OR domain_type = 'renew' ) AND\n\t \t\t\t\t( suspend_billing = 0 OR suspend_billing IS NULL ) ")); $service = $rs->fields; } else { $service = $VAR; } if (empty($service['id'])) { global $C_debug; $C_debug->alert("Unable to generate domain renweal invoice due to domain status."); return false; } # Get the parent invoice details: if (!empty($service['invoice_id'])) { $rs = $db->Execute(sqlSelect($db, 'invoice', '*', " id = {$service['invoice_id']} ", "")); $invoice = $rs->fields; } else { $invoice = false; } # Get the account details: $rs = $db->Execute(sqlSelect($db, 'account', '*', " id = {$service['account_id']} ", "")); $account = $rs->fields; # Get the account price include_once PATH_MODULES . 'host_tld/host_tld.inc.php'; $tldObj = new host_tld(); $tld_arr = $tldObj->price_tld_arr($service['domain_tld'], 'renew', false, false, false, $service['account_id']); foreach ($tld_arr as $term => $price) { break; } # Calculate taxes: $rs = $db->Execute($sql = sqlSelect($db, "host_tld", "taxable", "name = ::{$service['domain_tld']}::")); if ($service['taxable'] || @$rs->fields['taxable']) { $tax_arr = $taxObj->calculate($price, $account["country_id"], $account["state"]); } else { $tax_arr = false; } $total = $price; $tax_amt = 0; if (is_array($tax_arr)) { foreach ($tax_arr as $tx) { $tax_amt += $tx['rate']; } $total += $tax_amt; } # calculate the dates $expire = $service['domain_date_expire'] + $term * 86400; $due_date = $service['domain_date_expire'] - 86400 * 3; # Create the invoice $id = sqlGenID($db, "invoice"); $insert = $db->Execute($sql = sqlInsert($db, "invoice", array('date_orig' => time(), 'date_last' => time(), 'type' => 2, 'process_status' => 0, 'billing_status' => 0, 'suspend_billing' => 0, 'print_status' => 0, 'parent_id' => $service['invoice_id'], 'account_id' => $service['account_id'], 'account_billing_id' => $service['account_billing_id'], 'affiliate_id' => @$invoice['affiliate_id'], 'campaign_id' => @$invoice['campaign_id'], 'reseller_id' => @$invoice['reseller_id'], 'checkout_plugin_id' => @$invoice['checkout_plugin_id'], 'tax_amt' => $tax_amt, 'discount_arr' => serialize(@$discount_arr), 'discount_amt' => @$discount_amt, 'total_amt' => $total, 'billed_amt' => 0, 'billed_currency_id' => DEFAULT_CURRENCY, 'actual_billed_amt' => 0, 'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'], 'notice_count' => 0, 'notice_next_date' => time(), 'notice_max' => MAX_BILLING_NOTICE, 'grace_period' => 0, 'due_date' => $due_date), $id)); # create the invoice item: if ($insert) { $db->Execute($idx = sqlInsert($db, "invoice_item", array('date_orig' => time(), 'invoice_id' => $id, 'account_id' => $service['account_id'], 'service_id' => $service['id'], 'sku' => 'DOMAIN-RENEW', 'quantity' => 1, 'item_type' => 2, 'price_type' => 0, 'price_base' => $price, 'price_setup' => 0, 'domain_type' => 'renew', 'date_start' => $service['domain_date_expire'], 'date_stop' => $expire, 'domain_name' => $service['domain_name'], 'domain_tld' => $service['domain_tld'], 'domain_term' => $term, 'tax_amt' => $tax_amt, 'total_amt' => $price))); # Insert tax records $taxObj->invoice_item($id, $idx, $service['account_id'], @$item_tax_arr); # Update the service record $fields = array('active' => 0); $db->Execute(sqlUpdate($db, "service", $fields, "id = {$service['id']}")); global $C_debug; $C_debug->alert("Generated domain renewal invoice for {$service['domain_name']}.{$service['domain_tld']}"); return $id; } }