Пример #1
0
 /**
  * Getting The end javascript
  *
  * @return string
  */
 protected function _getEndJs()
 {
     if (!($order = Order::get($this->Request['orderId'])) instanceof Order) {
         die('Invalid Order!');
     }
     if (trim($order->getType()) !== Order::TYPE_INVOICE) {
         header('Location: /order/' . $order->getId() . '.html?' . $_SERVER['QUERY_STRING']);
         die;
     }
     $js = parent::_getEndJs();
     $orderItems = $courierArray = array();
     foreach ($order->getOrderItems() as $orderItem) {
         $orderItems[] = $orderItem->getJson();
     }
     $purchaseEdit = $warehouseEdit = $accounEdit = $statusEdit = 'false';
     if ($order->canEditBy(Core::getRole())) {
         $statusEdit = $order->canEditBy(Core::getRole()) && Core::getRole()->getId() === trim(Role::ID_SYSTEM_ADMIN) ? 'true' : 'false';
         if (in_array(intval(Core::getRole()->getId()), array(Role::ID_SYSTEM_ADMIN, Role::ID_STORE_MANAGER, Role::ID_SALES))) {
             $purchaseEdit = $warehouseEdit = $accounEdit = 'true';
         } else {
             if (trim(Core::getRole()->getId()) === trim(Role::ID_PURCHASING)) {
                 $purchaseEdit = 'true';
             } else {
                 if (trim(Core::getRole()->getId()) === trim(Role::ID_WAREHOUSE)) {
                     $purchaseEdit = 'false';
                     $warehouseEdit = 'true';
                     $statusEdit = 'false';
                 }
             }
         }
     }
     if (in_array(intval(Core::getRole()->getId()), array(Role::ID_SYSTEM_ADMIN, Role::ID_STORE_MANAGER, Role::ID_ACCOUNTING, Role::ID_SALES))) {
         $accounEdit = 'true';
     }
     $orderArray = $order->getJson();
     $orderArray['childrenOrders'] = array_map(create_function('$a', 'return $a->getOrder()->getJson();'), OrderInfo::getAllByCriteria('typeId = ? and value = ?', array(OrderInfoType::ID_CLONED_FROM_ORDER_NO, trim($order->getOrderNo()))));
     $orderArray['creditNotes'] = array_map(create_function('$a', 'return $a->getJson();'), CreditNote::getAllByCriteria('orderId = ?', array(trim($order->getId()))));
     $orderStatuses = array_map(create_function('$a', 'return $a->getJson();'), OrderStatus::findAll());
     $courierArray = array_map(create_function('$a', 'return $a->getJson();'), Courier::findAll());
     $js .= 'pageJs';
     $js .= '.setCallbackId("updateOrder", "' . $this->updateOrderBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeOrderStatus", "' . $this->changeOrderStatusBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateOIForWH", "' . $this->updateOIForWHBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateShippingInfo", "' . $this->updateShippingInfoBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("clearETA", "' . $this->clearETABtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeIsOrdered", "' . $this->changeIsOrderedBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateAddress", "' . $this->updateAddressBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updatePONo", "' . $this->updatePONoBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("changeShippingMethod", "' . $this->changeShippingMethodBtn->getUniqueID() . '")';
     $js .= '.setCallbackId("updateSerials", "' . $this->updateSerialsBtn->getUniqueID() . '")';
     $js .= '.setEditMode(' . $purchaseEdit . ', ' . $warehouseEdit . ', ' . $accounEdit . ', ' . $statusEdit . ')';
     $js .= '.setOrder(' . json_encode($orderArray) . ', ' . json_encode($orderItems) . ', ' . json_encode($orderStatuses) . ', ' . OrderStatus::ID_SHIPPED . ')';
     $js .= '.setCourier(' . json_encode($courierArray) . ', ' . Courier::ID_LOCAL_PICKUP . ')';
     $js .= '.setCommentType("' . Comments::TYPE_PURCHASING . '", "' . Comments::TYPE_WAREHOUSE . '")';
     $js .= '.setOrderStatusIds([' . OrderStatus::ID_NEW . ', ' . OrderStatus::ID_INSUFFICIENT_STOCK . '], [' . OrderStatus::ID_ETA . ', ' . OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING . ', ' . OrderStatus::ID_INSUFFICIENT_STOCK . '], [' . OrderStatus::ID_PICKED . '])';
     $js .= '.init("detailswrapper")';
     $js .= '.load();';
     return $js;
 }