public function run() { Eloquent::unguard(); DB::table('services')->truncate(); DB::table('service_options')->truncate(); DB::table('billing_cycles')->truncate(); $faker = Faker\Factory::create(); $service = Service::create(array('name' => 'Simful Travel', 'description' => 'Complete solution for travel agents')); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Economy', 'base_price' => '15', 'description' => 'Designed for small, starter agents.')); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Professional', 'base_price' => '24', 'description' => 'Great for small and mid-size agents.')); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Super', 'base_price' => '45', 'description' => 'For mid-size to large agents.')); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Ultima', 'base_price' => '125', 'description' => 'For the enterprise level.')); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 3, 'discount' => 5)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 6, 'discount' => 10)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 12, 'discount' => 20)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 24, 'discount' => 25)); for ($i = 0; $i < 10; $i++) { $service = Service::create(array('name' => studly_case($faker->domainWord), 'description' => $faker->sentence)); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Economy', 'base_price' => $faker->randomNumber(1, 15), 'description' => $faker->sentence)); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Professional', 'base_price' => $faker->randomNumber(16, 35), 'description' => $faker->sentence)); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Super', 'base_price' => $faker->randomNumber(36, 100), 'description' => $faker->sentence)); ServiceOption::create(array('service_id' => $service->id, 'option_name' => 'Ultima', 'base_price' => $faker->randomNumber(101, 200), 'description' => $faker->sentence)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 3, 'discount' => 5)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 6, 'discount' => 10)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 12, 'discount' => 20)); BillingCycle::create(array('service_id' => $service->id, 'cycle' => 24, 'discount' => 25)); } }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('text', 'quantity', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Quantity'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'setupfee', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup fees'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'discount', array('filters' => array('StringTrim'), 'label' => $translate->_('Discount'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'cost', array('filters' => array('StringTrim'), 'label' => $translate->_('Cost'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('select', 'product_id', array('filters' => array('StringTrim'), 'required' => false, 'label' => $translate->_('Products'), 'class' => 'form-control')); $this->getElement('product_id')->setAllowEmpty(false)->setMultiOptions(Products::getList(true)); $this->addElement('text', 'price', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Price'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('select', 'billing_cycle_id', array('label' => $translate->_('Billing Cycle'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('billing_cycle_id')->setAllowEmpty(false)->setMultiOptions(BillingCycle::getList(true)); $this->addElement('text', 'date_start', array('filters' => array('StringTrim'), 'label' => $translate->_('Start Date'), 'required' => true, 'decorators' => array('Bootstrap'), 'class' => 'form-control date', 'dateformat' => Settings::getJsDateFormat())); $this->addElement('text', 'date_end', array('filters' => array('StringTrim'), 'label' => $translate->_('Expiry Date'), 'decorators' => array('Bootstrap'), 'class' => 'form-control date', 'dateformat' => Settings::getJsDateFormat())); $this->addElement('textarea', 'description', array('filters' => array('StringTrim'), 'label' => $translate->_('Description'), 'decorators' => array('Bootstrap'), 'rows' => 5, 'class' => 'form-control')); $this->addElement('textarea', 'parameters', array('filters' => array('StringTrim'), 'label' => $translate->_('Service Panel Configuration'), 'decorators' => array('Bootstrap'), 'rows' => 5, 'description' => $translate->_('Parameters model accepted: {"domain":{"name":"domain.com","tld":"2","action":"renewDomain","authcode":null}}'), 'class' => 'form-control')); $this->addElement('select', 'status_id', array('label' => $translate->_('Status'), 'required' => true, 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('status_id')->setAllowEmpty(false)->setMultiOptions(Statuses::getList('orders')); $this->addElement('select', 'autorenew', array('decorators' => array('Bootstrap'), 'label' => $translate->_('Auto Renewal'), 'class' => 'form-control', 'multioptions' => array(0 => 'NO', 1 => 'YES'))); $this->addElement('multiselect', 'domains', array('label' => $translate->_('Available Domains'), 'decorators' => array('Bootstrap'), 'class' => 'form-control tmpitems')); $this->getElement('domains')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Domains::getList()); $this->addElement('multiselect', 'domains_selected', array('label' => $translate->_('Selected domains'), 'decorators' => array('Bootstrap'), 'class' => 'form-control items')); $this->getElement('domains_selected')->setRegisterInArrayValidator(false); // Disable the Validator in order to manage a dynamic list. $this->addElement('hidden', 'detail_id'); }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('text', 'date_start', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Creation date'), 'decorators' => array('Bootstrap'), 'class' => 'form-control date', 'dateformat' => Settings::getJsDateFormat())); $this->addElement('text', 'date_end', array('filters' => array('StringTrim'), 'label' => $translate->_('Expiry Date'), 'decorators' => array('Bootstrap'), 'class' => 'form-control date', 'dateformat' => Settings::getJsDateFormat())); $this->addElement('text', 'quantity', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Quantity'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('textarea', 'message', array('filters' => array('StringTrim'), 'label' => $translate->_('Message'), 'decorators' => array('Bootstrap'), 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('textarea', 'note', array('filters' => array('StringTrim'), 'label' => $translate->_('Note'), 'description' => $translate->_('Write here a note. An email will be sent to the ISP staff.'), 'decorators' => array('Bootstrap'), 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('textarea', 'setup', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup Configuration'), 'description' => $translate->_('Here you can read the service configuration written by the ISP modules. These information are read-only.'), 'decorators' => array('Bootstrap'), 'class' => 'col-lg-12')); $this->addElement('select', 'order_id', array('label' => $translate->_('Orders'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('order_id')->setAllowEmpty(false)->setMultiOptions(Orders::getList(true)); $this->addElement('multiselect', 'domains', array('label' => $translate->_('Available domains'), 'decorators' => array('Bootstrap'), 'class' => 'form-control col-lg-12 tmpitems')); $this->getElement('domains')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Domains::getList()); $this->addElement('multiselect', 'domains_selected', array('label' => $translate->_('Selected domains'), 'decorators' => array('Bootstrap'), 'class' => 'form-control col-lg-12 items')); $this->getElement('domains_selected')->setRegisterInArrayValidator(false); // Disable the Validator in order to manage a dynamic list. $this->addElement('select', 'product_id', array('label' => $translate->_('Products'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('product_id')->setAllowEmpty(false)->setMultiOptions(Products::getList(true)); $this->addElement('select', 'billing_cycle_id', array('label' => $translate->_('Billing Cycle'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('billing_cycle_id')->setAllowEmpty(false)->setMultiOptions(BillingCycle::getList(true)); $this->addElement('select', 'status_id', array('label' => $translate->_('Status'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('status_id')->setAllowEmpty(false)->setMultiOptions(Statuses::getList('orders', false, true)); $this->addElement('select', 'autorenew', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'label' => $translate->_('Auto Renewal'), 'description' => $translate->_('Enable or disable the automatic renewal of the service'), 'class' => 'form-control')); $this->getElement('autorenew')->setAllowEmpty(false)->setMultiOptions(array('1' => $translate->_('Yes, I would like to renew the service at the expiration date.'), '0' => $translate->_('No, I am not interested in the service renew.'))); $this->addElement('hidden', 'detail_id'); }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('select', 'billing_id', array('decorators' => array('Bootstrap'), 'class' => 'form-control', 'multiple' => false)); $this->getElement('billing_id')->setIsArray(true)->setAllowEmpty(false)->setMultiOptions(BillingCycle::getList(null, true)); $this->addElement('submit', 'order', array('label' => $translate->_('Create the Order'), 'decorators' => array('Bootstrap'), 'class' => 'btn btn-primary bigbtn')); }
function addToCart() { if (!Input::get('option')) { return Redirect::to('order'); } if (!Input::get('cycle')) { return Redirect::to('order'); } $option = ServiceOption::find(Input::get('option')); $service = Service::find($option->service_id); $cycle = BillingCycle::find(Input::get('cycle')); Cart::insert(array('id' => $option->id, 'name' => $service->name . ' ' . $option->option_name, 'price' => $option->base_price, 'quantity' => $cycle->cycle)); return Redirect::to('order'); }
/** * 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); }
public function postChangeServiceType() { try { // pr(Input::all()); $user_id = Input::get('user_id'); $user = Subscriber::findOrFail($user_id); $disconnect = new stdClass(); $disconnect->set = FALSE; DB::transaction(function () use($user, $disconnect) { $plan_type = Input::get('plan_type'); if ($user->plan_type != $plan_type) { $disconnect->set = TRUE; } $user->plan_type = $plan_type; if (!$user->save()) { throw new Exception('Failed to change service type.'); } if ($user->plan_type == ADVANCEPAID_PLAN) { $billing = BillingCycle::firstOrNew(['user_id' => $user->id]); $input = Input::all(); $input['expiration'] = date("Y-m-d H:i:s", strtotime($input['expiration'])); $billing->fill($input); if (!$billing->save()) { throw new Exception("Failed to save billing cycle details."); } // pr($billing->toArray()); } if ($user->plan_type == FREE_PLAN) { Subscriber::updateFreePlan($user->id); } }); if ($disconnect->set) { Subscriber::destroyAllSessions($user); } $this->notifySuccess("Service Type Updated."); } catch (Exception $e) { $this->notifyError($e->getMessage()); return Redirect::route('subscriber.profile', $user_id); } return Redirect::route('subscriber.profile', $user_id); }
/** * 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'); } }
/** * print the invoice * @param unknown_type $invoiceid */ public static function PrintPDF($invoice_id, $show = true, $force = false, $path = "/documents/invoices/") { $currency = Shineisp_Registry::getInstance()->Zend_Currency; $pdf = new Shineisp_Commons_PdfOrder(); if (!is_numeric($invoice_id)) { return false; } $invoice = Invoices::find($invoice_id); if (!$invoice) { return false; } $invoice = $invoice->toArray(); // Set the basepath for the file $Order = Doctrine::getTable('Orders')->findOneBy('order_id', $invoice['order_id']); $invoicePath = $path . $Order->isp_id . '/' . str_replace('-', '/', $invoice['invoice_id']); // Set the name of the file $filename = $invoicePath . '/' . $invoice['invoice_id'] . ".pdf"; $filenameOld = $path . $invoice['invoice_date'] . " - " . $invoice['number'] . ".pdf"; // Invoice already exists, we return it if ((file_exists(PUBLIC_PATH . $filename) || file_exists(PUBLIC_PATH . $filenameOld)) && $show && !$force) { $outputFilename = !empty($invoice['formatted_number']) ? $invoice['formatted_number'] . ".pdf" : $invoice['invoice_date'] . "_" . $invoice['number'] . ".pdf"; header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="' . $outputFilename . '"'); $invoice = file_exists(PUBLIC_PATH . $filename) ? file_get_contents(PUBLIC_PATH . $filename) : file_get_contents(PUBLIC_PATH . $filenameOld); die($invoice); } $translator = Shineisp_Registry::getInstance()->Zend_Translate; $payments = Payments::findbyorderid($invoice['order_id'], null, true); $order = Orders::getAllInfo($invoice['order_id'], null, true); $database['header']['label'] = $translator->translate('Invoice No.') . " " . (!empty($invoice['formatted_number']) ? $invoice['formatted_number'] : $database['records']['invoice_number']) . " - " . Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']); $database['columns'][] = array("value" => $translator->translate("SKU"), "size" => 20, "align" => "left", "key" => "sku"); $database['columns'][] = array("value" => $translator->translate("Description"), "size" => 65, "align" => "left", "key" => "description"); $database['columns'][] = array("value" => $translator->translate("Qty"), "size" => 2, "align" => "right", "key" => "qty"); $database['columns'][] = array("value" => $translator->translate("Unit"), "size" => 12, "align" => "left", "key" => "unit"); $database['columns'][] = array("value" => $translator->translate("Tax Free Price"), "size" => 9, "align" => "right", "key" => "taxfreeprice"); $database['columns'][] = array("value" => $translator->translate("Discount"), "size" => 10, "align" => "right", "key" => "discount"); $database['columns'][] = array("value" => $translator->translate("Setup fee"), "size" => 15, "align" => "right", "key" => "setup"); $database['columns'][] = array("value" => $translator->translate("Total"), "size" => 18, "align" => "right", "key" => "total"); if (isset($order[0])) { $orderinfo['order_number'] = !empty($order[0]['order_number']) ? $order[0]['order_number'] : Orders::formatOrderId($order[0]['order_id']); $orderinfo['invoice_id'] = $invoice['number']; $orderinfo['date'] = Shineisp_Commons_Utilities::formatDateOut($invoice['invoice_date']); //if customer comes from reseller if ($order[0]['Customers']['parent_id']) { $invoice_dest = Customers::getAllInfo($order[0]['Customers']['parent_id'], 'c.*, a.*'); $orderinfo['customer']['customer_id'] = $invoice_dest['customer_id']; $orderinfo['customer']['company'] = $invoice_dest['company']; $orderinfo['customer']['firstname'] = $invoice_dest['firstname']; $orderinfo['customer']['lastname'] = $invoice_dest['lastname']; $orderinfo['customer']['vat'] = $invoice_dest['vat']; $orderinfo['customer']['taxpayernumber'] = $invoice_dest['taxpayernumber']; $orderinfo['customer']['email'] = $invoice_dest['email']; if (isset($invoice_dest['Addresses'][0])) { $orderinfo['customer']['address'] = $invoice_dest['Addresses'][0]['address']; $orderinfo['customer']['city'] = $invoice_dest['Addresses'][0]['city']; $orderinfo['customer']['code'] = $invoice_dest['Addresses'][0]['code']; $orderinfo['customer']['country'] = !empty($invoice_dest['Addresses'][0]['Countries']['name']) ? $invoice_dest['Addresses'][0]['Countries']['name'] : ""; } } else { $orderinfo['customer']['customer_id'] = $order[0]['Customers']['customer_id']; $orderinfo['customer']['company'] = $order[0]['Customers']['company']; $orderinfo['customer']['firstname'] = $order[0]['Customers']['firstname']; $orderinfo['customer']['lastname'] = $order[0]['Customers']['lastname']; $orderinfo['customer']['vat'] = $order[0]['Customers']['vat']; $orderinfo['customer']['taxpayernumber'] = $order[0]['Customers']['taxpayernumber']; $orderinfo['customer']['email'] = $order[0]['Customers']['email']; if (isset($order[0]['Customers']['Addresses'][0])) { $orderinfo['customer']['address'] = $order[0]['Customers']['Addresses'][0]['address']; $orderinfo['customer']['city'] = $order[0]['Customers']['Addresses'][0]['city']; $orderinfo['customer']['code'] = $order[0]['Customers']['Addresses'][0]['code']; $orderinfo['customer']['country'] = $order[0]['Customers']['Addresses'][0]['Countries']['name']; } } $orderinfo['payments'] = array(); if (count($payments) > 0) { if ($payments > 1) { $numPayment = 1; foreach ($payments as $payment) { if ($numPayment++ > 10) { break; } $payment['paymentdate'] = Shineisp_Commons_Utilities::formatDateOut($payment['paymentdate']); $payment['income'] = $currency->toCurrency($payment['income'], array('currency' => Settings::findbyParam('currency'))); $orderinfo['payments'][] = $payment; } } $orderinfo['payment_date'] = Shineisp_Commons_Utilities::formatDateOut($payments[0]['paymentdate']); $orderinfo['payment_mode'] = $payments[0]['Banks']['name']; $orderinfo['payment_description'] = $payments[0]['description']; $orderinfo['payment_transaction_id'] = $payments[0]['reference']; } $orderinfo['invoice_number'] = $invoice['number']; $orderinfo['company']['name'] = $order[0]['Isp']['company']; $orderinfo['company']['manager'] = $order[0]['Isp']['manager']; $orderinfo['company']['vat'] = $order[0]['Isp']['vatnumber']; $orderinfo['company']['bankname'] = $order[0]['Isp']['bankname']; $orderinfo['company']['iban'] = $order[0]['Isp']['iban']; $orderinfo['company']['bic'] = $order[0]['Isp']['bic']; $orderinfo['company']['address'] = $order[0]['Isp']['address']; $orderinfo['company']['zip'] = $order[0]['Isp']['zip']; $orderinfo['company']['city'] = $order[0]['Isp']['city']; $orderinfo['company']['country'] = $order[0]['Isp']['country']; $orderinfo['company']['telephone'] = $order[0]['Isp']['telephone']; $orderinfo['company']['fax'] = $order[0]['Isp']['fax']; $orderinfo['company']['website'] = $order[0]['Isp']['website']; $orderinfo['company']['email'] = $order[0]['Isp']['email']; $orderinfo['company']['slogan'] = $order[0]['Isp']['slogan']; $orderinfo['company']['custom1'] = $order[0]['Isp']['custom1']; $orderinfo['company']['custom2'] = $order[0]['Isp']['custom2']; $orderinfo['company']['custom3'] = $order[0]['Isp']['custom3']; $orderinfo['subtotal'] = $currency->toCurrency($order[0]['total'], array('currency' => Settings::findbyParam('currency'))); $orderinfo['grandtotal'] = $currency->toCurrency($order[0]['grandtotal'], array('currency' => Settings::findbyParam('currency'))); $orderinfo['vat'] = $currency->toCurrency($order[0]['vat'], array('currency' => Settings::findbyParam('currency'))); $orderinfo['delivery'] = 0; if ($order[0]['status_id'] == Statuses::id("tobepaid", "orders")) { // To be payed $orderinfo['ribbon']['text'] = $translator->translate("To be Paid"); $orderinfo['ribbon']['color'] = "#D60000"; } elseif ($order[0]['status_id'] == Statuses::id("paid", "orders")) { // Paid $orderinfo['ribbon']['text'] = $translator->translate("Paid"); $orderinfo['ribbon']['color'] = "#009926"; } elseif ($order[0]['status_id'] == Statuses::id("complete", "orders")) { // Complete $orderinfo['ribbon']['text'] = $translator->translate("Complete"); $orderinfo['ribbon']['color'] = "#009926"; } else { $orderinfo['ribbon']['text'] = $translator->translate(Statuses::getLabel($order[0]['status_id'])); $orderinfo['ribbon']['color'] = "#FFCC33"; } $database['records'] = $orderinfo; foreach ($order[0]['OrdersItems'] as $item) { $billingCycle = BillingCycle::getAllinfo($item['billing_cycle_id']); if (!empty($billingCycle)) { if (!empty($billingCycle['months']) && empty($item['tld_id'])) { $price = $item['price'] * $billingCycle['months'] + $item['setupfee']; } else { $price = $item['price'] + $item['setupfee']; } } else { $price = $item['price'] * $item['quantity'] + $item['setupfee']; } $rowtotal = $price + $item['vat']; $item['price'] = $currency->toCurrency($item['price'], array('currency' => Settings::findbyParam('currency'))); $item['setupfee'] = $currency->toCurrency($item['setupfee'], array('currency' => Settings::findbyParam('currency'))); $rowtotal = $currency->toCurrency($rowtotal, array('currency' => Settings::findbyParam('currency'))); if (!empty($item['discount'])) { $item['discount'] = $item['discount'] . "%"; } if (!empty($billingCycle['name']) && empty($item['tld_id'])) { $item['date_end'] = Shineisp_Commons_Utilities::formatDateOut($item['date_end']); $billingCycleName = $billingCycle['name']; $item['description'] .= "<br/><br/> - " . $translator->translate('Expiring date') . ": " . $item['date_end']; } else { $billingCycleName = "-"; } // var_dump($item); $database['records']['items'][] = array($item['Products']['sku'], $item['description'], $item['quantity'], $billingCycleName, $item['price'], $item['discount'], $item['setupfee'], $rowtotal); } // var_dump($database['records']); // die; // Sanitize some fields $database['records']['invoice_number'] = !empty($database['records']['invoice_number']) ? $database['records']['invoice_number'] : ""; $database['records']['formatted_number'] = !empty($invoice['formatted_number']) ? $invoice['formatted_number'] : $database['records']['invoice_number']; $database['records']['payment_description'] = !empty($database['records']['payment_description']) ? $database['records']['payment_description'] : ""; $database['records']['payment_mode'] = !empty($database['records']['payment_mode']) ? $database['records']['payment_mode'] : ""; $database['records']['payment_date'] = !empty($database['records']['payment_date']) ? $database['records']['payment_date'] : ""; $database['records']['totalPayments'] = count($database['records']['payments']); // QRCode Image $code['order'] = $database['records']['order_number']; $code['customer'] = $database['records']['customer']['customer_id']; $jcode = base64_encode(json_encode($code)); $database['records']['qrcode_url'] = $_SERVER['HTTP_HOST'] . "/index/qrcode/q/" . $jcode; $database['records']['skip_barcode'] = 1; if (!empty($database['records']['invoice_number'])) { $database['records']['barcode'] = $database['records']['invoice_number']; $database['records']['skip_barcode'] = 0; } if (isset($order[0])) { // Create the path structure if (!is_dir(PUBLIC_PATH . $invoicePath)) { mkdir(PUBLIC_PATH . $invoicePath, 0700, true); } // Template name $templateName = Settings::findByParam('invoice_template'); if (empty($templateName)) { $templateName = Shineisp_Commons_Utilities::getFirstFile(PUBLIC_PATH . '/skins/commons/invoices', '/\\.phtml$/'); } $invoiceview = new Shineisp_Invoice(); $invoiceview->assign('header', $database['header']); $invoiceview->assign('columns', $database['columns']); $invoiceview->assign('data', $database['records']); $html = $invoiceview->render($templateName); $html2pdf = new HTML2PDF('P', 'A4', 'it', true, 'UTF-8', array(4, 4, 4, 1)); $html2pdf->WriteHTML($html); $html2pdf->Output(PUBLIC_PATH . $filename, "F"); // Execute a custom event self::events()->trigger('invoices_pdf_created', "Invoices", array('order' => $order, 'invoice' => $invoice, 'file' => $filename)); return PUBLIC_PATH . $filename; } } return false; }
public function init() { // Set the custom decorator $this->addElementPrefixPath('Shineisp_Decorator', 'Shineisp/Decorator/', 'decorator'); $translate = Shineisp_Registry::get('Zend_Translate'); $this->addElement('text', 'name', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Product name'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'nickname', array('filters' => array('StringTrim'), 'required' => true, 'label' => $translate->_('Product Nickname'), 'description' => $translate->_('This is the short name of the product'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'uri', array('filters' => array('StringTrim'), 'label' => $translate->_('URI'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'sku', array('filters' => array('StringTrim'), 'label' => $translate->_('SKU'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('textarea', 'shortdescription', array('filters' => array('StringTrim'), 'label' => $translate->_('Short Description'), 'id' => 'shortdescription', 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('textarea', 'metakeywords', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'label' => $translate->_('Keywords'), 'rows' => 5, 'class' => 'col-lg-12 form-control')); $this->addElement('textarea', 'metadescription', array('filters' => array('StringTrim'), 'decorators' => array('Bootstrap'), 'label' => $translate->_('Meta Description'), 'rows' => 5, 'class' => 'col-lg-12 form-control')); $this->addElement('textarea', 'description', array('filters' => array('StringTrim'), 'label' => $translate->_('Description'), 'id' => 'description', 'class' => 'col-lg-12 form-control wysiwyg')); $this->addElement('select', 'category_id', array('label' => $translate->_('Category'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('category_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ProductsCategories::getList()); $this->addElement('select', 'welcome_mail_id', array('label' => $translate->_('Welcome E-Mail'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('welcome_mail_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(EmailsTemplates::getList()); $this->addElement('select', 'server_group_id', array('label' => $translate->_('Server group'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('server_group_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ServersGroups::getList(true)); $this->addElement('select', 'autosetup', array('label' => $translate->_('Automatic setup'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('autosetup')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(array('0' => 'Do not automatically setup this product', '1' => 'Automatically setup the product as soon as an order is placed', '2' => 'Automatically setup the product as soon as the first payment is received', '3' => 'Automatically setup the product when you manually accept a pending order', '4' => 'Automatically setup the product as soon as the payment is complete')); $this->addElement('multiselect', 'related', array('label' => $translate->_('Related Products'), 'decorators' => array('Bootstrap'), 'size' => '20x', 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->addElement('multiselect', 'upgrade', array('label' => $translate->_('Product Upgrades'), 'decorators' => array('Bootstrap'), 'size' => '20x', 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('related')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Products::getList()); $this->getElement('upgrade')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Products::getList()); $this->addElement('select', 'tax_id', array('label' => 'Tax', 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('tax_id')->setAllowEmpty(false)->setMultiOptions(Taxes::getList(true)); $this->addElement('text', 'cost', array('filters' => array('StringTrim'), 'label' => $translate->_('Cost'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'price_1', array('filters' => array('StringTrim'), 'label' => $translate->_('Price'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'setupfee', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup Fee'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('textarea', 'setup', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup'), 'decorators' => array('Bootstrap'), 'description' => $translate->_('XML Setup Configuration. See the manual'), 'class' => 'col-lg-12 form-control')); $this->addElement('select', 'enabled', array('label' => $translate->_('Enabled'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'Disabled', '1' => 'Active'))); $this->addElement('select', 'ishighlighted', array('label' => $translate->_('Is Highlighted'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'isrefundable', array('label' => $translate->_('Is Refundable'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'default', array('label' => $translate->_('Default Image'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'iscomparable', array('label' => $translate->_('Is Comparable'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'showonrss', array('label' => $translate->_('Publish on RSS Feed'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'downgradable', array('label' => $translate->_('Allow downgrades'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('0' => 'No', '1' => 'Yes'))); $this->addElement('select', 'type', array('label' => $translate->_('Product Type'), 'decorators' => array('Bootstrap'), 'class' => 'form-control', 'multioptions' => array('generic' => $translate->_('Generic'), 'domain' => $translate->_('Domain'), 'hosting' => $translate->_('Hosting')))); // If the browser client is an Apple client hide the file upload html object if (false == Shineisp_Commons_Utilities::isAppleClient()) { $this->addElement('text', 'filedescription', array('filters' => array('StringTrim'), 'label' => $translate->_('Description'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $MBlimit = Settings::findbyParam('adminuploadlimit'); $Byteslimit = Shineisp_Commons_Utilities::MB2Bytes($MBlimit); $filetypes = Settings::findbyParam('adminuploadfiletypes', 'Admin'); $file = $this->createElement('file', 'attachments', array('label' => $translate->_('Attachment'), 'decorators' => array('File', array('ViewScript', array('viewScript' => 'partials/file.phtml', 'placement' => false))), 'description' => $translate->_('Select the document to upload. Files allowed are (%s) - Max %s', $filetypes, Shineisp_Commons_Utilities::formatSizeUnits($Byteslimit)), 'data-classButton' => 'btn btn-primary', 'data-input' => 'false', 'class' => 'filestyle')); $file->addValidator('Extension', false, $filetypes)->addValidator('Size', false, $Byteslimit)->addValidator('Count', false, 1); $this->addElement($file); } $this->addElement('multiselect', 'wikipages', array('label' => $translate->_('Wiki Pages'), 'decorators' => array('Bootstrap'), 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('wikipages')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(Wiki::getList()); $this->addElement('select', 'tranche_billing_cycle_id', array('label' => $translate->_('Billing Cycle'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->getElement('tranche_billing_cycle_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(BillingCycle::getList()); $this->addElement('text', 'tranche_qty', array('filters' => array('StringTrim'), 'label' => $translate->_('Quantity'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_measure', array('filters' => array('StringTrim'), 'label' => $translate->_('Measurement label'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_setupfee', array('filters' => array('StringTrim'), 'label' => $translate->_('Setup fee'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('text', 'tranche_price', array('filters' => array('StringTrim'), 'label' => $translate->_('Unit Price'), 'decorators' => array('Bootstrap'), 'class' => 'form-control')); $this->addElement('multiselect', 'tranche_includes_domains', array('isArray' => true, 'label' => $translate->_('Domain included'), 'decorators' => array('Bootstrap'), 'title' => $translate->_('Select ...'), 'data-container' => 'body', 'data-selected-text-format' => 'count > 2', 'data-size' => 'auto', 'data-live-search' => 'true', 'class' => 'multiselect show-tick col-md-4')); $this->getElement('tranche_includes_domains')->setAllowEmpty(true)->setRegisterInArrayValidator(false)->setMultiOptions(DomainsTlds::getList()); $this->addElement('select', 'group_id', array('decorators' => array('Bootstrap'), 'label' => $translate->_('Attribute Group'), 'required' => true, 'class' => 'form-control')); $this->getElement('group_id')->setAllowEmpty(false)->setRegisterInArrayValidator(false)->setMultiOptions(ProductsAttributesGroups::getList()); $this->addElement('text', 'position', array('decorators' => array('Bootstrap'), 'label' => $translate->_('Position'), 'class' => 'form-control')); $this->addElement('textarea', 'blocks', array('filters' => array('StringTrim'), 'label' => $translate->_('Blocks'), 'decorators' => array('Bootstrap'), 'class' => 'col-lg-12 form-control')); $this->addElement('hidden', 'product_id'); }
/** * 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; }