Exemplo n.º 1
0
 /**
  * Finds the Reason model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Reason the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Reason::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Reason::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['reason_text' => SORT_ASC]]]);
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['reason_id' => $this->reason_id]);
     $query->andFilterWhere(['like', 'reason_text', $this->reason_text]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdReason()
 {
     return $this->hasOne(Reason::className(), ['reason_id' => 'id_reason'])->from(['idReason' => Reason::tableName()])->inverseOf('osmotrakts');
 }
Exemplo n.º 4
0
    public function actionImportRemont()
    {
        header('Content-Type: text/html');
        try {
            $conn = new \PDO('mysql:host=127.0.0.1;dbname=remont;charset=UTF8', 'root', '265463');
            $sql = 'SELECT akt.akt_id,
	pol.pol_name,
	obor.obor_name,
	akt.akt_inv,
	akttext.akttext_name,
	aktuser.aktuser_name,
	prog.aktuser_name AS prog_name,
	akt.akt_kab,
	akt.akt_date,
	akt.akt_serial,
	akt.akt_closedate,
	akt.akt_datesend
FROM akt
INNER JOIN akttext ON akt.id_akttext = akttext.akttext_id
INNER JOIN obor ON akt.id_obor = obor.obor_id
INNER JOIN pol ON akt.id_pol = pol.pol_id
INNER JOIN aktuser ON akt.id_aktuser = aktuser.aktuser_id
INNER JOIN aktuser prog ON akt.id_prog = prog.aktuser_id';
            $fail = 0;
            $succ = 0;
            // Prepare
            /*     $Employee = \app\models\Fregat\Employee::find()
                   ->joinWith([
                   'idperson' => function($query) {
                   $query->from(['idperson' => 'auth_user']);
                   }
                   ])
                   ->andWhere(['like', 'idperson.auth_user_fullname', 'ЧЕПЕНКО АЛЕКСЕЙ ВЛАДИМИРОВИЧ'])
                   ->one();
                   $Employee->id_build = 2;
                   $Employee->save(); */
            $Employee = \app\models\Fregat\Employee::find()->joinWith(['idperson'])->andWhere(['like', 'idperson.auth_user_fullname', 'БАЙТИНГЕР АНАСТАСИЯ ВЛАДИМИРОВНА'])->all();
            foreach ($Employee as $ar) {
                \app\models\Fregat\Employee::updateAll(['id_build' => 1], ['employee_id' => $ar->employee_id]);
            }
            $Organ = new \app\models\Fregat\Organ();
            $Organ->organ_name = 'ООО "Северная линия"';
            $Organ->save();
            $Organ = new \app\models\Fregat\Organ();
            $Organ->organ_name = 'ООО «Копи-Мастер»';
            $Organ->organ_email = '*****@*****.**';
            $Organ->organ_phones = '8(3466)31-02-09';
            $Organ->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется замена термопленки';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется замена аккумулятора';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется замена резинового вала';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется замена фотобарабана';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется ремонт печки';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Неисправен податчик бумаги';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется замена инвертора подсветки матрицы';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Выводит на печать чистые листы';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Не определяет наличие бумаги в лотке';
            $Reason->save();
            $Reason = new Reason();
            $Reason->reason_text = 'Требуется заправка';
            $Reason->save();
            $Authuser = Authuser::findOne(1);
            //admin
            $Authuser->scenario = 'Changepassword';
            $Authuser->auth_user_password = '******';
            $Authuser->auth_user_password2 = '265463';
            $Authuser->save();
            $Authuser = Authuser::find()->andWhere(['in', 'auth_user_id', [989, 986, 987, 984, 988, 985, 1020]])->all();
            foreach ($Authuser as $ar) {
                $ar2 = Authuser::findOne($ar->primaryKey);
                $ar2->scenario = 'Changepassword';
                $ar2->auth_user_password = '******';
                $ar2->auth_user_password2 = '265463';
                $ar2->save();
                $auth = Yii::$app->authManager;
                if (!$auth->checkAccess($ar->primaryKey, 'Administrator')) {
                    $Role = $auth->getRole('Administrator');
                    $auth->assign($Role, $ar->primaryKey);
                }
            }
            $Hos = Authuser::find()->andWhere(['in', 'auth_user_id', [384, 489, 590, 614, 744, 466, 755, 614]])->all();
            foreach ($Hos as $ar) {
                $ar2 = Authuser::findOne($ar->primaryKey);
                $ar2->scenario = 'Changepassword';
                $ar2->auth_user_password = '******';
                $ar2->auth_user_password2 = '44444444';
                $ar2->save();
                $auth = Yii::$app->authManager;
                if (!$auth->checkAccess($ar->primaryKey, 'FregatHozSister')) {
                    $Role = $auth->getRole('FregatHozSister');
                    $auth->assign($Role, $ar->primaryKey);
                }
            }
            $querybuild = Build::find()->andWhere(['like', 'build_name', 'Административный корпус'])->one();
            if (empty($querybuild)) {
                $Build = new Build();
                $Build->build_name = 'Административный корпус';
                $Build->save();
            }
            // Prepare end
            foreach ($conn->query($sql, \PDO::FETCH_ASSOC) as $row) {
                //  var_dump($row);
                $mes = '<BR>' . 'akt №' . $row['akt_id'] . ' от ' . Yii::$app->formatter->asDate($row['akt_date']) . ' (Дата закрытия: ' . Yii::$app->formatter->asDate($row['akt_closedate']) . ')';
                $ok = false;
                $fail++;
                $mattraffic = \app\models\Fregat\Mattraffic::find()->joinWith(['idMaterial'])->join('LEFT JOIN', '(select id_material as id_material_m2, id_mol as id_mol_m2, mattraffic_date as mattraffic_date_m2, mattraffic_tip as mattraffic_tip_m2 from mattraffic) m2', 'mattraffic.id_material = m2.id_material_m2 and mattraffic.id_mol = m2.id_mol_m2 and mattraffic.mattraffic_date < m2.mattraffic_date_m2 and m2.mattraffic_tip_m2 in (1,2)')->andWhere(['in', 'mattraffic_tip', [1, 2]])->andWhere(['m2.mattraffic_date_m2' => NULL])->andWhere(['like', 'idMaterial.material_inv', $row['akt_inv'], false])->all();
                if (count($mattraffic) >= 2) {
                    $mattraffic = \app\models\Fregat\Mattraffic::find()->joinWith(['idMaterial'])->join('LEFT JOIN', '(select id_material as id_material_m2, id_mol as id_mol_m2, mattraffic_date as mattraffic_date_m2, mattraffic_tip as mattraffic_tip_m2 from mattraffic) m2', 'mattraffic.id_material = m2.id_material_m2 and mattraffic.id_mol = m2.id_mol_m2 and mattraffic.mattraffic_date < m2.mattraffic_date_m2 and m2.mattraffic_tip_m2 in (1,2)')->andWhere(['in', 'mattraffic_tip', [1, 2]])->andWhere(['m2.mattraffic_date_m2' => NULL])->andWhere(['idMaterial.material_tip' => 1])->andWhere(['like', 'idMaterial.material_inv', $row['akt_inv'], false])->all();
                }
                //  var_dump(count($mattraffic));
                if (count($mattraffic) == 1) {
                    $mes .= '<BR>' . $mattraffic[0]->idMaterial->material_name . ' inv=' . $mattraffic[0]->idMaterial->material_inv;
                    if ($mattraffic[0]->idMol->idbuild->build_name !== mb_strtoupper($row['pol_name'], 'UTF-8')) {
                        $mes .= '<BR>' . 'Build Problem: ' . $mattraffic[0]->idMol->idbuild->build_name . ' <> ' . mb_strtoupper($row['pol_name'], 'UTF-8');
                        /*   $Employee = \app\models\Fregat\Employee::find($mattraffic[0]->id_mol)->one();
                             $Employee_new = new \app\models\Fregat\Employee;
                             $Employee_new->attributes = $Employee->attributes;
                             $Employee_new->id_build = Build::find()->andWhere(['like', 'build_name', $row['pol_name']])->one()->build_id;
                             if (!$Employee_new->save())
                             $mes.='<BR>' . print_r($Employee_new->errors, true); */
                    } else {
                        $installer = \app\models\Fregat\Employee::find()->joinWith(['idperson', 'iddolzh', 'idpodraz', 'idbuild'])->andWhere(['like', 'idperson.auth_user_fullname', $row['prog_name']])->all();
                        $mes .= '<BR>' . 'instcount = ' . count($installer);
                        if (count($installer) == 0) {
                            $mes .= '<BR>' . $row['prog_name'] . ' not found';
                        } else {
                            if (count($installer) > 1) {
                                foreach ($installer as $ar) {
                                    $mes .= '<BR>' . $ar->idperson->auth_user_fullname . ' dolzh=' . $ar->iddolzh->dolzh_name;
                                }
                            } else {
                                if (count($installer) == 1) {
                                    $mes .= '<BR>' . $installer[0]->idperson->auth_user_fullname . ' dolzh=' . $installer[0]->iddolzh->dolzh_name;
                                    $transaction = Yii::$app->db->beginTransaction();
                                    try {
                                        $installakt = new \app\models\Fregat\Installakt();
                                        $installakt->installakt_date = substr($row['akt_date'], 0, 10);
                                        $installakt->id_installer = $installer[0]->primaryKey;
                                        if (!$installakt->save()) {
                                            $mes .= '<BR>' . print_r($installakt->errors, true);
                                            $transaction->rollBack();
                                        } else {
                                            $Mattraffic_tr = new \app\models\Fregat\Mattraffic();
                                            $Mattraffic_tr->attributes = $mattraffic[0]->attributes;
                                            $Mattraffic_tr->mattraffic_date = date('Y-m-d');
                                            $Mattraffic_tr->mattraffic_number = 1;
                                            $Mattraffic_tr->mattraffic_tip = 3;
                                            if ($Mattraffic_tr->validate()) {
                                                $Mattraffic_tr->save(false);
                                                $trosnov = new \app\models\Fregat\TrOsnov();
                                                $trosnov->id_installakt = $installakt->primaryKey;
                                                $trosnov->id_mattraffic = $Mattraffic_tr->primaryKey;
                                                $trosnov->tr_osnov_kab = $row['akt_kab'];
                                                if (!$trosnov->save()) {
                                                    $mes .= '<BR>' . print_r($trosnov->errors);
                                                    $transaction->rollBack();
                                                } else {
                                                    $mes .= '<BR>' . 'aktinstall saved';
                                                    $user = \app\models\Fregat\Employee::find()->joinWith(['idperson', 'iddolzh', 'idpodraz', 'idbuild'])->andWhere(['like', 'idperson.auth_user_fullname', $row['aktuser_name']])->all();
                                                    $mes .= '<BR>' . 'usercount = ' . count($user);
                                                    if (count($user) == 0) {
                                                        $mes .= '<BR>' . $row['aktuser_name'] . ' not found';
                                                        $transaction->rollBack();
                                                    } else {
                                                        if (count($user) >= 1) {
                                                            if (count($user) > 1) {
                                                                foreach ($user as $ar) {
                                                                    $mes .= '<BR>' . $ar->idperson->auth_user_fullname . ' dolzh=' . $ar->iddolzh->dolzh_name;
                                                                }
                                                            }
                                                            $osmotrakt = new \app\models\Fregat\Osmotrakt();
                                                            $osmotrakt->osmotrakt_id = $row['akt_id'];
                                                            $osmotrakt->osmotrakt_comment = $row['akttext_name'];
                                                            $osmotrakt->osmotrakt_date = substr($row['akt_date'], 0, 10);
                                                            $osmotrakt->id_master = $installer[0]->primaryKey;
                                                            $osmotrakt->id_user = $user[0]->primaryKey;
                                                            $osmotrakt->id_tr_osnov = $trosnov->primaryKey;
                                                            if (!$osmotrakt->save()) {
                                                                $mes .= '<BR>' . print_r($osmotrakt->errors);
                                                                $transaction->rollBack();
                                                            } else {
                                                                $mes .= '<BR>' . 'osmotrakt saved';
                                                                if (!empty($row['akt_closedate'])) {
                                                                    $Recoverysendakt = new \app\models\Fregat\Recoverysendakt();
                                                                    $organname = 'Северная линия';
                                                                    if (strtotime($row['akt_closedate']) >= strtotime('2016-05-04')) {
                                                                        $organname = 'Копи-Мастер';
                                                                    }
                                                                    $Organ = \app\models\Fregat\Organ::find()->andWhere(['like', 'organ_name', $organname])->one();
                                                                    $Recoverysendakt->id_organ = $Organ->PrimaryKey;
                                                                    $Recoverysendakt->recoverysendakt_date = substr($row['akt_closedate'], 0, 10);
                                                                    if (!$Recoverysendakt->save()) {
                                                                        $mes .= '<BR>' . print_r($Recoverysendakt->errors, true);
                                                                        $transaction->rollBack();
                                                                    } else {
                                                                        $Recoveryrecieveakt = new \app\models\Fregat\Recoveryrecieveakt();
                                                                        $Recoveryrecieveakt->id_osmotrakt = $osmotrakt->primaryKey;
                                                                        $Recoveryrecieveakt->id_recoverysendakt = $Recoverysendakt->primaryKey;
                                                                        $Recoveryrecieveakt->recoveryrecieveakt_result = 'Импортировано из старой программы';
                                                                        $Recoveryrecieveakt->recoveryrecieveakt_repaired = mb_stripos($row['obor_name'], 'ИБП', 0, 'UTF-8') === false ? 2 : 1;
                                                                        $Recoveryrecieveakt->recoveryrecieveakt_date = substr($row['akt_closedate'], 0, 10);
                                                                        if (!$Recoveryrecieveakt->save()) {
                                                                            $mes .= '<BR>' . print_r($Recoveryrecieveakt->errors, true);
                                                                            $transaction->rollBack();
                                                                        } else {
                                                                            $mes .= '<BR>' . 'Recoveryrecieveakt saved';
                                                                            $ok = true;
                                                                            $transaction->commit();
                                                                            $succ++;
                                                                            $fail--;
                                                                        }
                                                                    }
                                                                } else {
                                                                    $ok = true;
                                                                    $transaction->commit();
                                                                    $succ++;
                                                                    $fail--;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } else {
                                                $mes .= '<BR>' . print_r($Mattraffic_tr->errors);
                                                $transaction->rollBack();
                                            }
                                        }
                                    } catch (Exception $e) {
                                        $transaction->rollBack();
                                        throw new Exception($e->getMessage());
                                    }
                                }
                            }
                        }
                    }
                } else {
                    if (count($mattraffic) == 0) {
                        $mes .= '<BR>' . $row['akt_inv'] . ' not found';
                    } else {
                        if (count($mattraffic) > 1) {
                            foreach ($mattraffic as $ar) {
                                $mes .= '<BR>' . $ar->idMaterial->material_name . ' inv=' . $ar->idMaterial->material_inv;
                            }
                        }
                    }
                }
                $mes .= '<BR>' . '------------------------------------------------------------------';
                if (!$ok) {
                    echo $mes;
                }
            }
            var_dump('success = ' . $succ . ' (' . round($succ * 100 / ($succ + $fail), 2) . '%), fail = ' . $fail . ' from ' . ($succ + $fail));
        } catch (PDOException $e) {
            die('Подключение не удалось: ' . $e->getMessage());
        }
    }