Skip to Content
author's profile photo Former Member
Former Member

Ayuda TN

Buenas tardes compa;eros,

tengo las siguientes sentencias que me deberian bloquear la facturacion cuando este el precio por debajo del costo, pero no logro que asi se realice tal vez y ustedes encuentran la falla que yo no he podido.

@object_type = '13' and (@transaction_type = 'U' or @transaction_type = 'A')

BEGIN

DECLARE @IndexFac INT

DECLARE @RowsFac INT

--SET @RowsFac = (SELECT DISTINCT COUNT(T1.LineNum) FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry=@list_of_cols_val_tab_del)

SET @IndexFac = 0

WHILE(@IndexFac<@RowsFac)

BEGIN

-- --Declaración de variables

DECLARE @CodigoAF VARCHAR(8) -- Código de almacén factura

DECLARE @ArticuloF VARCHAR(100) -- Código del artículo

DECLARE @PrecioF NUMERIC(19,6) -- Precio del artículo

DECLARE @TreeTypeF CHAR(1) -- Artículo componente de un código E

DECLARE @MonedaF NVARCHAR(15) -- Moneda factura

DECLARE @BaseTypeF INT -- Documento base factura

DECLARE @Reserva NVARCHAR(1) -- Indicador de factura reserva

-- --Asignación de valores a variables

SET @CodigoAF = (SELECT T1.WhsCode FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry = @list_of_cols_val_tab_del and T1.LineNum=@IndexFac)

SET @ArticuloF = (SELECT T1.ItemCode FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry = @list_of_cols_val_tab_del and T1.LineNum=@IndexFac)

SET @PrecioF = (SELECT T1.Price FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry = @list_of_cols_val_tab_del and T1.LineNum=@IndexFac)

SET @TreeTypeF = (SELECT T1.TreeType FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry = @list_of_cols_val_tab_del and T1.LineNum=@IndexFac)

SET @MonedaF = (SELECT T0.DocCur FROM OINV T0 WHERE T0.DocEntry = @list_of_cols_val_tab_del)

SET @BaseTypeF = (SELECT T1.BaseType FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE T0.DocEntry = @list_of_cols_val_tab_del and T1.LineNum=@IndexFac)

SET @Reserva = (SELECT T0.IsIns FROM OINV T0 WHERE T0.DocEntry = @list_of_cols_val_tab_del)

SET @error =

CASE

--(1) Precio Bajo el Costo

WHEN @PrecioF <= (SELECT t4.AvgPrice FROM OITW t4 WHERE t4.ItemCode=@ArticuloF AND t4.WhsCode = @CodigoAF) /*and @Reserva = 'Y'*/ THEN 1301

--(2) Facturación desde Cotización Bloqueada

WHEN @Reserva = 'N' AND @BaseTypeF = '23' THEN 1302

ELSE 0

END

SET @error_message =

CASE

WHEN @error=1301 THEN N'Precio abajo del costo para el articulo ' +@ArticuloF

WHEN @error=1302 THEN N'No se pueden crear facturas desde una cotizacion.'

END

IF @error>0

BREAK

SET @IndexFac = @IndexFac+1

END

END

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jul 25, 2016 at 05:38 PM

    Crstiano:

    Prueba con este procedimiento:

    -- Factura de Clientes bajo el costo

    IF @object_type = '13' and @transaction_type IN ('A','U')

    BEGIN

    if exists (SELECT T1.[ItemCode]

    FROM OINV T0

    INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry

    INNER JOIN OITW T2 ON T1.ITEMCODE=T2.ITEMCODE

    WHERE (T1.[price] <= (((T2.[avgprice] * 10) / 100) + T2.[avgprice])) and (T0.docentry = @list_of_cols_val_tab_del))

    BEGIN

    SELECT @error = 1, @error_message = 'Factura con precio unitario por bajo el costo'

    END

    END

    END

    Saludos cordiales,

    Manuel Díaz G.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.