| Server IP : 162.214.74.102 / Your IP : 216.73.217.103 Web Server : Apache System : Linux dedi-4363141.lrsys.com.br 3.10.0-1160.119.1.el7.tuxcare.els25.x86_64 #1 SMP Wed Oct 1 17:37:27 UTC 2025 x86_64 User : lrsys ( 1015) PHP Version : 5.6.40 Disable Function : exec,passthru,shell_exec,system MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/lrsys/public_html/lrsys_apps/imobles/application/plugins/module_hr/controllers/ |
Upload File : |
<?php
_auth();
$dir = "application/plugins/module_hr";
$ui->assign('_application_menu', "module_hr");
$ui->assign('_title', $_L['HR module'] . ' - ' . $config['CompanyName']);
$action = $routes['2'];
$user = User::_info();
$ui->assign('user', $user);
$ui->assign('_st', $_L['HR module']);
switch ($action) {
case 'point':
$gs = ORM::for_table('module_hr_points')
->raw_query('select max(id) as id
from module_hr_points a
where func = 1000')
->find_many();
if (!empty($gs[0]['id'])) {
$gs = ORM::for_table('module_hr_points')
->raw_query('select id,
cast(a.date as date) as date_,
a.time_entry as entry_,
a.time_out as out_
from module_hr_points a
where func = 1000
and id = ' . $gs[0]['id'] . '
group by id')
->find_many();
if (empty($gs[0]['out_'])) {
$ui->assign('status', $_L['Out Point']);
$ui->assign('id_point', $gs[0]['id']);
} else {
$ui->assign('status', $_L['Entry Point']);
$ui->assign('id_point', '');
}
} else {
$ui->assign('status', $_L['Entry Point']);
$ui->assign('id_point', '');
}
$mode_css = Asset::css('footable/css/footable.core.min');
$mode_js = Asset::js(array('footable/js/footable.all.min', 'contacts/mode_search'));
$ui->assign('xheader', $mode_css . '<link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/bottom_bar.css"/><link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/default.css">');
$ui->assign('xfooter', $mode_js .
'<script type="text/javascript" src="' . $dir . '/assets/js/canvas_clock.js"></script><script type="text/javascript" src="' . $dir . '/assets/js/points.js"></script>' . '<script type="text/javascript" src="' . $dir . '/assets/js/bottom_bar.js"></script>');
$allPoints = ORM::for_table('module_hr_points')->where('func', 1000)->find_array();
$ui->assign('allPoints', $allPoints);
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
');
$paginator = Paginator::bootstrap('module_hr_points');
$valMax = ORM::for_table('module_hr_points')
->raw_query('select SUM(timediff(time_out, time_entry)) AS hrs
from module_hr_points
where func = 1000')
->find_many();
$ui->assign('config', $config);
$ui->assign('dir', $dir);
$ui->assign('totalSalary', $valMax[0]['hrs']);
$ui->assign('qtdFuncs', 2);
$ui->assign('paginator', $paginator);
$ui->assign('_include', $action);
$ui->display('wrapper.tpl');
break;
case 'sector':
// find all groups
$gs = ORM::for_table('module_hr_sectors')->order_by_asc('name')->find_array();
$ui->assign('gs', $gs);
$ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/sectors.js">');
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
');
$ui->assign('_include', $action);
$ui->display('wrapper.tpl');
break;
case 'function':
// find all groups
$gs = ORM::for_table('module_hr_functions')->order_by_asc('name')->find_array();
$ui->assign('gs', $gs);
$ui->assign('xfooter', '<script type="text/javascript" src="' . $dir . '/assets/js/functions.js">');
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
');
$ui->assign('_include', $action);
$ui->display('wrapper.tpl');
break;
case 'list':
$name = _post('name');
$mode_css = '';
$mode_js = '';
if ($config['contact_set_view_mode'] == 'search') {
// Foo Table
$mode_css = Asset::css(array('../../application/plugins/module_hr/assets/css/default',
's2/css/select2.min'));
$mode_js = Asset::js(array(
's2/js/select2.min',
// 'footable/js/footable.all.min',
// 'contacts/mode_search',
'../../application/plugins/module_hr/assets/js/list'));
$filter = array();
$filter['items_per_page'] = 10;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$filter['search'] = filter_var(_post('search'), FILTER_SANITIZE_STRING);
$filter['items_per_page'] = filter_var(_post('items_per_page'), FILTER_SANITIZE_STRING);
$filter['sector'] = filter_var(_post('sector'), FILTER_SANITIZE_STRING);
$filter['function'] = filter_var(_post('function'), FILTER_SANITIZE_STRING);
} else {
if ($i = array_search('search', $routes))
$filter['search'] = filter_var($routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('items_per_page', $routes))
$filter['items_per_page'] = filter_var($routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('sector', $routes))
$filter['sector'] = filter_var($routes[$i + 1], FILTER_SANITIZE_STRING);
if ($i = array_search('function', $routes))
$filter['function'] = filter_var($routes[$i + 1], FILTER_SANITIZE_STRING);
}
$select = "SELECT
c.*, cd.func_salary, hs.name as sector, hf.name as function
FROM
crm_accounts as c
LEFT JOIN crm_accounts_groups g ON (g.crm_accounts_id = c.id)
LEFT JOIN module_hr_compl_data cd ON (c.id = cd.func)
JOIN module_hr_sectors hs ON (hs.id = cd.func_sector)
JOIN module_hr_functions hf ON (hf.id = cd.func_carg)
WHERE g.crm_group_id = 5 ";
$where = "";
// Filtro pelo grupo
if (isset($filter['sector']) && $filter['sector'] > 0)
{
$where .= ' AND hf.id = '.$filter['sector'];
}
// Filtro pela função
if (isset($filter['function']) && $filter['function'] > 0)
{
$where .= ' AND hf.id = '.$filter['function'];
}
// Filtro pelo campo de busca
if (isset($filter['search']) && $filter['search'] != '') {
$where .= " AND (c.account LIKE '%" . $filter['search'] . "%'
OR c.company LIKE '%" . $filter['search'] . "%'
OR c.code LIKE '%" . $filter['search'] . "%'
OR c.cpf_cnpj LIKE '%" . $filter['search'] . "%')";
}
$group_by = " ";
$order_by = " ORDER BY c.account ASC ";
$query = $select . $where . $group_by . $order_by;
// print_r($query);exit;
// pego o filtro
if ($filter['items_per_page'] != 'all')
$filter['items_per_page'] = ($filter['items_per_page'] > 0) ? $filter['items_per_page'] : 10;
// pego a pagina atual
$page = isset($routes['3']) ? $routes['3'] : 1;
// var_dump($routes['2']);exit;
// pego o total de registros
$select_count = "SELECT
COUNT(c.id) as count
FROM
crm_accounts as c";
$query_count = $select_count . $where;
$totalItems = 0;
$totalItems_aux = ORM::for_table('crm_accounts')->raw_query($query)->find_one();
if($totalItems_aux)
{
$totalItems = $totalItems_aux->count;
}
// var_dump($totalItems);exit;
$paginator = new ModulePaginator('crm_accounts', $query, $filter);
$d = $paginator->setItemsPerPage($filter['items_per_page'])
->setCurrentPageNumber($page)
->setTotalItems($totalItems)
->run();
// pego o nome do setor
if(isset($filter['sector']) && $filter['sector'] > 0)
{
$grupo = ORM::for_table('module_hr_sectors')->find_one($filter['sector']);
$ui->assign('filter_sector', $grupo->name);
}
// pego o nome da função
if(isset($filter['function']) && $filter['function'] > 0)
{
$grupo = ORM::for_table('module_hr_functions')->find_one($filter['function']);
$ui->assign('filter_function', $grupo->name);
}
} elseif ($name != '') {
$paginator = Paginator::bootstrap('crm_accounts', 'account', '%' . $name . '%');
$d = ORM::for_table('crm_accounts')->where_like('account', '%' . $name . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} elseif (isset($routes[2]) AND ( $routes[2]) != '' AND ( !is_numeric($routes[2]))) {
$tags = $routes[2];
$paginator['contents'] = '';
$d = ORM::for_table('crm_accounts')->where_like('tags', '%' . $tags . '%')->order_by_desc('id')->find_many();
} else {
$paginator = Paginator::bootstrap('crm_accounts');
$d = ORM::for_table('crm_accounts')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
// $totalFuncsQtd = ORM::for_table('crm_accounts')
// ->table_alias('c')
// ->select('c.*')
// ->left_outer_join('crm_accounts_groups', array('c.id', '=', 'g.crm_accounts_id'), 'g')
// ->where('g.crm_group_id', 5)
// ->order_by_desc('id')->find_array();
$qtdFuncs = sizeof($d);
$valMax = ORM::for_table('module_hr_compl_data')
->raw_query('select CAST( SUM(func_salary) AS DECIMAL(10,2)) as qtd
from module_hr_compl_data')
->find_many();
$sum_salario = 0;
foreach ($d as $func)
{
$sum_salario += $func['func_salary'];
}
$totalSalary = $sum_salario;
$ui->assign('d', $d);
$ui->assign('config', $config);
$ui->assign('dir', $dir);
$ui->assign('totalSalary', $totalSalary);
$ui->assign('qtdFuncs', $qtdFuncs);
$ui->assign('paginator', $paginator);
$ui->assign('filter', $filter);
$ui->assign('xheader', $mode_css . '<link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/bottom_bar.css"/>');
$ui->assign('xfooter', $mode_js .
'<script type="text/javascript" src="' . $_theme . '/lib/list-contacts.js"></script>' . '<script type="text/javascript" src="' . $dir . '/assets/js/bottom_bar.js"></script>');
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
');
// pego o setor do funcionário
$sectors = ORM::for_table('module_hr_sectors')->find_many();
$ui->assign('sector', $sectors);
// pego a função do funcionário
$grupos = ORM::for_table('module_hr_functions')->find_many();
$ui->assign('function', $grupos);
$ui->assign('_include', $action);
$ui->display('wrapper.tpl');
break;
case 'add':
$css_arr = array('s2/css/select2.min', 'modal', 'dp/dist/datepicker.min', 'redactor/redactor');
$js_arr = array('redactor/redactor.min', 'modal', 'numeric', 'modal-add-contact', 's2/js/select2.min', 's2/js/i18n/' . lan(), 'dp/dist/datepicker.min', '/../../theme/lrsys/lib/jquery.maskMoney.min', 'dp/i18n/' . $config['language'], 'add-contact');
$roles = Model::factory('Models_Role')->find_array();
$ui->assign('roles', $roles);
$ui->assign('xheader', Asset::css($css_arr) . '<link rel="stylesheet" type="text/css" href="' . $dir . '/assets/css/default.css"><link rel="stylesheet" type="text/css" href="ui/lib/dropzone/dropzone.css">');
$ui->assign('xfooter', Asset::js($js_arr) . '<script type="text/javascript" src="' . $dir . '/assets/js/default.js"></script><script type="text/javascript" src="ui/lib/dropzone/dropzone.js"></script>');
//CARREGA A LISTA DE estados
$e = ORM::for_table('state')->order_by_asc('state_name')->find_many();
$cost_center = ORM::for_table('module_billing_cost_center')->order_by_asc('name')->find_many();
$ui->assign('state', $e);
$ui->assign('cost_center', $cost_center);
$ui->assign('screen', '1');
$ui->assign('_include', $action);
// CUSTOMIZAÇÃO_HEXAGON
$products_category = ORM::for_table('sys_items_category')->order_by_asc('name')->find_many();
$ui->assign('products_category', $products_category);
$ui->display('wrapper.tpl');
break;
case 'add-post':
$msg = '';
if (empty(_post('dt'))) {
$data_compl = ORM::for_table('module_hr_compl_data')->create();
$d = ORM::for_table('crm_accounts')->create();
$userNew=false;
} else {
$data_compl = ORM::for_table('module_hr_compl_data')->where('func', _post('dt'))->find_one();
$d = ORM::for_table('crm_accounts')->find_one($data_compl->func);
$userNew = ORM::for_table('sys_users')
->where('crm_accounts_id', $data_compl->func)
->find_one();
}
$d->account = _post('account');
$d->kind_of_person = null;
$d->company = null;
$d->code = _post('code');
$d->cpf_cnpj = _post('cpf');
$cpfCnpjTipo = 'CPF';
$d->country = 'Brazil';
$d->rg = _post('rg');
if (!empty(_post('date_of_birth')))
$d->date_of_birth = implode("-", array_reverse(explode("/", _post('date_of_birth'))));
if ($d->currency == '')
$d->currency = '0';
$password = _post('password');
$cpassword = _post('cpassword');
$u_password = '';
//valida tamanho da senha
if ($password != '') {
if (!Validator::Length($password, 15, 5)) {
$msg .= $_L['Password should be between 6 to 15 characters'] . '<br>';
}
$u_password = $password;
$password = Password::_crypt($password);
}
$d->foreign_doc_identification = null;
$d->taxpayer = null;
$d->ie = null;
$d->im = null;
$d->email = _post('email');
$d->email_nfe = null;
$d->phone = _post('phone');
$d->fax = _post('fax');
$d->cell_phone = _post('cell_phone');
$d->web_site = _post('web_site');
$d->currency = null;
$d->country = null;
$d->notes = null;
$d->marital_status = null;
$d->jobtitle = null;
$d->sex = _post('sex');
$d->crt = null;
$d->inscription_suframa = null;
$d->credit_limit = null;
// LEONARDO LOPES
// 02/06/2020
// Centro de Custo
$d->cost_center_id = _post('cost_center');
if ($d->account == '') {
$msg .= $_L['Name'] . $_L['is required'];
}
$acessToAdmin = empty(_post('acess_admin'))?'N': _post('acess_admin');
if($acessToAdmin=='Y'){
$adm = ORM::for_table('sys_users')->where('username', _post('email'))->find_one();
if ($adm)
{
if ($userNew == false || $adm->id != $userNew->id)
$msg .= $_L['account_already_exist'] . '<br>';
}
if (empty(_post('email'))) {
$msg .= $_L['Email'] . $_L['is required'];
}
if($acessToAdmin=='Y' && empty($password) && $userNew == false){
$msg .= $_L['Password'] . $_L['is required'];
}
}
if ($d->cpf_cnpj != '') {
$f = ORM::for_table('crm_accounts')->where('cpf_cnpj', $d->cpf_cnpj)->find_one();
if ($f && empty(_post('dt'))) {
$msg .= $d->cpf_cnpj . $_L['Exists'] . ' <br>';
}
} else {
// $msg .= 'CPF ' . $_L['is required'];
}
if ($msg != '') {
echo ($msg);
die();
} else {
if (!empty($password))
$d->password = $password;
$d->fname = '';
$d->lname = '';
$d->cid = '0';
$d->o = '0';
$d->balance = '0.00';
$d->status = 'Active';
$d->token = '';
$d->ts = '';
$d->web = '';
$d->facebook = '';
$d->google = '';
$d->linkedin = '';
$d->father_name = _post('father_name');
$d->mother_name = _post('mother_name');
$d->save();
//Pega id func
$cid = $d->id();
//salva os grupos para o Funcionário
ORM::for_table('crm_accounts_groups')->where('crm_accounts_id',$cid)->where_not_equal('crm_group_id',5)->delete_many();
if (isset($_POST['group'])) {
$group = $_POST['group'];
if (!empty($group)) {
foreach ($group as $g) {
if($g != 5)
{
$dataGroup = ORM::for_table('crm_accounts_groups')->create();
$dataGroup->crm_accounts_id = $cid;
$dataGroup->crm_group_id = $g;
$dataGroup->save();
}
}
}
}
if (empty(_post('dt'))) {
$dataGroup = ORM::for_table('crm_accounts_groups')->create();
$dataGroup->crm_accounts_id = $cid;
$dataGroup->crm_group_id = 5;
$dataGroup->save();
}
//salva o endereço do funcionario
if (empty(_post('dt'))) {
$address = ORM::for_table('crm_accounts_address')->create();
} else {
$address = ORM::for_table('crm_accounts_address')->where('crm_account_id', _post('dt'))->find_one();
}
//recebe os dados do endereço
if (intval(_post('state'))) {
$address->state_id = _post('state');
}
if (intval(_post('city')) > 0) {
$address->city_id = _post('city');
}
$address->zip = _post('zip');
$address->address = _post('address');
$address->neighborhood = _post('neighborhood');
$address->number = _post('number');
$address->complement = _post('complement');
$address->type_address = "tax_address";
$address->crm_account_id = $cid;
$address->save();
//Validar se o usuário vai receber email
// $send_client_signup_email = _post('send_client_signup_email');
// if (($d->email != '') && ($send_client_signup_email == 'Yes') && ($u_password != '')) {
// $email_data = array();
// $email_data['account'] = $d->account;
// $email_data['company'] = $d->company;
// $email_data['password'] = $u_password;
// $email_data['email'] = $d->email;
// $send_email = Ib_Email::send_client_welcome_email($email_data);
// }
//--Inicio dados complementares..
if (!empty(_post('dt_ctps'))) {
$dtCtps = implode("-", array_reverse(explode("/", _post('dt_ctps'))));
} else {
$dtCtps = NULL;
}
if (!empty(_post('func_dt_admss'))) {
$dtAdmss = implode("-", array_reverse(explode("/", _post('func_dt_admss'))));
} else {
$dtAdmss = NULL;
}
$civil = (_post('civil')) ? intval(_post('civil')) : null;
$skin = (_post('skin')) ? intval(_post('skin')) : null;
$sector_m = (_post('sector_m')) ? intval(_post('sector_m')) : null;
$function_m = (_post('function_m')) ? intval(_post('function_m')) : null;
$num_reservista = (_post('num_reservista')) ? intval(_post('num_reservista')) : null;
$num_ctps = (_post('num_ctps')) ? intval(_post('num_ctps')) : null;
$uf_ctps = (_post('uf_ctps')) ? intval(_post('uf_ctps')) : null;
$pis = (_post('pis')) ? intval(_post('pis')) : null;
$rg_uf = (_post('rg_uf')) ? intval(_post('rg_uf')) : null;
$dgr_instruction = (_post('dgr_instruction')) ? intval(_post('dgr_instruction')) : null;
$num_titulo_eleit = (_post('num_titulo_eleit')) ? intval(_post('num_titulo_eleit')) : null;
$cnh = (_post('cnh')) ? intval(_post('cnh')) : null;
$cat_cnh = (_post('cat_cnh')) ? intval(_post('cat_cnh')) : null;
$bank = (_post('bank')) ? intval(_post('bank')) : null;
$bank_cc = (_post('bank_cc')) ? intval(_post('bank_cc')) : null;
$bank_dg = (_post('bank_dg')) ? intval(_post('bank_dg')) : null;
$bank_ag = (_post('bank_ag')) ? intval(_post('bank_ag')) : null;
$payment_type = (_post('payment_type')) ? intval(_post('payment_type')) : null;
$cost_center = (_post('cost_center')) ? intval(_post('cost_center')) : null;
$data_compl->func = $cid;
$data_compl->civil = $civil;
$data_compl->skin = $skin;
$data_compl->func_sector = $sector_m;
$data_compl->func_carg = $function_m;
$data_compl->func_salary = Finance::amount_fix(_post('func_salary'));
$data_compl->sales_comission = Finance::amount_fix(_post('sales_comission'));
$data_compl->profission = _post('profission');
$data_compl->registry_advice = _post('registry-advice');
$data_compl->registry_uf = _post('registry-uf');
$data_compl->registry_desc = _post('registry_desc');
$data_compl->obs_registry_professional = _post('obs_registry_professional');
$data_compl->naturalit = _post('naturalit');
$data_compl->nationalit = _post('nationalit');
$data_compl->name_conj = _post('name_conj');
$data_compl->cpf_conj = _post('cpf_conj');
$data_compl->num_reservista = $num_reservista;
$data_compl->num_ctps = $num_ctps;
$data_compl->ser_ctps = _post('ser_ctps');
$data_compl->uf_ctps = $uf_ctps;
$data_compl->dt_ctps = $dtCtps;
$data_compl->pis = $pis;
$data_compl->rg_org_emiss = _post('rg_org_emiss');
$data_compl->rg_uf = $rg_uf;
$data_compl->rg_dt_emiss = $dtCtps;
$data_compl->dgr_instruction = $dgr_instruction;
$data_compl->num_titulo_eleit = $num_titulo_eleit;
$data_compl->zon_titulo_eleit = _post('zon_titulo_eleit');
$data_compl->sec_titulo_eleit = _post('sec_titulo_eleit');
$data_compl->cnh = $cnh;
$data_compl->cat_cnh = $cat_cnh;
$data_compl->bank = $bank;
$data_compl->bank_cc = $bank_cc;
$data_compl->bank_dg = $bank_dg;
$data_compl->bank_ag = $bank_ag;
$data_compl->func_dt_admss = $dtAdmss;
$data_compl->cost_center = $cost_center;
$data_compl->payment_type = $payment_type;
// LEONARDO LOPES RAMOS
// AJUSTE PARA MÓDULO DE AGENDAMENTO
$data_compl->cbos = _post('cbos');
$data_compl->cnes = _post('cnes');
// LEONARDO LOPES RAMOS
// AJUSTE PARA MÓDULO DE HELPDESK
$products_category = null;
if(isset($_POST['products_category']))
{
$products_category = json_encode($_POST['products_category']);
}
$data_compl->product_category = $products_category;
$data_compl->save();
//Trata filhos
if (_post('qtd_sun') > 0) {
$qtd = _post('qtd_sun');
$id = 1;
$del = ORM::for_table('module_hr_suns')->where('func', $cid)->delete_many();
while ($qtd > 0) {
$data_suns = ORM::for_table('module_hr_suns')->create();
$data_suns->func = $cid;
$data_suns->nome = _post('nm_sun_' . $id);
if (!empty(_post('dt_sun_' . $id))) {
$dtSun = implode("-", array_reverse(explode("/", _post('dt_sun_' . $id))));
} else {
$dtSun = NULL;
}
$data_suns->nascto_dt = $dtSun;
$data_suns->nascto_local = _post('lcl_sun_' . $id);
$data_suns->livro = _post('liv_sun_' . $id);
$data_suns->cartorio = _post('car_sun_' . $id);
$data_suns->registro = _post('reg_sun_' . $id);
$data_suns->save();
$qtd--;
$id++;
}
}
// Deleto a grade de trabalho antiga
ORM::for_table('module_hr_job_journey')->where('func', $cid)->delete_many();
//Adiciona o horário de trabalho
if (_post('ind_dom')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_dom_ini_mn');
$data_times->hr_fim_manha = _post('hr_dom_fim_mn');
$data_times->hr_ini_tarde = _post('hr_dom_ini_tr');
$data_times->hr_fim_tarde = _post('hr_dom_fim_tr');
$data_times->ind_dia = 0;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_seg')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_seg_ini_mn');
$data_times->hr_fim_manha = _post('hr_seg_fim_mn');
$data_times->hr_ini_tarde = _post('hr_seg_ini_tr');
$data_times->hr_fim_tarde = _post('hr_seg_fim_tr');
$data_times->ind_dia = 1;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_ter')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_ter_ini_mn');
$data_times->hr_fim_manha = _post('hr_ter_fim_mn');
$data_times->hr_ini_tarde = _post('hr_ter_ini_tr');
$data_times->hr_fim_tarde = _post('hr_ter_fim_tr');
$data_times->ind_dia = 2;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_qua')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_qua_ini_mn');
$data_times->hr_fim_manha = _post('hr_qua_fim_mn');
$data_times->hr_ini_tarde = _post('hr_qua_ini_tr');
$data_times->hr_fim_tarde = _post('hr_qua_fim_tr');
$data_times->ind_dia = 3;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_qui')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_qui_ini_mn');
$data_times->hr_fim_manha = _post('hr_qui_fim_mn');
$data_times->hr_ini_tarde = _post('hr_qui_ini_tr');
$data_times->hr_fim_tarde = _post('hr_qui_fim_tr');
$data_times->ind_dia = 4;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_sex')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_sex_ini_mn');
$data_times->hr_fim_manha = _post('hr_sex_fim_mn');
$data_times->hr_ini_tarde = _post('hr_sex_ini_tr');
$data_times->hr_fim_tarde = _post('hr_sex_fim_tr');
$data_times->ind_dia = 5;
$data_times->func = $cid;
$data_times->save();
}
if (_post('ind_sab')) {
$data_times = ORM::for_table('module_hr_job_journey')->create();
$data_times->hr_ini_manha = _post('hr_sab_ini_mn');
$data_times->hr_fim_manha = _post('hr_sab_fim_mn');
$data_times->hr_ini_tarde = _post('hr_sab_ini_tr');
$data_times->hr_fim_tarde = _post('hr_sab_fim_tr');
$data_times->ind_dia = 6;
$data_times->func = $cid;
$data_times->save();
}
//imagens..
$files = ORM::for_table('module_hr_empl_files')
->where('id', _post('id_ref_imgs'))
->find_one();
if (!$files) {
$files = ORM::for_table('module_hr_empl_files')->create();
} else {
$files = ORM::for_table('module_hr_empl_files')
->find_one(_post('id_ref_imgs'));
}
$files->func = $cid;
$files->save();
// Verifico se tem acesso ao ADMIN
if ($acessToAdmin == 'Y') {
if (!$userNew) {
$userNew = ORM::for_table('sys_users')->create();
$userNew->creationdate = date('Y-m-d H:i:s');
$userNew->pin = '';
$userNew->img = '';
$userNew->otp = 'No';
$userNew->pin_enabled = 'No';
$userNew->api = 'No';
$userNew->pwresetkey = '';
$userNew->keyexpire = '';
$userNew->status = 'Active';
$userNew->crm_accounts_id = $cid;
}
$r = Model::factory('Models_Role')->find_one(_post('user_role'));
$role = $r->rname;
$roleid = _post('user_role');
$user_type = $r->rname;
// Add Account
$userNew->username = _post('email');
if(!empty($password)){
$userNew->password = $password;
}
$userNew->fullname = _post('account');
$userNew->user_type = $user_type;
$userNew->role = $role;
$userNew->roleid = $roleid;
$userNew->email = _post('email');
$userNew->save();
}
else
{
if ($userNew)
{
$userNew->delete();
}
}
echo "OK_" . $files->id;
}
break;
case 'sectors':
$gs = ORM::for_table('module_hr_sectors')->find_many();
foreach ($gs as $g) {
$data[] = array(
'id' => $g->id,
'name' => $g->name
);
}
echo json_encode($data);
break;
case 'add-sector':
$sector_name = _post('sector_name');
if ($sector_name != '') {
$c = ORM::for_table('module_hr_sectors')->where('name', $sector_name)->find_one();
if ($c) {
ib_die("Setor já cadastrado.");
}
$d = ORM::for_table('module_hr_sectors')->create();
$d->name = $sector_name;
$d->save();
echo $d->id();
} else {
echo "Favor inserir o nome do Setor";
}
break;
case 'edit-sector':
$id = _post('id');
$id = str_replace('e', '', $id);
$gname = _post('gname');
//grupos fixos no sistema não pode editar. validação para ação
$d = ORM::for_table('module_hr_sectors')->find_one($id);
if ($d) {
$d->name = $gname;
$d->save();
echo $d->id;
}
break;
case 'del-sector':
$id = $routes['3'];
$id = str_replace('g', '', $id);
$d = ORM::for_table('module_hr_sectors')->find_one($id);
if ($d) {
$d->delete();
}
r2(U . 'module_hr/hr/sector/', '', $_L['Data Deleted']);
break;
case 'add-function':
$function_name = _post('function_name');
if ($function_name != '') {
$c = ORM::for_table('module_hr_functions')->where('name', $function_name)->find_one();
if ($c) {
ib_die("Função já cadastrada.");
}
$d = ORM::for_table('module_hr_functions')->create();
$d->name = $function_name;
$d->save();
echo $d->id();
}
break;
case 'edit-function':
$id = _post('id');
$id = str_replace('e', '', $id);
$gname = _post('gname');
$d = ORM::for_table('module_hr_functions')->find_one($id);
if ($d) {
$d->name = $gname;
$d->save();
echo $d->id;
}
case 'functions':
$gs = ORM::for_table('module_hr_functions')->find_many();
foreach ($gs as $g) {
$data[] = array(
'id' => $g->id,
'name' => $g->name
);
}
echo json_encode($data);
break;
case 'del-function':
$id = $routes['3'];
$id = str_replace('g', '', $id);
$d = ORM::for_table('module_hr_functions')->find_one($id);
if ($d) {
$d->delete();
}
r2(U . 'module_hr/hr/function/', '', $_L['Data Deleted']);
break;
case 'empl-add-image':
$typeUpload = $routes['3'];
(isset($routes['4'])) ? $id = $routes['4'] : $id = "";
$uploader = new Uploader();
if ($typeUpload == 1) {
$typeFile = "empl_cnh";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 2) {
$typeFile = "empl_compr_escola";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 3) {
$typeFile = "empl_compr_residencia";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 4) {
$typeFile = "empl_cpf";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 5) {
$typeFile = "empl_ctps";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 6) {
$typeFile = "empl_exam_med_ocu";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 7) {
$typeFile = "empl_photos";
$uploader->setDir('application/storage/pics/');
} else if ($typeUpload == 8) {
$typeFile = "empl_reservist";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 9) {
$typeFile = "empl_rg";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 10) {
$typeFile = "empl_tit_eleitor";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
} else if ($typeUpload == 11) {
$typeFile = "empl_dig_signature";
$uploader->setDir($dir . '/uploads/' . $typeFile . '/');
}
$uploader->sameName(false);
$uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'pdf')); //allowed extensions list//
if ($uploader->uploadFile('file')) { //txtFile is the filebrowse element name //
$uploaded = $uploader->getUploadName(); //get uploaded file name, renames on upload//
$file = $uploaded;
$msg = "Envio concluído";
$success = 'Yes';
$files = ORM::for_table('module_hr_empl_files')
->where('id', $id)
->find_one();
if (!$files) {
$files = ORM::for_table('module_hr_empl_files')->create();
} else {
$files = ORM::for_table('module_hr_empl_files')
->find_one($id);
}
if ($typeUpload == 1) {
if ($files->file_cnh != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_cnh);
}
$files->file_cnh = $uploaded;
} else if ($typeUpload == 2) {
if ($files->file_compr_escolaridade != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_compr_escolaridade);
}
$files->file_compr_escolaridade = $uploaded;
} else if ($typeUpload == 3) {
if ($files->file_compr_residencia != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_compr_residencia);
}
$files->file_compr_residencia = $uploaded;
} else if ($typeUpload == 4) {
if ($files->file_cpf != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_cpf);
}
$files->file_cpf = $uploaded;
} else if ($typeUpload == 5) {
if ($files->file_ctps != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_ctps);
}
$files->file_ctps = $uploaded;
} else if ($typeUpload == 6) {
if ($files->file_ex_med_ocu_adm != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_ex_med_ocu_adm);
}
$files->file_ex_med_ocu_adm = $uploaded;
} else if ($typeUpload == 7) {
if ($files->file_pic_employe != "") {
// unlink($dir.'/uploads/'.$typeFile.'/'.$files->file_pic_employe);
unlink('application/storage/pics/' . $files->file_pic_employe);
}
$files->file_pic_employe = $uploaded;
if ($files->func != '') {
$d = ORM::for_table('crm_accounts')->find_one($files->func);
$d->img = 'application/storage/pics/' . $uploaded;
$d->save();
}
} else if ($typeUpload == 8) {
if ($files->file_reservista != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_reservista);
}
$files->file_reservista = $uploaded;
} else if ($typeUpload == 9) {
if ($files->file_rg != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_rg);
}
$files->file_rg = $uploaded;
} else if ($typeUpload == 10) {
if ($files->file_tit_eleitor != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_tit_eleitor);
}
$files->file_tit_eleitor = $uploaded;
} else if ($typeUpload == 11) {
if ($files->file_digit_signature != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_digit_signature);
}
$files->file_digit_signature = $uploaded;
}
$files->save();
$id = $files->id;
} else {//upload failed
$file = '';
$msg = $uploader->getMessage();
$success = 'No';
$id = '';
}
$a = array(
'success' => $success,
'msg' => $msg,
'file' => $file,
'id' => $id
);
header('Content-Type: application/json');
echo json_encode($a);
break;
case 'empl-delete-image':
$typeUpload = $routes['3'];
if ($typeUpload == 1) {
$typeFile = "empl_cnh";
} else if ($typeUpload == 2) {
$typeFile = "empl_compr_escola";
} else if ($typeUpload == 3) {
$typeFile = "empl_compr_residencia";
} else if ($typeUpload == 4) {
$typeFile = "empl_cpf";
} else if ($typeUpload == 5) {
$typeFile = "empl_ctps";
} else if ($typeUpload == 6) {
$typeFile = "empl_exam_med_ocu";
} else if ($typeUpload == 7) {
$typeFile = "empl_photos";
} else if ($typeUpload == 8) {
$typeFile = "empl_reservist";
} else if ($typeUpload == 9) {
$typeFile = "empl_rg";
} else if ($typeUpload == 10) {
$typeFile = "empl_tit_eleitor";
} else if ($typeUpload == 11) {
$typeFile = "empl_dig_signature";
}
$id = _post('id');
$files = ORM::for_table('module_hr_empl_files')
->find_one($id);
if ($typeUpload == 1) {
if ($files->file_cnh != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_cnh);
}
$files->file_cnh = '';
} else if ($typeUpload == 2) {
if ($files->file_compr_escolaridade != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_compr_escolaridade);
}
$files->file_compr_escolaridade = '';
} else if ($typeUpload == 3) {
if ($files->file_compr_residencia != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_compr_residencia);
}
$files->file_compr_residencia = '';
} else if ($typeUpload == 4) {
if ($files->file_cpf != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_cpf);
}
$files->file_cpf = '';
} else if ($typeUpload == 5) {
if ($files->file_ctps != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_ctps);
}
$files->file_ctps = '';
} else if ($typeUpload == 6) {
if ($files->file_ex_med_ocu_adm != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_ex_med_ocu_adm);
}
$files->file_ex_med_ocu_adm = '';
} else if ($typeUpload == 7) {
if ($files->file_pic_employe != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_pic_employe);
}
$files->file_pic_employe = '';
} else if ($typeUpload == 8) {
if ($files->file_reservista != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_reservista);
}
$files->file_reservista = '';
} else if ($typeUpload == 9) {
if ($files->file_rg != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_rg);
}
$files->file_rg = '';
} else if ($typeUpload == 10) {
if ($files->file_tit_eleitor != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_tit_eleitor);
}
$files->file_tit_eleitor = '';
} else if ($typeUpload == 11) {
if ($files->file_digit_signature != "") {
unlink($dir . '/uploads/' . $typeFile . '/' . $files->file_digit_signature);
}
$files->file_digit_signature = '';
}
$files->save();
$data = array(
'status' => "OK",
'msg' => "Arquivo removido.",
);
header('Content-Type: application/json');
echo json_encode($data);
break;
case 'add-point':
$point_time = _post('time');
$id = _post('id');
$c = Contacts::details();
if ($point_time != '') {
if ($id == "")
$d = ORM::for_table('module_hr_points')->create();
else
$d = ORM::for_table('module_hr_points')->create()->find_one($id);
if ($id == "")
$d->time_entry = $point_time;
else
$d->time_out = $point_time;
$d->func = $c['id'];
$d->save();
echo "OK";
} else {
echo "Favor inserir o horário!";
}
break;
case 'edit-point':
$id = _post('id');
$id = str_replace('e', '', $id);
$gname = _post('gname');
//grupos fixos no sistema não pode editar. validação para ação
$d = ORM::for_table('module_hr_sectors')->find_one($id);
if ($d) {
$d->name = $gname;
$d->save();
echo $d->id;
}
break;
case 'del-point':
$id = $routes['3'];
$id = str_replace('g', '', $id);
$d = ORM::for_table('module_hr_sectors')->find_one($id);
if ($d) {
$d->delete();
}
r2(U . 'module_hr/hr/sector/', '', $_L['Data Deleted']);
break;
default:
echo 'action not defined';
}