src-db/database/model/triggers/C_INVOICE_TRG2.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
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_INVOICE_TRG2">
adrian@94
     3
    <trigger name="C_INVOICE_TRG2" table="C_INVOICE" fires="after" insert="true" update="false" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
carlos@59
     7
adrian@94
     8
adrian@94
     9
/*************************************************************************
adrian@94
    10
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
    11
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    12
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    13
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    14
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    15
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    16
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    17
* License for the specific  language  governing  rights  and  limitations
adrian@94
    18
* under the License.
adrian@94
    19
* The Original Code is Openbravo ERP.
adrian@94
    20
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    21
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    22
* All Rights Reserved.
adrian@94
    23
* Contributor(s):  ______________________________________.
adrian@94
    24
************************************************************************/
adrian@94
    25
   TYPE RECORD IS REF CURSOR;
adrian@94
    26
  Cur_Discounts RECORD;
juanpablo@1605
    27
  v_Key VARCHAR2(32) ;
adrian@94
    28
BEGIN
adrian@94
    29
  FOR Cur_Discounts IN
adrian@94
    30
    (
adrian@94
    31
    SELECT C_DISCOUNT_ID,
adrian@94
    32
      LINE,
adrian@94
    33
      CASCADE
adrian@94
    34
    FROM C_BPARTNER_DISCOUNT
adrian@94
    35
    WHERE C_BPARTNER_ID=:NEW.C_BPARTNER_ID
adrian@94
    36
      AND ISACTIVE='Y'
adrian@94
    37
      AND(ISCUSTOMER=:NEW.ISSOTRX
gorkaion@239
    38
      OR ISVENDOR <> :NEW.ISSOTRX)
adrian@94
    39
    ORDER BY LINE
adrian@94
    40
    )
adrian@94
    41
  LOOP
adrian@94
    42
    Ad_Sequence_Next('C_Invoice_Discount', :NEW.AD_Client_ID, v_Key) ;
adrian@94
    43
    INSERT
adrian@94
    44
    INTO C_INVOICE_DISCOUNT
adrian@94
    45
      (
adrian@94
    46
        C_INVOICE_DISCOUNT_ID, AD_CLIENT_ID, AD_ORG_ID,
adrian@94
    47
        ISACTIVE, CREATED, CREATEDBY,
adrian@94
    48
        UPDATED, UPDATEDBY, C_INVOICE_ID,
adrian@94
    49
        C_DISCOUNT_ID, LINE, CASCADE
adrian@94
    50
      )
adrian@94
    51
      VALUES
adrian@94
    52
      (
adrian@94
    53
        v_Key, :NEW.AD_Client_ID, :NEW.AD_Org_ID,
antonio@735
    54
         'Y', now(),  :NEW.CREATEDBY,
antonio@735
    55
        now(), :NEW.UPDATEDBY, :NEW.C_INVOICE_ID,
adrian@94
    56
        Cur_Discounts.C_DISCOUNT_ID, Cur_Discounts.LINE, Cur_Discounts.CASCADE
adrian@94
    57
      )
adrian@94
    58
      ;
adrian@94
    59
  END LOOP;
antonio@735
    60
END C_INVOICE_TRG2
gorkaion@239
    61
]]></body>
adrian@94
    62
    </trigger>
adrian@94
    63
  </database>