Пример #1
0
 public function MaxNumberSpis($attribute)
 {
     if (!empty($this->id_mattraffic)) {
         $currentMattraffic = Mattraffic::findOne($this->id_mattraffic);
         $query = Mattraffic::find()->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(['id_material' => $currentMattraffic->id_material, 'id_mol' => $currentMattraffic->id_mol])->andWhere(['in', 'mattraffic_tip', [1, 2]])->andWhere(['m2.mattraffic_date_m2' => NULL])->one();
         if (!empty($query) && $this->spisosnovmaterials_number > $query->mattraffic_number) {
             $this->addError($attribute, 'Количество не может превышать ' . $query->mattraffic_number);
         }
     }
 }
Пример #2
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;
     }
 }
Пример #3
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());
         }
     }
 }
Пример #4
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]);
             }
         }
     }
 }
Пример #5
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;
 }
Пример #6
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]);
             }
         }
     }
 }