Boa tarde,
Eu tive um problema série em desconto, tive que travar usando "transaction" no banco de dados, o pessoal aqui não pode dar desconto em nada no detalhe, talvez isso ajude você.
-- FBS - TRAVA DESCONTO NO DETALHE DE ALGUNS DOCUMENTOS IF (@error = 0) AND @sObjTyp IN ('13', '14', '15', '16', '17', '20', '21') AND @sTraTyp IN ('A', 'U') BEGIN SET @vTmp = 0 SET @vTmp = ( SELECT ABS(max(desconto)) from ( SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[INV1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp UNION --13 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[RIN1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp UNION --14 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[DLN1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp UNION --15 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[RDN1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp UNION --16 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[RDR1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp AND T0.LineStatus = 'O' UNION --17 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[PDN1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp UNION --20 SELECT max(T0.DiscPrcnt) as Desconto FROM [dbo].[RPD1] T0 WHERE isnull(T0.DiscPrcnt,0) <> 0 and T0.DocEntry = @sKeyVal and T0.[ObjType] = @sObjTyp --21 ) G0 ) IF isnull(@vTmp,0) > 0 BEGIN SET @error=1 SET @error_message = 'TI: Proibido qualquer tipo de desconto, verifique documento - detalhe ' + ltrim(str(@sKeyVal)) END END
Abraço
Fabio
SAP 8.82 PL14 / SAP 9.0 PL10
Addon: BrOne, Skill Triple One, BankSync.