private function loadProfile()
 {
     $this->load->file('application/modules/app/user_profile/form/profile_form.php');
     $resAjax = new Response_Ajax();
     $id_person = Helper_App_Session::getPersonId();
     $oBus = Business_App_Person::loadByPersonId($id_person);
     $data = $oBus->data();
     /* @var $ePerson ePerson  */
     $ePerson = $data['ePerson'];
     $frm_data = new Form_App_Profile();
     $frm_data->setPersonEntity($ePerson);
     /* @var $eCiudad eCiudad */
     $oBus1 = Business_App_Ciudad::loadCiudad($ePerson->id_ciudad, $eCiudad);
     $frm_data->id_provincia = $eCiudad->id_provincia;
     $frm_data->id_pais = $eCiudad->id_pais;
     $id_profile = Helper_App_Session::getProfileId();
     $oBusP = Business_App_Profile::loadProfile($id_profile);
     $dataProfile = $oBusP->data();
     $eProfile = $dataProfile['eProfile'];
     $frm_data->name_profile = $eProfile->name;
     $resAjax->isSuccess($oBus->isSuccess());
     $resAjax->message($oBus->message());
     $resAjax->form('profile', $frm_data->toArray());
     echo $resAjax->toJsonEncode();
 }
 public static function saveAcount(ePerson $ePerson, eUser $eUser, eUserProfile $eUserProfile, $eUserProfile_CompanyBranches)
 {
     $oBus = new Response_Business();
     $MY =& MY_Controller::get_instance();
     /* @var $mPerson Person_Model */
     $mPerson =& $MY->mPerson;
     /* @var $mUser User_Model */
     $mUser =& $MY->mUser;
     /* @var $mUserProfile User_Profile_Model */
     $mUserProfile =& $MY->mUserProfile;
     /* @var $mUserProfileCompanyBranch User_Profile_Company_Branch_Model */
     $mUserProfileCompanyBranch =& $MY->mUserProfileCompanyBranch;
     $oTransaction = new MY_Business();
     $oTransaction->begin();
     try {
         if (!Helper_App_Session::isAdminProfile() || !Helper_App_Session::isSuperAdminProfile()) {
             if (Business_App_Person::isValidDocument($ePerson->document)) {
                 throw new Exception('Documento Invalido, No permitido');
             }
         }
         $ePersonT = $mPerson->loadByDocument($ePerson->document, $ePerson->id);
         if (!$ePersonT->isEmpty()) {
             throw new Exception('Persona Existente');
         }
         $eUserT = $mUser->load($eUser->username, 'username', $eUser->id);
         if (!$eUserT->isEmpty()) {
             throw new Exception('Usuario Existente');
         }
         $mPerson->save($ePerson);
         $mUser->save($eUser);
         $eUserProfileT = $mUserProfile->loadArray(array('id_user' => $eUser->id, 'id_profile' => $eUserProfile->id_profile));
         $eUserProfile->id_user = $eUser->id;
         $eUserProfile->id = $eUserProfileT->id;
         $mUserProfile->save($eUserProfile);
         $mUserProfileCompanyBranch->deleteByUserProfile($eUserProfile->id);
         if (!empty($eUserProfile_CompanyBranches)) {
             /* @var $eUserProfileCompanyBranch eUserProfileCompanyBranch */
             foreach ($eUserProfile_CompanyBranches as $eUserProfileCompanyBranch) {
                 $eUserProfileCompanyBranch->id_user_profile = $eUserProfile->id;
                 $mUserProfileCompanyBranch->save($eUserProfileCompanyBranch);
             }
         }
         $oTransaction->commit();
         $oBus->isSuccess(TRUE);
         $oBus->message("Guardado exitosamente");
     } catch (Exception $e) {
         $oTransaction->rollback();
         $oBus->isSuccess(FALSE);
         $oBus->message($e->getMessage());
     }
     return $oBus;
 }
 public static function savePerson(ePerson $ePerson)
 {
     $oBus = new Response_Business();
     $MY =& MY_Controller::get_instance();
     /* @var $mPerson Person_Model */
     $mPerson =& $MY->mPerson;
     $oTransaction = new MY_Business();
     $oTransaction->begin();
     try {
         $ePersonT = $mPerson->load($ePerson->id);
         if (!Helper_App_Session::isAdminProfile() || !Helper_App_Session::isSuperAdminProfile()) {
             if (Business_App_Person::isValidDocument($ePerson->document)) {
                 throw new Exception('Documento Invalido: ' + $ePerson->document);
             }
             if ($ePersonT->tipo_documento != $ePerson->tipo_documento) {
                 throw new Exception('No tiene permisos para editar el tipo de documento');
             }
             if ($ePersonT->document != $ePerson->document) {
                 throw new Exception('No tiene permisos para editar el documento');
             }
         }
         $ePersonDocument = $mPerson->loadByDocument($ePerson->document, $ePerson->id);
         if (!$ePersonDocument->isEmpty()) {
             throw new Exception('Documento Existente: ' + $ePerson->document);
         }
         $mPerson->save($ePerson);
         $oBus->isSuccess(TRUE);
         $oBus->message("Guardado exitosamente");
         $oTransaction->commit();
     } catch (Exception $e) {
         $oTransaction->rollback();
         $oBus->isSuccess(FALSE);
         $oBus->message($e->getMessage());
     }
     return $oBus;
 }
 private function loadAcount()
 {
     $this->load->file('application/modules/app/user_settings/form/user_settings_form.php');
     $resAjax = new Response_Ajax();
     $id_user = $this->input->post('id_user');
     try {
         //USER
         $oBusUser = Business_App_User::loadUser($id_user);
         if (!$oBusUser->isSuccess()) {
             throw new Exception($oBusUser->message());
         }
         $dataUser = $oBusUser->data();
         /* @var $eUser eUser  */
         $eUser = $dataUser['eUser'];
         //PERSON
         $oBusPerson = Business_App_Person::loadByPersonId($eUser->id_person);
         if (!$oBusPerson->isSuccess()) {
             throw new Exception($oBusPerson->message());
         }
         $dataPerson = $oBusPerson->data();
         /* @var $ePerson ePerson  */
         $ePerson = $dataPerson['ePerson'];
         //USER_PROFILE
         $oBusUserProfile = Business_App_User_Profile::loadUserProfile($eUser->id);
         if (!$oBusUserProfile->isSuccess()) {
             throw new Exception($oBusUserProfile->message());
         }
         $dataUserProfile = $oBusUserProfile->data();
         /* @var $eUserProfile eUserProfile  */
         $eUserProfile = $dataUserProfile['eUserProfile'];
         //COMPANY_BRANCH
         $oBusCompanyBranch = Business_App_User_Settings::listCompanyBranchsByUserProfile($eUserProfile->id_user, $eUserProfile->id_profile);
         if (!$oBusCompanyBranch->isSuccess()) {
             throw new Exception($oBusCompanyBranch->message());
         }
         $dataCompanyBranchs = $oBusCompanyBranch->data();
         $eCompanyBranchs = $dataCompanyBranchs['eCompanyBranchs'];
         $frm_data = new Form_App_User_Settings();
         $frm_data->setUserEntity($eUser);
         $frm_data->setPersonEntity($ePerson);
         $frm_data->setUserProfileEntity($eUserProfile);
         $frm_data->setUserProfile_CompanyBranchEntity($eCompanyBranchs);
         $resAjax->isSuccess(TRUE);
     } catch (Exception $exc) {
         $resAjax->isSuccess(FALSE);
         $resAjax->message($exc->getMessage());
     }
     $resAjax->form('acount', $frm_data->toArray());
     echo $resAjax->toJsonEncode();
 }