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
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_REVENUERECOGNITION_PLAN_TRG">
adrian@94
     3
    <trigger name="C_REVENUERECOGNITION_PLAN_TRG" table="C_REVENUERECOGNITION_PLAN" fires="after" insert="true" update="false" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
adrian@94
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * Create Service Plan for new RevenueRegognition Plans
adrian@94
    26
    */
adrian@94
    27
    v_IsTimeBased CHAR
adrian@94
    28
    (
adrian@94
    29
      1
adrian@94
    30
    )
adrian@94
    31
    ;
juanpablo@1605
    32
  v_NextNo       VARCHAR2(32);
adrian@94
    33
  v_Qty          NUMBER;
juanpablo@1605
    34
  v_M_Product_ID VARCHAR2(32);
adrian@94
    35
BEGIN
adrian@95
    36
  -- Is RevenueRecognition Time Based
adrian@94
    37
  SELECT IsTimeBased
adrian@94
    38
  INTO v_IsTimeBased
adrian@94
    39
  FROM C_RevenueRecognition
adrian@94
    40
  WHERE C_RevenueRecognition_ID=:new.C_RevenueRecognition_ID;
adrian@94
    41
  -- Add Service Plan
adrian@94
    42
  IF(v_IsTimeBased='Y') THEN
adrian@94
    43
    -- Get InvoiveQty
adrian@94
    44
    SELECT QtyInvoiced,
adrian@94
    45
      M_Product_ID
adrian@94
    46
    INTO v_Qty,
adrian@94
    47
      v_M_Product_ID
adrian@94
    48
    FROM C_InvoiceLine
adrian@94
    49
    WHERE C_InvoiceLine_ID=:new.C_InvoiceLine_ID;
adrian@94
    50
    -- Insert
adrian@94
    51
    AD_Sequence_Next('C_ServiceLevel', :new.AD_Client_ID, v_NextNo) ;
adrian@94
    52
    INSERT
adrian@94
    53
    INTO C_ServiceLevel
adrian@94
    54
      (
adrian@94
    55
        C_ServiceLevel_ID, C_RevenueRecognition_Plan_ID, AD_Client_ID,
adrian@94
    56
        AD_Org_ID, IsActive, Created,
adrian@94
    57
        CreatedBy, Updated, UpdatedBy,
adrian@94
    58
        M_Product_ID, Description, ServiceLevelInvoiced,
adrian@94
    59
        ServiceLevelProvided, Processing, Processed
adrian@94
    60
      )
adrian@94
    61
      VALUES
adrian@94
    62
      (
adrian@94
    63
        v_NextNo, :new.C_RevenueRecognition_Plan_ID, :new.AD_Client_ID,
antonio@735
    64
        :new.AD_Org_ID,  'Y', now(),
antonio@735
    65
        :new.CreatedBy, now(), :new.UpdatedBy,
adrian@94
    66
        v_M_Product_ID, NULL, v_Qty,
adrian@94
    67
        0, 'N',  'N'
adrian@94
    68
      )
adrian@94
    69
      ;
adrian@94
    70
  END IF;
antonio@735
    71
END C_REVENUERECOGNITION_PLAN_TRG
gorkaion@239
    72
]]></body>
adrian@94
    73
    </trigger>
adrian@94
    74
  </database>