/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Firms::find()->orderBy('id desc'); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere([ 'id' => $this->id, 'date' => $this->date, ]); $query->andFilterWhere(['ilike', 'firm', $this->firm]) ->andFilterWhere(['ilike', 'file', $this->file]); return $dataProvider; }
/** * report for Medcenter * @param integer $firm */ public function actionStatreport($firm) { $this->layout = 'main'; $results = []; $firm_model = \app\models\Firms::find()->where(['id' => $firm])->one(); $patients = Patients::find()->where(['firm_id' => $firm])->all(); if ($patients) { $results = $this->_reportStat($patients); } \app\models\Functions::statreportExcel('stat', 'report.ods', $results); return $this->render('statreport', ['firm' => $firm_model->firm, 'res' => $this->statreportHtml($results), 'css' => file_get_contents('../web/css/print.css')]); }
/** * Creates a new Patients model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($firm_id) { $model = new Patients(); $firm = Firms::find()->where(['id' => $firm_id])->one(); $model->firm_id = $firm->id; $model->firm = $firm->firm; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Displays homepage. * * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Firms::find()]); $dataProviderPhones = new ActiveDataProvider(['query' => Phones::find()]); $sql = "SELECT id, Name, p.Phone as pPhone FROM " . Firms::tableName() . " LEFT JOIN " . Phones::tableName() . " as p ON id = p.FirmID " . " GROUP BY id"; $query = Firms::findBySql($sql); $dataProvider1 = new ActiveDataProvider(['query' => $query]); $sql = "SELECT id, Name, p.Phone as pPhone FROM " . Firms::tableName() . " LEFT JOIN " . Phones::tableName() . " as p ON id = p.FirmID " . " GROUP BY id HAVING count(p.phone_id) = '0'"; $query = Firms::findBySql($sql); $dataProvider2 = new ActiveDataProvider(['query' => $query]); $sql = "SELECT id, Name, p.Phone as pPhone FROM " . Firms::tableName() . " LEFT JOIN " . Phones::tableName() . " as p ON id = p.FirmID " . " GROUP BY id HAVING count(p.phone_id) >= '2'"; $query = Firms::findBySql($sql); $dataProvider3 = new ActiveDataProvider(['query' => $query]); $sql = "SELECT id, Name, p.Phone as pPhone FROM " . Firms::tableName() . " LEFT JOIN " . Phones::tableName() . " as p ON id = p.FirmID " . " GROUP BY id HAVING count(p.phone_id) < '2'"; $query = Firms::findBySql($sql); $dataProvider4 = new ActiveDataProvider(['query' => $query]); $sql = "SELECT id, Name, p.Phone as pPhone FROM " . Firms::tableName() . " LEFT JOIN " . Phones::tableName() . " as p ON id = p.FirmID " . " GROUP BY id HAVING count(p.phone_id) = (SELECT MAX( cpid) AS mcpid\n FROM (\n SELECT count(FirmID) AS cpid\n FROM " . Firms::tableName() . "\n LEFT JOIN " . Phones::tableName() . " ON id = FirmID\n GROUP BY FirmID\n ) AS cphone)"; $query = Firms::findBySql($sql); $dataProvider5 = new ActiveDataProvider(['query' => $query]); return $this->render('index', ['dataProvider' => $dataProvider, 'dataProviderPhones' => $dataProviderPhones, 'dataProvider1' => $dataProvider1, 'dataProvider2' => $dataProvider2, 'dataProvider3' => $dataProvider3, 'dataProvider4' => $dataProvider4, 'dataProvider5' => $dataProvider5]); }
/** * Finds the Firms model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Firms the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Firms::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public static function add($data) { $firm=new Firms(); $firm->attributes=$data; $firm->date=date('d.m.Y H:i:s'); if($firm->save()) { return $firm->id; } return false; }
/** * preparing loaded data to save * @param string $filename * @param iont $talon * @return array */ protected static function prepareData($filename,$talon) { $data=self::loadFromXls($filename); if(!$data) { return 'Нет данных'; } $data_to_save=[]; $firm=''; $firm_id=false; foreach ($data as $i=>$row) { if($i==0) { if(!isset($row[4])) { return 'Не задано предприятие'; } $firm=$row[4]; $firm_id=Firms::add(['firm'=>$firm,'file'=>$filename]); if(!$firm_id) { return 'Не удалось сохранить! Попробуйте еще раз.'; } continue; } foreach([2,3,4,5,6,8] as $column) { if(!isset($row[$column])) { return 'Не заданы основные атрибуты: Фамилия, Имя, Отчество, Пол, Специальность, Дата Рождения у пациента '.$row[2].' '.$row[3].' '.$row[4]; } } if(!isset($row[9]) && !isset($row[10])) { return 'Не заданы пункты Приложений у пациента '.$row[2].' '.$row[3].' '.$row[4]; } $new_row9=self::prepareFactors($row[9]); if($new_row9) { $check_factors1=self::checkFactors($new_row9,1); if($check_factors1!=1) { return $check_factors1.' у пациента '.$row[2].' '.$row[3].' '.$row[4]; } } $new_row10=self::prepareFactors($row[10]); if($new_row10) { $check_factors2=self::checkFactors($new_row10,2); if($check_factors2!=1) { return $check_factors2.' у пациента '.$row[2].' '.$row[3].' '.$row[4]; } } foreach([1,7,11,12,13,14,15,16,17,18,19,20,21,22,23,24] as $column) { if(!array_key_exists($column, $row)) { $data[$i][$column]=''; } else { $data[$i][$column].=''; } } $birthday=self::formatDate($row[8]); if(!$birthday) { return 'Неправильно указана дата рождения у пациента '.$row[2].' '.$row[3].' '.$row[4]; } $data_to_save[]=[ 'firm'=>$firm.'', 'snils'=>$row[1].'', 'surname'=>$row[2].'', 'name'=>$row[3].'', 'patron'=>$row[4].'', 'sex'=> self::defineSex($row[5]), 'spec'=>$row[6].'', 'phone'=>$row[7].'', 'birthday'=> self::formatDate($row[8]), 'factors1'=> $new_row9, 'factors2'=> $new_row10, 'seniority'=>$row[11].'', 'dep'=>$row[12].'', 'prof'=>$row[13].'', 'addresse_reg'=>$row[14].'', 'addresse_fact'=>$row[15].'', 'disability'=>$row[16].'', 'passport_series'=> self::toInt($row[17]), 'passport_number'=> self::toInt($row[18]), 'passport_given_date'=> self::formatDate($row[19]).'', 'passport_given_who'=>$row[20].'', 'insurance_number'=>$row[21].'', 'insurance_company'=>$row[22].'', 'living_lpu'=>$row[23].'', 'descr'=>$row[24].'', 'file'=>$filename, 'talon'=>$talon, 'firm_id'=>$firm_id, ]; } usort($data_to_save,function($row1,$row2) { return $row1['surname'].$row1['name'].$row1['patron'].$row1['birthday']>$row2['surname'].$row2['name'].$row2['patron'].$row2['birthday'] ? 1 : 0; }); return $data_to_save; }
/** * @return \yii\db\ActiveQuery */ public function getFirms0() { return $this->hasOne(Firms::className(), ['id' => 'firm_id']); }