| Server IP : 162.214.74.102 / Your IP : 216.73.217.80 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/www/lrsys_apps/marisol/application/controllers/ |
Upload File : |
<?php
_auth();
$ui->assign('_application_menu', 'settings');
$ui->assign('_title', $_L['Unit'] . ' - ' . $config['CompanyName']);
$ui->assign('_st', $_L['Unit']);
$ui->assign('content_inner', inner_contents($config['c_cache']));
$action = $routes['1'];
$user = User::_info();
$ui->assign('user', $user);
switch ($action) {
case 'list':
$ui->assign('units', Unit::all());
$ui->assign('xfooter', Asset::js(array('unit')));
//seta o idioma para o js
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
_L[\'Int Value\'] = \'' . $_L['Int Value'] . '\';
_L[\'Save\'] = \'' . $_L['Save'] . '\';
_L[\'Yes\'] = \'' . $_L['Yes'] . '\';
_L[\'No\'] = \'' . $_L['No'] . '\';
');
$ui->display('list-unit.tpl');
break;
case 'add-post':
//recebe o nome do segmento para adicionar no banco de dados
$msg = "";
$name = _post('name');
$initials = _post('initials');
$int_value = empty(_post('int_value')) ? 0 : 1;
if (trim($name) == '') {
$msg = $_L['Unit Name'] . $_L['is required'];
}
if (trim($initials) == '') {
$msg = $_L['Unit Initials'] . $_L['is required'];
}
if (strlen($initials) > 6) {
$msg = $_L['Maximum initial size is 6 characters'];
}
if ($msg == '') {
//check same group already exist
$c = ORM::for_table('sys_items_unit')->where('initials', $initials)->find_one();
if ($c) {
ib_die($_L['A Unit with same initials already exist']);
}
$d = ORM::for_table('sys_items_unit')->create();
$d->name = $name;
$d->initials = $initials;
$d->int_value = $int_value;
$d->sorder = 0;
$d->save();
if(isset($routes['2'])&& $routes['2']=='no-msg'){
//VALIDAÇÃO PARA EXIBIR OU NAO MENSAGEM AO SALVAR
}else{
_notify($_L['Add Successfull'],'s');
}
echo $d->id();
} else {
echo $msg;
}
break;
case 'edit-post':
$id = _post('id');
$name = _post('name');
$initials = _post('initials');
$int_value = empty(_post('int_value')) ? 0 : 1;
$msg = "";
if ($name == '') {
$msg = $_L['Unit Name'] . $_L['is required'];
}
if ($initials == '') {
$msg = $_L['Unit Initials'] . $_L['is required'];
}
if (strlen($initials) > 6) {
$msg = $_L['Maximum initial size is 6 characters'];
}
if ($msg == '') {
$d = ORM::for_table('sys_items_unit')->find_one($id);
if ($d) {
if (!$d->default) {
$d->name = $name;
$d->initials = $initials;
$d->int_value = $int_value;
$d->save();
_notify($_L['Edited Successfull'],'s');
echo $d->id;
} else {
r2(U . 'unit/list/', 'e', $_L['Not permited edit this unit']);
}
} else {
echo $_L['Not found'];
}
} else {
echo $msg;
}
break;
///listagem ajax
case 'ajax-list':
//recebe o parametro do estado
$segment = ORM::for_table('sys_items_unit')->order_by_asc('sorder')->find_many();
foreach ($segment as $s) {
$data[] = array(
'id' => $s->id,
'int_value' => $s->int_value,
'name' => ($s->default) ? $_L[$s->name] : $s->name, //verifica se são os dados pre cadastrados que são traduzidos
'initials' => ($s->default) ? $_L[$s->initials] : $s->initials
);
}
echo json_encode($data);
break;
case 'delete':
$id = intval(str_replace('u', '', $routes[2]));
$d = ORM::for_table('sys_items_unit')->find_one($id);
if ($d) {
if (!$d->default) {
// find all items com a unidade
//se encontrar emite mensagem de impossibilidade de exclusão
$itens = ORM::for_table('sys_items')->raw_query(" select 1 from sys_items where commercial_unit_id = $id or tax_unit_id=$id ")->find_many();
if (count($itens) > 0) {
r2(U . 'unit/list/', 'e', $_L['Not permited remove this unit. Unit having Items']);
} else {
$d->delete();
_log($_L['Unit Deleted'] . " - " + $d->name, 'Admin', $user['id']);
r2(U . 'unit/list/', 's', $_L['Unit Deleted Successfully']);
}
} else {
r2(U . 'unit/list/', 'e', $_L['Not permited remove this unit']);
}
} else {
echo $_L['Not found'];
}
break;
default:
echo 'action not defined';
}