src-db/database/model/triggers/C_INVOICELINE_TRG2.xml
changeset 17454 745fd4a939d1
parent 17348 5671a6587aa6
child 18314 6113c22ee84c
equal deleted inserted replaced
17453:d7ccce4b6131 17454:745fd4a939d1
    74   DELETE FROM C_INVOICELINE_OFFER
    74   DELETE FROM C_INVOICELINE_OFFER
    75    WHERE C_InvoiceLine_ID = :NEW.C_InvoiceLine_ID;
    75    WHERE C_InvoiceLine_ID = :NEW.C_InvoiceLine_ID;
    76    v_Insert := TRUE;
    76    v_Insert := TRUE;
    77    END IF;
    77    END IF;
    78  END IF;
    78  END IF;
    79 
    79  
    80  IF INSERTING OR v_Insert THEN
    80  IF INSERTING OR v_Insert THEN
    81    SELECT C_BPartner_ID, dateInvoiced, priceprecision, i.M_PriceList_ID,p.istaxincluded
    81    SELECT C_BPartner_ID, dateInvoiced, priceprecision, i.M_PriceList_ID,p.istaxincluded
    82     INTO v_BPartner_ID, v_DateInvoiced, v_Precision, v_PriceList_ID, v_istaxincluded
    82     INTO v_BPartner_ID, v_DateInvoiced, v_Precision, v_PriceList_ID, v_istaxincluded
    83      FROM C_INVOICE i
    83      FROM C_INVOICE i
    84              JOIN m_pricelist p ON i.m_pricelist_id = p.m_pricelist_id,
    84              JOIN m_pricelist p ON i.m_pricelist_id = p.m_pricelist_id,
    87           
    87           
    88    WHERE C_Invoice_ID = :NEW.C_Invoice_ID
    88    WHERE C_Invoice_ID = :NEW.C_Invoice_ID
    89      AND i.C_Currency_ID = c.C_Currency_ID;
    89      AND i.C_Currency_ID = c.C_Currency_ID;
    90 
    90 
    91    IF (v_istaxincluded = 'Y') THEN
    91    IF (v_istaxincluded = 'Y') THEN
    92      IF (DELETING) THEN
    92      IF (UPDATING) THEN
    93         v_oldgrossamt := :old.line_gross_amount;
       
    94      ELSIF (UPDATING) THEN
       
    95         v_oldgrossamt := :old.line_gross_amount;
    93         v_oldgrossamt := :old.line_gross_amount;
    96         v_newgrossamt := :new.line_gross_amount;
    94         v_newgrossamt := :new.line_gross_amount;
    97      ELSE
    95      ELSE
    98         v_newgrossamt := :new.line_gross_amount;
    96         v_newgrossamt := :new.line_gross_amount;
    99      END IF;
    97      END IF;
   219  END IF;
   217  END IF;
   220 
   218 
   221   /**************************************************************************
   219   /**************************************************************************
   222    * Calculate Tax, etc.
   220    * Calculate Tax, etc.
   223    */
   221    */
   224  SELECT processed, stdPrecision
   222  SELECT processed, stdPrecision, pl.istaxincluded
   225    INTO v_Processed, v_Prec
   223    INTO v_Processed, v_Prec, v_istaxincluded
   226  FROM C_Invoice, C_Currency
   224  FROM C_Invoice, C_Currency, m_pricelist pl
   227  WHERE C_Invoice.C_Currency_ID = C_Currency.C_Currency_ID
   225  WHERE C_Invoice.C_Currency_ID = C_Currency.C_Currency_ID
       
   226  AND C_Invoice.m_pricelist_id = pl.m_pricelist_id
   228  AND C_Invoice_ID=v_ID;
   227  AND C_Invoice_ID=v_ID;
   229  v_oldLine:=0;
   228  v_oldLine:=0;
   230  v_newLineNetAmt:=0;
   229  v_newLineNetAmt:=0;
   231  IF(v_Processed='N') THEN
   230  IF(v_Processed='N') THEN
   232   -- Calculate taxes
   231   -- Calculate taxes
   262                      ELSE TotalLines - v_oldLine + v_newLineNetAmt + COALESCE(v_taxAmt, 0)
   261                      ELSE TotalLines - v_oldLine + v_newLineNetAmt + COALESCE(v_taxAmt, 0)
   263                   END
   262                   END
   264    --  Updated = SysDate -- Don't update as otherwise it does not save changes
   263    --  Updated = SysDate -- Don't update as otherwise it does not save changes
   265    WHERE C_Invoice_ID = :new.C_Invoice_ID;
   264    WHERE C_Invoice_ID = :new.C_Invoice_ID;
   266   ELSE -- DELETING
   265   ELSE -- DELETING
       
   266    IF (v_istaxincluded = 'Y') THEN
       
   267      v_oldgrossamt := :old.line_gross_amount;
       
   268    END IF;
   267    SELECT SUM(TaxAmt)
   269    SELECT SUM(TaxAmt)
   268      INTO v_taxAmt
   270      INTO v_taxAmt
   269    FROM C_InvoiceTax
   271    FROM C_InvoiceTax
   270    WHERE C_Invoice_ID=:old.C_Invoice_ID;
   272    WHERE C_Invoice_ID=:old.C_Invoice_ID;
   271   -- DBMS_OUTPUT.PUT_LINE('TaxAmt = ' || v_taxAmt);
   273   -- DBMS_OUTPUT.PUT_LINE('TaxAmt = ' || v_taxAmt);