/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $model = $this->loadModel($id); if (null == InvoicesFkt::model()->findByAttributes(array('template_id' => (int) $id))) { if ($model->delete()) { $msg = 'Шаблон счета-фактуры #' . $model->id . ' - ' . $model->name . ' удалён'; Yii::app()->user->setFlash('success', $msg); Yii::app()->logger->write($msg); } } else { Yii::app()->user->setFlash('notice', 'Удаление невозможно. Шаблон счета-фактуры #' . $model->id . ' - ' . $model->name . ' используется!'); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'admin' page. * @param integer $id the ID of the model to be deleted */ public function actionDelete($id) { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request $model = $this->loadModel($id); if (Payments::model()->count('order_id=' . $id) !== 0) { $transaction = Yii::app()->db->beginTransaction(); try { Contracts::model()->deleteAll('order_id=' . $id); Acts::model()->deleteAll('order_id=' . $id); Invoices::model()->deleteAll('order_id=' . $id); InvoicesFkt::model()->deleteAll('order_id=' . $id); Works::model()->deleteAll('order_id=' . $id); $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' и документы по нему удалёны'; $model->delete(); $transaction->commit(); Yii::app()->user->setFlash('success', $msg); Yii::app()->logger->write($msg); } catch (Exception $e) { $transaction->rollBack(); $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' - удаление не удалось'; Yii::app()->user->setFlash('error', $msg); Yii::app()->logger->write($msg); } } else { $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' - удаление невозможно. По этому заказу уже были проведены платежи'; Yii::app()->user->setFlash('notice', $msg); Yii::app()->logger->write($msg); } // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser if (!isset($_GET['ajax'])) { $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin')); } } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = InvoicesFkt::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }