Advertisement
Guest User

NOTA/RECEBIMENTO > Pedido +2%

a guest
Mar 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.57 KB | None | 0 0
  1. -- [OPCH e OPDN] - Nota Fiscal e Recebimento
  2. IF @object_type IN (N'18',N'20') AND @transaction_type IN ('A', 'U')
  3. BEGIN
  4.     -- Recebimento de Mercadoria e Nota Fiscal de entrada, nao pode ultrapassar 2% do valor do pedido de compra vinculado
  5.     IF EXISTS (SELECT *
  6.                FROM POR1 P1
  7.                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
  8.                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
  9.                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)
  10.     BEGIN
  11.         SET @Linhas = STUFF((SELECT ',' + CAST(ISNULL(R1.VisOrder,0)+ISNULL(N1.VisOrder,0)+1 AS VARCHAR(3))
  12.                              FROM POR1 P1
  13.                              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
  14.                              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
  15.                              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
  16.                              FOR XML PATH('')
  17.                             ), 1, 1, '')
  18.         SET @error = 17001
  19.         SET @error_message = 'Linhas ' + @Linhas + ' desviam mais que 2% do Preço do Pedido de Venda.'
  20.     END
  21. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement