src-db/database/model/triggers/C_BANKACCOUNTIBAN_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Mon, 28 Apr 2008 09:28:08 +0000
changeset 785 8dba91261590
parent 783 66817fa8e876
child 934 016ed4681fa0
permissions -rw-r--r--
Fix last update of copyright years in database files
juanpablo@785
     1
<?xml version="1.0"?>
juanpablo@785
     2
  <database name="TRIGGER C_BANKACCOUNTIBAN_TRG">
juanpablo@785
     3
    <trigger name="C_BANKACCOUNTIBAN_TRG" table="C_BANKACCOUNT" fires="before" insert="true" update="true" delete="false" foreach="row">
juanpablo@785
     4
      <body><![CDATA[
juanpablo@785
     5
    /*************************************************************************
juanpablo@785
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@785
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@785
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@785
     9
    * the legal folder of your Openbravo installation.
juanpablo@785
    10
    * Software distributed under the License is distributed on an
juanpablo@785
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
juanpablo@785
    12
    * implied. See the License for the specific language governing rights
juanpablo@785
    13
    * and limitations under the License.
juanpablo@785
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@785
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
juanpablo@785
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
juanpablo@785
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
juanpablo@785
    18
    * All Rights Reserved.
juanpablo@785
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@785
    21
    *
juanpablo@785
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@785
    23
    * file and version.
juanpablo@785
    24
    *************************************************************************
juanpablo@785
    25
    * $Id: A_ASSET_Trg.sql,v 1.4 2002/10/23 03:16:57 jjanke Exp $
juanpablo@785
    26
    ***
juanpablo@785
    27
    * Title: Asset new necord
juanpablo@785
    28
    * Description:
juanpablo@785
    29
    *    - create default Account records
juanpablo@785
    30
    ************************************************************************/
pablo@711
    31
pablo@711
    32
  v_IBAN_check NUMBER;
pablo@711
    33
  v_Bank NVARCHAR2(4);
pablo@711
    34
  v_Branch NVARCHAR2(4);
pablo@711
    35
  v_DigitBank NVARCHAR2(1);
pablo@711
    36
  v_Country NUMBER;
pablo@711
    37
  v_CountryId NVARCHAR2(2);
antonio@737
    38
  v_Length NUMBER;
pablo@711
    39
BEGIN
pablo@711
    40
  --  Default Accounts for all AcctSchema
pablo@711
    41
  IF(INSERTING OR UPDATING) THEN
pablo@711
    42
    IF (:NEW.CODEACCOUNT IS NOT NULL OR :NEW.DIGITCONTROL IS NOT NULL) THEN
pablo@711
    43
      SELECT CODEBANK, CODEBRANCH, DIGITCONTROL
pablo@711
    44
      INTO v_Bank, v_Branch, v_DigitBank
pablo@711
    45
      FROM C_BANK
pablo@711
    46
      WHERE C_BANK_ID=:NEW.C_BANK_ID;
pablo@711
    47
      IF (v_Bank IS NULL OR v_Branch IS NULL OR v_DigitBank IS NULL) THEN
pablo@711
    48
        RAISE_APPLICATION_ERROR(-20258, 'Bank information is missing.');
pablo@711
    49
      END IF;
pablo@711
    50
    END IF;
pablo@711
    51
    IF (:NEW.IBAN IS NOT NULL) THEN
pablo@711
    52
        SELECT MOD(CONCAT(
pablo@711
    53
                 CONCAT(
pablo@711
    54
                   CONCAT(
pablo@711
    55
                     SUBSTR(:NEW.IBAN, 5, LENGTH(:NEW.IBAN)-4),
pablo@711
    56
                     ASCII(SUBSTR(:NEW.IBAN,1,1))-55
pablo@711
    57
                   ),
pablo@711
    58
                   ASCII(SUBSTR(:NEW.IBAN,2,1))-55),
pablo@711
    59
                 SUBSTR(:NEW.IBAN,3,2)),97) AS DC
pablo@711
    60
                 INTO v_IBAN_check
pablo@711
    61
        FROM DUAL;
pablo@711
    62
        IF (v_IBAN_check <> 1) THEN
pablo@711
    63
          RAISE_APPLICATION_ERROR(-20257, 'Incorrect IBAN Code.');
pablo@711
    64
        END IF;
pablo@711
    65
        SELECT C_COUNTRY_ID
pablo@711
    66
        INTO v_Country
pablo@711
    67
        FROM C_BANK
pablo@711
    68
        WHERE C_BANK_ID=:NEW.C_BANK_ID;
pablo@711
    69
        IF (v_Country IS NULL) THEN
pablo@711
    70
          RAISE_APPLICATION_ERROR(-20260, 'Bank does not have country defined.');
pablo@711
    71
        END IF;
pablo@711
    72
        SELECT IBANCOUNTRY, IBANNODIGITS
pablo@711
    73
        INTO v_CountryId, v_Length
pablo@711
    74
        FROM C_COUNTRY
pablo@711
    75
        WHERE C_COUNTRY_ID=(
pablo@711
    76
          SELECT C_COUNTRY_ID
pablo@711
    77
          FROM C_BANK
pablo@711
    78
          WHERE C_BANK_ID=:NEW.C_BANK_ID
pablo@711
    79
          );
pablo@711
    80
        IF ((v_CountryId IS NULL OR v_Length IS NULL) OR (v_CountryId <> SUBSTR(:NEW.IBAN,1,2) OR v_Length <> LENGTH(:NEW.IBAN))) THEN
pablo@711
    81
          RAISE_APPLICATION_ERROR(-20259, 'The IBAN number defined in the bank account tab, must fit the IBAN data of the country defined in the bank tab.');
pablo@711
    82
        END IF;
pablo@711
    83
      END IF;
antonio@737
    84
    IF (:NEW.SHOWSPANISH='Y') THEN
pablo@711
    85
      SELECT CODEBANK, CODEBRANCH, DIGITCONTROL
pablo@711
    86
      INTO v_Bank, v_Branch, v_DigitBank
pablo@711
    87
      FROM C_BANK
pablo@711
    88
      WHERE C_BANK_ID=:NEW.C_BANK_ID;
david@783
    89
      :NEW.DISPLAYEDACCOUNT:=v_Bank || '-' || v_Branch || '-' || v_DigitBank || :NEW.DIGITCONTROL || '-' || :NEW.CODEACCOUNT;
pablo@711
    90
    ELSIF (:NEW.SHOWIBAN='Y') THEN
pablo@711
    91
      :NEW.DISPLAYEDACCOUNT:=SUBSTR(:NEW.IBAN,1,4) || '-' || SUBSTR(:NEW.IBAN, 5, LENGTH(:NEW.IBAN)-4);
pablo@711
    92
    ELSE
pablo@711
    93
      :NEW.DISPLAYEDACCOUNT:=:NEW.GENERICACCOUNT;
pablo@711
    94
    END IF;
pablo@711
    95
  END IF;
pablo@711
    96
EXCEPTION
pablo@711
    97
 WHEN NO_DATA_FOUND THEN
pablo@711
    98
  RAISE_APPLICATION_ERROR(-20257, 'Incorrect IBAN Code.') ;
pablo@711
    99
END C_BANKACCOUNTIBAN_TRG
juanpablo@785
   100
]]></body>
juanpablo@785
   101
    </trigger>
juanpablo@785
   102
  </database>