Example #1
0
 public function ProductImage($productid, $maxWidth = 100, $maxHeight = 100, $showall = false)
 {
     $NS = new Zend_Session_Namespace('Default');
     $this->view->width = $maxWidth;
     $this->view->height = $maxHeight;
     $this->view->showall = $showall;
     $this->view->resources = ProductsMedia::getMediabyProductId($productid, "*", $NS->langid);
     $this->view->productdata = Products::getAllInfo($productid, $NS->langid);
     return $this->view->render('partials/media.phtml');
 }
Example #2
0
 public function get($productid)
 {
     $this->authenticate();
     if (empty($productid)) {
         throw new Shineisp_Api_Exceptions(400002, ":: 'productid' field");
         exit;
     }
     $product = new Products();
     $details = $product->getAllInfo($productid);
     $details['ProductsUpgrades'] = ProductsUpgrades::getItemsbyProductID($productid);
     return $details;
 }
Example #3
0
 public static function getRefundInfo($orderid)
 {
     $service = self::getDetail($orderid);
     $product = $service['Products'];
     $productid = $product['product_id'];
     $productInfo = Products::getAllInfo($productid);
     $isrefundable = intval($productInfo['isrefundable']);
     $priceRefund = 0;
     if ($isrefundable > 0) {
         $pricePaid = $service['price'];
         $date = explode(' ', $service['date_start']);
         $date = array_shift($date);
         list($yyyy, $mm, $dd) = explode('-', $date);
         $tsStartService = mktime(0, 0, 0, $mm, $dd, $yyyy);
         $date = explode(' ', $service['date_end']);
         $date = array_shift($date);
         list($yyyy, $mm, $dd) = explode('-', $date);
         $tsEndService = mktime(0, 0, 0, $mm, $dd, $yyyy);
         $tsToday = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
         $dayService = round(($tsEndService - $tsStartService) / (60 * 60 * 24));
         $priceServiceForDay = $pricePaid / $dayService;
         $tsRemain = 0;
         $priceRefund = false;
         if ($tsEndService > $tsToday) {
             $dayRemain = round(($tsEndService - $tsToday) / (60 * 60 * 24));
             $priceRefund = round($priceServiceForDay * $dayRemain, 2);
         }
     }
     $result = array('productid' => $productid, 'refund' => $priceRefund);
     return $result;
 }
