public function actionAdmin() { $model = new BeneficiaryStatus('search'); $model->unsetAttributes(); if (isset($_GET['BeneficiaryStatus'])) { $model->setAttributes($_GET['BeneficiaryStatus']); } $this->render('admin', array('model' => $model)); }
<div class="row"> <?php echo $form->label($model, 'registration_code'); ?> <?php echo $form->textField($model, 'registration_code', array('maxlength' => 20)); ?> </div> <div class="row"> <?php echo $form->label($model, 'status_id'); ?> <?php echo $form->dropDownList($model, 'status_id', GxHtml::listDataEx(BeneficiaryStatus::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'neighborhood_id'); ?> <?php echo $form->dropDownList($model, 'neighborhood_id', GxHtml::listDataEx(Community::model()->findAllAttributes(null, true)), array('prompt' => Yii::t('app', 'All'))); ?> </div> <div class="row"> <?php echo $form->label($model, 'deleted_at');
public function actionImport() { $model = new Beneficiary('search'); $model->unsetAttributes(); $result = new BeneficiaryImportResult(); $count_inserted = 0; $count_updated = 0; if (isset($_FILES) && !empty($_FILES)) { move_uploaded_file($_FILES['UploadFileName']['tmp_name'], Yii::app()->params['IMPORT_PATH'] . $_FILES['UploadFileName']['name']); Yii::import('application.extensions.phpexcel.Classes.PHPExcel', true); $objReader = new PHPExcel_Reader_Excel5(); $objPHPExcel = $objReader->load(Yii::app()->params['IMPORT_PATH'] . $_FILES['UploadFileName']['name']); $objWorksheet = $objPHPExcel->getActiveSheet(); $highestRow = $objWorksheet->getHighestRow(); // e.g. 10 $highestColumn = $objWorksheet->getHighestColumn(); // e.g 'F' $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); // e.g. 5 $criteria = new CDbCriteria(); $criteria->addCondition('name="Active"'); // created Status for vouchers $status = BeneficiaryStatus::model()->find($criteria); $inserted_arr = []; $updated_arr = []; for ($row = 2; $row <= $highestRow; ++$row) { $criteria = new CDbCriteria(); $criteria->addCondition('registration_code="' . $objWorksheet->getCellByColumnAndRow(0, $row)->getValue() . '"'); // created Status for vouchers $beneficiary = Beneficiary::model()->find($criteria); $insert = 0; if (!$beneficiary) { $beneficiary = new Beneficiary(); $insert = 1; $count_inserted++; //$result->set_count_inserted($result->get_count_inserted()++); } else { $count_updated++; } //$result->set_count_updated($result->get_count_updated()++); $communitycriteria = new CDbCriteria(); $communitycriteria->addCondition('en_name="' . $objWorksheet->getCellByColumnAndRow(6, $row)->getValue() . '"'); $community = Community::model()->find($communitycriteria); $beneficiary->registration_code = $objWorksheet->getCellByColumnAndRow(0, $row)->getValue(); $beneficiary->ar_name = $objWorksheet->getCellByColumnAndRow(1, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(1, $row)->getValue() : $beneficiary->ar_name; $beneficiary->en_name = $objWorksheet->getCellByColumnAndRow(2, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(2, $row)->getValue() : $beneficiary->en_name; $beneficiary->family_member = $objWorksheet->getCellByColumnAndRow(3, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(3, $row)->getValue() : $beneficiary->family_member; $beneficiary->main_income_source = $objWorksheet->getCellByColumnAndRow(4, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(4, $row)->getValue() : $beneficiary->main_income_source; $beneficiary->combine_household = $objWorksheet->getCellByColumnAndRow(5, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(5, $row)->getValue() : $beneficiary->combine_household; $beneficiary->phone_number = $objWorksheet->getCellByColumnAndRow(7, $row)->getValue() ? $objWorksheet->getCellByColumnAndRow(7, $row)->getValue() : $beneficiary->phone_number; $beneficiary->neighborhood_id = $objWorksheet->getCellByColumnAndRow(6, $row)->getValue() ? $community->id : $beneficiary->neighborhood_id; $beneficiary->status_id = $status->id; $beneficiary->save(); if ($insert) { array_push($inserted_arr, $beneficiary->registration_code); } else { array_push($updated_arr, $beneficiary->registration_code); } } } else { $result->set_error('No File Selected'); } $result->set_count_inserted($count_inserted); $result->set_count_updated($count_updated); $result->set_record_inserted($inserted_arr); $result->set_record_updated($updated_arr); return $this->sendAjaxResponse($result); }
<?php echo $form->labelEx($model, 'registration_code'); ?> <?php echo $form->textField($model, 'registration_code', array('maxlength' => 20)); ?> <?php echo $form->error($model, 'registration_code'); ?> </div><!-- row --> <div class="row"> <?php echo $form->labelEx($model, 'status_id'); ?> <?php echo $form->dropDownList($model, 'status_id', GxHtml::listDataEx(BeneficiaryStatus::model()->findAllAttributes(null, true))); ?> <?php echo $form->error($model, 'status_id'); ?> </div><!-- row --> <div class="row"> <?php echo $form->labelEx($model, 'neighborhood_id'); ?> <?php echo $form->dropDownList($model, 'neighborhood_id', GxHtml::listDataEx(Community::model()->findAllAttributes(null, true))); ?> <?php echo $form->error($model, 'neighborhood_id'); ?>
<?php $this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('app', 'Manage')); $this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create'))); Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('beneficiary-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n"); ?> <h1><?php echo Yii::t('app', 'Manage') . ' ' . GxHtml::encode($model->label(2)); ?> </h1> <p> You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done. </p> <?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?> <div class="search-form"> <?php $this->renderPartial('_search', array('model' => $model)); ?> </div><!-- search-form --> <?php $this->widget('zii.widgets.grid.CGridView', array('id' => 'beneficiary-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', 'create_date', 'update_date', 'registration_code', array('name' => 'status_id', 'value' => 'GxHtml::valueEx($data->status)', 'filter' => GxHtml::listDataEx(BeneficiaryStatus::model()->findAllAttributes(null, true))), array('name' => 'neighborhood_id', 'value' => 'GxHtml::valueEx($data->neighborhood)', 'filter' => GxHtml::listDataEx(Community::model()->findAllAttributes(null, true))), array('class' => 'CButtonColumn'))));
<?php $this->breadcrumbs = array(BeneficiaryStatus::label(2), Yii::t('app', 'Index')); $this->menu = array(array('label' => Yii::t('app', 'Create') . ' ' . BeneficiaryStatus::label(), 'url' => array('create')), array('label' => Yii::t('app', 'Manage') . ' ' . BeneficiaryStatus::label(2), 'url' => array('admin'))); ?> <h1><?php echo GxHtml::encode(BeneficiaryStatus::label(2)); ?> </h1> <?php $this->widget('zii.widgets.CListView', array('dataProvider' => $dataProvider, 'itemView' => '_view'));