Пример #1
0
 /**
  * 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 == Contracts::model()->findByAttributes(array('template_id' => (int) $id))) {
             if ($model->delete()) {
                 $msg = 'Шаблон договора ' . $model->name . ' удалён';
                 Yii::app()->user->setFlash('success', $msg);
                 Yii::app()->logger->write($msg);
                 //				$this->redirect(array('admin', 'id' => $model->id));
             }
         } else {
             Yii::app()->user->setFlash('notice', 'Удаление невозможно. Шаблон договора ' . $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.');
     }
 }
Пример #2
0
 /**
  *
  * @param <type> $contract_id
  */
 public function actionHtml()
 {
     if (!isset($_GET['contract_id']) or !is_numeric($_GET['contract_id'])) {
         $msg = 'Неверный ID договора';
         Yii::app()->user->setFlash('error', $msg);
         Yii::app()->logger->write($msg);
     } else {
         $model = Contracts::model()->findByPk($_GET['contract_id']);
         $this->layout = false;
         //contract/template_pdf';
         $this->render('html', array('model' => $model));
     }
 }
Пример #3
0
 /**
  * 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.');
     }
 }
Пример #4
0
	<div class="row">
		<?php 
echo $form->labelEx($model, 'sum');
?>
		<?php 
echo $form->textField($model, 'sum');
?>

	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'autoprolonged');
?>
		<?php 
echo $form->dropDownList($model, 'autoprolonged', Contracts::model()->itemAlias('autoprolonged'));
?>

	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'template_id');
?>
		<?php 
echo $form->dropDownList($model, 'template_id', CHtml::listData(ContractsTmpl::model()->findAll(), 'id', 'name'));
?>

	</div>

	<div class="row">
Пример #5
0
 private function _prepare_body($mdl = null)
 {
     $return_msg = '';
     if (is_null($mdl)) {
         if (!isset($_POST['act_id']) and !isset($_POST['order_id']) and empty($_POST['works']) and !isset($_POST['client_id']) and !isset($_POST['template_id']) and !isset($_POST['date']) and !isset($_POST['sum']) and !isset($_POST['num'])) {
             die("Необходимых данных недостаточно </br>");
         }
         $date = $_POST['date'];
         $sum = $_POST['sum'];
         $num = (int) $_POST['num'];
         $act_id = (int) $_POST['act_id'];
         $order_id = (int) $_POST['order_id'];
         $works = $_POST['works'];
         $client_id = (int) $_POST['client_id'];
         $template_id = (int) $_POST['template_id'];
     } else {
         $date = $mdl->date;
         $sum = $mdl->sum;
         $num = $mdl->num;
         $act_id = $mdl->id;
         $order_id = $mdl->order_id;
         $works = false;
         $client_id = $mdl->client_id;
         $template_id = $mdl->template_id;
     }
     $data['act']['date'] = $date;
     $data['act']['sum'] = $sum;
     $data['act']['num'] = $num;
     if (!is_array($order_pos = Works::model()->worksByOrder($order_id, $act_id, $works))) {
         $return_msg .= "Невозможно получить список работ </br>";
     }
     $data['works'] = $order_pos;
     //			parse_str($_POST['works']);
     //			Dumper::d($Works);die;
     $data['contract'] = Contracts::model()->findByPk($order_id, array('select' => 'date, num'));
     //			if (is_null($data['contract'] = Contracts::model()->findByPk((int) $_POST['order_id'], array('select' => 'date, num')))) {
     //				$return_msg .= "Невозможно получить данные договора \n";
     //			}
     if (is_null($data['client'] = Clients::model()->findByPk($client_id))) {
         $return_msg .= "Невозможно получить данные клиента \n";
     }
     if (!is_array($data['settings'] = Config::model()->get_settings())) {
         $return_msg .= "Невозможно получить основные параметры \n";
     }
     $body = $this->_tmpl_body($data, Acts::model()->get_act_tmpl($template_id));
     if ($body == '') {
         $return_msg .= "Невозможно сформировать шаблон \n";
     }
     if ($return_msg == '') {
         echo $body;
     } else {
         echo $return_msg;
     }
 }
Пример #6
0
 /**
  * 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 = Contracts::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }