예제 #1
0
 /**
  * Add or Remove an order item to/from a server
  * 
  * 
  * @param integer $orderItemID
  * @param integer $serverID
  */
 private static function doAddRemove($orderItemID, $serverID, $action = '')
 {
     $ret = false;
     if (is_numeric($orderItemID) && is_numeric($serverID) && ($action == 'add' || $action == 'remove')) {
         $serverID = intval($serverID);
         $itemID = intval($orderItemID);
         if ($action == 'remove') {
             $record = self::findByServerAndItem($serverID, $itemID);
             $record->delete();
             $ret = true;
         } else {
             $order = OrdersItems::find($orderItemID, 'order_id', true);
             if (!empty($order) && is_array($order) && count($order) > 0) {
                 $order = $order[0];
                 if (!isset($order['order_id']) || intval($order['order_id']) == 0) {
                     $ret = false;
                 }
                 $orderID = intval($order['order_id']);
                 $OrdersItemsServers = new self();
                 $OrdersItemsServers->server_id = $serverID;
                 $OrdersItemsServers->order_id = $orderID;
                 $OrdersItemsServers->orderitem_id = $itemID;
                 $OrdersItemsServers->save();
                 $ret = true;
             }
         }
         // Always update server stats
         $Server = Servers::find($serverID);
         $Server->services = OrdersItemsServers::countByServerId($serverID);
         $Server->save();
         return $ret;
     }
     return false;
 }
예제 #2
0
 /**
  * deleteAction
  * Delete a record previously selected by the order
  * @return unknown_type
  */
 public function deleteAction()
 {
     $files = new Files();
     $id = $this->getRequest()->getParam('id');
     if (is_numeric($id)) {
         $details = OrdersItems::find($id, "order_id", true);
         if (!empty($details[0]['order_id'])) {
             $record = Doctrine::getTable('OrdersItems')->find($id)->delete();
             $orderID = $details[0]['order_id'];
             Orders::updateTotalsOrder($orderID);
             return $this->_helper->redirector('edit', 'orders', 'admin', array('id' => $orderID));
         }
         return $this->_helper->redirector('list', 'orders', 'admin');
     }
     return $this->_helper->redirector('list', 'orders', 'admin');
 }
예제 #3
0
파일: Orders.php 프로젝트: kokkez/shineisp
 /**
  * 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;
             }
         }
     }
 }