/** * saveAll * Save all the data * @param $params * @return Boolean */ public static function saveAll($id, $params) { $date_end = null; if (!is_array($params)) { return false; } $details = Doctrine::getTable('OrdersItems')->find($id); // Generic price setting $rowtotal = $params['price']; $vat = null; $percentage = null; // Get the taxes applied $tax = Taxes::getTaxbyProductID($params['product_id']); if ($tax['percentage'] > 0) { $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100; $vat = $params['price'] * $tax['percentage'] / 100; $percentage = $tax['percentage']; } else { if (!empty($params['parameters'])) { // it is a domain $domainparams = json_decode($params['parameters'], true); if (!empty($domainparams['domain']['tld'])) { $tax = Taxes::getTaxbyTldID($domainparams['domain']['tld']); if ($tax['percentage'] > 0) { $vat = $params['price'] * $tax['percentage'] / 100; $percentage = $tax['percentage']; $rowtotal = $params['price'] * (100 + $tax['percentage']) / 100; } } } } if (!empty($params['billing_cycle_id'])) { $months = BillingCycle::getMonthsNumber($params['billing_cycle_id']); } if ($months > 0 && is_numeric($params['product_id']) && $params['product_id'] > 0) { // only for the product and services. Domains excluded $rowtotal = $rowtotal * $months; } $params['date_end'] = Shineisp_Commons_Utilities::add_date($params['date_start'], null, $months); $details->quantity = $params['quantity']; $details->date_start = Shineisp_Commons_Utilities::formatDateIn($params['date_start']); $details->date_end = Shineisp_Commons_Utilities::formatDateIn($params['date_end']); $details->billing_cycle_id = !empty($params['billing_cycle_id']) ? $params['billing_cycle_id'] : null; $details->price = $params['price']; $details->vat = $vat; $details->percentage = $percentage; $details->cost = $params['cost']; $details->product_id = is_numeric($params['product_id']) && $params['product_id'] > 0 ? $params['product_id'] : NULL; $details->setupfee = $params['setupfee']; $details->discount = $params['discount']; $details->subtotal = $rowtotal * $params['quantity']; $details->status_id = $params['status_id']; $details->description = $params['description']; $details->parameters = $params['parameters']; if ($details->trySave()) { OrdersItems::setAutorenew($id, $params['autorenew']); // Remove all domains OrdersItemsDomains::removeAllDomains($id); if ($params['domains_selected']) { foreach ($params['domains_selected'] as $domain) { OrdersItemsDomains::addDomain($details['order_id'], $domain); } } return true; } return false; }
/** * Get the price of the product * * If there's a refund subtrack to the price (20130409) * @param integer $productid * @param float $refund */ public static function getPrices($productid, $refund = false) { $prices = array(); if (is_numeric($productid)) { $product = self::getAllInfo($productid); // Get the tax percentage $tax = Taxes::getTaxbyProductID($productid); if (!empty($product)) { if (!empty($product['price_1']) && $product['price_1'] > 0) { if ($refund !== false) { $priceToPayWithRefund = $product['price_1'] - $refund; if ($priceToPayWithRefund < 0) { $product['price_1'] = $priceToPayWithRefund; } } // Taxes calculation if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $taxincluded = $product['price_1'] * ($tax['percentage'] + 100) / 100; } else { $taxincluded = $product['price_1']; } return array('type' => 'flat', 'value' => $product['price_1'], 'taxincluded' => $taxincluded, 'taxes' => $tax); } else { // Get the price min & max interval tranches $tranches = ProductsTranches::getMinMaxTranches($productid); if (!empty($tranches[1])) { // Refund calculation price if ($refund !== false) { $idBillingCircle = $tranches[0]['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $tranches[0]['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $tranches[0]['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $tranches[0]['price'] - $refund; if ($priceToPayWithRefund > 0) { $tranches[0]['price'] = $priceToPayWithRefund; } } $idBillingCircle = $tranches[1]['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $tranches[1]['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $tranches[1]['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $tranches[1]['price'] - $refund; if ($priceToPayWithRefund > 0) { $tranches[1]['price'] = $priceToPayWithRefund; } } } // Taxes calculation if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $minvaluewithtaxes = $tranches[0]['price'] * ($tax['percentage'] + 100) / 100; $maxvaluewithtaxes = $tranches[1]['price'] * ($tax['percentage'] + 100) / 100; } else { $minvaluewithtaxes = $tranches[0]['price']; $maxvaluewithtaxes = $tranches[1]['price']; } $discount = floatval($tranches[1]['price']) - floatval($tranches[0]['price']); $minvalue = $tranches[0]['price']; $maxvalue = $tranches[1]['price']; $data = array('type' => 'multiple', 'measurement' => $tranches[0]['measurement'], 'tranches' => $tranches, 'minvalue' => $minvalue, 'maxvalue' => $maxvalue, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => $maxvaluewithtaxes, 'discount' => $discount, 'taxes' => $tax); return $data; } elseif (!empty($tranches['price'])) { // Taxes calculation if ($refund !== false) { $priceToPayWithRefund = $tranches['price'] - $refund; if ($priceToPayWithRefund < 0) { $tranches['price'] = $priceToPayWithRefund; } } if (!empty($tax['percentage']) && is_numeric($tax['percentage'])) { $minvaluewithtaxes = $tranches['price'] * ($tax['percentage'] + 100) / 100; } else { $minvaluewithtaxes = $tranches['price']; } $price = $tranches['price']; $data = array('type' => 'multiple', 'measurement' => $tranches['measurement'], 'minvalue' => $price, 'maxvalue' => $price, 'taxes' => $tax, 'minvaluewithtaxes' => $minvaluewithtaxes, 'maxvaluewithtaxes' => 0, 'discount' => 0); return $data; } } } } return array('type' => 'flat', 'value' => 0, 'taxincluded' => 0, 'taxes' => 0); }
/** * renewOrder * Renew of Order * @return orderid integer */ public static function renewOrder($customer_id, $products) { $order = new Orders(); $i = 0; $total = 0; $vat = 0; $tldid = null; // Check if there are auto-renewal services/products if (!self::checkAutorenewProducts($products)) { return false; } if (is_numeric($customer_id)) { $customer = Customers::getAllInfo($customer_id); if (count($products) > 0) { $order->customer_id = $customer_id; $order->isp_id = $customer['isp_id']; $order->is_renewal = true; $order->order_date = date('Y-m-d'); $order->status_id = Statuses::id("tobepaid", "orders"); // To be paid $order->uuid = Shineisp_Commons_Uuid::generate(); $order->save(); // Create the public number but I need the order id $order->order_number = self::formatOrderId($order->getIncremented()); $order->save(); // Get the generated order id $orderid = $order->getIncremented(); // Log data Shineisp_Commons_Utilities::log("A new renewal order (" . $order->order_number . ") for " . $customer['fullname'] . " has been created successfully"); // Add a fastlink to a order $link_exist = Fastlinks::findlinks($orderid, $customer_id, 'orders'); if (count($link_exist) == 0) { $link = new Fastlinks(); $link->controller = "orders"; $link->action = "edit"; $link->params = json_encode(array('id' => $orderid)); $link->customer_id = $customer_id; $link->sqltable = "orders"; $link->id = $orderid; $link->code = Shineisp_Commons_Utilities::GenerateRandomString(); $link->save(); } if (count($products) > 0) { foreach ($products as $product) { $orderitem = new OrdersItems(); if (!empty($product['oldorderitemid']) && is_numeric($product['oldorderitemid'])) { // Find the details of the old order item details $oldOrderDetails = OrdersItems::find($product['oldorderitemid'], null, true); // Check if the last order is present in the db and check if the product must be renewed if (!empty($oldOrderDetails[0]) && $product['renew']) { // Set the new order details fields $orderitem->order_id = $orderid; $orderitem->product_id = $oldOrderDetails[0]['product_id']; $orderitem->billing_cycle_id = $oldOrderDetails[0]['billing_cycle_id']; if ($product['type'] == "service") { // Get the number of the months to be sum to the expiration date of the service $date_end = Shineisp_Commons_Utilities::add_date(date($oldOrderDetails[0]['date_end']), null, BillingCycle::getMonthsNumber($oldOrderDetails[0]['billing_cycle_id']) * $oldOrderDetails[0]['quantity']); $orderitem->date_start = $oldOrderDetails[0]['date_end']; // The new order will have the date_end as date_start $orderitem->date_end = Shineisp_Commons_Utilities::formatDateIn($date_end); $orderitem->price = $oldOrderDetails[0]['price']; $orderitem->vat = $oldOrderDetails[0]['vat']; $orderitem->percentage = $oldOrderDetails[0]['percentage']; $orderitem->subtotal = $oldOrderDetails[0]['subtotal']; $orderitem->cost = $oldOrderDetails[0]['cost']; } elseif ($product['type'] == "domain") { // Get the number of the months to be sum to the expiration date of the domain $parameters = json_decode($oldOrderDetails[0]['parameters'], true); $tldid = !empty($parameters['tld']) ? $parameters['tld'] : NULL; $domain = !empty($parameters['domain']['name']) ? $parameters['domain']['name'] : NULL; // get the tld information $arrdomain = Shineisp_Commons_Utilities::getTld($domain); if (!empty($arrdomain[1])) { $tld = DomainsTlds::getbyTld($arrdomain[1]); if (!empty($tld['tld_id'])) { $tax = Taxes::getTaxbyTldID($tld['tld_id']); // Check if the product has some tax to be added $orderitem->tld_id = $tld['tld_id']; if (!empty($tld['tax_id'])) { $vat = $tld['renewal_price'] * $tax['percentage'] / 100; $subtotal = $tld['renewal_price'] * ($tax['percentage'] + 100) / 100; $percentage = $tax['percentage']; } else { $vat = 0; $subtotal = $tld['renewal_price']; $percentage = 0; } } } $date_end = Shineisp_Commons_Utilities::add_date(date($product['expiring_date']), null, BillingCycle::getMonthsNumber($oldOrderDetails[0]['billing_cycle_id']) * $oldOrderDetails[0]['quantity']); $orderitem->date_start = $product['expiring_date']; // The new order will have the date_end as date_start $orderitem->date_end = Shineisp_Commons_Utilities::formatDateIn($date_end); $orderitem->parameters = json_encode(array('domain' => array('name' => trim($domain), 'tld' => $tldid, 'action' => 'renewDomain', 'authinfo' => null))); $orderitem->vat = $vat; $orderitem->percentage = $percentage; $orderitem->subtotal = $subtotal; $orderitem->price = $tld['renewal_price']; $orderitem->cost = $tld['renewal_cost']; } $orderitem->autorenew = $oldOrderDetails[0]['autorenew']; $orderitem->description = $oldOrderDetails[0]['description']; $orderitem->quantity = $oldOrderDetails[0]['quantity']; $orderitem->status_id = Statuses::id("tobepaid", "orders"); // To be payed status set $orderitem->save(); $newOrderItemId = $orderitem->getIncremented(); // Attach all the services, products, and domains with the order $oldOID = OrdersItemsDomains::findIDsByOrderItemID($product['oldorderitemid'], null, true); if (isset($oldOID[0])) { // Some services are not linked to a domain $ordersitemsdomains = new OrdersItemsDomains(); $ordersitemsdomains->domain_id = $oldOID[0]['domain_id']; $ordersitemsdomains->order_id = $orderid; $ordersitemsdomains->orderitem_id = $newOrderItemId; $ordersitemsdomains->save(); } $i++; } } } // If there are items to be save ... if ($i > 0) { // Update Order self::updateTotalsOrder($orderid); } return $orderid; } } } }
/** * getList * Get the product options by productid * @param $productid * @return array */ public static function getList($productid, $refund = false) { $translator = Shineisp_Registry::getInstance()->Zend_Translate; $currency = Shineisp_Registry::getInstance()->Zend_Currency; try { $items = array(); $dq = Doctrine_Query::create()->from('ProductsTranches pt')->leftJoin('pt.BillingCycle bc')->where('pt.product_id = ?', $productid)->orderBy('bc.months asc'); $records = $dq->execute(array(), Doctrine_Core::HYDRATE_ARRAY); // Check the refund options foreach ($records as $c) { if ($refund !== false) { $idBillingCircle = $c['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $c['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $c['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $c['price'] - $refund; if ($priceToPayWithRefund > 0) { $c['price'] = $priceToPayWithRefund; } } } $items[$c['tranche_id']] = ""; // If quantity is more than one ShineISP must show the item quantity if ($c['quantity'] > 1) { $items[$c['tranche_id']] .= "No. " . $c['quantity'] . " "; } $items[$c['tranche_id']] .= "(" . $translator->translate($c['BillingCycle']['name']) . ") - " . $currency->toCurrency($c['price'], array('currency' => Settings::findbyParam('currency'))); if (!empty($c['measurement'])) { $items[$c['tranche_id']] .= "/" . $translator->translate($c['measurement']); } } return $items; } catch (Exception $e) { die($e->getMessage()); } }
public function getpriceAction() { $currency = Shineisp_Registry::get('Zend_Currency'); $translator = Shineisp_Registry::get('Zend_Translate'); $id = $this->getRequest()->getParam('id'); $refund = $this->getRequest()->getParam('refund'); $data = array(); if (is_numeric($id)) { $tranche = ProductsTranches::getTranchebyId($id); // JAY 20130409 - Add refund if exist $NS = new Zend_Session_Namespace('Default'); if (is_array($NS->upgrade)) { //Check if the product is OK for upgrade and if OK take refund foreach ($NS->upgrade as $orderid => $upgradeProduct) { if ($orderid != 0) { if (in_array($id, $upgradeProduct)) { $refundInfo = OrdersItems::getRefundInfo($orderid); $refund = $refundInfo['refund']; $idBillingCircle = $tranche['BillingCycle']['billing_cycle_id']; $monthBilling = BillingCycle::getMonthsNumber($idBillingCircle); if ($monthBilling > 0) { $priceToPay = $tranche['price'] * $monthBilling; $priceToPayWithRefund = $priceToPay - $refund; if ($priceToPayWithRefund < 0) { $priceToPayWithRefund = $priceToPay; } $tranche['price'] = round($priceToPayWithRefund / $monthBilling, 2); } else { $priceToPayWithRefund = $tranche['price'] - $refund; if ($priceToPayWithRefund > 0) { $tranche['price'] = $priceToPayWithRefund; } } break; } } } } $includes = ProductsTranchesIncludes::getIncludeForTrancheId($id); $textIncludes = array(); if (array_key_exists('domains', $includes)) { $textIncludes[] = $this->translator->translate('Domains Included') . ": " . implode(", ", $includes['domains']); } $textInclude = ""; if (!empty($textIncludes)) { $textInclude = implode("<br/>", $textIncludes); } // Prepare the data to send to the json $data['price'] = $tranche['price']; if (!empty($tranche['Products']['Taxes']['percentage']) && is_numeric($tranche['Products']['Taxes']['percentage'])) { $data['pricetax'] = $tranche['price'] * ($tranche['Products']['Taxes']['percentage'] + 100) / 100; } else { $data['pricetax'] = $tranche['price']; } $data['pricelbl'] = $currency->toCurrency($tranche['price'], array('currency' => Settings::findbyParam('currency'))); $data['months'] = $tranche['BillingCycle']['months']; $data['pricepermonths'] = $data['pricetax'] * $tranche['BillingCycle']['months']; $data['name'] = $this->translator->translate($tranche['BillingCycle']['name']); $data['pricetax'] = $currency->toCurrency($data['pricetax'], array('currency' => Settings::findbyParam('currency'))); $data['pricepermonths'] = $currency->toCurrency($data['pricepermonths'], array('currency' => Settings::findbyParam('currency'))); $data['setupfee'] = $currency->toCurrency($tranche['setupfee'], array('currency' => Settings::findbyParam('currency'))); $data['includes'] = $textInclude; } die(json_encode($data)); }
/** * processAction * Update the record previously selected * @return unknown_type */ public function processAction() { $i = 0; $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $form = $this->getForm("/admin/services/process"); $request = $this->getRequest(); // Create the buttons in the edit form $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/services/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/services/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null))); // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('list', 'services', 'admin'); } if ($form->isValid($request->getPost())) { // Get the id $id = $this->getRequest()->getParam('detail_id'); // Set the new values if (is_numeric($id)) { $this->services = Doctrine::getTable('OrdersItems')->find($id); } // Get the values posted $params = $form->getValues(); $datestart = explode(" ", $params['date_start']); try { $months = BillingCycle::getMonthsNumber($params['billing_cycle_id']); if ($months > 0) { $date_end = Shineisp_Commons_Utilities::add_date($datestart[0], null, $months); } else { $date_end = null; } $this->services->date_start = Shineisp_Commons_Utilities::formatDateIn($params['date_start']); $this->services->date_end = Shineisp_Commons_Utilities::formatDateIn($date_end); $this->services->order_id = $params['order_id']; $this->services->product_id = $params['product_id']; $this->services->billing_cycle_id = $params['billing_cycle_id']; $this->services->quantity = $params['quantity']; $this->services->status_id = $params['status_id']; $this->services->setup = $params['setup']; $this->services->note = $params['note']; // Save the data $this->services->save(); $id = is_numeric($id) ? $id : $this->services->getIncremented(); // Set the autorenew OrdersItems::setAutorenew($id, $params['autorenew']); // Save the message note if (!empty($params['message'])) { $message = new Messages(); $message->dateposted = date('Y-m-d H:i:s'); $message->message = $params['message']; $message->isp_id = 1; $message->detail_id = $id; $message->save(); } // Clear the list from the DB Doctrine::getTable('OrdersItemsDomains')->findBy('orderitem_id', $id)->delete(); if ($params['domains_selected']) { $service_domains = new Doctrine_Collection('OrdersItemsDomains'); foreach ($params['domains_selected'] as $domain) { $service_domains[$i]->domain_id = $domain; $service_domains[$i]->order_id = $params['order_id']; $service_domains[$i]->orderitem_id = $id; $i++; } $service_domains->save(); } $this->_helper->redirector('edit', 'services', 'admin', array('id' => $id, 'mex' => 'The task requested has been executed successfully.', 'status' => 'success')); } catch (Exception $e) { $this->_helper->redirector('edit', 'services', 'admin', array('id' => $id, 'mex' => $this->translator->translate('Unable to process the request at this time.') . ": " . $e->getMessage(), 'status' => 'danger')); } $redirector->gotoUrl("/admin/services/edit/id/{$id}"); } else { $this->view->form = $form; $this->view->title = $this->translator->translate("Service Details"); $this->view->description = $this->translator->translate("Here you can see the details of the service subscribed by the customer."); return $this->render('applicantform'); } }