/** * Delete current Estate and related records (LinkCounters, Counters, Records) * * @param int $id * @return \yii\web\Response * @throws ForbiddenHttpException * @throws NotFoundHttpException * @throws \Exception */ public function actionDelete($id) { $model = $this->findEstate($id); $linkCounters = LinkCounter::findAll(['estate_id' => $model->id]); foreach ($linkCounters as $linkCounter) { /** @var Counter $counter */ $counter = Counter::findOne($linkCounter->getCounterId()); Record::deleteAll(['counter_id' => $counter->id]); $counter->delete(); $linkCounter->delete(); } $model->delete(); Yii::$app->session->setFlash('success', Yii::t('app', 'FLASH_ESTATE_DELETED')); return $this->redirect(['index']); }
echo Html::submitButton(Yii::t('app', 'RECORD_SUBMIT'), ['class' => 'btn btn-primary', 'name' => 'signup-button', 'style' => 'width: 200px']); ?> <?php echo Html::a(Yii::t('app', 'RECORD_CANCEL'), ['/communal/manage/' . $estate->id], ['class' => 'btn btn-default']); ?> </div> <?php echo $form->field($model, 'counterId')->hiddenInput()->label(false); ?> <?php ActiveForm::end(); ?> <?php /** @var \common\modules\communal\models\Record $lastRecord */ $lastRecord = \common\modules\communal\models\Record::getLastRecordByCounterId($link->getCounterId()); ?> <table class="table table-striped detail-view"> <tbody> <tr> <td><b><?php echo Yii::t('app', 'RECORD_COMSERVICE_TITLE'); ?> </b></td> <td><?php echo $link->getComService()->title; ?> </td> </tr> <tr>
/** * Generate record list for Communal Service manager * * @return string * @throws ForbiddenHttpException */ public function actionGetRecords() { $currentUserId = Yii::$app->user->id; $comService = LinkManager::findByUserId($currentUserId); if (LinkManager::isAccessible($currentUserId)) { if ($post = Yii::$app->request->post()) { if (isset($post["get-list"]) && isset($post["get-format"])) { if ($post["get-list"] == 'month') { $model = Record::find()->where(['comservice_id' => $comService->id])->andWhere(['>=', 'created_at', time() - 2678400])->all(); } elseif ($post["get-list"] == 'interval' && isset($post["from_date"]) && isset($post["to_date"])) { $from_date = strtotime($post["from_date"]); $to_date = strtotime($post["to_date"]); $model = Record::find()->where(['comservice_id' => $comService->id])->andWhere(['>=', 'created_at', $from_date])->andWhere(['<=', 'created_at', $to_date])->all(); } else { $model = Record::find()->where(['comservice_id' => $comService->id])->andWhere(['status' => Record::STATUS_NEW])->all(); } return $this->renderPartial('get-records-list', ['model' => $model, 'format' => $post["get-format"]]); } } return $this->render('get-records', ['comService' => $comService]); } else { throw new ForbiddenHttpException(Yii::t('app', 'ERROR_FORBIDDEN')); } }