Example #4
0
 /**
  * saveAll
  * Save all the data in the database
  * @param array $params
  * @param integer $id
  */
 public static function saveAll($params, $id = "")
 {
     $orders = new Orders();
     $translator = Shineisp_Registry::getInstance()->Zend_Translate;
     $currentStatus = "";
     try {
         // Set the new values
         if (is_numeric($id)) {
             $orders = Doctrine::getTable('Orders')->find($id);
             $currentStatus = $orders->status_id;
             // used to detect status changes
         }
         if (!empty($params) && is_array($params)) {
             $params['date_start'] = !empty($params['date_start']) ? $params['date_start'] : new Zend_Date();
             $params['order_date'] = !empty($params['order_date']) ? $params['order_date'] : new Zend_Date();
             $customer = Customers::getAllInfo($params['customer_id']);
             $isp_id = $customer['isp_id'];
             $orders->order_date = Shineisp_Commons_Utilities::formatDateIn($params['order_date']);
             $orders->customer_id = $params['customer_id'];
             $orders->isp_id = $isp_id;
             $orders->status_id = $params['status_id'];
             $orders->invoice_id = !empty($params['invoice_id']) ? $params['invoice_id'] : null;
             $orders->note = $params['note'];
             $orders->is_renewal = $params['is_renewal'] == 1 ? 1 : 0;
             $orders->expiring_date = Shineisp_Commons_Utilities::formatDateIn($params['expiring_date']);
             $orders->vat = $params['vat'];
             $orders->total = $params['total'];
             $orders->grandtotal = $params['total'] + $params['vat'];
             // Save the data
             $orders->save();
             $id = is_numeric($id) ? $id : $orders->getIncremented();
             // Status changed? Let's call set_status. This is needed to properly log all status change.
             if (isset($params['status_id']) && $params['status_id'] != $currentStatus) {
                 self::logStatusChange($id, $params['status_id']);
             }
             // Add a fastlink to a order
             $link_exist = Fastlinks::findlinks($id, 'orders');
             $link = new Fastlinks();
             if (count($link_exist) == 0) {
                 $link->controller = "orders";
                 $link->action = "edit";
                 $link->params = json_encode(array('id' => $id));
                 $link->customer_id = $params['customer_id'];
                 $link->sqltable = "orders";
                 $link->id = $id;
                 $link->code = Shineisp_Commons_Utilities::GenerateRandomString();
             } else {
                 $link = Doctrine::getTable('Fastlinks')->find($link_exist[0]['fastlink_id']);
                 $link->code = $params['fastlink'];
             }
             $link->save();
             // Save the message note and send an alert
             if (!empty($params['message'])) {
                 $order = self::getAllInfo($id, null, true);
                 $link = Fastlinks::findlinks($id, $params['customer_id'], 'orders');
                 $isp = Isp::find($isp_id);
                 $retval = Shineisp_Commons_Utilities::getEmailTemplate('order_message');
                 if ($retval) {
                     $in_reply_to = md5($id);
                     // Save the message written by the ISP owner
                     Messages::addMessage($params['message'], null, null, $id, null, $isp_id);
                     // Create the array with all the placeholders
                     $placeholders['fullname'] = $order[0]['Customers']['firstname'] . " " . $order[0]['Customers']['lastname'];
                     $placeholders['url'] = "http://" . $_SERVER['HTTP_HOST'] . "/index/link/id/" . $link[0]['code'];
                     $placeholders['orderid'] = sprintf("%03s", $id) . " - " . Shineisp_Commons_Utilities::formatDateOut($order[0]['order_date']);
                     $placeholders['messagetype'] = $translator->translate('Order Details');
                     $placeholders['message'] = $params['message'];
                     Shineisp_Commons_Utilities::sendEmailTemplate(Contacts::getEmails($order[0]['Customers']['customer_id']), 'order_message', $placeholders, $in_reply_to, null, null, null, $order[0]['Customers']['language_id']);
                     // Change the URL for the administrator
                     $placeholders['url'] = "http://" . $_SERVER['HTTP_HOST'] . "/admin/login/link/id/" . $link[0]['code'] . "/keypass/" . Shineisp_Commons_Hasher::hash_string($isp->email);
                     // Send a message to the administrator
                     Shineisp_Commons_Utilities::sendEmailTemplate($isp->email, 'order_message_admin', $placeholders, $in_reply_to);
                 }
             }
             // Saving the domain
             if (!empty($params['domains_selected'])) {
                 self::SaveDomainsDetails($params, $id);
             } else {
                 if (!empty($params['products'])) {
                     $date_end = null;
                     // Get the product information
                     $product = Products::getAllInfo($params['products']);
                     // Manage the details of the order
                     if (!empty($params['billingcycle_id'])) {
                         $months = BillingCycle::getMonthsNumber($params['billingcycle_id']);
                         // Add months to the starting date
                         if ($months > 0) {
                             $params['date_end'] = Shineisp_Commons_Utilities::add_date($params['date_start'], null, $months);
                         }
                     }
                     // Format the dates before to save them in the database
                     $params['date_end'] = Shineisp_Commons_Utilities::formatDateIn($params['date_end']);
                     $params['date_start'] = Shineisp_Commons_Utilities::formatDateIn($params['date_start']);
                     if (!empty($product['Taxes']['tax_id'])) {
                         $vat = $params['price'] * $product['Taxes']['percentage'] / 100;
                         $subtotal = $params['price'] * ($product['Taxes']['percentage'] + 100) / 100;
                         $percentage = $product['Taxes']['percentage'];
                     } else {
                         $vat = 0;
                         $subtotal = $params['price'];
                         $percentage = 0;
                     }
                     $details = new OrdersItems();
                     $details->order_id = $id;
                     $details->quantity = $params['quantity'];
                     $details->cost = Products::getCost($params['products']);
                     $details->price = $params['price'];
                     $details->date_start = $params['date_start'];
                     $details->date_end = $params['date_end'];
                     $details->billing_cycle_id = !empty($params['billingcycle_id']) ? $params['billingcycle_id'] : null;
                     $details->product_id = $params['products'];
                     $details->description = $params['description'];
                     $details->status_id = $params['status_id'];
                     $details->vat = $vat;
                     $details->percentage = $percentage;
                     $details->subtotal = $subtotal;
                     if ($product['type'] == "hosting") {
                         // Get all the product attributes
                         $attrs = ProductsAttributes::getAttributebyProductID($params['products']);
                         // Create the system attributes parameters
                         foreach ($attrs as $attr) {
                             if ($attr['system'] && !empty($attr['ProductsAttributesIndexes'][0]['value'])) {
                                 $hostingplan[$attr['code']] = $attr['ProductsAttributesIndexes'][0]['value'];
                             }
                         }
                         $details->parameters = json_encode($hostingplan);
                     }
                     $details->save();
                     $detail_id = $details->getIncremented();
                     // Attaching of the service a particular domain. It's not a mandatory field because the services and the products can be bought also without a domain
                     if (is_numeric($params['referdomain']) && $params['referdomain'] > 0) {
                         $ordersitemsdomains = new OrdersItemsDomains();
                         $ordersitemsdomains->domain_id = $params['referdomain'];
                         $ordersitemsdomains->order_id = $id;
                         $ordersitemsdomains->orderitem_id = $detail_id;
                         $ordersitemsdomains->save();
                     }
                 }
             }
             // Handle the payment transaction
             if (!empty($params['paymentdate'])) {
                 Payments::addPayment($id, $params['reference'], $params['bank_id'], $params['confirmed'], $params['income'], $params['paymentdate'], $params['customer_id'], $params['payment_description']);
             }
             // Set the status of the order
             OrdersItems::setNewStatus($id, $params['status_id']);
             // Update the totals of the order selected
             self::updateTotalsOrder($id);
             return $id;
         }
     } catch (Exception $e) {
         die($e->getMessage());
     }
     return false;
 }
