/** * 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'); } }
/** * 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; }
/** * processAction * Update the record previously selected * @return unknown_type */ public function processAction() { $request = $this->getRequest(); // Check if we have a POST request if (!$request->isPost()) { return $this->_helper->redirector('index'); } // Get our form and validate it $form = $this->getForm('/admin/service/process'); if (!$form->isValid($request->getPost())) { // Invalid entries $this->view->form = $form; $this->view->title = $this->translator->translate("Service"); $this->view->description = $this->translator->translate("Check all the fields and click on the save button"); return $this->_helper->viewRenderer('customform'); // re-render the login form } // Get the values posted $params = $form->getValues(); // Get the id $id = $this->getRequest()->getParam('detail_id'); if (is_numeric($id)) { OrdersItems::setAutorenew($id, $params['autorenew']); } // Save the message note if (!empty($params['message'])) { Messages::addMessage($params['message'], $this->customer['customer_id'], null, null, $id); $isp = Shineisp_Registry::get('ISP'); $placeholder['fullname'] = $this->customer['firstname'] . " " . $this->customer['lastname']; $placeholder['messagetype'] = $this->translator->translate('Order Details'); $placeholder['message'] = $params['message']; Messages::sendMessage("message_new", $this->customer['email'], $placeholder); Messages::sendMessage("message_admin", $isp->email, $placeholder); } $this->_helper->redirector('edit', 'services', 'default', array('id' => $id, 'mex' => 'The task requested has been executed successfully.', 'status' => 'success')); }