public function setOrderServiceCompleteAction()
 {
     $sn = strtoupper(trim($this->_getParam('sn')));
     $result = 0;
     $ofd = new Model_OrderForDriver($sn);
     $order = new Model_Order($sn);
     if ($ofd->exists() && $ofd->get('driver_code') == $this->code && $order->get('status') < Model_Order::STATUS_SERVICE_COMPLATE) {
         $order->set('status', Model_Order::STATUS_SERVICE_COMPLATE);
         $result = $order->save();
     }
     $this->sendResult($result);
 }
 public function orderDetailAction()
 {
     $this->view->activeMenu = 'orders';
     $sn = trim($this->_getParam('sn'));
     if (empty($sn)) {
         $this->error('SN Does not exists.');
         return;
     }
     $order = new Model_Order($sn);
     if (!$order->exists() || $order->get('user_id') != $this->user->get('id')) {
         $this->error('Order does not exists.');
         return;
     }
     $this->view->order = $order;
     $ofd = new Model_OrderForDriver($sn);
     $driverAssigned = false;
     $vehicleAssigned = false;
     if ($ofd->exists() && !empty($ofd->get('driver_code'))) {
         $driverAssigned = new Model_Driver($ofd->get('driver_code'));
     }
     if ($ofd->exists() && !empty($ofd->get('vehicle_id'))) {
         $vehicleAssigned = new Model_Vehicle($ofd->get('vehicle_id'));
     }
     $this->view->driverAssigned = $driverAssigned;
     $this->view->vehicleAssigned = $vehicleAssigned;
     $this->view->vehicleTypes = (new Model_VehicleType())->fetchPagedList(1, 999999)['rows'];
     if (!$this->_request->isXmlHttpRequest()) {
         return;
     }
     // edit order
     $arp = new AjaxResponse();
     $arp->setStatus(AjaxResponse::STATUS_FAILED);
     $availableParams = array('forwho', 'city', 'contact-name', 'contact-email', 'contact-phone', 'passenger-names', 'passenger-phone', 'passenger-num', 'when', 'pickup-address', 'dropoff-address', 'vehicle', 'payment-method', 'notes');
     $via = $this->_getParam('via-address');
     $viaToSave = array();
     if (is_array($via)) {
         foreach ($via as $k => $v) {
             if (!empty($v)) {
                 $viaToSave[] = $v;
             }
         }
     }
     $via = json_encode($viaToSave);
     foreach ($availableParams as $paramName) {
         $value = trim($this->getParam($paramName, ''));
         $colName = str_replace('-', '_', $paramName);
         $order->set($colName, $value);
     }
     $order->set('via', $via);
     $order->save();
     $arp->setStatus(AjaxResponse::STATUS_OK);
     $arp->setMessage($sn);
     $this->json($arp);
 }
 public function editOrderForDriverAction()
 {
     $sn = $this->_getParam('sn');
     if (empty($sn)) {
         $this->error('nothing to edit');
         return;
     }
     $order = new Model_Order($sn);
     $ofd = new Model_OrderForDriver($sn);
     $ofd->set('sn', $sn);
     $availableParams = array('driver-code', 'vehicle-id', 'contact-name', 'contact-phone', 'pickup-address', 'pickup-coordinates', 'dropoff-address', 'dropoff-coordinates', 'payment-method', 'notes');
     foreach ($availableParams as $paramName) {
         $value = trim($this->_getParam($paramName, ''));
         $colName = str_replace('-', '_', $paramName);
         $ofd->set($colName, $value);
     }
     $when = strtotime(trim($this->_getParam('when', '')));
     $ofd->set('when', $when);
     $via = trim($this->_getParam('via', ''));
     $viaArray = explode("\n", $via);
     foreach ($viaArray as $k => $v) {
         $viaArray[$k] = trim($v);
         if (empty($viaArray[$k])) {
             unset($viaArray[$k]);
         }
     }
     $ofd->set('via', json_encode($viaArray));
     $viaCoordinates = trim($this->_getParam('via-coordinates', ''));
     $viaCoordinatesArray = explode("\n", $viaCoordinates);
     foreach ($viaCoordinatesArray as $k => $v) {
         $viaCoordinatesArray[$k] = trim($v);
         if (empty($viaCoordinatesArray[$k])) {
             unset($viaCoordinatesArray[$k]);
         }
     }
     $ofd->set('via_coordinates', json_encode($viaCoordinatesArray));
     $ofd->save();
     if ($this->_getParam('driver-code', '') && $order->get('status') < Model_Order::STATUS_DRIVER_ASSIGNED) {
         $order->set('status', Model_Order::STATUS_DRIVER_ASSIGNED);
         $order->save();
     }
     $this->_redirect('order-detail?sn=' . $sn);
 }