Example #5
0
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::find($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     $isVATFree = Customers::isVATFree($id);
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], array());
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
     $banks = Banks::find($params['payment'], "*", true);
     if (!empty($banks[0]['classname'])) {
         $class = $banks[0]['classname'];
         if (class_exists($class)) {
             // Get the payment form object
             $banks = Banks::findbyClassname($class);
             $gateway = new $class($orderID);
             $gateway->setFormHidden(true);
             $gateway->setRedirect(true);
             $gateway->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($banks['classname']));
             $gateway->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($banks['classname']));
             return $gateway->CreateForm();
         }
     }
     throw new Shineisp_Api_Exceptions(400006, ":: bad request");
     exit;
 }
Example #6
0
 /**
  * Check the product and redirect the user to the right destination
  */
 public function addAction()
 {
     try {
         $isVATFree = false;
         $session = new Zend_Session_Namespace('Default');
         if (empty($session->cart)) {
             $session->cart = new Cart();
         }
         // Get the sent parameters
         $request = $this->getRequest()->getParams();
         if (!empty($request['product_id']) && is_numeric($request['product_id'])) {
             // Check the quantity value posted
             if (!empty($request['quantity']) && is_numeric($request['quantity'])) {
                 // Get all the info about the product selected
                 $product = Products::getAllInfo($request['product_id']);
                 // Check if the user has been logged in
                 if (!empty($this->customer['customer_id'])) {
                     // Set the customer for the active cart
                     $session->cart->setCustomer($this->customer['customer_id']);
                     // Check if the user is VAT free
                     $isVATFree = Customers::isVATFree($session->cart->getCustomerId());
                 }
                 $priceInfo = Products::getPriceSelected($request['product_id'], $request['term'], $isVATFree);
                 $item = new CartItem();
                 if ($session->cart->getItem($request['product_id'])) {
                     $item = $session->cart->getItem($request['product_id']);
                     $session->cart->updateItem($item, $item->getQty() + 1);
                 } else {
                     // Add the items to the cart:
                     $item->setId($request['product_id'])->setSku($product['sku'])->setName($product['ProductsData'][0]['name'])->setCost($product['cost'])->setTerm($request['term'])->setQty($request['quantity'])->setUnitprice($priceInfo['unitprice'])->setTaxId($product['tax_id'])->setSetupfee($priceInfo['setupfee'])->setType(Products::getProductType($request['product_id']));
                     $session->cart->addItem($item);
                 }
                 // Check if a hosting product is present in the cart
                 if ($session->cart->getCustomer()) {
                     $this->_helper->redirector('summary', 'cart', 'default');
                 } else {
                     $this->_helper->redirector('contacts');
                 }
             }
             // Quantity is not correct and the user is redirected to the homepage
             $this->_helper->redirector('index', 'index', 'default');
         }
     } catch (Exception $e) {
         $this->_helper->redirector('index', 'index', 'default', array('mex' => $e->getMessage()));
     }
 }
