src-db/database/model/triggers/C_ORDERLINE_TRG.xml
changeset 28646 7d8b06f475a6
parent 27263 1e97969be198
parent 28317 77f1cb4dd278
child 28403 885f451f4996
equal deleted inserted replaced
28645:34256f6c8e07 28646:7d8b06f475a6
    30   v_IsSOTrx CHAR(1);
    30   v_IsSOTrx CHAR(1);
    31   v_Count NUMBER;
    31   v_Count NUMBER;
    32   v_CountRelations NUMBER;
    32   v_CountRelations NUMBER;
    33   v_reservation_id    VARCHAR2(32);
    33   v_reservation_id    VARCHAR2(32);
    34   v_prereservedqty    NUMBER;
    34   v_prereservedqty    NUMBER;
    35   v_IsWithholding_Tax C_Tax.IsWithholdingTax%TYPE;
       
    36   v_IsCashVAT_Tax C_Tax.IsCashVAT%TYPE;
    35   v_IsCashVAT_Tax C_Tax.IsCashVAT%TYPE;
    37   v_IsCashVAT_Order C_Order.IsCashVAT%TYPE;
    36   v_IsCashVAT_Order C_Order.IsCashVAT%TYPE;
    38   v_Rate_Tax C_Tax.Rate%TYPE;
       
    39   v_istaxincluded CHAR(1);
    37   v_istaxincluded CHAR(1);
    40   v_PriceActual NUMBER;
    38   v_PriceActual NUMBER;
    41   
    39   
    42   v_Warehouse_ID VARCHAR2(32);
    40   v_Warehouse_ID VARCHAR2(32);
    43   v_BPartner_Location_ID VARCHAR2(32);
    41   v_BPartner_Location_ID VARCHAR2(32);
   256  END IF;
   254  END IF;
   257 
   255 
   258  -- Update C_Order.IsCashVAT flag from the line tax rate.
   256  -- Update C_Order.IsCashVAT flag from the line tax rate.
   259  -- We do it this way to force any process that creates Orders to properly set the C_Order.IsCashVAT
   257  -- We do it this way to force any process that creates Orders to properly set the C_Order.IsCashVAT
   260  -- If a user manually changes the tax rate when entering a line, the order's header IsCash VAT may change
   258  -- If a user manually changes the tax rate when entering a line, the order's header IsCash VAT may change
   261  -- This will just work for not withholding tax rates
       
   262  IF (INSERTING OR UPDATING) THEN
   259  IF (INSERTING OR UPDATING) THEN
   263   IF (:NEW.C_TAX_ID IS NOT NULL) THEN
   260   IF (:NEW.C_TAX_ID IS NOT NULL) THEN  
   264    SELECT COALESCE(iswithholdingtax, 'N'), COALESCE(IsCashVAT, 'N'), COALESCE(rate, 0)
   261    SELECT CASE WHEN COUNT(*) > 0 THEN 'Y' ELSE 'N' END
   265    INTO v_IsWithholding_Tax, v_IsCashVAT_Tax, v_Rate_Tax
   262    INTO v_IsCashVAT_Tax
   266    FROM C_Tax
   263    FROM dual
   267    WHERE C_Tax_ID=:NEW.C_Tax_ID;
   264    WHERE EXISTS (
   268 
   265         select 1
   269    IF (v_IsWithholding_Tax='N' AND v_Rate_Tax<>0) THEN
   266         from c_tax t
   270     SELECT COALESCE(IsCashVAT, 'N')
   267         where C_TAX_ISMEMBER(:NEW.C_Tax_ID, t.c_tax_id) = 1
   271     INTO v_IsCashVAT_Order
   268         and t.isCashVAT = 'Y'
   272     FROM C_Order
   269         and t.rate <> 0
   273     WHERE C_Order_ID=:NEW.C_Order_ID;
   270         and t.isSummary = 'N'
   274 
   271                  );
   275     IF (v_IsCashVAT_Tax <> v_IsCashVAT_Order) THEN
   272 
   276       UPDATE C_Order
   273    SELECT COALESCE(IsCashVAT, 'N')
   277       SET IsCashVAT = v_IsCashVAT_Tax
   274    INTO v_IsCashVAT_Order
   278       WHERE C_Order_ID=:NEW.C_Order_ID;
   275    FROM C_Order
   279     END IF;
   276    WHERE C_Order_ID=:NEW.C_Order_ID;
       
   277 
       
   278    IF (v_IsCashVAT_Tax <> v_IsCashVAT_Order) THEN
       
   279      UPDATE C_Order
       
   280      SET IsCashVAT = v_IsCashVAT_Tax
       
   281      WHERE C_Order_ID=:NEW.C_Order_ID;
   280    END IF;
   282    END IF;
   281   END IF;
   283   END IF;
   282  END IF;
   284  END IF;
   283 
   285 
   284 END C_ORDERLINE_TRG
   286 END C_ORDERLINE_TRG