Beispiel #1
0
 /**
  * Creating new data record for Communal module
  *
  * @param $counter
  * @return string|yii\web\Response
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  */
 public function actionAddRecord($counter)
 {
     /** @var LinkCounter $linkModel */
     $linkModel = LinkCounter::findOne(['counter_id' => $counter]);
     if (!is_null($linkModel)) {
         /** @var Estate $estate */
         $estate = $this->findEstate($linkModel->getEstateId());
         $comServiceId = $linkModel->getComServiceId();
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'ERROR_WRONG_ID'));
     }
     $model = new AddRecordForm();
     $model->setCounterId($counter);
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         /** @var Record $record */
         $record = new Record();
         $record->setCounterId($model->getCounterId());
         $record->setComServiceId($comServiceId);
         $record->setData($model->getData());
         $record->setStatus(Record::STATUS_NEW);
         if ($record->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'FLASH_RECORD_SUCCESS'));
             return $this->redirect(['/communal/manage/' . $estate->id]);
         } else {
             Yii::$app->session->setFlash('error', Yii::t('app', 'FLASH_RECORD_FAILED'));
             return $this->redirect(['/communal/manage/' . $estate->id]);
         }
     } else {
         return $this->render('record', ['model' => $model, 'estate' => $estate, 'link' => $linkModel]);
     }
 }
Beispiel #2
0
 /**
  * Update the current Communal's model
  *
  * @param int $id
  * @return string|\yii\web\Response
  * @throws ForbiddenHttpException
  * @throws NotFoundHttpException
  */
 public function actionUpdate($id)
 {
     /** @var Estate $estate */
     $estate = $this->findEstate($id);
     if (!LinkCounter::initialized($estate->id)) {
         $this->initializeEstate($estate->id);
     }
     $links = LinkCounter::getLinksByEstateId($estate->id);
     $model = new CounterList();
     foreach ($links as $link) {
         array_push($model->counters, $link);
         // Full array with counter list from Estate
     }
     if ($post = Yii::$app->request->post()) {
         foreach ($post["Counters"] as $key => $item) {
             foreach ($model->counters as $counter) {
                 if ($counter->id == $key) {
                     /** @var LinkCounter $linkModify */
                     $linkModify = LinkCounter::findOne($key);
                     $linkModify->setAccount((int) $item);
                     $linkModify->save();
                     Yii::$app->session->setFlash('success', Yii::t('app', 'FLASH_COMMUNAL_ACCOUNT_UPDATED'));
                 }
             }
         }
         return $this->redirect(['view', 'id' => $estate->id]);
     } else {
         return $this->render('update', ['model' => $model, 'estate' => $estate]);
     }
 }
Beispiel #3
0
 /**
  * Returns Account number
  *
  * @return int
  */
 public function getAccountNumber()
 {
     /** @var LinkCounter $model */
     $model = LinkCounter::findOne(['counter_id' => $this->counter_id]);
     return $model->getAccountCode();
 }