/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($shipment_id) { $model = Pickup::model()->findByAttributes(array('shipment_id' => $shipment_id)); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $shipment = Shipment::model()->findByPk($shipment_id); $criteria = new CDbCriteria(); $criteria->with = array('user', 'pickup'); $driver_list_available = new CActiveDataProvider('Driver', array('criteria' => $criteria)); if (isset($_GET['driver_id'])) { $model->driver_id = $_GET['driver_id']; $model->shipment_id = $shipment_id; $trans = Yii::app()->db->beginTransaction(); try { if ($model->save()) { $event = new ShipmentEvent(); $event->shipment_id = $shipment_id; $event->event_time = time(); $event->with_mde = 0; $event->user_id = Yii::app()->user->id; $event->status = 11; $event->setScenario('order'); if ($event->save()) { $shipment->shipping_status = 11; $shipment->setScenario('event'); if ($shipment->save()) { $trans->commit(); $this->redirect(array('shipment/operation')); } else { throw new CException($shipment->getErrors()); } } else { throw new CException($event->getErrors()); } } else { throw new CException($model->getErrors()); } } catch (CException $e) { $trans->rollback(); throw $e; } } $this->render('update', array('model' => $model, 'driver_list_available' => $driver_list_available, 'shipment_id' => $shipment_id)); }
public function actionTrackingDetails($id) { $this->layout = '//layouts/column2'; $shipment = Shipment::model()->findByPk($id); $customer = Customer::model()->findByPk($shipment->customer_id); $criteria = new CDbCriteria(); $criteria->compare('shipment_id', $shipment->id); $list_event = new CActiveDataProvider('ShipmentEvent', array('criteria' => $criteria)); $new_event = new ShipmentEvent(); $new_event->event_time = date('m/d/Y H:i', time()); $new_event->status = $shipment->shipping_status; $new_event->recipient_name = $shipment->recipient_name; $new_event->recipient_title = $shipment->recipient_title; if ($shipment->recipient_date != '') { $new_event->recipient_date = date('m/d/Y H:i', $shipment->recipient_date); } if (isset($_POST['ShipmentEvent'])) { $new_event->setAttributes($_POST['ShipmentEvent']); $shipment->shipping_status = $new_event->status; $shipment->shipping_remark = $new_event->remark; $shipment->recipient_name = $new_event->recipient_name; $shipment->recipient_title = $new_event->recipient_title; $shipment->event_time = strtotime($new_event->event_time); if (isset($new_event->recipient_date)) { $shipment->recipient_date = strtotime($new_event->recipient_date); } $shipment->setScenario('event'); $trans = Yii::app()->db->beginTransaction(); // error_log(strtotime($new_event->recipient_date).' - '.$new_event->recipient_date); error_log($shipment->recipient_date); try { if ($new_event->save()) { error_log($shipment->recipient_date); if ($shipment->save()) { error_log($shipment->recipient_date); Yii::app()->user->setFlash('success', 'Order status has successfully updated'); $trans->commit(); $this->redirect(array('trackingDetails', 'id' => $id)); } else { // throw new CException(var_export($shipment->getErrors())); CVarDumper::dump($shipment->getErrors(), 10, true); exit; } } else { throw new CException(var_export($new_event->getErrors())); } } catch (CException $e) { $trans->rollback(); throw $e; } } $this->render('view', array('list_event' => $list_event, 'new_event' => $new_event, 'shipment' => $shipment, 'customer' => $customer)); }
/** * Set shipment status to completed * * @param Shipment $shipment * @param string $recepient_name */ private function setJneStatusOrder(Shipment $shipment, $status, $recepient_name = '') { $event = new ShipmentEvent(); $shipment->setScenario('event'); $event->created = time(); $event->event_time = $event->created; $event->shipment_id = $shipment->id; $event->user_id = User::USER_SYSTEM; switch (strtoupper($status)) { case 'DELIVERED': $event->status = ShipmentStatus::POD; $shipment->shipping_status = ShipmentStatus::POD; $shipment->event_time = $event->event_time; $shipment->recipient_name = $recepient_name; break; case 'MANIFESTED': $event->status = ShipmentStatus::MDE; $shipment->shipping_status = ShipmentStatus::MDE; $shipment->event_time = $event->event_time; break; case 'RECEIVED ON DESTINATION': $event->status = ShipmentStatus::ARR; $shipment->shipping_status = ShipmentStatus::ARR; $shipment->event_time = $event->event_time; break; case 'ON PROCESS': $event->status = ShipmentStatus::OTW; $shipment->shipping_status = ShipmentStatus::OTW; $shipment->event_time = $event->event_time; break; } try { $trans = Yii::app()->db->beginTransaction(); if ($event->save()) { if ($shipment->save()) { $trans->commit(); $this->printf('Shipment set to %s', $status); return true; } else { print_r($shipment->getErrors()); throw new CException(); } } else { print_r($event->getErrors()); throw new CException(); } } catch (CException $e) { $trans->rollback(); throw $e; } }