src-db/database/model/triggers/C_BPARTNER_LOCATION_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Thu, 24 Apr 2008 19:34:53 +0000
changeset 771 f0f606b4acf4
parent 756 ae11e4610537
child 778 6150609a1a0a
permissions -rw-r--r--
Update database files with the correct license
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_BPARTNER_LOCATION_TRG">
adrian@94
     3
    <trigger name="C_BPARTNER_LOCATION_TRG" table="C_BPARTNER_LOCATION" fires="before" insert="true" update="true" 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.
gorkaion@239
    10
adrian@94
    11
    * Software distributed under the License is distributed on an
adrian@94
    12
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    13
    * implied. See the License for the specific language governing rights
juanpablo@771
    14
adrian@94
    15
    * and limitations under the License.
juanpablo@771
    16
    * The Original Code is  Compiere  ERP \&  Business Solution
juanpablo@771
    17
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
juanpablo@771
    18
adrian@94
    19
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    20
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    21
    * All Rights Reserved.
adrian@94
    22
    * Contributor(s): Openbravo SL
juanpablo@771
    23
juanpablo@771
    24
    * Contributions are Copyright (C) 1999-2008 Openbravo, S.L
juanpablo@771
    25
    *
juanpablo@771
    26
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    27
    * file and version.
adrian@94
    28
    *************************************************************************
adrian@94
    29
    * $Id: C_BPartner_Location_Trg.sql,v 1.3 2002/10/01 02:23:31 jjanke Exp $
adrian@94
    30
    ***
adrian@94
    31
    * Title: Update Name with (updated) Location details
adrian@94
    32
    * Description:
adrian@94
    33
    * Set Name to City
adrian@94
    34
    *  or if not exists to Address1
adrian@94
    35
    *  or if not exists to "-'
adrian@94
    36
    ************************************************************************/
adrian@94
    37
adrian@94
    38
    --v_City    VARCHAR2(60);
adrian@94
    39
    --v_Address1   VARCHAR2(60);
adrian@94
    40
    --v_Address2   VARCHAR2(60);
adrian@94
    41
    v_name VARCHAR2(60) ;
gorkaion@280
    42
    v_DateNull DATE := TO_DATE('01-01-1900', 'DD-MM-YYYY');
adrian@94
    43
BEGIN
adrian@94
    44
  DBMS_OUTPUT.PUT_LINE('C_BPartner_Location_Trg') ;
adrian@94
    45
  IF(UPDATING) THEN
gorkaion@280
    46
    IF NOT(COALESCE(:old.C_Location_ID, 0) <> COALESCE(:NEW.C_Location_ID, 0) OR COALESCE(:old.Updated, v_DateNull) <> COALESCE(:NEW.Updated, v_DateNull)) THEN
adrian@94
    47
      RETURN;
adrian@94
    48
    END IF;
adrian@94
    49
  END IF;
adrian@94
    50
  /* -- Get Address Info
adrian@94
    51
  SELECT City, Address1, Address2
adrian@94
    52
  INTO v_City, v_Address1, v_Address2
adrian@94
    53
  FROM  C_Location
adrian@94
    54
  WHERE  C_Location_ID=:new.C_Location_ID;
adrian@94
    55
  -- No City
adrian@94
    56
  IF (v_City IS NULL) THEN
adrian@94
    57
  v_City:=v_Address1;
adrian@94
    58
  END IF;
adrian@94
    59
  -- No City nor Address 1
adrian@94
    60
  IF (v_City IS NULL) THEN
adrian@94
    61
  v_City:='-';
adrian@94
    62
  DBMS_OUTPUT.PUT_LINE('No Address Info ID=' || :new.C_BPartner_Location_ID);
adrian@94
    63
  END IF;
adrian@94
    64
  */
adrian@94
    65
  -- Set Name
adrian@94
    66
  IF DELETING THEN
adrian@94
    67
    v_name:=:old.Name;
adrian@94
    68
  ELSE
adrian@94
    69
    v_name:=:new.Name;
adrian@94
    70
  END IF;
adrian@94
    71
  IF(SUBSTR(v_name, 1, 1)='.') THEN
adrian@94
    72
    :new.Name:='.'||C_Location_Name(:new.C_Location_ID) ;
adrian@94
    73
  END IF;
adrian@94
    74
EXCEPTION
adrian@94
    75
WHEN OTHERS THEN
adrian@94
    76
  DBMS_OUTPUT.PUT_LINE('Not unique - ' || SQLERRM) ;
adrian@94
    77
  :new.Name:=C_Location_Name(:new.C_Location_ID) ||'('||:new.C_Location_ID||')';
antonio@735
    78
END C_BPARTNER_LOCATION_TRG
gorkaion@239
    79
]]></body>
adrian@94
    80
    </trigger>
adrian@94
    81
  </database>