Ejemplo n.º 1
0
 public function actionAdminAjax($ccmp_id)
 {
     $model4grid = new CcucUserCompany('search');
     $model4grid->setAttribute('ccuc_ccmp_id', $ccmp_id);
     $model4grid->ccuc_ccmp_id = $ccmp_id;
     if (isset($_GET['User'])) {
         $model4grid->attributes = $_GET['CcbrBranch'];
     }
     $this->renderPartial("/Customers/_customer_grid", array('model4grid' => $model4grid, 'ccmp_id' => $ccmp_id));
 }
Ejemplo n.º 2
0
 protected function afterSave()
 {
     parent::afterSave();
     //if added syscomany group, add company as SYS to person in ccuc
     if (isset(Yii::app()->params['ccgr_group_sys_company']) && $this->ccxg_ccgr_id == Yii::app()->params['ccgr_group_sys_company']) {
         $ccuc = new CcucUserCompany();
         $ccuc->ccuc_ccmp_id = $this->ccxg_ccmp_id;
         $ccuc->ccuc_person_id = Yii::app()->getModule('user')->user()->profile->person_id;
         $ccuc->ccuc_status = CcucUserCompany::CCUC_STATUS_SYS;
         $ccuc->save();
     }
 }
Ejemplo n.º 3
0
 public function searchClient($criteria = null)
 {
     if (is_null($criteria)) {
         $criteria = new CDbCriteria();
     }
     $criteria->distinct = true;
     $ccuc = CcucUserCompany::model()->getPersonCompnies(Yii::app()->getModule('user')->user()->profile->person_id, CcucUserCompany::CCUC_STATUS_PERSON);
     $cl = [];
     foreach ($ccuc as $c) {
         if ($c->ccuc_ccmp_id == Yii::app()->sysCompany->getActiveCompany()) {
             continue;
         }
         $cl[] = $c->ccuc_ccmp_id;
     }
     if (!empty($cl)) {
         $criteria->join = "  \n                INNER JOIN pf_order o \n                    ON o.id = t.order_id \n            ";
         $criteria->addCondition(" \n                    (\n                    o.client_ccmp_id IN (" . implode(',', $cl) . ") \n                    OR t.manufakturer_ccmp_id IN (" . implode(',', $cl) . ")\n                    OR t.manufakturer_ccmp_id IS NULL    \n                    )\n                    ");
     }
     $criteria = $this->searchCriteria($criteria);
     return new CActiveDataProvider(get_class($this), ['criteria' => $criteria]);
 }
Ejemplo n.º 4
0
 public function actionAdmin()
 {
     $model = new CcucUserCompany('search');
     $scopes = $model->scopes();
     if (isset($scopes[$this->scope])) {
         $model->{$this->scope}();
     }
     $model->unsetAttributes();
     if (isset($_GET['CcucUserCompany'])) {
         $model->attributes = $_GET['CcucUserCompany'];
     }
     $model->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON;
     $this->render('admin', array('model' => $model));
 }
 public function actionUpdateCustomers($ccmp_id, $ccuc_id)
 {
     $model = $this->loadModel($ccmp_id);
     $m = new CcucUserCompany();
     $mCcuc = $m->findByPk($ccuc_id);
     $this->performAjaxValidation($mCcuc, 'ccuc-user-company-form');
     if (isset($_POST['CcucUserCompany'])) {
         $mCcuc->attributes = $_POST['CcucUserCompany'];
         try {
             if ($mCcuc->save()) {
                 if (isset($_GET['returnUrl'])) {
                     $this->redirect($_GET['returnUrl']);
                 } else {
                     $this->redirect(array('adminManagers', 'ccmp_id' => $ccmp_id));
                 }
             }
         } catch (Exception $e) {
             $model->addError('ccuc_id', $e->getMessage());
         }
     }
     $model->scenario = $this->scenario;
     $this->render('update_extended', array('model' => $model, 'mCcuc' => $mCcuc, 'active_tab' => 'company_manager_update'));
 }
Ejemplo n.º 6
0
Archivo: view.php Proyecto: uldisn/ace
    foreach ($all_roles as $role_record) {
        $all_roles_dict[$role_record['name']] = $role_record['description'];
    }
    $UserAdminRoles = Yii::app()->getModule('user')->UserAdminRoles;
    $list = [];
    foreach ($UserAdminRoles as $role_name) {
        //add only defined roles
        if (isset($all_roles_dict[$role_name])) {
            $list[$role_name] = $all_roles_dict[$role_name];
        }
    }
    $body = CHtml::checkBoxList('user_role_name', $aChecked, $list, array('labelOptions' => array('style' => 'display: inline'), 'template' => '{input}<span class="lbl"></span> {label}', 'class' => 'ace'));
}
$this->widget('AceBox', array('header_text' => UserModule::t('Roles'), 'info_allert' => $info_allert, 'body' => $body));
$companies_list = Yii::app()->sysCompany->getClientCompanies();
$aUserCompanies = CcucUserCompany::model()->getUserCompnies($model->id, CcucUserCompany::CCUC_STATUS_SYS);
$aChecked = array();
foreach ($aUserCompanies as $UC) {
    $aChecked[] = $UC->ccuc_ccmp_id;
}
if (count($aChecked) == 1) {
    //kaut kads gljuks, nedrikst padot masivu ar vienu elementu
    $aChecked = $aChecked[0];
}
$list = array();
if (UserModule::isAdmin()) {
    //for admin get all sys companies
    $sql = "\n                    SELECT \n                        ccmp_id,\n                        ccmp_name \n                      FROM\n                        ccxg_company_x_group \n                        INNER JOIN ccmp_company \n                          ON ccxg_ccmp_id = ccmp_id \n                      WHERE ccxg_ccgr_id = " . Yii::app()->params['ccgr_group_sys_company'] . " \n                      ORDER BY ccmp_name";
    $ccmp_list = Yii::app()->db->createCommand($sql)->queryAll();
    foreach ($ccmp_list as $ccmp) {
        $list[$ccmp['ccmp_id']] = $ccmp['ccmp_name'];
Ejemplo n.º 7
0
 public function afterSave()
 {
     //for new records set syscompany
     if (!$this->ccucUserCompanies) {
         $ccuc = new CcucUserCompany();
         $ccuc->ccuc_person_id = $this->pprs_id;
         $ccuc->ccuc_ccmp_id = Yii::app()->sysCompany->getActiveCompany();
         $ccuc->ccuc_status = CcucUserCompany::CCUC_STATUS_SYS;
         $ccuc->save();
         //person company
         if (!empty($this->pprs_ccmp_id)) {
             $ccuc = new CcucUserCompany();
             $ccuc->ccuc_person_id = $this->pprs_id;
             $ccuc->ccuc_ccmp_id = $this->pprs_ccmp_id;
             $ccuc->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON;
             $ccuc->save();
         }
     }
     parent::afterSave();
 }
    ?>
</div>

<?php 
    $criteria = new CDbCriteria();
    $criteria->compare('ccuc_person_id', $modelMain->primaryKey);
    $criteria->compare('ccuc_status', CcucUserCompany::CCUC_STATUS_PERSON);
    $m = CcucUserCompany::model()->find($criteria);
    if (empty($m)) {
        $model = new CcucUserCompany();
        $model->ccuc_person_id = $modelMain->primaryKey;
        $model->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON;
        $model->save();
        unset($model);
    }
    $model = new CcucUserCompany();
    $model->ccuc_person_id = $modelMain->primaryKey;
    $model->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON;
    // render grid view
    $can_edit_ccuc = Yii::app()->user->checkAccess("D2company.CcucUserCompany.Update");
    $bft = !$can_edit_ccuc ? 'false' : 'true';
    if (Yii::app()->getModule('d2person')->ccucCompanyList == D2personModule::ALL_COMPANIES) {
        $comapniesSource = CHtml::listData(CcmpCompany::model()->findAll(array('limit' => 1000, 'order' => 'ccmp_name')), 'ccmp_id', 'itemLabel');
    } else {
        /**
         * actual person syscompanies
         */
        $comapniesSource = CHtml::listData(Yii::app()->sysCompany->getClientCompanies(), 'ccmp_id', 'ccmp_name');
    }
    $this->widget('TbGridView', array('id' => 'ccuc-user-company-grid', 'dataProvider' => $model->searchPersonsForRel(), 'template' => '{summary}{items}', 'summaryText' => '&nbsp;', 'htmlOptions' => array('class' => 'rel-grid-view'), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'ccuc_ccmp_id', 'value' => '$data->ccmp_name', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2company/ccucUserCompany/editableSaver'), 'source' => $comapniesSource, 'apply' => $can_edit_ccuc)), array('class' => 'editable.EditableColumn', 'name' => 'ccuc_cucp_id', 'value' => '(!' . $bft . ' && !empty($data->ccuc_cucp_id))?$data->ccucCucp->cucp_name:""', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2company/ccucUserCompany/editableSaver'), 'source' => CHtml::listData(CucpUserCompanyPosition::model()->findAll(array('limit' => 1000)), 'cucp_id', 'itemLabel'), 'apply' => $can_edit_ccuc)), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'FALSE'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'TRUE')), 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("/d2company/ccucUserCompany/delete", array("ccuc_id" => $data->ccuc_id))', 'deleteConfirmation' => Yii::t('D2personModule.crud_static', 'Do you want to delete this item?'), 'deleteButtonOptions' => array('data-toggle' => 'tooltip'), 'visible' => Yii::app()->user->checkAccess("D2company.CcucUserCompany.Delete")))));
    Yii::endProfile('ccuc_person_id.view.grid');
