/** * 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; } }
/** * 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 getEvent() { $criteria = new CDbCriteria(); $criteria->order = 'created DESC'; return ShipmentEvent::model()->findByAttributes(array('shipment_id' => $this->id), $criteria); }
public function actionUpdateBulkStatus() { $new_event = new ShipmentEvent('bulkinsert'); $failed = array(); $success = array(); if (isset($_POST['ShipmentEvent'])) { $new_event->setAttributes($_POST['ShipmentEvent']); if ($new_event->validate()) { $rawsAwb = nl2br($new_event->shipment_list); $arrAwb = explode('<br />', $rawsAwb); foreach ($arrAwb as $awb) { $awb = trim($awb); $shipment = Shipment::model()->findByAttributes(array('awb' => $awb)); if ($shipment instanceof Shipment) { array_push($success, $awb); // CVarDumper::dump($success,10,true); $event = new ShipmentEvent(); $event->setAttributes($_POST['ShipmentEvent']); $event->setAttribute('shipment_id', $shipment->id); $shipment->shipping_status = $event->status; $shipment->shipping_remark = $event->remark; $shipment->recipient_name = $event->recipient_name; $shipment->recipient_title = $event->recipient_title; $shipment->event_time = strtotime($event->event_time); if (isset($event->recipient_date)) { $shipment->recipient_date = strtotime($event->recipient_date); } $shipment->setScenario('event'); $event->save(); $shipment->save(); } else { array_push($failed, $awb); } if (count($success) != 0) { $list_success = implode(', ', $success); Yii::app()->user->setFlash('success', 'Success : ' . $list_success); } if (count($failed) != 0) { $list_failed = implode(', ', $failed); Yii::app()->user->setFlash('error', 'Failed : ' . $list_failed); } } } } $this->render('updateBulk', array('new_event' => $new_event)); }
public function actionAssigncancel() { if (!isset($_REQUEST['token']) && !isset($_REQUEST['awb'])) { echo CJSON::encode($this->statusError(0)); } else { $driver = Driver::getUserId($_REQUEST['token']); $shipment = Shipment::model()->findByAttributes(array('awb' => $_REQUEST['awb'], 'shipping_status' => 11)); if ($shipment == null) { echo CJSON::encode($this->statusError('shippment null')); } else { $shipment->shipping_status = 1; $shipment->save(false); $shipmentEvent = new ShipmentEvent(); $shipmentEvent->shipment_id = $shipment->id; $shipmentEvent->user_id = $driver; $shipmentEvent->status = 1; $shipmentEvent->created = time(); $shipmentEvent->event_time = time(); $shipmentEvent->description = isset($_REQUEST['keterangan']) ? $_REQUEST['keterangan'] : ''; $shipmentEvent->save(false); $pickup = Pickup::model()->findByAttributes(array('shipment_id' => $shipment->id)); $pickup->delete(false); echo CJSON::encode($this->statusSuccess(1)); } } Yii::app()->end(); }
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(); } } }
public function actionCreate($service_type = '') { $items = array(); $costs = array(); $model = new Shipment(); if ($service_type == '') { $this->beforeCreate($model); } else { if (!array_key_exists($service_type, $model->Service_type)) { throw new CHttpException(404, 'Halaman tidak ditemukan'); } $model->service_type = $service_type; $this->performAjaxValidation($model); $good_types = GoodType::model()->findAll(); $weight_to_count = array(); $arr_cost = array(); $total_cost = 0; $total_weight = 0; $ratePrice = 0; /** * model untuk data tambahan */ if ($model->service_type == 'domestic') { $model_domestic = new ShipmentDomestic(); } elseif ($model->service_type == 'city') { $model_city = new ShipmentIntracity(); } elseif ($model->service_type == 'international') { $model_international = new ShipmentInternational(); } if (isset($_POST['Shipment'])) { $model->setAttributes($_POST['Shipment']); /** * set the attributs to each service type */ if ($model->service_type == 'domestic' && isset($_POST['ShipmentDomestic'])) { $model_domestic->setAttributes($_POST['ShipmentDomestic']); } elseif ($model->service_type == 'city' && isset($_POST['ShipmentIntracity'])) { $model_city->setAttributes($_POST['ShipmentIntracity']); } elseif ($model->service_type == 'international' && isset($_POST['ShipmentInternational'])) { $model_international->setAttributes($_POST['ShipmentInternational']); } $trans = Yii::app()->db->beginTransaction(); try { if ($model->save()) { /** * this is for adding shipment events */ $shipment_event = new ShipmentEvent(); $shipment_event->shipment_id = $model->id; $shipment_event->status = $model->shipping_status; $shipment_event->user_id = Yii::app()->user->id; $shipment_event->save(); /** * this is for shipment items */ $shipment_items = $_POST['ShipmentItem']; foreach ($shipment_items as $item) { $shipment_item = new ShipmentItem(); $shipment_item->attributes = $item; $shipment_item->shipment_id = $model->id; $shipment_item->save(); array_push($weight_to_count, $shipment_item->getWeightToCount()); } $total_weight = array_sum($weight_to_count); /** * this is for shipment additional cost */ $shipment_costs = $_POST['ShipmentAdditionalCharge']; foreach ($shipment_costs as $cost) { $shipment_cost = new ShipmentAdditionalCharge(); $shipment_cost->attributes = $cost; $shipment_cost->shipment_id = $model->id; $shipment_cost->save(); array_push($arr_cost, $shipment_cost->cost); } $total_cost = array_sum($arr_cost); /** * Get the rate price base on service_type */ if ($model->service_type == 'domestic') { $ratePrice = RateDomestic::getRatePrice($model->service_id, 1, $model_domestic->district_id, $model_domestic->zone_id, $total_weight); $model_domestic->shipment_id = $model->id; $model_domestic->save(); } elseif ($model->service_type == 'city') { $ratePrice = IntraCityServices::getRates($model->service_id, $area_id = $model_city->area_id, $total_weight); $model_city->shipment_id = $model->id; $model_city->save(); } elseif ($model->service_type == 'international' && isset($_POST['ShipmentInternational'])) { $ratePrice = RateInternational::getRatePrice($model->service_id, $total_weight, $model->type, $model_international->zone); $model_international->shipment_id = $model->id; $model_international->save(); } $total_cost = $total_cost + $ratePrice; $model->package_weight = $total_weight; $model->charges = $total_cost; $model->save(); $trans->commit(); $this->redirect(array('admin')); } } catch (CDbException $e) { $trans->rollback(); throw $e; } } $items[] = new ShipmentItem(); $costs[] = new ShipmentAdditionalCharge(); $data_render = array('model' => $model, 'service_type' => $service_type, 'items' => $items, 'costs' => $costs, 'good_types' => $good_types); if ($model->service_type == 'domestic') { $data_render['model_domestic'] = $model_domestic; } else { if ($model->service_type == 'city') { $data_render['model_city'] = $model_city; } else { if ($model->service_type == 'international') { $data_render['model_international'] = $model_international; } } } $this->render('create', $data_render); } }