Example #1
0
 /**
  * editAction
  * Get a record and populate the application form 
  * @return unknown_type
  */
 public function editAction()
 {
     $form = $this->getForm('/orders/process');
     $id = $this->getRequest()->getParam('id');
     $NS = new Zend_Session_Namespace('Default');
     $currency = Shineisp_Registry::getInstance()->Zend_Currency;
     try {
         if (!empty($id) && is_numeric($id)) {
             $fields = "o.order_id, \n\t\t\t\t\t\t\to.order_number as order_number,\n\t\t\t\t\t\t\tDATE_FORMAT(o.order_date, '%d/%m/%Y') as Starting, \n\t\t\t\t\t\t\tDATE_FORMAT(o.expiring_date, '%d/%m/%Y') as Valid_Up, \n\t\t\t\t\t\t\tin.invoice_id as invoice_id, \n\t\t\t\t\t\t\tin.formatted_number as invoice_number, \n\t\t\t\t\t\t\tCONCAT(d.domain, '.', w.tld) as Domain, \n\t\t\t\t\t\t\tc.company as company, \n\t\t\t\t\t\t\to.status_id, \n\t\t\t\t\t\t\ts.status as Status, \n\t\t\t\t\t\t\to.vat as VAT, \n\t\t\t\t\t\t\to.total as Total, \n\t\t\t\t\t\t\to.grandtotal as Grandtotal";
             $rs = Orders::getAllInfo($id, $fields, true, $NS->customer['customer_id']);
             if (!empty($rs)) {
                 // Check the status of the order.
                 // If the order has to be paid we have update it to the last prices and taxes
                 if ($rs[0]['status_id'] == Statuses::id('tobepaid', 'orders')) {
                     // Update the total order
                     Orders::updateTotalsOrder($id);
                     // Reload the data
                     $rs = Orders::getAllInfo($id, $fields, true, $NS->customer['customer_id']);
                     $rs[0]['Total'] = $currency->toCurrency($rs[0]['Total'], array('currency' => Settings::findbyParam('currency')));
                     $rs[0]['VAT'] = $currency->toCurrency($rs[0]['VAT'], array('currency' => Settings::findbyParam('currency')));
                     $rs[0]['Grandtotal'] = $currency->toCurrency($rs[0]['Grandtotal'], array('currency' => Settings::findbyParam('currency')));
                     $this->view->tobepaid = true;
                     // To be Paid status
                 }
                 $records = OrdersItems::getAllDetails($id, "oi.detail_id, \n                                        \t\t\t\t\t        oi.description as description, \n                                        \t\t\t\t\t        DATE_FORMAT(oi.date_end, '%d/%m/%Y') as expiration_date, \n                                        \t\t\t\t\t        oi.quantity as quantity, \n                                        \t\t\t\t\t        oi.price as price, \n                                        \t\t\t\t\t        CONCAT(oi.discount, '%') as discount, \n                                        \t\t\t\t\t        oi.subtotal as subtotal, \n                                        \t\t\t\t\t        bc.name as billingcycle, \n                                        \t\t\t\t\t        oi.setupfee as setupfee", true);
                 for ($i = 0; $i < count($records); $i++) {
                     $records[$i]['price'] = $currency->toCurrency($records[$i]['price'], array('currency' => Settings::findbyParam('currency')));
                     $records[$i]['subtotal'] = $currency->toCurrency($records[$i]['subtotal'], array('currency' => Settings::findbyParam('currency')));
                     $records[$i]['setupfee'] = $currency->toCurrency($records[$i]['setupfee'], array('currency' => Settings::findbyParam('currency')));
                 }
                 $columns = array();
                 $columns[] = $this->translator->translate('Description');
                 $columns[] = $this->translator->translate('Expiry Date');
                 $columns[] = $this->translator->translate('Qty');
                 $columns[] = $this->translator->translate('Price');
                 $columns[] = $this->translator->translate('Discount');
                 $columns[] = $this->translator->translate('Subtotal');
                 $columns[] = $this->translator->translate('Billing Cycle');
                 $columns[] = $this->translator->translate('Setup Fee');
                 $this->view->customer_id = $NS->customer['customer_id'];
                 $this->view->invoiced = $rs[0]['status_id'] == Statuses::id("complete", "orders") && $rs[0]['invoice_number'] > 0 ? true : false;
                 $this->view->invoice_id = $rs[0]['invoice_id'];
                 $this->view->order = array('records' => $rs);
                 $this->view->details = array('records' => $records, 'columns' => $columns);
                 // Get Order status history
                 $this->view->statushistory = StatusHistory::getStatusList($id);
                 // Show the list of the messages attached to this domain
                 $this->view->messages = Messages::getbyOrderId($id);
                 $this->view->headTitle()->prepend($this->translator->_('Order %s', $rs[0]['order_number']));
                 $rsfiles = Files::findbyExternalId($id, "orders", "file, Date_Format(date, '%d/%m/%Y') as date, fc.name as categoryname, publickey, download");
                 if (isset($rsfiles[0])) {
                     $this->view->files = $rsfiles;
                 }
                 // Send the data to the form
                 $form->populate($rs[0]);
                 $this->view->title = $this->translator->_('Order %s', $rs[0]['order_number']);
                 $this->view->orderid = $id;
             } else {
                 $this->_helper->redirector('index', 'orders', 'default', array('mex' => 'Order not found', 'status' => 'information'));
                 die;
             }
         }
         #$this->view->title = $this->translator->_('Order %s', $formattedID);
         $this->view->description = "Here you can see all the order information.";
         $this->view->dnsdatagrid = $this->dnsGrid();
         $this->view->form = $form;
         $this->_helper->viewRenderer('customform');
     } catch (Exception $e) {
         echo $e->getMessage();
         die;
     }
 }