Example #7
0
 /**
  * export the content in a excel file
  * @param array $items
  */
 public function bulk_xml($items = array())
 {
     // Get the records from the customer table
     $data = self::get_customers($items);
     $xml = new ExSimpleXMLElement('<shineisp></shineisp>');
     $customers = $xml->addChild('customers');
     foreach ($data as $item) {
         $customer = $customers->addChild('customer');
         $customer->addAttribute('id', $item['customer_id']);
         $customer->addChildCData('company', $item['company']);
         $customer->addChild('firstname', $item['firstname']);
         $customer->addChild('lastname', $item['lastname']);
         $customer->addChild('gender', $item['gender']);
         $customer->addChild('email', $item['email']);
         $customer->addChild('password', $item['password']);
         $customer->addChild('birthdate', $item['birthdate']);
         $customer->addChild('birthplace', $item['birthplace']);
         $customer->addChild('birthdistrict', $item['birthdistrict']);
         $customer->addChild('birthcountry', $item['birthcountry']);
         $customer->addChild('birthnationality', $item['birthnationality']);
         $customer->addChild('taxpayernumber', $item['taxpayernumber']);
         $customer->addChild('vat', $item['vat']);
         $customer->addChild('birthnationality', $item['birthnationality']);
         $ctype = $customer->addChild('companytype', $item['CompanyTypes']['name']);
         $ctype->addAttribute('type_id', $item['type_id']);
         $legalform = $customer->addChild('companytype', $item['Legalforms']['name']);
         $legalform->addAttribute('legalform_id', $item['legalform_id']);
         $status = $customer->addChild('companytype', $item['Statuses']['status']);
         $status->addAttribute('status_id', $item['status_id']);
         $cgroup = $customer->addChild('companytype', $item['CustomersGroups']['name']);
         $cgroup->addAttribute('group_id', $item['group_id']);
         $customer->addChildCData('note', $item['note']);
         $language = $customer->addChild('language', $item['Languages']['language']);
         $language->addAttribute('language_id', $item['language_id']);
         $customer->addChild('issubscriber', $item['issubscriber']);
         $customer->addChild('created_at', $item['created_at']);
         $customer->addChild('updated_at', $item['updated_at']);
         $customer->addChild('taxfree', $item['taxfree']);
         $addresses = $customer->addChild('addresses');
         foreach ($item['Addresses'] as $addr) {
             $address = $addresses->addChild('address');
             $address->addAttribute('address_id', $addr['address_id']);
             $address->addChild('address', $addr['address']);
             $address->addChild('city', $addr['city']);
             $address->addChild('postcode', $addr['code']);
             $address->addChild('countrycode', $addr['Countries']['code']);
             $country = $address->addChild('country', $addr['Countries']['name']);
             $country->addAttribute('country_id', $addr['country_id']);
             $address->addChild('area', $addr['area']);
             $address->addChild('latitude', $addr['latitude']);
             $address->addChild('longitude', $addr['longitude']);
         }
         $contacts = $customer->addChild('contacts');
         foreach ($item['Contacts'] as $cnt) {
             $contact = $contacts->addChild('contact');
             $contact->addAttribute('contact_id', $cnt['contact_id']);
             $mycnt = $contact->addChild('contact', $cnt['contact']);
             $mycnt->addAttribute('type_id', $cnt['type_id']);
             $mycnt->addAttribute('label', $cnt['ContactsTypes']['name']);
         }
         $orders = $customer->addChild('orders');
         foreach ($item['Orders'] as $odr) {
             $order = $orders->addChild('order');
             $order->addAttribute('order_id', $odr['order_id']);
             $order->addChild('order_date', $odr['order_date']);
             $order->addChild('total', $odr['total']);
             $order->addChild('cost', $odr['cost']);
             $order->addChild('vat', $odr['vat']);
             $order->addChild('grandtotal', $odr['grandtotal']);
             $details = $order->addChild('details');
             foreach ($odr['OrdersItems'] as $dtl) {
                 $detail = $details->addChild('detail');
                 $detail->addAttribute('detail_id', $dtl['detail_id']);
                 $detail->addAttribute('status_id', $dtl['status_id']);
                 $arrProduct = Products::getAllInfo($dtl['product_id']);
                 if (!empty($arrProduct)) {
                     $product = $detail->addChild('product');
                     $product->addAttribute('product_id', $dtl['product_id']);
                     $product->addAttribute('sku', $arrProduct['sku']);
                     if (!empty($arrProduct['ProductsData'])) {
                         $product->addChildCData('name', $arrProduct['ProductsData'][0]['name']);
                     }
                 }
                 $detail->addChild('date_start', $dtl['date_start']);
                 $detail->addChild('date_end', $dtl['date_end']);
                 $detail->addChild('quantity', $dtl['quantity']);
                 $detail->addChildCData('description', $dtl['description']);
                 $detail->addChild('cost', $dtl['cost']);
                 $detail->addChild('price', $dtl['price']);
                 $detail->addChild('setupfee', $dtl['setupfee']);
                 $detail->addChild('status_id', $dtl['status_id']);
             }
         }
     }
     $xml->saveXML(PUBLIC_PATH . "/tmp/customers.xml");
     if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
         die(json_encode(array('url' => "/tmp/customers.xml")));
     }
 }
