function smarty_function_opalo_cotizador($params, &$smarty)
{
    global $sugar_config;
    $Items = FnCrm::get_items_by_parent($params['parent_type'], $params['parent_id']);
    if ($Items) {
        $ItemsOPA = array();
        foreach ($Items as $key => $item) {
            $ItemsOPA[$key]['id'] = $item->id;
            $ItemsOPA[$key]['referencia'] = $item->referencia;
            $ItemsOPA[$key]['name'] = $item->name;
            $ItemsOPA[$key]['cantidad'] = $item->cantidad % 10 == 0 ? number_format($item->cantidad) : rtrim((double) $item->cantidad, '0');
            $ItemsOPA[$key]['vr_unit'] = $item->vr_unit % 10 == 0 ? round($item->vr_unit) : rtrim((double) $item->vr_unit, '0');
            $ItemsOPA[$key]['vr_total'] = $item->vr_total % 10 == 0 ? round($item->vr_total) : rtrim((double) $item->vr_total, '0');
            $ItemsOPA[$key]['rowid_item'] = $item->rowid_item;
            $ItemsOPA[$key]['bodega_id'] = $item->bodega_id;
            $ItemsOPA[$key]['bodega'] = $item->bodega;
            $ItemsOPA[$key]['unidad_medida'] = $item->unidad_medida;
            $ItemsOPA[$key]['impuestos'] = FnOtros::trunc_number($item->impuestos);
            $ItemsOPA[$key]['porcentaje_descuento'] = FnOtros::trunc_number($item->porcentaje_descuento);
            $ItemsOPA[$key]['descuento_moneda'] = FnOtros::trunc_number($item->descuento_moneda);
        }
    }
    $smarty->assign('subtotalField', !empty($params['subtotal']) ? $params['subtotal'] : 'subtotal');
    $smarty->assign('impuestosField', !empty($params['impuestos']) ? $params['impuestos'] : 'impuestos');
    $smarty->assign('descuentoField', !empty($params['descuento']) ? $params['descuento'] : 'descuento');
    $smarty->assign('totalField', !empty($params['total']) ? $params['total'] : 'total');
    $smarty->assign('vr_descuento', !empty($params['vr_descuento']) ? FnOtros::trunc_number($params['vr_descuento']) : 0);
    $smarty->assign('Items', $ItemsOPA);
    $smarty->assign('params', $params);
    $smarty->assign('site_url', $sugar_config['site_url']);
    $html = dataERP($params);
    $html .= $smarty->fetch("custom/opalo/partials/cotizador_edit.tpl");
    return $html;
}
function smarty_function_opalo_cotizador($params, &$smarty)
{
    global $sugar_config;
    require_once 'custom/opalo/lib/functions_cotizador.php';
    $Items = get_items_by_parent($params['parent_type'], $params['parent_id']);
    if ($Items) {
        $ItemsOPA = array();
        foreach ($Items as $key => $item) {
            $ItemsOPA[$key]['id'] = $item->id;
            $ItemsOPA[$key]['referencia'] = $item->referencia;
            $ItemsOPA[$key]['name'] = $item->name;
            $ItemsOPA[$key]['cantidad'] = $item->cantidad % 10 == 0 ? number_format($item->cantidad) : rtrim((double) $item->cantidad, '0');
            $ItemsOPA[$key]['vr_unit'] = $item->vr_unit % 10 == 0 ? round($item->vr_unit) : rtrim((double) $item->vr_unit, '0');
            $ItemsOPA[$key]['vr_total'] = $item->vr_total % 10 == 0 ? round($item->vr_total) : rtrim((double) $item->vr_total, '0');
            $ItemsOPA[$key]['rowid_item'] = $item->rowid_item;
            $ItemsOPA[$key]['bodega_id'] = $item->bodega_id;
            $ItemsOPA[$key]['bodega'] = $item->bodega;
            $ItemsOPA[$key]['unidad_medida'] = $item->unidad_medida;
        }
    }
    $smarty->assign('Items', $ItemsOPA);
    $smarty->assign('params', $params);
    $smarty->assign('site_url', $sugar_config['site_url']);
    $html = dataERP($params);
    $html .= $smarty->fetch("custom/opalo/Partials/cotizador_edit.tpl");
    return $html;
}