Example #2
0
 /**
  * Check if all items of order are completed
  ***/
 public static function checkIfOrderItemsAreCompleted($orderid)
 {
     $records = OrdersItems::getAllDetails($orderid, "s.code as statuscode", true);
     foreach ($records as $record) {
         if ($record['statuscode'] != Statuses::id('complete', 'orders')) {
             return false;
         }
     }
     return true;
 }
Example #3
0
 public function get($uuid, $order_uuid = null, $service_uuid = null)
 {
     $this->authenticate();
     $customers = Customers::findWithUuid($uuid);
     if (empty($customers)) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'uuid' not valid");
         exit;
     }
     $id = $customers['customer_id'];
     if ($order_uuid == null && $service_uuid == null) {
         throw new Shineisp_Api_Exceptions(400006, ":: 'order_uuid' not valid and 'service_uuid' not valid");
     }
     #TODO get order from $order_uuid
     if ($service_uuid != null) {
         $objService = OrdersItems::findByUUID($service_uuid);
         if ($objService == false) {
             return false;
         }
         $service = $objService->toArray();
         $orderid = $service['order_id'];
         $fields = "o.order_id, \n            \t\t   o.order_number,\n                        DATE_FORMAT(o.order_date, '%d/%m/%Y') as Starting, \n                        DATE_FORMAT(o.expiring_date, '%d/%m/%Y') as Valid_Up, \n                        in.invoice_id as invoice_id, \n                        in.number as Invoice, \n                        CONCAT(d.domain, '.', w.tld) as Domain, \n                        c.company as company, \n                        o.status_id, \n                        s.status as Status, \n                        o.vat as VAT, \n                        o.total as Total, \n                        o.grandtotal as Grandtotal\n                        so.code as servStatus";
         $rs = Orders::getAllInfo($orderid, "*", true, $id);
         if (empty($rs)) {
             throw new Shineisp_Api_Exceptions(404001, ":: Orders not found");
         }
         return $rs;
         $currency = Shineisp_Registry::getInstance()->Zend_Currency;
         $result = array();
         $order = array_shift($rs);
         // Check the status of the order.
         // If the order has to be paid we have update it to the last prices and taxes
         if ($order['status_id'] == Statuses::id('tobepaid', 'orders')) {
             // Update the total order
             Orders::updateTotalsOrder($orderid);
             // Reload the data
             $rs = Orders::getAllInfo($orderid, $fields, true, $id);
             $order = array_shift($rs);
             $order['Total'] = $currency->toCurrency($order['Total'], array('currency' => Settings::findbyParam('currency')));
             $order['VAT'] = $currency->toCurrency($order['VAT'], array('currency' => Settings::findbyParam('currency')));
             $order['Grandtotal'] = $currency->toCurrency($order['Grandtotal'], array('currency' => Settings::findbyParam('currency')));
             $order['price'] = $order['Grandtotal'];
             $result['tobepaid'] = true;
         }
         $result['order'] = $order;
         $records = OrdersItems::getAllDetails($orderid, "oi.detail_id, oi.description as description, DATE_FORMAT(oi.date_end, '%d/%m/%Y') as expiration_date, oi.quantity as quantity, oi.price as price, bc.name as billingcycle, oi.setupfee as setupfee,p.autosetup as autosetup, s.code as statuscode", true);
         $allactive = false;
         for ($i = 0; $i < count($records); $i++) {
             $records[$i]['itemactiveonorder'] = false;
             if ($records[$i]['autosetup'] == 1) {
                 $records[$i]['itemactiveonorder'] = true;
                 $allactive = true;
             } else {
                 $allactive = false;
             }
             $records[$i]['price'] = $currency->toCurrency($records[$i]['price'], array('currency' => Settings::findbyParam('currency')));
             $records[$i]['setupfee'] = $currency->toCurrency($records[$i]['setupfee'], array('currency' => Settings::findbyParam('currency')));
         }
         $result['activeonorder'] = $allactive;
         $result['orderitems'] = $records;
         $result['invoidid'] = $order['status_id'] == Statuses::id("complete", "orders") && $order['Invoice'] > 0 ? true : false;
         $result['invoidnumber'] = $order['Invoice'];
         $result['invoidid'] = $order['invoice_id'];
         $result['payments'] = "";
         if ($result['tobepaid'] == true) {
             $result['payments'] = array();
             $banks = Banks::findAllActive("classname", true);
             if (!empty($banks)) {
                 foreach ($banks as $bank) {
                     if (!empty($bank['classname']) && class_exists($bank['classname'])) {
                         if (class_exists($bank['classname'])) {
                             $class = $bank['classname'];
                             $payment = new $class($id);
                             $payment->setUrlOk($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($bank['classname']));
                             $payment->setUrlKo($_SERVER['HTTP_HOST'] . "/orders/response/gateway/" . md5($bank['classname']));
                             $payment->setUrlCallback($_SERVER['HTTP_HOST'] . "/common/callback/gateway/" . md5($bank['classname']));
                             $result['payments'][] = $payment->CreateForm();
                         }
                     }
                 }
             }
         }
         return $result;
     }
 }