/** * aanan fanan me likha buy :P */ public function actionBuy($id) { return; $currDateTime = new DateTime(); $currDateTime = $currDateTime->format('Y-m-d H:i:s'); $selectedTiffin = ATiffin::model()->findAll(array('select' => 't.id, t.name, t.contents', 'condition' => 't.verified_by != "not verified" AND t.is_deleted = "no" AND t.id = ' . $id, 'order' => 't.id ASC, aPriceTimes.id ASC', 'with' => array('aPriceTimes' => array('select' => 'aPriceTimes.price_after_discount, aPriceTimes.order_end_time, aPriceTimes.discount, aPriceTimes.id, aPriceTimes.order_delivery_time, aPriceTimes.quantity_currently_available, aPriceTimes.orderType', 'on' => 'aPriceTimes.order_start_time <= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_end_time >= ' . '"' . $currDateTime . '"', 'condition' => 'aPriceTimes.verified_by != "not verified" AND aPriceTimes.is_deleted = "no"')))); if (isset($selectedTiffin[0]) and isset($selectedTiffin[0]->aPriceTimes[0])) { $model = new BuyForm(); if (isset($_POST['BuyForm'])) { $model->attributes = $_POST['BuyForm']; $model->name = Yii::app()->user->name; $model->email = AppCommon::getEmail(); if ($model->validate()) { $temp_date = DateTime::createFromFormat('Y-m-d H:i:s', $selectedTiffin[0]->aPriceTimes[0]->order_delivery_time); $temp_date_sms = $temp_date; if ($temp_date != FALSE) { $temp_date_sms = $temp_date->format('d M Y h:i a'); //01 Apr 2015 01:22 am $temp_date = $temp_date->format('Y-M-d l, h:i:s a'); } Yii::ankFileSave("\n"); Yii::ankFileSave("order-start"); Yii::ankFileSave($model->name); Yii::ankFileSave($model->quantity); Yii::ankFileSave($model->email); Yii::ankFileSave($model->phone); Yii::ankFileSave($model->quantity); Yii::ankFileSave($model->techpark); Yii::ankFileSave($model->address); Yii::ankFileSave($model->paymentMode); Yii::ankFileSave($selectedTiffin[0]->name); Yii::ankFileSave($selectedTiffin[0]->id); Yii::ankFileSave($selectedTiffin[0]->aPriceTimes[0]->id); Yii::ankFileSave($temp_date); Yii::ankFileSave("order-stop"); Yii::ankFileSave("\n"); $subject_email = "Tiffin order confirmation " . $temp_date; $content_user = "******" . $model->name . ",\n" . "Your order comprising " . $model->quantity . " tiffin(s) of " . $selectedTiffin[0]->name . " has been accepted." . " We will deliver the order by " . $temp_date . " ( +/- 15 min. ) to " . $model->address . ", " . $model->techpark . ".\n The order is " . $model->paymentMode . " and order's cost is " . $model->quantity . " x " . $selectedTiffin[0]->aPriceTimes[0]->price_after_discount . " = Rs. " . $model->quantity * $selectedTiffin[0]->aPriceTimes[0]->price_after_discount . ". We may call on " . $model->phone . " for asking directions, if needed." . " Kindly receive the calls to make us deliver quickly. \n Thanks and regards, \n tw.in team "; //notify customer AppCommon::sendEmail($model->email, $model->name, $subject_email, $content_user, array("order_notification_customer")); //notify tw team AppCommon::sendEmail(Yii::app()->params['adminEmail'], $model->name, $subject_email, $content_user, array("order_notification_tiffinwale.in_team")); $content_sms = "Dear Customer, we have received your order and it will be delivered" . " on " . $temp_date_sms . " ( +/- 15 min. ). Do check your email for complete details." . " Thanks! tw.in"; /*$content_sms = "Dear Customer, we have received your order and it will be delivered". " on 01 Apr 2015 12:00 am. Do check your email for complete details.". " Thanks! tw.in"; $content_sms = "Dear Customer, we have received your order from". " and it will be delivered between 12:30 PM to 2:00 PM. Thank You! tw.in";*/ //sms customer AppCommon::sendSmsOnTime($model->phone, $content_sms, "null", true); Yii::app()->user->setFlash('buy', 'Thank you for ordering. Kindly check sms on your phone, we will deliver the meal at your address by ' . $temp_date . '.'); $this->refresh(); } } $this->render('buy', array('model' => $model, 'data' => $selectedTiffin[0])); } else { Yii::app()->user->setFlash('buy', 'Currently this meal is unavailable. Kindly do visit us again tomorrow, during lunch hours.'); //$this->refresh(); $this->render('buy'); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return ATiffin the loaded model * @throws CHttpException */ public function loadModel($id, $condition = '') { $model = ATiffin::model()->findByPk($id, $condition); if ($model === null) { throw new CHttpException(404, 'Either, the requested page does not exist or you are not allowed to view this page now.'); } return $model; }
/** * takes the given array and respond with changed array which contains proper quantity of every tiffin * plus some message is given with the tiffin quantity row. * reponse array has 'total_price' as total cart price and 'has_changed' over all and per tiffin row to depict * if cart has changed like quantity has been changed * or tiffins have been removed. Example row below * tiffn_id=>array("has_changed"=>true,"id"=>xyz,"tiffin_name"=>xyz,"tiffin_content"=>xyz,"image_link"=>xyz,"delivery_time"=>xyz * , 'quantity'=> xyz, "per_unit_price"=> xyz,"error_msg"=>xyz ) * error_msg exists when row's has_changed is true and if has_changed is false error_msg does not exists */ public static function modifyInputTiffinsQuantity($tiffinAndQuantArr, $location = null) { $response = array(); $response["has_changed"] = false; //made true if a change is array data is made $response["total_price"] = 0; $response["total_items_at_locality"] = 0; $tiffinIdSqlInCondtStr = ATiffin::model()->getCommandBuilder()->createInCondition(ATiffin::model()->tableName(), 'id', array_keys($tiffinAndQuantArr), 't.'); //string containing IN condition $selectedTiffins = array(); $currDateTime = new DateTime(); $currDateTime = $currDateTime->format('Y-m-d H:i:s'); if (isset($location)) { $selectedTiffins = ATiffin::model()->findAll(array('select' => 't.id, t.name, t.contents, t.rating_of_tiffin, t.num_of_reviews, t.image', 'condition' => 't.verified_by != "not verified" AND t.is_deleted = "no" AND ' . $tiffinIdSqlInCondtStr, 'order' => 't.id, aPriceTimes.order_delivery_time ASC', 'with' => array('tiffin2userDetails' => array('select' => 'tiffin2userDetails.id, tiffin2userDetails.first_name, tiffin2userDetails.last_name, tiffin2userDetails.rating_of_tiffinwala, tiffin2userDetails.unique_name', 'on' => 'tiffin2userDetails.is_active=1 AND tiffin2userDetails.user_type = 1', 'with' => array('aBangaloreLocalities' => array('on' => 'aBangaloreLocalities.is_deleted = "no" AND aBangaloreLocalities.locality_name=' . '"' . $location . '"', 'joinType' => 'LEFT OUTER JOIN'))), 'aPriceTimes' => array('select' => 'aPriceTimes.price_after_discount, aPriceTimes.order_end_time, aPriceTimes.order_delivery_time, aPriceTimes.quantity_currently_available, aPriceTimes.orderType, aPriceTimes.discount', 'on' => 'aPriceTimes.order_start_time <= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_end_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_delivery_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.quantity_currently_available > 0 ' . 'AND aPriceTimes.verified_by != "not verified" AND aPriceTimes.is_deleted = "no"', 'joinType' => 'LEFT OUTER JOIN')))); } else { $selectedTiffins = ATiffin::model()->findAll(array('select' => 't.id, t.name, t.contents, t.rating_of_tiffin, t.num_of_reviews, t.image', 'condition' => 't.verified_by != "not verified" AND t.is_deleted = "no" AND ' . $tiffinIdSqlInCondtStr, 'order' => 't.id, aPriceTimes.order_delivery_time ASC', 'with' => array('tiffin2userDetails' => array('select' => 'tiffin2userDetails.id, tiffin2userDetails.first_name, tiffin2userDetails.last_name, tiffin2userDetails.rating_of_tiffinwala, tiffin2userDetails.unique_name', 'on' => 'tiffin2userDetails.is_active=1 AND tiffin2userDetails.user_type = 1'), 'aPriceTimes' => array('select' => 'aPriceTimes.price_after_discount, aPriceTimes.order_end_time, aPriceTimes.order_delivery_time, aPriceTimes.quantity_currently_available, aPriceTimes.orderType, aPriceTimes.discount', 'on' => 'aPriceTimes.order_start_time <= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_end_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_delivery_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.quantity_currently_available > 0 ' . 'AND aPriceTimes.verified_by != "not verified" AND aPriceTimes.is_deleted = "no"', 'joinType' => 'LEFT OUTER JOIN')))); } foreach ($selectedTiffins as $currRec) { if (isset($tiffinAndQuantArr[$currRec->id])) { $response[$currRec->id]["has_changed"] = false; if (isset($location) and !isset($currRec->tiffin2userDetails->aBangaloreLocalities[0])) { $response[$currRec->id]["is_available_at_current_locality"] = false; } else { $response[$currRec->id]["is_available_at_current_locality"] = true; } if (isset($currRec->aPriceTimes[0]) and $currRec->aPriceTimes[0]->quantity_currently_available > 0) { if ($tiffinAndQuantArr[$currRec->id] < 1) { $tiffinAndQuantArr[$currRec->id] = 1; $response["has_changed"] = true; $response[$currRec->id]["has_changed"] = true; $response[$currRec->id]["error_msg"] = AppCommon::$cartErrorMsgTiffinQuanCappedToLimits; $response[$currRec->id]["quantity"] = $tiffinAndQuantArr[$currRec->id]; $response[$currRec->id]["per_unit_price"] = $currRec->aPriceTimes[0]->price_after_discount; $response[$currRec->id]["delivery_time"] = AppCommon::getDetailedDateString($currRec->aPriceTimes[0]->order_delivery_time); } else { if ($tiffinAndQuantArr[$currRec->id] > $currRec->aPriceTimes[0]->quantity_currently_available) { $tiffinAndQuantArr[$currRec->id] = $currRec->aPriceTimes[0]->quantity_currently_available; $response["has_changed"] = true; $response[$currRec->id]["has_changed"] = true; $response[$currRec->id]["error_msg"] = AppCommon::$cartErrorMsgTiffinQuanCappedToLimits; $response[$currRec->id]["quantity"] = $tiffinAndQuantArr[$currRec->id]; $response[$currRec->id]["per_unit_price"] = $currRec->aPriceTimes[0]->price_after_discount; $response[$currRec->id]["delivery_time"] = AppCommon::getDetailedDateString($currRec->aPriceTimes[0]->order_delivery_time); } else { $response[$currRec->id]["quantity"] = $tiffinAndQuantArr[$currRec->id]; $response[$currRec->id]["per_unit_price"] = $currRec->aPriceTimes[0]->price_after_discount; $response[$currRec->id]["delivery_time"] = AppCommon::getDetailedDateString($currRec->aPriceTimes[0]->order_delivery_time); } } if ($response[$currRec->id]["is_available_at_current_locality"]) { $response["total_items_at_locality"] = $response["total_items_at_locality"] + $response[$currRec->id]["quantity"]; $response["total_price"] = $response["total_price"] + $response[$currRec->id]["quantity"] * $response[$currRec->id]["per_unit_price"]; } } else { $response["has_changed"] = true; $response[$currRec->id]["has_changed"] = true; $response[$currRec->id]["error_msg"] = AppCommon::$cartErrorMsgTiffinNotAvailable; } $imagePath = null; $response[$currRec->id]["id"] = $currRec->id; $response[$currRec->id]["tiffin_name"] = $currRec->name; $response[$currRec->id]["tiffin_content"] = $currRec->contents; $response[$currRec->id]["chef_id"] = $currRec->tiffin2userDetails->id; if (isset($currRec->image)) { $imagePath = AppCommon::getAppFolderUrl() . '/images/tiffin_images/' . $currRec->image; } else { $imagePath = AppCommon::getAppFolderUrl() . '/images/tiffin_images/5.jpg'; } //default image $response[$currRec->id]["image_link"] = $imagePath; unset($tiffinAndQuantArr[$currRec->id]); } } foreach ($tiffinAndQuantArr as $key => $value) { $response["has_changed"] = true; $response[$key]["has_changed"] = true; $response[$key]["error_msg"] = AppCommon::$cartErrorMsgTiffinNotExist; } //$response["total_items"] = AppCommon::cartItemCount( ); $response["location"] = $location; return $response; }