[ 'className' => 'Acl.Acl' ] ]; /** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { if(@$this->request->getData('branch')) { $this->db = $this->request->getData('branch'); } parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => ['Form'=> ['contain' => ['Groups','Profiles'=>['Commerces']]]], 'authorize' => [ 'Acl.Actions' => ['actionPath' => 'controllers/'] ], 'loginAction' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'loginRedirect' => [ 'plugin' => false, 'controller' => 'pages', 'action' => 'home' ], 'logoutRedirect' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'unauthorizedRedirect' => [ 'controller' => 'Users', 'action' => 'login', 'prefix' => false ], 'authError' => 'No puede acceder a esta área', 'flash' => [ 'element' => 'error' ] ]); $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']); } public function beforeFilter(Event $event) { if(!is_null($this->Auth->user('setBranch'))) { $this->db = $this->Auth->user('setBranch'); } $dbSelected = 'orcu_'.$this->db; ConnectionManager::drop('default'); ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'orcusisdb', 'password' => 'orcusis@db#2018', 'database' => $dbSelected, 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, ]); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->PTOVTA = $busCompany['PTOVTA']; $this->Security->requireSecure(); $notAccess = ['Gerentes','mp','Comercios']; //Restringir acceso if(in_array($this->Auth->user('group.layout'),$notAccess)) { $this->Auth->logout(); } //Defino que layout usar según el tipo de usuario if (!is_null($this->Auth->user('group.layout'))) { $this->viewBuilder()->theme($this->Auth->user('group.layout')); } //Si es una pc de caja $SysComputers = TableRegistry::get('SysComputers'); $this->request->trustProxy = true; $pcPos = $SysComputers->find('all')->where(['ip'=>$this->request->clientIp()])->matching('SysPos')->toArray(); if (count($pcPos)>0) { $this->viewBuilder()->theme("Cajeros"); } //$this->viewBuilder()->theme("Cajeros"); #quitar, solo para prueba $this->set('user', $this->Auth->user()); } /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { $Plans = TableRegistry::get("Plans"); $getPlans = $Plans->find('list',['order'=>['oldid ASC'],'keyField' => 'id', 'valueField' => 'OldidName'])->where(['activo'=>1]); $hoy = date('Y-m-d'); $Campaigns = TableRegistry::get("Campaigns"); $getCampaigns = $Campaigns->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->order(['created DESC']); $Procedures = TableRegistry::get("Procedures"); $getProcedures = $Procedures->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->andWhere(['procedure_status_id'=> 3]) ->order(['created DESC']); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->set(compact(['getPlans','getCampaigns','getProcedures','busCompany'])); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml']) ) { $this->set('_serialize', true); } } public function forceSSL() { //return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here); //$this->request->getRequestTarget() } protected function _verifyTheme() { if($this->theme!=='Cajeros') { if($this->Auth->user('group_id')!='fe0cdb34-ed20-4416-a35c-a694a07505ca'&&$this->Auth->user('group_id')!='f3820488-acac-4991-96fd-aa5bccec5311') { $this->Flash->error(__('No puede acceder a Caja desde esta PC')); return $this->redirect(['controller'=>'pages','action' => 'home']); } } } protected function _verifyDrawerStatus($drawer_id) { $AccountingDrawerStatus = TableRegistry::get('AccountingDrawerStatus'); $lastStatus = $AccountingDrawerStatus->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['id DESC']) ->first(); return $lastStatus->status; } protected function _verifyDrawerBalance($drawer_id) { $Accountings = TableRegistry::get('Accountings'); $accountings = $Accountings->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['date DESC']) ->first(); $return = false; if(@$accountings->balance>1000) { $return = true; } return true; //$return; **revisar** } protected function _calculaDisponible($iTotal=null) { $AccountTypes = TableRegistry::get('AccountTypes'); $accountTypes = $AccountTypes->find('all') ->contain(['Products']) ->where([':iTotal BETWEEN salary_from AND salary_to']) ->bind(':iTotal', $iTotal, 'decimal') ->toArray()[0]; $a = $accountTypes['affect_amount']>0?$accountTypes['affect_amount']:($iTotal * $accountTypes['affect_percent']); $q = $accountTypes['term']; $i = $accountTypes['interest']; $m = $a * $q; $c = $accountTypes['max_amount']>0?$accountTypes['max_amount']:$m/(1+($i*$q)); $d = $accountTypes['affect_quote_amount']>0?$accountTypes['affect_quote_amount']:($iTotal*$accountTypes['affect_quote']); $accountTypes['a'] = $a; $accountTypes['c'] = $c; $accountTypes['d'] = $d; return $accountTypes; } protected function _getLatLong($address=null){ $return = false; if(!empty($address)) { $formattedAddr = str_replace(' ','+',$address); $geocodeFromAddr = "";//file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false&key=AIzaSyBaupPCi2LeR7xf_bx3xWckBDBRXDLmvGI'); $output = json_decode($geocodeFromAddr); $data['place_id'] = @$output->results[0]->place_id; $data['lat'] = @$output->results[0]->geometry->location->lat; $data['lng'] = @$output->results[0]->geometry->location->lng; if(!empty($data)) { $return = $data; } } return $return; } protected function groupArray($array,$groupkey) { if(count($array)>0) { $keys = array_keys($array[0]); $removekey = array_search($groupkey, $keys); if($removekey===false) { return array("Clave \"$groupkey\" no existe"); } else { unset($keys[$removekey]); } $groupcriteria = array(); $return=array(); foreach($array as $value) { $item=null; foreach ($keys as $key) { $item[$key] = $value[$key]; } $busca = array_search($value[$groupkey], $groupcriteria); if($busca === false) { $groupcriteria[]=$value[$groupkey]; $return[]=array($groupkey=>$value[$groupkey],'result'=>array()); $busca=count($return)-1; } $return[$busca]['result'][]=$item; } return $return; } else { return array(); } } } [ 'className' => 'Acl.Acl' ] ]; /** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { if(@$this->request->getData('branch')) { $this->db = $this->request->getData('branch'); } parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => ['Form'=> ['contain' => ['Groups','Profiles'=>['Commerces']]]], 'authorize' => [ 'Acl.Actions' => ['actionPath' => 'controllers/'] ], 'loginAction' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'loginRedirect' => [ 'plugin' => false, 'controller' => 'pages', 'action' => 'home' ], 'logoutRedirect' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'unauthorizedRedirect' => [ 'controller' => 'Users', 'action' => 'login', 'prefix' => false ], 'authError' => 'No puede acceder a esta área', 'flash' => [ 'element' => 'error' ] ]); $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']); } public function beforeFilter(Event $event) { if(!is_null($this->Auth->user('setBranch'))) { $this->db = $this->Auth->user('setBranch'); } $dbSelected = 'orcu_'.$this->db; ConnectionManager::drop('default'); ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'orcusisdb', 'password' => 'orcusis@db#2018', 'database' => $dbSelected, 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, ]); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->PTOVTA = $busCompany['PTOVTA']; $this->Security->requireSecure(); $notAccess = ['Gerentes','mp','Comercios']; //Restringir acceso if(in_array($this->Auth->user('group.layout'),$notAccess)) { $this->Auth->logout(); } //Defino que layout usar según el tipo de usuario if (!is_null($this->Auth->user('group.layout'))) { $this->viewBuilder()->theme($this->Auth->user('group.layout')); } //Si es una pc de caja $SysComputers = TableRegistry::get('SysComputers'); $this->request->trustProxy = true; $pcPos = $SysComputers->find('all')->where(['ip'=>$this->request->clientIp()])->matching('SysPos')->toArray(); if (count($pcPos)>0) { $this->viewBuilder()->theme("Cajeros"); } //$this->viewBuilder()->theme("Cajeros"); #quitar, solo para prueba $this->set('user', $this->Auth->user()); } /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { $Plans = TableRegistry::get("Plans"); $getPlans = $Plans->find('list',['order'=>['oldid ASC'],'keyField' => 'id', 'valueField' => 'OldidName'])->where(['activo'=>1]); $hoy = date('Y-m-d'); $Campaigns = TableRegistry::get("Campaigns"); $getCampaigns = $Campaigns->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->order(['created DESC']); $Procedures = TableRegistry::get("Procedures"); $getProcedures = $Procedures->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->andWhere(['procedure_status_id'=> 3]) ->order(['created DESC']); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->set(compact(['getPlans','getCampaigns','getProcedures','busCompany'])); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml']) ) { $this->set('_serialize', true); } } public function forceSSL() { //return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here); //$this->request->getRequestTarget() } protected function _verifyTheme() { if($this->theme!=='Cajeros') { if($this->Auth->user('group_id')!='fe0cdb34-ed20-4416-a35c-a694a07505ca'&&$this->Auth->user('group_id')!='f3820488-acac-4991-96fd-aa5bccec5311') { $this->Flash->error(__('No puede acceder a Caja desde esta PC')); return $this->redirect(['controller'=>'pages','action' => 'home']); } } } protected function _verifyDrawerStatus($drawer_id) { $AccountingDrawerStatus = TableRegistry::get('AccountingDrawerStatus'); $lastStatus = $AccountingDrawerStatus->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['id DESC']) ->first(); return $lastStatus->status; } protected function _verifyDrawerBalance($drawer_id) { $Accountings = TableRegistry::get('Accountings'); $accountings = $Accountings->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['date DESC']) ->first(); $return = false; if(@$accountings->balance>1000) { $return = true; } return true; //$return; **revisar** } protected function _calculaDisponible($iTotal=null) { $AccountTypes = TableRegistry::get('AccountTypes'); $accountTypes = $AccountTypes->find('all') ->contain(['Products']) ->where([':iTotal BETWEEN salary_from AND salary_to']) ->bind(':iTotal', $iTotal, 'decimal') ->toArray()[0]; $a = $accountTypes['affect_amount']>0?$accountTypes['affect_amount']:($iTotal * $accountTypes['affect_percent']); $q = $accountTypes['term']; $i = $accountTypes['interest']; $m = $a * $q; $c = $accountTypes['max_amount']>0?$accountTypes['max_amount']:$m/(1+($i*$q)); $d = $accountTypes['affect_quote_amount']>0?$accountTypes['affect_quote_amount']:($iTotal*$accountTypes['affect_quote']); $accountTypes['a'] = $a; $accountTypes['c'] = $c; $accountTypes['d'] = $d; return $accountTypes; } protected function _getLatLong($address=null){ $return = false; if(!empty($address)) { $formattedAddr = str_replace(' ','+',$address); $geocodeFromAddr = "";//file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false&key=AIzaSyBaupPCi2LeR7xf_bx3xWckBDBRXDLmvGI'); $output = json_decode($geocodeFromAddr); $data['place_id'] = @$output->results[0]->place_id; $data['lat'] = @$output->results[0]->geometry->location->lat; $data['lng'] = @$output->results[0]->geometry->location->lng; if(!empty($data)) { $return = $data; } } return $return; } protected function groupArray($array,$groupkey) { if(count($array)>0) { $keys = array_keys($array[0]); $removekey = array_search($groupkey, $keys); if($removekey===false) { return array("Clave \"$groupkey\" no existe"); } else { unset($keys[$removekey]); } $groupcriteria = array(); $return=array(); foreach($array as $value) { $item=null; foreach ($keys as $key) { $item[$key] = $value[$key]; } $busca = array_search($value[$groupkey], $groupcriteria); if($busca === false) { $groupcriteria[]=$value[$groupkey]; $return[]=array($groupkey=>$value[$groupkey],'result'=>array()); $busca=count($return)-1; } $return[$busca]['result'][]=$item; } return $return; } else { return array(); } } } [ 'className' => 'Acl.Acl' ] ]; /** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { if(@$this->request->getData('branch')) { $this->db = $this->request->getData('branch'); } parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => ['Form'=> ['contain' => ['Groups','Profiles'=>['Commerces']]]], 'authorize' => [ 'Acl.Actions' => ['actionPath' => 'controllers/'] ], 'loginAction' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'loginRedirect' => [ 'plugin' => false, 'controller' => 'pages', 'action' => 'home' ], 'logoutRedirect' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'unauthorizedRedirect' => [ 'controller' => 'Users', 'action' => 'login', 'prefix' => false ], 'authError' => 'No puede acceder a esta área', 'flash' => [ 'element' => 'error' ] ]); $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']); } public function beforeFilter(Event $event) { if(!is_null($this->Auth->user('setBranch'))) { $this->db = $this->Auth->user('setBranch'); } $dbSelected = 'orcu_'.$this->db; ConnectionManager::drop('default'); ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'orcusisdb', 'password' => 'orcusis@db#2018', 'database' => $dbSelected, 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, ]); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->PTOVTA = $busCompany['PTOVTA']; $this->Security->requireSecure(); $notAccess = ['Gerentes','mp','Comercios']; //Restringir acceso if(in_array($this->Auth->user('group.layout'),$notAccess)) { $this->Auth->logout(); } //Defino que layout usar según el tipo de usuario if (!is_null($this->Auth->user('group.layout'))) { $this->viewBuilder()->theme($this->Auth->user('group.layout')); } //Si es una pc de caja $SysComputers = TableRegistry::get('SysComputers'); $this->request->trustProxy = true; $pcPos = $SysComputers->find('all')->where(['ip'=>$this->request->clientIp()])->matching('SysPos')->toArray(); if (count($pcPos)>0) { $this->viewBuilder()->theme("Cajeros"); } //$this->viewBuilder()->theme("Cajeros"); #quitar, solo para prueba $this->set('user', $this->Auth->user()); } /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { $Plans = TableRegistry::get("Plans"); $getPlans = $Plans->find('list',['order'=>['oldid ASC'],'keyField' => 'id', 'valueField' => 'OldidName'])->where(['activo'=>1]); $hoy = date('Y-m-d'); $Campaigns = TableRegistry::get("Campaigns"); $getCampaigns = $Campaigns->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->order(['created DESC']); $Procedures = TableRegistry::get("Procedures"); $getProcedures = $Procedures->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->andWhere(['procedure_status_id'=> 3]) ->order(['created DESC']); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->set(compact(['getPlans','getCampaigns','getProcedures','busCompany'])); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml']) ) { $this->set('_serialize', true); } } public function forceSSL() { //return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here); //$this->request->getRequestTarget() } protected function _verifyTheme() { if($this->theme!=='Cajeros') { if($this->Auth->user('group_id')!='fe0cdb34-ed20-4416-a35c-a694a07505ca'&&$this->Auth->user('group_id')!='f3820488-acac-4991-96fd-aa5bccec5311') { $this->Flash->error(__('No puede acceder a Caja desde esta PC')); return $this->redirect(['controller'=>'pages','action' => 'home']); } } } protected function _verifyDrawerStatus($drawer_id) { $AccountingDrawerStatus = TableRegistry::get('AccountingDrawerStatus'); $lastStatus = $AccountingDrawerStatus->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['id DESC']) ->first(); return $lastStatus->status; } protected function _verifyDrawerBalance($drawer_id) { $Accountings = TableRegistry::get('Accountings'); $accountings = $Accountings->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['date DESC']) ->first(); $return = false; if(@$accountings->balance>1000) { $return = true; } return true; //$return; **revisar** } protected function _calculaDisponible($iTotal=null) { $AccountTypes = TableRegistry::get('AccountTypes'); $accountTypes = $AccountTypes->find('all') ->contain(['Products']) ->where([':iTotal BETWEEN salary_from AND salary_to']) ->bind(':iTotal', $iTotal, 'decimal') ->toArray()[0]; $a = $accountTypes['affect_amount']>0?$accountTypes['affect_amount']:($iTotal * $accountTypes['affect_percent']); $q = $accountTypes['term']; $i = $accountTypes['interest']; $m = $a * $q; $c = $accountTypes['max_amount']>0?$accountTypes['max_amount']:$m/(1+($i*$q)); $d = $accountTypes['affect_quote_amount']>0?$accountTypes['affect_quote_amount']:($iTotal*$accountTypes['affect_quote']); $accountTypes['a'] = $a; $accountTypes['c'] = $c; $accountTypes['d'] = $d; return $accountTypes; } protected function _getLatLong($address=null){ $return = false; if(!empty($address)) { $formattedAddr = str_replace(' ','+',$address); $geocodeFromAddr = "";//file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false&key=AIzaSyBaupPCi2LeR7xf_bx3xWckBDBRXDLmvGI'); $output = json_decode($geocodeFromAddr); $data['place_id'] = @$output->results[0]->place_id; $data['lat'] = @$output->results[0]->geometry->location->lat; $data['lng'] = @$output->results[0]->geometry->location->lng; if(!empty($data)) { $return = $data; } } return $return; } protected function groupArray($array,$groupkey) { if(count($array)>0) { $keys = array_keys($array[0]); $removekey = array_search($groupkey, $keys); if($removekey===false) { return array("Clave \"$groupkey\" no existe"); } else { unset($keys[$removekey]); } $groupcriteria = array(); $return=array(); foreach($array as $value) { $item=null; foreach ($keys as $key) { $item[$key] = $value[$key]; } $busca = array_search($value[$groupkey], $groupcriteria); if($busca === false) { $groupcriteria[]=$value[$groupkey]; $return[]=array($groupkey=>$value[$groupkey],'result'=>array()); $busca=count($return)-1; } $return[$busca]['result'][]=$item; } return $return; } else { return array(); } } } [ 'className' => 'Acl.Acl' ] ]; /** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { if(@$this->request->getData('branch')) { $this->db = $this->request->getData('branch'); } parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => ['Form'=> ['contain' => ['Groups','Profiles'=>['Commerces']]]], 'authorize' => [ 'Acl.Actions' => ['actionPath' => 'controllers/'] ], 'loginAction' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'loginRedirect' => [ 'plugin' => false, 'controller' => 'pages', 'action' => 'home' ], 'logoutRedirect' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'unauthorizedRedirect' => [ 'controller' => 'Users', 'action' => 'login', 'prefix' => false ], 'authError' => 'No puede acceder a esta área', 'flash' => [ 'element' => 'error' ] ]); $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']); } public function beforeFilter(Event $event) { if(!is_null($this->Auth->user('setBranch'))) { $this->db = $this->Auth->user('setBranch'); } $dbSelected = 'orcu_'.$this->db; ConnectionManager::drop('default'); ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'orcusisdb', 'password' => 'orcusis@db#2018', 'database' => $dbSelected, 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, ]); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->PTOVTA = $busCompany['PTOVTA']; $this->Security->requireSecure(); $notAccess = ['Gerentes','mp','Comercios']; //Restringir acceso if(in_array($this->Auth->user('group.layout'),$notAccess)) { $this->Auth->logout(); } //Defino que layout usar según el tipo de usuario if (!is_null($this->Auth->user('group.layout'))) { $this->viewBuilder()->theme($this->Auth->user('group.layout')); } //Si es una pc de caja $SysComputers = TableRegistry::get('SysComputers'); $this->request->trustProxy = true; $pcPos = $SysComputers->find('all')->where(['ip'=>$this->request->clientIp()])->matching('SysPos')->toArray(); if (count($pcPos)>0) { $this->viewBuilder()->theme("Cajeros"); } //$this->viewBuilder()->theme("Cajeros"); #quitar, solo para prueba $this->set('user', $this->Auth->user()); } /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { $Plans = TableRegistry::get("Plans"); $getPlans = $Plans->find('list',['order'=>['oldid ASC'],'keyField' => 'id', 'valueField' => 'OldidName'])->where(['activo'=>1]); $hoy = date('Y-m-d'); $Campaigns = TableRegistry::get("Campaigns"); $getCampaigns = $Campaigns->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->order(['created DESC']); $Procedures = TableRegistry::get("Procedures"); $getProcedures = $Procedures->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->andWhere(['procedure_status_id'=> 3]) ->order(['created DESC']); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->set(compact(['getPlans','getCampaigns','getProcedures','busCompany'])); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml']) ) { $this->set('_serialize', true); } } public function forceSSL() { //return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here); //$this->request->getRequestTarget() } protected function _verifyTheme() { if($this->theme!=='Cajeros') { if($this->Auth->user('group_id')!='fe0cdb34-ed20-4416-a35c-a694a07505ca'&&$this->Auth->user('group_id')!='f3820488-acac-4991-96fd-aa5bccec5311') { $this->Flash->error(__('No puede acceder a Caja desde esta PC')); return $this->redirect(['controller'=>'pages','action' => 'home']); } } } protected function _verifyDrawerStatus($drawer_id) { $AccountingDrawerStatus = TableRegistry::get('AccountingDrawerStatus'); $lastStatus = $AccountingDrawerStatus->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['id DESC']) ->first(); return $lastStatus->status; } protected function _verifyDrawerBalance($drawer_id) { $Accountings = TableRegistry::get('Accountings'); $accountings = $Accountings->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['date DESC']) ->first(); $return = false; if(@$accountings->balance>1000) { $return = true; } return true; //$return; **revisar** } protected function _calculaDisponible($iTotal=null) { $AccountTypes = TableRegistry::get('AccountTypes'); $accountTypes = $AccountTypes->find('all') ->contain(['Products']) ->where([':iTotal BETWEEN salary_from AND salary_to']) ->bind(':iTotal', $iTotal, 'decimal') ->toArray()[0]; $a = $accountTypes['affect_amount']>0?$accountTypes['affect_amount']:($iTotal * $accountTypes['affect_percent']); $q = $accountTypes['term']; $i = $accountTypes['interest']; $m = $a * $q; $c = $accountTypes['max_amount']>0?$accountTypes['max_amount']:$m/(1+($i*$q)); $d = $accountTypes['affect_quote_amount']>0?$accountTypes['affect_quote_amount']:($iTotal*$accountTypes['affect_quote']); $accountTypes['a'] = $a; $accountTypes['c'] = $c; $accountTypes['d'] = $d; return $accountTypes; } protected function _getLatLong($address=null){ $return = false; if(!empty($address)) { $formattedAddr = str_replace(' ','+',$address); $geocodeFromAddr = "";//file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false&key=AIzaSyBaupPCi2LeR7xf_bx3xWckBDBRXDLmvGI'); $output = json_decode($geocodeFromAddr); $data['place_id'] = @$output->results[0]->place_id; $data['lat'] = @$output->results[0]->geometry->location->lat; $data['lng'] = @$output->results[0]->geometry->location->lng; if(!empty($data)) { $return = $data; } } return $return; } protected function groupArray($array,$groupkey) { if(count($array)>0) { $keys = array_keys($array[0]); $removekey = array_search($groupkey, $keys); if($removekey===false) { return array("Clave \"$groupkey\" no existe"); } else { unset($keys[$removekey]); } $groupcriteria = array(); $return=array(); foreach($array as $value) { $item=null; foreach ($keys as $key) { $item[$key] = $value[$key]; } $busca = array_search($value[$groupkey], $groupcriteria); if($busca === false) { $groupcriteria[]=$value[$groupkey]; $return[]=array($groupkey=>$value[$groupkey],'result'=>array()); $busca=count($return)-1; } $return[$busca]['result'][]=$item; } return $return; } else { return array(); } } } [ 'className' => 'Acl.Acl' ] ]; /** * Initialization hook method. * * Use this method to add common initialization code like loading components. * * e.g. `$this->loadComponent('Security');` * * @return void */ public function initialize() { if(@$this->request->getData('branch')) { $this->db = $this->request->getData('branch'); } parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => ['Form'=> ['contain' => ['Groups','Profiles'=>['Commerces']]]], 'authorize' => [ 'Acl.Actions' => ['actionPath' => 'controllers/'] ], 'loginAction' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'loginRedirect' => [ 'plugin' => false, 'controller' => 'pages', 'action' => 'home' ], 'logoutRedirect' => [ 'plugin' => false, 'controller' => 'Users', 'action' => 'login' ], 'unauthorizedRedirect' => [ 'controller' => 'Users', 'action' => 'login', 'prefix' => false ], 'authError' => 'No puede acceder a esta área', 'flash' => [ 'element' => 'error' ] ]); $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']); } public function beforeFilter(Event $event) { if(!is_null($this->Auth->user('setBranch'))) { $this->db = $this->Auth->user('setBranch'); } $dbSelected = 'orcu_'.$this->db; ConnectionManager::drop('default'); ConnectionManager::setConfig('default', [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost', 'username' => 'orcusisdb', 'password' => 'orcusis@db#2018', 'database' => $dbSelected, 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, ]); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->PTOVTA = $busCompany['PTOVTA']; $this->Security->requireSecure(); $notAccess = ['Gerentes','mp','Comercios']; //Restringir acceso if(in_array($this->Auth->user('group.layout'),$notAccess)) { $this->Auth->logout(); } //Defino que layout usar según el tipo de usuario if (!is_null($this->Auth->user('group.layout'))) { $this->viewBuilder()->theme($this->Auth->user('group.layout')); } //Si es una pc de caja $SysComputers = TableRegistry::get('SysComputers'); $this->request->trustProxy = true; $pcPos = $SysComputers->find('all')->where(['ip'=>$this->request->clientIp()])->matching('SysPos')->toArray(); if (count($pcPos)>0) { $this->viewBuilder()->theme("Cajeros"); } //$this->viewBuilder()->theme("Cajeros"); #quitar, solo para prueba $this->set('user', $this->Auth->user()); } /** * Before render callback. * * @param \Cake\Event\Event $event The beforeRender event. * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { $Plans = TableRegistry::get("Plans"); $getPlans = $Plans->find('list',['order'=>['oldid ASC'],'keyField' => 'id', 'valueField' => 'OldidName'])->where(['activo'=>1]); $hoy = date('Y-m-d'); $Campaigns = TableRegistry::get("Campaigns"); $getCampaigns = $Campaigns->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->order(['created DESC']); $Procedures = TableRegistry::get("Procedures"); $getProcedures = $Procedures->find('all') ->where(['date_start <='=>$hoy, 'date_end >='=>$hoy]) ->andWhere(['procedure_status_id'=> 3]) ->order(['created DESC']); $BusCompanies = TableRegistry::get("BusCompanies"); $busCompany = $BusCompanies->find('all')->first(); $this->set(compact(['getPlans','getCampaigns','getProcedures','busCompany'])); if (!array_key_exists('_serialize', $this->viewVars) && in_array($this->response->type(), ['application/json', 'application/xml']) ) { $this->set('_serialize', true); } } public function forceSSL() { //return $this->redirect('https://' . env('SERVER_NAME') . $this->request->here); //$this->request->getRequestTarget() } protected function _verifyTheme() { if($this->theme!=='Cajeros') { if($this->Auth->user('group_id')!='fe0cdb34-ed20-4416-a35c-a694a07505ca'&&$this->Auth->user('group_id')!='f3820488-acac-4991-96fd-aa5bccec5311') { $this->Flash->error(__('No puede acceder a Caja desde esta PC')); return $this->redirect(['controller'=>'pages','action' => 'home']); } } } protected function _verifyDrawerStatus($drawer_id) { $AccountingDrawerStatus = TableRegistry::get('AccountingDrawerStatus'); $lastStatus = $AccountingDrawerStatus->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['id DESC']) ->first(); return $lastStatus->status; } protected function _verifyDrawerBalance($drawer_id) { $Accountings = TableRegistry::get('Accountings'); $accountings = $Accountings->find('all') ->where(['accounting_drawer_id'=>$drawer_id]) ->order(['date DESC']) ->first(); $return = false; if(@$accountings->balance>1000) { $return = true; } return true; //$return; **revisar** } protected function _calculaDisponible($iTotal=null) { $AccountTypes = TableRegistry::get('AccountTypes'); $accountTypes = $AccountTypes->find('all') ->contain(['Products']) ->where([':iTotal BETWEEN salary_from AND salary_to']) ->bind(':iTotal', $iTotal, 'decimal') ->toArray()[0]; $a = $accountTypes['affect_amount']>0?$accountTypes['affect_amount']:($iTotal * $accountTypes['affect_percent']); $q = $accountTypes['term']; $i = $accountTypes['interest']; $m = $a * $q; $c = $accountTypes['max_amount']>0?$accountTypes['max_amount']:$m/(1+($i*$q)); $d = $accountTypes['affect_quote_amount']>0?$accountTypes['affect_quote_amount']:($iTotal*$accountTypes['affect_quote']); $accountTypes['a'] = $a; $accountTypes['c'] = $c; $accountTypes['d'] = $d; return $accountTypes; } protected function _getLatLong($address=null){ $return = false; if(!empty($address)) { $formattedAddr = str_replace(' ','+',$address); $geocodeFromAddr = "";//file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.$formattedAddr.'&sensor=false&key=AIzaSyBaupPCi2LeR7xf_bx3xWckBDBRXDLmvGI'); $output = json_decode($geocodeFromAddr); $data['place_id'] = @$output->results[0]->place_id; $data['lat'] = @$output->results[0]->geometry->location->lat; $data['lng'] = @$output->results[0]->geometry->location->lng; if(!empty($data)) { $return = $data; } } return $return; } protected function groupArray($array,$groupkey) { if(count($array)>0) { $keys = array_keys($array[0]); $removekey = array_search($groupkey, $keys); if($removekey===false) { return array("Clave \"$groupkey\" no existe"); } else { unset($keys[$removekey]); } $groupcriteria = array(); $return=array(); foreach($array as $value) { $item=null; foreach ($keys as $key) { $item[$key] = $value[$key]; } $busca = array_search($value[$groupkey], $groupcriteria); if($busca === false) { $groupcriteria[]=$value[$groupkey]; $return[]=array($groupkey=>$value[$groupkey],'result'=>array()); $busca=count($return)-1; } $return[$busca]['result'][]=$item; } return $return; } else { return array(); } } }