Example #8
0
 /**
  * Get product info
  * @return Json
  */
 public function getproductinfoAction()
 {
     $ns = new Zend_Session_Namespace('Admin');
     $id = $this->getRequest()->getParam('id');
     $product = Products::getAllInfo($id, $ns->langid);
     die(json_encode($product));
 }
Example #9
0
 /**
  * Calculate the subtotal for each product in the cart
  *
  * @param integer $id        	
  * @param integer $qty        	
  * @param boolean $isvatfree        	
  * @return ArrayObject
  */
 private function calcSubtotal(CartItem $item, $isvatfree = false)
 {
     foreach ($this->items as $item) {
         $isrecurring = false;
         $months = 0;
         $percentage = 0;
         $tax = 0;
         if ("domain" == $item->getType()) {
             $item->setIsrecurring(true);
             // Get the billyng cycle / term / recurring period price
             if ($item->getTerm()) {
                 $priceInfo = ProductsTranches::getTranchebyId($item->getTerm());
                 $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']);
                 $months = $priceInfo['BillingCycle']['months'];
             } else {
                 $priceInfo = BillingCycle::getDefaultDomainBillingCycle();
                 $item->setBillingid($priceInfo['billing_cycle_id']);
                 $months = $priceInfo['months'];
             }
             $unitprice = $item->getUnitPrice();
             $setupfee = 0;
             // Calculate the price per Quantity
             $subtotal = $unitprice * $item->getQty();
             // check the taxes
             if (Taxes::get_percentage($item->getTaxId())) {
                 $percentage = Taxes::get_percentage($item->getTaxId());
                 $tax = $subtotal * $percentage / 100;
                 $price = $subtotal * (100 + $percentage) / 100;
             }
         } else {
             // Get all the product information
             $product = Products::getAllInfo($item->getId());
             // Check the type of the product and get the price information
             if ($product['ProductsAttributesGroups']['isrecurring']) {
                 $item->setIsrecurring(true);
                 // Get the billyng cycle / term / recurring period price
                 $priceInfo = ProductsTranches::getTranchebyId($item->getTerm());
                 // Price multiplier
                 $months = $priceInfo['BillingCycle']['months'];
                 $unitprice = $priceInfo['price'];
                 $setupfee = $priceInfo['setupfee'];
                 // Calculate the price per the months per Quantity
                 $subtotal = $unitprice * $months * $item->getQty();
                 $item->setBillingid($priceInfo['BillingCycle']['billing_cycle_id']);
             } else {
                 $item->setIsrecurring(false);
                 $unitprice = $product['price_1'];
                 $setupfee = $product['setupfee'];
                 // Calculate the price per Quantity
                 $subtotal = $unitprice * $item->getQty();
             }
             // check the taxes for each product
             if (!empty($product['tax_id']) && !$isvatfree) {
                 if (!empty($product['Taxes']['percentage']) && is_numeric($product['Taxes']['percentage'])) {
                     $percentage = $product['Taxes']['percentage'];
                     $tax = $subtotal * $percentage / 100;
                     $price = $subtotal * (100 + $percentage) / 100;
                 }
             }
         }
         // ... and add the setup fees
         $price = $subtotal + $setupfee;
         $item->setSubtotals(array('months' => $months, 'subtotal' => $subtotal, 'setupfee' => $setupfee, 'price' => $price, 'taxes' => $tax, 'percentage' => $percentage));
     }
     return $this->items;
 }
