XUDF XML

XUDF XML

<function name='gart_unidefs_get_canbase'>
    <args>
        <arg name='p_codart' like='gvenpedl.codart' />     <!-- Artículo                    -->
        <arg name='p_varlog' like='gvenpedl.varlog' />     <!-- Variable logística          -->
        <arg name='p_udmdoc' like='gvenpedl.udmven' />     <!-- Unidad medida documento     -->
        <arg name='p_udmalt' like='gvenpedl.udmalt' />     <!-- Unidad alternativa          -->
        <arg name='p_candoc' like='gvenpedl.canped' />     <!-- Cantidad del documento      -->
        <arg name='p_canalt' like='gvenpedl.canalt' />     <!-- Cantidad alternativa        -->
    </args>

    <returns type='decimal' size='12,3' />                 <!-- Cantidad en unidad base     -->

    <define>
        <variable name='m_udmbas'     like='garticul.udmbas' />
        <variable name='m_udmaux'     like='garticul.udmaux' />
        <variable name='m_udmrel'     like='gart_unidefs.udmrel' />

        <variable name='m_candes'     like='gvenpedl.canped' />
    </define>

    <body>

        <set name='m_candes'>NULL</set>

        <!-- ============================================================================== -->
        <!-- Obtener la unidad base y auxiliar del artículo.                                -->
        <!-- ============================================================================== -->
        <select>udmbas, udmaux
          <into>m_udmbas, m_udmaux</into>
           FROM garticul
          WHERE codigo  = p_codart
        </select>

        <if>
            <expr>m_udmbas IS NULL</expr>
            <then>
                <exception>'Artículo: [' || p_codart || '] no encontrado en garticul'</exception>
            </then>
        </if>

        <!-- ============================================================================== -->
        <!-- Si la unidad del documento coincide con la base, la cantidad en unidades base  -->
        <!-- es la cantidad del documento.                                                  -->
        <!-- ============================================================================== -->
        <if>
            <expr>p_udmdoc = m_udmbas</expr>
            <then>
                <return>p_candoc</return>
            </then>
        </if>

        <!-- ============================================================================== -->
        <!-- La unidad alternativa coincide con la unidad base.                             -->
        <!-- ============================================================================== -->
        <if>
            <expr>p_udmalt IS NOT NULL AND p_udmalt = m_udmbas </expr>
            <then>
                <return>p_canalt</return>
            </then>
        </if>

        <!-- ============================================================================== -->
        <!-- La unidad del documento no coincide con la unidad base pero está relacionada.  -->
        <!-- ============================================================================== -->
        <execute-function name='gart_unidefs_get_udmrel' into='m_udmrel'>
            p_codart, p_varlog, p_udmdoc
        </execute-function>

        <if>
            <expr>
                m_udmrel = 'B' OR (m_udmrel = 'A' AND p_udmalt IS NULL)
            </expr>
            <then>
                <execute-function name='gart_uniconv_get_cantid' into='m_candes'>
                    <cast type='smallint'>0</cast>, p_codart, p_varlog, p_udmdoc, <cast type='varchar'>NULL</cast>, m_udmbas, p_candoc, <cast type='decimal' size='16,6'>NULL</cast>
                </execute-function>
            </then>
        </if>

        <!-- ============================================================================== -->
        <!-- La unidad alternativa del documento está relacionada con la unidad base.       -->
        <!-- ============================================================================== -->
        <if>
            <expr>m_candes IS NULL AND p_udmalt IS NOT NULL</expr>
            <then>

                <execute-function name='gart_unidefs_get_udmrel' into='m_udmrel'>
                    p_codart, p_varlog, p_udmalt
                </execute-function>

                <if>
                    <expr>m_udmrel = 'B'</expr>
                    <then>
                        <execute-function name='gart_uniconv_get_cantid' into='m_candes'>
                            <cast type='smallint'>0</cast>, p_codart, p_varlog, p_udmalt, <cast type='varchar'>NULL</cast>, m_udmbas, p_canalt, <cast type='decimal' size='16,6'>NULL</cast>
                        </execute-function>
                    </then>
                    <else>
                        <execute-function name='gart_uniconv_get_cantid' into='m_candes'>
                            <cast type='smallint'>0</cast>, p_codart, p_varlog, p_udmdoc, <cast type='varchar'>NULL</cast>, m_udmbas, p_candoc, <cast type='decimal' size='16,6'>NULL</cast>
                        </execute-function>
                    </else>
                </if>
            </then>
        </if>

        <!-- ============================================================================== -->
        <!-- No se pudo obtener la cantidad de la línea de documento unidad base.           -->
        <!-- ============================================================================== -->
<!--
BPR 19-05-2009
Este exception debe ser condicional a un parámetro.
Mientras no se realice esta modificación se comenta, ya que el error impide entrar lineas de
documentos, en caso de haber un artículo mal parametrizado. 

        <if>
            <expr>m_candes IS NULL</expr>
            <then>
                <exception>'Art:[' || <trim>p_codart</trim> || '] VL:[' || <trim><nvl>p_varlog, ''</nvl></trim> || '] Udm:[' || <trim>p_udmdoc</trim> || '. No se pudo convertir a unidad base' </exception>
            </then>
        </if>
-->
        <return>m_candes</return>
    </body>
</function>