Beispiel #1
0
 /**
  * Get the price of a specific product
  * 
  * @param integer $id
  * @param integer $trancheId
  * @param boolean $isvatfree
  * @return ArrayObject
  */
 public static function getPriceSelected($id, $trancheId = null, $isvatfree = false)
 {
     $product = self::getAllInfo($id, $isvatfree);
     // Check the type of the product and get the price information
     if ($trancheId) {
         // Get the billyng cycle / term / recurring period price
         $priceInfo = ProductsTranches::getTranchebyId($trancheId);
         $price['unitprice'] = $priceInfo['price'];
         $price['setupfee'] = $priceInfo['setupfee'];
     } else {
         $price['unitprice'] = $product['price_1'];
         $price['setupfee'] = $product['setupfee'];
     }
     return $price;
 }
Beispiel #2
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;
 }
Beispiel #3
0
 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));
 }
Beispiel #4
0
 /**
  * setdefaultrance
  * Set the default trance price 
  * @return void
  */
 public function setdefaultranceAction()
 {
     $id = $this->getRequest()->getParam('id');
     if (is_numeric($id)) {
         $trance = ProductsTranches::getTranchebyId($id);
         ProductsTranches::setDefault($id);
         $this->_helper->redirector('edit', 'products', 'admin', array('id' => $trance['product_id'], 'mex' => 'The task requested has been executed successfully.', 'status' => 'success'));
     }
     $this->_helper->redirector('list', 'products', 'admin', array('mex' => 'An error occured during the operation.', 'status' => 'danger'));
 }
Beispiel #5
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;
 }
Beispiel #6
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);
     }
 }