Example #10
0
 public function create($params)
 {
     $this->authenticate();
     $uuid = $params['uuid'];
     $customers = Customers::findWithUuid($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $trancheid = intval($params['trancheid']);
     $tranche = ProductsTranches::getTranchebyId($trancheid);
     if (empty($tranche)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'trancheid' not valid");
         exit;
     }
     #Check Products
     if (empty($params['products']) && !is_array($params['products'])) {
         throw new Shineisp_Api_Exceptions(400006, ":: not 'products' choose");
         exit;
     }
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $ttry = ProductsTranches::getTranchesBy_ProductId_BillingId($productid, $billingid);
         if (empty($ttry)) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'productid' or 'bilingid' not valid");
             exit;
         }
         $ttry = array_shift($ttry);
         if ($ttry['tranche_id'] != $trancheid) {
             throw new Shineisp_Api_Exceptions(400006, ":: 'bilingid' not valid");
             exit;
         }
     }
     $id = $customers['customer_id'];
     if ($params['status'] == "complete") {
         $status = Statuses::id('complete', 'orders');
     } else {
         $status = Statuses::id('tobepaid', 'orders');
     }
     $theOrder = Orders::create($customers['customer_id'], $status, $params['note']);
     foreach ($params['products'] as $product) {
         $productid = intval($product['productid']);
         $billingid = intval($product['billingid']);
         $quantity = intval($product['quantity']);
         $p = Products::getAllInfo($productid);
         $options = array('uuid' => $product['uuid']);
         $upgrade = false;
         if (array_key_exists('upgrade', $product) && $product['upgrade'] != false) {
             $orderItemsUpgrade = OrdersItems::findByUUID($product['upgrade']);
             $fromUpgrade = $orderItemsUpgrade->toArray();
             $upgrade = $fromUpgrade['detail_id'];
         }
         $ts_start = false;
         if (array_key_exists('ts_start', $product) && $product['ts_start'] != false) {
             $ts_start = $product['ts_start'];
         }
         Orders::addItem($productid, $quantity, $billingid, $trancheid, $p['ProductsData'][0]['name'], $options, $upgrade, $ts_start);
     }
     $orderID = $theOrder['order_id'];
     if ($params['sendemail'] == 1) {
         Orders::sendOrder($orderID);
     }
 }