/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Prices(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Prices'])) { $model->attributes = $_POST['Prices']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionAdd() { $model = new Prices(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Prices'])) { $record = Prices::model()->findByAttributes(array('genre_id' => $_POST['Prices']['genre_id'], 'package' => $_POST['Prices']['package'], 'user_id' => $_POST['Prices']['user_id'])); if ($record->id == '') { $model->attributes = $_POST['Prices']; //print_r($model->attributes); exit(); if ($model->save()) { $this->redirect(array('index')); } } else { $model = $this->loadModel($record->id); $model->attributes = $_POST['Prices']; //print_r($model->attributes); exit(); if ($model->save()) { $this->redirect(array('index')); } } } $this->render('index', array('model' => $model)); }
public function actionSetPrice() { $dates = date('Y-m-d H:i:s'); $model = Menu::model()->with('dish')->findAll(); foreach ($model as $val) { $price = new Prices(); $price->price_date = $dates; $price->price = $val->getRelated('dish')->price; $price->menu_type = $val->mType; $price->just_id = $val->just_id; $price->types = $val->type; $price->save(); } $model2 = Menu::model()->with('halfstuff')->findAll(); foreach ($model2 as $val) { $price = new Prices(); $price->price_date = $dates; $price->price = $val->getRelated('halfstuff')->price; $price->menu_type = $val->mType; $price->just_id = $val->just_id; $price->types = $val->type; $price->save(); } $model3 = Menu::model()->with('products')->findAll(); foreach ($model3 as $val) { $price = new Prices(); $price->price_date = $dates; $price->price = $val->getRelated('products')->price; $price->menu_type = $val->mType; $price->just_id = $val->just_id; $price->types = $val->type; $price->save(); } }
public function actionFullupload() { /* $price_update = Prices::model()->findByAttributes(['trade_date'=>'0000-00-00', 'instrument_id' =>43], [ 'condition'=>'price!=:price', 'params'=>array('price'=>17.420), ] ); var_dump($price_update); exit; */ $model = new Uploads(); //$path = Yii::app()->basePath.'../../uploads/'; $path = Yii::getPathOfAlias('webroot') . '/uploads/'; if (isset($_POST['Uploads'])) { Yii::import('ext.phpexcel.XPHPExcel'); XPHPExcel::init(); ini_set('max_execution_time', 150000); ini_set("memory_limit", "128M"); require_once Yii::app()->basePath . '/extensions/XLSXReader/XLSXReader.php'; //OKarray(2) { ["Uploads"]=> array(2) { ["instrument_id"]=> string(2) "12" ["upload_description"]=> string(5) "sfggs" } ["yt0"]=> string(6) "Upload" } $model->attributes = $_POST['Uploads']; if ($upload_file = self::uploadMultifile($model, 'upload_file', $path)) { $model->upload_file = implode(",", $upload_file); } $model->user_id = Yii::app()->user->id; //$instrument_id = $model->instrument_id; ////////////////////////////////////////// if ($model->validate()) { //Upload File // if ($model->save()) { $upload_file_id = Yii::app()->db->getLastInsertID(); $csvFile = CUploadedFile::getInstance($model, 'upload_file', '../../uploads/'); $tempLoc = Yii::getPathOfAlias('webroot') . '/uploads/' . $model->upload_file; $xlsx = new XLSXReader($tempLoc); $data = $xlsx->getSheetData('Sheet1'); $instruments = Instruments::model()->findAll(array('select' => 'id, instrument')); $instruments_for_returns_update = []; foreach ($data as $dat) { $trade_date = gmdate('Y-m-d', PHPExcel_Shared_Date::ExcelToPHP($dat['0'])); $instrument_name = trim($dat['1']); $price = $dat['2']; $currency = $dat['3']; $instrument = Instruments::model()->findByAttributes(['instrument' => $instrument_name, 'is_current' => 1]); if ($instrument) { $instrument_id = $instrument->id; $instruments_for_returns_update[] = $instrument_id; } else { $new_instrument = new Instruments(); $new_instrument->instrument = $instrument_name; $new_instrument->price_uploaded = 1; $new_instrument->currency = $currency; $new_instrument->save(); $instrument_id = $new_instrument->id; $instruments_for_returns_update[] = $instrument_id; } $existing_record = Prices::model()->findByAttributes(['trade_date' => $trade_date, 'instrument_id' => $instrument_id]); if ($existing_record) { if ($existing_record->price !== $price) { $existing_record->price = $price; $existing_record->upload_file_id = $upload_file_id; $existing_record->save(); } } else { $new_price = new Prices(); $new_price->instrument_id = $instrument_id; $new_price->trade_date = $trade_date; $new_price->price = $price; $new_price->upload_file_id = $upload_file_id; //$new_price->name = $instrument_name; $new_price->save(); } } $unique_instruments_for_returns_update = array_unique($instruments_for_returns_update); Returns::model()->instrumnetReturnsUpdate($unique_instruments_for_returns_update); Yii::app()->user->setFlash('success', "Prices Uploaded!"); @chmod($tempLoc, 0777); @unlink($tempLoc); //unlink(Yii::getPathOfAlias('webroot').'/uploads/'.$model->upload_file); //$this->redirect(array('view','id'=>$model->id)); $user_data = Users::model()->findByPk(Yii::app()->user->id); $step_completed = $user_data->step_completed; if ($user_data->user_role == 2 && $step_completed < 2) { $user_data->step_completed = 1; $user_data->save(); $this->redirect(Yii::app()->baseUrl . '/site/admin'); } //else{ // $this->redirect(Yii::app()->baseUrl.'/site/admin'); // $this->render('overview', ['user_data' => $user_data]); } } } /////////////////////////////////////////// } $this->render('upload_form', array('model' => $model)); }
public function priceAdd($id, $mType, $price, $types) { $model = new Prices(); $dates = date('Y-m-d H:i:s'); $model->price_date = $dates; $model->price = $price; $model->menu_type = $mType; $model->just_id = $id; $model->types = $types; $model->save(); }