Hi All.
We have tried to create a stored proc to block users from adding an invoice if the GP % is not within a certain range (this is defined in UDF's) for certain bp's.
However does not work for all values within the range.
example. customer A's GP % should be between 5 and 30%
it will let an invoice with 16% go through, but will block a document with a 24% GP.
Please see the code below which we have used.
begin error := 0;
error_message := N'Ok';
IF :object_type = '13'AND :transaction_type = 'A'THEN
SELECT
(SELECTCount(*)
FROM OINV T0 INNERJOIN INV1 T1 ON T0."DocEntry" = T1."DocEntry"
INNERJOIN OCRD T2 ON T0."CardCode" = T2."CardCode"
WHERE T0."DocEntry" = :list_of_cols_val_tab_del
GROUPBY T1."DocEntry", T0."DocEntry", T0."DocTotal", T0."VatSum",T2."U_MinMargin",T2."U_MaxMargin"
HAVINGnullif(T0."DocTotal" - T0."VatSum" - (SUM(T1."Quantity" * T1."GrossBuyPr")), 0)/ nullif(SUM(T1."Quantity" * T1."GrossBuyPr"), 0) * 100 notBETWEEN"U_MinMargin"and"U_MaxMargin"
) into temp_var_1 FROM DUMMY;
IF :temp_var_1 > 0 THEN
SELECT -1, 'ERROR: Check GP%'INTO error, error_message FROM DUMMY;
ENDIF;
ENDIF;
We have used the NOT BETWEEN and
HAVINGnullif(T0."DocTotal" - T0."VatSum" - (SUM(T1."Quantity" * T1."GrossBuyPr")), 0)/ nullif(SUM(T1."Quantity" * T1."GrossBuyPr"), 0) * 100 >="U_MinMargin" or (T0."DocTotal" - T0."VatSum" - (SUM(T1."Quantity" * T1."GrossBuyPr")), 0)/ nullif(SUM(T1."Quantity" * T1."GrossBuyPr"), 0) * 100 >="U_MaxMargin"
and get the same behaviour..any GP% that is in the twenties gets blocked
Any ideas on what it could be.
Thank you
Jerusha