Trigger XML

Trigger XML

<xsql-trigger
    name='gcommovh_upd'
    table='gcommovh'
    event='update'
    >

    <foreach-row>
        <!-- ===================================================================== -->
        <!-- Posible código particularizado de customizacion.                      -->
        <!-- ===================================================================== -->
        <include name='before' />

        <!-- ===================================================================== -->
        <!-- Restricciones de modificación.                                        -->
        <!-- Siempre:                           tipdoc                             -->
        <!-- Si líneas                          docori, almori, almdes             -->
        <!-- Si docori informado                delega, tercer, almori, almdes     -->
        <!-- Si lineas procesadas:              delega, tercer, terenv, divisa     -->
        <!-- ===================================================================== -->
        <when>
           <expr>
                <prv>tipdoc</prv> != <nxt>tipdoc</nxt> AND
                <nxt>movhis</nxt> != -1
           </expr>
           <then>
               <execute-procedure name='sdm_raise_msg'>
                   <in>
                       <param>0</param>
                       <param>'No se puede modificar ciertos datos claves del movimiento'</param>
                   </in>
               </execute-procedure>
           </then>
        </when>

        <when>
            <expr>
               (<prv>almori</prv> != <nxt>almori</nxt>                       OR
                <prv>almdes</prv> != <nxt>almdes</nxt>                       OR
               (<prv>almdes</prv> IS NULL AND <nxt>almdes</nxt> IS NOT NULL) OR
               (<prv>almdes</prv> IS NOT NULL AND <nxt>almdes</nxt> IS NULL) OR
                <nvl><prv>docori</prv>, <whitespace /></nvl> != <nvl><nxt>docori</nxt>, <whitespace /></nvl>) AND
                <nxt>movhis</nxt> != -1
            </expr>
            <expr>
                <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovl
                     WHERE cabid = <nxt>cabid</nxt>
                </expr-select> &gt; 0
            </expr>
            <then>
                <execute-procedure name='sdm_raise_msg'>
                    <in>
                        <param>0</param>
                        <param>'No se puede modificar ciertos datos si hay líneas'</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
           <expr>
                <length><nxt>docori</nxt></length> &gt; 0 AND
               (<prv>delega</prv> != <nxt>delega</nxt> OR <prv>tercer</prv> != <nxt>tercer</nxt>) AND
                <nxt>movhis</nxt> != -1
           </expr>
           <then>
               <execute-procedure name='sdm_raise_msg'>
                  <in>
                      <param>0</param>
                      <param>'Mov. con documento origen, ciertos datos no se pueden modificar'</param>
                  </in>
               </execute-procedure>
           </then>
        </when>

        <when>
           <expr>
               (<prv>delega</prv> != <nxt>delega</nxt>  OR
                <prv>tercer</prv> != <nxt>tercer</nxt>  OR
                <prv>terenv</prv> != <nxt>terenv</nxt>  OR
                <prv>divisa</prv> != <nxt>divisa</nxt>) AND
                <nxt>movhis</nxt> != -1
           </expr>
           <expr>
               <expr-select>
                  SELECT COUNT(*)
                  <expr-into type='integer' />
                    FROM gcommovd
                   WHERE codigo = <nxt>tipdoc</nxt>
                     AND tabdes = 'FC'
               </expr-select> = 0 AND
               <expr-select>
                   SELECT COUNT(*)
                   <expr-into type='integer' />
                     FROM gcommovl
                    WHERE cabid = <nxt>cabid</nxt>
                      AND estlin NOT IN ('E', 'V')
               </expr-select> &gt; 0
           </expr>
           <then>
               <execute-procedure name='sdm_raise_msg'>
                   <in>
                       <param>0</param>
                       <param>'Mov. con lineas procesadas, ciertos datos no se pueden modificar'</param>
                   </in>
               </execute-procedure>
           </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Fecha del movimiento anterior a última valoración de almacén          -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <nxt>fecmov</nxt> != <prv>fecmov</prv> AND
                <nxt>movhis</nxt> != -1 AND
                <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd, galmctas a, galmctas b
                     WHERE gcommovd.codigo = <nxt>tipdoc</nxt>
                       AND gcommovd.ctaori = a.codigo
                       AND gcommovd.ctades = b.codigo
                       AND (a.indsal != 'N' OR b.indsal != 'N')
                </expr-select> &gt; 0 AND
                <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM galmacen
                     WHERE (codigo = <nxt>almori</nxt> OR  codigo = <nxt>almdes</nxt>)
                       AND fecval IS NOT NULL
                       AND (fecval &gt;= <nxt>fecmov</nxt>
                        OR  fecval &gt;= <prv>fecmov</prv>)
                </expr-select> &gt; 0
            </expr>
            <then>
                <execute-procedure name='sdm_raise_msg'>
                    <in>
                        <param>0</param>
                        <param>'Fecha movimiento anterior a la del ultimo cierre del almacen orig/dest'</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si el documento ha evolucionado en importaciones, no se permite       -->
        <!-- modificar dosier, contenedores ni despachos(aduana y transito)        -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <nxt>impnxt</nxt> = 1 AND
                (<nvl><prv>conten</prv>,<whitespace /></nvl> != <nvl><nxt>conten</nxt>,<whitespace /></nvl> OR
                 <nvl><prv>dosier</prv>,<whitespace /></nvl> != <nvl><nxt>dosier</nxt>,<whitespace /></nvl> OR
                 <nvl><prv>destra</prv>,<whitespace /></nvl> != <nvl><nxt>destra</nxt>,<whitespace /></nvl> OR
                 <nvl><prv>desadu</prv>,<whitespace /></nvl> != <nvl><nxt>desadu</nxt>,<whitespace /></nvl>)
            </expr>
            <then>

                <execute-procedure name='sdm_raise_msg'>
                    <in>
                        <param>0</param>
                        <param>'Movimiento [' || <trim><nxt>docser</nxt></trim> || '] evolucionado. No se puede cambiar datos de importaciones'</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!--  Resetear los campos movest y movis a 0 ante cualquier cambio, salvo  -->
        <!--  los cambios sobre sí mismos                                          -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>movest</prv>  = 1                 AND
                <prv>movest</prv>  = <nxt>movest</nxt> AND
                <prv>movhis</prv>  = <nxt>movhis</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-function name='sdm_set_value' into='movest'>'0'</execute-function>
            </then>
        </when>

        <when>
            <expr>
                <prv>movhis</prv> = 1                 AND
                <prv>movhis</prv> = <nxt>movhis</nxt> AND
               (<prv>movest</prv> = <nxt>movest</nxt> OR <prv>movest</prv> = 1 AND <nxt>movest</nxt> = 0)
            </expr>
            <then>
                <execute-function name='sdm_set_value' into='movhis'>'0'</execute-function>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!--  Registro de tracking para estadísticas                               -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>movest</prv> != <nxt>movest</nxt> AND
                <nxt>movest</nxt>  = 0 AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <insert table='gdoc_traspaso'>
                    <column name='tabname'>'gcommovh'</column>
                    <column name='colname'>'cabid'</column>
                    <column name='colval'><nxt>cabid</nxt></column>
                    <column name='tipope'>1</column>
                    <column name='tippro'>0</column>
                </insert>

            </then>
        </when>

        <!-- ===================================================================== -->
        <!--  Registro de tracking para histórico                                  -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>movhis</prv> != <nxt>movhis</nxt> AND
                <nxt>movhis</nxt>  = 0 AND
                <prv>movhis</prv> != -1
            </expr>
            <then>
                <insert table='gdoc_traspaso'>
                    <column name='tabname'>'gcommovh'</column>
                    <column name='colname'>'cabid'</column>
                    <column name='colval'><nxt>cabid</nxt></column>
                    <column name='tipope'>1</column>
                    <column name='tippro'>1</column>
                </insert>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!--  Borrado de tracking para estadísticas                                -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>movest</prv> != <nxt>movest</nxt> AND
                <nxt>movest</nxt>  = 1 AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <delete table='gdoc_traspaso'>
                    <where>
                        tabname = 'gcommovh'       AND
                        colname = 'cabid'          AND
                        colval  = <nxt>cabid</nxt> AND
                        tippro  = 0
                     </where>
                </delete>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!--  Borrado de tracking para histórico                                   -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>movhis</prv> != <nxt>movhis</nxt> AND
                <nxt>movhis</nxt>  = 1 AND
                <prv>movhis</prv> != -1
            </expr>
            <then>
                <delete table='gdoc_traspaso'>
                     <where>
                        tabname = 'gcommovh'        AND
                        colname = 'cabid'           AND
                        colval  = <nxt>cabid</nxt>  AND
                        tippro  = 1
                     </where>
                </delete>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si se cambia el estado del movimiento, o la fecha de recepcion y el   -->
        <!-- tipo de movimiento actualiza 'stock planificado'; actualizar los      -->
        <!-- movimientos planificados correspondientes.                            -->
        <!-- ===================================================================== -->
        <when>
            <expr>
               ((<prv>estcab</prv>  = 'E' AND <nxt>estcab</nxt> != 'E') OR
                (<prv>estcab</prv> != 'E' AND <nxt>estcab</nxt>  = 'E') OR
                 <prv>fecrec</prv> != <nxt>fecrec</nxt>) AND
                 <nxt>movhis</nxt> != -1 AND
                 <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd
                     WHERE codigo = <prv>tipdoc</prv>
                       AND stkpla IN (1, 2, 3, 4)
                 </expr-select> &gt; 0
            </expr>
            <then>
                <update table='gpro_stkplanm'>
                    <column name='estado'>CASE WHEN <nxt>estcab</nxt> = 'E' THEN 'E' ELSE 'V' END</column>
                    <column name='fecmov'><nxt>fecrec</nxt></column>
                    <where>
                        tabmov = 'gcommovh' AND
                        docser = <prv>docser</prv>
                    </where>
                </update>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si existe una reserva de stock planificado para alguna línea del      -->
        <!-- suministro y la fecha de recepción es anterior a la fecha de entrega  -->
        <!-- del pedido de ventas, anular reserva.                                 -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                 <prv>fecrec</prv> &lt; <nxt>fecrec</nxt> AND
                 <nxt>movhis</nxt> != -1 AND
                 <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd
                     WHERE codigo = <prv>tipdoc</prv>
                       AND stkpla IN (1, 2, 3, 4)
                 </expr-select> &gt; 0
            </expr>
            <then>
                <update table='greserva'>
                    <column name='estlin'>'A'</column>
                    <where>
                        tabres    = 'gvenpedh'        AND
                        tabapr    = 'gcommovh'        AND
                        docapr    = <nxt>docser</nxt> AND
                        fecent &lt; <nxt>fecrec</nxt> AND
                        estlin   != 'A'               AND
                        canpro   != 0
                    </where>
                </update>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- El coste medio pasa a 0 para obligar a modificar la fecha de última   -->
        <!-- valoración de las líneas de suministros                               -->
        <!-- ===================================================================== -->
         <when>
            <expr>
                <nxt>fecmov</nxt> != <prv>fecmov</prv> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <update table='gcommovl'>
                    <column name='cosmed'>0</column>
                    <where>
                        cabid   = <nxt>cabid</nxt> AND
                        cosmed != 0
                    </where>
                </update>
            </then>
         </when>

        <!-- ===================================================================== -->
        <!-- Si se modifican datos que intervienen en valoración -> recalcular     -->
        <!-- ===================================================================== -->
        <when mutating-reference='gcommovl'>
            <expr>
               (<prv>tercer</prv> != <nxt>tercer</nxt> OR
                <prv>delega</prv> != <nxt>delega</nxt> OR
                <prv>terenv</prv> != <nxt>terenv</nxt> OR
                <prv>divisa</prv> != <nxt>divisa</nxt>) AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <delete table='gcommovh_dtcl'>
                    <where>cabid = <nxt>cabid</nxt></where>
                </delete>
                <delete table='gcommovl_dtlh'>
                    <where>cabid = <nxt>cabid</nxt></where>
                </delete>

                <update table='gcommovl'>
                    <column name='precio'>0</column>
                    <column name='dtolin'>0</column>
                    <column name='pretar'>NULL</column>
                    <column name='dtotar'>NULL</column>
                    <where>cabid  = <nxt>cabid</nxt></where>
                </update>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si se contabiliza el albarán y tiene activado el indicador de         -->
        <!-- generar gastos aplicados de presupuestos al contabilizar. Eliminar    -->
        <!-- los registros de compromisos de la inversión.                         -->
        <!-- ===================================================================== -->
        <when>
           <expr>
               <prv>fconta</prv> IS NULL     AND
               <nxt>fconta</nxt> IS NOT NULL AND
               <nxt>movhis</nxt> != -1 AND
               <expr-select>
                   SELECT COUNT(*)
                   <expr-into type='integer' />
                     FROM gcommovd
                    WHERE codigo  = <prv>tipdoc</prv>
                      AND cominv != 'N'
                      AND aplcon != 0
               </expr-select> &gt; 0
           </expr>
           <then>
               <delete table='cpar_premovi'>
                  <where>
                      tabori = 'gcomalbh'        AND
                      docser = <prv>docser</prv> AND
                      estado = 'C'
                  </where>
               </delete>
           </then>
        </when>


        <!-- ===================================================================== -->
        <!--  Si un albarán pasa a entrado y el tipo de documento indicaba         -->
        <!--  que inserta obligaciones de inversión. Eliminar los registros        -->
        <!--  de obligación de la inversión                                        -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>estcab</prv>  = 'V' AND
                <nxt>estcab</nxt>  = 'E' AND
                <nxt>movhis</nxt> != -1  AND
                <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd
                     WHERE codigo = <prv>tipdoc</prv>
                       AND cominv = 'S'
                </expr-select> &gt; 0
            </expr>
            <then>
                <delete table='cpar_premovi'>
                    <where>
                        tabori = 'gcomalbh' AND
                        docser = <prv>docser</prv>
                    </where>
                </delete>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si el documento se ha cursado ya no se puede modificar                -->
        <!-- [-]  => [-]                                                           -->
        <!-- [P]  => [V]                                                           -->
        <!-- [EV] => [P]                                                           -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>estcab</prv> != <nxt>estcab</nxt>                 AND
               (<prv>estcab</prv>  = 'P' AND <nxt>estcab</nxt> != 'V') AND
               (<prv>estcab</prv> != 'E' AND <prv>estcab</prv> != 'V') AND
               (<nxt>estcab</nxt>  = 'E'  OR <nxt>estcab</nxt>  = 'V') AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='sdm_raise_msg'>
                    <in>
                        <param>0</param>
                        <param>'Cabecera de transaccion cursada. No se puede alterar'</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si cambio el descuento general debo actualizar el acuerdo             -->
        <!-- Se hace a partir de la suma de las lineas ya que el importe total     -->
        <!-- total del documento no se tiene en el trigger sino con posterioridad  -->
        <!-- cuando se revalora el documento                                       -->
        <!-- ===================================================================== -->
        <when mutating='y'>
            <expr>
                <prv>dtogen</prv> != <nxt>dtogen</nxt> AND
                <nxt>docori</nxt> IS NOT NULL          AND
                <nxt>movhis</nxt> != -1 AND
                <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd
                     WHERE codigo = <nxt>tipdoc</nxt>
                       AND tabori = 'MC'
                       AND actori = 'S'
                </expr-select> &gt; 0
            </expr>
            <then>
                <update table='gcomacuh'>
                    <column name='imptot'> imptot +
                         (SELECT <nvl>SUM(impnet), 0</nvl> * (<nxt>dtogen</nxt> - <prv>dtogen</prv>) / 100
                            FROM gcommovl
                           WHERE cabid = <nxt>cabid</nxt>)</column>
                    <column name='user_updated'><user /></column>
                    <column name='date_updated'><current /></column>
                    <where>
                        docser = <nxt>docori</nxt>
                    </where>
                </update>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Si es un movimiento que genera factura si se modifica el descuento    -->
        <!-- general en el movimiento se ha de modificar en la factura             -->
        <!-- automáticamente. Lo mismo para el descuento pronto pago y fecha       -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                (<prv>dtogen</prv> != <nxt>dtogen</nxt> OR
                 <prv>fecmov</prv> != <nxt>fecmov</nxt> OR
                 <prv>dtopp</prv>  != <nxt>dtopp</nxt>) AND
                 <nxt>movhis</nxt> != -1 AND
                 <expr-select>
                    SELECT COUNT(*)
                    <expr-into type='integer' />
                      FROM gcommovd
                     WHERE codigo = <nxt>tipdoc</nxt>
                       AND tabdes = 'FC'
                 </expr-select> &gt; 0
            </expr>
            <then>
                <update table='gcomfach'>
                    <column name='dtogen'><nxt>dtogen</nxt></column>
                    <column name='dtopp'><nxt>dtopp</nxt></column>
                    <column name='fecha'><nxt>fecmov</nxt></column>
                    <column name='valor'><nxt>fecmov</nxt></column>
                    <column name='user_updated'><user /></column>
                    <column name='date_updated'><current /></column>
                    <where>
                        cabori = <nxt>cabid</nxt>
                    </where>
                </update>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Invalidar autorizaciones para bloqueos relacionados con ciertos       -->
        <!-- campos.                                                               -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>tipdoc</prv> != <nxt>tipdoc</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'tipdoc'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>delega</prv> != <nxt>delega</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'delega'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>depart</prv> != <nxt>depart</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'depart'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>almori</prv> != <nxt>almori</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'almori'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>almdes</prv> != <nxt>almdes</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'almdes'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>refter</prv> != <nxt>refter</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'refter'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>tipefe</prv> != <nxt>tipefe</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'tipefe'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>frmpag</prv> != <nxt>frmpag</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'frmpag'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>imptot</prv> != <nxt>imptot</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'imptot'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>tercer</prv> != <nxt>tercer</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'tercer'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>tipdir</prv> != <nxt>tipdir</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'tipdir'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>terfac</prv> != <nxt>terfac</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'terfac'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>dirfac</prv> != <nxt>dirfac</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'dirfac'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>divisa</prv> != <nxt>divisa</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'divisa'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>dtogen</prv> != <nxt>dtogen</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'dtogen'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>dtopp</prv>  != <nxt>dtopp</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'dtopp'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <nvl><prv>conten</prv>, <whitespace /></nvl> != <nvl><nxt>conten</nxt>, <whitespace /></nvl> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'conten'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <when>
            <expr>
                <prv>impres</prv> != <nxt>impres</nxt> AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <execute-procedure name='cerrauth_anular'>
                    <in>
                        <param>'gcommovh'</param>
                        <param>'impres'</param>
                        <param><nxt>cabid</nxt></param>
                        <param>0</param>
                    </in>
                </execute-procedure>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Inserción en la tabla de sincronización de documentos.                -->
        <!-- Sincronización de documentos al validar.                              -->
        <!-- ===================================================================== -->
        <when>
            <expr><nxt>movhis</nxt> != -1</expr>
            <then>
                <execute-procedure name='csyn_document_inserta'>
                    <in>
                        <param>'gcommovh'</param>
                        <param><nxt>tipdoc</nxt></param>
                        <param><nxt>docser</nxt></param>
                    </in>
                </execute-procedure>
            </then>
        </when>


        <!-- ===================================================================== -->
        <!-- Inserción en la tabla de sincronización de documentos.                -->
        <!-- Sincronización de documentos al imprimir.                             -->
        <!-- ===================================================================== -->
        <when>
            <expr>
                <prv>impres</prv> != <nxt>impres</nxt> AND
                <nxt>impres</nxt>  = 'S' AND
                <nxt>movhis</nxt> != -1
            </expr>
            <then>
                <insert table='csyn_document' columns='tabid, docser, accion, progname, proces'>
                    <select>
                        <columns>
                            tabid, <nxt>docser</nxt>, 2, progname, 0
                        </columns>
                        <from table='csyn_tablas' />
                        <where>
                            tabid = 'gcommovh' AND
                            <nvl>tipdoc, <nxt>tipdoc</nxt></nvl> = <nxt>tipdoc</nxt> AND
                            indnot = 2
                        </where>
                    </select>
                </insert>
            </then>
        </when>

        <!-- ===================================================================== -->
        <!-- Posible código particularizado de customizacion.                      -->
        <!-- ===================================================================== -->
        <include name='after' />
    </foreach-row>
</xsql-trigger>