src-db/database/model/triggers/C_INVOICELINE_TRG2.xml
changeset 31570 68702618a590
parent 31540 e6fef7749bc4
child 31599 b3ee13f262a4
equal deleted inserted replaced
31569:9c931e5263c1 31570:68702618a590
    54   
    54   
    55   v_PriceLine NUMBER;
    55   v_PriceLine NUMBER;
    56   v_CalcLine NUMBER;
    56   v_CalcLine NUMBER;
    57   v_maxline NUMBER;    
    57   v_maxline NUMBER;    
    58           
    58           
    59   v_prepayment NUMBER;
       
    60 
       
    61   TYPE RECORD IS REF CURSOR;
    59   TYPE RECORD IS REF CURSOR;
    62   Cur_BOM RECORD;          
    60   Cur_BOM RECORD;          
    63 BEGIN
    61 BEGIN
    64     
    62     
    65     IF AD_isTriggerEnabled()='N' THEN RETURN;
    63     IF AD_isTriggerEnabled()='N' THEN RETURN;
    92  WHERE C_Invoice.C_Currency_ID = C_Currency.C_Currency_ID
    90  WHERE C_Invoice.C_Currency_ID = C_Currency.C_Currency_ID
    93  AND C_Invoice.m_pricelist_id = pl.m_pricelist_id
    91  AND C_Invoice.m_pricelist_id = pl.m_pricelist_id
    94  AND C_Invoice_ID=v_ID;
    92  AND C_Invoice_ID=v_ID;
    95  v_oldLine:=0;
    93  v_oldLine:=0;
    96  v_newLineNetAmt:=0;
    94  v_newLineNetAmt:=0;
    97  v_prepayment:=0;
       
    98  
       
    99  IF(v_Processed='N') THEN
    95  IF(v_Processed='N') THEN
   100   -- Calculate taxes
    96   -- Calculate taxes
   101   IF (v_istaxincluded = 'Y') THEN
    97   IF (v_istaxincluded = 'Y') THEN
   102      IF (UPDATING) THEN
    98      IF (UPDATING) THEN
   103         v_oldgrossamt := :old.line_gross_amount;
    99         v_oldgrossamt := :old.line_gross_amount;
   104         v_newgrossamt := :new.line_gross_amount;
   100         v_newgrossamt := :new.line_gross_amount;
   105      ELSIF (INSERTING) THEN
   101      ELSIF (INSERTING) THEN
   106         v_newgrossamt := :new.line_gross_amount;
   102         v_newgrossamt := :new.line_gross_amount;
   107      END IF;
   103      END IF;
   108    END IF;  
   104    END IF;  
   109   IF (UPDATING OR DELETING) THEN
   105   IF(UPDATING OR DELETING) THEN
   110     v_oldLine:= COALESCE(:old.LineNetAmt,0);
   106   v_oldLine:= COALESCE(:old.LineNetAmt,0);
   111     IF UPDATING THEN
       
   112       v_newLineNetAmt:= COALESCE(:new.LineNetAmt,0);
       
   113     END IF;
       
   114     
       
   115     IF (:old.c_orderline_id IS NOT NULL AND (v_oldLine <> 0 OR v_newLineNetAmt <> 0)) THEN
       
   116       SELECT COALESCE(SUM(fps.paidamt),0)
       
   117         INTO v_prepayment
       
   118       FROM fin_payment_schedule fps
       
   119         JOIN c_order ord ON ord.c_order_id=fps.c_order_id
       
   120         JOIN c_orderline ordline ON ordline.c_order_id = ord.c_order_id
       
   121       WHERE ordline.c_orderline_id = :old.c_orderline_id;
       
   122       IF UPDATING THEN
       
   123         IF v_newLineNetAmt <> 0 AND v_oldLine = 0 THEN
       
   124           v_prepayment:= -1 * v_prepayment;
       
   125         ELSIF v_newLineNetAmt <> 0 AND v_oldLine <> 0 THEN
       
   126           v_prepayment:= 0;
       
   127         END IF;
       
   128       END IF;
       
   129       UPDATE c_invoice
       
   130       SET prepaymentamt = prepaymentamt - v_prepayment
       
   131       WHERE c_invoice_id = v_ID;
       
   132     END IF;
       
   133   END IF;  
   107   END IF;  
   134   IF (INSERTING OR UPDATING) THEN
   108   IF (INSERTING OR UPDATING) THEN
   135    v_newLineNetAmt := COALESCE(:new.LineNetAmt,0);
   109    v_newLineNetAmt := COALESCE(:new.LineNetAmt,0);
   136    v_newLineAlternate := COALESCE(:new.TaxBaseAmt,0);
   110    v_newLineAlternate := COALESCE(:new.TaxBaseAmt,0);
   137    IF (UPDATING) THEN
   111    IF (UPDATING) THEN