/** * 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 afterSave() { if ($this->isNewRecord) { //for the tracker $tracker = new OrderTracking('OrderCreated'); $tracker->shipments_id = $this->primaryKey; $tracker->save(); //for shipment event $shipment_event = new ShipmentEvent(); $shipment_event->shipment_id = $this->id; $shipment_event->status = $this->shipping_status; $shipment_event->event_time = $this->event_time; if ($this->getScenario() == 'api-requestpickup') { $shipment_event->user_id = 0; } else { $shipment_event->user_id = Yii::app()->user->id; } $shipment_event->setScenario('order'); $shipment_event->save(); if (!empty($this->customer_id)) { $trans = new Transaction(); $trans->shipment_id = $this->id; $trans->customer_id = $this->customer_id; $trans->created = $this->created; $trans->charges = $this->shipping_charges; $trans->total = $this->charges; $trans->save(); } } else { if ($this->getScenario() != 'event') { $shipment_event = new ShipmentEvent(); $shipment_event->shipment_id = $this->id; $shipment_event->status = $this->shipping_status; $shipment_event->event_time = time(); $shipment_event->user_id = Yii::app()->user->id; $shipment_event->with_mde = 1; $shipment_event->setScenario('order'); $shipment_event->save(); } if (!empty($this->customer_id)) { $trans = Transaction::model()->findByAttributes(array('shipment_id' => $this->id)); $trans->shipment_id = $this->id; $trans->customer_id = $this->customer_id; $trans->created = $this->created; $trans->charges = $this->shipping_charges; $trans->total = $this->charges; $trans->save(); } } }