示例#1
0
 public function save($IDinstaller)
 {
     if ($this->validate()) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $Installakt = new Installakt();
             $Installakt->installakt_date = date('Y-m-d');
             $Installakt->id_installer = $IDinstaller;
             if ($Installakt->save()) {
                 $Mattraffic = new Mattraffic();
                 $Mattraffic_choose = Mattraffic::findOne($this->id_mattraffic);
                 $Mattraffic->attributes = $Mattraffic_choose->attributes;
                 $Mattraffic->mattraffic_date = date('Y-m-d');
                 $Mattraffic->mattraffic_number = empty($this->mattraffic_number) ? 1 : $this->mattraffic_number;
                 $Mattraffic->mattraffic_tip = 3;
                 if ($Mattraffic->save()) {
                     $trOsnov = new TrOsnov();
                     $trOsnov->id_installakt = $Installakt->primaryKey;
                     $trOsnov->id_mattraffic = $Mattraffic->primaryKey;
                     $trOsnov->tr_osnov_kab = $this->tr_osnov_kab;
                     if ($trOsnov->save()) {
                         $this->mattraffic_trosnov_id = $trOsnov->primaryKey;
                         $this->primaryKey = $trOsnov->primaryKey;
                         $transaction->commit();
                         return true;
                     } else {
                         $transaction->rollBack();
                         return false;
                     }
                 } else {
                     $this->addError('mattraffic_number', $Mattraffic->getErrors('mattraffic_number')[0]);
                     $transaction->rollBack();
                     return false;
                 }
             } else {
                 $transaction->rollBack();
                 return false;
             }
         } catch (Exception $e) {
             $transaction->rollBack();
             throw new Exception($e->getMessage());
         }
     } else {
         return false;
     }
 }
示例#2
0
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $Mattraffic = Mattraffic::find()->andWhere(['id_material' => $model->material_id])->andWhere(['in', 'mattraffic_tip', [1, 2]])->orderBy('mattraffic_date desc, mattraffic_id desc')->one();
     $searchModel_mattraffic = new MattrafficSearch();
     $dataProvider_mattraffic = $searchModel_mattraffic->searchformaterialmattraffic(Yii::$app->request->queryParams);
     $searchModel_recovery = new OsmotraktSearch();
     $dataProvider_recovery = $searchModel_recovery->searchformaterialkarta(Yii::$app->request->queryParams);
     $searchModel_recoverymat = new TrMatOsmotrSearch();
     $dataProvider_recoverymat = $searchModel_recoverymat->searchformaterialkarta(Yii::$app->request->queryParams);
     $searchModel_recoverysend = new RecoveryrecieveaktSearch();
     $dataProvider_recoverysend = $searchModel_recoverysend->searchformaterialkarta(Yii::$app->request->queryParams);
     $searchModel_recoverysendmat = new RecoveryrecieveaktmatSearch();
     $dataProvider_recoverysendmat = $searchModel_recoverysendmat->searchformaterialkarta(Yii::$app->request->queryParams);
     $searchModel_mattraffic_contain = new TrMatSearch();
     $dataProvider_mattraffic_contain = $searchModel_mattraffic_contain->searchformaterialcontain(Yii::$app->request->queryParams);
     if (Yii::$app->user->can('MaterialEdit') && $model->load(Yii::$app->request->post()) && $model->save() && $Mattraffic->load(Yii::$app->request->post()) && $Mattraffic->save()) {
         return $this->redirect(Proc::GetPreviousURLBreadcrumbsFromSession());
     } else {
         return $this->render('update', ['model' => $model, 'Mattraffic' => $Mattraffic, 'searchModel_mattraffic' => $searchModel_mattraffic, 'dataProvider_mattraffic' => $dataProvider_mattraffic, 'searchModel_recovery' => $searchModel_recovery, 'dataProvider_recovery' => $dataProvider_recovery, 'searchModel_recoverymat' => $searchModel_recoverymat, 'dataProvider_recoverymat' => $dataProvider_recoverymat, 'searchModel_recoverysend' => $searchModel_recoverysend, 'dataProvider_recoverysend' => $dataProvider_recoverysend, 'searchModel_recoverysendmat' => $searchModel_recoverysendmat, 'dataProvider_recoverysendmat' => $dataProvider_recoverysendmat, 'searchModel_mattraffic_contain' => $searchModel_mattraffic_contain, 'dataProvider_mattraffic_contain' => $dataProvider_mattraffic_contain]);
     }
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdMattraffic()
 {
     return $this->hasOne(Mattraffic::className(), ['mattraffic_id' => 'id_mattraffic'])->from(['idMattraffic' => Mattraffic::tableName()])->inverseOf('trMats');
 }
示例#4
0
 public function actionDelete($id)
 {
     if (Yii::$app->request->isAjax) {
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $tr_osnov = $this->findModel($id);
             $id_mattraffic = $tr_osnov->id_mattraffic;
             $tr_osnov->delete();
             echo Mattraffic::findOne($id_mattraffic)->delete();
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
             throw new Exception($e->getMessage());
         }
     }
 }
示例#5
0
 /**
  * @depends loadData
  */
 public function destroyData()
 {
     Mattraffic::deleteAll();
     Material::deleteAll();
     Employee::deleteAll();
     Matvid::deleteAll();
     Izmer::deleteAll();
     Schetuchet::deleteAll();
     Authuser::deleteAll('auth_user_id <> 1');
     Build::deleteAll();
     Dolzh::deleteAll();
     Podraz::deleteAll();
 }
示例#6
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());
        }
    }
示例#7
0
use yii\bootstrap\ButtonDropdown;
use yii\bootstrap\ButtonGroup;
use app\models\Fregat\Mattraffic;
use app\models\Fregat\Material;
use app\models\Fregat\Employee;
/* @var $this yii\web\View */
/* @var $searchModel app\models\Fregat\MattrafficSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Движение материальных ценностей';
$this->params['breadcrumbs'] = Proc::Breadcrumbs($this);
?>
<div class="mattraffic-index">
    <?php 
$result = Proc::GetLastBreadcrumbsFromSession();
$foreign = isset($result['dopparams']['foreign']) ? $result['dopparams']['foreign'] : '';
$mattraffic_tip = Mattraffic::VariablesValues('mattraffic_tip');
$material_tip = Material::VariablesValues('material_tip');
$material_writeoff = Material::VariablesValues('material_writeoff');
$material_importdo = Material::VariablesValues('material_importdo');
$employee_importdo = Employee::VariablesValues('employee_importdo');
echo DynaGrid::widget(Proc::DGopts(['options' => ['id' => 'mattrafficgrid'], 'columns' => Proc::DGcols(['buttonsfirst' => true, 'buttons' => empty($foreign) ? [] : ['chooseajax' => ['Fregat/mattraffic/assign-to-select2']], 'buttonsfirst' => true, 'columns' => [['attribute' => 'mattraffic_date', 'format' => 'date'], ['attribute' => 'mattraffic_tip', 'filter' => $mattraffic_tip, 'value' => function ($model) use($mattraffic_tip) {
    return isset($mattraffic_tip[$model->mattraffic_tip]) ? $mattraffic_tip[$model->mattraffic_tip] : '';
}], 'mattraffic_number', ['attribute' => 'idMaterial.material_tip', 'filter' => $material_tip, 'value' => function ($model) use($material_tip) {
    return isset($material_tip[$model->idMaterial->material_tip]) ? $material_tip[$model->idMaterial->material_tip] : '';
}], ['attribute' => 'idMaterial.idMatv.matvid_name', 'visible' => false], 'idMaterial.material_name', 'idMaterial.material_inv', ['attribute' => 'idMaterial.material_serial', 'visible' => false], ['attribute' => 'idMaterial.material_release', 'format' => 'date', 'visible' => false], 'idMaterial.material_number', 'idMaterial.idIzmer.izmer_name', 'idMaterial.material_price', ['attribute' => 'idMol.employee_id', 'visible' => false], 'idMol.idperson.auth_user_fullname', 'idMol.iddolzh.dolzh_name', 'idMol.idpodraz.podraz_name', 'idMol.idbuild.build_name', ['attribute' => 'idMol.employee_dateinactive', 'format' => 'date', 'visible' => false], ['attribute' => 'idMaterial.material_writeoff', 'filter' => $material_writeoff, 'value' => function ($model) use($material_writeoff) {
    return isset($material_writeoff[$model->idMaterial->material_writeoff]) ? $material_writeoff[$model->idMaterial->material_writeoff] : '';
}, 'visible' => false], ['attribute' => 'idMaterial.material_username', 'visible' => false], ['attribute' => 'idMaterial.material_lastchange', 'format' => 'datetime', 'visible' => false], ['attribute' => 'idMaterial.material_importdo', 'filter' => $material_importdo, 'value' => function ($model) use($material_importdo) {
    return isset($material_importdo[$model->idMaterial->material_importdo]) ? $material_importdo[$model->idMaterial->material_importdo] : '';
}, 'visible' => false], ['attribute' => 'idMol.employee_username', 'visible' => false], ['attribute' => 'idMol.employee_lastchange', 'format' => 'datetime', 'visible' => false], ['attribute' => 'idMol.employee_importdo', 'filter' => $employee_importdo, 'value' => function ($model) use($employee_importdo) {
    return isset($employee_importdo[$model->idMol->employee_importdo]) ? $employee_importdo[$model->idMol->employee_importdo] : '';
}, 'visible' => false], ['attribute' => 'mattraffic_username', 'visible' => false], ['attribute' => 'mattraffic_lastchange', 'format' => 'datetime', 'visible' => false]]]), 'gridOptions' => ['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model, $index, $widget, $grid) {
示例#8
0
 public function actionFillnewinstallakt()
 {
     if (Yii::$app->request->isAjax) {
         $id_mattraffic = Yii::$app->request->post('id_mattraffic');
         if (!empty($id_mattraffic)) {
             $query = Mattraffic::findOne($id_mattraffic);
             if (!empty($query)) {
                 $material_writeoff = Material::VariablesValues('material_writeoff');
                 echo json_encode(['material_id' => $query->id_material, 'material_name' => $query->idMaterial->material_name, 'material_writeoff' => $material_writeoff[$query->idMaterial->material_writeoff], 'auth_user_fullname' => $query->idMol->idperson->auth_user_fullname, 'dolzh_name' => $query->idMol->iddolzh->dolzh_name, 'build_name' => $query->idMol->idbuild->build_name, 'mattraffic_number' => $query->mattraffic_number]);
             }
         }
     }
 }
示例#9
0
 protected function Body()
 {
     $ID = $this->getDopparamID();
     $this->setReportName('Акт перемещения матер-ых цен-тей №' . $ID);
     $Installakt = Installakt::findOne($ID);
     $Trosnov = TrOsnov::findAll(['id_installakt' => $ID]);
     $Trmat = TrMat::find()->andWhere(['id_installakt' => $ID])->GroupBy('id_parent')->all();
     $objPHPExcel = $this->getObjPHPExcel();
     $objPHPExcel->getActiveSheet()->setCellValue('A3', 'материальных ценностей № ' . $Installakt->installakt_id . ' от ' . Yii::$app->formatter->asDate($Installakt->installakt_date));
     $num = 5;
     $c_Trosnov = count($Trosnov);
     if ($c_Trosnov > 0) {
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Перемещение материальных ценностей');
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 10, $num);
         $this->setStyle(self::$TITLE, 'A' . $num . ':K' . $num);
         $num++;
         $this->SetTitlebyArray(['№', 'Вид', 'Наименование', 'Инвентарный номер', 'Серийный номер', 'Кол-во', 'Единица измерения', 'Лицо отправитель', 'Здание, кабинет, откуда перемещено', 'Лицо получатель', 'Здание, кабинет, куда перемещено'], $num);
         $this->setStyle(self::$CAPTION, 'A' . $num . ':K' . $num);
         $this->CellsWrapAndTop('A' . $num . ':K' . $num);
         $num++;
         $this->setColumnNumbers($num, 11);
         $this->setStyle(self::$NUMS, 'A' . $num . ':K' . $num);
         $this->CellsWrapAndTop('A' . $num . ':K' . $num);
         $num++;
         $startrow = $num;
         foreach ($Trosnov as $ar) {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - $startrow + 1);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idMattraffic->idMaterial->idMatv->matvid_name);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idMattraffic->idMaterial->material_name);
             $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, $ar->idMattraffic->idMaterial->material_serial);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, $ar->idMattraffic->mattraffic_number);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->idMattraffic->idMaterial->idIzmer->izmer_name);
             $mattraffic_previous = Mattraffic::GetPreviousMattrafficByInstallaktMaterial($ID, $ar->idMattraffic->id_material);
             if (!empty($mattraffic_previous)) {
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $mattraffic_previous->idMol->idperson->auth_user_fullname . ', ' . $mattraffic_previous->idMol->iddolzh->dolzh_name);
                 if ($mattraffic_previous->mattraffic_tip == 1 && empty($mattraffic_previous->trOsnovs[0]->tr_osnov_kab)) {
                     $kab = ', Приход';
                 } elseif ($mattraffic_previous->mattraffic_tip == 2 && empty($mattraffic_previous->trOsnovs[0]->tr_osnov_kab)) {
                     $kab = ', Списание';
                 } else {
                     $kab = ', ' . $mattraffic_previous->trOsnovs[0]->tr_osnov_kab;
                 }
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $mattraffic_previous->idMol->idbuild->build_name . $kab);
             }
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, $ar->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idMattraffic->idMol->iddolzh->dolzh_name);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, $ar->idMattraffic->idMol->idbuild->build_name . ', ' . $ar->tr_osnov_kab);
             $num++;
         }
         if (count($Trosnov) > 0) {
             $this->setStyle(self::$DATA, 'A' . $startrow . ':K' . ($num - 1));
         }
         $this->CellsWrapAndTop('A' . $startrow . ':K' . $num);
         $num++;
     }
     $c_Trmat = count($Trmat);
     if ($c_Trmat > 0) {
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Установка комплектующих');
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 10, $num);
         $this->setStyle(self::$TITLE, 'A' . $num . ':K' . $num);
         $num++;
         foreach ($Trmat as $arm) {
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Материальная ценность');
             $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 10, $num);
             $this->setStyle(self::$TITLELEFT, 'A' . $num . ':K' . $num);
             $num++;
             $this->SetTitlebyArray(['№', 'Вид', 'Наименование', 'Инвентарный номер', 'Серийный номер', 'Год выпуска', 'Стоимость', 'Здание', 'Кабинет', 'Материально-ответственное лицо', 'Тип'], $num);
             $this->setStyle(self::$CAPTION, 'A' . $num . ':K' . $num);
             $this->CellsWrapAndTop('A' . $num . ':K' . $num);
             $num++;
             $this->setColumnNumbers($num, 11);
             $this->setStyle(self::$NUMS, 'A' . $num . ':K' . $num);
             $this->CellsWrapAndTop('A' . $num . ':K' . $num);
             $num++;
             $material_tip = Material::VariablesValues('material_tip');
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 1);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $arm->idParent->idMaterial->idMatv->matvid_name);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $arm->idParent->idMaterial->material_name);
             $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $arm->idParent->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, $arm->idParent->idMaterial->material_serial);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, Yii::$app->formatter->asDate($arm->idParent->idMaterial->material_release, 'y'));
             $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(6, $num, $arm->idParent->idMaterial->material_price, \PHPExcel_Cell_DataType::TYPE_STRING);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $arm->idParent->idMol->idbuild->build_name);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $arm->idParent->trOsnovs[0]->tr_osnov_kab);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, $arm->idParent->idMol->idperson->auth_user_fullname . ', ' . $arm->idParent->idMol->iddolzh->dolzh_name);
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, $material_tip[$arm->idParent->idMaterial->material_tip]);
             $this->setStyle(self::$DATA, 'A' . $num . ':K' . $num);
             $this->CellsWrapAndTop('A' . $num . ':K' . $num);
             $num++;
             $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Установленные комплектующие');
             $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 10, $num);
             $this->setStyle(self::$TITLELEFT, 'A' . $num . ':K' . $num);
             $num++;
             $this->SetTitlebyArray(['№', 'Вид', 'Наименование', 'Инвентарный номер', 'Серийный номер', 'Кол-во', 'Единица измерения', 'Год выпуска', 'Стоимость', 'Материально-ответственное лицо', 'Тип'], $num);
             $this->setStyle(self::$CAPTION, 'A' . $num . ':K' . $num);
             $this->CellsWrapAndTop('A' . $num . ':K' . $num);
             $num++;
             $this->setColumnNumbers($num, 11);
             $this->setStyle(self::$NUMS, 'A' . $num . ':K' . $num);
             $this->CellsWrapAndTop('A' . $num . ':K' . $num);
             $num++;
             $MatbyParent = TrMat::find()->andWhere(['id_parent' => $arm->idParent->primaryKey, 'id_installakt' => $Installakt->installakt_id])->all();
             $startrow = $num;
             foreach ($MatbyParent as $ar) {
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - $startrow + 1);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idMattraffic->idMaterial->idMatv->matvid_name);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idMattraffic->idMaterial->material_name);
                 $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, $ar->idMattraffic->idMaterial->material_serial);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, $ar->idMattraffic->mattraffic_number);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->idMattraffic->idMaterial->idIzmer->izmer_name);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, Yii::$app->formatter->asDate($ar->idMattraffic->idMaterial->material_release, 'y'));
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $ar->idMattraffic->idMaterial->material_price);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, $ar->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idMattraffic->idMol->iddolzh->dolzh_name);
                 $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, $material_tip[$ar->idMattraffic->idMaterial->material_tip]);
                 $num++;
             }
             if (count($MatbyParent) > 0) {
                 $this->setStyle(self::$DATA, 'A' . $startrow . ':K' . ($num - 1));
             }
             $this->CellsWrapAndTop('A' . $startrow . ':K' . $num);
             $num++;
         }
     }
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, '(Подпись)');
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num, '(Должность)');
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, '(Ф.И.О.)');
     $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num, 6, $num);
     $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num, 10, $num);
     $this->setStyle(self::$SIGN, 'A' . $num . ':K' . $num);
     $num++;
     $Mols = Installakt::getMolsByInstallakt($Installakt->installakt_id);
     $startrow = $num;
     foreach ($Mols as $ar) {
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Материально ответственное лицо');
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 1, $num);
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num, 6, $num);
         $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num, 10, $num);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num, $ar->dolzh_name_tmp);
         $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->auth_user_fullname_tmp);
         $this->CellsWrapAndTop('A' . $num . ':K' . $num);
         $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(45.75);
         $num++;
     }
     $this->setStyle(self::$TITLELEFT, 'A' . $startrow . ':B' . ($num - 1));
     $this->setStyle(self::$SIGNDATA, 'C' . $startrow . ':K' . ($num - 1));
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, 'Мастер');
     $this->setStyle(self::$TITLELEFT, 'A' . $num . ':B' . $num);
     $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num, 1, $num);
     $this->setStyle(self::$SIGNDATA, 'C' . $num . ':K' . $num);
     $Master = Employee::findOne($Installakt->id_installer);
     $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num, 6, $num);
     $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num, 10, $num);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num, $Master->iddolzh->dolzh_name);
     $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $Master->idperson->auth_user_fullname);
     $this->CellsWrapAndTop('A' . $num . ':K' . $num);
     $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(45.75);
 }
示例#10
0
 public function searchforspisosnovakt($params)
 {
     $query = Mattraffic::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['mattraffic_date' => SORT_DESC, 'mattraffic_id' => SORT_DESC]]]);
     $query->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)');
     $this->baseRelations($query);
     $query->andWhere('(mattraffic_number > 0 and idMaterial.material_tip in (1,3))')->andWhere(['in', 'mattraffic_tip', [1]])->andWhere(['m2.mattraffic_date_m2' => NULL, 'idMaterial.material_writeoff' => 0]);
     $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;
     }
     $this->baseFilter($query);
     $this->baseSort($dataProvider);
     return $dataProvider;
 }
示例#11
0
 static function ImportDo()
 {
     // Делаем запись в таблицу отчетов импорта
     $logreport = new Logreport();
     $Importconfig = self::GetRowsPDO('select * from importconfig where importconfig_id = 1');
     if ($Importconfig['importconfig_do']) {
         self::$os_start = $Importconfig['os_startrow'];
         self::$mat_start = $Importconfig['mat_startrow'];
         self::$gu_start = $Importconfig['gu_startrow'];
         self::$Mishanya = 0;
         self::$Debug = YII_DEBUG;
         $starttime = microtime(true);
         $logreport->logreport_date = date('Y-m-d');
         $doreport = false;
         self::$materialexists = Material::find()->count() > 0;
         self::DeleteOldReports();
         // Идем по файлам импорта из 1С (os.xls - Основные средства, mat.xls - Материалы)
         foreach ([$Importconfig['emp_filename'] . '.txt', $Importconfig['os_filename'] . '.xlsx', $Importconfig['mat_filename'] . '.xlsx', $Importconfig['gu_filename'] . '.xlsx'] as $filename) {
             self::$filename = dirname($_SERVER['SCRIPT_FILENAME']) . '/imp/' . $filename;
             $FileType = self::$filename === dirname($_SERVER['SCRIPT_FILENAME']) . '/imp/' . $Importconfig['os_filename'] . '.xlsx' ? self::os : (self::$filename === dirname($_SERVER['SCRIPT_FILENAME']) . '/imp/' . $Importconfig['mat_filename'] . '.xlsx' ? self::mat : self::gu);
             self::SetFileType($FileType);
             self::Setxls();
             if (file_exists(self::$filename)) {
                 self::$filelastdate = date("Y-m-d H:i:s", filemtime(self::$filename));
                 $filelastdateFromDB = self::GetMaxFileLastDate($Importconfig);
                 if (self::$Debug || empty($filelastdateFromDB) || strtotime(self::$filelastdate) > strtotime($filelastdateFromDB)) {
                     /*   var_dump(self::$filename);
                          var_dump(self::$filelastdate);
                          var_dump($filelastdateFromDB);
                          var_dump($_SERVER);
                          var_dump($_ENV); */
                     ini_set('max_execution_time', $Importconfig['max_execution_time']);
                     // 1000 seconds
                     ini_set('memory_limit', $Importconfig['memory_limit']);
                     // 1Gbyte Max Memory
                     $logreport->save();
                     self::$logreport_id = $logreport->logreport_id;
                     $doreport = true;
                     // Определяем показатели импорта
                     self::$logreport_errors = 0;
                     // Не загружено записей из-за ошибок
                     self::$logreport_updates = 0;
                     // Записей изменено
                     self::$logreport_additions = 0;
                     // Записей добавлено
                     self::$logreport_missed = 0;
                     // Записей пропущено (исключены из обработки)
                     self::$logreport_amount = 0;
                     // Всего записей
                     if ($filename === $Importconfig['emp_filename'] . '.txt') {
                         self::$employee = true;
                     }
                     if (self::$employee) {
                         $i = 0;
                         $handle = @fopen(self::$filename, "r");
                         if ($handle) {
                             $UTF8deleteBOM = true;
                             while (($subject = fgets($handle, 4096)) !== false) {
                                 if ($UTF8deleteBOM) {
                                     $subject = str_replace("", '', $subject);
                                     $UTF8deleteBOM = false;
                                 }
                                 $transaction = Yii::$app->db->beginTransaction();
                                 $i++;
                                 try {
                                     $pattern = '/^(.*?)\\|(Поликлиника №\\s?[1,2,3] )?(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|/ui';
                                     preg_match($pattern, $subject, $matches);
                                     if ($matches[0] !== NULL) {
                                         $pattern = '/(^Поликлиника №)\\s?([1,2,3])\\s?$/ui';
                                         $matches[2] = preg_replace($pattern, 'Взрослая $1$2', mb_strtolower($matches[2], 'UTF-8'));
                                         if ($matches[3] === 'Поликлиника профилактических осмотров') {
                                             $matches[2] = $matches[3];
                                         }
                                         $pattern = '/^(.+) БУ "Нижневартовская городская поликлиника"$/ui';
                                         $matches[3] = preg_replace($pattern, '$1', $matches[3]);
                                         $employee_fio = $matches[1];
                                         $location = self::AssignLocationForEmployeeImport(trim($matches[3]), trim($matches[2]));
                                         $id_dolzh = self::AssignDolzh(trim($matches[4]));
                                         //            $sqlstr = empty($location->id_build) ? ' and id_build is null' : ' and id_build = :id_build';
                                         $Employee = Employee::find()->joinWith('idperson')->where(array_merge(['id_dolzh' => $id_dolzh, 'id_podraz' => $location->id_podraz], empty($location->id_build) ? [] : ['id_build' => $location->id_build]))->andFilterWhere(['like', 'auth_user_fullname', $employee_fio, false])->one();
                                         /*  $Employee = self::GetRowsPDO('select employee_id, auth_user_fullname, id_dolzh, id_podraz, id_build from employee inner join auth_user on employee.id_person = auth_user.auth_user_id  where auth_user_fullname like :employee_fio and id_dolzh = :id_dolzh and id_podraz = :id_podraz' . $sqlstr, array_merge([
                                             'employee_fio' => $employee_fio,
                                             'id_dolzh' => $id_dolzh,
                                             'id_podraz' => $location->id_podraz,
                                             ], empty($location->id_build) ? [] : ['id_build' => $location->id_build])); */
                                         if (empty($Employee)) {
                                             /*  var_dump('ok');
                                                 var_dump($Employee);
                                                 var_dump($employee_fio);
                                                 var_dump($location);
                                                 var_dump($id_dolzh); */
                                             $AuthuserCount = Authuser::find()->where(['like', 'auth_user_fullname', $employee_fio, false])->count();
                                             $Authuser = $AuthuserCount == 1 ? Authuser::find()->where(['like', 'auth_user_fullname', $employee_fio, false])->one() : false;
                                             $newEmployee = false;
                                             if (empty($Authuser) || $AuthuserCount > 1) {
                                                 $Authuser = new Authuser();
                                                 $Authuser->auth_user_fullname = $employee_fio;
                                                 $Authuser->auth_user_login = Proc::CreateLogin($employee_fio);
                                                 $Authuser->auth_user_password = Yii::$app->getSecurity()->generatePasswordHash('11111111');
                                                 $newEmployee = true;
                                             }
                                             $Employee = new Employee();
                                             $Employee->attributes = ['id_dolzh' => $id_dolzh, 'id_podraz' => $location->id_podraz, 'id_build' => $location->id_build, 'employee_forinactive' => 1];
                                             $Employeelog = new Employeelog();
                                             $Employeelog->id_logreport = self::$logreport_id;
                                             $Employeelog->employeelog_type = 1;
                                             $Employeelog->employeelog_filename = self::$filename;
                                             $Employeelog->employeelog_filelastdate = self::$filelastdate;
                                             $Employeelog->employeelog_rownum = $i;
                                             $Employeelog->employeelog_message = 'Запись добавлена.';
                                             if (isset($Employee->scenarios()['import1c'])) {
                                                 $Employee->scenario = 'import1c';
                                             }
                                             if (isset($Authuser->scenarios()['import1c'])) {
                                                 $Authuser->scenario = 'import1c';
                                             }
                                             if ($Authuser->validate()) {
                                                 $Authuser->save(false);
                                                 $Profile = Profile::findOne($Authuser->primaryKey);
                                                 $Profile = empty($Profile) ? new Profile() : $Profile;
                                                 $Profile->profile_id = $Authuser->primaryKey;
                                                 $Profile->profile_dr = $matches[16];
                                                 $Profile->profile_pol = $matches[15];
                                                 $Profile->profile_inn = $matches[11];
                                                 $Profile->profile_snils = $matches[12];
                                                 $Profile->profile_address = $matches[10];
                                                 $Profile->save();
                                                 if ($Profile->getErrors()) {
                                                     var_dump($Profile->getErrors());
                                                 }
                                                 $Employeelog->employeelog_message = $Profile->getErrors() ? 'Запись добавлена. Ошибка при создании профиля' : 'Запись добавлена.';
                                                 $Employee->id_person = $Authuser->getPrimaryKey();
                                                 if ($Employee->validate()) {
                                                     $newEmployee ? self::$logreport_additions++ : self::$logreport_updates++;
                                                     $Employee->save(false);
                                                     if ($newEmployee && !self::$Debug) {
                                                         self::Mishanya($Authuser, $Employee, $matches);
                                                     }
                                                 } else {
                                                     $Employeelog->employeelog_type = 3;
                                                     $Employeelog->employeelog_message = 'Ошибка при добавлении записи: ';
                                                     foreach ($Employee->getErrors() as $fields) {
                                                         $Employeelog->employeelog_message .= implode(' ', $fields) . ' ';
                                                     }
                                                     self::$logreport_errors++;
                                                 }
                                             } else {
                                                 $Employeelog->employeelog_type = 3;
                                                 $Employeelog->employeelog_message = 'Ошибка при добавлении записи: ';
                                                 foreach ($Authuser->getErrors() as $fields) {
                                                     $Employeelog->employeelog_message .= implode(' ', $fields) . ' ';
                                                 }
                                                 self::$logreport_errors++;
                                             }
                                             $Employeelog->employee_fio = $Authuser->auth_user_fullname;
                                             $Employeelog->dolzh_name = Dolzh::findOne($Employee->id_dolzh)->dolzh_name;
                                             //self::GetNameByID('dolzh', 'dolzh_name', $Employee->id_dolzh);
                                             $Employeelog->podraz_name = Podraz::findOne($Employee->id_podraz)->podraz_name;
                                             //self::GetNameByID('podraz', 'podraz_name', $Employee->id_podraz);
                                             if (!empty($Employee->id_build)) {
                                                 $Employeelog->build_name = Build::findOne($Employee->id_build)->build_name;
                                             }
                                             //self::GetNameByID('build', 'build_name', $Employee->id_build);
                                             $Employeelog->save(false);
                                         } else {
                                             if ($Employee->employee_importdo === 1) {
                                                 if (isset($Employee->scenarios()['import1c'])) {
                                                     $Employee->scenario = 'import1c';
                                                 }
                                                 $inactivePerson = Employee::find()->andWhere(['id_person' => $Employee->id_person, 'employee_dateinactive' => NULL])->count();
                                                 if (empty($inactivePerson)) {
                                                     $Employee = Employee::find(['id_person' => $Employee->id_person])->andWhere(['id_person' => $Employee->id_person])->orderBy(['employee_id' => SORT_DESC])->one();
                                                     $Employeelog = new Employeelog();
                                                     $Employeelog->id_logreport = self::$logreport_id;
                                                     $Employeelog->employeelog_type = 2;
                                                     $Employeelog->employeelog_filename = self::$filename;
                                                     $Employeelog->employeelog_filelastdate = self::$filelastdate;
                                                     $Employeelog->employeelog_rownum = $i;
                                                     $Employeelog->employeelog_message = 'Запись изменена. Очищена дата неактивности специальности "' . Yii::$app->formatter->asDate($Employee->employee_dateinactive) . '"';
                                                     $Employeelog->employee_fio = Authuser::findOne($Employee->id_person)->auth_user_fullname;
                                                     $Employeelog->dolzh_name = Dolzh::findOne($Employee->id_dolzh)->dolzh_name;
                                                     $Employeelog->podraz_name = Podraz::findOne($Employee->id_podraz)->podraz_name;
                                                     if (!empty($Employee->id_build)) {
                                                         $Employeelog->build_name = Build::findOne($Employee->id_build)->build_name;
                                                     }
                                                     $Employeelog->save(false);
                                                     $Employee->employee_dateinactive = null;
                                                     self::$logreport_updates++;
                                                 }
                                                 $Employee->employee_forinactive = 1;
                                                 $Employee->save(false);
                                             }
                                         }
                                     } elseif (trim($subject) !== '') {
                                         $Employeelog = new Employeelog();
                                         $Employeelog->id_logreport = self::$logreport_id;
                                         $Employeelog->employeelog_type = 3;
                                         $Employeelog->employeelog_filename = self::$filename;
                                         $Employeelog->employeelog_filelastdate = self::$filelastdate;
                                         $Employeelog->employeelog_rownum = $i;
                                         $Employeelog->employeelog_message = 'Ошибка при добавлении записи: Не пройдено регулярное выражение /^(.*?)\\|(Поликлиника №\\s?[1,2,3] )?(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|(.*?)\\|/ui';
                                         $Employeelog->save(false);
                                         self::$logreport_errors++;
                                     }
                                     $transaction->commit();
                                 } catch (Exception $e) {
                                     $transaction->rollBack();
                                     throw new Exception($e->getMessage() . ' $i = ' . $i . '; $filename = ' . self::$filename);
                                 }
                             }
                             fclose($handle);
                             if (!self::$Debug) {
                                 self::InactiveEmployee();
                             }
                         }
                         $logreport->logreport_amount += $i;
                         $logreport->logreport_employeelastdate = self::$filelastdate;
                         self::$employee = false;
                     } else {
                         if (self::IsFileType(self::mat) || self::IsFileType(self::gu)) {
                             Mattraffic::updateAll(['mattraffic_forimport' => NULL], ['mattraffic_forimport' => 1]);
                         }
                         $startRow = self::IsFileType(self::os) ? self::$os_start : (self::IsFileType(self::mat) ? self::$mat_start : self::$gu_start);
                         //начинаем читать с определенной строки
                         $exit = false;
                         //флаг выхода
                         $empty_value = 0;
                         //счетчик пустых знаений
                         // Загружаем данные из файла Excel
                         //        $inputFileType = 'Excel5';
                         //       $inputFileName = self::$filename;
                         $chunkSize = 1000;
                         //размер считываемых строк за раз
                         //
                         $objReader = \PHPExcel_IOFactory::createReaderForFile(self::$filename);
                         //     $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
                         $chunkFilter = new chunkReadFilter();
                         $objReader->setReadFilter($chunkFilter);
                         $objReader->setReadDataOnly(true);
                         while (!$exit) {
                             // Инициализируем переменные
                             //  $row = $sheetData[self::$rownum_xls];
                             $chunkFilter->setRows($startRow, $chunkSize);
                             //устанавливаем знаечние фильтра
                             $objPHPExcel = $objReader->load(self::$filename);
                             //открываем файл
                             $objPHPExcel->setActiveSheetIndex(0);
                             //устанавливаем индекс активной страницы
                             $objWorksheet = $objPHPExcel->getActiveSheet();
                             //делаем активной нужную страницу
                             // Идем по данных excel
                             for ($i = $startRow; $i < $startRow + $chunkSize; $i++) {
                                 //внутренний цикл по строкам
                                 self::$rownum_xls = $i;
                                 $value = trim(htmlspecialchars($objWorksheet->getCellByColumnAndRow(0, $i)->getValue()));
                                 //получаем первое знаение в строке
                                 if (empty($value)) {
                                     //проверяем значение на пустоту
                                     $empty_value++;
                                 }
                                 if ($empty_value == 1) {
                                     //после трех пустых значений, завершаем обработку файла, думая, что это конец
                                     $exit = true;
                                     break;
                                 }
                                 /* Манипуляции с данными каким Вам угодно способом, в PHPExcel их превеликое множество */
                                 $row = $objWorksheet->rangeToArray('A' . $i . ':M' . $i, null, true, true, true);
                                 $row = $row[key($row)];
                                 $material = new Material();
                                 $authuser = new Authuser();
                                 $employee = new Employee();
                                 $mattraffic = new Mattraffic();
                                 $matlog = new Matlog();
                                 $employeelog = new Employeelog();
                                 $traflog = new Traflog();
                                 $MaterialDo = false;
                                 $EmployeeDo = false;
                                 $MattrafficDo = false;
                                 // Начинаем транзакцию
                                 $transaction = Yii::$app->db->beginTransaction();
                                 try {
                                     // Применяем значения атрубутов Материальной ценности
                                     $MaterialDo = self::MaterialDo($material, $matlog, $row);
                                     if ($MaterialDo) {
                                         // Применяем значения атрубутов Сотрудника
                                         $EmployeeDo = self::EmployeeDo($employee, $employeelog, $row);
                                         if ($EmployeeDo) {
                                             // Применяем значения атрубутов "Операции над материальной ценностью"
                                             $MattrafficDo = self::MattrafficDo($mattraffic, $traflog, $row, $material, $employee->employee_id);
                                         }
                                     }
                                     // $matlog->matlog_type !== 5 - Если Запись не изменилась не пишем в лог
                                     if ($matlog->matlog_type !== 5 && ($MaterialDo || count($material->getErrors()) > 0)) {
                                         $matlog->save(false);
                                         if ($matlog->matlog_type === 2) {
                                             $material->save(false);
                                         }
                                     }
                                     if ($MaterialDo) {
                                         // $employeelog->employeelog_type !== 5 - Если Запись не изменилась не пишем в лог
                                         if ($employeelog->employeelog_type !== 5 && ($EmployeeDo || count($employee->getErrors()) > 0)) {
                                             $employeelog->save(false);
                                         }
                                         if ($EmployeeDo) {
                                             if ($MattrafficDo || count($mattraffic->getErrors()) > 0) {
                                                 if ($matlog->IsNewRecord) {
                                                     $matlog->material_number = $material->material_number;
                                                     // Иначе пишется предыдущее значение количества материальной ценности
                                                     $matlog->save(false);
                                                 }
                                                 if ($employeelog->IsNewRecord) {
                                                     $employeelog->save(false);
                                                 }
                                                 $traflog->id_matlog = $matlog->matlog_id;
                                                 $traflog->id_employeelog = $employeelog->employeelog_id;
                                                 if ($traflog->validate()) {
                                                     $traflog->save(false);
                                                 }
                                             }
                                             if ($MattrafficDo) {
                                                 $material->save(false);
                                                 $employee->save(false);
                                                 $mattraffic->id_material = $material->material_id;
                                                 $mattraffic->id_mol = $employee->employee_id;
                                                 $mattraffic->save(false);
                                                 // Применяем значения атрубутов, если материальная ценность списна
                                                 self::WriteOffDo($material, $matlog, $mattraffic, $traflog, $row);
                                             }
                                         }
                                     }
                                     //    if ($transaction->isActive)
                                     $transaction->commit();
                                 } catch (Exception $e) {
                                     $transaction->rollBack();
                                     throw new Exception($e->getMessage() . ' $rownum_xls = ' . self::$rownum_xls . '; $filename = ' . self::$filename);
                                 }
                             }
                             $objPHPExcel->disconnectWorksheets();
                             //чистим
                             unset($objPHPExcel);
                             //память
                             unset($material);
                             unset($employee);
                             unset($mattraffic);
                             unset($matlog);
                             unset($employeelog);
                             unset($traflog);
                             unset($objWorksheet);
                             echo '<BR>Память использована с ' . $startRow . ' по ' . ($startRow + $chunkSize) . ' : ' . Yii::$app->formatter->asShortSize(memory_get_usage(true));
                             $startRow += $chunkSize;
                             //переходим на следующий шаг цикла, увеличивая строку, с которой будем читать файл
                         }
                         $logreport->logreport_amount += self::$rownum_xls - (self::IsFileType(self::os) ? self::$os_start : (self::IsFileType(self::mat) ? self::$mat_start : self::$gu_start));
                         if (self::IsFileType(self::os)) {
                             $logreport->logreport_oslastdate = self::$filelastdate;
                         } elseif (self::IsFileType(self::mat)) {
                             $logreport->logreport_matlastdate = self::$filelastdate;
                         } else {
                             $logreport->logreport_gulastdate = self::$filelastdate;
                         }
                         if (self::IsFileType(self::mat) || self::IsFileType(self::gu)) {
                             self::MaterialSpisanie();
                         }
                     }
                     $logreport->logreport_additions += self::$logreport_additions;
                     $logreport->logreport_updates += self::$logreport_updates;
                     $logreport->logreport_errors += self::$logreport_errors;
                     $logreport->logreport_missed += self::$logreport_missed;
                     $logreport->save();
                 } else {
                     if (self::IsFileType(self::os)) {
                         $logreport->logreport_oslastdate = self::$filelastdate;
                     } elseif (self::IsFileType(self::mat)) {
                         $logreport->logreport_matlastdate = self::$filelastdate;
                     } else {
                         $logreport->logreport_gulastdate = self::$filelastdate;
                     }
                     if ($filename === $Importconfig['emp_filename'] . '.txt') {
                         $logreport->logreport_employeelastdate = self::$filelastdate;
                     }
                 }
             }
         }
         if ($doreport) {
             self::MakeReport();
             $endtime = microtime(true);
             $logreport->logreport_executetime = gmdate('H:i:s', $endtime - $starttime);
             $logreport->logreport_memoryused = memory_get_usage(true);
             $logreport->save();
         }
         $endtime = microtime(true);
         echo 'ImportDo success<BR>';
         echo 'Использовано памяти: ' . Yii::$app->formatter->asShortSize(memory_get_usage(true)) . '; Время выполнения: ' . gmdate('H:i:s', $endtime - $starttime);
     } else {
         echo 'Импорт отключен';
     }
 }
示例#12
0
 public static function CanIsDelete($Mattraffic_id)
 {
     $status = '';
     if (!empty($Mattraffic_id)) {
         $Mattraffic = Mattraffic::findOne($Mattraffic_id);
         if (!empty($Mattraffic)) {
             $First = self::find()->andWhere(['id_material' => $Mattraffic->id_material, 'id_mol' => $Mattraffic->id_mol])->andWhere('mattraffic_id IN (SELECT mattraffic_id FROM mattraffic WHERE id_material = ' . $Mattraffic->id_material . ' GROUP BY id_material HAVING min(mattraffic_date))')->count('mattraffic_id');
             if (empty($First)) {
                 $CountForDelete = self::find()->andWhere(['id_material' => $Mattraffic->id_material, 'id_mol' => $Mattraffic->id_mol])->andWhere('NOT EXISTS (SELECT mt.mattraffic_id FROM mattraffic mt WHERE mt.id_material = ' . $Mattraffic->id_material . ' AND mt.id_mol = ' . $Mattraffic->id_mol . ' AND mt.mattraffic_tip IN (3,4) AND mt.mattraffic_date >= mattraffic.mattraffic_date)')->andWhere('mattraffic_date <= \'' . $Mattraffic->mattraffic_date . '\'')->count('mattraffic_id');
                 if (empty($CountForDelete)) {
                     $status = 'Данную запись удалить нельзя, т.к. она используется при перемещении материальной ценности.';
                 }
             } else {
                 $status = 'Материально-ответственное лицо, назначенное материалу первым, удалить нельзя.';
             }
         }
     }
     return $status;
 }
