Ejemplo n.º 1
0
 public function approveFromBookkeeper($method)
 {
     if ($this->approve != 1) {
         $tran = Yii::app()->db->beginTransaction();
         try {
             $this->method = $method;
             $this->approve = 1;
             $this->pay_date = date("Y-m-d");
             $this->save(false);
             if ($this->payment_type == 1) {
                 $payment = ProjectPayments::model()->findByAttributes(['order_id' => $this->order_id]);
                 $payment->payed += $this->summ;
                 $payment->to_pay -= $this->summ;
                 $payment->save(false);
             }
             $tran->commit();
         } catch (Exception $ex) {
             $tran->rollback();
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 public function init()
 {
     $this->parts = ZakazParts::model()->findAllByAttributes(['proj_id' => $this->project->id]);
     $this->payments = ProjectPayments::model()->findByAttributes(['order_id' => $this->project->id]);
     $this->changes = ProjectChanges::model()->findAllByAttributes(['project_id' => $this->project->id]);
     $this->messages = ProjectMessages::model()->findAllByAttributes(['order' => $this->project->id], ['order' => 'id DESC']);
 }
Ejemplo n.º 3
0
 public function init()
 {
     // --- Организации
     $c_id = Campaign::getId();
     if ($c_id) {
         Payment::$table_prefix = $c_id . '_';
         //Profile::$table_prefix = $c_id.'_';
         //ProfileField::$table_prefix = $c_id.'_';
         ProjectChanges::$table_prefix = $c_id . '_';
         ProjectChanges::$file_path = 'uploads/c' . $c_id . '/changes_documents';
         //ProjectMessages::$table_prefix = $c_id.'_';
         ProjectPayments::$table_prefix = $c_id . '_';
         Zakaz::$table_prefix = $c_id . '_';
         Zakaz::$files_folder = '/uploads/c' . $c_id . '/';
         Events::$table_prefix = $c_id . '_';
         ZakazParts::$table_prefix = $c_id . '_';
         UpdateProfile::$table_prefix = $c_id . '_';
         ZakazPartsFiles::$table_prefix = $c_id . '_';
         PaymentImage::$table_prefix = $c_id . '_';
         Emails::$table_prefix = $c_id . '_';
         Yii::app()->language = Campaign::getLanguage();
     } else {
         ProjectChanges::$file_path = 'uploads/changes_documents';
     }
     // ---
     if (!Yii::app()->user->isGuest) {
         switch (User::model()->getUserRole()) {
             case 'Manager':
             case 'Admin':
                 Yii::app()->theme = 'admin';
                 break;
             case 'Author':
                 $this->menu = array(array('label' => Yii::t('site', 'My orders'), 'url' => array('/project/zakaz/ownList')), array('label' => Yii::t('site', 'New projects'), 'url' => array('/project/zakaz/list')), array('label' => Yii::t('site', 'Profile'), 'url' => array('/user/profile/edit')), array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 $this->authMenu = array(array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 Yii::app()->theme = 'client';
                 break;
             case 'Customer':
                 $this->menu = array(array('label' => Yii::t('site', 'My orders'), 'url' => array('/project/zakaz/customerOrderList')), array('label' => Yii::t('site', 'Create order'), 'url' => array('/project/zakaz/create')), array('label' => Yii::t('site', 'Profile'), 'url' => array('/user/profile/edit')), array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 $this->authMenu = array(array('label' => Yii::t('site', 'Logout'), 'url' => array('/user/logout')));
                 Yii::app()->theme = 'client';
                 break;
         }
     }
     //		var_dump(Yii::app()->controller->module->id ,Yii::app()->controller->id, Yii::app()->controller->action->id);
     //		die();
 }
 public function init()
 {
     Yii::app()->clientScript->registerScriptFile('/js/project_payment.js');
     $payments = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $this->projectId));
     /*
     * убрал генерацию мусорных записей в таблицу
             if (!$payment) {
        $payment = new ProjectPayments;
        $payment->order_id = $this->projectId;
        $payment->received = 0;
        $payment->to_receive = 0;
        $payment->to_pay = 0;
        $payment->save();
             }
     * 
     */
     $this->renderForm($payments);
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     if (isset($_GET['sid'])) {
         // Меняем статус, ajax
         $sid = $_GET['sid'];
         $model = $this->loadModel($id);
         $model->status = $sid;
         $model->save();
         Yii::app()->end();
     }
     if (Yii::app()->request->isAjaxRequest) {
         //echo 'test';
         $data = Yii::app()->request->getRestParams();
         $field = str_replace('Zakaz_', '', $data['elid']);
         if (is_array($data)) {
             $model = $this->loadModel($data['id']);
             echo json_encode($model->{$field} = $data['data']);
             echo json_encode($model->save());
             echo json_encode($model->errors);
             Yii::app()->end();
         }
         $this->renderPartial('_order_list_update');
         Yii::app()->end();
     }
     Yii::app()->session['project_id'] = $id;
     $model = $this->loadModel($id);
     if (Yii::app()->request->getParam('close') == 'yes') {
         $model->old_status = $model->status;
         $model->status = 5;
         $model->save(false);
         $user = User::model()->findByPk($model->user_id);
         if ($user->pid) {
             $payed = Payment::model()->exists('order_id = :p1 AND payment_type = :p2', array(':p1' => $model->id, ':p2' => Payment::OUTCOMING_WEBMASTER));
             if (!$payed) {
                 // Only first time
                 $webmaster = User::model()->with('profile')->findByPk($user->pid);
                 $openlog = WebmasterLog::model()->findByAttributes(array('order_id' => $model->id), 'action = :p1 OR action = :p2', array(':p1' => WebmasterLog::FIRST_ORDER, ':p2' => WebmasterLog::NON_FIRST_ORDER));
                 $webmasterlog = new WebmasterLog();
                 $webmasterlog->pid = $user->pid;
                 $webmasterlog->uid = $user->id;
                 $webmasterlog->date = date("Y-m-d");
                 $webmasterlog->order_id = $model->id;
                 if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                     $webmasterlog->action = WebmasterLog::FINISH_FIRST_ORDER_SUCCESS;
                 } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                     $webmasterlog->action = WebmasterLog::FINISH_NON_FIRST_ORDER_SUCCESS;
                 }
                 $webmasterlog->save();
                 // Pament for webmaster ~~~~~~~~~~~~~~~~~~~~~~~~~~
                 $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $model->id));
                 $manag = User::model()->findByPk(Yii::app()->user->id);
                 $buh = new Payment();
                 $buh->order_id = $model->id;
                 $buh->receive_date = date('Y-m-d');
                 $buh->theme = $model->title;
                 $buh->user = $webmaster->email;
                 $buh->details_ya = $webmaster->profile->yandex;
                 $buh->details_wm = $webmaster->profile->wmr;
                 $buh->details_bank = $webmaster->profile->bank_account;
                 $buh->payment_type = Payment::OUTCOMING_WEBMASTER;
                 $buh->manager = $manag->email;
                 //$buh->approve = 0;
                 $buh->method = 'Cash or Bank';
                 if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                     $buh->summ = (double) $payment->project_price * Company::getWebmasterFirstOrderRate();
                 } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                     $buh->summ = (double) $payment->project_price * Company::getWebmasterSecondOrderRate();
                 }
                 $buh->save();
             }
         }
         $this->redirect(array('update', 'id' => $model->id));
     } elseif (Yii::app()->request->getParam('open') == 'yes') {
         $model->status = $model->old_status;
         $model->save(false);
         $this->redirect(array('update', 'id' => $model->id));
     } elseif (Yii::app()->request->getParam('refound') == 'yes') {
         $model->old_status = $model->status;
         $model->status = 5;
         $model->save(false);
         $user = User::model()->findByPk($model->user_id);
         // Refound ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         $manag = User::model()->findByPk(Yii::app()->user->id);
         $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $model->id));
         if ($payment && $payment->received > 0) {
             $refound = $payment->received;
             $payment->received = 0;
             $payment->save();
             $buh = new Payment();
             $buh->order_id = $model->id;
             $buh->receive_date = date('Y-m-d');
             $buh->theme = $model->title;
             $buh->user = $user->email;
             $buh->summ = (double) $refound;
             $buh->payment_type = Payment::OUTCOMING_CUSTOMER;
             $buh->manager = $manag->email;
             //$buh->approve = 0;
             $buh->method = 'Cash or Bank';
             $buh->save();
         }
         if ($user->pid) {
             $webmasterlog = new WebmasterLog();
             $webmasterlog->pid = $user->pid;
             $webmasterlog->uid = $user->id;
             $webmasterlog->date = date("Y-m-d");
             $webmasterlog->order_id = $model->id;
             $openlog = WebmasterLog::model()->findByAttributes(array('order_id' => $model->id), 'action = :p1 OR action = p2', array(':p1' => WebmasterLog::FIRST_ORDER, ':p2' => WebmasterLog::NON_FIRST_ORDER));
             if ($openlog->action == WebmasterLog::FIRST_ORDER) {
                 $webmasterlog->action = WebmasterLog::FINISH_FIRST_ORDER_FAILURE;
             } elseif ($openlog->action == WebmasterLog::NON_FIRST_ORDER) {
                 $webmasterlog->action = WebmasterLog::FINISH_NON_FIRST_ORDER_FAILURE;
             } else {
                 echo 'Somthing wrong...';
                 Yii::app()->end();
             }
             $webmasterlog->save();
         }
         $this->redirect(array('update', 'id' => $model->id));
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Zakaz'])) {
         $model->attributes = $_POST['Zakaz'];
         if (isset($_POST['Zakaz']['dbdate'])) {
             $model->dbdate = $_POST['Zakaz']['dbdate'];
         }
         $projectFields = $model->getFields();
         if ($projectFields) {
             foreach ($projectFields as $field) {
                 if ($field->field_type == "TIMESTAMP") {
                     // ----------------------------------------------------
                     $tmp = $field->varname;
                     if (isset($_POST['Zakaz'][$tmp])) {
                         $model->{$tmp} = $_POST['Zakaz'][$tmp];
                         $model->timestampInput($field);
                     }
                 }
             }
         }
         if ($model->save()) {
             if (Yii::app()->request->getParam('accepted') && User::model()->isCorrector()) {
                 EventHelper::correctorAccepted($model->id);
             }
             $role = User::model()->getUserRole();
             if ($role != 'Manager' && $role != 'Admin') {
                 // где-то есть дублрующий вызов записи события, поэтому этот комментируем
                 // oldbadger 09.10.2015
                 //					EventHelper::editOrder($model->id);
                 //$view = 'orderInModerate';
                 $this->redirect(array("../project/chat?orderId={$id}"));
             } else {
                 //					$this->redirect(array('project/chat','orderId'=>$model->id));
                 $this->redirect(array('update', 'id' => $model->id));
             }
         }
     }
     $managerlog = new ManagerLog();
     $managerlog->uid = Yii::app()->user->id;
     $managerlog->action = ManagerLog::ORDER_PAGE_VIEW;
     $managerlog->datetime = date('Y-m-d H:i:s');
     $managerlog->order_id = $model->id;
     $managerlog->save();
     $hints = Templates::model()->getTemplateList(4);
     $view = 'update';
     $isModified = false;
     $this->render($view, array('model' => $model, 'hints' => $hints, 'isModified' => $isModified));
 }
Ejemplo n.º 6
0
<?php

if (User::model()->isCustomer()) {
    $to_recive = ProjectPayments::model()->findByAttributes(array('order_id' => $order->id))->to_receive;
    if ($to_recive > 0) {
        if (Campaign::getPaymentCash() == 1) {
            echo '<div class="col-xs-12 block-for-upload-chek">';
            $upload = new UploadPaymentImage();
            $form = $this->beginWidget('CActiveForm', array('id' => 'check-form', 'action' => ['zakaz/uploadPayment', 'id' => $order->id], 'enableAjaxValidation' => false, 'htmlOptions' => array('enctype' => 'multipart/form-data')));
            ?>
			<div class="to-pay">
				<span class="text-to-pay"><?php 
            echo ProjectModule::t('To pay');
            ?>
<span> <span class="value-to-pay"><? echo $to_recive; ?></span> <span class="rub">&#8381;</span>
			</div>
			<div class="row chek">
				<span class="text_scan"><?php 
            echo ProjectModule::t('Scan check');
            ?>
</span> <?php 
            echo $form->fileField($upload, 'file');
            ?>
			</div>
			<div class="row buttons check-button-upload">
				<?php 
            echo CHtml::submitButton(ProjectModule::t('Upload'));
            ?>
			</div>
			<?php 
            $this->endWidget();
Ejemplo n.º 7
0
                echo CHtml::link('Чек ' . $i++, UploadPaymentImage::$folder . $item->image, array('target' => '_blank')) . ' ';
            }
            echo '</div>';
        }
        echo '</div><hr>';
    }
}
?>
                <?php 
if (User::model()->isAuthor()) {
    ?>
				<div class="col-xs-12"><?php 
    if ($order->executor != 0) {
        // Если назначен исполнитель
        echo '<div class="my-rating">' . ProjectModule::t('My rating:') . ' <span class="value">' . Profile::model()->findByPk($order->executor)->rating . '</span></div>';
        $payment = ProjectPayments::model()->findByAttributes(array('order_id' => $order->id));
        echo '<div class="my-rating">' . ProjectModule::t('Work price:') . ' <span class="value">' . $payment->work_price . '</span></div>';
        //Стоимость проекта для автора
        echo '<div class="my-rating">' . ProjectModule::t('To pay:') . ' <span class="value">' . $payment->to_pay . '</span></div>';
        echo '<div class="my-rating">' . ProjectModule::t('Payed:') . ' <span class="value">' . $payment->payed . '</span></div>';
    }
    ?>
</div>
                <?php 
}
?>
				<?php 
$this->widget('application.modules.project.widgets.zakazParts.ZakazPartWidget', array('projectId' => $order->id));
?>
                <div class="col-xs-12">
                    <?php 
 public function actionManagersCancel()
 {
     $this->_prepairJson();
     $orderId = $this->_request->getParam('order_id');
     $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array('ORDER_ID' => $orderId));
     $payment->to_receive = 0;
     if ($payment->save()) {
         PaymentImage::model()->remove($orderId);
         $this->_response->setData(array('to_receive' => $payment->to_receive));
     } else {
         $this->_response->setData(array('to_receive' => $payment->to_receive));
     }
     $this->_response->send();
 }
 public function processOrderPage()
 {
     $message = false;
     $login_ok = false;
     if (!Yii::app()->user->isGuest && User::model()->isCustomer()) {
         $login_ok = true;
     }
     if (!$login_ok && isset($_POST['Login'])) {
         if (Yii::app()->user->isGuest) {
             $model = new UserLogin();
             //$this->performAjaxValidation($model);
             // collect user input data
             $model->attributes = $_POST['Login'];
             // validate user input and redirect to previous page if valid
             if ($model->validate()) {
                 //$this->lastViset();
                 $login_ok = true;
             } else {
                 $message = 'Incorrect login or password';
                 //Yii::app()->end();
             }
         }
     }
     if (!$login_ok && isset($_POST['User'])) {
         $model = new User();
         $attributes = $_POST['User'];
         //$attributes['full_name'] =  $_POST['User']['first_name'].' '.$_POST['User']['last_name'];
         $pos = strpos($attributes['email'], '@');
         $attributes['username'] = str_replace(array('@', '.'), '_', $attributes['email']);
         // substr( $attributes['email'], 0, $pos);
         $attributes['full_name'] = $_POST['User']['first_name'] . ' ' . $_POST['User']['last_name'];
         unset($attributes['first_name']);
         unset($attributes['last_name']);
         $p = $_POST['Profile'];
         $country = $p['country'];
         $countryCodes = $this->getCountryCodes();
         $code = $countryCodes[$country];
         $attributes['phone_number'] = '+' . $code . $attributes['phone_number'];
         Yii::import('user.controllers.RegistrationController');
         if (RegistrationController::register($model, $attributes)) {
             $login_ok = true;
             $profile = new Profile();
             $profile->user_id = $model->id;
             $profile->country = $country;
             $profile->save();
         } else {
             if ($attributes['email'] != '') {
                 $message = 'Sorry, registration faild...<br>';
                 foreach ($model->errors as $err => $descr) {
                     $message .= $descr[0] . '<br>';
                 }
             }
         }
     }
     $model = new Zakaz();
     $model->attributes = $_POST['Zakaz'];
     // (unixtime)
     if ($login_ok) {
         Yii::import('project.controllers.ZakazController');
         if (ZakazController::createProject($model, $_POST['Project'])) {
             $cost = $this->calculateCost($model);
             $payment = new ProjectPayments();
             $payment->order_id = $model->id;
             $payment->project_price = $cost;
             $payment->received = 0;
             $payment->to_receive = $cost;
             $payment->work_price = 0;
             $payment->payed = 0;
             $payment->to_pay = 0;
             $payment->save();
             if (Campaign::getPayment2Chekout() != 0) {
                 $user = User::model()->with('profile')->findByPk($model->user_id);
                 $data = array('sid' => Campaign::getPayment2Chekout(), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => 'order' . $model->id, 'li_0_price' => $cost, 'li_0_product_id' => $model->id, 'x_receipt_link_url' => 'http://' . $_SERVER["HTTP_HOST"] . '/project/payment/affiliatePayment', 'card_holder_name' => $user->full_name, 'country' => $user->profile->country, 'email' => $user->email, 'phone' => $user->phone_number);
                 $this->redirectWithPost('https://2checkout.com/checkout/purchase', $data);
             }
             echo 'Ok! Cost = ' . $cost;
             Yii::app()->end();
         } else {
             //echo 'Project is not valid!!<br>';
             //print_r($_POST['Project']);
             //Yii::app()->end();
             $message = 'Please complete all required fields.';
         }
     }
     if (!isset($model->unixtime) or $model->unixtime == '') {
         $model->unixtime = time();
     }
     Yii::app()->theme = explode('.', $_SERVER['SERVER_NAME'])[0];
     $this->render('page/order', array('logged' => $login_ok, 'message' => $message, 'project' => $model, 'countryCodes' => $this->getCountryCodes()));
     Yii::app()->end();
 }
Ejemplo n.º 10
0
 public function insertVariables($in, $orderId)
 {
     $in = $this->replaceBBCode($in);
     preg_match_all("/\\{(.+?)\\}/is", $in, $out);
     foreach ($out[1] as $k => $o) {
         $var = explode('_', $o);
         $model_name = ucfirst(array_shift($var));
         if (@class_exists($model_name)) {
             if ($model_name == 'Projectpayments') {
                 $model = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $orderId));
             } elseif ($model_name == 'Company') {
                 $model = Company::getCompany();
             } else {
                 $model = $model_name::model()->findByPk($orderId);
             }
             $var = implode('_', $var);
             if ($model && in_array($var, $model->attributeNames())) {
                 $fields[$k] = $model->{$var};
             } elseif ($model) {
                 $fields[$k] = '#wrong property#';
             } else {
                 $fields[$k] = '#cant find model#';
             }
         } else {
             $fields[$k] = '#wrong model#';
         }
     }
     return str_replace($out[0], $fields, $in);
 }