/** provision did */ function provision_did_new($obj) { @($a = unserialize($obj->service['prod_attr_cart'])); $did = $a['station']; // new or top-up? $db =& DB(); $didrs = $db->Execute($sql = sqlSelect($db, "voip_prepaid", "id,pin,balance", "pin = ::{$did}:: AND voip_did_id is not null AND voip_did_id <> 0 ")); if ($didrs && $didrs->RecordCount() > 0) { $new = false; } else { $new = true; } // the balance from the invoice line item (not including setup fee) $itemid = $obj->service['invoice_item_id']; $invoiceItem = $db->Execute(sqlSelect($db, "invoice_item", "price_base", "id = {$itemid}")); if ($invoiceItem && $invoiceItem->RecordCount() > 0) { $balance = $invoiceItem->fields['price_base']; } else { $balance = $obj->service['price']; } /* echo "<BR><BR>$sql<BR><BR>"; echo $new; echo "$".$balance; #print_r($obj->service); */ if ($new) { // include voip plugin and provision the did include_once PATH_PLUGINS . 'product/VOIP.php'; $voip = new plgn_prov_VOIP(); if (!$voip->p_one($obj->service_id)) { return false; } # create the prepaid record $didrs = $db->Execute(sqlSelect($db, "voip_did", "id,did", "service_id = ::{$obj->service_id}::")); if ($didrs && $didrs->RecordCount() > 0) { $fields = array('account_id' => $obj->account['id'], 'product_id' => $obj->service['product_id'], 'voip_did_id' => $didrs->fields['id'], 'pin' => $didrs->fields['did'], 'balance' => $balance, 'in_use' => 0); $pin_id = sqlGenID($db, "voip_prepaid"); $sql = sqlInsert($db, "voip_prepaid", $fields, $pin_id); $rs = $db->Execute($sql); return true; } else { return false; } } else { # top-up the prepaid balance $fields = array('balance' => $balance + $didrs->fields['balance']); $db->Execute($sql = sqlUpdate($db, "voip_prepaid", $fields, "id = {$didrs->fields['id']}")); return true; } return true; }
function p_delete() { $db =& DB(); # determine the prepaid type: switch ($this->product_attr['type']) { case 'ani': $sql = sqlDelete($db, "voip_prepaid", "pin=::{$this->prod_attr_cart['ani_new']}::"); $db->Execute($sql); break; case 'did': include_once PATH_PLUGINS . 'product/VOIP.php'; $voip = new plgn_prov_VOIP(); $voip->p_one($this->service_id); break; } $rs = $db->Execute($sql = sqlSelect($db, "voip_did", "id,did", "service_id = {$this->service_id}")); $did_id = $rs->fields['id']; $db->Execute($sql = sqlDelete($db, "voip_prepaid", "voip_did_id = {$did_id}")); return true; }