Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $acts_id = 0)
 {
     $query = ActsTable::find()->where(['acts_id' => $acts_id]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'acts_id' => $this->acts_id, 'date_doc' => $this->date_doc, 'beg_sald' => $this->beg_sald, 'end_sald' => $this->end_sald]);
     $query->andFilterWhere(['like', 'act_num', $this->act_num])->andFilterWhere(['like', 'num_doc', $this->num_doc])->andFilterWhere(['like', 'name_doc', $this->name_doc])->andFilterWhere(['like', 'cod_good', $this->cod_good])->andFilterWhere(['like', 'actstable_comm', $this->actstable_comm]);
     return $dataProvider;
 }
Пример #2
0
 public function readreestr()
 {
     $filename = 'ActdocFile/reestr.txt';
     $readfile = fopen($filename, 'r');
     while ($str = fgets($readfile)) {
         //echo $str . '<br>';
         $items = explode(';', $str);
         $type_act = $items[0];
         if ($type_act == 'V') {
             //Определяем суммы сальдо заранее
             $beg_sald = $items[9];
             $beg_sald = str_replace(",", '.', $beg_sald);
             $beg_sald = preg_replace("/[^x\\d|*\\.]/", "", $beg_sald);
             $end_sald = $items[10];
             $end_sald = str_replace(",", '.', $end_sald);
             $end_sald = preg_replace("/[^x\\d|*\\.]/", "", $end_sald);
             $beg_sald = (int) ($beg_sald * 100);
             $end_sald = (int) ($end_sald * 100);
             $num_doc = $items[6];
             $num_act = $items[1];
             if (!empty($num_doc)) {
                 $date_doc = $items[5];
                 $name_doc = $items[7];
                 $cod_good = $items[8];
                 $actstabfind = ActsTable::find()->andFilterWhere(['num_doc' => $num_doc])->andFilterWhere(['date_doc' => date('Y-m-d', strtotime($date_doc))])->one();
                 if (isset($actstabfind)) {
                     $actstable = $this->findModel($actstabfind->id);
                     $actstable->beg_sald = $beg_sald;
                     $actstable->end_sald = $end_sald;
                     $actstable->save();
                 } else {
                     $actfind = ActsDoc::find()->andFilterWhere(['num_act' => $num_act])->one();
                     if (isset($actfind)) {
                         //echo $actfind->id_doc;
                         $actstable = new ActsTable();
                         $actstable->acts_id = $actfind->id_doc;
                         $actstable->act_num = $num_act;
                         $actstable->date_doc = date('Y-m-d', strtotime($date_doc));
                         //$date_doc;
                         $actstable->num_doc = $num_doc;
                         $actstable->name_doc = $name_doc;
                         $actstable->cod_good = $cod_good;
                         $actstable->beg_sald = $beg_sald;
                         $actstable->end_sald = $end_sald;
                         $actstable->save();
                     }
                 }
             } else {
                 ////var_dump($beg_sald,$end_sald);
                 //echo '<br>';
                 //continue;
                 //Находим сответствие в базе
                 $actfind = ActsDoc::find()->andFilterWhere(['num_act' => $num_act])->one();
                 if (isset($actfind)) {
                     //Если нашли то устанавливаем сальдо
                     $actsdoc = $this->findModel($actfind->id_doc);
                     if ($beg_sald > 0) {
                         $actsdoc->beg_sald = $beg_sald;
                     }
                     if ($end_sald > 0) {
                         $actsdoc->end_sald = $end_sald;
                     }
                     $actsdoc->save();
                 } else {
                     //Если не находим то создаем новый элемент
                     $begdate = $items[2];
                     $enddate = $items[3];
                     $contr_doc = $items[4];
                     //$beg_sald = $items[9];
                     //$end_sald = $items[10];
                     $actsdoc = new ActsDoc();
                     $actsdoc->type_act = 0;
                     $actsdoc->num_act = $num_act;
                     $actsdoc->begdate = date('Y-m-d', strtotime($begdate));
                     $actsdoc->enddate = date('Y-m-d', strtotime($enddate));
                     $actsdoc->contr_doc = $contr_doc;
                     $actsdoc->user_id = Yii::$app->user->id;
                     if ($beg_sald > 0) {
                         $actsdoc->beg_sald = $beg_sald;
                     }
                     if ($end_sald > 0) {
                         $actsdoc->end_sald = $end_sald;
                     }
                     $actsdoc->save();
                 }
             }
         }
     }
 }