src-db/database/model/triggers/C_REVENUERECOGNITION_PLAN_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
<?xml version="1.0"?>
  <database name="TRIGGER C_REVENUERECOGNITION_PLAN_TRG">
    <trigger name="C_REVENUERECOGNITION_PLAN_TRG" table="C_REVENUERECOGNITION_PLAN" fires="after" insert="true" update="false" delete="false" foreach="row">
      <body><![CDATA[
    /*************************************************************************
    * The contents of this file are subject to the Compiere Public
    * License 1.1 ("License"); You may not use this file except in
    * compliance with the License. You may obtain a copy of the License in
    * the legal folder of your Openbravo installation.
    * Software distributed under the License is distributed on an
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
    * implied. See the License for the specific language governing rights
    * and limitations under the License.
    * The Original Code is  Compiere  ERP &  Business Solution
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
    * All Rights Reserved.
    * Contributor(s): Openbravo SL
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
    *
    * Specifically, this derivative work is based upon the following Compiere
    * file and version.
    *************************************************************************
    * Create Service Plan for new RevenueRegognition Plans
    */
    v_IsTimeBased CHAR
    (
      1
    )
    ;
  v_NextNo       VARCHAR2(32);
  v_Qty          NUMBER;
  v_M_Product_ID VARCHAR2(32);
BEGIN
  -- Is RevenueRecognition Time Based
  SELECT IsTimeBased
  INTO v_IsTimeBased
  FROM C_RevenueRecognition
  WHERE C_RevenueRecognition_ID=:new.C_RevenueRecognition_ID;
  -- Add Service Plan
  IF(v_IsTimeBased='Y') THEN
    -- Get InvoiveQty
    SELECT QtyInvoiced,
      M_Product_ID
    INTO v_Qty,
      v_M_Product_ID
    FROM C_InvoiceLine
    WHERE C_InvoiceLine_ID=:new.C_InvoiceLine_ID;
    -- Insert
    AD_Sequence_Next('C_ServiceLevel', :new.AD_Client_ID, v_NextNo) ;
    INSERT
    INTO C_ServiceLevel
      (
        C_ServiceLevel_ID, C_RevenueRecognition_Plan_ID, AD_Client_ID,
        AD_Org_ID, IsActive, Created,
        CreatedBy, Updated, UpdatedBy,
        M_Product_ID, Description, ServiceLevelInvoiced,
        ServiceLevelProvided, Processing, Processed
      )
      VALUES
      (
        v_NextNo, :new.C_RevenueRecognition_Plan_ID, :new.AD_Client_ID,
        :new.AD_Org_ID,  'Y', now(),
        :new.CreatedBy, now(), :new.UpdatedBy,
        v_M_Product_ID, NULL, v_Qty,
        0, 'N',  'N'
      )
      ;
  END IF;
END C_REVENUERECOGNITION_PLAN_TRG
]]></body>
    </trigger>
  </database>