| 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/erp/application/controllers/ |
Upload File : |
<?php
_auth();
$ui->assign('_application_menu', 'settings');
$ui->assign('_title', $_L['Packing'] . ' - ' . $config['CompanyName']);
$ui->assign('_st', $_L['Packing']);
$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('packings', ProductPacking::all());
//adiciona os js necessários
$js_arr = array('jslib/product-packing', 'numeric');
$ui->assign('xfooter', Asset::js($js_arr));
//seta o idioma para o js
$ui->assign('jsvar', '
_L[\'are_you_sure\'] = \'' . $_L['are_you_sure'] . '\';
');
$ui->assign('xjq', '
$(\'.amount\').autoNumeric(\'init\');
');
$ui->display('list-product-packing.tpl');
break;
//chama o form com parametros para adicionar
case 'add':
//adiciona os js necessários
$js_arr = array('jslib/form-product-packing', 'numeric');
$ui->assign('xjq', '
$(\'.amount\').autoNumeric(\'init\');
');
$ui->assign('xfooter', Asset::js($js_arr));
$ui->assign('title_ibox', $_L['Add New Packing']);
$ui->assign('pack', null);
$ui->display('form-product-packing.tpl');
break;
//chama o form com parametros para edicao
case 'edit':
$d = ORM::for_table('sys_items_packing')->find_one($routes['2']);
//adiciona os js necessários
if ($d) {
$js_arr = array('jslib/form-product-packing','numeric');
$ui->assign('xjq', '
$(\'.amount\').autoNumeric(\'init\');
');
$ui->assign('xfooter', Asset::js($js_arr));
$ui->assign('title_ibox', $_L['Edit Packing']);
$ui->assign('pack', $d);
$ui->display('form-product-packing.tpl');
} else {
r2('product_packing/list', 'e', $_L['Not Found']);
}
break;
case 'add-post':
$msg = "";
$type = _post('pack_type');
$description = _post('description');
if (trim($type) == '') {
$msg = $_L['Type of packaging'] . $_L['is required'];
}
if (trim($description) == '') {
$msg .= $_L['Description'] . $_L['is required'];
}
if ($msg == '') {
$d = ORM::for_table('sys_items_packing')->create();
$d->type = $type;
$d->description = $description;
$d->weight = Finance::amount_fix(_post('pack_weight')); //adiciona o peso
//adicona os valors possíves das medidas de cada tipo de embalagem
if ($type == 'envelope') {
$d->width = Finance::amount_fix( _post('pack_width'));
$d->length = Finance::amount_fix(_post('pack_length'));
$d->height = null;
$d->diameter = null;
} else if ($type == 'package_box') {
$d->width = Finance::amount_fix(_post('pack_width'));
$d->length = Finance::amount_fix(_post('pack_length'));
$d->height = Finance::amount_fix(_post('pack_height'));
$d->diameter = null;
} else if ($type == 'roller_cylinder') {
$d->length = Finance::amount_fix(_post('pack_length'));
$d->diameter = Finance::amount_fix(_post('pack_diameter'));
$d->height = null;
$d->width = null;
}
$d->save();
_log($_L['Packing Added'] . " - $d->id - " + $d->description, 'Admin', $user['id']);
//se informar que deve emitir msg de salvo
if ($routes['2'] == 'msg') {
_msglog("s", $_L['added_successful']);
}
echo $d->id();
} else {
echo $msg;
}
break;
case 'edit-post':
//padrão do dit
$id = _post('id');
$type = _post('pack_type');
$description = _post('description');
$msg = "";
if (trim($type) == '') {
$msg = $_L['Type of packaging'] . $_L['is required'];
}
if (trim($description) == '') {
$msg .= $_L['Description'] . $_L['is required'];
}
if ($msg == '') {
$d = ORM::for_table('sys_items_packing')->find_one($id);
if ($d) {
// update all gname in contacts
$d->type = $type;
$d->description = $description;
$d->weight = Finance::amount_fix(_post('pack_weight')); //adiciona o peso
//adicona os valors possíves das medidas de cada tipo de embalagem
if ($type == 'envelope') {
$d->width = Finance::amount_fix(_post('pack_width'));
$d->length = Finance::amount_fix(_post('pack_length'));
$d->height = null;
$d->diameter = null;
} else if ($type == 'package_box') {
$d->width = Finance::amount_fix(post('pack_width'));
$d->length = Finance::amount_fix(_post('pack_length'));
$d->height = Finance::amount_fix(_post('pack_height'));
$d->diameter = null;
} else if ($type == 'roller_cylinder') {
$d->length = Finance::amount_fix(_post('pack_length'));
$d->diameter = Finance::amount_fix(_post('pack_diameter'));
$d->height = null;
$d->weidth = null;
}
$d->save();
_log($_L['Packing Edited'] . " - $d->id - " + $d->description, 'Admin', $user['id']);
//se informar que deve emitir msg de salvo
if ($routes['2'] == 'msg') {
_msglog("s", $_L['edit_successful']);
}
echo $d->id;
}
} else {
echo $msg;
}
break;
case 'delete':
$id = intval($routes[2]);
$d = ORM::for_table('sys_items_packing')->find_one($id);
if ($d) {
// 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 sys_items_packing_id = $id")->find_many();
//valida se tem itens com a indicação do pacote
if (count($itens) > 0) {
r2(U . 'product_packing/list/', 'e', $_L['Not permited remove this packing. Packing having products']);
} else {
$d->delete();
_log($_L['Packing Deleted'] . "- $d->id - " + $d->description, 'Admin', $user['id']);
r2(U . 'product_packing/list/', 's', $_L['Packing Deleted Successfully']);
}
} else {
echo $_L['Not found'];
}
break;
//lista ajax, utilizada nos combos
case 'ajax-list':
//recebe o parametro do estado
$type = $_GET['type'];
$pack = ORM::for_table('sys_items_packing');
if($type!=''){
$pack->where("type",$type);
}
$packing= $pack->find_many();
$data="";
foreach ($packing as $p) {
$data[] = array(
'id' => $p->id,
'description' => $p->description,
'width'=>$p->width,
'height'=>$p->height,
'diameter'=>$p->diameter,
'length'=>$p->length
);
}
echo json_encode($data);
break;
default:
echo 'action not defined';
}