function modifyService($item, $billing_id) { global $C_debug; # Get the product details $db =& DB(); $q = "SELECT * FROM " . AGILE_DB_PREFIX . "product WHERE\n\t \t id \t\t= " . $db->qstr($item->fields['product_id']) . " AND\n\t \t site_id \t= " . $db->qstr(DEFAULT_SITE); $prod = $db->Execute($q); # Get the current service details $q = "SELECT * FROM " . AGILE_DB_PREFIX . "service WHERE\n\t \t id \t\t= " . $db->qstr($item->fields['service_id']) . " AND\n\t \t site_id \t= " . $db->qstr(DEFAULT_SITE); $servrs = $db->Execute($q); $service = $servrs->fields; $service_id = $service['id']; # Determine Price, Price Type, and Next Invoice Date: if ($item->fields['price_type'] == '1') { # Recurring Item $this->recurring_schedule = $item->fields['recurring_schedule']; $this->price = $item->fields['price_base']; $this->bind = '1'; # Determine the next invoice date: $this->next_invoice = $this->calcNextInvoiceDate(time(), $this->recurring_schedule, $prod->fields['price_recurr_type'], $prod->fields['price_recurr_weekday'], $prod->fields['price_recurr_week']); # Determine the last invoice date: if (empty($service['date_last_invoice'])) { $this->last_invoice = time(); } else { $this->last_invoice = $service['date_last_invoice']; } $old_unit = $this->getDailyCost($service['recur_schedule'], $service['price']); $new_unit = $this->getDailyCost($item->fields['recurring_schedule'], $this->price); //echo "old_unit=$old_unit <br> new_unit=$new_unit <br>"; $daysLeft = ceil(($service['date_next_invoice'] - time()) / 86400); $prorated = $old_unit * $daysLeft; $daysDiff = ceil($prorated / $new_unit); //echo "daysLeft=$daysLeft prorated=$prorated daysDiff=$daysDiff <br>"; //echo "dt=". date("d-m-Y", $this->next_invoice)."<br>"; $this->next_invoice += $daysDiff * 86400; //echo "final dt=". date("d-m-Y", $this->next_invoice) ."<br>"; } # If set-date type recurring transaction, determine full price: if ($prod->fields['price_type'] == '1' && $prod->fields['price_recurr_type'] == '1') { include_once PATH_MODULES . 'cart/cart.inc.php'; $cart = new cart(); $price = $cart->price_prod($prod->fields, $this->recurring_schedule, $invoice->fields['account_id'], false); $this->price = $price['base']; $price = $cart->price_attr($prod->fields, $item->fields['product_attr_cart'], $this->recurring_schedule, $invoice->fields['account_id'], false); $this->price += $price['base']; } # Determine the Service Type: if (!empty($prod->fields['assoc_grant_group'])) { if (!empty($prod->fields['prod_plugin'])) { $this->type = 'product_group'; } elseif (!empty($prod->fields['host'])) { $this->type = 'host_group'; } else { $this->type = 'group'; } } elseif (!empty($prod->fields['prod_plugin'])) { $this->type = 'product'; } elseif (!empty($prod->fields['host'])) { $this->type = 'host'; } else { $this->type = 'none'; } # Reconfigure host data: $host_arr = ""; if ($this->type == "host" || $this->type == "host_group") { $old = serialize($service['host_provision_plugin_data']); $host_arr = $prod->fields['host_provision_plugin_data']; if (is_array($old) && count($old) > 0) { foreach ($old as $key => $val) { if (!isset($host_arr["{$key}"]) && @$old["{$key}"] != "") { $host_arr["{$key}"] = $val; } } } } # Create the item record: $q = "UPDATE " . AGILE_DB_PREFIX . "service SET\n\t\t date_last\t\t\t\t= " . $db->qstr(time()) . ", \n\t\t invoice_id\t\t\t\t= " . $db->qstr($item->fields['invoice_id']) . ",\n\t\t invoice_item_id\t\t\t= " . $db->qstr($item->fields['id']) . ", \n\t\t account_billing_id \t\t= " . $db->qstr($billing_id) . ",\n\t\t product_id\t\t\t\t= " . $db->qstr($prod->fields['id']) . ",\n\t\t sku\t\t\t\t\t\t= " . $db->qstr($item->fields['sku']) . ",\n\t\t active\t\t\t\t\t= " . $db->qstr(1) . ", \n\t\t type\t\t\t\t\t= " . $db->qstr($this->type) . ",\n\t\t queue\t\t\t\t\t= " . $db->qstr('edit') . ", \n\t\t price\t\t\t\t\t= " . $db->qstr(@$this->price) . ",\n\t\t price_type\t\t\t\t= " . $db->qstr($prod->fields['price_type']) . ",\n\t\t taxable\t\t\t\t\t= " . $db->qstr($prod->fields['taxable']) . ", \n\t\t date_last_invoice\t\t= " . $db->qstr(@$this->last_invoice) . ",\n\t\t date_next_invoice\t\t= " . $db->qstr(@$this->next_invoice) . ",\n\t\t recur_schedule\t\t\t= " . $db->qstr(@$this->recurring_schedule) . ",\n\t\t recur_type\t\t\t\t= " . $db->qstr($prod->fields['price_recurr_type']) . ",\n\t\t recur_weekday\t\t\t= " . $db->qstr($prod->fields['price_recurr_weekday']) . ",\n\t\t recur_week\t\t\t\t= " . $db->qstr($prod->fields['price_recurr_week']) . ",\n\t\t recur_schedule_change \t= " . $db->qstr($prod->fields['price_recurr_schedule']) . ",\n\t\t recur_cancel\t\t\t= " . $db->qstr($prod->fields['price_recurr_cancel']) . ", \n\t\t recur_modify\t\t\t= " . $db->qstr($prod->fields['price_recurr_modify']) . ", \n\t\t group_grant\t\t\t\t= " . $db->qstr($prod->fields['assoc_grant_group']) . ",\n\t\t group_type\t\t\t\t= " . $db->qstr($prod->fields['assoc_grant_group_type']) . ",\n\t\t group_days\t\t\t\t= " . $db->qstr($prod->fields['assoc_grant_group_days']) . ", \n\t\t host_provision_plugin_data=" . $db->qstr(@$host_arr) . ", \n\t\t prod_plugin_name\t\t= " . $db->qstr(@$prod->fields["prod_plugin_file"]) . ",\n\t\t prod_plugin_data\t\t= " . $db->qstr(@$prod->fields["prod_plugin_data"]) . " \n\t\t WHERE \n\t\t site_id = " . DEFAULT_SITE . " AND id = {$service_id}"; $rs = $db->Execute($q); if ($rs === false) { global $C_debug; $C_debug->error('service.inc.php', 'invoiceItemToService', $q . " | " . @$db->ErrorMsg()); } # Run the queue on this item: $this->queue_one($service_id, false); return true; }