示例#13
0
 public function getCurrentMattraffic()
 {
     return $this->hasOne(Mattraffic::className(), ['id_material' => 'material_id'])->from(['currentmattraffic' => Mattraffic::tableName()])->leftJoin('mattraffic mt1', 'currentmattraffic.id_material = mt1.id_material and `currentmattraffic`.`mattraffic_tip` IN (1, 2) and mt1.mattraffic_tip IN (1, 2) and (currentmattraffic.mattraffic_date < mt1.mattraffic_date or currentmattraffic.mattraffic_date = mt1.mattraffic_date  and currentmattraffic.mattraffic_id < mt1.mattraffic_id)')->andWhere(['in', 'currentmattraffic.mattraffic_tip', [1, 2]])->andWhere(['mt1.mattraffic_date' => NULL]);
 }
示例#14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMattraffics()
 {
     return $this->hasMany(Mattraffic::className(), ['id_mol' => 'employee_id'])->from(['mattraffics' => Mattraffic::tableName()]);
 }
示例#15
0
 public function actionMaxNumberMaterialByMol()
 {
     if (Yii::$app->request->isAjax) {
         $mattraffic_id = Yii::$app->request->post('mattraffic_id');
         if (!empty($mattraffic_id)) {
             $query = Mattraffic::findOne($mattraffic_id);
             if (!empty($query)) {
                 echo json_encode(['mattraffic_number' => $query->mattraffic_number]);
             }
         }
     }
 }