src-db/database/model/triggers/AD_COLUMN_TRG2.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1291 b56cf1635810
child 1929 ad0353d93b0f
permissions -rw-r--r--
Merge r2.5x intro trunk
gorkaion@1291
     1
<?xml version="1.0"?>
gorkaion@1291
     2
  <database name="TRIGGER AD_COLUMN_TRG2">
gorkaion@1291
     3
    <trigger name="AD_COLUMN_TRG2" table="AD_COLUMN" fires="after" insert="true" update="true" delete="false" foreach="row">
gorkaion@1291
     4
      <body><![CDATA[
gorkaion@1291
     5
/*************************************************************************
gorkaion@1291
     6
* The contents of this file are subject to the Openbravo  Public  License
gorkaion@1291
     7
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
gorkaion@1291
     8
* Version 1.1  with a permitted attribution clause; you may not  use this
gorkaion@1291
     9
* file except in compliance with the License. You  may  obtain  a copy of
gorkaion@1291
    10
* the License at http://www.openbravo.com/legal/license.html
gorkaion@1291
    11
* Software distributed under the License  is  distributed  on  an "AS IS"
gorkaion@1291
    12
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
gorkaion@1291
    13
* License for the specific  language  governing  rights  and  limitations
gorkaion@1291
    14
* under the License.
gorkaion@1291
    15
* The Original Code is Openbravo ERP.
gorkaion@1291
    16
* The Initial Developer of the Original Code is Openbravo SL
gorkaion@1291
    17
* All portions are Copyright (C) 2008 Openbravo SL
gorkaion@1291
    18
* All Rights Reserved.
gorkaion@1291
    19
* Contributor(s):  ______________________________________.
gorkaion@1291
    20
************************************************************************/
gorkaion@1291
    21
  TYPE RECORD IS REF CURSOR;
gorkaion@1291
    22
  CUR_Clients RECORD;
gorkaion@1291
    23
  v_TableName VARCHAR2(40);
juanpablo@1605
    24
  v_NextNo VARCHAR2(32);
gorkaion@1291
    25
  BEGIN
gorkaion@1291
    26
  /**
gorkaion@1291
    27
  * Create Sequence for DocumentNo and Value columns
gorkaion@1291
    28
  */
gorkaion@1291
    29
  IF (:new.ColumnName = 'DocumentNo' OR :new.ColumnName = 'Value') THEN
gorkaion@1291
    30
    SELECT TableName INTO v_TableName
gorkaion@1291
    31
    FROM ad_table
gorkaion@1291
    32
    WHERE ad_table.ad_table_id = :new.ad_table_id;
gorkaion@1291
    33
         
gorkaion@1291
    34
    FOR CUR_Clients IN (
gorkaion@1291
    35
      SELECT ad_client_id
gorkaion@1291
    36
      FROM ad_client
gorkaion@1291
    37
      WHERE NOT EXISTS (SELECT 1 FROM ad_sequence WHERE name = 'DocumentNo_' || v_tablename)
juanpablo@1605
    38
        AND ad_client_id <> '0'
gorkaion@1291
    39
    ) LOOP
gorkaion@1291
    40
      Ad_Sequence_Next('AD_Sequence', CUR_Clients.ad_client_id, v_NextNo) ;
gorkaion@1291
    41
      INSERT INTO AD_Sequence (
gorkaion@1291
    42
        AD_Sequence_ID, AD_Client_ID, AD_Org_ID, IsActive, 
gorkaion@1291
    43
        Created, CreatedBy, Updated, UpdatedBy,
gorkaion@1291
    44
        Name, Description, 
gorkaion@1291
    45
        VFormat, IsAutoSequence, IncrementNo, 
gorkaion@1291
    46
        StartNo, CurrentNext, CurrentNextSys, 
gorkaion@1291
    47
        IsTableID, Prefix, Suffix, StartNewYear
gorkaion@1291
    48
      ) VALUES (
juanpablo@1605
    49
        v_NextNo, CUR_Clients.ad_client_id, '0', 'Y',
juanpablo@1605
    50
        now(), '0', now(), '0',
gorkaion@1291
    51
        'DocumentNo_' || v_TableName,  'DocumentNo/Value for Table ' || v_TableName,
gorkaion@1291
    52
        NULL,  'Y', 1,
gorkaion@1291
    53
        10000000, 10000000, 10000000,
gorkaion@1291
    54
        'N', NULL, NULL, 'N'
gorkaion@1291
    55
      );
gorkaion@1291
    56
    END LOOP;
gorkaion@1291
    57
  END IF;
gorkaion@1291
    58
END AD_COLUMN_TRG2
gorkaion@1291
    59
]]></body>
gorkaion@1291
    60
    </trigger>
gorkaion@1291
    61
  </database>