예제 #1
0
 public function actionconfirm()
 {
     if (!isset($_POST['result']) || !isset($_POST['x_invoice']) || !isset($_POST['x_iduser']) || !isset($_POST['x_document'])) {
         Yii::app()->user->setFlash('error', Yii::t('translation', 'Error unexpexted'));
         $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
     }
     $user = Yii::app()->user->data();
     $invo = Invoices::model()->findByAttributes(array('id_user' => $user->id, 'invoice_number' => $_POST['x_invoice']));
     if (!is_null($invo)) {
         $invo->astropay_result = $_POST['result'];
         $invo->status = $_POST['result'] - 5;
         $invo->id_astropay = $_POST['x_document'];
         $invo->save();
         $tran = Transaction::model()->findByAttributes(array('id_trans' => $invo->id_trans));
         switch ($invo->astropay_result) {
             case 6:
                 $tran->status = 2;
                 break;
             case 7:
                 $tran->status = 0;
                 break;
             case 8:
                 $tran->status = 2;
                 break;
             case 9:
                 $tran->status = 1;
                 break;
         }
         $tran->save();
         $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
     } else {
         Yii::app()->user->setFlash('error', Yii::t('translation', 'Error unexpexted'));
         $this->redirect(Yii::app()->request->baseUrl . "/deposit/");
     }
 }
 /**
  * Get all task waiting to solve
  * By default project_id is selected
  * @return model list of invoices statistics amounts
  */
 public function getStatistics()
 {
     if (Yii::app()->user->getState('project_selected') != null) {
         return Invoices::model()->getInvoicesStatistics(Yii::app()->user->getState('project_selected'));
     } else {
         $Projects = Projects::model()->findMyProjects(Yii::app()->user->id);
         $projectList = array(0);
         foreach ($Projects as $project) {
             array_push($projectList, $project->project_id);
         }
         return Invoices::model()->getInvoicesStatistics(implode(",", $projectList));
     }
 }
예제 #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 (null == Invoices::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.');
     }
 }
 /**
  * Creates a new model.
  */
 public function actionCreate()
 {
     // create Comments Object
     $model = new Comments();
     // if Comments form exist
     if (isset($_POST['Comments'])) {
         // set form elements to Comments model attributes
         $model->attributes = $_POST['Comments'];
         $module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id)));
         // set module_id finded to model
         $model->module_id = $module->module_id;
         $project = Yii::app()->user->getState('project_selected');
         $model->project_id = $project;
         // validate and save
         if ($model->save()) {
             // create an instance of file uploaded
             $image = CUploadedFile::getInstancesByName('Comment');
             // if file upload exist
             if (count($image > 0)) {
                 // for each file uploaded
                 for ($i = 0; $i < count($image); $i++) {
                     // create an Document object
                     $modeldocs = new Documents();
                     $modeldocs->image = $image[$i];
                     if (!$modeldocs->image->getError()) {
                         // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
                         $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
                         // set the extension file uploaded
                         $extension = $modeldocs->image->getExtensionName();
                         // if no error saving file
                         if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                             $modeldocs->project_id = $project;
                             $modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30);
                             $modeldocs->document_description = $model->comment_text;
                             $modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             $modeldocs->document_revision = '1';
                             $modeldocs->document_uploadDate = date("Y-m-d");
                             $modeldocs->document_type = $modeldocs->image->getType();
                             $modeldocs->document_baseRevision = date('dmYHis');
                             $modeldocs->user_id = Yii::app()->user->id;
                             $modeldocs->comment_id = $model->primaryKey;
                             // save file uploaded as document
                             if ($modeldocs->save()) {
                                 Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk'));
                             } else {
                                 Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors());
                             }
                         } else {
                             Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError'));
                         }
                     } else {
                         Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors'));
                     }
                 }
             }
             // save log
             $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project);
             Logs::model()->saveLog($attributes);
             // find project managers to sent comment via mail
             $recipientsList = array();
             $ProjectManagers = Projects::model()->findManagersByProject($project);
             $managersArray = array();
             foreach ($ProjectManagers as $manager) {
                 $managersArray['email'] = $manager->user_email;
                 $managersArray['name'] = $manager->CompleteName;
                 array_push($recipientsList, $managersArray);
             }
             // find task owners to send comment via mail
             if ($module->module_name == 'tasks') {
                 $collaborators = Projects::model()->findAllUsersByProject($project);
                 $ColaboratorsArray = array();
                 foreach ($collaborators as $colaborator) {
                     $ColaboratorsArray['email'] = $colaborator->user_email;
                     $ColaboratorsArray['name'] = $colaborator->CompleteName;
                     // avoid to repeat email address
                     if (!in_array($ColaboratorsArray, $recipientsList)) {
                         array_push($recipientsList, $ColaboratorsArray);
                     }
                 }
             }
             // finding resource title
             switch ($module->module_name) {
                 case "budgets":
                     $resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title;
                     break;
                 case "invoices":
                     $resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number;
                     break;
                 case "expenses":
                     $resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name;
                     break;
                 case "documents":
                     $resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name;
                     break;
                 case "milestones":
                     $resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title;
                     break;
                 case "cases":
                     $resourceModelTitle = Cases::model()->findByPk($model->comment_resourceid)->case_name;
                     break;
                 case "tasks":
                     $resourceModelTitle = Tasks::model()->findByPk($model->comment_resourceid)->task_name;
                     break;
                 default:
                     $resourceModelTitle = "{empty}";
                     break;
             }
             // get project information
             $project = Projects::model()->findByPk($project);
             // prepare template to send via email
             $str = $this->renderPartial('//templates/comments/created', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'resourceTitle' => $resourceModelTitle, 'moduleName' => Yii::t('modules', $module->module_name), 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl($module->module_name . '/view', array('id' => $model->comment_resourceid))), true);
             Yii::import('application.extensions.phpMailer.yiiPhpMailer');
             $mailer = new yiiPhpMailer();
             $subject = Yii::t('email', 'CommentPosted') . " - " . $project->project_name . " - " . Yii::t('modules', $module->module_name);
             $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
         } else {
             Yii::app()->user->setFlash('CommentMessage', Yii::t('comments', 'RequiredComment'));
         }
     }
     $this->redirect(Yii::app()->createUrl($_GET['module'] . '/' . $_GET['action'], array('id' => $_GET['id'], '#' => 'comment-' . $model->primaryKey)));
 }
예제 #5
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.');
     }
 }
예제 #6
0
 public function actionChangeOrder()
 {
     $return_msg = '';
     //		Dumper::d($_POST['order_id']);die;
     if (Yii::app()->request->isAjaxRequest) {
         if (is_numeric($_POST['order_id'])) {
             $q = Invoices::model()->listData((int) $_POST['order_id']);
             if (count($q) > 0) {
                 foreach ($q as $key => $value) {
                     $haOptions[] = array('value' => $key, 'text' => $value);
                 }
                 $return_msg = json_encode($haOptions);
             } else {
                 $return_msg = json_encode('no');
             }
         } else {
             $return_msg = '[{"value":"","text":"Некорректный формат запроса"}]';
         }
     } else {
         $return_msg = '[{"value":"",text:"Некорректный формат запроса"}]';
     }
     echo $return_msg;
 }
예제 #7
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 (count(Invoices::model()->findAllByAttributes(array('act_id' => (int) $id))) == 0) {
             if ($model->delete()) {
                 $msg = 'Акт #' . $model->id . ' для Заказа #' . $model->order_id . ' ' . $model->order->name . ' удалён';
                 Yii::app()->user->setFlash('success', $msg);
                 Yii::app()->logger->write($msg);
             }
         } else {
             $msg = 'Акт #' . $model->id . ' для Заказа #' . $model->order_id . ' ' . $model->order->name . ' нельзя удалить - есть счета';
             Yii::app()->user->setFlash('notice', $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.');
     }
 }
예제 #8
0
파일: _form.php 프로젝트: ASDAFF/its-crm
		<?php 
$orders = $model->isNewRecord ? Orders::model()->open()->listData($model->client_id) : Orders::model()->listData($model->client_id);
echo $form->labelEx($model, 'order_id');
?>
		<?php 
echo $form->dropDownList($model, 'order_id', $orders, array('empty' => ''));
?>
		<span class="note" style="display: block" id="ajax_order_mess"></span>
	</div>	

	<div class="row">
		<?php 
echo $form->labelEx($model, 'invoice_id');
?>
		<?php 
echo $form->dropDownList($model, 'invoice_id', Invoices::model()->listData($model->order_id), array('encode' => false, 'empty' => ''));
?>
	</div>

	<div class="row">
		<?php 
echo $form->labelEx($model, 'date');
?>
		<?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('attribute' => 'date', 'model' => $model, 'value' => $model->date, 'language' => 'ru', 'options' => array('showAnim' => 'fold', 'changeYear' => true, 'changeMonth' => true, 'dateFormat' => 'yy-mm-dd')));
//		echo $form->textField($model,'date');
?>
	</div>

	<div class="row">
		<?php 
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * @param CAction $action the action to be executed.
  * @return boolean whether the action should be executed
  */
 public function beforeAction($action)
 {
     $response = false;
     if (Yii::app()->user->getState('project_selected') != null) {
         if (in_array($action->id, array('view', 'update'))) {
             $response = Invoices::model()->countInvoicesByProject((int) $_GET['id'], Yii::app()->user->getState('project_selected')) > 0 ? true : false;
         } else {
             $response = true;
         }
     } else {
         $response = false;
     }
     if (!$response) {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     } else {
         return $response;
     }
 }
예제 #10
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 = Invoices::model()->findByPk((int) $id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
예제 #11
0
    public function getInvoicesStatistics($project_id)
    {
        $criteria = new CDbCriteria();
        $criteria->select = 'count(t.status_id) AS items, SUM(
			(SELECT SUM(ic.invoicesConcept_amount) 
			FROM tb_invoicesConcepts ic 
			WHERE (ic.invoice_id = t.invoice_id))
		) as amount';
        // Si se ha seleccionado un proyecto
        /*if (!empty($project_id))
        		{
        			$criteria->condition = 't.project_id IN (:project_id)';
        			$criteria->params = array(
        				'project_id'=>$project_id,
        			);
        		}*/
        /*$criteria->condition = 'Cusers.user_id = :user_id';
        		$criteria->params = array(
        			':user_id' => Yii::app()->user->id,
        		);*/
        $criteria->condition = 't.project_id IN (' . $project_id . ')';
        $criteria->group = 't.status_id';
        $criteria->together = true;
        $criteria->with = array('Status', 'Projects.Currency');
        return Invoices::model()->findAll($criteria);
    }