Ejemplo n.º 9
0
<?php

if (!$ajax) {
    Yii::app()->clientScript->registerCss('rel_grid', '
            .rel-grid-view {margin-top:-60px;}
            .rel-grid-view div.summary {height: 60px;}
            ');
    Yii::app()->clientScript->registerScript('hide_user_company_grid_header', '
                $("#ccuc-user-company-grid thead").hide();
            ');
    ?>
<div class="table-header">
    <?php 
    echo UserModule::t("Customer companies ");
    ?>
    <?php 
    $this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'ajaxButton', 'type' => 'primary', 'size' => 'mini', 'icon' => 'icon-plus', 'url' => array("{$this->id}/customerAjaxCompanyAdd", 'id' => $model->id, 'pprs_id' => $model->profile->person_id, 'ajax' => 'ccuc-user-company-grid'), 'ajaxOptions' => array('success' => 'function (html) {
                $.fn.yiiGridView.update(\'ccuc-user-company-grid\');
                
            }'), 'htmlOptions' => array('title' => UserModule::t('Add company'), 'data-toggle' => 'tooltip')));
    ?>
</div>

    <?php 
}
$ccuc = new CcucUserCompany();
$ccuc->ccuc_person_id = $model->profile->person_id;
// render grid view
$this->widget('TbGridView', array('id' => 'ccuc-user-company-grid', 'dataProvider' => $ccuc->searchPersonsForRel(), 'template' => '{summary}{items}', 'summaryText' => '&nbsp;', 'enableSorting' => false, 'htmlOptions' => array('class' => 'rel-grid-view'), 'afterAjaxUpdate' => 'function(){$("#ccuc-user-company-grid thead").hide()}', 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'ccuc_ccmp_id', 'value' => '$data->ccmp_name', 'editable' => array('type' => 'select', 'url' => $this->createUrl('//d2company/ccucUserCompany/editableSaver'), 'source' => CHtml::listData(CcmpCompany::model()->findAll(array('order' => 'ccmp_name')), 'ccmp_id', 'itemLabel'))), array('class' => 'TbButtonColumn', 'buttons' => array('view' => array('visible' => 'FALSE'), 'update' => array('visible' => 'FALSE'), 'delete' => array('visible' => 'TRUE')), 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("/d2company/ccucUserCompany/delete", array("ccuc_id" => $data->ccuc_id))', 'deleteConfirmation' => UserModule::t('Do you want to delete this item?'), 'deleteButtonOptions' => array('data-toggle' => 'tooltip')))));
Ejemplo n.º 10
0
 public function actionCustomerAjaxCompanyAdd($pprs_id, $ajax)
 {
     $ccuc = new CcucUserCompany();
     $ccuc->ccuc_person_id = $pprs_id;
     $ccuc->ccuc_status = CcucUserCompany::CCUC_STATUS_PERSON;
     $ccuc->save();
 }
Ejemplo n.º 11
0
 /**
  * Displays a particular model.
  */
 public function actionView()
 {
     $this->layout = '';
     $model = $this->loadModel();
     //update record
     if (isset($_POST['user_role_name']) || isset($_POST['user_sys_ccmp_id'])) {
         //cheked roles
         $aChecked = Authassignment::model()->getUserRoles($model->id);
         //get in form checked
         $aPostRole = array();
         if (isset($_POST['user_role_name'])) {
             foreach ($_POST['user_role_name'] as $nRoleId) {
                 $aPostRole[] = $nRoleId;
             }
         }
         $aDelRole = array_diff($aChecked, $aPostRole);
         $aNewRole = array_diff($aPostRole, $aChecked);
         $UserAdminRoles = Yii::app()->getModule('user')->UserAdminRoles;
         foreach ($aNewRole as $sRoleName) {
             // can not add no User Admin roles defined in main config
             if (!in_array($sRoleName, $UserAdminRoles)) {
                 continue;
             }
             $aa_model = new Authassignment();
             $aa_model->itemname = $sRoleName;
             $aa_model->userid = $model->id;
             if (!$aa_model->save()) {
                 print_r($aa_model->errors);
                 exit;
             }
         }
         if (!empty($aDelRole)) {
             Authassignment::model()->deleteAll("`userid` = :userid AND itemname in('" . implode("','", $aDelRole) . "')", array(':userid' => $model->id));
         }
         //checked companies
         $aUserCompanies = CcucUserCompany::model()->getUserCompnies($model->id, CcucUserCompany::CCUC_STATUS_SYS);
         $aChecked = array();
         foreach ($aUserCompanies as $UC) {
             $aChecked[] = $UC->ccuc_ccmp_id;
         }
         //get in form checked
         $aPostSysCcmp = array();
         if (isset($_POST['user_sys_ccmp_id'])) {
             foreach ($_POST['user_sys_ccmp_id'] as $ccmp_id) {
                 $aPostSysCcmp[] = $ccmp_id;
             }
         }
         $aDelSysCcmpid = array_diff($aChecked, $aPostSysCcmp);
         $aNewSysCcmpid = array_diff($aPostSysCcmp, $aChecked);
         $list = array();
         if (UserModule::isAdmin()) {
             //for admin get all sys companies
             $criteria = new CDbCriteria();
             $criteria->compare('t.ccxg_ccgr_id', 1);
             //1 - syscompany
             $model_ccxg = CcxgCompanyXGroup::model()->findAll($criteria);
             foreach ($model_ccxg as $mCcxg) {
                 $list[$mCcxg->ccxg_ccmp_id] = 1;
             }
         } else {
             foreach (Yii::app()->sysCompany->getClientCompanies() as $mCcmp) {
                 $list[$mCcmp->ccucCcmp->ccmp_id] = 1;
             }
         }
         foreach ($aNewSysCcmpid as $cmmp_id) {
             // can not add no User Admin sys ccmp
             if (!isset($list[$cmmp_id])) {
                 continue;
             }
             //create ccuc (company <==> person)
             $mCcuc = new CcucUserCompany();
             $mCcuc->ccuc_ccmp_id = $cmmp_id;
             $mCcuc->ccuc_status = CcucUserCompany::CCUC_STATUS_SYS;
             $mCcuc->ccuc_person_id = $model->profile->person_id;
             $mCcuc->save();
             if (!$mCcuc->save()) {
                 print_r($mCcuc->errors);
                 exit;
             }
         }
         if (!empty($aDelSysCcmpid)) {
             CcucUserCompany::model()->deleteAll("`ccuc_status` = :ccuc_status " . " AND `ccuc_person_id` = :ccuc_person_id " . " AND ccuc_ccmp_id in('" . implode("','", $aDelSysCcmpid) . "')", array(':ccuc_person_id' => $model->profile->person_id, ':ccuc_status' => CcucUserCompany::CCUC_STATUS_SYS));
         }
     }
     $view = 'view';
     if (Yii::app()->getModule('user')->view) {
         $alt_view = Yii::app()->getModule('user')->view . '.admin.' . $view;
         if (is_readable(Yii::getPathOfAlias($alt_view) . '.php')) {
             $view = $alt_view;
             $this->layout = Yii::app()->getModule('user')->layout;
         }
     }
     $model = $this->loadModel();
     $this->render($view, array('model' => $model));
 }
Ejemplo n.º 12
0
 public function getUserPersonCompanies()
 {
     if ($this->_userPersonCompanies) {
         return $this->_userPersonCompanies;
     }
     $personId = Yii::app()->getModule('user')->user()->profile->person_id;
     $this->_userPersonCompanies = CcucUserCompany::model()->getPersonCompnies($personId, CcucUserCompany::CCUC_STATUS_PERSON);
     return $this->_userPersonCompanies;
 }
 public function loadModel($id)
 {
     $m = CcucUserCompany::model();
     // apply scope, if available
     $scopes = $m->scopes();
     if (isset($scopes[$this->scope])) {
         $m->{$this->scope}();
     }
     $model = $m->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, Yii::t('D2companyModule.crud_static', 'The requested page does not exist.'));
     }
     return $model;
 }
Ejemplo n.º 14
0
 /**
  * get person companies by person and status
  * @param type $pprs_id - person
  * @param type $status - statuss
  * @return type
  */
 public function getPersonCompnies($pprs_id, $status)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "t.ccuc_person_id = " . $pprs_id . " and t.ccuc_status = '" . $status . "'";
     return CcucUserCompany::model()->findAll($criteria);
 }