src-db/database/model/functions/AD_SEQUENCE_DOCTYPE.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
child 4473 c7b88381dc8b
permissions -rw-r--r--
Merge r2.5x intro trunk
carlos@0
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="FUNCTION AD_SEQUENCE_DOCTYPE">
adrian@94
     3
    <function name="AD_SEQUENCE_DOCTYPE" type="NULL">
juanpablo@1605
     4
      <parameter name="p_doctype_id" type="VARCHAR" mode="in">
antonio@735
     5
        <default/>
antonio@735
     6
      </parameter>
juanpablo@1605
     7
      <parameter name="p_id" type="VARCHAR" mode="in">
antonio@735
     8
        <default/>
antonio@735
     9
      </parameter>
antonio@735
    10
      <parameter name="p_update_next" type="CHAR" mode="in">
antonio@735
    11
        <default/>
antonio@735
    12
      </parameter>
antonio@735
    13
      <parameter name="p_documentno" type="VARCHAR" mode="out">
antonio@735
    14
        <default/>
antonio@735
    15
      </parameter>
gorkaion@239
    16
      <body><![CDATA[/*************************************************************************
juanpablo@771
    17
  * The contents of this file are subject to the Compiere Public
juanpablo@771
    18
  * License 1.1 ("License"); You may not use this file except in
juanpablo@771
    19
  * compliance with the License. You may obtain a copy of the License in
juanpablo@771
    20
  * the legal folder of your Openbravo installation.
carlos@0
    21
  * Software distributed under the License is distributed on an
carlos@0
    22
  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
carlos@0
    23
  * implied. See the License for the specific language governing rights
carlos@0
    24
  * and limitations under the License.
juanpablo@778
    25
  * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    26
  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
carlos@0
    27
  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
carlos@0
    28
  * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
carlos@0
    29
  * All Rights Reserved.
carlos@0
    30
  * Contributor(s): Openbravo SL
juanpablo@785
    31
  * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    32
  *
juanpablo@771
    33
  * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    34
  * file and version.
carlos@0
    35
  *************************************************************************
carlos@0
    36
  * $Id: AD_Sequence_DocType.sql,v 1.9 2003/08/06 06:51:27 jjanke Exp $
carlos@0
    37
  ***
carlos@0
    38
  * Title: Get the next DocumentNo of Document Type
carlos@0
    39
  * Description:
carlos@0
    40
  *  store in parameter p_DocumentNo
gorkaion@239
    41
  *  If ID < 1000000, use System Doc Sequence
carlos@0
    42
  *  If no Document Sequence is defined, return null !
carlos@0
    43
  *   Use AD_Sequence_Doc('DocumentNo_myTable',.. to get it directly
carlos@0
    44
  ************************************************************************/
juanpablo@1605
    45
  v_NextNo VARCHAR2(32);
carlos@0
    46
  v_NextNoSys NUMBER;
juanpablo@1605
    47
  v_Sequence_ID VARCHAR2(32):=NULL;
carlos@0
    48
  v_Prefix VARCHAR2(30) ;
carlos@0
    49
  v_Suffix VARCHAR2(30) ;
carlos@0
    50
BEGIN
adrian@95
    51
  -- Is a document Sequence defined and valid
carlos@0
    52
BEGIN
carlos@0
    53
  SELECT DocNoSequence_ID
carlos@0
    54
  INTO v_Sequence_ID
carlos@0
    55
  FROM C_DocType
carlos@0
    56
  WHERE C_DocType_ID=p_DocType_ID -- parameter
carlos@0
    57
    AND IsDocNoControlled='Y'  AND IsActive='Y';
carlos@0
    58
EXCEPTION
carlos@0
    59
WHEN OTHERS THEN
carlos@0
    60
  NULL;
carlos@0
    61
END;
carlos@0
    62
IF(v_Sequence_ID IS NULL) THEN -- No Sequence Number
carlos@0
    63
  p_DocumentNo:= NULL; -- Return NULL
carlos@0
    64
  DBMS_OUTPUT.PUT_LINE('[AD_Sequence_DocType: not found - C_DocType_ID=' || p_DocType_ID || ']') ;
carlos@0
    65
  RETURN;
carlos@0
    66
END IF;
carlos@0
    67
-- Get the numbers
carlos@0
    68
SELECT s.AD_Sequence_ID, s.CurrentNext, s.CurrentNextSys, s.Prefix, s.Suffix
carlos@0
    69
INTO v_Sequence_ID, v_NextNo, v_NextNoSys, v_Prefix, v_Suffix
carlos@0
    70
FROM C_DocType d, AD_Sequence s
carlos@0
    71
WHERE d.C_DocType_ID=p_DocType_ID -- parameter
carlos@0
    72
  AND d.DocNoSequence_ID=s.AD_Sequence_ID  AND s.IsActive='Y'  AND s.IsTableID='N'  AND s.IsAutoSequence='Y'  FOR UPDATE OF CurrentNext, CurrentNextSys;
juanpablo@1605
    73
IF(v_NextNoSys<>-1 AND p_ID<'1000000') THEN -- System No
carlos@0
    74
  IF p_Update_Next='Y' THEN
carlos@0
    75
    UPDATE AD_Sequence
carlos@0
    76
      SET CurrentNextSys=CurrentNextSys + IncrementNo
carlos@0
    77
    WHERE AD_Sequence_ID=v_Sequence_ID;
carlos@0
    78
  END IF;
carlos@0
    79
  p_DocumentNo:=COALESCE(v_Prefix, '') || v_NextNoSys || COALESCE(v_Suffix, '') ;
carlos@0
    80
ELSE -- Standard No
carlos@0
    81
  IF p_Update_Next='Y' THEN
carlos@0
    82
    UPDATE AD_Sequence
carlos@0
    83
      SET CurrentNext=CurrentNext + IncrementNo
carlos@0
    84
    WHERE AD_Sequence_ID=v_Sequence_ID;
carlos@0
    85
  END IF;
carlos@0
    86
  p_DocumentNo:=COALESCE(v_Prefix, '') || v_NextNo || COALESCE(v_Suffix, '') ;
carlos@0
    87
END IF;
carlos@0
    88
-- DBMS_OUTPUT.PUT_LINE(p_DocumentNo);
carlos@0
    89
EXCEPTION
carlos@0
    90
WHEN NO_DATA_FOUND THEN
carlos@0
    91
  RAISE_APPLICATION_ERROR(-20000, '@DocumentTypeSequenceNotFound@') ;
antonio@735
    92
END AD_SEQUENCE_DOCTYPE
gorkaion@239
    93
]]></body>
adrian@94
    94
    </function>
adrian@94
    95
  </database>