/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Schetuchet::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['schetuchet_id' => $this->schetuchet_id]); $query->andFilterWhere(['like', 'schetuchet_kod', $this->schetuchet_kod])->andFilterWhere(['like', 'schetuchet_name', $this->schetuchet_name]); return $dataProvider; }
/** * @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(); }
/** * @return \yii\db\ActiveQuery */ public function getIdSchetuchet() { return $this->hasOne(Schetuchet::className(), ['schetuchet_id' => 'id_schetuchet'])->from(['idSchetuchet' => Schetuchet::tableName()]); }
/** * Finds the Schetuchet model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Schetuchet the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Schetuchet::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
private static function MaterialSpisanie() { $transaction = Yii::$app->db->beginTransaction(); try { $Typemat = self::IsFileType(self::mat) ? 2 : 3; $SP = Mattraffic::find()->from(['m1' => 'mattraffic'])->join('LEFT JOIN', 'material', 'm1.id_material = material.material_id')->join('LEFT JOIN', 'mattraffic m2', 'm1.id_material = m2.id_material and m1.id_mol = m2.id_mol and m1.mattraffic_date < m2.mattraffic_date and m1.mattraffic_tip in (1,2) and m2.mattraffic_tip in (1,2)')->andWhere(['m1.mattraffic_forimport' => NULL, 'material_writeoff' => 0])->andWhere(['in', 'material_tip', [$Typemat]])->andWhere(['in', 'm1.mattraffic_tip', [1, 2]])->andWhere(['m1.mattraffic_tip' => 1])->andWhere(['m2.mattraffic_date' => NULL])->all(); if (!empty($SP)) { foreach ($SP as $i => $ar) { $spismat = self::SpisatMaterial($ar->id_material, $ar->id_mol); $Mattraffic = new Mattraffic(); $Mattraffic->attributes = $ar->attributes; $Mattraffic->mattraffic_date = date('Y-m-d'); $Mattraffic->mattraffic_number = 0; $Mattraffic->mattraffic_tip = 2; // Списание if (isset($Mattraffic->scenarios()['import1c'])) { $Mattraffic->scenario = 'import1c'; } $Mattraffic->save(false); $writeoffakt = new Writeoffakt(); $writeoffakt->id_mattraffic = $Mattraffic->mattraffic_id; $writeoffakt->save(false); $Material = Material::findOne($ar->id_material); $Matlog = new Matlog(); $Matlog->attributes = $Material->attributes; $Matlog->id_logreport = self::$logreport_id; $Matlog->matlog_filename = self::$filename; $Matlog->matlog_filelastdate = self::$filelastdate; $Matlog->matlog_rownum = 0; $Matlog->matlog_type = $spismat ? 4 : 2; $Matlog->matlog_message = $spismat ? 'Материал списан. ' : 'Запись не изменялась. '; $Matlog->matvid_name = self::GetNameByID('matvid', 'matvid_name', $Material->id_matvid); $Matlog->izmer_name = self::GetNameByID('izmer', 'izmer_name', $Material->id_izmer); $Matlog->schetuchet_kod = Schetuchet::findOne($Material->id_schetuchet)->schetuchet_kod; $Matlog->schetuchet_name = Schetuchet::findOne($Material->id_schetuchet)->schetuchet_name; $Matlog->material_writeoff = $Material->material_writeoff === 1 ? 'Да' : 'Нет'; $Matlog->material_release = isset($Material->material_release) ? Yii::$app->formatter->asDate($Material->material_release) : $Material->material_release; $Matlog->save(false); $Employee = Employee::find()->joinWith(['idperson', 'iddolzh', 'idpodraz', 'idbuild'])->where(['employee_id' => $ar->id_mol])->one(); $Employeelog = new Employeelog(); $Employeelog->attributes = $Employee->attributes; $Employeelog->id_logreport = self::$logreport_id; $Employeelog->employeelog_filename = self::$filename; $Employeelog->employeelog_filelastdate = self::$filelastdate; $Employeelog->employeelog_rownum = 0; $Employeelog->employeelog_type = 2; $Employeelog->employeelog_message = 'Запись не изменилась'; $Employeelog->employee_fio = $Employee->idperson->auth_user_fullname; $Employeelog->dolzh_name = $Employee->iddolzh->dolzh_name; $Employeelog->podraz_name = $Employee->idpodraz->podraz_name; $Employeelog->build_name = $Employee->isRelationPopulated('idbuild') ? $Employee->idbuild['build_name'] : ''; $Employeelog->save(false); $Traflog = new Traflog(); $Traflog->id_logreport = self::$logreport_id; $Traflog->traflog_type = 1; $Traflog->traflog_filename = self::$filename; $Traflog->traflog_rownum = 0; $Traflog->traflog_message = ''; $Traflog->id_matlog = $Matlog->primaryKey; $Traflog->id_employeelog = $Employeelog->primaryKey; $Traflog->traflog_message = 'Запись добавлена. Добавлен акт списания с номером "' . $writeoffakt->writeoffakt_id . '" на дату "' . date('d.m.Y', strtotime($Mattraffic->mattraffic_date)) . '".'; $Traflog->mattraffic_number = $ar->mattraffic_number; $Traflog->save(false); self::$logreport_additions++; } } Mattraffic::updateAll(['mattraffic_forimport' => NULL], ['mattraffic_forimport' => 1]); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); Mattraffic::updateAll(['mattraffic_forimport' => NULL], ['mattraffic_forimport' => 1]); throw new Exception($e->getMessage() . ' MaterialSpisanie(), $filename = ' . self::$filename); } }