public function actionAdd($id = 0)
 {
     if (!empty($id)) {
         $Insurance = Insurance::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Insurance->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->insurance != '1' || $Insurance->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $Insurance->address;
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->insurance != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Insurance = new Insurance();
         $Address = new Address();
         $Address->setscenario('insurance');
     }
     //if(isset($_POST['save'])) {
     if (!empty($_POST)) {
         if (!empty($Insurance->address)) {
             Address::model()->deleteByPk($Insurance->address->address_id);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $Insurance->setAttributes($_POST['Insurance'], false);
         $Address->setAttributes($_POST['Address'], false);
         $valid = $Address->validate();
         $valid = $Insurance->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Insurance->user_id = User::createFakeUser($ContentManager);
                 $Insurance->contact_id = $Insurance->user_id;
             }
             $Address->save();
             $Insurance->address_id = $Address->address_id;
             $Insurance->save();
             $Insurance->autosearch();
             //                $this->redirect('/insurance');
             $this->render('insuranceaddsuccess', ['Insurance' => $Insurance, 'contacts' => User::getContact()]);
             exit;
         }
     }
     $this->render('add', ['Insurance' => $Insurance, 'Address' => $Address, 'contacts' => User::getContact(), 'ContentManager' => $ContentManager]);
 }
 /**
  *  обавить
  * @param int $id
  * @param null $delivery
  * @throws CException
  * @throws CHttpException
  */
 public function actionAdd($id = 0, $delivery = null)
 {
     if (!empty($id)) {
         $Cargo = Cargo::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Cargo->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->cargo != '1' || $Cargo->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $AddressesForm = $Cargo->getAddressForm();
         $CostForm = $Cargo->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->cargo != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Cargo = new Cargo();
         $AddressesForm = new AddressesForm();
         if (isset($delivery)) {
             $product = Product::model()->findByPk($delivery);
             $AddressesForm->from_1_name = $product->getEavAttribute('adres_name');
             $AddressesForm->from_1_address_lat = $product->getEavAttribute('adres_adress_lat');
             $AddressesForm->from_1_address_long = $product->getEavAttribute('adres_adress_long');
             $AddressesForm->from_1_ind = '';
         }
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     $Cargo->contact_id = Yii::app()->user->id;
     if (!empty($_POST)) {
         $Cargo->setAttributes($_POST['Cargo'], false);
         $AddressesForm->setAttributes($_POST['AddressesForm'], false);
         if ($Cargo->price_asc == '0') {
             $CostForm->setAttributes($_POST['CostForm'], false);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $AddressesForm->validate();
         $valid = $Cargo->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($Cargo, $AddressesForm, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Cargo->user_id = User::createFakeUser($ContentManager);
                 $Cargo->contact_id = $Cargo->user_id;
             }
             $Cargo->save();
             $_POST['Cargo']['type_transport'] = '';
             if (isset($Cargo->transport_type_id)) {
                 switch ($Cargo->transport_type_id) {
                     case 20:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['sea_transport'];
                         break;
                     case 21:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['zhd_transport'];
                         break;
                     case 22:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['air_transport'];
                         break;
                     case 72:
                         $_POST['Cargo']['type_transport'] = $_POST['Cargo']['river_transport'];
                         break;
                     default:
                         break;
                 }
             }
             $Cargo->setRelations($_POST['Cargo']);
             $Cargo->setAddress($AddressesForm);
             $Cargo->setCost($CostForm);
             $Cargo->autosearch();
             if ($_POST['Cargo']['customs_clearance'] == 1) {
                 if ($_POST['AddressesForm']['from_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['from_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'RU') {
                     $_POST['AddressesForm']['to_1_ind'] = 'RUS';
                 }
                 if ($_POST['AddressesForm']['from_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['from_1_ind'] = 'CHE';
                 }
                 if ($_POST['AddressesForm']['to_1_ind'] == 'CH') {
                     $_POST['AddressesForm']['to_1_ind'] = 'CHE';
                 }
                 $from = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['from_1_ind']]);
                 $to = DictionaryData::model()->findByAttributes(['code' => $_POST['AddressesForm']['to_1_ind']]);
                 $Custom = new Custom();
                 $Custom->type_id = $_POST['Cargo']['name_id'];
                 $Custom->packing_id = $_POST['Cargo']['packing_id'];
                 $Custom->country_from = isset($from) ? $from->id : 0;
                 $Custom->country_to = isset($to) ? $to->id : 0;
                 $Custom->weight_netto = $_POST['Cargo']['weight'];
                 $Custom->weight_brutto = $_POST['Cargo']['weight'];
                 $Custom->volume = $_POST['Cargo']['volume'];
                 $Custom->date_from = $_POST['Cargo']['when_from'];
                 $Custom->date_to = $_POST['Cargo']['when_to'];
                 $Custom->user_id = Yii::app()->user->id;
                 $Custom->contact_id = $_POST['Cargo']['contact_id'];
                 $Custom->save();
                 $Custom->autosearch();
             }
             if ($_POST['Cargo']['cargo_insurance'] == 1) {
                 $addrId = Yii::app()->db->createCommand()->select('address_id')->from('site_cargo_address u')->where('cargo_id=:cargo_id', array(':cargo_id' => $Cargo->cargo_id))->order('cargo_id ASC')->limit(1)->queryRow();
                 $addr = Address::model()->findByPk($addrId);
                 $Insurance = new Insurance();
                 $Insurance->category_id = 147;
                 $Insurance->address_id = $addr->address_id;
                 $Insurance->description = '';
                 $Insurance->contact_id = $_POST['Cargo']['contact_id'];
                 $Insurance->create = date('Y-m-d H:i:s');
                 $Insurance->user_id = Yii::app()->user->id;
                 $Insurance->date_to = $_POST['Cargo']['when_to'] != '' ? $_POST['Cargo']['when_to'] : '0000-00-00';
                 $Insurance->save();
                 $Insurance->autosearch();
             }
             echo CJSON::encode(array('status' => '500', 'redirect' => '/cargoaddsuccess/' . $Cargo->cargo_id));
             Yii::app()->end();
         }
     }
     $DictionaryData = \DictionaryData::model()->findAll('group_id=3');
     $this->render('add', ['Cargo' => $Cargo, 'addreses' => $AddressesForm, 'CostForm' => $CostForm, 'contacts' => $contacts, 'ContentManager' => $ContentManager, 'DictionaryData' => $DictionaryData]);
 }
 public function actionAddcall($id = 0)
 {
     $flZayavka = 1;
     if (!empty($id)) {
         $this->pageTitle = Yii::t('MarketModule.default', 'Редактирование спецтехники');
         $title = Yii::t('MarketModule.default', 'Редактирование заявки на спецтехнику');
     } else {
         $this->pageTitle = Yii::t('MarketModule.default', 'Добавление спецтехники');
         $title = Yii::t('MarketModule.default', 'Добавление заявки на спецтехнику');
     }
     $this->breadcrumbs = array_merge([CHtml::encode(Yii::t('MarketModule.default', 'Заявки на спецтехнику')) => ['/specialtechniquecall']], [CHtml::encode($this->pageTitle)]);
     if (!empty($id)) {
         $SpecialTechnique = SpecialTechnique::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $SpecialTechnique->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || $SpecialTechnique->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $Address = $SpecialTechnique->address;
         $CostForm = $SpecialTechnique->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->specialtech != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $SpecialTechnique = new SpecialTechnique();
         $Address = new Address();
         $Address->setscenario('specialtechnique');
         $CostForm = new CostForm();
     }
     $contacts = User::getContact();
     if (!empty($_POST)) {
         if (!empty($SpecialTechnique->address)) {
             Address::model()->deleteByPk($SpecialTechnique->address->address_id);
         }
         $SpecialTechnique->setAttributes($_POST['SpecialTechnique'], false);
         $SpecialTechnique->type_request = 'request';
         $CostForm->setAttributes($_POST['CostForm'], false);
         $Address->setAttributes($_POST['Address'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $Address->validate();
         $valid = $SpecialTechnique->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($SpecialTechnique, $Address, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $SpecialTechnique->user_id = User::createFakeUser($ContentManager);
                 $SpecialTechnique->contact_id = $SpecialTechnique->user_id;
             }
             $Address->save();
             $SpecialTechnique->address_id = $Address->address_id;
             $SpecialTechnique->save();
             $SpecialTechnique->setRelations($_POST['SpecialTechnique']);
             $SpecialTechnique->setCost($CostForm);
             $SpecialTechnique->autosearch();
             //$this->redirect('/specialtechniquecall');
             echo CJSON::encode(array('status' => '500', 'redirect' => '/specialaddcallsuccess/' . $SpecialTechnique->special_technique_id));
             Yii::app()->end();
         }
     }
     $this->render('add', ['showPhoto' => false, 'CostForm' => $CostForm, 'SpecialTechnique' => $SpecialTechnique, 'contacts' => $contacts, 'Address' => $Address, 'title' => $title, 'ContentManager' => $ContentManager, 'flZayavka' => $flZayavka]);
 }
 public function actionAdd($id = 0)
 {
     //	 !\Yii::app()->user->getProfile()->company->validate
     if (\Yii::app()->user->getProfile()->company->validate && !\ext\services\AccountingPayed::getInstance()->checkPayed()) {
         $this->redirect('/cabinet/tarif');
     }
     $AddressesForm = new AddressesForm();
     if (!empty($id)) {
         $Reis = Reis::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Reis->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->transport != '1' || $Reis->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $i = 1;
         $AddressesForm = $Reis->getAddressForm();
         $CostForm = $Reis->getCostForm();
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->transport != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $Reis = new Reis();
         $Reis->when_type_id = 40;
         $Reis->when_from = date("Y-m-d");
         $Reis->when_to = date("Y-m-d", time() + 60 * 60 * 24 * 15);
         $CostForm = new CostForm();
     }
     $company_id = Yii::app()->getUser()->getProfile()->company_id;
     $Contacts = User::model()->findAllByAttributes(['company_id' => $company_id]);
     $contacts = [];
     foreach ($Contacts as $Contact) {
         $contacts[$Contact->id] = $Contact->first_name . ' ' . $Contact->last_name . ' (' . $Contact->contact_phone . ')';
     }
     $AddressesForm->setScenario('reis');
     // alternative validation
     if (!empty($_POST)) {
         if (!empty($_POST['Reis']['reis_id'])) {
             $Reis = Reis::model()->findByPk($_POST['Reis']['reis_id']);
         } else {
             $Reis = new Reis();
         }
         $postReis = $Reis->processComplexAttributes($_POST);
         $Reis->setAttributes($postReis['Reis'], false);
         $AddressesForm->setAttributes($_POST['AddressesForm'], false);
         if ($Reis->price_asc == '0') {
             $CostForm->setAttributes($_POST['CostForm'], false);
         }
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $AddressesForm->validate();
         $valid = $Reis->validate() && $CostForm->validate() && $valid && $contentValid;
         if (!$valid) {
             Yii::import('bootstrap.widgets.TbActiveForm');
             if ($ContentManager) {
                 echo TbActiveForm::validate(array($Reis, $AddressesForm, $CostForm, $ContentManager));
             } else {
                 echo TbActiveForm::validate(array($Reis, $AddressesForm, $CostForm));
             }
             Yii::app()->end();
         } else {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $Reis->user_id = User::createFakeUser($ContentManager);
                 $Reis->contact_id = $Reis->user_id;
             }
             $Reis->save();
             $Reis->setRelations($postReis['Reis']);
             $Reis->setAddress($AddressesForm);
             $Reis->setCost($CostForm);
             $Reis->autosearch();
             echo CJSON::encode(array('status' => '500', 'redirect' => '/transportaddsuccess/' . $Reis->reis_id));
             Yii::app()->end();
         }
     }
     // список своего транспорта
     $listAvtopark = null;
     if (Yii::app()->user->checkAccess('avtopark')) {
         $criteria = new CDbCriteria();
         $criteria->with = ['user' => ['joinType' => 'INNER JOIN', 'condition' => 'user.company_id = :company_id']];
         $criteria->params = [':company_id' => $company_id];
         $listAvtoparkTmp = Transport::model()->findAll($criteria);
         $arrAttr = ['transport_id', 'name'];
         // только 2 этих аттрибута, остальное подгрузить через ajax
         foreach ($listAvtoparkTmp as $vlist) {
             $arrTmp = [];
             foreach ($arrAttr as $vattr) {
                 $arrTmp[$vattr] = $vlist->attributes[$vattr];
             }
             $listAvtopark[] = $arrTmp;
         }
     }
     $this->render('add', ['Reis' => $Reis, 'addreses' => $AddressesForm, 'CostForm' => $CostForm, 'contacts' => $contacts, 'listAvtopark' => $listAvtopark, 'ContentManager' => $ContentManager]);
 }
Esempio n. 5
0
 /**
  *  Добавление товара
  * @param int $id
  * @throws CHttpException
  * @throws \CException
  */
 public function actionStoreadd($id = 0)
 {
     \Yii::import('application.modules.store.models.*');
     \Yii::import('application.modules.cabinet.*');
     $photos = array();
     $values = array();
     $request = Yii::app()->request->pathInfo;
     $type = preg_match('/(service)/', $request);
     $StoreCategory = new \StoreCategory();
     $ProductaForm = new \ProductaForm();
     $Address = new \Address();
     if ($id != 0) {
         $Product = \Product::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $Product->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->product != '1' || $Product->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $StoreCategory = \StoreCategory::model()->findByPk($Product->category_id);
         $Address->name = $Product->address_name;
         $Address->lat = $Product->address_lat;
         $Address->long = $Product->address_long;
         $OptionForm = $Product->getOptionForm();
         $ProductaForm->SetCategoryId($Product->category_id);
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->product != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new \ContentManager();
         }
         $Product = new \Product();
         $Product->payment_id = 2;
         $Product->price = '';
         $StoreCategory = new \StoreCategory();
         $StoreCategory->slug = 'tmp';
         $OptionForm = new \OptionForm();
     }
     $Product->type_id = 1;
     $Product->tiu_id = 0;
     if (\Yii::app()->getRequest()->getPost('call')) {
         $Product->scenario = 'call';
     }
     if (\Yii::app()->getRequest()->getPost('Product')) {
         $photos = \Yii::app()->getRequest()->getPost('photos');
         $attributes = \Yii::app()->getRequest()->getPost('Product');
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $OptionForm->setAttributes($_POST['OptionForm'], false);
         $valid = $OptionForm->validate();
         $Address->setAttributes($_POST['Address'], false);
         $Product->address_name = $Address->name;
         $Product->address_lat = $Address->lat;
         $Product->address_long = $Address->long;
         if (isset($attributes['category_id'])) {
             $StoreCategory = \StoreCategory::model()->findByPk($attributes['category_id']);
             $ProductaForm->SetCategoryId($attributes['category_id']);
             if (isset($StoreCategory)) {
                 $type = \Type::model()->findByAttributes(['name' => $StoreCategory->slug]);
                 $attributes['type_id'] = $type->id;
             } else {
                 $StoreCategory = new \StoreCategory();
                 $StoreCategory->addErrors(['name' => Yii::t('default', "Необходимо заполнить поле «{title}».", array('{title}' => $StoreCategory->attributeLabels()['name']))]);
             }
         }
         if ($ProductaForm->validate()) {
             $Product = $Product->saveData($attributes, array(), array(), $photos);
         } else {
             $contentValid = false;
         }
         if (empty($_POST['Address']['name']) || empty($_POST['Address']['lat']) && empty($_POST['Address']['long'])) {
             if ($type) {
                 $Address->addError('name', Yii::t('default', "Необходимо заполнить поле «Адрес оказания услуги»."));
             } else {
                 $Address->addError('name', Yii::t('default', "Необходимо заполнить поле «Адрес товара»."));
             }
         }
         if (!$Product->hasErrors() && $contentValid == true) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $user_id = \User::createFakeUser($ContentManager);
                 Yii::app()->db->createCommand()->update('tbl_user', array('user_id' => $user_id), 'id=:id', array(':id' => $Product->id));
             }
             $Product->setOption($OptionForm);
             $Product->autosearch();
             $this->render('storeaddsuccess', ['Product' => $Product, 'StoreCategory' => $StoreCategory, 'Address' => $Address, 'type' => $type]);
             exit;
         }
     }
     $this->render('productadd', ['Product' => $Product, 'StoreCategory' => $StoreCategory, 'Address' => $Address, 'OptionForm' => $OptionForm, 'ContentManager' => $ContentManager, 'photos' => $photos, 'values' => $values, 'ProductaForm' => $ProductaForm]);
 }
 public function actionAddcall($id = 0)
 {
     /*if(!Yii::app()->user->checkAccess('addSklad')) {
           throw new CHttpException(404,'Указанная запись не найдена');
       }*/
     if (!empty($id)) {
         $SkladCall = SkladCall::model()->findByPk($id);
         $Address = $SkladCall->address;
         $Area = $SkladCall->getAreaForm();
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $SkladCall->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->storage != '1' || $SkladCall->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->storage != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $SkladCall = new SkladCall();
         $Address = new Address();
         $Address->setscenario('sklad');
         $Area = new AreaForm();
     }
     $contacts = User::getContact();
     if (isset($_POST['save'])) {
         if (!empty($_POST['SkladCall']['sklad_call_id'])) {
             $SkladCall = SkladCall::model()->findByPk($_POST['SkladCall']['sklad_call_id']);
         } else {
             $SkladCall = new SkladCall();
         }
         if (!empty($SkladCall->address)) {
             Address::model()->deleteByPk($SkladCall->address->address_id);
         }
         $SkladCall->setAttributes($_POST['SkladCall'], false);
         $Address->setAttributes($_POST['Address'], false);
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $valid = $Address->validate();
         $valid = $SkladCall->validate() && $valid && $contentValid;
         if ($valid) {
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $SkladCall->user_id = User::createFakeUser($ContentManager);
                 $SkladCall->contact_id = $SkladCall->user_id;
             }
             $Address->save();
             $SkladCall->address_id = $Address->address_id;
             $SkladCall->save();
             $SkladCall->setRelations($_POST['SkladCall']);
             $SkladCall->setArea($_POST['AreaForm']);
             $SkladCall->autosearch();
             //$this->redirect('/storagecall');
             $this->render('skladaddcallsuccess', ['SkladCall' => $SkladCall, 'contacts' => $contacts, 'Area' => $Area, 'Address' => $Address]);
             exit;
         }
     }
     $this->render('addcall', ['SkladCall' => $SkladCall, 'contacts' => $contacts, 'Area' => $Area, 'Address' => $Address, 'ContentManager' => $ContentManager]);
 }
 public function actionAdd($type, $id = 0)
 {
     Yii::import('application.modules.store.models.*');
     if ($id != 0) {
         $StoreCall = StoreCall::model()->findByPk($id);
         if (!Yii::app()->user->checkAccess('admin') && ((Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY || Yii::app()->user->getProfile()->company_id != $StoreCall->user->company_id) && (Yii::app()->getUser()->getProfile()->modules->product != '1' || $StoreCall->user_id != Yii::app()->user->id) || Yii::app()->getUser()->getProfile()->company->active == '0')) {
             throw new CHttpException(403);
         }
         $StoreCategory = StoreCategory::model()->findByPk($StoreCall->category_id);
         $Address = $StoreCall->address;
         $ContentManager = null;
     } else {
         if (Yii::app()->user->getProfile()->content_manager == '0') {
             if (!Yii::app()->user->checkAccess('admin') && (Yii::app()->getUser()->getProfile()->modules->head != \UserModules::DIRECTOR_COMPANY && Yii::app()->getUser()->getProfile()->modules->product != '1' || Yii::app()->getUser()->getProfile()->company->active == '0')) {
                 throw new CHttpException(403);
             } elseif (!Yii::app()->getUser()->getProfile()->company->validate) {
                 $this->redirect('/complete');
             }
             $ContentManager = null;
         } else {
             $ContentManager = new ContentManager();
         }
         $StoreCall = new StoreCall();
         $StoreCategory = new StoreCategory();
         $StoreCategory->slug = 'tmp';
         $Address = new Address();
     }
     $contacts = User::getContact();
     if (isset($_POST['save'])) {
         $StoreCall->setAttributes($_POST['StoreCall'], false);
         $StoreCall->type = $type;
         if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
             $ContentManager->setAttributes($_POST['ContentManager'], false);
             $contentValid = $ContentManager->validate();
         } else {
             $contentValid = true;
         }
         $validate = $StoreCall->validate() && $contentValid;
         if ($_POST['StoreCall']['category_id'] == '') {
             $StoreCategory->addErrors(['name' => Yii::t('default', "Необходимо заполнить поле «{title}».", ['{title}' => $StoreCategory->attributeLabels()['name']])]);
             $categoryValidate = false;
         } else {
             $StoreCategory = \StoreCategory::model()->findByPk($_POST['StoreCall']['category_id']);
             $categoryValidate = true;
         }
         if ($validate && $categoryValidate) {
             if (!empty($StoreCall->address)) {
                 Address::model()->deleteByPk($StoreCall->address_id);
             }
             if (Yii::app()->user->getProfile()->content_manager == '1' && $id == 0) {
                 $StoreCall->user_id = User::createFakeUser($ContentManager);
             }
             $Address = new Address();
             $Address->setAttributes($_POST['Address'], false);
             $Address->save();
             $StoreCall->address_id = $Address->address_id;
             $StoreCall->save();
             $StoreCall->autosearch();
             Yii::app()->user->setFlash('success', Yii::t('CabinetModule.default', 'Запрос успешно добавлен.'));
             $this->redirect('/storecall/' . $type);
             $this->render('storecallsuccess', ['StoreCategory' => $StoreCategory, 'StoreCall' => $StoreCall, 'type' => $type, 'contacts' => $contacts, 'Address' => $Address]);
             exit;
         }
     }
     $this->render('add', ['StoreCategory' => $StoreCategory, 'StoreCall' => $StoreCall, 'type' => $type, 'contacts' => $contacts, 'Address' => $Address, 'ContentManager' => $ContentManager]);
 }