/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate($shipment_id) { $model = new Pickup(); // 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('create', array('model' => $model, 'driver_list_available' => $driver_list_available, 'shipment_id' => $shipment_id)); }