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
<?xml version="1.0"?>
  <database name="TRIGGER AD_COLUMN_TRG2">
    <trigger name="AD_COLUMN_TRG2" table="AD_COLUMN" fires="after" insert="true" update="true" delete="false" foreach="row">
      <body><![CDATA[
/*************************************************************************
* The contents of this file are subject to the Openbravo  Public  License
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
* Version 1.1  with a permitted attribution clause; you may not  use this
* file except in compliance with the License. You  may  obtain  a copy of
* the License at http://www.openbravo.com/legal/license.html
* 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 Openbravo ERP.
* The Initial Developer of the Original Code is Openbravo SL
* All portions are Copyright (C) 2008 Openbravo SL
* All Rights Reserved.
* Contributor(s):  ______________________________________.
************************************************************************/
  TYPE RECORD IS REF CURSOR;
  CUR_Clients RECORD;
  v_TableName VARCHAR2(40);
  v_NextNo VARCHAR2(32);
  BEGIN
  /**
  * Create Sequence for DocumentNo and Value columns
  */
  IF (:new.ColumnName = 'DocumentNo' OR :new.ColumnName = 'Value') THEN
    SELECT TableName INTO v_TableName
    FROM ad_table
    WHERE ad_table.ad_table_id = :new.ad_table_id;
         
    FOR CUR_Clients IN (
      SELECT ad_client_id
      FROM ad_client
      WHERE NOT EXISTS (SELECT 1 FROM ad_sequence WHERE name = 'DocumentNo_' || v_tablename)
        AND ad_client_id <> '0'
    ) LOOP
      Ad_Sequence_Next('AD_Sequence', CUR_Clients.ad_client_id, v_NextNo) ;
      INSERT INTO AD_Sequence (
        AD_Sequence_ID, AD_Client_ID, AD_Org_ID, IsActive, 
        Created, CreatedBy, Updated, UpdatedBy,
        Name, Description, 
        VFormat, IsAutoSequence, IncrementNo, 
        StartNo, CurrentNext, CurrentNextSys, 
        IsTableID, Prefix, Suffix, StartNewYear
      ) VALUES (
        v_NextNo, CUR_Clients.ad_client_id, '0', 'Y',
        now(), '0', now(), '0',
        'DocumentNo_' || v_TableName,  'DocumentNo/Value for Table ' || v_TableName,
        NULL,  'Y', 1,
        10000000, 10000000, 10000000,
        'N', NULL, NULL, 'N'
      );
    END LOOP;
  END IF;
END AD_COLUMN_TRG2
]]></body>
    </trigger>
  </database>