Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [OPCH e OPDN] - Nota Fiscal e Recebimento
- IF @object_type IN (N'18',N'20') AND @transaction_type IN ('A', 'U')
- BEGIN
- -- Recebimento de Mercadoria e Nota Fiscal de entrada, nao pode ultrapassar 2% do valor do pedido de compra vinculado
- IF EXISTS (SELECT *
- FROM POR1 P1
- LEFT JOIN PDN1 R1 ON R1.BaseLine = P1.LineNum AND R1.BaseEntry = P1.DocEntry AND R1.ObjType = @object_type AND R1.DocEntry = @list_of_cols_val_tab_del
- LEFT JOIN PCH1 N1 ON N1.BaseLine = P1.LineNum AND N1.BaseEntry = P1.DocEntry AND N1.ObjType = @object_type AND N1.DocEntry = @list_of_cols_val_tab_del
- WHERE P1.TrgetEntry = ISNULL(R1.DocEntry, N1.DocEntry) AND P1.TargetType = @object_type AND ISNULL(R1.LineTotal, 0) + ISNULL(N1.LineTotal, 0) - P1.LineTotal > P1.LineTotal * 0.02)
- BEGIN
- SET @Linhas = STUFF((SELECT ',' + CAST(ISNULL(R1.VisOrder,0)+ISNULL(N1.VisOrder,0)+1 AS VARCHAR(3))
- FROM POR1 P1
- LEFT JOIN PDN1 R1 ON R1.BaseLine = P1.LineNum AND R1.BaseEntry = P1.DocEntry AND R1.ObjType = @object_type AND R1.DocEntry = @list_of_cols_val_tab_del
- LEFT JOIN PCH1 N1 ON N1.BaseLine = P1.LineNum AND N1.BaseEntry = P1.DocEntry AND N1.ObjType = @object_type AND N1.DocEntry = @list_of_cols_val_tab_del
- WHERE P1.TrgetEntry = @list_of_cols_val_tab_del AND P1.TargetType = @object_type AND (ISNULL(R1.LineTotal, 0) + ISNULL(N1.LineTotal, 0) - P1.LineTotal) > P1.LineTotal * 0.02
- FOR XML PATH('')
- ), 1, 1, '')
- SET @error = 17001
- SET @error_message = 'Linhas ' + @Linhas + ' desviam mais que 2% do Preço do Pedido de Venda.'
- END
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement