/** * 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; }
/** * 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; }