Beispiel #1
0
 /**
  * Getting The end javascript
  *
  * @return string
  */
 protected function _getEndJs()
 {
     $js = parent::_getEndJs();
     if (!isset($this->Request['id'])) {
         die('System ERR: no param passed in!');
     }
     if (trim($this->Request['id']) === 'new') {
         $order = new Order();
     } else {
         if (!($order = Order::get($this->Request['id'])) instanceof Order) {
             die('Invalid Order!');
         }
     }
     if ($order instanceof Order && trim($order->getType()) === Order::TYPE_INVOICE) {
         header('Location: /orderdetails/' . $order->getId() . '.html?' . $_SERVER['QUERY_STRING']);
         die;
     }
     $cloneOrder = null;
     if (isset($_REQUEST['cloneorderid']) && !($cloneOrder = Order::get(trim($_REQUEST['cloneorderid']))) instanceof Order) {
         die('Invalid Order to clone from');
     }
     $paymentMethods = array_map(create_function('$a', 'return $a->getJson();'), PaymentMethod::getAll(true, null, DaoQuery::DEFAUTL_PAGE_SIZE, array('name' => 'asc')));
     $shippingMethods = array_map(create_function('$a', 'return $a->getJson();'), Courier::getAll(true, null, DaoQuery::DEFAUTL_PAGE_SIZE, array('name' => 'asc')));
     $customer = isset($_REQUEST['customerid']) && ($customer = Customer::get(trim($_REQUEST['customerid']))) instanceof Customer ? $customer->getJson() : null;
     $js .= "pageJs";
     $js .= ".setHTMLID('itemDiv', 'detailswrapper')";
     $js .= ".setHTMLID('searchPanel', 'search_panel')";
     $js .= ".setCallbackId('searchCustomer', '" . $this->searchCustomerBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('searchProduct', '" . $this->searchProductBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('saveOrder', '" . $this->saveOrderBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('cancelOrder', '" . $this->cancelOrderBtn->getUniqueID() . "')";
     $js .= ".setPaymentMethods(" . json_encode($paymentMethods) . ")";
     $js .= ".setShippingMethods(" . json_encode($shippingMethods) . ")";
     $js .= ".setOrderTypes(" . json_encode(Order::getAllTypes()) . ")";
     if ($cloneOrder instanceof Order) {
         $clonOrderArray = $cloneOrder->getJson();
         $clonOrderArray['items'] = array_map(create_function('$a', 'return $a->getJson();'), OrderItem::getAllByCriteria('orderId = ?', array($cloneOrder->getId())));
         $js .= ".setOriginalOrder(" . json_encode($clonOrderArray) . ")";
     }
     if ($order instanceof Order && trim($order->getId()) !== '') {
         $orderArray = $order->getJson();
         $orderArray['items'] = array_map(create_function('$a', 'return $a->getJson();'), OrderItem::getAllByCriteria('orderId = ?', array($order->getId())));
         $js .= ".setOrder(" . json_encode($orderArray) . ")";
     }
     $js .= ".init(" . json_encode($customer) . ")";
     if (!AccessControl::canAccessCreateOrderPage(Core::getRole())) {
         $js .= ".disableEverything(" . (in_array(Core::getRole()->getId(), array(Role::ID_ACCOUNTING, Role::ID_SALES, Role::ID_PURCHASING)) ? 'true' : '') . ")";
     } else {
         if ($order instanceof Order && trim($order->getId()) !== '' && intval($order->getStatus()->getId()) === OrderStatus::ID_CANCELLED) {
             $js .= ".disableEverything()";
             $js .= ".showModalBox('<h4>Error</h4>', '<h4>This " . $order->getType() . " has been " . $order->getStatus()->getName() . "!</h4><h4>No one can edit it anymore</h4>')";
         }
     }
     $js .= ";";
     return $js;
 }
Beispiel #2
0
 /**
  * Getting The end javascript
  *
  * @return string
  */
 protected function _getEndJs()
 {
     $class = get_called_class();
     $js = $this->_getJSPrefix();
     $js .= parent::_getEndJs();
     $paymentMethods = array_map(create_function('$a', 'return $a->getJson();'), PaymentMethod::getAll());
     $shippingMethods = array_map(create_function('$a', 'return $a->getJson();'), Courier::getAll());
     $supplier = isset($_REQUEST['supplierid']) && ($supplier = Supplier::get(trim($_REQUEST['supplierid']))) instanceof Supplier ? $supplier->getJson() : null;
     $js .= "pageJs";
     $js .= ".setHTMLID('itemDiv', 'detailswrapper')";
     $js .= ".setHTMLID('searchPanel', 'search_panel')";
     $js .= ".setCallbackId('searchSupplier', '" . $this->searchSupplierBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('searchProduct', '" . $this->searchProductBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('saveOrder', '" . $this->saveOrderBtn->getUniqueID() . "')";
     $js .= ".setPaymentMethods(" . json_encode($paymentMethods) . ")";
     $js .= ".setShippingMethods(" . json_encode($shippingMethods) . ")";
     $js .= ".init(" . json_encode($supplier) . ");";
     return $js;
 }
 /**
  * Getting The end javascript
  *
  * @return string
  */
 protected function _getEndJs()
 {
     if (!isset($this->Request['id'])) {
         die('System ERR: no param passed in!');
     }
     if (!($creditNote = CreditNote::get($this->Request['id'])) instanceof CreditNote && trim($this->Request['id']) !== 'new') {
         die('Invalid CreditNote passed in!');
     }
     $js = parent::_getEndJs();
     $customer = isset($_REQUEST['customerid']) && ($customer = Customer::get(trim($_REQUEST['customerid']))) instanceof Customer ? $customer->getJson() : null;
     $order = null;
     if (isset($_REQUEST['orderid']) && !($order = Order::get(trim($_REQUEST['orderid']))) instanceof Order) {
         die('Invalid Order passed in!');
     }
     if ($order instanceof Order && $creditNote instanceof CreditNote && $creditNote->getOrder() instanceof Order && $creditNote->getOrder()->getId() !== $order->getId()) {
         die('You can ONLY create NEW Credit Note from an existing ORDER');
     }
     if ($order instanceof Order && intval($order->getStatus()->getId()) === OrderStatus::ID_CANCELLED) {
         die('You can NOT create a credit note against a CANCELED order(OrderNo: ' . $order->getOrderNo() . ')');
     }
     if ($creditNote instanceof CreditNote) {
         $js .= "pageJs._creditNote=" . json_encode($creditNote->getJson(array('customer' => $creditNote->getCustomer()->getJson(), 'items' => array_map(create_function('$a', 'return $a->getJson(array("product"=>$a->getProduct()->getJson()));'), $creditNote->getCreditNoteItems())))) . ";";
     }
     if ($order instanceof Order) {
         $js .= "pageJs._order=" . json_encode($order->getJson(array('customer' => $order->getCustomer()->getJson(), 'items' => array_map(create_function('$a', 'return $a->getJson(array("product"=>$a->getProduct()->getJson()));'), $order->getOrderItems())))) . ";";
     } else {
         $js .= "pageJs._customer=" . json_encode($customer) . ";";
     }
     $paymentMethods = array_map(create_function('$a', 'return $a->getJson();'), PaymentMethod::getAll(true, null, DaoQuery::DEFAUTL_PAGE_SIZE, array('name' => 'asc')));
     $applyToOptions = CreditNote::getApplyToTypes();
     $js .= "pageJs._applyToOptions=" . json_encode($applyToOptions) . ";";
     $js .= "pageJs";
     $js .= ".setHTMLID('itemDiv', 'detailswrapper')";
     $js .= ".setHTMLID('searchPanel', 'search_panel')";
     $js .= ".setCallbackId('searchCustomer', '" . $this->searchCustomerBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('searchProduct', '" . $this->searchProductBtn->getUniqueID() . "')";
     $js .= ".setCallbackId('saveOrder', '" . $this->saveOrderBtn->getUniqueID() . "')";
     $js .= ".setPaymentMethods(" . json_encode($paymentMethods) . ")";
     $js .= ".init();";
     return $js;
 }