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)); }
<?php echo CHtml::link('Advanced Search', '#', array('class' => 'search-button')); ?> <div class="search-form" style="display:none"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'prices-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'template' => "{items}\n<div class=\"span\">{pager}</div><div class=\"span\">{summary}</div>", 'enablePagination' => true, 'type' => TbHtml::GRID_TYPE_BORDERED, 'pagerCssClass' => 'CustomPager', 'rowCssClass' => 'CustomPager', 'columns' => array('id', 'trade_date', array('name' => 'instrument_id', 'header' => 'Instrument', 'type' => 'raw', 'value' => function ($data) { $ss = Instruments::model()->findByAttributes(array("id" => $data->instrument_id)); if ($ss) { return $ss->instrument; } else { return '-'; } }, 'filter' => CHtml::listData(Instruments::model()->findAll(), 'id', 'instrument'), 'htmlOptions' => array('width' => '150px')), array('name' => 'price', 'header' => 'Price', 'type' => 'raw', 'value' => function ($data) { return number_format($data->price, 2); }, 'htmlOptions' => array('width' => '30px')), array('name' => 'is_current', 'header' => 'Is Current', 'type' => 'raw', 'value' => function ($data) { if ($data->is_current == 1) { return 'Yes'; } else { return 'No'; } }, 'filter' => CHtml::listData([['id' => 'Yes', 'instrument' => 'Yes'], ['id' => 'No', 'instrument' => 'No']], 'id', 'instrument'), 'htmlOptions' => array('width' => '30px')), 'created_at', array('class' => 'CButtonColumn', 'template' => $access_buttons)))); ?>
$where = ' 1 = 1 '; if (isset($_REQUEST['instrument']) && !($_REQUEST['instrument'] == '')) { $instrument_id = $_REQUEST['instrument']; } if (isset($_REQUEST['dt']) && !($_REQUEST['dt'] == '')) { $dt = $_REQUEST['dt']; $where .= " and l.trade_date >='{$dt}' "; } //$this->beginWidget('zii.widgets.CPortlet', array('title'=>"Selection",)); echo CHtml::beginForm('returnCalculation', 'post'); ?> <div class="row form-group"> <label class="col-md-3 control-label"></label> <div class="col-md-4"> <?php echo CHtml::dropDownList('instrument', $instrument_id, CHtml::listData(Instruments::model()->findAll(array('select' => 'id, instrument', 'order' => 'instrument')), 'id', 'instrument'), array('empty' => '-- Select Instrument --', 'class' => 'form-control')); ?> </div> </div> <div class="row form-group"> <label class="col-md-3 control-label"></label> <div class="col-md-4"> <?php $this->widget('zii.widgets.jui.CJuiDatePicker', array('name' => 'dt', 'options' => array('showAnim' => 'fold', 'dateFormat' => 'yy-mm-dd'), 'htmlOptions' => array('placeholder' => 'YYYY-MM-DD', 'class' => 'form-control'))); ?> </div> </div> <div class="row form-group"> <label class="col-md-3 control-label"></label>
/** * 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 Instruments the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Instruments::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
$list = CHtml::listData($ports, 'id', 'portfolio'); echo CHtml::dropDownList('portfolio', $portfolio, $list, ['id' => 'portfolio', 'empty' => '-- Select --', 'onchange' => 'overviewload()', 'class' => "form-control"]); ?> </div> <div class="col-sm-2 control-label">Currency:</div> <div class="col-sm-2"> <?php echo CHtml::dropDownList('currency', 'USD', CHtml::listData(Currencies::model()->findAll(), 'currency', 'currency'), ['id' => 'currency', 'empty' => '-- Select --', 'onchange' => 'overviewload()', 'class' => "form-control"]); ?> </div> <div class="col-sm-2 control-label">Instrument:</div> <div class="col-sm-2"> <?php echo CHtml::dropDownList('instrument', '', CHtml::listData(Instruments::model()->findAll(), 'id', 'instrument'), ['id' => 'instrument', 'empty' => '-- Select --', 'onchange' => 'overviewload()', 'class' => "form-control"]); ?> </div> </div> </form> <div id="overview-view"></div> <div id="wait" style="display:none;width:69px;height:89px;position:absolute;top:50%;left:50%;padding:2px;"> <img src='<?php echo Yii::app()->theme->baseUrl; ?> /img/demo_wait.gif' width="64" height="64" /><br>Loading.. </div> <script>