move branch adempire311 to trunk

This commit is contained in:
vpj-cd 2006-11-17 03:06:54 +00:00
parent c42a77c460
commit 1fb80939f9
177 changed files with 511474 additions and 0 deletions

11
db/.project Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>db</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

13
db/CopyRight.sql Normal file
View File

@ -0,0 +1,13 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CopyRight.sql,v 1.1 2006/04/21 17:51:59 jjanke Exp $
***
* Title:
* Description:
************************************************************************/

191318
db/ERModel/AD25.dm1 Normal file

File diff suppressed because one or more lines are too long

242162
db/ERModel/AD25g2.dm1 Normal file

File diff suppressed because one or more lines are too long

28840
db/ERModel/Logical.dtd Normal file

File diff suppressed because it is too large Load Diff

10
db/UpdateAdempiere.bat Normal file
View File

@ -0,0 +1,10 @@
@Title Update local Adempiere DB
@Rem $Id: UpdateAdempiere.bat,v 1.4 2004/11/01 06:06:16 jjanke Exp $
@dir database\DatabaseBuild.sql
@Echo requires manual entry of exit
sqlplus adempiere/adempiere @database\DatabaseBuild.sql
sqlplus adempiere/adempiere @maintain\Maintenance\DBA_Recompile_Run.sql

10
db/UpdateReference.bat Normal file
View File

@ -0,0 +1,10 @@
@Title Update local Reference DB
@Rem $Id: UpdateReference.bat,v 1.1 2003/10/11 05:24:26 jjanke Exp $
@dir database\DatabaseBuild.sql
@Echo requires manual entry of exit
sqlplus reference/reference @database\DatabaseBuild.sql
sqlplus reference/reference @maintain\Maintenance\DBA_Recompile_Run.sql

View File

@ -0,0 +1,129 @@
CREATE OR REPLACE PACKAGE BODY Adempiere_Context
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Context_Body.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Security Procedure
* Description:
* When logging in, the procedure requires access to login tables
* (AD_User, AD_User_Roles, AD_Role, AD_Client, AD_Org, M_Warehouse)
* The security policy includes all tables but these
* (also exclused report views, temporary tables)
* All tables but AD_ have GRANTs to public
*
* The user has to log in with UserName, Password and Role
* This sets ClientList, OrgList, Language
* Unrestricted access is obtained by loggin in as Accorto/Internal Server
* This sets Server to true
******************************************************************************/
/******************************************************************************
* Sets Context Client - ClientList, OrgList
*/
PROCEDURE Login
(
UserName IN VARCHAR2,
UserPwd IN VARCHAR2,
UserRole IN VARCHAR2,
UserLang IN VARCHAR2 DEFAULT 'USAENG'
)
IS
ClientList VARCHAR2(60);
OrgList VARCHAR2(60);
BEGIN
-- No Access Restrictions
IF (UserName = 'Adempiere' AND UserPwd = 'Internal' AND UserRole = 'Server') THEN
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'Server', 'true');
RETURN;
END IF;
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'Server', 'false');
/* Check Access
SELECT r.ClientList, r.OrgList
INTO ClientList, OrgList
FROM AD_User u, AD_User_Roles ur, AD_Role r
WHERE u.AD_User_ID=ur.AD_User_ID
AND r.AD_Role_ID=ur.AD_Role_ID
AND u.IsActive='Y' AND r.IsActive='Y' AND ur.IsActive='Y'
AND u.Name=UserName AND u.Password=UserPwd AND r.Name=UserRole;
*/
-- Check Values to include System
IF (ClientList <> '0' AND SUBSTR(ClientList,1,2) <> '0,') THEN
ClientList := '0,' || ClientList;
END IF;
IF (OrgList <> '0' AND SUBSTR(OrgList,1,2) <> '0,') THEN
OrgList := '0,' || OrgList;
END IF;
-- Set Values
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'ClientList', ClientList);
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'OrgList', OrgList);
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'Language', UserLang);
--
EXCEPTION
WHEN OTHERS THEN
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'ClientList', NULL);
DBMS_SESSION.SET_CONTEXT('AdempiereInc', 'Login', NULL);
RAISE_APPLICATION_ERROR(-20222, 'LoginFailure');
END Login;
/******************************************************************************
* Set Environment Variables
*/
PROCEDURE SetEnv
(
Name IN VARCHAR2,
NewValue IN VARCHAR
)
IS
BEGIN
IF (Name <> 'ClientList' AND Name <> 'OrgList' AND Name <> 'Login') THEN
DBMS_SESSION.SET_CONTEXT('AdempiereInc', Name, NewValue);
END IF;
END SetEnv;
/******************************************************************************
* Return Security Predicates
*/
FUNCTION GetPredicate
(
ObjectSchema VARCHAR2,
ObjectName VARCHAR2
)
RETURN VARCHAR2
IS
Predicate VARCHAR2 (2000);
BEGIN
-- Unrestricted Access
IF (SYS_CONTEXT('AdempiereInc','Server') = 'true') THEN
Predicate := '';
-- No Access
ELSIF (SYS_CONTEXT('AdempiereInc','ClientList') IS NULL) THEN
Predicate := '1=2';
-- Translation
ELSIF (ObjectName LIKE '%TRL' AND SYS_CONTEXT('AdempiereInc','Language') <> 'USAENG') THEN
Predicate := 'AD_Language=''' || SYS_CONTEXT('AdempiereInc','Language') || '''';
-- Standard Security
ELSE
Predicate := 'AD_Client_ID IN (' || SYS_CONTEXT('AdempiereInc','ClientList')
|| ') AND AD_Org_ID IN (' || SYS_CONTEXT('AdempiereInc','OrgList') || ')';
END IF;
RETURN Predicate;
END GetPredicate;
END Adempiere_Context;
/

View File

@ -0,0 +1,22 @@
CREATE OR REPLACE PACKAGE Adempiere_Context
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Context_Header.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Context Header
* Description:
************************************************************************/
AS
PROCEDURE Login (UserName VARCHAR2, UserPwd VARCHAR2, UserRole VARCHAR2, UserLang VARCHAR2 DEFAULT 'USAENG');
--
PROCEDURE SetEnv (Name VARCHAR2, NewValue VARCHAR);
--
FUNCTION GetPredicate (ObjectSchema VARCHAR2, ObjectName VARCHAR2) RETURN VARCHAR2;
--
END Adempiere_Context;
/

View File

@ -0,0 +1,23 @@
/**
* List Context
*/
select * from dba_context order by 1,2
/
select * from dba_policies order by 1,2
/
-- Context
SELECT SYS_CONTEXT('USERENV', 'CURRENT_USER') "Current User",
SYS_CONTEXT('USERENV', 'CURRENT_USERID') "Current UserID",
SYS_CONTEXT('USERENV', 'DB_NAME') "DB Name",
SYS_CONTEXT('USERENV', 'LANGUAGE') "Language",
SYS_CONTEXT('USERENV', 'SESSIONID') "Session ID",
SYS_CONTEXT('USERENV', 'HOST') "Host",
SYS_CONTEXT('USERENV', 'IP_ADDRESS') "IP Address"
FROM DUAL
/
BEGIN
DBMS_SESSION.SET_IDENTIFIER('A123');
END;
/
SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL
/

View File

@ -0,0 +1,13 @@
DECLARE
string VARCHAR2(60);
no NUMBER;
BEGIN
-- Adempiere_Context.Login('SuperUser','System','Friedenburg Mandant','GERGER');
-- Adempiere_Context.Login('SuperUser','System','System Administrator');
-- Adempiere_Context.Login('System','System','System Administrator');
Adempiere_Context.Login('Adempiere','Internal','Server');
--
SELECT COUNT(*) INTO No FROM C_DocType;
DBMS_OUTPUT.PUT_LINE('Count= ' || No);
END;

View File

@ -0,0 +1,15 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CreateContext.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Create Context
* Description:
************************************************************************/
CREATE OR REPLACE CONTEXT AdempiereInc USING Adempiere.Adempiere_Context ACCESSED GLOBALLY
/
--DROP CONTEXT AdempiereInc

View File

@ -0,0 +1,51 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Policy_Add.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Create Policies
* Description:
************************************************************************/
DECLARE
CURSOR Cur_Tables IS
SELECT TableName
FROM AD_Table
-- General accessible tables
WHERE TableName NOT LIKE 'RV%' -- Report Views
AND TableName NOT LIKE 'T%' -- Temporary
-- Login Tables
AND TableName NOT IN ('AD_User', 'AD_User_Roles', 'AD_Role', 'AD_Client', 'AD_Org', 'M_Warehouse')
-- Non Standard Tables
AND TableName NOT LIKE 'AD_PInstance%'
AND TableName NOT IN ('AD_Find')
ORDER BY TableName;
BEGIN
DBMS_OUTPUT.PUT_LINE('Loging in ...');
Adempiere_Context.Login('SuperUser','System','System Administrator');
-- Adempiere_Context.Login('Adempiere','Internal','Server');
--
DBMS_OUTPUT.PUT_LINE('Creating Policies ...');
FOR t IN Cur_Tables LOOP
BEGIN
DBMS_OUTPUT.PUT(t.TableName);
DBMS_RLS.ADD_POLICY (
'Adempiere', -- object_schema
t.TableName, -- object_name
t.TableName || '_Pol', -- policy_name
'Adempiere', -- function_schema
'Adempiere_Context.GetPredicate', -- policy_function
NULL, -- statement_types 'SELECT,INSERT,UPDATE,DELETE'
TRUE, -- update_check
TRUE); -- enable
DBMS_OUTPUT.PUT_LINE(' ok');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(' *** error ***');
END;
END LOOP;
END;
/

View File

@ -0,0 +1,35 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Policy_Drop.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Drop Policies
* Description:
************************************************************************/
DECLARE
CURSOR Cur_Tables IS
SELECT *
FROM DBA_Policies
ORDER BY 2;
BEGIN
Adempiere_Context.Login('Adempiere','Internal','Server');
DBMS_OUTPUT.PUT_LINE('Dropping Policies ...');
FOR t IN Cur_Tables LOOP
BEGIN
DBMS_OUTPUT.PUT(InitCap(t.Object_Name));
DBMS_RLS.DROP_POLICY (
NULL, -- object_schema
t.Object_Name, -- object_name
t.Policy_Name); -- policy_name
DBMS_OUTPUT.PUT_LINE(' ok');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(' * not found *');
END;
END LOOP;
END;

View File

@ -0,0 +1,35 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Privileges.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Pivileges - Access to Adempiere
* Description:
************************************************************************/
DECLARE
-- Read only to all Tables but Dictionary
CURSOR Cur_Tables_RO IS
SELECT TableName
FROM AD_Table
WHERE TableName NOT LIKE 'AD_%';
CMD VARCHAR2(256);
BEGIN
DBMS_OUTPUT.PUT_LINE('Granting Access to Public ...');
FOR ro IN Cur_Tables_RO LOOP
CMD := 'GRANT SELECT ON ' || ro.TableName || ' TO PUBLIC';
DBMS_OUTPUT.PUT(ro.TableName);
BEGIN
EXECUTE IMMEDIATE CMD;
DBMS_OUTPUT.PUT_LINE(' ok');
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(' ** error **');
END;
END LOOP;
END;
/

View File

@ -0,0 +1,20 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Wrap.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: SQL Plus Script to Wrap Security
* Description:
************************************************************************/
START Context_Header.plb
/
START Context_Body.plb
/
SELECT * FROM USER_ERRORS
/
EXIT

View File

@ -0,0 +1,16 @@
@Title Wrap Security Procedures
@Rem $Id: access.bat,v 1.3 2001/11/19 14:26:47 jjanke Exp $
@Echo ------
@Echo Wrap
@Echo ------
wrap iname=context_header
wrap iname=context_body
@Echo ------
@Echo Create
@Echo ------
@sqlplus adempiere/adempiere @Wrap
@pause

View File

@ -0,0 +1,660 @@
CREATE OR REPLACE PACKAGE BODY Adempiere_Context wrapped
0
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
abcd
3
b
8106000
1
4
0
48
2 :e:
1PACKAGE:
1BODY:
1ADEMPIERE_CONTEXT:
1LOGIN:
1USERNAME:
1VARCHAR2:
1USERPWD:
1USERROLE:
1USERLANG:
1USAENG:
1CLIENTLIST:
160:
1ORGLIST:
1=:
1Adempiere:
1Internal:
1Server:
1DBMS_SESSION:
1SET_CONTEXT:
1AdempiereInc:
1true:
1RETURN:
1false:
1R:
1AD_USER:
1U:
1AD_USER_ROLES:
1UR:
1AD_ROLE:
1AD_USER_ID:
1AD_ROLE_ID:
1ISACTIVE:
1Y:
1NAME:
1PASSWORD:
1!=:
10:
1SUBSTR:
11:
12:
10,:
1||:
1ClientList:
1OrgList:
1Language:
1OTHERS:
1Login:
1RAISE_APPLICATION_ERROR:
1-:
120222:
1LoginFailure:
1SETENV:
1NEWVALUE:
1VARCHAR:
1FUNCTION:
1GETPREDICATE:
1OBJECTSCHEMA:
1OBJECTNAME:
1PREDICATE:
12000:
1SYS_CONTEXT:
1:
1ELSIF:
1IS NULL:
11=2:
1LIKE:
1%TRL:
1AD_Language=':
1':
1AD_Client_ID IN (:
1) AND AD_Org_ID IN (:
1):
0
0
0
1e3
2
0 a0 1d a0 97 9a 8f a0
b0 3d 8f a0 b0 3d 8f a0
b0 3d 8f a0 6e b0 3d b4
a3 55 6a a0 51 a5 1c 81
b0 a3 a0 51 a5 1c 81 b0
a0 7e 6e b4 2e a0 7e 6e
b4 2e a 10 a0 7e 6e b4
2e a 10 5a :2 a0 6b :3 6e a5
57 a0 65 b7 19 3c :2 a0 6b
:3 6e a5 57 :2 a0 6b :2 a0 6b ac
:4 a0 b9 :2 a0 b9 :2 a0 b9 b2 ee
:2 a0 6b a0 7e a0 6b b4 2e
:2 a0 6b a0 7e a0 6b b4 2e
a 10 :2 a0 6b 7e 6e b4 2e
a 10 :2 a0 6b 7e 6e b4 2e
a 10 :2 a0 6b 7e 6e b4 2e
a 10 :2 a0 6b a0 7e b4 2e
a 10 :2 a0 6b a0 7e b4 2e
a 10 :2 a0 6b a0 7e b4 2e
a 10 ac e5 d0 b2 e9 a0
7e 6e b4 2e :2 a0 :2 51 a5 b
7e 6e b4 2e a 10 5a a0
6e 7e a0 b4 2e d b7 19
3c a0 7e 6e b4 2e :2 a0 :2 51
a5 b 7e 6e b4 2e a 10
5a a0 6e 7e a0 b4 2e d
b7 19 3c :2 a0 6b :2 6e a0 a5
57 :2 a0 6b :2 6e a0 a5 57 :2 a0
6b :2 6e a0 a5 57 b7 a0 53
:2 a0 6b :2 6e 4d a5 57 :2 a0 6b
:2 6e 4d a5 57 a0 7e 51 b4
2e 6e a5 57 b7 a6 9 a4
a0 b1 11 68 4f 9a 8f a0
b0 3d 8f a0 b0 3d b4 55
6a a0 7e 6e b4 2e a0 7e
6e b4 2e a 10 a0 7e 6e
b4 2e a 10 5a :2 a0 6b 6e
:2 a0 a5 57 b7 19 3c b7 a4
a0 b1 11 68 4f a0 8d 8f
a0 b0 3d 8f a0 b0 3d b4
:2 a0 a3 2c 6a a0 51 a5 1c
81 b0 a0 :2 6e a5 b 7e 6e
b4 2e 5a a0 6e d a0 b7
a0 :2 6e a5 b 7e b4 2e 5a
a0 6e d a0 b7 19 a0 7e
6e b4 2e a0 :2 6e a5 b 7e
6e b4 2e a 10 5a a0 6e
7e a0 :2 6e a5 b b4 2e 7e
6e b4 2e d b7 19 a0 6e
7e a0 :2 6e a5 b b4 2e 7e
6e b4 2e 7e a0 :2 6e a5 b
b4 2e 7e 6e b4 2e d b7
:2 19 3c :2 a0 65 b7 a4 a0 b1
11 68 4f b1 b7 a4 11 a0
b1 56 4f 17 b5
1e3
2
0 3 7 8 c 16 2f 2b
2a 37 44 40 27 4c 55 51
3f 5d 6f 66 6a 3c 77 65
99 80 84 88 62 8c 8d 95
7f b5 a4 7c a8 a9 b1 a3
bc a0 c0 c5 c6 cb cf d2
d7 d8 1 dd e2 e6 e9 ee
ef 1 f4 f9 fc 100 104 107
10c 111 116 117 11c 120 124 126
12a 12d 131 135 138 13d 142 147
148 14d 151 155 158 15c 160 163
164 168 16c 170 174 176 17a 17e
180 184 188 18a 18b 192 196 19a
19d 1a1 1a4 1a8 1ab 1ac 1b1 1b5
1b9 1bc 1c0 1c3 1c7 1ca 1cb 1
1d0 1d5 1d9 1dd 1e0 1e3 1e8 1e9
1 1ee 1f3 1f7 1fb 1fe 201 206
207 1 20c 211 215 219 21c 21f
224 225 1 22a 22f 233 237 23a
23e 241 242 1 247 24c 250 254
257 25b 25e 25f 1 264 269 26d
271 274 278 27b 27c 1 281 286
287 28d 291 292 297 29b 29e 2a3
2a4 2a9 2ad 2b1 2b4 2b7 2b8 2ba
2bd 2c2 2c3 1 2c8 2cd 2d0 2d4
2d9 2dc 2e0 2e1 2e6 2ea 2ec 2f0
2f3 2f7 2fa 2ff 300 305 309 30d
310 313 314 316 319 31e 31f 1
324 329 32c 330 335 338 33c 33d
342 346 348 34c 34f 353 357 35a
35f 364 368 369 36e 372 376 379
37e 383 387 388 38d 391 395 398
39d 3a2 3a6 3a7 3ac 3ae 1 3b2
3b6 3ba 3bd 3c2 3c7 3c8 3c9 3ce
3d2 3d6 3d9 3de 3e3 3e4 3e5 3ea
3ee 3f1 3f4 3f5 3fa 3ff 400 405
407 408 40d 411 415 417 423 427
429 442 43e 43d 44a 457 453 43a
45f 452 464 468 46c 44f 470 475
476 47b 47f 482 487 488 1 48d
492 496 499 49e 49f 1 4a4 4a9
4ac 4b0 4b4 4b7 4bc 4c0 4c4 4c5
4ca 4cc 4d0 4d3 4d5 4d9 4dd 4df
4eb 4ef 4f1 4f5 50e 50a 509 516
523 51f 506 52b 51e 530 534 555
53c 540 544 51b 548 549 551 53b
55c 560 565 538 56a 56c 56f 574
575 57a 57d 581 586 58a 58e 590
594 599 59e 59f 5a1 5a4 5a5 5aa
5ad 5b1 5b6 5ba 5be 5c0 5c4 5c8
5cb 5d0 5d1 5d6 5da 5df 5e4 5e5
5e7 5ea 5ef 5f0 1 5f5 5fa 5fd
601 606 609 60d 612 617 618 61a
61b 620 623 628 629 62e 632 634
638 63c 641 644 648 64d 652 653
655 656 65b 65e 663 664 669 66c
670 675 67a 67b 67d 67e 683 686
68b 68c 691 695 697 69b 69f 6a2
6a6 6aa 6ae 6b0 6b4 6b8 6ba 6c6
6ca 6cc 6ce 6d0 6d4 6e0 6e4 6e6
6e9 6eb 6f4
1e3
2
0 :2 1 9 e c 3 f :3 3
f :3 3 f :3 3 f 20 :2 3 2
3 :2 2 e 17 16 :2 e :2 3 c
15 14 :2 c 3 7 10 12 :2 10
21 29 2b :2 29 :2 7 3a 43 45
:2 43 :2 7 6 7 :2 14 20 2f 39
:2 7 :2 4 4f :3 3 :2 10 1c 2b 35
:2 3 b :2 d 19 :2 1b b a 16
8 10 8 13 21 13 25 2d
25 3 8 9 :2 b 16 15 :2 19
:2 15 9 :2 b 16 15 :2 19 :2 15 :3 9
:2 b 13 14 :2 13 :2 9 1c :2 1e 26
27 :2 26 :2 9 2f :2 32 3a 3b :2 3a
:3 9 :2 b 10 :3 f :2 9 1d :2 1f 28
:3 27 :2 9 34 :2 36 3b :3 3a :2 9 :5 3
7 12 15 :2 12 1d 24 2f 31
:2 1d 34 37 :2 34 :2 7 6 4 12
17 1a :2 12 4 3d :2 3 7 f
12 :2 f 1a 21 29 2b :2 1a 2e
31 :2 2e :2 7 6 4 f 14 17
:2 f 4 37 :2 3 6 :2 13 1f 2e
3c :3 6 :2 13 1f 2e 39 :3 6 :2 13
1f 2e 3a :2 6 2 :2 9 8 :2 15
21 30 3e :3 8 :2 15 21 30 39
:2 8 5 1d 1e :2 1d 25 :2 5 10
:2 4 3 6 :4 2 c 3 d :3 3
10 :2 3 :3 2 7 c f :2 c 20
25 28 :2 25 :2 7 36 3b 3e :2 3b
:2 7 6 4 :2 11 1d 2c 32 :2 4
47 :2 3 :2 2 6 :5 2 b 6 16
:3 6 16 :2 6 :2 2 9 6 :2 2 14
1e 1d :2 14 6 8 14 22 :2 8
2c 2e :2 2c 7 4 11 4 3
36 a 16 24 :5 a 9 4 11
4 3 3b 36 :2 a 1a :2 a 25
31 3f :2 25 4b 4e :2 4b :2 a 9
4 11 22 25 31 3f :2 25 :2 11
4b 4e :2 11 4 58 36 7 14
28 2b 37 45 :2 2b :2 14 5 8
:2 14 1f 22 2e 3c :2 22 :2 14 47
4a :2 14 7 :2 3 :2 4 6 d 6
:2 2 6 :8 2 5 :5 1
1e3
2
0 :4 1 1d :4 1f :4 20 :4 21 :5 22 1e
25 :2 1d :6 25 :7 26 :14 29 :8 2a :2 2b :3 29
:8 2d :7 30 :2 31 :b 32 :9 33 :9 34 :2 33 :7 35
:2 33 :7 35 :2 33 :7 35 :2 33 :7 36 :2 33 :7 36
:2 33 :7 36 :2 33 32 :4 30 :12 39 :7 3a :3 39
:12 3c :7 3d :3 3c :8 41 :8 42 :8 43 27 :2 46
:8 47 :8 48 :8 49 :3 46 45 4b :3 1d 4b
51 :4 53 :4 54 52 :2 51 :14 58 :8 59 :3 58
:2 57 5b :3 51 5b :2 61 :4 63 :4 64 62
:2 66 68 :2 61 :6 68 :a 6b :3 6c 6f 6b
:9 6f :3 70 73 6f 6b :11 73 :f 74 73
6b :a 78 :2 79 :2 78 :6 79 :2 78 :2 79 :3 78
:2 77 :2 6b :3 7d :2 69 7e :3 61 7e :4 1d
80 :5 1
6f6
4
:3 0 1 :4 0 2
:3 0 3 :6 0 1
:2 0 4 :a 0 126
2 :4 0 5 3c
0 3 6 :3 0
5 :7 0 8 7
:3 0 9 62 0
7 6 :3 0 7
:7 0 c b :3 0
6 :3 0 8 :7 0
10 f :3 0 c
:2 0 b 6 :3 0
a :4 0 9 :7 0
15 13 14 :2 0
c :2 0 12 17
:2 0 126 5 19
:2 0 6 :3 0 10
1b 1d :6 0 20
1e 0 124 b
:6 0 e :2 0 16
6 :3 0 14 22
24 :6 0 27 25
0 124 d :6 0
5 :3 0 f :4 0
1a 29 2b :3 0
7 :3 0 e :2 0
10 :4 0 1f 2e
30 :3 0 2c 32
31 :2 0 8 :3 0
e :2 0 11 :4 0
24 35 37 :3 0
33 39 38 :2 0
3a :2 0 12 :3 0
13 :3 0 3c 3d
0 14 :4 0 11
:4 0 15 :4 0 27
3e 42 :2 0 46
16 :6 0 46 2b
47 3b 46 0
48 2e 0 104
12 :3 0 13 :3 0
49 4a 0 14
:4 0 11 :4 0 17
:4 0 30 4b 4f
:2 0 104 18 :3 0
b :3 0 51 52
0 18 :3 0 d
:3 0 54 55 0
34 b :3 0 d
:3 0 19 :3 0 1a
:3 0 5a 5b 1b
:3 0 1c :3 0 5d
5e 1d :3 0 18
:3 0 60 61 37
63 ae 0 af
:3 0 1a :3 0 1e
:3 0 65 66 0
1c :3 0 e :2 0
1e :3 0 68 6a
0 3d 69 6c
:3 0 18 :3 0 1f
:3 0 6e 6f 0
1c :3 0 e :2 0
1f :3 0 71 73
0 42 72 75
:3 0 6d 77 76
:2 0 1a :3 0 20
:3 0 79 7a 0
e :2 0 21 :4 0
47 7c 7e :3 0
78 80 7f :2 0
18 :3 0 20 :3 0
82 83 0 e
:2 0 21 :4 0 4c
85 87 :3 0 81
89 88 :2 0 1c
:3 0 20 :3 0 8b
8c 0 e :2 0
21 :4 0 51 8e
90 :3 0 8a 92
91 :2 0 1a :3 0
22 :3 0 94 95
0 5 :3 0 e
:2 0 56 98 99
:3 0 93 9b 9a
:2 0 1a :3 0 23
:3 0 9d 9e 0
7 :3 0 e :2 0
5b a1 a2 :3 0
9c a4 a3 :2 0
18 :3 0 22 :3 0
a6 a7 0 8
:3 0 e :2 0 60
aa ab :3 0 a5
ad ac :3 0 b1
b2 :5 0 57 64
0 63 0 b0
:2 0 104 b :3 0
24 :2 0 25 :4 0
68 b5 b7 :3 0
26 :3 0 b :3 0
27 :2 0 28 :2 0
6b b9 bd 24
:2 0 29 :4 0 71
bf c1 :3 0 b8
c3 c2 :2 0 c4
:2 0 b :3 0 29
:4 0 2a :2 0 b
:3 0 74 c8 ca
:3 0 c6 cb 0
cd 77 ce c5
cd 0 cf 79
0 104 d :3 0
24 :2 0 25 :4 0
7d d1 d3 :3 0
26 :3 0 d :3 0
27 :2 0 28 :2 0
80 d5 d9 24
:2 0 29 :4 0 86
db dd :3 0 d4
df de :2 0 e0
:2 0 d :3 0 29
:4 0 2a :2 0 d
:3 0 89 e4 e6
:3 0 e2 e7 0
e9 8c ea e1
e9 0 eb 8e
0 104 12 :3 0
13 :3 0 ec ed
0 14 :4 0 2b
:4 0 b :3 0 90
ee f2 :2 0 104
12 :3 0 13 :3 0
f4 f5 0 14
:4 0 2c :4 0 d
:3 0 94 f6 fa
:2 0 104 12 :3 0
13 :3 0 fc fd
0 14 :4 0 2d
:4 0 9 :3 0 98
fe 102 :2 0 104
9c 125 2e :3 0
12 :3 0 13 :3 0
107 108 0 14
:4 0 2b :5 0 a5
109 10d :2 0 11f
12 :3 0 13 :3 0
10f 110 0 14
:4 0 2f :5 0 a9
111 115 :2 0 11f
30 :3 0 31 :2 0
32 :2 0 ad 118
11a :3 0 33 :4 0
af 117 11d :2 0
11f bd 121 b6
120 11f :2 0 122
b8 :2 0 125 4
:3 0 ba 125 124
104 122 :6 0 126
1 0 5 19
125 1de :2 0 34
:a 0 158 3 :4 0
c2 44f 0 b2
6 :3 0 22 :7 0
12b 12a :3 0 24
:2 0 c4 36 :3 0
35 :7 0 12f 12e
:3 0 131 :2 0 158
128 132 :2 0 22
:3 0 2b :4 0 c9
135 137 :3 0 22
:3 0 24 :2 0 2c
:4 0 ce 13a 13c
:3 0 138 13e 13d
:2 0 22 :3 0 24
:2 0 2f :4 0 d3
141 143 :3 0 13f
145 144 :2 0 146
:2 0 12 :3 0 13
:3 0 148 149 0
14 :4 0 22 :3 0
35 :3 0 d6 14a
14e :2 0 150 da
151 147 150 0
152 dc 0 153
e0 157 :3 0 157
34 :4 0 157 156
153 154 :6 0 158
1 0 128 132
157 1de :2 0 37
:3 0 38 :a 0 1d7
4 :4 0 e5 51b
0 e3 6 :3 0
39 :7 0 15e 15d
:3 0 3c :2 0 e7
6 :3 0 3a :7 0
162 161 :3 0 16
:3 0 6 :3 0 ee
:2 0 ec 164 166
0 1d7 15b 168
:2 0 6 :3 0 ea
16a 16c :6 0 16f
16d 0 1d5 3b
:6 0 3d :3 0 14
:4 0 11 :4 0 170
173 e :2 0 15
:4 0 f3 175 177
:3 0 178 :2 0 3b
:3 0 3e :4 0 17a
17b 0 17e 3f
:3 0 f6 1cd 3d
:3 0 14 :4 0 2b
:4 0 f8 17f 182
40 :2 0 fb 184
185 :3 0 186 :2 0
3b :3 0 41 :4 0
188 189 0 18c
3f :3 0 fd 18d
187 18c 0 1ce
3a :3 0 42 :2 0
43 :4 0 ff 18f
191 :3 0 3d :3 0
14 :4 0 2d :4 0
102 193 196 24
:2 0 a :4 0 107
198 19a :3 0 192
19c 19b :2 0 19d
:2 0 3b :3 0 44
:4 0 2a :2 0 3d
:3 0 14 :4 0 2d
:4 0 10a 1a2 1a5
10d 1a1 1a7 :3 0
2a :2 0 45 :4 0
110 1a9 1ab :3 0
19f 1ac 0 1ae
113 1af 19e 1ae
0 1ce 3b :3 0
46 :4 0 2a :2 0
3d :3 0 14 :4 0
2b :4 0 115 1b3
1b6 118 1b2 1b8
:3 0 2a :2 0 47
:4 0 11b 1ba 1bc
:3 0 2a :2 0 3d
:3 0 14 :4 0 2c
:4 0 11e 1bf 1c2
121 1be 1c4 :3 0
2a :2 0 48 :4 0
124 1c6 1c8 :3 0
1b0 1c9 0 1cb
127 1cc 0 1cb
0 1ce 179 17e
0 1ce 129 0
1d2 16 :3 0 3b
:3 0 1d0 :2 0 1d2
133 1d6 :3 0 1d6
38 :3 0 131 1d6
1d5 1d2 1d3 :6 0
1d7 1 0 15b
168 1d6 1de :3 0
1dc 0 1dc :3 0
1dc 1de 1da 1db
:6 0 1df :2 0 3
:3 0 137 0 4
1dc 1e1 :2 0 2
1df 1e2 :8 0
13b
4
:2 0 12e 1 6
1 a 1 e
1 12 4 9
d 11 16 1
1c 1 18 1
23 1 21 1
2a 2 28 2a
1 2f 2 2d
2f 1 36 2
34 36 3 3f
40 41 2 43
45 1 47 3
4c 4d 4e 2
53 56 3 5c
5f 62 1 6b
2 67 6b 1
74 2 70 74
1 7d 2 7b
7d 1 86 2
84 86 1 8f
2 8d 8f 1
97 2 96 97
1 a0 2 9f
a0 1 a9 2
a8 a9 2 58
59 1 b6 2
b4 b6 3 ba
bb bc 1 c0
2 be c0 2
c7 c9 1 cc
1 ce 1 d2
2 d0 d2 3
d6 d7 d8 1
dc 2 da dc
2 e3 e5 1
e8 1 ea 3
ef f0 f1 3
f7 f8 f9 3
ff 100 101 8
48 50 b3 cf
eb f3 fb 103
3 10a 10b 10c
3 112 113 114
1 119 2 11b
11c 1 129 0
11e 1 106 1
121 2 1f 26
4 10e 116 11e
127 1 12d 2
12c 130 1 136
2 134 136 1
13b 2 139 13b
1 142 2 140
142 3 14b 14c
14d 1 14f 1
151 1 152 2
152 159 1 15c
1 160 2 15f
163 1 16b 1
167 2 171 172
1 176 2 174
176 1 17c 2
180 181 1 183
1 18a 2 18e
190 2 194 195
1 199 2 197
199 2 1a3 1a4
2 1a0 1a6 2
1a8 1aa 1 1ad
2 1b4 1b5 2
1b1 1b7 2 1b9
1bb 2 1c0 1c1
2 1bd 1c3 2
1c5 1c7 1 1ca
4 1cd 18d 1af
1cc 3 :2 0 1
16e 3 1ce 1d1
1d8 3 126 158
1d7
1
4
0
1e1
0
1
14
4
f
0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0
e 2 0
129 3 0
12 2 0
18 2 0
a 2 0
6 2 0
12d 3 0
160 4 0
15b 1 4
128 1 3
5 1 2
21 2 0
167 4 0
15c 4 0
4 0 1
0
/

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,52 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Sequences.sql,v 1.1 2006/04/21 17:51:59 jjanke Exp $
***
* Title: Sequences
* Description:
* (Re)Create Sequences
************************************************************************/
/**
* Error Messages (deleteable) Primary Key
*/
TRUNCATE TABLE AD_Error
/
DROP SEQUENCE AD_Error_Seq
/
CREATE SEQUENCE AD_Error_Seq
START WITH 1
INCREMENT BY 1
/
/**
* Process Log
*/
DELETE FROM T_Report
/
DELETE FROM AD_PInstance
/
DROP SEQUENCE AD_PInstance_Seq
/
CREATE SEQUENCE AD_PInstance_Seq
START WITH 1
INCREMENT BY 1
/
/**
* T_Spool (Global Temporary Table) Primary Key
*/
DROP SEQUENCE T_Spool_Seq
/
CREATE SEQUENCE T_Spool_Seq
START WITH 1
INCREMENT BY 1
/

View File

@ -0,0 +1,93 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Temporary.sql,v 1.1 2006/04/21 17:51:59 jjanke Exp $
***
* Title: Temporary Tables
* Description:
************************************************************************/
DROP TABLE T_Selection CASCADE CONSTRAINTS
/
-- Truely temporary table
CREATE GLOBAL TEMPORARY TABLE T_Selection
(
T_Selection_ID NUMBER(10, 0) NOT NULL
CONSTRAINT T_Selection_Key PRIMARY KEY
)
ON COMMIT DELETE ROWS
/
DROP TABLE T_Selection2
/
-- Temporary table over commit
CREATE GLOBAL TEMPORARY TABLE T_Selection2
(
Query_ID NUMBER NOT NULL,
T_Selection_ID NUMBER(10) NOT NULL,
CONSTRAINT T_Selection2_Key PRIMARY KEY (Query_ID,T_Selection_ID)
)
ON COMMIT PRESERVE ROWS
/
/**
* Spool Table
*/
DROP SEQUENCE T_Spool_Seq
/
CREATE SEQUENCE T_Spool_Seq
INCREMENT BY 1
START WITH 1
/
-- INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, Msg) VALUES (123, T_Spool_Seq.NextVal, 'ggg');
DROP TABLE T_InventoryValue
/
CREATE TABLE T_InventoryValue(
AD_PInstance_ID NUMBER(10, 0) NOT NULL,
M_Warehouse_ID NUMBER(10, 0) NOT NULL,
M_Product_ID NUMBER(10, 0) NOT NULL,
M_AttributeSetInstance_ID NUMBER(10, 0) NOT NULL,
AD_Client_ID NUMBER(10, 0),
AD_Org_ID NUMBER(10, 0),
M_PriceList_Version_ID NUMBER(10, 0),
DateValue DATE,
C_Currency_ID NUMBER(10, 0),
QtyOnHand NUMBER DEFAULT 0,
PricePO NUMBER DEFAULT 0,
PriceList NUMBER DEFAULT 0,
PriceStd NUMBER DEFAULT 0,
PriceLimit NUMBER DEFAULT 0,
CostStandard NUMBER DEFAULT 0,
Cost NUMBER DEFAULT 0,
PricePOAmt NUMBER DEFAULT 0,
PriceListAmt NUMBER DEFAULT 0,
PriceStdAmt NUMBER DEFAULT 0,
PriceLimitAmt NUMBER DEFAULT 0,
CostStandardAmt NUMBER DEFAULT 0,
CostAmt NUMBER DEFAULT 0,
M_CostElement_ID NUMBER(10, 0),
CONSTRAINT T_InventoryValue_Key PRIMARY KEY (AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID),
CONSTRAINT MPLVersion_TInventoryValue FOREIGN KEY (M_PriceList_Version_ID)
REFERENCES M_PriceList_Version(M_PriceList_Version_ID),
CONSTRAINT CCurrency_TInventoryValue FOREIGN KEY (C_Currency_ID)
REFERENCES C_Currency(C_Currency_ID),
CONSTRAINT MWarehouse_TInventoryValue FOREIGN KEY (M_Warehouse_ID)
REFERENCES M_Warehouse(M_Warehouse_ID) ON DELETE CASCADE,
CONSTRAINT MProduct_TInventoryValue FOREIGN KEY (M_Product_ID)
REFERENCES M_Product(M_Product_ID) ON DELETE CASCADE,
CONSTRAINT ADPInstance_TInventoryValue FOREIGN KEY (AD_PInstance_ID)
REFERENCES AD_PInstance(AD_PInstance_ID) ON DELETE CASCADE,
CONSTRAINT MCostElement_TInventoryValue FOREIGN KEY (M_CostElement_ID)
REFERENCES M_CostElement(M_CostElement_ID),
CONSTRAINT MASI_TInventoryValue FOREIGN KEY (M_AttributeSetInstance_ID)
REFERENCES M_AttributeSetInstance(M_AttributeSetInstance_ID)
)
/

3240
db/database/Create/Views.sql Normal file

File diff suppressed because it is too large Load Diff

553
db/database/Database.epj Normal file
View File

@ -0,0 +1,553 @@
Begin Project "Database", "Adempiere Database Project", VC_PROJECT=, AUXPROJPATH=
DATASOURCE=Dev2.reference
DATABASE=
Begin SubProject "Startup", "", PATH=.\startup
Begin SubProject "oracle", "", PATH=.\startup\oracle
Begin File "AfterImport.sql"
PATH=.\startup\oracle\afterimport.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=208
OBJECTTYPE=38
End File
Begin File "BackupCold.sql"
PATH=.\startup\oracle\backupcold.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "BeforeExport.sql"
PATH=.\startup\oracle\BeforeExport.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "CheckDB.sql"
PATH=.\startup\oracle\checkdb.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "CreateUser.sql"
PATH=.\startup\oracle\createuser.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "Daily.sql"
PATH=.\startup\oracle\Daily.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Start.sql"
PATH=.\startup\oracle\start.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "Stop.sql"
PATH=.\startup\oracle\stop.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "Test.sql"
PATH=.\startup\oracle\test.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
End SubProject
Begin SubProject "Create", "", PATH=.\create
Begin File "Adempiere.sql"
PATH=.\create\adempiere.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "Sequences.sql"
PATH=.\create\sequences.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=47
OBJECTTYPE=38
End File
Begin File "Temporary.sql"
PATH=.\create\temporary.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=46
OBJECTTYPE=38
End File
Begin File "Views.sql"
PATH=.\create\views.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=48
OBJECTTYPE=38
End File
Begin File "AdempiereEtc.sql"
PATH=.\create\AdempiereEtc.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "Functions", "", PATH=.\functions
Begin File "Acct_Balance.sql"
PATH=.\functions\Acct_Balance.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=44
OBJECTTYPE=-1
End File
Begin File "BOM_PriceLimit.sql"
PATH=.\functions\bom_pricelimit.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=0
OBJECTTYPE=-1
End File
Begin File "BOM_PriceList.sql"
PATH=.\functions\bom_pricelist.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=1
OBJECTTYPE=-1
End File
Begin File "BOM_PriceStd.sql"
PATH=.\functions\bom_pricestd.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=2
OBJECTTYPE=-1
End File
Begin File "BOM_Qty_Available.sql"
PATH=.\functions\bom_qty_available.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=3
OBJECTTYPE=-1
End File
Begin File "BOM_Qty_OnHand.sql"
PATH=.\functions\bom_qty_onhand.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=4
OBJECTTYPE=-1
End File
Begin File "BOM_Qty_Ordered.sql"
PATH=.\functions\bom_qty_ordered.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=5
OBJECTTYPE=-1
End File
Begin File "BOM_Qty_Reserved.sql"
PATH=.\functions\bom_qty_reserved.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=6
OBJECTTYPE=-1
End File
Begin File "C_Base_Convert.sql"
PATH=.\functions\c_base_convert.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=7
OBJECTTYPE=-1
End File
Begin File "C_BPartner_RemitLocation.SQL"
PATH=.\functions\C_BPartner_RemitLocation.SQL
DESCRIPTION=
INCLUDE=1
BUILDINDEX=39
OBJECTTYPE=-1
End File
Begin File "C_Currency_Convert.sql"
PATH=.\functions\c_currency_convert.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=38
OBJECTTYPE=-1
End File
Begin File "C_Currency_Rate.sql"
PATH=.\functions\c_currency_rate.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=37
OBJECTTYPE=-1
End File
Begin File "C_Currency_Round.sql"
PATH=.\functions\c_currency_round.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=19
OBJECTTYPE=-1
End File
Begin File "C_Invoice_Discount.sql"
PATH=.\functions\c_invoice_discount.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=35
OBJECTTYPE=-1
End File
Begin File "C_Invoice_Open.sql"
PATH=.\functions\c_invoice_open.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=8
OBJECTTYPE=-1
End File
Begin File "C_Invoice_Paid.sql"
PATH=.\functions\c_invoice_paid.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=9
OBJECTTYPE=-1
End File
Begin File "C_Payment_Allocated.sql"
PATH=.\functions\c_payment_allocated.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=10
OBJECTTYPE=-1
End File
Begin File "C_Payment_Available.sql"
PATH=.\functions\c_payment_available.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=11
OBJECTTYPE=-1
End File
Begin File "C_PaymentTerm_Discount.sql"
PATH=.\functions\c_paymentterm_discount.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=12
OBJECTTYPE=-1
End File
Begin File "C_PaymentTerm_DueDays.sql"
PATH=.\functions\c_paymentterm_duedays.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=13
OBJECTTYPE=-1
End File
Begin File "DBA_ConstraintCmd.sql"
PATH=.\functions\dba_constraintcmd.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=22
OBJECTTYPE=-1
End File
Begin File "DBA_DisplayType.sql"
PATH=.\functions\dba_displaytype.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=31
OBJECTTYPE=-1
End File
Begin File "M_Attribute_Name.sql"
PATH=.\functions\M_Attribute_Name.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=42
OBJECTTYPE=-1
End File
Begin File "C_PaymentTerm_DueDate.sql"
PATH=.\functions\C_PaymentTerm_DueDate.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=43
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "Procedures", "", PATH=.\procedures
Begin File "AD_Column_Sync.sql"
PATH=.\procedures\ad_column_sync.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=34
OBJECTTYPE=-1
End File
Begin File "AD_PrintPaper_Default.sql"
PATH=.\procedures\AD_PrintPaper_Default.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=40
OBJECTTYPE=-1
End File
Begin File "AD_Sequence_Doc.sql"
PATH=.\procedures\ad_sequence_doc.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=14
OBJECTTYPE=-1
End File
Begin File "AD_Sequence_DocType.sql"
PATH=.\procedures\ad_sequence_doctype.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=15
OBJECTTYPE=-1
End File
Begin File "AD_Sequence_Next.sql"
PATH=.\procedures\ad_sequence_next.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=16
OBJECTTYPE=-1
End File
Begin File "AD_Syncronize.sql"
PATH=.\procedures\ad_syncronize.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=32
OBJECTTYPE=-1
End File
Begin File "C_Order_DrillDown.sql"
PATH=.\procedures\c_order_drilldown.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=20
OBJECTTYPE=-1
End File
Begin File "DBA_AfterImport.sql"
PATH=.\procedures\dba_afterimport.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=29
OBJECTTYPE=21
End File
Begin File "DBA_Cleanup.sql"
PATH=.\procedures\dba_cleanup.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=30
OBJECTTYPE=21
End File
Begin File "DBA_Recompile.sql"
PATH=.\procedures\dba_recompile.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=28
OBJECTTYPE=-1
End File
Begin File "Fact_Acct_Balance_Update.sql"
PATH=.\procedures\Fact_Acct_Balance_Update.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=41
OBJECTTYPE=-1
End File
Begin File "M_PriceList_Create.sql"
PATH=.\procedures\m_pricelist_create.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=23
OBJECTTYPE=-1
End File
Begin File "M_Product_BOM_Check.sql"
PATH=.\procedures\m_product_bom_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=24
OBJECTTYPE=-1
End File
Begin File "M_Product_Delete.sql"
PATH=.\procedures\m_product_delete.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=26
OBJECTTYPE=-1
End File
Begin File "M_Production_Run.sql"
PATH=.\procedures\m_production_run.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=27
OBJECTTYPE=-1
End File
Begin File "T_InventoryValue_Create.sql"
PATH=.\procedures\t_inventoryvalue_create.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=33
OBJECTTYPE=-1
End File
Begin File "nextID.sql"
PATH=.\procedures\nextID.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=45
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "Access", "", PATH=.\access
Begin File "Context_Body.sql"
PATH=.\access\context_body.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=100
OBJECTTYPE=20
End File
Begin File "Context_Header.sql"
PATH=.\access\context_header.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=98
OBJECTTYPE=19
End File
Begin File "Context_List.sql"
PATH=.\access\context_list.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=154
OBJECTTYPE=38
End File
Begin File "Context_Test.sql"
PATH=.\access\context_test.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=155
OBJECTTYPE=38
End File
Begin File "CreateContext.sql"
PATH=.\access\createcontext.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=99
OBJECTTYPE=38
End File
Begin File "Policy_Add.sql"
PATH=.\access\policy_add.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=157
OBJECTTYPE=-1
End File
Begin File "Policy_Drop.sql"
PATH=.\access\policy_drop.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=158
OBJECTTYPE=38
End File
Begin File "Privileges.sql"
PATH=.\access\privileges.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=159
OBJECTTYPE=38
End File
Begin File "Wrap.sql"
PATH=.\access\wrap.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=160
OBJECTTYPE=38
End File
End SubProject
Begin SubProject "Custom", "", PATH=.\custom
End SubProject
Begin File "DatabaseBuild.sql"
PATH=.\DatabaseBuild.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End Project

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
CREATE OR REPLACE FUNCTION acctBalance
(
p_Account_ID IN NUMBER,
p_AmtDr IN NUMBER,
p_AmtCr IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2004 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Acct_Balance.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Aclculate Balance based on Account Sign + Type
* Description:
* If an account is specified and found
* - If the account sign is Natural it sets it based on Account Type
* Returns Credit or Debit Balance
* Test:
SELECT Acct_Balance (0,11,22) FROM DUAL
SELECT AccountType, AccountSign,
Acct_Balance(C_ElementValue_ID, 20, 10) "DR Balance",
Acct_Balance(C_ElementValue_ID, 10, 20) "CR Balance"
FROM C_ElementValue
WHERE AccountSign<>'N'
ORDER BY AccountSign
************************************************************************/
AS
v_balance NUMBER;
v_AccountType C_ElementValue.AccountType%TYPE;
v_AccountSign C_ElementValue.AccountSign%TYPE;
BEGIN
v_balance := p_AmtDr - p_AmtCr;
--
IF (p_Account_ID > 0) THEN
SELECT AccountType, AccountSign
INTO v_AccountType, v_AccountSign
FROM C_ElementValue
WHERE C_ElementValue_ID=p_Account_ID;
-- DBMS_OUTPUT.PUT_LINE('Type=' || v_AccountType || ' - Sign=' || v_AccountSign);
-- Natural Account Sign
IF (v_AccountSign='N') THEN
IF (v_AccountType IN ('A','E')) THEN
v_AccountSign := 'D';
ELSE
v_AccountSign := 'C';
END IF;
-- DBMS_OUTPUT.PUT_LINE('Type=' || v_AccountType || ' - Sign=' || v_AccountSign);
END IF;
-- Debit Balance
IF (v_AccountSign = 'C') THEN
v_balance := p_AmtCr - p_AmtDr;
END IF;
END IF;
--
RETURN v_balance;
EXCEPTION WHEN OTHERS THEN
-- In case Acct not found
RETURN p_AmtDr - p_AmtCr;
END acctBalance;
/

View File

@ -0,0 +1,48 @@
CREATE OR REPLACE FUNCTION bomPriceLimit
(
Product_ID IN NUMBER,
PriceList_Version_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BOM_PriceLimit.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return Limit Price of Product/BOM
* Description:
* if not found: 0
************************************************************************/
AS
v_Price NUMBER;
v_ProductPrice NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=Product_ID;
--
BEGIN
-- Try to get price from PriceList directly
SELECT COALESCE (SUM(PriceLimit), 0)
INTO v_Price
FROM M_ProductPrice
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
-- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
-- No Price - Check if BOM
IF (v_Price = 0) THEN
FOR bom IN CUR_BOM LOOP
v_ProductPrice := bomPriceLimit (bom.M_ProductBOM_ID, PriceList_Version_ID);
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
END LOOP;
END IF;
--
RETURN v_Price;
END bomPriceLimit;
/

View File

@ -0,0 +1,49 @@
CREATE OR REPLACE FUNCTION bomPriceList
(
Product_ID IN NUMBER,
PriceList_Version_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BOM_PriceList.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return List Price of Product/BOM
* Description:
* if not found: 0
************************************************************************/
AS
v_Price NUMBER;
v_ProductPrice NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=Product_ID;
--
BEGIN
-- Try to get price from pricelist directly
SELECT COALESCE (SUM(PriceList), 0)
INTO v_Price
FROM M_ProductPrice
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
-- DBMS_OUTPUT.PUT_LINE('Price=' || Price);
-- No Price - Check if BOM
IF (v_Price = 0) THEN
FOR bom IN CUR_BOM LOOP
v_ProductPrice := bomPriceList (bom.M_ProductBOM_ID, PriceList_Version_ID);
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
-- DBMS_OUTPUT.PUT_LINE('Qry=' || bom.BOMQty || ' @ ' || v_ProductPrice || ', Price=' || v_Price);
END LOOP; -- BOM
END IF;
--
RETURN v_Price;
END bomPriceList;
/

View File

@ -0,0 +1,49 @@
CREATE OR REPLACE FUNCTION bomPriceStd
(
Product_ID IN NUMBER,
PriceList_Version_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BOM_PriceStd.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return Standard Price of Product/BOM
* Description:
* if not found: 0
************************************************************************/
AS
v_Price NUMBER;
v_ProductPrice NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=Product_ID;
--
BEGIN
-- Try to get price from pricelist directly
SELECT COALESCE(SUM(PriceStd), 0)
INTO v_Price
FROM M_ProductPrice
WHERE M_PriceList_Version_ID=PriceList_Version_ID AND M_Product_ID=Product_ID;
-- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
-- No Price - Check if BOM
IF (v_Price = 0) THEN
FOR bom IN CUR_BOM LOOP
v_ProductPrice := bomPriceStd (bom.M_ProductBOM_ID, PriceList_Version_ID);
v_Price := v_Price + (bom.BOMQty * v_ProductPrice);
-- DBMS_OUTPUT.PUT_LINE('Price=' || v_Price);
END LOOP; -- BOM
END IF;
--
RETURN v_Price;
END bomPriceStd;
/

View File

@ -0,0 +1,21 @@
CREATE OR REPLACE FUNCTION bomQtyAvailable
(
Product_ID IN NUMBER,
Warehouse_ID IN NUMBER,
Locator_ID IN NUMBER -- Only used, if warehouse is null
)
RETURN NUMBER
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Return quantity available for BOM
*/
AS
BEGIN
RETURN bomQtyOnHand(Product_ID, Warehouse_ID, Locator_ID)
- bomQtyReserved(Product_ID, Warehouse_ID, Locator_ID);
END bomQtyAvailable;
/

View File

@ -0,0 +1,120 @@
CREATE OR REPLACE FUNCTION bomQtyOnHand
(
Product_ID IN NUMBER,
Warehouse_ID IN NUMBER,
Locator_ID IN NUMBER -- Only used, if warehouse is null
)
RETURN NUMBER
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Return quantity on hand for BOM
*/
AS
myWarehouse_ID NUMBER;
Quantity NUMBER := 99999; -- unlimited
IsBOM CHAR(1);
IsStocked CHAR(1);
ProductType CHAR(1);
ProductQty NUMBER;
StdPrecision NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM, p.IsStocked, p.ProductType
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=Product_ID;
--
BEGIN
-- Check Parameters
myWarehouse_ID := Warehouse_ID;
IF (myWarehouse_ID IS NULL) THEN
IF (Locator_ID IS NULL) THEN
RETURN 0;
ELSE
SELECT SUM(M_Warehouse_ID) INTO myWarehouse_ID
FROM M_Locator
WHERE M_Locator_ID=Locator_ID;
END IF;
END IF;
IF (myWarehouse_ID IS NULL) THEN
RETURN 0;
END IF;
-- DBMS_OUTPUT.PUT_LINE('Warehouse=' || myWarehouse_ID);
-- Check, if product exists and if it is stocked
BEGIN
SELECT IsBOM, ProductType, IsStocked
INTO IsBOM, ProductType, IsStocked
FROM M_Product
WHERE M_Product_ID=Product_ID;
--
EXCEPTION -- not found
WHEN OTHERS THEN
RETURN 0;
END;
-- Unimited capacity if no item
IF (IsBOM='N' AND (ProductType<>'I' OR IsStocked='N')) THEN
RETURN Quantity;
-- Stocked item
ELSIF (IsStocked='Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyOnHand), 0)
INTO ProductQty
FROM M_Storage s
WHERE M_Product_ID=Product_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=myWarehouse_ID);
--
-- DBMS_OUTPUT.PUT_LINE('Qty=' || ProductQty);
RETURN ProductQty;
END IF;
-- Go though BOM
-- DBMS_OUTPUT.PUT_LINE('BOM');
FOR bom IN CUR_BOM LOOP
-- Stocked Items "leaf node"
IF (bom.ProductType = 'I' AND bom.IsStocked = 'Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyOnHand), 0)
INTO ProductQty
FROM M_Storage s
WHERE M_Product_ID=bom.M_ProductBOM_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=myWarehouse_ID);
-- Get Rounding Precision
SELECT NVL(MAX(u.StdPrecision), 0)
INTO StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=bom.M_ProductBOM_ID;
-- How much can we make with this product
ProductQty := ROUND (ProductQty/bom.BOMQty, StdPrecision);
-- How much can we make overall
IF (ProductQty < Quantity) THEN
Quantity := ProductQty;
END IF;
-- Another BOM
ELSIF (bom.IsBOM = 'Y') THEN
ProductQty := bomQtyOnHand (bom.M_ProductBOM_ID, myWarehouse_ID, Locator_ID);
-- How much can we make overall
IF (ProductQty < Quantity) THEN
Quantity := ProductQty;
END IF;
END IF;
END LOOP; -- BOM
IF (Quantity > 0) THEN
-- Get Rounding Precision for Product
SELECT NVL(MAX(u.StdPrecision), 0)
INTO StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=Product_ID;
--
RETURN ROUND (Quantity, StdPrecision);
END IF;
RETURN 0;
END bomQtyOnHand;
/

View File

@ -0,0 +1,126 @@
CREATE OR REPLACE FUNCTION bomQtyOrdered
(
p_Product_ID IN NUMBER,
p_Warehouse_ID IN NUMBER,
p_Locator_ID IN NUMBER -- Only used, if warehouse is null
)
RETURN NUMBER
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Return quantity ordered for BOM
*/
AS
v_Warehouse_ID NUMBER;
v_Quantity NUMBER := 99999; -- unlimited
v_IsBOM CHAR(1);
v_IsStocked CHAR(1);
v_ProductType CHAR(1);
v_ProductQty NUMBER;
v_StdPrecision NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM, p.IsStocked, p.ProductType
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=p_Product_ID;
--
BEGIN
-- Check Parameters
v_Warehouse_ID := p_Warehouse_ID;
IF (v_Warehouse_ID IS NULL) THEN
IF (p_Locator_ID IS NULL) THEN
RETURN 0;
ELSE
SELECT MAX(M_Warehouse_ID) INTO v_Warehouse_ID
FROM M_Locator
WHERE M_Locator_ID=p_Locator_ID;
END IF;
END IF;
IF (v_Warehouse_ID IS NULL) THEN
RETURN 0;
END IF;
-- DBMS_OUTPUT.PUT_LINE('Warehouse=' || v_Warehouse_ID);
-- Check, if product exists and if it is stocked
BEGIN
SELECT IsBOM, ProductType, IsStocked
INTO v_IsBOM, v_ProductType, v_IsStocked
FROM M_Product
WHERE M_Product_ID=p_Product_ID;
--
EXCEPTION -- not found
WHEN OTHERS THEN
RETURN 0;
END;
-- No reservation for non-stocked
IF (v_IsBOM='N' AND (v_ProductType<>'I' OR v_IsStocked='N')) THEN
RETURN 0;
-- Stocked item
ELSIF (v_IsStocked='Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyOrdered), 0)
INTO v_ProductQty
FROM M_Storage s
WHERE M_Product_ID=p_Product_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=v_Warehouse_ID);
--
RETURN v_ProductQty;
END IF;
-- Go though BOM
-- DBMS_OUTPUT.PUT_LINE('BOM');
FOR bom IN CUR_BOM LOOP
-- Stocked Items "leaf node"
IF (bom.ProductType = 'I' AND bom.IsStocked = 'Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyOrdered), 0)
INTO v_ProductQty
FROM M_Storage s
WHERE M_Product_ID=bom.M_ProductBOM_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=v_Warehouse_ID);
-- Get Rounding Precision
SELECT NVL(MAX(u.StdPrecision), 0)
INTO v_StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=bom.M_ProductBOM_ID;
-- How much can we make with this product
v_ProductQty := ROUND (v_ProductQty/bom.BOMQty, v_StdPrecision);
-- How much can we make overall
IF (v_ProductQty < v_Quantity) THEN
v_Quantity := v_ProductQty;
END IF;
-- Another BOM
ELSIF (bom.IsBOM = 'Y') THEN
v_ProductQty := bomQtyOrdered (bom.M_ProductBOM_ID, v_Warehouse_ID, p_Locator_ID);
-- How much can we make overall
IF (v_ProductQty < v_Quantity) THEN
v_Quantity := v_ProductQty;
END IF;
END IF;
END LOOP; -- BOM
-- Unlimited (e.g. only services)
IF (v_Quantity = 99999) THEN
RETURN 0;
END IF;
IF (v_Quantity > 0) THEN
-- Get Rounding Precision for Product
SELECT NVL(MAX(u.StdPrecision), 0)
INTO v_StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=p_Product_ID;
--
RETURN ROUND (v_Quantity, v_StdPrecision);
END IF;
--
RETURN 0;
END bomQtyOrdered;
/

View File

@ -0,0 +1,125 @@
CREATE OR REPLACE FUNCTION bomQtyReserved
(
p_Product_ID IN NUMBER,
p_Warehouse_ID IN NUMBER,
p_Locator_ID IN NUMBER -- Only used, if warehouse is null
)
RETURN NUMBER
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Return quantity reserved for BOM
*/
AS
v_Warehouse_ID NUMBER;
v_Quantity NUMBER := 99999; -- unlimited
v_IsBOM CHAR(1);
v_IsStocked CHAR(1);
v_ProductType CHAR(1);
v_ProductQty NUMBER;
v_StdPrecision NUMBER;
-- Get BOM Product info
CURSOR CUR_BOM IS
SELECT b.M_ProductBOM_ID, b.BOMQty, p.IsBOM, p.IsStocked, p.ProductType
FROM M_Product_BOM b, M_Product p
WHERE b.M_ProductBOM_ID=p.M_Product_ID
AND b.M_Product_ID=p_Product_ID;
--
BEGIN
-- Check Parameters
v_Warehouse_ID := p_Warehouse_ID;
IF (v_Warehouse_ID IS NULL) THEN
IF (p_Locator_ID IS NULL) THEN
RETURN 0;
ELSE
SELECT MAX(M_Warehouse_ID) INTO v_Warehouse_ID
FROM M_Locator
WHERE M_Locator_ID=p_Locator_ID;
END IF;
END IF;
IF (v_Warehouse_ID IS NULL) THEN
RETURN 0;
END IF;
-- DBMS_OUTPUT.PUT_LINE('Warehouse=' || v_Warehouse_ID);
-- Check, if product exists and if it is stocked
BEGIN
SELECT IsBOM, ProductType, IsStocked
INTO v_IsBOM, v_ProductType, v_IsStocked
FROM M_Product
WHERE M_Product_ID=p_Product_ID;
--
EXCEPTION -- not found
WHEN OTHERS THEN
RETURN 0;
END;
-- No reservation for non-stocked
IF (v_IsBOM='N' AND (v_ProductType<>'I' OR v_IsStocked='N')) THEN
RETURN 0;
-- Stocked item
ELSIF (v_IsStocked='Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyReserved), 0)
INTO v_ProductQty
FROM M_Storage s
WHERE M_Product_ID=p_Product_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=v_Warehouse_ID);
--
RETURN v_ProductQty;
END IF;
-- Go though BOM
-- DBMS_OUTPUT.PUT_LINE('BOM');
FOR bom IN CUR_BOM LOOP
-- Stocked Items "leaf node"
IF (bom.ProductType = 'I' AND bom.IsStocked = 'Y') THEN
-- Get ProductQty
SELECT NVL(SUM(QtyReserved), 0)
INTO v_ProductQty
FROM M_Storage s
WHERE M_Product_ID=bom.M_ProductBOM_ID
AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=v_Warehouse_ID);
-- Get Rounding Precision
SELECT NVL(MAX(u.StdPrecision), 0)
INTO v_StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=bom.M_ProductBOM_ID;
-- How much can we make with this product
v_ProductQty := ROUND (v_ProductQty/bom.BOMQty, v_StdPrecision);
-- How much can we make overall
IF (v_ProductQty < v_Quantity) THEN
v_Quantity := v_ProductQty;
END IF;
-- Another BOM
ELSIF (bom.IsBOM = 'Y') THEN
v_ProductQty := bomQtyReserved (bom.M_ProductBOM_ID, v_Warehouse_ID, p_Locator_ID);
-- How much can we make overall
IF (v_ProductQty < v_Quantity) THEN
v_Quantity := v_ProductQty;
END IF;
END IF;
END LOOP; -- BOM
-- Unlimited (e.g. only services)
IF (v_Quantity = 99999) THEN
RETURN 0;
END IF;
IF (v_Quantity > 0) THEN
-- Get Rounding Precision for Product
SELECT NVL(MAX(u.StdPrecision), 0)
INTO v_StdPrecision
FROM C_UOM u, M_Product p
WHERE u.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=p_Product_ID;
--
RETURN ROUND (v_Quantity, v_StdPrecision);
END IF;
RETURN 0;
END bomQtyReserved;
/

View File

@ -0,0 +1,34 @@
CREATE OR REPLACE FUNCTION bpartnerRemitLocation
(
p_C_BPartner_ID C_BPartner.C_BPartner_ID%TYPE
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_BPartner_RemitLocation.SQL,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return the first RemitTo C_Location_ID of a Business Partner
* Description:
*
************************************************************************/
AS
v_C_Location_ID NUMBER := NULL;
CURSOR CUR_BPLoc IS
SELECT IsRemitTo, C_Location_ID
FROM C_BPartner_Location
WHERE C_BPartner_ID=p_C_BPartner_ID
ORDER BY IsRemitTo DESC;
BEGIN
FOR l IN CUR_BPLoc LOOP
IF (v_C_Location_ID IS NULL) THEN
v_C_Location_ID := l.C_Location_ID;
END IF;
END LOOP;
RETURN v_C_Location_ID;
END bpartnerRemitLocation;
/

View File

@ -0,0 +1,47 @@
CREATE OR REPLACE FUNCTION currencyBase
(
p_Amount IN NUMBER,
p_CurFrom_ID IN NUMBER,
p_ConvDate IN DATE,
p_Client_ID IN NUMBER,
p_Org_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Base_Convert.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Convert Amount to Base Currency of Client
* Description:
* Get CurrencyTo from Client
* Returns NULL, if conversion not found
* Standard Rounding
* Test:
* SELECT C_Base_Convert(100,116,11,null) FROM DUAL => 64.72
************************************************************************/
AS
v_CurTo_ID NUMBER;
BEGIN
-- Get Currency
SELECT MAX(ac.C_Currency_ID)
INTO v_CurTo_ID
FROM AD_ClientInfo ci, C_AcctSchema ac
WHERE ci.C_AcctSchema1_ID=ac.C_AcctSchema_ID
AND ci.AD_Client_ID=p_Client_ID;
-- Same as Currency_Conversion - if currency/rate not found - return 0
IF (v_CurTo_ID IS NULL) THEN
RETURN NULL;
END IF;
-- Same currency
IF (p_CurFrom_ID = v_CurTo_ID) THEN
RETURN p_Amount;
END IF;
RETURN currencyConvert (p_Amount, p_CurFrom_ID, v_CurTo_ID, p_ConvDate, null, p_Client_ID, p_Org_ID);
END currencyBase;
/

View File

@ -0,0 +1,51 @@
CREATE OR REPLACE FUNCTION currencyConvert
(
p_Amount IN NUMBER,
p_CurFrom_ID IN NUMBER,
p_CurTo_ID IN NUMBER,
p_ConvDate IN DATE,
p_ConversionType_ID IN NUMBER,
p_Client_ID IN NUMBER,
p_Org_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Currency_Convert.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Convert Amount (using IDs)
* Description:
* from CurrencyFrom_ID to CurrencyTo_ID
* Returns NULL, if conversion not found
* Standard Rounding
* Test:
* SELECT C_Currency_Convert(100,116,100,null,null) FROM DUAL => 64.72
* SELECT C_Currency_Convert(100,116,100) FROM DUAL => 64.72
************************************************************************/
AS
v_Rate NUMBER;
BEGIN
-- Return Amount
IF (p_Amount = 0 OR p_CurFrom_ID = p_CurTo_ID) THEN
RETURN p_Amount;
END IF;
-- Return NULL
IF (p_Amount IS NULL OR p_CurFrom_ID IS NULL OR p_CurTo_ID IS NULL) THEN
RETURN NULL;
END IF;
-- Get Rate
v_Rate := currencyRate (p_CurFrom_ID, p_CurTo_ID, p_ConvDate, p_ConversionType_ID, p_Client_ID, p_Org_ID);
IF (v_Rate IS NULL) THEN
RETURN NULL;
END IF;
-- Standard Precision
RETURN currencyRound(p_Amount * v_Rate, p_CurTo_ID, null);
END currencyConvert;
/

View File

@ -0,0 +1,171 @@
CREATE OR REPLACE FUNCTION currencyRate
(
p_CurFrom_ID IN NUMBER,
p_CurTo_ID IN NUMBER,
p_ConvDate IN DATE,
p_ConversionType_ID IN NUMBER,
p_Client_ID IN NUMBER,
p_Org_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Currency_Rate.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return Conversion Rate
* Description:
* from CurrencyFrom_ID to CurrencyTo_ID
* Returns NULL, if rate not found
* Test
* SELECT C_Currency_Rate(116, 100, null, null) FROM DUAL; => .647169
* SELECT C_Currency_Rate(116, 100) FROM DUAL; => .647169
************************************************************************/
AS
-- Currency From variables
cf_IsEuro CHAR(1);
cf_IsEMUMember CHAR(1);
cf_EMUEntryDate DATE;
cf_EMURate NUMBER;
-- Currency To variables
ct_IsEuro CHAR(1);
ct_IsEMUMember CHAR(1);
ct_EMUEntryDate DATE;
ct_EMURate NUMBER;
-- Triangle
v_CurrencyFrom NUMBER;
v_CurrencyTo NUMBER;
v_CurrencyEuro NUMBER;
--
v_ConvDate DATE := SysDate;
v_ConversionType_ID NUMBER := 0;
v_Rate NUMBER;
BEGIN
-- No Conversion
IF (p_CurFrom_ID = p_CurTo_ID) THEN
RETURN 1;
END IF;
-- Default Date Parameter
IF (p_ConvDate IS NOT NULL) THEN
v_ConvDate := p_ConvDate; -- SysDate
END IF;
-- Default Conversion Type
IF (p_ConversionType_ID IS NULL OR p_ConversionType_ID = 0) THEN
BEGIN
SELECT C_ConversionType_ID
INTO v_ConversionType_ID
FROM C_ConversionType
WHERE IsDefault='Y'
AND AD_Client_ID IN (0,p_Client_ID)
AND ROWNUM=1
ORDER BY AD_Client_ID DESC;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Conversion Type Not Found');
END;
ELSE
v_ConversionType_ID := p_ConversionType_ID;
END IF;
-- Get Currency Info
SELECT MAX(IsEuro), MAX(IsEMUMember), MAX(EMUEntryDate), MAX(EMURate)
INTO cf_IsEuro, cf_IsEMUMember, cf_EMUEntryDate, cf_EMURate
FROM C_Currency
WHERE C_Currency_ID = p_CurFrom_ID;
-- Not Found
IF (cf_IsEuro IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('From Currency Not Found');
RETURN NULL;
END IF;
SELECT MAX(IsEuro), MAX(IsEMUMember), MAX(EMUEntryDate), MAX(EMURate)
INTO ct_IsEuro, ct_IsEMUMember, ct_EMUEntryDate, ct_EMURate
FROM C_Currency
WHERE C_Currency_ID = p_CurTo_ID;
-- Not Found
IF (ct_IsEuro IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('To Currency Not Found');
RETURN NULL;
END IF;
-- Fixed - From Euro to EMU
IF (cf_IsEuro = 'Y' AND ct_IsEMUMember ='Y' AND v_ConvDate >= ct_EMUEntryDate) THEN
RETURN ct_EMURate;
END IF;
-- Fixed - From EMU to Euro
IF (ct_IsEuro = 'Y' AND cf_IsEMUMember ='Y' AND v_ConvDate >= cf_EMUEntryDate) THEN
RETURN 1 / cf_EMURate;
END IF;
-- Fixed - From EMU to EMU
IF (cf_IsEMUMember = 'Y' AND cf_IsEMUMember ='Y'
AND v_ConvDate >= cf_EMUEntryDate AND v_ConvDate >= ct_EMUEntryDate) THEN
RETURN ct_EMURate / cf_EMURate;
END IF;
-- Flexible Rates
v_CurrencyFrom := p_CurFrom_ID;
v_CurrencyTo := p_CurTo_ID;
-- if EMU Member involved, replace From/To Currency
IF ((cf_isEMUMember = 'Y' AND v_ConvDate >= cf_EMUEntryDate)
OR (ct_isEMUMember = 'Y' AND v_ConvDate >= ct_EMUEntryDate)) THEN
SELECT MAX(C_Currency_ID)
INTO v_CurrencyEuro
FROM C_Currency
WHERE IsEuro = 'Y';
-- Conversion Rate not Found
IF (v_CurrencyEuro IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('Euro Not Found');
RETURN NULL;
END IF;
IF (cf_isEMUMember = 'Y' AND v_ConvDate >= cf_EMUEntryDate) THEN
v_CurrencyFrom := v_CurrencyEuro;
ELSE
v_CurrencyTo := v_CurrencyEuro;
END IF;
END IF;
-- Get Rate
DECLARE
CURSOR CUR_Rate IS
SELECT MultiplyRate
FROM C_Conversion_Rate
WHERE C_Currency_ID=v_CurrencyFrom AND C_Currency_ID_To=v_CurrencyTo
AND C_ConversionType_ID=v_ConversionType_ID
AND v_ConvDate BETWEEN ValidFrom AND ValidTo
AND AD_Client_ID IN (0,p_Client_ID) AND AD_Org_ID IN (0,p_Org_ID)
ORDER BY AD_Client_ID DESC, AD_Org_ID DESC, ValidFrom DESC;
BEGIN
FOR c IN CUR_Rate LOOP
v_Rate := c.MultiplyRate;
EXIT; -- only first
END LOOP;
END;
-- Not found
IF (v_Rate IS NULL) THEN
DBMS_OUTPUT.PUT_LINE('Conversion Rate Not Found');
RETURN NULL;
END IF;
-- Currency From was EMU
IF (cf_isEMUMember = 'Y' AND v_ConvDate >= cf_EMUEntryDate) THEN
RETURN v_Rate / cf_EMURate;
END IF;
-- Currency To was EMU
IF (ct_isEMUMember = 'Y' AND v_ConvDate >= ct_EMUEntryDate) THEN
RETURN v_Rate * ct_EMURate;
END IF;
RETURN v_Rate;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
RETURN NULL;
END currencyRate;
/

View File

@ -0,0 +1,49 @@
CREATE OR REPLACE FUNCTION currencyRound
(
p_Amount IN NUMBER,
p_CurTo_ID IN NUMBER,
p_Costing IN VARCHAR2 -- Default 'N'
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Currency_Round.SQL,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Round amount for Traget Currency
* Description:
* Round Amount using Costing or Standard Precision
* Returns unmodified amount if currency not found
* Test:
* SELECT C_Currency_Round(C_Currency_Convert(100,116,100,null,null),100,null) FROM DUAL => 64.72
************************************************************************/
AS
v_StdPrecision NUMBER;
v_CostPrecision NUMBER;
BEGIN
-- Nothing to convert
IF (p_Amount IS NULL OR p_CurTo_ID IS NULL) THEN
RETURN p_Amount;
END IF;
-- Ger Precision
SELECT MAX(StdPrecision), MAX(CostingPrecision)
INTO v_StdPrecision, v_CostPrecision
FROM C_Currency
WHERE C_Currency_ID = p_CurTo_ID;
-- Currency Not Found
IF (v_StdPrecision IS NULL) THEN
RETURN p_Amount;
END IF;
IF (p_Costing = 'Y') THEN
RETURN ROUND (p_Amount, v_CostPrecision);
END IF;
RETURN ROUND (p_Amount, v_StdPrecision);
END currencyRound;
/

View File

@ -0,0 +1,74 @@
CREATE OR REPLACE FUNCTION invoiceDiscount
(
p_C_Invoice_ID IN NUMBER,
p_PayDate IN DATE,
p_C_InvoicePaySchedule_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Invoice_Discount.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Payment Discount Amount
* Description:
* - Calculate discountable amount (i.e. with or without tax)
* - Calculate and return payment discount
************************************************************************/
AS
v_Amount NUMBER;
v_IsDiscountLineAmt CHAR(1);
v_GrandTotal NUMBER;
v_TotalLines NUMBER;
v_C_PaymentTerm_ID NUMBER(10);
v_DocDate DATE;
v_PayDate DATE := SysDate;
v_IsPayScheduleValid CHAR(1);
BEGIN
SELECT ci.IsDiscountLineAmt, i.GrandTotal, i.TotalLines,
i.C_PaymentTerm_ID, i.DateInvoiced, i.IsPayScheduleValid
INTO v_IsDiscountLineAmt, v_GrandTotal, v_TotalLines,
v_C_PaymentTerm_ID, v_DocDate, v_IsPayScheduleValid
FROM AD_ClientInfo ci, C_Invoice i
WHERE ci.AD_Client_ID=i.AD_Client_ID
AND i.C_Invoice_ID=p_C_Invoice_ID;
-- What Amount is the Discount Base?
IF (v_IsDiscountLineAmt = 'Y') THEN
v_Amount := v_TotalLines;
ELSE
v_Amount := v_GrandTotal;
END IF;
-- Anything to discount?
IF (v_Amount = 0) THEN
RETURN 0;
END IF;
IF (p_PayDate IS NOT NULL) THEN
v_PayDate := p_PayDate;
END IF;
-- Valid Payment Schedule
IF (v_IsPayScheduleValid='Y' AND p_C_InvoicePaySchedule_ID > 0) THEN
SELECT COALESCE(MAX(DiscountAmt),0)
INTO v_Amount
FROM C_InvoicePaySchedule
WHERE C_InvoicePaySchedule_ID=p_C_InvoicePaySchedule_ID
AND DiscountDate <= v_PayDate;
--
RETURN v_Amount;
END IF;
-- return discount amount
RETURN paymentTermDiscount (v_Amount, 0, v_C_PaymentTerm_ID, v_DocDate, p_PayDate);
-- Most likely if invoice not found
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END invoiceDiscount;
/

View File

@ -0,0 +1,115 @@
CREATE OR REPLACE FUNCTION invoiceOpen
(
p_C_Invoice_ID IN NUMBER,
p_C_InvoicePaySchedule_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Invoice_Open.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Open Item Amount in Invoice Currency
* Description:
* Add up total amount open for C_Invoice_ID if no split payment.
* Grand Total minus Sum of Allocations in Invoice Currency
*
* For Split Payments:
* Allocate Payments starting from first schedule.
SELECT C_Invoice_Open (109) FROM DUAL;
SELECT C_Invoice_Open (109, null) FROM DUAL;
SELECT C_Invoice_Open (109, 11) FROM DUAL;
SELECT C_Invoice_Open (109, 102) FROM DUAL;
SELECT C_Invoice_Open (109, 103) FROM DUAL;
SELECT * FROM RV_OpenItem WHERE C_Invoice_ID=109;
SELECT C_InvoicePaySchedule_ID, DueAmt FROM C_InvoicePaySchedule WHERE C_Invoice_ID=109 ORDER BY DueDate;
* Cannot be used for IsPaid as mutating
************************************************************************/
AS
v_Currency_ID NUMBER(10);
v_TotalOpenAmt NUMBER := 0;
v_PaidAmt NUMBER := 0;
v_Remaining NUMBER := 0;
v_MultiplierAP NUMBER := 0;
v_MultiplierCM NUMBER := 0;
v_Temp NUMBER := 0;
--
CURSOR Cur_Alloc IS
SELECT a.AD_Client_ID, a.AD_Org_ID,
al.Amount, al.DiscountAmt, al.WriteOffAmt,
a.C_Currency_ID, a.DateTrx
FROM C_AllocationLine al
INNER JOIN C_AllocationHdr a ON (al.C_AllocationHdr_ID=a.C_AllocationHdr_ID)
WHERE al.C_Invoice_ID = p_C_Invoice_ID
AND a.IsActive='Y';
--
CURSOR Cur_PaySchedule IS
SELECT C_InvoicePaySchedule_ID, DueAmt
FROM C_InvoicePaySchedule
WHERE C_Invoice_ID = p_C_Invoice_ID
AND IsValid='Y'
ORDER BY DueDate;
BEGIN
-- Get Currency
BEGIN
SELECT MAX(C_Currency_ID), SUM(GrandTotal), MAX(MultiplierAP), MAX(Multiplier)
INTO v_Currency_ID, v_TotalOpenAmt, v_MultiplierAP, v_MultiplierCM
FROM C_Invoice_v -- corrected for CM / Split Payment
WHERE C_Invoice_ID = p_C_Invoice_ID;
EXCEPTION -- Invoice in draft form
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('InvoiceOpen - ' || SQLERRM);
RETURN NULL;
END;
-- DBMS_OUTPUT.PUT_LINE('== C_Invoice_ID=' || p_C_Invoice_ID || ', Total=' || v_TotalOpenAmt || ', AP=' || v_MultiplierAP || ', CM=' || v_MultiplierCM);
-- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP
v_Temp := a.Amount + a.DisCountAmt + a.WriteOffAmt;
v_PaidAmt := v_PaidAmt
-- Allocation
+ currencyConvert(v_Temp * v_MultiplierAP,
a.C_Currency_ID, v_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
DBMS_OUTPUT.PUT_LINE(' PaidAmt=' || v_PaidAmt || ', Allocation=' || v_Temp || ' * ' || v_MultiplierAP);
END LOOP;
-- Do we have a Payment Schedule ?
IF (p_C_InvoicePaySchedule_ID > 0) THEN -- if not valid = lists invoice amount
v_Remaining := v_PaidAmt;
FOR s IN Cur_PaySchedule LOOP
IF (s.C_InvoicePaySchedule_ID = p_C_InvoicePaySchedule_ID) THEN
v_TotalOpenAmt := (s.DueAmt*v_MultiplierCM) + v_Remaining;
IF (s.DueAmt - v_Remaining < 0) THEN
v_TotalOpenAmt := 0;
END IF;
-- DBMS_OUTPUT.PUT_LINE('Sched Total=' || v_TotalOpenAmt || ', Due=' || s.DueAmt || ',Remaining=' || v_Remaining || ',CM=' || v_MultiplierCM);
ELSE -- calculate amount, which can be allocated to next schedule
v_Remaining := v_Remaining - s.DueAmt;
IF (v_Remaining < 0) THEN
v_Remaining := 0;
END IF;
-- DBMS_OUTPUT.PUT_LINE('Remaining=' || v_Remaining);
END IF;
END LOOP;
ELSE
v_TotalOpenAmt := v_TotalOpenAmt - v_PaidAmt;
END IF;
-- DBMS_OUTPUT.PUT_LINE('== Total=' || v_TotalOpenAmt);
-- Ignore Rounding
IF (v_TotalOpenAmt BETWEEN -0.00999 AND 0.00999) THEN
v_TotalOpenAmt := 0;
END IF;
-- Round to penny
v_TotalOpenAmt := ROUND(COALESCE(v_TotalOpenAmt,0), 2);
RETURN v_TotalOpenAmt;
END invoiceOpen;
/

View File

@ -0,0 +1,60 @@
CREATE OR REPLACE FUNCTION invoicePaid
(
p_C_Invoice_ID IN NUMBER,
p_C_Currency_ID IN NUMBER,
p_MultiplierAP IN NUMBER -- DEFAULT 1
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Invoice_Paid.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Paid/Allocated amount in Currency
* Description:
* Add up total amount paid for for C_Invoice_ID.
* Split Payments are ignored.
* all allocation amounts converted to invoice C_Currency_ID
* round it to the nearest cent
* and adjust for CreditMemos by using C_Invoice_v
* and for Payments with the multiplierAP (-1, 1)
*
SELECT C_Invoice_ID, IsPaid, IsSOTrx, GrandTotal,
C_Invoice_Paid (C_Invoice_ID, C_Currency_ID, MultiplierAP)
FROM C_Invoice_v;
--
UPDATE C_Invoice_v1
SET IsPaid = CASE WHEN C_Invoice_Paid(C_Invoice_ID,C_Currency_ID,MultiplierAP)=GrandTotal THEN 'Y' ELSE 'N' END
WHERE C_Invoice_ID>1000000
*
************************************************************************/
AS
v_MultiplierAP NUMBER := 1;
v_PaymentAmt NUMBER := 0;
CURSOR Cur_Alloc IS
SELECT a.AD_Client_ID, a.AD_Org_ID,
al.Amount, al.DiscountAmt, al.WriteOffAmt,
a.C_Currency_ID, a.DateTrx
FROM C_AllocationLine al
INNER JOIN C_AllocationHdr a ON (al.C_AllocationHdr_ID=a.C_AllocationHdr_ID)
WHERE al.C_Invoice_ID = p_C_Invoice_ID
AND a.IsActive='Y';
BEGIN
-- Default
IF (p_MultiplierAP IS NOT NULL) THEN
v_MultiplierAP := p_MultiplierAP;
END IF;
-- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP
v_PaymentAmt := v_PaymentAmt
+ currencyConvert(a.Amount + a.DisCountAmt + a.WriteOffAmt,
a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
END LOOP;
--
RETURN ROUND(NVL(v_PaymentAmt,0), 2) * v_MultiplierAP;
END invoicePaid;
/

View File

@ -0,0 +1,71 @@
CREATE OR REPLACE FUNCTION paymentTermDiscount
(
Amount IN NUMBER,
Currency_ID IN NUMBER,
PaymentTerm_ID IN NUMBER,
DocDate IN DATE,
PayDate IN DATE
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_PaymentTerm_Discount.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Discount
* Description:
* Calculate the allowable Discount Amount of the Payment Term
*
* Test: SELECT C_PaymentTerm_Discount(17777, 103, '10-DEC-1999') FROM DUAL
************************************************************************/
AS
Discount NUMBER := 0;
CURSOR Cur_PT IS
SELECT *
FROM C_PaymentTerm
WHERE C_PaymentTerm_ID = PaymentTerm_ID;
Discount1Date DATE;
Discount2Date DATE;
Add1Date NUMBER := 0;
Add2Date NUMBER := 0;
BEGIN
-- No Data - No Discount
IF (Amount IS NULL OR PaymentTerm_ID IS NULL OR DocDate IS NULL) THEN
RETURN 0;
END IF;
FOR p IN Cur_PT LOOP -- for convineance only
-- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Doc = ' || TO_CHAR(DocDate));
Discount1Date := TRUNC(DocDate + p.DiscountDays + p.GraceDays);
Discount2Date := TRUNC(DocDate + p.DiscountDays2 + p.GraceDays);
-- Next Business Day
IF (p.IsNextBusinessDay='Y') THEN
-- Not fully correct - only does weekends (7=Saturday, 1=Sunday)
SELECT DECODE(TO_CHAR(Discount1Date,'D'), '7',2, '1',1, 0),
DECODE(TO_CHAR(Discount2Date,'D'), '7',2, '1',1, 0)
INTO Add1Date, Add2Date
FROM DUAL;
Discount1Date := Discount1Date+Add1Date;
Discount2Date := Discount2Date+Add2Date;
END IF;
-- Discount 1
IF (Discount1Date >= TRUNC(PayDate)) THEN
-- DBMS_OUTPUT.PUT_LINE('Discount 1 ' || TO_CHAR(Discount1Date) || ' ' || p.Discount);
Discount := Amount * p.Discount / 100;
-- Discount 2
ELSIF (Discount2Date >= TRUNC(PayDate)) THEN
-- DBMS_OUTPUT.PUT_LINE('Discount 2 ' || TO_CHAR(Discount2Date) || ' ' || p.Discount2);
Discount := Amount * p.Discount2 / 100;
END IF;
END LOOP;
--
RETURN ROUND(NVL(Discount,0), 2); -- fixed rounding
END paymentTermDiscount;
/

View File

@ -0,0 +1,52 @@
CREATE OR REPLACE FUNCTION paymentTermDueDate
(
PaymentTerm_ID IN NUMBER,
DocDate IN DATE
)
RETURN DATE
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_PaymentTerm_DueDate.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get Due Date
* Description:
* Returns the due date
************************************************************************/
AS
Days NUMBER := 0;
DueDate DATE := TRUNC(DocDate);
--
CURSOR Cur_PT IS
SELECT *
FROM C_PaymentTerm
WHERE C_PaymentTerm_ID = PaymentTerm_ID;
FirstDay DATE;
NoDays NUMBER;
BEGIN
FOR p IN Cur_PT LOOP -- for convineance only
-- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Doc = ' || TO_CHAR(DocDate));
-- Due 15th of following month
IF (p.IsDueFixed = 'Y') THEN
-- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Day = ' || p.FixMonthDay);
FirstDay := TRUNC(DocDate, 'MM');
NoDays := TRUNC(DocDate) - FirstDay;
DueDate := FirstDay + (p.FixMonthDay-1); -- starting on 1st
DueDate := ADD_MONTHS(DueDate, p.FixMonthOffset);
IF (NoDays > p.FixMonthCutoff) THEN
DueDate := ADD_MONTHS(DueDate, 1);
END IF;
ELSE
-- DBMS_OUTPUT.PUT_LINE('Net = ' || p.NetDays);
DueDate := TRUNC(DocDate) + p.NetDays;
END IF;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE('Due = ' || TO_CHAR(DueDate) || ', Pay = ' || TO_CHAR(PayDate));
RETURN DueDate;
END paymentTermDueDate;
/

View File

@ -0,0 +1,58 @@
CREATE OR REPLACE FUNCTION paymentTermDueDays
(
PaymentTerm_ID IN NUMBER,
DocDate IN DATE,
PayDate IN DATE
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_PaymentTerm_DueDays.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get Due Days
* Description:
* Returns the days due (positive) or the days till due (negative)
* Grace days are not considered!
* If record is not found it assumes due immediately
*
* Test: SELECT C_PaymentTerm_DueDays(103, '01-DEC-2000', '15-DEC-2000') FROM DUAL
************************************************************************/
AS
Days NUMBER := 0;
DueDate DATE := TRUNC(DocDate);
--
CURSOR Cur_PT IS
SELECT *
FROM C_PaymentTerm
WHERE C_PaymentTerm_ID = PaymentTerm_ID;
FirstDay DATE;
NoDays NUMBER;
BEGIN
FOR p IN Cur_PT LOOP -- for convineance only
-- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Doc = ' || TO_CHAR(DocDate));
-- Due 15th of following month
IF (p.IsDueFixed = 'Y') THEN
-- DBMS_OUTPUT.PUT_LINE(p.Name || ' - Day = ' || p.FixMonthDay);
FirstDay := TRUNC(DocDate, 'MM');
NoDays := TRUNC(DocDate) - FirstDay;
DueDate := FirstDay + (p.FixMonthDay-1); -- starting on 1st
DueDate := ADD_MONTHS(DueDate, p.FixMonthOffset);
IF (NoDays > p.FixMonthCutoff) THEN
DueDate := ADD_MONTHS(DueDate, 1);
END IF;
ELSE
-- DBMS_OUTPUT.PUT_LINE('Net = ' || p.NetDays);
DueDate := TRUNC(DocDate) + p.NetDays;
END IF;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE('Due = ' || TO_CHAR(DueDate) || ', Pay = ' || TO_CHAR(PayDate));
Days := TRUNC(PayDate) - DueDate;
RETURN Days;
END paymentTermDueDays;
/

View File

@ -0,0 +1,57 @@
CREATE OR REPLACE FUNCTION paymentAllocated
(
p_C_Payment_ID IN NUMBER,
p_C_Currency_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Payment_Allocated.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Allocated Payment Amount in Payment Currency
* Description:
--
SELECT C_Payment_Allocated(C_Payment_ID,C_Currency_ID), PayAmt, IsAllocated
FROM C_Payment_v
WHERE C_Payment_ID>=1000000;
--
UPDATE C_Payment_v
SET IsAllocated=CASE WHEN C_Payment_Allocated(C_Payment_ID, C_Currency_ID)=PayAmt THEN 'Y' ELSE 'N' END
WHERE C_Payment_ID>=1000000;
************************************************************************/
AS
v_AllocatedAmt NUMBER := 0;
v_PayAmt NUMBER;
CURSOR Cur_Alloc IS
SELECT a.AD_Client_ID, a.AD_Org_ID, al.Amount, a.C_Currency_ID, a.DateTrx
FROM C_AllocationLine al
INNER JOIN C_AllocationHdr a ON (al.C_AllocationHdr_ID=a.C_AllocationHdr_ID)
WHERE al.C_Payment_ID = p_C_Payment_ID
AND a.IsActive='Y';
-- AND al.C_Invoice_ID IS NOT NULL;
BEGIN
-- Charge - nothing available
SELECT MAX(PayAmt)
INTO v_PayAmt
FROM C_Payment
WHERE C_Payment_ID=p_C_Payment_ID AND C_Charge_ID > 0;
IF (v_PayAmt IS NOT NULL) THEN
RETURN 0;
END IF;
-- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP
v_AllocatedAmt := v_AllocatedAmt
+ currencyConvert(a.Amount, a.C_Currency_ID, p_C_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
END LOOP;
-- Round to penny
v_AllocatedAmt := ROUND(NVL(v_AllocatedAmt,0), 2);
RETURN v_AllocatedAmt;
END paymentAllocated;
/

View File

@ -0,0 +1,62 @@
CREATE OR REPLACE FUNCTION paymentAvailable
(
p_C_Payment_ID IN NUMBER
)
RETURN NUMBER
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: C_Payment_Available.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Calculate Available Payment Amount in Payment Currency
* Description:
* similar to C_Invoice_Open
************************************************************************/
AS
v_Currency_ID NUMBER(10);
v_AvailableAmt NUMBER := 0;
v_IsReceipt C_Payment.IsReceipt%TYPE;
v_Amt NUMBER := 0;
CURSOR Cur_Alloc IS
SELECT a.AD_Client_ID, a.AD_Org_ID, al.Amount, a.C_Currency_ID, a.DateTrx
FROM C_AllocationLine al
INNER JOIN C_AllocationHdr a ON (al.C_AllocationHdr_ID=a.C_AllocationHdr_ID)
WHERE al.C_Payment_ID = p_C_Payment_ID
AND a.IsActive='Y';
-- AND al.C_Invoice_ID IS NOT NULL;
BEGIN
-- Charge - fully allocated
SELECT MAX(PayAmt)
INTO v_Amt
FROM C_Payment
WHERE C_Payment_ID=p_C_Payment_ID AND C_Charge_ID > 0;
IF (v_Amt IS NOT NULL) THEN
RETURN v_Amt;
END IF;
-- Get Currency
SELECT C_Currency_ID, PayAmt, IsReceipt
INTO v_Currency_ID, v_AvailableAmt, v_IsReceipt
FROM C_Payment_v -- corrected for AP/AR
WHERE C_Payment_ID = p_C_Payment_ID;
-- DBMS_OUTPUT.PUT_LINE('== C_Payment_ID=' || p_C_Payment_ID || ', PayAmt=' || v_AvailableAmt || ', Receipt=' || v_IsReceipt);
-- Calculate Allocated Amount
FOR a IN Cur_Alloc LOOP
v_Amt := currencyConvert(a.Amount, a.C_Currency_ID, v_Currency_ID, a.DateTrx, null, a.AD_Client_ID, a.AD_Org_ID);
v_AvailableAmt := v_AvailableAmt - v_Amt;
-- DBMS_OUTPUT.PUT_LINE(' Allocation=' || a.Amount || ' - Available=' || v_AvailableAmt);
END LOOP;
-- Ignore Rounding
IF (v_AvailableAmt BETWEEN -0.00999 AND 0.00999) THEN
v_AvailableAmt := 0;
END IF;
-- Round to penny
v_AvailableAmt := ROUND(NVL(v_AvailableAmt,0), 2);
RETURN v_AvailableAmt;
END paymentAvailable;
/

View File

@ -0,0 +1,59 @@
CREATE OR REPLACE FUNCTION DBA_ConstraintCmd
(
p_ConstraintName IN VARCHAR2
)
RETURN VARCHAR2
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: DBA_ConstraintCmd.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
* $Source: /cvs/adempiere/db/database/Functions/DBA_ConstraintCmd.sql,v $
***
* Title: Create DML command for given constraint
* Description:
* SELECT DBA_ConstraintCmd(Constraint_Name) FROM User_Constraints WHERE CONSTRAINT_TYPE='R'
************************************************************************/
AS
v_Result VARCHAR2(2000);
v_TableName VARCHAR2(256);
v_ColumnName VARCHAR2(256);
v_ConstraintName VARCHAR2(256);
v_DeleteRule VARCHAR2(256);
BEGIN
-- Get First Part
SELECT c.Table_Name, cc.Column_name, c.R_Constraint_Name, c.Delete_Rule
INTO v_TableName, v_ColumnName, v_ConstraintName, v_DeleteRule
FROM USER_Constraints c, USER_Cons_Columns cc
WHERE c.Constraint_Name=cc.Constraint_Name
AND cc.Constraint_Name=p_ConstraintName;
-- Create First Part
v_Result := 'ALTER TABLE ' || v_TableName || ' ADD CONSTRAINT ' || p_ConstraintName
|| ' FOREIGN KEY (' || v_ColumnName || ') ';
-- Not a valid FK Reference
IF (v_ConstraintName IS NULL) THEN
RETURN NULL;
END IF;
-- Get Second Part
SELECT c.Table_Name, cc.Column_name
INTO v_TableName, v_ColumnName
FROM USER_Constraints c, USER_Cons_Columns cc
WHERE c.Constraint_Name=cc.Constraint_Name
AND cc.Constraint_Name=v_ConstraintName;
-- Create Second Part
v_Result := v_Result || 'REFERENCES ' || v_TableName || '(' || v_ColumnName || ')';
IF (v_DeleteRule = 'CASCADE') THEN
v_Result := v_Result || ' ON DELETE CASCADE';
END IF;
-- DBMS_OUTPUT.PUT_LINE(v_Result);
RETURN v_Result;
END DBA_ConstraintCmd;
/

View File

@ -0,0 +1,46 @@
CREATE OR REPLACE FUNCTION DBA_DisplayType
(
AD_Reference_ID IN NUMBER
)
RETURN VARCHAR2
AS
BEGIN
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: DBA_DisplayType.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Show clear text od DisplayType
* Description:
************************************************************************/
IF (AD_Reference_ID = 10) THEN RETURN 'String = 10';
ELSIF (AD_Reference_ID = 11) THEN RETURN 'Integer = 11';
ELSIF (AD_Reference_ID = 12) THEN RETURN 'Amount = 12';
ELSIF (AD_Reference_ID = 13) THEN RETURN 'ID = 13';
ELSIF (AD_Reference_ID = 14) THEN RETURN 'Text = 14';
ELSIF (AD_Reference_ID = 15) THEN RETURN 'Date = 15';
ELSIF (AD_Reference_ID = 16) THEN RETURN 'DateTime = 16';
ELSIF (AD_Reference_ID = 17) THEN RETURN 'List = 17';
ELSIF (AD_Reference_ID = 18) THEN RETURN 'Table = 18';
ELSIF (AD_Reference_ID = 19) THEN RETURN 'TableDir = 19';
ELSIF (AD_Reference_ID = 20) THEN RETURN 'YesNo = 20';
ELSIF (AD_Reference_ID = 21) THEN RETURN 'Location = 21';
ELSIF (AD_Reference_ID = 22) THEN RETURN 'Number = 22';
ELSIF (AD_Reference_ID = 23) THEN RETURN 'Binary = 23';
ELSIF (AD_Reference_ID = 24) THEN RETURN 'Time = 24';
ELSIF (AD_Reference_ID = 25) THEN RETURN 'Account = 25';
ELSIF (AD_Reference_ID = 26) THEN RETURN 'RowID = 26';
ELSIF (AD_Reference_ID = 27) THEN RETURN 'Color = 27';
ELSIF (AD_Reference_ID = 28) THEN RETURN 'Button = 28';
ELSIF (AD_Reference_ID = 29) THEN RETURN 'Quantity = 29';
ELSIF (AD_Reference_ID = 30) THEN RETURN 'Search = 30';
ELSIF (AD_Reference_ID = 31) THEN RETURN 'Locator = 31';
ELSIF (AD_Reference_ID = 32) THEN RETURN 'Image = 32';
ELSIF (AD_Reference_ID = 33) THEN RETURN 'Assignment= 33';
ELSE RETURN 'Unknown ('||AD_Reference_ID||')'; END IF;
END DBA_DisplayType;
/

View File

@ -0,0 +1,84 @@
CREATE OR REPLACE FUNCTION productAttribute
(
p_M_AttributeSetInstance_ID IN NUMBER
)
RETURN NVARCHAR2
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: M_Attribute_Name.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Return Instance Attribute Info
* Description:
*
* Test:
SELECT M_Attribute_Name (M_AttributeSetInstance_ID)
FROM M_InOutLine WHERE M_AttributeSetInstance_ID > 0
--
SELECT p.Name
FROM C_InvoiceLine il LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID);
SELECT p.Name || M_Attribute_Name (il.M_AttributeSetInstance_ID)
FROM C_InvoiceLine il LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID);
************************************************************************/
AS
v_Name NVARCHAR2(2000) := NULL;
v_NameAdd NVARCHAR2(2000) := '';
--
v_Lot M_AttributeSetInstance.Lot%TYPE;
v_LotStart M_AttributeSet.LotCharSOverwrite%TYPE;
v_LotEnd M_AttributeSet.LotCharEOverwrite%TYPE;
v_SerNo M_AttributeSetInstance.SerNo%TYPE;
v_SerNoStart M_AttributeSet.SerNoCharSOverwrite%TYPE;
v_SerNoEnd M_AttributeSet.SerNoCharEOverwrite%TYPE;
v_GuaranteeDate M_AttributeSetInstance.GuaranteeDate%TYPE;
--
CURSOR CUR_Attributes IS
SELECT ai.Value, a.Name
FROM M_AttributeInstance ai
INNER JOIN M_Attribute a ON (ai.M_Attribute_ID=a.M_Attribute_ID AND a.IsInstanceAttribute='Y')
WHERE ai.M_AttributeSetInstance_ID=p_M_AttributeSetInstance_ID;
BEGIN
/* -- Get Product Name
SELECT Name
INTO v_Name
FROM M_Product WHERE M_Product_ID=p_M_Product_ID;
*/
-- Get Product Attribute Set Instance
IF (p_M_AttributeSetInstance_ID > 0) THEN
SELECT asi.Lot, asi.SerNo, asi.GuaranteeDate,
COALESCE(a.SerNoCharSOverwrite, N'#'), COALESCE(a.SerNoCharEOverwrite, N''),
COALESCE(a.LotCharSOverwrite, N'<EFBFBD>'), COALESCE(a.LotCharEOverwrite, N'<EFBFBD>')
INTO v_Lot, v_SerNo, v_GuaranteeDate,
v_SerNoStart, v_SerNoEnd, v_LotStart, v_LotEnd
FROM M_AttributeSetInstance asi
INNER JOIN M_AttributeSet a ON (asi.M_AttributeSet_ID=a.M_AttributeSet_ID)
WHERE asi.M_AttributeSetInstance_ID=p_M_AttributeSetInstance_ID;
--
IF (v_SerNo IS NOT NULL) THEN
v_NameAdd := v_NameAdd || v_SerNoStart || v_SerNo || v_SerNoEnd || ' ';
END IF;
IF (v_Lot IS NOT NULL) THEN
v_NameAdd := v_NameAdd || v_LotStart || v_Lot || v_LotEnd || ' ';
END IF;
IF (v_GuaranteeDate IS NOT NULL) THEN
v_NameAdd := v_NameAdd || v_GuaranteeDate || ' ';
END IF;
--
FOR a IN CUR_Attributes LOOP
v_NameAdd := v_NameAdd || a.Name || ':' || a.Value || ' ';
END LOOP;
--
IF (LENGTH(v_NameAdd) > 0) THEN
v_Name := v_Name || ' (' || TRIM(v_NameAdd) || ')';
END IF;
END IF;
RETURN v_Name;
END productAttribute;
/

View File

@ -0,0 +1,280 @@
CREATE OR REPLACE PROCEDURE AD_Column_Sync
(
p_PInstance_ID IN NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_Column_Sync.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Synchronize Column with Database
* Description:
************************************************************************/
AS
-- Logistice
v_ResultStr VARCHAR2(2000);
v_Message VARCHAR2(2000);
v_Result NUMBER := 1; -- 0=failure
v_Record_ID NUMBER;
v_AD_User_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (pp_PInstance NUMBER) IS
SELECT i.Record_ID, i.AD_User_ID,
p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=pp_PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
-- Variables
v_TableName AD_Table.TableName%TYPE;
v_ColumnName AD_Column.ColumnName%TYPE;
v_AD_Reference_ID AD_Column.AD_Reference_ID%TYPE;
v_FieldLength AD_Column.FieldLength%TYPE;
v_DefaultValue AD_Column.DefaultValue%TYPE;
v_IsMandatory AD_Column.IsMandatory%TYPE;
--
v_DB_DataType USER_TAB_COLUMNS.DATA_TYPE%TYPE;
v_Cmd VARCHAR2(255);
v_DB_TableName VARCHAR(60) := NULL;
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID);
v_ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
-- Get Parameters
v_ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (p_PInstance_ID) LOOP
v_Record_ID := p.Record_ID;
v_AD_User_ID := p.AD_User_ID;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || v_Record_ID);
-- Get Table/Column Info
v_ResultStr := 'ReadingColumnInfo';
SELECT t.TableName, c.ColumnName, c.AD_Reference_ID, c.FieldLength,
c.DefaultValue, c.IsMandatory
INTO v_TableName, v_ColumnName, v_AD_Reference_ID, v_FieldLength,
v_DefaultValue, v_IsMandatory
FROM AD_Table t, AD_Column c
WHERE t.AD_Table_ID = c.AD_Table_ID
AND c.AD_Column_ID = v_Record_ID;
-- Check if Table exists
v_ResultStr := 'ReadingDBTableInfo';
BEGIN
SELECT Table_Name
INTO v_DB_TableName
FROM USER_TABLES
WHERE Table_Name=UPPER(v_TableName);
EXCEPTION
WHEN OTHERS THEN NULL;
END;
-- Table does not exists
IF (v_DB_TableName IS NULL) THEN
v_ResultStr := 'CreateTableCommand';
BEGIN
v_CMD := 'CREATE TABLE ' || SYS_CONTEXT('USERENV', 'CURRENT_USER') || '.'
|| UPPER(v_TableName) || ' (XXXX CHAR(1))';
EXECUTE IMMEDIATE v_Cmd;
EXCEPTION
WHEN OTHERS THEN
v_Result := 0; -- failure
v_Message := 'Error: ' || SQLERRM || ' - Command: ' || v_Cmd;
GOTO FINISH_PROCESS;
END;
END IF;
-- Get Data Dictionary Info
v_ResultStr := 'ReadingDBColumnInfo';
BEGIN
SELECT DATA_TYPE --, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT
INTO v_DB_DataType
FROM USER_TAB_COLUMNS
WHERE TABLE_NAME=UPPER(v_TableName)
AND COLUMN_NAME=UPPER(v_ColumnName);
EXCEPTION
WHEN OTHERS THEN NULL;
END;
/**
* Create Column in Database
*/
IF (v_DB_DataType IS NULL) THEN
v_ResultStr := 'CreateALTERCommand';
BEGIN
-- Get TableName
v_Cmd := 'ALTER TABLE ' || v_TableName || ' ADD ' || v_ColumnName || ' ';
-- Map Data Type
IF (v_AD_Reference_ID IN (10,14)) THEN
-- String, Text
v_Cmd := v_Cmd || 'NVARCHAR2(' || v_FieldLength || ')';
ELSIF (v_AD_Reference_ID IN (17,20,28)) THEN
-- List,YesNo,Button
v_Cmd := v_Cmd || 'CHAR(' || v_FieldLength || ')';
ELSIF (v_AD_Reference_ID IN (13,18,19,21,25,27,30,31)) THEN
-- ID,Table,TableDir,Location,Account,Color,Search,Locator
v_Cmd := v_Cmd || 'NUMBER(10)';
ELSIF (v_AD_Reference_ID IN (11,12,22,29)) THEN
-- Integer,Amount,Number,Quantity
v_Cmd := v_Cmd || 'NUMBER';
ELSIF (v_AD_Reference_ID IN (15,16)) THEN
-- Date,DateTime
v_Cmd := v_Cmd || 'DATE';
ELSE -- 23-Binary, 24-Radio, 26-RowID, 32-Image
v_Result := 0; -- failure
v_Message := 'DisplayType Not Supported';
END IF;
-- Default (literal)
IF (v_DefaultValue IS NOT NULL AND LENGTH(v_DefaultValue) <> 0) THEN
IF (v_AD_Reference_ID IN (10,14,17,20,28)) THEN
v_Cmd := v_Cmd || ' DEFAULT (''' || v_DefaultValue || ''')';
ELSE
v_Cmd := v_Cmd || ' DEFAULT ' || v_DefaultValue;
END IF;
END IF;
-- Mandatory
IF (v_IsMandatory = 'Y') THEN
IF (v_DefaultValue IS NULL OR LENGTH(v_DefaultValue) = 0) THEN
v_Result := 0; -- failure
v_Message := 'Mandatory requites literal default value';
ELSE
v_Cmd := v_Cmd || ' NOT NULL';
END IF;
END IF;
-- Execute it
IF (v_Result = 1) THEN
EXECUTE IMMEDIATE v_Cmd;
v_Message := '@Created@ - ' || v_Cmd;
END IF;
EXCEPTION
WHEN OTHERS THEN
v_Result := 0; -- failure
v_Message := 'Error: ' || SQLERRM || ' - Command: ' || v_Cmd;
END;
/**
* Change certain Attributes
*/
ELSE
v_ResultStr := 'CreateALTERCommand';
BEGIN
-- Get TableName
v_Cmd := 'ALTER TABLE ' || v_TableName || ' MODIFY ' || v_ColumnName || ' ';
-- Map Data Type
IF (v_AD_Reference_ID IN (10,14)) THEN
-- String, Text
v_Cmd := v_Cmd || 'NVARCHAR2(' || v_FieldLength || ')';
ELSIF (v_AD_Reference_ID IN (17,20,28)) THEN
-- List,YesNo,Button
v_Cmd := v_Cmd || 'CHAR(' || v_FieldLength || ')';
ELSIF (v_AD_Reference_ID IN (13,18,19,21,25,27,30,31)) THEN
-- ID,Table,TableDir,Location,Account,Color,Search,Locator
v_Cmd := v_Cmd || 'NUMBER(10)';
ELSIF (v_AD_Reference_ID IN (11,12,22,29)) THEN
-- Integer,Amount,Number,Quantity
v_Cmd := v_Cmd || 'NUMBER';
ELSIF (v_AD_Reference_ID IN (15,16)) THEN
-- Date,DateTime
v_Cmd := v_Cmd || 'DATE';
ELSE -- 23-Binary, 24-Radio, 26-RowID, 32-Image
v_Result := 0; -- failure
v_Message := 'DisplayType Not Supported';
END IF;
-- Default (literal)
IF (v_DefaultValue IS NOT NULL AND LENGTH(v_DefaultValue) <> 0) THEN
IF (v_AD_Reference_ID IN (10,14,17,20,28)) THEN
v_Cmd := v_Cmd || ' DEFAULT (''' || v_DefaultValue || ''')';
ELSE
v_Cmd := v_Cmd || ' DEFAULT ' || v_DefaultValue;
END IF;
END IF;
-- Mandatory
IF (v_IsMandatory = 'Y') THEN
IF (v_DefaultValue IS NULL OR LENGTH(v_DefaultValue) = 0) THEN
v_Result := 0; -- failure
v_Message := 'Mandatory requites literal default value';
ELSE
v_Cmd := v_Cmd || ' NOT NULL';
END IF;
END IF;
-- Execute it
IF (v_Result = 1) THEN
EXECUTE IMMEDIATE v_Cmd;
v_Message := '@Updated@ - ' || v_Cmd;
END IF;
EXCEPTION
WHEN OTHERS THEN
v_Result := 0; -- failure
v_Message := 'Error: ' || SQLERRM || ' - Command: ' || v_Cmd;
END;
END IF;
/**
* Delete Column
*
ELSE
v_Cmd := 'ALTER TABLE ' || v_TableName
|| ' DROP COLUMN ' || v_ColumnName;
-- Execute it
EXECUTE IMMEDIATE v_Cmd;
END IF;
/**/
-- Table did not exist - drop initial column
IF (v_DB_TableName IS NULL) THEN
v_ResultStr := 'CreateDropXXColumnCommand';
BEGIN
v_CMD := 'ALTER TABLE ' || v_TableName || ' DROP COLUMN XXXX';
EXECUTE IMMEDIATE v_Cmd;
EXCEPTION
WHEN OTHERS THEN
v_Result := 0; -- failure
v_Message := 'Error: ' || SQLERRM || ' - Command: ' || v_Cmd;
END;
END IF;
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = v_Result, -- 1=success
ErrorMsg = v_Message
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
v_ResultStr := v_ResultStr || ': ' || SQLERRM || ' - ' || v_Message;
DBMS_OUTPUT.PUT_LINE(v_ResultStr);
ROLLBACK;
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = v_ResultStr
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
RETURN;
END AD_Column_Sync;
/

View File

@ -0,0 +1,92 @@
CREATE OR REPLACE PROCEDURE AD_PrintPaper_Default
(
p_AD_PInstance_ID IN NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_PrintPaper_Default.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Set Current Format as Default
* Description:
************************************************************************/
AS
-- Logistice
v_ResultStr VARCHAR2(2000);
v_Message VARCHAR2(2000);
p_Record_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (PInstance NUMBER) IS
SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
p_AD_Client_ID NUMBER := NULL;
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_AD_PInstance_ID);
v_ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=p_AD_PInstance_ID;
COMMIT;
-- Get Parameters
v_ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (p_AD_PInstance_ID) LOOP
p_Record_ID := p.Record_ID;
IF (p.ParameterName = 'AD_Client_ID') THEN
p_AD_Client_ID := p.P_Number;
DBMS_OUTPUT.PUT_LINE(' AD_Client_ID=' || p_AD_Client_ID);
ELSE
DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
END IF;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || p_Record_ID);
v_ResultStr := 'Updating';
UPDATE AD_PrintFormat pf
SET AD_PrintPaper_ID = p_Record_ID
WHERE (AD_Client_ID = p_AD_Client_ID OR p_AD_Client_ID IS NULL)
AND EXISTS (SELECT * FROM AD_PrintPaper pp
WHERE pf.AD_PrintPaper_ID=pp.AD_PrintPaper_ID
AND IsLandscape = (SELECT IsLandscape FROM AD_PrintPaper
WHERE AD_PrintPaper_ID=p_Record_ID));
v_Message := '@Copied@=' || SQL%ROWCOUNT;
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 1, -- success
ErrorMsg = v_Message
WHERE AD_PInstance_ID=p_AD_PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
v_ResultStr := v_ResultStr || ': ' || SQLERRM || ' - ' || v_Message;
DBMS_OUTPUT.PUT_LINE(v_ResultStr);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = v_ResultStr
WHERE AD_PInstance_ID=p_AD_PInstance_ID;
COMMIT;
RETURN;
END AD_PrintPaper_Default;
/

View File

@ -0,0 +1,56 @@
CREATE OR REPLACE PROCEDURE AD_Sequence_Doc
(
p_SequenceName IN VARCHAR2,
p_AD_Client_ID IN NUMBER,
o_DocumentNo OUT VARCHAR2
)
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_Sequence_Doc.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get the next DocumentNo of TableName
* Description:
* store in parameter o_DocumentNo
* if ID < 1000000, use System Doc Sequence
************************************************************************/
v_NextNo NUMBER;
v_NextNoSys NUMBER;
v_Prefix VARCHAR2(30);
v_Suffix VARCHAR2(30);
BEGIN
SELECT CurrentNext, CurrentNextSys, Prefix, Suffix
INTO v_NextNo, v_NextNoSys, v_Prefix, v_Suffix
FROM AD_Sequence
WHERE Name = p_SequenceName
AND IsActive = 'Y'
AND IsTableID = 'N'
AND IsAutoSequence = 'Y'
AND AD_Client_ID = p_AD_Client_ID
FOR UPDATE OF CurrentNext, CurrentNextSys;
IF (v_NextNoSys <> -1 AND p_AD_Client_ID < 1000000) THEN -- System No
UPDATE AD_Sequence
SET CurrentNextSys = CurrentNextSys + IncrementNo,
Updated = SysDate
WHERE Name = p_SequenceName;
o_DocumentNo := NVL(v_Prefix, '') || v_NextNoSys || NVL(v_Suffix, '');
ELSE -- Standard No
UPDATE AD_Sequence
SET CurrentNext = CurrentNext + IncrementNo,
Updated = SysDate
WHERE Name = p_SequenceName;
o_DocumentNo := NVL(v_Prefix, '') || v_NextNo || NVL(v_Suffix, '');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20100, 'Document Sequence not found - ' || p_SequenceName);
END AD_Sequence_Doc;
/

View File

@ -0,0 +1,80 @@
CREATE OR REPLACE PROCEDURE AD_Sequence_DocType
(
p_DocType_ID IN NUMBER,
p_ID IN NUMBER,
p_DocumentNo OUT VARCHAR2
)
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_Sequence_DocType.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get the next DocumentNo of Document Type
* Description:
* store in parameter p_DocumentNo
* If ID < 1000000, use System Doc Sequence
* If no Document Sequence is defined, return null !
* Use AD_Sequence_Doc('DocumentNo_myTable',.. to get it directly
************************************************************************/
v_NextNo NUMBER;
v_NextNoSys NUMBER;
v_Sequence_ID NUMBER := NULL;
v_Prefix VARCHAR2(30);
v_Suffix VARCHAR2(30);
BEGIN
-- Is a document Sequence defined and valid?
BEGIN
SELECT DocNoSequence_ID
INTO v_Sequence_ID
FROM C_DocType
WHERE C_DocType_ID=p_DocType_ID -- parameter
AND IsDocNoControlled='Y'
AND IsActive='Y';
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
IF (v_Sequence_ID IS NULL) THEN -- No Sequence Number
p_DocumentNo := ''; -- Return NULL
DBMS_OUTPUT.PUT_LINE('[AD_Sequence_DocType: not found - C_DocType_ID=' || p_DocType_ID || ']');
RETURN;
END IF;
-- Get the numbers
SELECT s.AD_Sequence_ID, s.CurrentNext, s.CurrentNextSys, s.Prefix, s.Suffix
INTO v_Sequence_ID, v_NextNo, v_NextNoSys, v_Prefix, v_Suffix
FROM C_DocType d, AD_Sequence s
WHERE d.C_DocType_ID=p_DocType_ID -- parameter
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;
IF (v_NextNoSys <> -1 AND p_ID < 1000000) THEN -- System No
UPDATE AD_Sequence
SET CurrentNextSys = CurrentNextSys + IncrementNo
WHERE AD_Sequence_ID = v_Sequence_ID;
p_DocumentNo := NVL(v_Prefix, '') || v_NextNoSys || NVL(v_Suffix, '');
ELSE -- Standard No
UPDATE AD_Sequence
SET CurrentNext = CurrentNext + IncrementNo
WHERE AD_Sequence_ID = v_Sequence_ID;
p_DocumentNo := NVL(v_Prefix, '') || v_NextNo || NVL(v_Suffix, '');
END IF;
-- DBMS_OUTPUT.PUT_LINE(p_DocumentNo);
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20100, 'AD_Sequence_DocType: not found - DocType_ID='
|| p_DocType_ID || ', Sequence_ID=' || v_Sequence_ID);
END AD_Sequence_DocType;
/

View File

@ -0,0 +1,56 @@
CREATE OR REPLACE PROCEDURE AD_Sequence_Next
(
p_TableName IN VARCHAR2,
p_ID IN NUMBER,
p_NextNo OUT NUMBER
)
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_Sequence_Next.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get the next sequence number of TableName
* Description:
* store in parameter p_NextNo
* if ID < 1000000, use System Doc Sequence
************************************************************************/
v_NextNoSys NUMBER;
v_ResultStr VARCHAR(255);
BEGIN
v_ResultStr := 'Read';
SELECT CurrentNext, CurrentNextSys
INTO p_NextNo, v_NextNoSys
FROM AD_Sequence
WHERE Name = p_TableName
AND IsActive = 'Y'
AND IsTableID = 'Y'
AND IsAutoSequence = 'Y'
FOR UPDATE OF CurrentNext, CurrentNextSys;
v_ResultStr := 'Write';
IF (v_NextNoSys <> -1 AND p_ID < 1000000) THEN -- System No
UPDATE AD_Sequence
SET CurrentNextSys = CurrentNextSys + IncrementNo,
Updated = SysDate
WHERE Name = p_TableName;
p_NextNo := v_NextNoSys;
ELSE -- Standard No
UPDATE AD_Sequence
SET CurrentNext = CurrentNext + IncrementNo,
Updated = SysDate
WHERE Name = p_TableName;
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR (-20100, 'Table Sequence not found ');
-- || v_ResultStr || ': ' || p_TableName);
END AD_Sequence_Next;
/

View File

@ -0,0 +1,775 @@
CREATE OR REPLACE PROCEDURE AD_Synchronize
(
p_PInstance_ID IN NUMBER -- DEFAULT NULL
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AD_Syncronize.sql,v 1.2 2006/05/03 00:06:58 jjanke Exp $
***
* Title: Syncronize Application Dictionary
* Description:
* Synchronize Elements
* Update Column and Field with Names from Element and Process
* Update Process Parameters from Elements
* Update Workflow Notes from Windows
* Update Menu from Window/Form/Process/Task
************************************************************************/
AS
-- Logistice
v_ResultStr VARCHAR2(2000);
v_Message VARCHAR2(2000);
v_Result NUMBER := 1; -- 0=failure
v_Record_ID NUMBER;
v_AD_User_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (pp_PInstance NUMBER) IS
SELECT i.Record_ID, i.AD_User_ID,
p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=pp_PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
BEGIN
IF (p_PInstance_ID IS NOT NULL) THEN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID);
v_ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
-- Get Parameters
v_ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (p_PInstance_ID) LOOP
v_Record_ID := p.Record_ID;
v_AD_User_ID := p.AD_User_ID;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || v_Record_ID);
END IF;
---------------------------------------------------------------------------
DBMS_OUTPUT.PUT_LINE('Adding missing Elements');
DECLARE
NextNo NUMBER;
CURSOR Cur_Column IS
SELECT DISTINCT ColumnName, Name, Description, Help, EntityType
FROM AD_Column c
WHERE NOT EXISTS
(SELECT * FROM AD_Element e
WHERE UPPER(c.ColumnName)=UPPER(e.ColumnName));
CURSOR Cur_Process IS
SELECT DISTINCT ColumnName, Name, Description, Help, EntityType
FROM AD_Process_Para p
WHERE NOT EXISTS
(SELECT * FROM AD_Element e
WHERE UPPER(p.ColumnName)=UPPER(e.ColumnName));
CC Cur_Column%ROWTYPE;
BEGIN
DBMS_OUTPUT.PUT_LINE('Column:');
FOR CC IN Cur_Column LOOP
AD_Sequence_Next('AD_Element', 0, NextNo); -- get ID
INSERT INTO AD_ELEMENT
(AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
ColumnName, Name, PrintName, Description, Help, EntityType)
VALUES
(NextNo, 0, 0,
'Y', SysDate, 0, SysDate, 0,
CC.ColumnName, CC.Name, CC.Name, CC.Description, CC.Help, CC.EntityType);
DBMS_OUTPUT.PUT_LINE(' added ' || cc.ColumnName);
COMMIT;
END LOOP;
DBMS_OUTPUT.PUT_LINE('Parameter:');
FOR CC IN Cur_Process LOOP
AD_Sequence_Next('AD_Element', 0, NextNo); -- get ID
INSERT INTO AD_ELEMENT
(AD_ELEMENT_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
ColumnName, Name, PrintName, Description, Help, EntityType)
VALUES
(NextNo, 0, 0,
'Y', SysDate, 0, SysDate, 0,
CC.ColumnName, CC.Name, CC.Name, CC.Description, CC.Help, CC.EntityType);
DBMS_OUTPUT.PUT_LINE(' added ' || cc.ColumnName);
COMMIT;
END LOOP;
END;
DBMS_OUTPUT.PUT_LINE('Adding missing Element Translations');
INSERT INTO AD_Element_Trl (AD_Element_ID, AD_Language, AD_Client_ID, AD_Org_ID,
IsActive, Created, CreatedBy, Updated, UpdatedBy,
Name, PrintName, Description, Help, IsTranslated)
SELECT m.AD_Element_ID, l.AD_Language, m.AD_Client_ID, m.AD_Org_ID,
m.IsActive, m.Created, m.CreatedBy, m.Updated, m.UpdatedBy,
m.Name, m.PrintName, m.Description, m.Help, 'N'
FROM AD_Element m, AD_Language l
WHERE l.IsActive = 'Y' AND l.IsSystemLanguage = 'Y'
AND AD_Element_ID || AD_Language NOT IN
(SELECT AD_Element_ID || AD_Language FROM AD_Element_Trl);
DBMS_OUTPUT.PUT_LINE(' rows added: ' || SQL%ROWCOUNT);
DBMS_OUTPUT.PUT_LINE('Creating link from Element to Column');
UPDATE AD_Column c
SET AD_Element_id =
(SELECT AD_Element_ID FROM AD_Element e
WHERE UPPER(c.ColumnName)=UPPER(e.ColumnName))
WHERE AD_Element_ID IS NULL;
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
COMMIT;
DBMS_OUTPUT.PUT_LINE('Deleting unused Elements');
DELETE AD_Element_Trl
WHERE AD_Element_ID IN
(SELECT AD_Element_ID FROM AD_Element e
WHERE NOT EXISTS
(SELECT * FROM AD_Column c WHERE UPPER(e.ColumnName)=UPPER(c.ColumnName))
AND NOT EXISTS
(SELECT * FROM AD_Process_Para p WHERE UPPER(e.ColumnName)=UPPER(p.ColumnName)));
DELETE AD_Element e
WHERE NOT EXISTS
(SELECT * FROM AD_Column c WHERE UPPER(e.ColumnName)=UPPER(c.ColumnName))
AND NOT EXISTS
(SELECT * FROM AD_Process_Para p WHERE UPPER(e.ColumnName)=UPPER(p.ColumnName));
DBMS_OUTPUT.PUT_LINE(' rows deleted: ' || SQL%ROWCOUNT);
---------------------------------------------------------------------------
-- Columns
DBMS_OUTPUT.PUT_LINE('Synchronize Column');
/* Identify offending column
SELECT UPPER(ColumnName)
FROM AD_Element
GROUP BY UPPER(ColumnName)
HAVING COUNT(UPPER(ColumnName)) > 1
SELECT c.ColumnName, e.ColumnName
FROM AD_Column c
INNER JOIN AD_Element e ON (c.AD_Element_ID=e.AD_Element_ID)
WHERE c.ColumnName <> e.ColumnName
*/
UPDATE AD_Column c
SET (ColumnName, Name, Description, Help) =
(SELECT ColumnName, Name, Description, Help
FROM AD_Element e WHERE c.AD_Element_ID=e.AD_Element_ID),
Updated = SysDate
WHERE EXISTS (SELECT * FROM AD_Element e
WHERE c.AD_Element_ID=e.AD_Element_ID
AND (c.ColumnName <> e.ColumnName OR c.Name <> e.Name
OR NVL(c.Description,' ') <> NVL(e.Description,' ') OR NVL(c.Help,' ') <> NVL(e.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Fields should now be syncronized
DBMS_OUTPUT.PUT_LINE('Synchronize Field');
UPDATE AD_Field f
SET (Name, Description, Help) =
(SELECT e.Name, e.Description, e.Help
FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=f.AD_Column_ID),
Updated = SysDate
WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND EXISTS (SELECT * FROM AD_Element e, AD_Column c
WHERE f.AD_Column_ID=c.AD_Column_ID
AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
AND (f.Name <> e.Name OR NVL(f.Description,' ') <> NVL(e.Description,' ') OR NVL(f.Help,' ') <> NVL(e.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Field Translations
DBMS_OUTPUT.PUT_LINE('Synchronize Field Translations');
UPDATE AD_Field_trl trl
SET Name = (SELECT e.Name FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Description = (SELECT e.Description FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Help = (SELECT e.Help FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
IsTranslated = (SELECT e.IsTranslated FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Updated = SysDate
WHERE EXISTS (SELECT * FROM AD_Field f, AD_Element_trl e, AD_Column c
WHERE trl.AD_Field_ID=f.AD_Field_ID
AND f.AD_Column_ID=c.AD_Column_ID
AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
AND trl.AD_Language=e.AD_Language
AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND (trl.Name <> e.Name OR NVL(trl.Description,' ') <> NVL(e.Description,' ') OR NVL(trl.Help,' ') <> NVL(e.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Fields should now be syncronized
DBMS_OUTPUT.PUT_LINE('Synchronize PO Field');
UPDATE AD_Field f
SET Name = (SELECT e.PO_Name FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=f.AD_Column_ID),
Description = (SELECT e.PO_Description FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=f.AD_Column_ID),
Help = (SELECT e.PO_Help FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID AND c.AD_Column_ID=f.AD_Column_ID),
Updated = SysDate
WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND EXISTS (SELECT * FROM AD_Element e, AD_Column c
WHERE f.AD_Column_ID=c.AD_Column_ID
AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
AND (f.Name <> e.PO_Name OR NVL(f.Description,' ') <> NVL(e.PO_Description,' ') OR NVL(f.Help,' ') <> NVL(e.PO_Help,' '))
AND e.PO_Name IS NOT NULL)
AND EXISTS (SELECT * FROM AD_Tab t, AD_Window w
WHERE f.AD_Tab_ID=t.AD_Tab_ID
AND t.AD_Window_ID=w.AD_Window_ID
AND w.IsSOTrx='N');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Field Translations
DBMS_OUTPUT.PUT_LINE('Synchronize PO Field Translations');
UPDATE AD_Field_trl trl
SET Name = (SELECT e.PO_Name FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Description = (SELECT e.PO_Description FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Help = (SELECT e.PO_Help FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
IsTranslated = (SELECT e.IsTranslated FROM AD_Element_trl e, AD_Column c, AD_Field f
WHERE e.AD_Language=trl.AD_Language AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=f.AD_Column_ID AND f.AD_Field_ID=trl.AD_Field_ID),
Updated = SysDate
WHERE EXISTS (SELECT * FROM AD_Field f, AD_Element_trl e, AD_Column c
WHERE trl.AD_Field_ID=f.AD_Field_ID
AND f.AD_Column_ID=c.AD_Column_ID
AND c.AD_Element_ID=e.AD_Element_ID AND c.AD_Process_ID IS NULL
AND trl.AD_Language=e.AD_Language
AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND (trl.Name <> e.PO_Name OR NVL(trl.Description,' ') <> NVL(e.PO_Description,' ') OR NVL(trl.Help,' ') <> NVL(e.PO_Help,' '))
AND e.PO_Name IS NOT NULL)
AND EXISTS (SELECT * FROM AD_Field f, AD_Tab t, AD_Window w
WHERE trl.AD_Field_ID=f.AD_Field_ID
AND f.AD_Tab_ID=t.AD_Tab_ID
AND t.AD_Window_ID=w.AD_Window_ID
AND w.IsSOTrx='N');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Fields from Process
DBMS_OUTPUT.PUT_LINE('Synchronize Field from Process');
UPDATE AD_Field f
SET Name = (SELECT p.Name FROM AD_Process p, AD_Column c WHERE p.AD_Process_ID=c.AD_Process_ID
AND c.AD_Column_ID=f.AD_Column_ID),
Description = (SELECT p.Description FROM AD_Process p, AD_Column c WHERE p.AD_Process_ID=c.AD_Process_ID
AND c.AD_Column_ID=f.AD_Column_ID),
Help = (SELECT p.Help FROM AD_Process p, AD_Column c WHERE p.AD_Process_ID=c.AD_Process_ID
AND c.AD_Column_ID=f.AD_Column_ID),
Updated = SysDate
WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND EXISTS (SELECT * FROM AD_Process p, AD_Column c
WHERE c.AD_Process_ID=p.AD_Process_ID AND f.AD_Column_ID=c.AD_Column_ID
AND (f.Name<>p.Name OR NVL(f.Description,' ')<>NVL(p.Description,' ') OR NVL(f.Help,' ')<>NVL(p.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Field Translations from Process
DBMS_OUTPUT.PUT_LINE('Synchronize Field Trl from Process Trl');
UPDATE AD_Field_trl trl
SET Name = (SELECT p.Name FROM AD_Process_trl p, AD_Column c, AD_Field f
WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID
AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_Language=trl.AD_Language),
Description = (SELECT p.Description FROM AD_Process_trl p, AD_Column c, AD_Field f
WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID
AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_Language=trl.AD_Language),
Help = (SELECT p.Help FROM AD_Process_trl p, AD_Column c, AD_Field f
WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID
AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_Language=trl.AD_Language),
IsTranslated = (SELECT p.IsTranslated FROM AD_Process_trl p, AD_Column c, AD_Field f
WHERE p.AD_Process_ID=c.AD_Process_ID AND c.AD_Column_ID=f.AD_Column_ID
AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_Language=trl.AD_Language),
Updated = SysDate
WHERE EXISTS (SELECT * FROM AD_Process_Trl p, AD_Column c, AD_Field f
WHERE c.AD_Process_ID=p.AD_Process_ID AND f.AD_Column_ID=c.AD_Column_ID
AND f.AD_Field_ID=trl.AD_Field_ID AND p.AD_Language=trl.AD_Language
AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND (trl.Name<>p.Name OR NVL(trl.Description,' ')<>NVL(p.Description,' ') OR NVL(trl.Help,' ')<>NVL(p.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Sync Parameter ColumnName
UPDATE AD_Process_Para f
SET ColumnName = (SELECT e.ColumnName FROM AD_Element e
WHERE UPPER(e.ColumnName)=UPPER(f.ColumnName))
WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND EXISTS (SELECT * FROM AD_Element e
WHERE UPPER(e.ColumnName)=UPPER(f.ColumnName)
AND e.ColumnName<>f.ColumnName);
-- Paramenter Fields
UPDATE AD_Process_Para p
SET IsCentrallyMaintained = 'N'
WHERE IsCentrallyMaintained <> 'N'
AND NOT EXISTS (SELECT * FROM AD_Element e WHERE p.ColumnName=e.ColumnName);
-- Parameter Fields
DBMS_OUTPUT.PUT_LINE('Synchronize Process Parameter');
UPDATE AD_Process_Para f
SET Name = (SELECT e.Name FROM AD_Element e
WHERE e.ColumnName=f.ColumnName),
Description = (SELECT e.Description FROM AD_Element e
WHERE e.ColumnName=f.ColumnName),
Help = (SELECT e.Help FROM AD_Element e
WHERE e.ColumnName=f.ColumnName),
Updated = SysDate
WHERE f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND EXISTS (SELECT * FROM AD_Element e
WHERE e.ColumnName=f.ColumnName
AND (f.Name <> e.Name OR NVL(f.Description,' ') <> NVL(e.Description,' ') OR NVL(f.Help,' ') <> NVL(e.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Parameter Translations
DBMS_OUTPUT.PUT_LINE('Synchronize Process Parameter Trl');
UPDATE AD_Process_Para_Trl trl
SET Name = (SELECT et.Name FROM AD_Element_Trl et, AD_Element e, AD_Process_Para f
WHERE et.AD_Language=trl.AD_Language AND et.AD_Element_ID=e.AD_Element_ID
AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID),
Description = (SELECT et.Description FROM AD_Element_Trl et, AD_Element e, AD_Process_Para f
WHERE et.AD_Language=trl.AD_Language AND et.AD_Element_ID=e.AD_Element_ID
AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID),
Help = (SELECT et.Help FROM AD_Element_Trl et, AD_Element e, AD_Process_Para f
WHERE et.AD_Language=trl.AD_Language AND et.AD_Element_ID=e.AD_Element_ID
AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID),
IsTranslated = (SELECT et.IsTranslated FROM AD_Element_Trl et, AD_Element e, AD_Process_Para f
WHERE et.AD_Language=trl.AD_Language AND et.AD_Element_ID=e.AD_Element_ID
AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID),
Updated = SysDate
WHERE EXISTS (SELECT * FROM AD_Element_Trl et, AD_Element e, AD_Process_Para f
WHERE et.AD_Language=trl.AD_Language AND et.AD_Element_ID=e.AD_Element_ID
AND e.ColumnName=f.ColumnName AND f.AD_Process_Para_ID=trl.AD_Process_Para_ID
AND f.IsCentrallyMaintained='Y' AND f.IsActive='Y'
AND (trl.Name <> et.Name OR NVL(trl.Description,' ') <> NVL(et.Description,' ') OR NVL(trl.Help,' ') <> NVL(et.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Node - Window
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node from Window');
UPDATE AD_WF_Node n
SET Name = (SELECT w.Name FROM AD_Window w
WHERE w.AD_Window_ID=n.AD_Window_ID),
Description = (SELECT w.Description FROM AD_Window w
WHERE w.AD_Window_ID=n.AD_Window_ID),
Help = (SELECT w.Help FROM AD_Window w
WHERE w.AD_Window_ID=n.AD_Window_ID)
WHERE n.IsCentrallyMaintained = 'Y'
AND EXISTS (SELECT * FROM AD_Window w
WHERE w.AD_Window_ID=n.AD_Window_ID
AND (w.Name <> n.Name OR NVL(w.Description,' ') <> NVL(n.Description,' ') OR NVL(w.Help,' ') <> NVL(n.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Translations - Window
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node Trl from Window Trl');
UPDATE AD_WF_Node_Trl trl
SET Name = (SELECT t.Name FROM AD_Window_trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
AND trl.AD_Language=t.AD_Language),
Description = (SELECT t.Description FROM AD_Window_trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
AND trl.AD_Language=t.AD_Language),
Help = (SELECT t.Help FROM AD_Window_trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
AND trl.AD_Language=t.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Window_Trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Window_ID=t.AD_Window_ID
AND trl.AD_Language=t.AD_Language AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'
AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL(trl.Help,' ') <> NVL(t.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Node - Form
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node from Form');
UPDATE AD_WF_Node n
SET (Name, Description, Help) = (SELECT f.Name, f.Description, f.Help
FROM AD_Form f
WHERE f.AD_Form_ID=n.AD_Form_ID)
WHERE n.IsCentrallyMaintained = 'Y'
AND EXISTS (SELECT * FROM AD_Form f
WHERE f.AD_Form_ID=n.AD_Form_ID
AND (f.Name <> n.Name OR NVL(f.Description,' ') <> NVL(n.Description,' ') OR NVL(f.Help,' ') <> NVL(n.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Translations - Form
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node Trl from Form Trl');
UPDATE AD_WF_Node_Trl trl
SET (Name, Description, Help) = (SELECT t.Name, t.Description, t.Help
FROM AD_Form_trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
AND trl.AD_Language=t.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Form_Trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Form_ID=t.AD_Form_ID
AND trl.AD_Language=t.AD_Language AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'
AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL(trl.Help,' ') <> NVL(t.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Node - Report
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node from Process');
UPDATE AD_WF_Node n
SET (Name, Description, Help) = (SELECT f.Name, f.Description, f.Help
FROM AD_Process f
WHERE f.AD_Process_ID=n.AD_Process_ID)
WHERE n.IsCentrallyMaintained = 'Y'
AND EXISTS (SELECT * FROM AD_Process f
WHERE f.AD_Process_ID=n.AD_Process_ID
AND (f.Name <> n.Name OR NVL(f.Description,' ') <> NVL(n.Description,' ') OR NVL(f.Help,' ') <> NVL(n.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Workflow Translations - Form
DBMS_OUTPUT.PUT_LINE('Synchronize Workflow Node Trl from Process Trl');
UPDATE AD_WF_Node_Trl trl
SET (Name, Description, Help) = (SELECT t.Name, t.Description, t.Help
FROM AD_Process_trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Process_ID=t.AD_Process_ID
AND trl.AD_Language=t.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Process_Trl t, AD_WF_Node n
WHERE trl.AD_WF_Node_ID=n.AD_WF_Node_ID AND n.AD_Process_ID=t.AD_Process_ID
AND trl.AD_Language=t.AD_Language AND n.IsCentrallyMaintained='Y' AND n.IsActive='Y'
AND (trl.Name <> t.Name OR NVL(trl.Description,' ') <> NVL(t.Description,' ') OR NVL(trl.Help,' ') <> NVL(t.Help,' ')));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
-- Need centrally maintained flag here!
DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Name from Element');
UPDATE AD_PrintFormatItem pfi
SET Name = (SELECT e.Name
FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID)
WHERE pfi.IsCentrallyMaintained='Y'
AND EXISTS (SELECT *
FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID
AND e.Name<>pfi.Name)
AND EXISTS (SELECT * FROM AD_Client
WHERE AD_Client_ID=pfi.AD_Client_ID AND IsMultiLingualDocument='Y');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem PrintName from Element');
UPDATE AD_PrintFormatItem pfi
SET PrintName = (SELECT e.PrintName
FROM AD_Element e, AD_Column c
WHERE e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID)
WHERE pfi.IsCentrallyMaintained='Y'
AND EXISTS (SELECT *
FROM AD_Element e, AD_Column c, AD_PrintFormat pf
WHERE e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID
AND LENGTH(pfi.PrintName) > 0
AND e.PrintName<>pfi.PrintName
AND pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID
AND pf.IsForm='N' AND IsTableBased='Y')
AND EXISTS (SELECT * FROM AD_Client
WHERE AD_Client_ID=pfi.AD_Client_ID AND IsMultiLingualDocument='Y');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Trl from Element Trl (Multi-Lingual)');
UPDATE AD_PrintFormatItem_Trl trl
SET PrintName = (SELECT e.PrintName
FROM AD_Element_Trl e, AD_Column c, AD_PrintFormatItem pfi
WHERE e.AD_Language=trl.AD_Language
AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID
AND pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID)
WHERE EXISTS (SELECT *
FROM AD_Element_Trl e, AD_Column c, AD_PrintFormatItem pfi, AD_PrintFormat pf
WHERE e.AD_Language=trl.AD_Language
AND e.AD_Element_ID=c.AD_Element_ID
AND c.AD_Column_ID=pfi.AD_Column_ID
AND pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID
AND pfi.IsCentrallyMaintained='Y'
AND LENGTH(pfi.PrintName) > 0
AND (e.PrintName<>trl.PrintName OR trl.PrintName IS NULL)
AND pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID
AND pf.IsForm='N' AND IsTableBased='Y')
AND EXISTS (SELECT * FROM AD_Client
WHERE AD_Client_ID=trl.AD_Client_ID AND IsMultiLingualDocument='Y');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
DBMS_OUTPUT.PUT_LINE('Synchronize PrintFormatItem Trl (Not Multi-Lingual)');
UPDATE AD_PrintFormatItem_Trl trl
SET PrintName = (SELECT pfi.PrintName
FROM AD_PrintFormatItem pfi
WHERE pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID)
WHERE EXISTS (SELECT *
FROM AD_PrintFormatItem pfi, AD_PrintFormat pf
WHERE pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID
AND pfi.IsCentrallyMaintained='Y'
AND LENGTH(pfi.PrintName) > 0
AND pfi.PrintName<>trl.PrintName
AND pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID
AND pf.IsForm='N' AND pf.IsTableBased='Y')
AND EXISTS (SELECT * FROM AD_Client
WHERE AD_Client_ID=trl.AD_Client_ID AND IsMultiLingualDocument='N');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
DBMS_OUTPUT.PUT_LINE('Reset PrintFormatItem Trl where not used in base table');
UPDATE AD_PrintFormatItem_Trl trl
SET PrintName = NULL
WHERE PrintName IS NOT NULL
AND EXISTS (SELECT *
FROM AD_PrintFormatItem pfi
WHERE pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID
AND pfi.IsCentrallyMaintained='Y'
AND (LENGTH (pfi.PrintName) = 0 OR pfi.PrintName IS NULL));
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
/**
SELECT e.PrintName "Element", pfi.PrintName "FormatItem", trl.AD_Language, trl.PrintName "Trl"
FROM AD_Element e
INNER JOIN AD_Column c ON (e.AD_Element_ID=c.AD_Element_ID)
INNER JOIN AD_PrintFormatItem pfi ON (c.AD_Column_ID=pfi.AD_Column_ID)
INNER JOIN AD_PrintFormatItem_Trl trl ON (pfi.AD_PrintFormatItem_ID=trl.AD_PrintFormatItem_ID)
WHERE pfi.AD_PrintFormatItem_ID=?
**/
-- Sync Names - Window
DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Window');
UPDATE AD_Menu m
SET Name = (SELECT Name FROM AD_Window w WHERE m.AD_Window_ID=w.AD_Window_ID),
Description = (SELECT Description FROM AD_Window w WHERE m.AD_Window_ID=w.AD_Window_ID)
WHERE AD_Window_ID IS NOT NULL
AND Action = 'W';
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Menu_Trl mt
SET Name = (SELECT wt.Name FROM AD_Window_Trl wt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
AND mt.AD_Language=wt.AD_Language),
Description = (SELECT wt.Description FROM AD_Window_Trl wt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
AND mt.AD_Language=wt.AD_Language),
IsTranslated = (SELECT wt.IsTranslated FROM AD_Window_Trl wt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
AND mt.AD_Language=wt.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Window_Trl wt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Window_ID=wt.AD_Window_ID
AND mt.AD_Language=wt.AD_Language
AND m.AD_Window_ID IS NOT NULL
AND m.Action = 'W');
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Sync Names - Process
DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Processes');
UPDATE AD_Menu m
SET Name = (SELECT p.Name FROM AD_Process p WHERE m.AD_Process_ID=p.AD_Process_ID),
Description = (SELECT p.Description FROM AD_Process p WHERE m.AD_Process_ID=p.AD_Process_ID)
WHERE m.AD_Process_ID IS NOT NULL
AND m.Action IN ('R', 'P');
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Menu_Trl mt
SET Name = (SELECT pt.Name FROM AD_Process_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
AND mt.AD_Language=pt.AD_Language),
Description = (SELECT pt.Description FROM AD_Process_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
AND mt.AD_Language=pt.AD_Language),
IsTranslated = (SELECT pt.IsTranslated FROM AD_Process_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
AND mt.AD_Language=pt.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Process_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Process_ID=pt.AD_Process_ID
AND mt.AD_Language=pt.AD_Language
AND m.AD_Process_ID IS NOT NULL
AND Action IN ('R', 'P'));
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Sync Names = Form
DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Forms');
UPDATE AD_Menu m
SET Name = (SELECT Name FROM AD_Form f WHERE m.AD_Form_ID=f.AD_Form_ID),
Description = (SELECT Description FROM AD_Form f WHERE m.AD_Form_ID=f.AD_Form_ID)
WHERE AD_Form_ID IS NOT NULL
AND Action = 'X';
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Menu_Trl mt
SET Name = (SELECT ft.Name FROM AD_Form_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
AND mt.AD_Language=ft.AD_Language),
Description = (SELECT ft.Description FROM AD_Form_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
AND mt.AD_Language=ft.AD_Language),
IsTranslated = (SELECT ft.IsTranslated FROM AD_Form_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
AND mt.AD_Language=ft.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Form_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Form_ID=ft.AD_Form_ID
AND mt.AD_Language=ft.AD_Language
AND m.AD_Form_ID IS NOT NULL
AND Action = 'X');
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Sync Names - Workflow
DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Workflows');
UPDATE AD_Menu m
SET Name = (SELECT p.Name FROM AD_Workflow p WHERE m.AD_Workflow_ID=p.AD_Workflow_ID),
Description = (SELECT p.Description FROM AD_Workflow p WHERE m.AD_Workflow_ID=p.AD_Workflow_ID)
WHERE m.AD_Workflow_ID IS NOT NULL
AND m.Action = 'F';
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Menu_Trl mt
SET Name = (SELECT pt.Name FROM AD_Workflow_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
AND mt.AD_Language=pt.AD_Language),
Description = (SELECT pt.Description FROM AD_Workflow_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
AND mt.AD_Language=pt.AD_Language),
IsTranslated = (SELECT pt.IsTranslated FROM AD_Workflow_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
AND mt.AD_Language=pt.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Workflow_Trl pt, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Workflow_ID=pt.AD_Workflow_ID
AND mt.AD_Language=pt.AD_Language
AND m.AD_Workflow_ID IS NOT NULL
AND Action = 'F');
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Sync Names = Task
DBMS_OUTPUT.PUT_LINE('Synchronizing Menu with Tasks');
UPDATE AD_Menu m
SET Name = (SELECT Name FROM AD_Task f WHERE m.AD_Task_ID=f.AD_Task_ID),
Description = (SELECT Description FROM AD_Task f WHERE m.AD_Task_ID=f.AD_Task_ID)
WHERE AD_Task_ID IS NOT NULL
AND Action = 'T';
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Menu_Trl mt
SET Name = (SELECT ft.Name FROM AD_Task_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
AND mt.AD_Language=ft.AD_Language),
Description = (SELECT ft.Description FROM AD_Task_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
AND mt.AD_Language=ft.AD_Language),
IsTranslated = (SELECT ft.IsTranslated FROM AD_Task_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
AND mt.AD_Language=ft.AD_Language)
WHERE EXISTS (SELECT * FROM AD_Task_Trl ft, AD_Menu m
WHERE mt.AD_Menu_ID=m.AD_Menu_ID AND m.AD_Task_ID=ft.AD_Task_ID
AND mt.AD_Language=ft.AD_Language
AND m.AD_Task_ID IS NOT NULL
AND Action = 'T');
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Column Name + Element
DBMS_OUTPUT.PUT_LINE('Synchronizing Column with Element');
UPDATE AD_Column c
SET (Name,Description,Help) =
(SELECT e.Name,e.Description,e.Help
FROM AD_Element e WHERE c.AD_Element_ID=e.AD_Element_ID)
WHERE EXISTS
(SELECT * FROM AD_Element e
WHERE c.AD_Element_ID=e.AD_Element_ID
AND c.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Column_Trl ct
SET Name = (SELECT e.Name
FROM AD_Column c INNER JOIN AD_Element_Trl e ON (c.AD_Element_ID=e.AD_Element_ID)
WHERE ct.AD_Column_ID=c.AD_Column_ID AND ct.AD_Language=e.AD_Language)
WHERE EXISTS
(SELECT * FROM AD_Column c INNER JOIN AD_Element_Trl e ON (c.AD_Element_ID=e.AD_Element_ID)
WHERE ct.AD_Column_ID=c.AD_Column_ID AND ct.AD_Language=e.AD_Language
AND ct.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Table Name + Element
DBMS_OUTPUT.PUT_LINE('Synchronizing Table with Element');
UPDATE AD_Table t
SET (Name,Description) = (SELECT e.Name,e.Description FROM AD_Element e
WHERE t.TableName||'_ID'=e.ColumnName)
WHERE EXISTS (SELECT * FROM AD_Element e
WHERE t.TableName||'_ID'=e.ColumnName
AND t.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Table_Trl tt
SET Name = (SELECT e.Name
FROM AD_Table t INNER JOIN AD_Element ex ON (t.TableName||'_ID'=ex.ColumnName)
INNER JOIN AD_Element_Trl e ON (ex.AD_Element_ID=e.AD_Element_ID)
WHERE tt.AD_Table_ID=t.AD_Table_ID AND tt.AD_Language=e.AD_Language)
WHERE EXISTS (SELECT *
FROM AD_Table t INNER JOIN AD_Element ex ON (t.TableName||'_ID'=ex.ColumnName)
INNER JOIN AD_Element_Trl e ON (ex.AD_Element_ID=e.AD_Element_ID)
WHERE tt.AD_Table_ID=t.AD_Table_ID AND tt.AD_Language=e.AD_Language
AND tt.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
-- Trl Table Name + Element
UPDATE AD_Table t
SET (Name,Description) = (SELECT e.Name||' Trl', e.Description
FROM AD_Element e
WHERE SUBSTR(t.TableName,1,LENGTH(t.TableName)-4)||'_ID'=e.ColumnName)
WHERE TableName LIKE '%_Trl'
AND EXISTS (SELECT * FROM AD_Element e
WHERE SUBSTR(t.TableName,1,LENGTH(t.TableName)-4)||'_ID'=e.ColumnName
AND t.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' rows updated: ' || SQL%ROWCOUNT);
UPDATE AD_Table_Trl tt
SET Name = (SELECT e.Name || ' **'
FROM AD_Table t INNER JOIN AD_Element ex ON (SUBSTR(t.TableName,1,LENGTH(t.TableName)-4)||'_ID'=ex.ColumnName)
INNER JOIN AD_Element_Trl e ON (ex.AD_Element_ID=e.AD_Element_ID)
WHERE tt.AD_Table_ID=t.AD_Table_ID AND tt.AD_Language=e.AD_Language)
WHERE EXISTS (SELECT *
FROM AD_Table t INNER JOIN AD_Element ex ON (SUBSTR(t.TableName,1,LENGTH(t.TableName)-4)||'_ID'=ex.ColumnName)
INNER JOIN AD_Element_Trl e ON (ex.AD_Element_ID=e.AD_Element_ID)
WHERE tt.AD_Table_ID=t.AD_Table_ID AND tt.AD_Language=e.AD_Language
AND t.TableName LIKE '%_Trl'
AND tt.Name<>e.Name);
DBMS_OUTPUT.PUT_LINE(' trl rows updated: ' || SQL%ROWCOUNT);
/** Remaining tables
SELECT Name, TableName FROM AD_Table t WHERE Name=TableName ORDER BY 1
**/
<<FINISH_PROCESS>>
IF (p_PInstance_ID IS NOT NULL) THEN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = v_Result, -- 1=success
ErrorMsg = v_Message
WHERE AD_PInstance_ID=p_PInstance_ID;
END IF;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
v_ResultStr := v_ResultStr || ': ' || SQLERRM || ' - ' || v_Message;
DBMS_OUTPUT.PUT_LINE(v_ResultStr);
ROLLBACK;
IF (p_PInstance_ID IS NOT NULL) THEN
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = v_ResultStr
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
END IF;
RETURN;
END AD_Synchronize;
/

View File

@ -0,0 +1,173 @@
CREATE OR REPLACE PROCEDURE C_Order_DrillDown
(
PInstance_ID IN NUMBER
)
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* List Orders with their Shipments and Invoices
* Spool to T_Spool
*/
AS
ResultStr VARCHAR2(2000);
Message VARCHAR2(2000);
Record_ID NUMBER;
CURSOR Cur_Parameter (PInstance NUMBER) IS
SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter
C_Order_ID NUMBER;
--
CURSOR Cur_Order IS
SELECT o.C_Order_ID, d.Name, o.DocumentNo, o.DocStatus, o.DocAction, o.Processed
FROM C_Order o, C_DocType d
WHERE o.C_Order_ID=C_Order_ID
AND o.C_DocType_ID=d.C_DocType_ID
ORDER BY o.DocumentNo DESC;
BEGIN
-- No locking or Updating
-- Get Parameters
ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (PInstance_ID) LOOP
Record_ID := p.Record_ID;
IF (p.ParameterName = 'C_Order_ID') THEN
C_Order_ID := p.P_Number;
DBMS_OUTPUT.PUT_LINE(' C_Order_ID=' || C_Order_ID);
ELSE
DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
END IF;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || Record_ID);
IF (C_Order_ID IS NULL) THEN
C_Order_ID := Record_ID;
END IF;
-- Should be nothing there
DELETE T_Spool
WHERE AD_PInstance_ID=PInstance_ID;
-- Order Info
FOR o IN Cur_Order LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
o.Name || ' ' || o.DocumentNo || ': @DocStatus@=' || o.DocStatus
|| ', @DocAction@=' || o.DocAction || ', @Processed@=' || o.Processed);
-- Order Lines
DECLARE
CURSOR Cur_OrderLine IS
SELECT *
FROM C_OrderLine
WHERE C_Order_ID=o.C_Order_ID
ORDER BY Line;
BEGIN
FOR ol IN Cur_OrderLine LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
' @QtyOrdered@=' || ol.QtyOrdered || ', @QtyReserved@=' || ol.QtyReserved
|| ', @QtyDelivered@=' || ol.QtyDelivered || ', @QtyInvoiced@=' || ol.QtyInvoiced
|| ' - Wh=' || ol.M_Warehouse_ID
|| ', Prd=' || ol.M_Product_ID);
END LOOP;
END;
-- Shipment
DECLARE
CURSOR Cur_InOut IS
SELECT s.M_InOut_ID, d.Name, s.DocumentNo, s.DocStatus, s.Processed, s.M_Warehouse_ID
FROM M_InOut s, C_DocType d
WHERE s.C_Order_ID = o.C_Order_ID
AND s.C_DocType_ID=d.C_DocType_ID;
BEGIN
FOR s IN Cur_InOut LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
'> ' || s.Name || ' ' || s.DocumentNo || ': @DocStatus@=' || s.DocStatus
|| ', @Processed@=' || s.Processed || ', Wh=' || s.M_Warehouse_ID);
-- Shipment Lines
DECLARE
CURSOR Cur_InOutLine IS
SELECT *
FROM M_InOutLine
WHERE M_InOut_ID=s.M_InOut_ID
ORDER BY Line;
BEGIN
FOR sl IN Cur_InOutLine LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
' @QtyDelivered@=' || sl.MovementQty || ', Prd=' || sl.M_Product_ID);
END LOOP;
END; -- Shipment Lines
END LOOP; -- Shipments
END; -- Shipment
-- Invoice
DECLARE
CURSOR Cur_Invoice IS
SELECT i.C_Invoice_ID, d.Name, i.DocumentNo, i.DocStatus, i.Processed
FROM C_Invoice i, C_DocType d
WHERE i.C_DocType_ID=d.C_DocType_ID
AND EXISTS (SELECT * FROM C_InvoiceLine l, C_OrderLine ol
WHERE i.C_Invoice_ID = l.C_Invoice_ID
AND l.C_OrderLine_ID = ol.C_OrderLine_ID
AND ol.C_Order_ID=o.C_Order_ID);
BEGIN
FOR i IN Cur_Invoice LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
'> ' || i.Name || ' ' || i.DocumentNo || ': @DocStatus@=' || i.DocStatus
|| ', @Processed@=' || i.Processed);
-- Invoice Lines
DECLARE
CURSOR Cur_InvoiceLine IS
SELECT *
FROM C_InvoiceLine
WHERE C_Invoice_ID=i.C_Invoice_ID
ORDER BY Line;
BEGIN
FOR il IN Cur_InvoiceLine LOOP
INSERT INTO T_Spool (AD_PInstance_ID, SeqNo, MsgText) VALUES (PInstance_ID, T_Spool_Seq.NextVal,
' @QtyInvoiced@=' || il.QtyInvoiced || ', Prd=' || il.M_Product_ID);
END LOOP;
END; -- Invoice Lines
END LOOP; -- Invoices
END; -- Invoice
END LOOP; -- Order
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 1, -- success
ErrorMsg = Message
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
ResultStr := ResultStr || ': ' || SQLERRM || ' - ' || Message;
DBMS_OUTPUT.PUT_LINE(ResultStr);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = ResultStr
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
END C_Order_DrillDown;
/

View File

@ -0,0 +1,56 @@
IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'C_ProcessCreate')
BEGIN
PRINT '<<< DROPPING PROCEDURE C_ProcessCreate >>>'
DROP Procedure C_ProcessCreate
END
go
------------------------------------------------------------------------------
CREATE Procedure C_ProcessCreate
(
@AD_Table_ID Identifier,
@Record_ID Identifier,
@AD_IProcess_ID Identifier OUTPUT
)
--WITH ENCRYPTION
AS
/******************************************************************************
* Author: Jorg Janke (c) ClassApps 1999
* Version: $Header: /cvs/adempiere/db/database/Procedures/C_ProcessCreate.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
*
* Description:
* Create process for background execution
*
* Return values:
* Int_Process_ID
*
* Called by:
*
******************************************************************************/
BEGIN
Set NoCount ON
BEGIN TRANSACTION
SELECT @AD_IProcess_ID = ISNULL(MAX(AD_IProcess_ID), 0)+1
FROM AD_IProcess
---------------------------------
INSERT INTO AD_IProcess
(AD_IProcess_ID, AD_Table_ID, Record_ID, IsProcessing, Updated)
VALUES
(@AD_IProcess_ID, @AD_Table_ID, @Record_ID, 'N', null)
IF (@@ERROR <> 0)
BEGIN
RAISERROR 60001 'Int_Process insert error'
ROLLBACK TRAN
RETURN(1)
END
COMMIT TRANSACTION
END -- C_ProcessCreate
go
------------------------------------------------------------------------------
IF OBJECT_ID('C_ProcessCreate') IS NOT NULL
PRINT '<<< CREATED PROCEDURE C_ProcessCreate >>>'
ELSE
PRINT '<<< FAILED CREATING PROCEDURE C_ProcessCreate >>>'
go

View File

@ -0,0 +1,21 @@
CREATE OR REPLACE PROCEDURE Cleanup
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Cleanup old temporary data
*/
AS
BEGIN
-- Processes
DELETE FROM AD_PInstance;
-- Search Info
DELETE FROM AD_Find;
-- Errors older than 1 week
DELETE AD_ERROR WHERE Created < SysDate-7;
--
COMMIT;
END Cleanup;
/

View File

@ -0,0 +1,45 @@
CREATE OR REPLACE PROCEDURE DBA_AfterImport
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: DBA_AfterImport.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
* $Source: /cvs/adempiere/db/database/Procedures/DBA_AfterImport.sql,v $
***
* Title: Run after Import
* Description:
* - Set Java Permissions
* - Recompile
* - Compute Statistics
*****************************************************************************/
-- Statistics
CURSOR Cur_Stat IS
SELECT Table_Name, Blocks
FROM USER_TABLES
WHERE DURATION IS NULL -- No temporary tables
AND Table_Name NOT LIKE '%$%'
AND (LAST_ANALYZED IS NULL OR LAST_ANALYZED < SysDate-7);
--
v_Cmd VARCHAR2(256);
v_NoC NUMBER := 0;
--
BEGIN
-- Recompile
DBA_Recompile(NULL);
-- Statistics
FOR s IN Cur_Stat LOOP
v_Cmd := 'ANALYZE TABLE ' || s.Table_Name || ' COMPUTE STATISTICS';
-- DBMS_OUTPUT.PUT_LINE (v_Cmd);
v_NoC := v_NoC + 1;
EXECUTE IMMEDIATE v_Cmd;
END LOOP;
DBMS_OUTPUT.PUT_LINE ('Statistics computed: ' || v_NoC);
--
END DBA_AfterImport;
/

View File

@ -0,0 +1,117 @@
CREATE OR REPLACE PROCEDURE DBA_Cleanup
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: DBA_Cleanup.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Cleanup old temporary data
* Description:
************************************************************************/
AS
BEGIN
DBMS_OUTPUT.PUT_LINE('DBA_Cleanup');
-- Clean up data
/**
-- C_Invoice_CheckPaid();
UPDATE C_Payment_v
SET IsAllocated=CASE WHEN paymentAllocated(C_Payment_ID, C_Currency_ID)=PayAmt THEN 'Y' ELSE 'N' END
WHERE IsAllocated='N';
UPDATE C_Invoice_v1
SET IsPaid = CASE WHEN invoicePaid(C_Invoice_ID,C_Currency_ID,MultiplierAP)=GrandTotal THEN 'Y' ELSE 'N' END
WHERE IsPaid='N';
**/
-- Temporary Tables
DELETE FROM T_Aging;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Aging=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_DistributionRunDetail;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_DistributionRunDetail=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_InventoryValue;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_InventoryValue=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_Replenish;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Replenish=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_Report;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Report=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_ReportStatement;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_ReportStatement=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_TrialBalance;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_TrialBalance=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_Selection;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Selection=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_Selection2;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Selection2=' || SQL%ROWCOUNT);
END IF;
DELETE FROM T_Spool;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' T_Spool=' || SQL%ROWCOUNT);
END IF;
-- Search Info
DELETE FROM AD_Find;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' AD_Find=' || SQL%ROWCOUNT);
END IF;
-- Processes older than a week
DELETE FROM AD_PInstance WHERE Created < SysDate-7;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' Old AD_PInstance=' || SQL%ROWCOUNT);
END IF;
/** Old Session (1 Week)
DELETE FROM AD_ChangeLog WHERE Created < SysDate-7;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' Old AD_ChangeLock=' || SQL%ROWCOUNT);
END IF;
DELETE FROM AD_Session WHERE Created < SysDate-7;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' Old AD_Session=' || SQL%ROWCOUNT);
END IF;
/** */
-- Errors older than 1 week
DELETE FROM AD_Error WHERE Created < SysDate-7;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' Old AD_Error=' || SQL%ROWCOUNT);
END IF;
-- Acknowledged Notes older than a day
DELETE FROM AD_Note WHERE Processed='Y' AND Updated < SysDate-1;
IF (SQL%ROWCOUNT <> 0) THEN
DBMS_OUTPUT.PUT_LINE(' Processed AD_Note=' || SQL%ROWCOUNT);
END IF;
--
COMMIT;
END DBA_Cleanup;
/

View File

@ -0,0 +1,148 @@
CREATE OR REPLACE PROCEDURE DBA_Recompile
(
p_PInstance_ID IN NUMBER -- DEFAULT NULL
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: DBA_Recompile.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Recompile all User_Objects
* Description:
************************************************************************/
AS
-- Logistice
v_Message VARCHAR2(2000) := ' ';
v_Result NUMBER := 1; -- 0=failure
--
v_Buffer VARCHAR2(2000);
v_Line VARCHAR(100);
v_PrintInfo CHAR(1) := 'N'; -- Diagnostic
--
CURSOR Cur_Invalids IS
SELECT object_id, object_name, object_type
FROM user_objects
WHERE status <> 'VALID'
AND object_type IN ('VIEW', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION',
'PROCEDURE', 'TRIGGER', 'JAVA CLASS')
ORDER BY object_type, object_name;
CURSOR Cur_Valids (p_id NUMBER) IS
SELECT 'FOUND'
FROM user_objects
WHERE status = 'VALID'
AND object_id = p_id;
-- failed compile
TYPE invalid_tab IS TABLE OF Cur_Invalids%ROWTYPE INDEX BY BINARY_INTEGER;
invalid_tab_rec invalid_tab;
count_compiled PLS_INTEGER;
valid_text VARCHAR2(5);
exec_cursor PLS_INTEGER := DBMS_SQL.OPEN_CURSOR;
sql_statement VARCHAR2(200);
count_object PLS_INTEGER := 0;
BEGIN
LOOP
count_compiled := 0;
FOR ci IN Cur_Invalids LOOP
-- not unsuccessfuly compiled yet
IF NOT invalid_tab_rec.EXISTS(ci.object_id) THEN
IF (ci.object_type = 'JAVA CLASS') THEN
sql_statement := 'ALTER JAVA CLASS "' || ci.object_name || '" RESOLVE';
ELSIF (ci.object_type = 'PACKAGE BODY') THEN
sql_statement := 'ALTER PACKAGE ' || ci.object_name || ' COMPILE BODY';
ELSE
sql_statement := 'ALTER ' || ci.object_type || ' ' || ci.object_name || ' COMPILE';
END IF;
-- compile
BEGIN
count_object := count_object + 1;
DBMS_SQL.PARSE(exec_cursor, sql_statement, DBMS_SQL.NATIVE);
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
--
OPEN Cur_Valids (ci.object_ID);
FETCH Cur_Valids INTO valid_text;
IF Cur_Valids%ROWCOUNT > 0 THEN
IF (v_PrintInfo = 'Y') THEN
DBMS_OUTPUT.PUT_LINE('OK: ' || ci.object_type || ' ' || ci.object_name);
END IF;
count_compiled := count_compiled + 1;
CLOSE Cur_Valids;
EXIT;
ELSE
IF (LENGTH(v_Message) < 1950) THEN
v_Message := v_Message || ci.object_name || ' ';
END IF;
IF (v_PrintInfo = 'Y') THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || ci.object_type || ' ' || ci.object_name);
END IF;
--
invalid_tab_rec(ci.object_id).object_name := ci.object_name;
invalid_tab_rec(ci.object_id).object_type := ci.object_type;
CLOSE Cur_Valids;
END IF;
END IF; -- not unsuccessfuly compiled yet
END LOOP; -- Cur_Invalids
-- any other to be compiled
IF count_compiled = 0 THEN
EXIT;
END IF;
END LOOP; -- outer loop
DBMS_SQL.CLOSE_CURSOR(exec_cursor);
--
-- Print Message
IF (LENGTH(v_Message) = 1) THEN
v_Message := 'All valid';
DBMS_OUTPUT.PUT_LINE(v_Message);
ELSIF (LENGTH(v_Message) > 80) THEN
v_Buffer := v_Message;
DBMS_OUTPUT.PUT_LINE('>');
WHILE (LENGTH(v_Buffer) > 0) LOOP
v_Line := SUBSTR(v_Buffer, 1, 80);
DBMS_OUTPUT.PUT_LINE(v_Line);
v_Buffer := SUBSTR(v_Buffer, 81);
END LOOP;
DBMS_OUTPUT.PUT_LINE('<');
v_Result := 0;
DBMS_OUTPUT.PUT_LINE('ERROR');
ELSE
DBMS_OUTPUT.PUT_LINE('>' || v_Message || '<');
v_Result := 0;
DBMS_OUTPUT.PUT_LINE('ERROR');
END IF;
<<FINISH_PROCESS>>
IF (p_PInstance_ID IS NOT NULL) THEN
-- Update AD_PInstance
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = v_Result, -- 1=success
ErrorMsg = v_Message
WHERE AD_PInstance_ID=p_PInstance_ID;
END IF;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
IF DBMS_SQL.IS_OPEN(exec_cursor) THEN
DBMS_SQL.CLOSE_CURSOR(exec_cursor);
END IF;
IF Cur_Valids%ISOPEN THEN
CLOSE Cur_Valids;
END IF;
END DBA_Recompile;
/

View File

@ -0,0 +1,116 @@
CREATE OR REPLACE PROCEDURE Fact_Acct_Balance_Update
(
p_DeleteFirst IN VARCHAR2 DEFAULT 'N'
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Fact_Acct_Balance_Update.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Update ALL Balances
* Description:
* - Recreates all Balances
************************************************************************/
AS
BEGIN
IF (p_DeleteFirst = 'Y') THEN
DELETE Fact_Acct_Balance;
DBMS_OUTPUT.PUT_LINE(' Deletes=' || SQL%ROWCOUNT);
ELSE
/** Update **/
UPDATE Fact_Acct_Balance ab
SET (AmtAcctDr, AmtAcctCr, Qty) =
(SELECT COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0)
FROM Fact_Acct a
WHERE a.AD_Client_ID=ab.AD_Client_ID AND a.AD_Org_ID=ab.AD_Org_ID
AND a.C_AcctSchema_ID=ab.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(ab.DateAcct)
AND a.Account_ID=ab.Account_ID AND a.PostingType=ab.PostingType
AND COALESCE(a.M_Product_ID,0)=COALESCE(ab.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(ab.C_BPartner_ID,0)
AND COALESCE(a.C_Project_ID,0)=COALESCE(ab.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(ab.AD_OrgTrx_ID,0)
AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(ab.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(ab.C_Activity_ID,0)
AND COALESCE(a.C_Campaign_ID,0)=COALESCE(ab.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(ab.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(ab.C_LocFrom_ID,0)
AND COALESCE(a.User1_ID,0)=COALESCE(ab.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(ab.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(ab.GL_Budget_ID,0)
GROUP BY AD_Client_ID,AD_Org_ID,
C_AcctSchema_ID, TRUNC(DateAcct),
Account_ID, PostingType,
M_Product_ID, C_BPartner_ID,
C_Project_ID, AD_OrgTrx_ID,
C_SalesRegion_ID, C_Activity_ID,
C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,
User1_ID, User2_ID, GL_Budget_ID)
WHERE EXISTS
(SELECT *
FROM Fact_Acct a
WHERE a.AD_Client_ID=ab.AD_Client_ID AND a.AD_Org_ID=ab.AD_Org_ID
AND a.C_AcctSchema_ID=ab.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(ab.DateAcct)
AND a.Account_ID=ab.Account_ID AND a.PostingType=ab.PostingType
AND COALESCE(a.M_Product_ID,0)=COALESCE(ab.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(ab.C_BPartner_ID,0)
AND COALESCE(a.C_Project_ID,0)=COALESCE(ab.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(ab.AD_OrgTrx_ID,0)
AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(ab.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(ab.C_Activity_ID,0)
AND COALESCE(a.C_Campaign_ID,0)=COALESCE(ab.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(ab.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(ab.C_LocFrom_ID,0)
AND COALESCE(a.User1_ID,0)=COALESCE(ab.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(ab.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(ab.GL_Budget_ID,0)
GROUP BY AD_Client_ID,AD_Org_ID,
C_AcctSchema_ID, TRUNC(DateAcct),
Account_ID, PostingType,
M_Product_ID, C_BPartner_ID,
C_Project_ID, AD_OrgTrx_ID,
C_SalesRegion_ID, C_Activity_ID,
C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,
User1_ID, User2_ID, GL_Budget_ID);
DBMS_OUTPUT.PUT_LINE(' Updates=' || SQL%ROWCOUNT);
END IF;
/** Insert **/
INSERT INTO Fact_Acct_Balance ab
(AD_Client_ID, AD_Org_ID,
C_AcctSchema_ID, DateAcct,
Account_ID, PostingType,
M_Product_ID, C_BPartner_ID,
C_Project_ID, AD_OrgTrx_ID,
C_SalesRegion_ID,C_Activity_ID,
C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,
User1_ID, User2_ID, GL_Budget_ID,
AmtAcctDr, AmtAcctCr, Qty)
--
SELECT AD_Client_ID, AD_Org_ID,
C_AcctSchema_ID, TRUNC(DateAcct),
Account_ID, PostingType,
M_Product_ID, C_BPartner_ID,
C_Project_ID, AD_OrgTrx_ID,
C_SalesRegion_ID,C_Activity_ID,
C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,
User1_ID, User2_ID, GL_Budget_ID,
COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0)
FROM Fact_Acct a
WHERE NOT EXISTS
(SELECT *
FROM Fact_Acct_Balance x
WHERE a.AD_Client_ID=x.AD_Client_ID AND a.AD_Org_ID=x.AD_Org_ID
AND a.C_AcctSchema_ID=x.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(x.DateAcct)
AND a.Account_ID=x.Account_ID AND a.PostingType=x.PostingType
AND COALESCE(a.M_Product_ID,0)=COALESCE(x.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(x.C_BPartner_ID,0)
AND COALESCE(a.C_Project_ID,0)=COALESCE(x.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(x.AD_OrgTrx_ID,0)
AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(x.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(x.C_Activity_ID,0)
AND COALESCE(a.C_Campaign_ID,0)=COALESCE(x.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(x.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(x.C_LocFrom_ID,0)
AND COALESCE(a.User1_ID,0)=COALESCE(x.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(x.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(x.GL_Budget_ID,0) )
GROUP BY AD_Client_ID,AD_Org_ID,
C_AcctSchema_ID, TRUNC(DateAcct),
Account_ID, PostingType,
M_Product_ID, C_BPartner_ID,
C_Project_ID, AD_OrgTrx_ID,
C_SalesRegion_ID, C_Activity_ID,
C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,
User1_ID, User2_ID, GL_Budget_ID;
DBMS_OUTPUT.PUT_LINE(' Inserts=' || SQL%ROWCOUNT);
-----------------------
COMMIT;
END Fact_Acct_Balance_Update;
/

View File

@ -0,0 +1,374 @@
CREATE OR REPLACE PROCEDURE M_PriceList_Create
(
PInstance_ID IN NUMBER
)
AS
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: M_PriceList_Create.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Create Pricelist
* Description:
* Create PriceList by copying purchase prices (M_Product_PO)
* and applying product category discounts (M_CategoryDiscount)
************************************************************************/
-- Logistice
ResultStr VARCHAR2(2000);
Message VARCHAR2(2000) := '';
NoRate EXCEPTION;
-- Parameter
CURSOR Cur_Parameter (PInstance NUMBER) IS
SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
p_PriceList_Version_ID NUMBER;
p_DeleteOld CHAR(1) := 'N';
--
v_Currency_ID NUMBER;
v_Client_ID NUMBER;
v_Org_ID NUMBER;
v_UpdatedBy NUMBER;
v_StdPrecision NUMBER;
v_DiscountSchema_ID NUMBER;
v_PriceList_Version_Base_ID NUMBER;
--
v_NextNo NUMBER := 0;
-- Get PL Parameter
CURSOR Cur_DiscountLine (DiscountSchema_ID NUMBER) IS
SELECT *
FROM M_DiscountSchemaLine
WHERE M_DiscountSchema_ID=DiscountSchema_ID
AND IsActive='Y'
ORDER BY SeqNo;
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing');
ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
-- Get Parameters
ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (PInstance_ID) LOOP
p_PriceList_Version_ID := p.Record_ID;
IF (p.ParameterName = 'DeleteOld') THEN
p_DeleteOld := p.P_String;
DBMS_OUTPUT.PUT_LINE(' DeleteOld=' || p_DeleteOld);
ELSE
DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
END IF;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' PriceList_Version_ID=' || p_PriceList_Version_ID);
-- Checking Prerequisites
-- -- PO Prices must exists
ResultStr := 'CorrectingProductPO';
DBMS_OUTPUT.PUT_LINE(ResultStr);
UPDATE M_Product_PO
SET PriceList = 0
WHERE PriceList IS NULL;
UPDATE M_Product_PO
SET PriceLastPO = 0
WHERE PriceLastPO IS NULL;
UPDATE M_Product_PO
SET PricePO = PriceLastPO
WHERE (PricePO IS NULL OR PricePO = 0) AND PriceLastPO <> 0;
UPDATE M_Product_PO
SET PricePO = 0
WHERE PricePO IS NULL;
-- Set default current vendor
UPDATE M_Product_PO p
SET IsCurrentVendor = 'Y'
WHERE IsCurrentVendor = 'N'
AND NOT EXISTS
(SELECT pp.M_Product_ID FROM M_Product_PO pp
WHERE pp.M_Product_ID=p.M_Product_ID
GROUP BY pp.M_Product_ID HAVING COUNT(*) > 1);
COMMIT;
/**
* Make sure that we have only one active product
*/
ResultStr := 'CorrectingDuplicates';
DBMS_OUTPUT.PUT_LINE(ResultStr);
DECLARE
-- All duplicate products
CURSOR Cur_Duplicates IS
SELECT DISTINCT M_Product_ID
FROM M_Product_PO po
WHERE IsCurrentVendor='Y' AND IsActive='Y'
AND EXISTS ( SELECT M_Product_ID FROM M_Product_PO x
WHERE x.M_Product_ID=po.M_Product_ID
GROUP BY M_Product_ID HAVING COUNT(*) > 1 )
ORDER BY 1;
-- All vendors of Product - expensive first
CURSOR Cur_Vendors (Product_ID NUMBER) IS
SELECT M_Product_ID, C_BPartner_ID
FROM M_Product_PO
WHERE IsCurrentVendor='Y' AND IsActive='Y'
AND M_Product_ID=Product_ID
ORDER BY PriceList DESC;
--
Product_ID NUMBER;
BPartner_ID NUMBER;
BEGIN
FOR dupl IN Cur_Duplicates LOOP
OPEN Cur_Vendors (dupl.M_Product_ID);
FETCH Cur_Vendors INTO Product_ID, BPartner_ID; -- Leave First
LOOP
FETCH Cur_Vendors INTO Product_ID, BPartner_ID; -- Get Record ID
EXIT WHEN Cur_Vendors%NOTFOUND;
--
DBMS_OUTPUT.PUT_LINE(' Record: ' || Product_ID || ' / ' || BPartner_ID);
UPDATE M_Product_PO
SET IsCurrentVendor='N'
WHERE M_Product_ID=Product_ID AND C_BPartner_ID=BPartner_ID;
END LOOP;
CLOSE Cur_Vendors;
END LOOP;
COMMIT;
END;
/** Delete Old Data */
ResultStr := 'DeletingOld';
IF (p_DeleteOld = 'Y') THEN
DELETE M_ProductPrice
WHERE M_PriceList_Version_ID = p_PriceList_Version_ID;
Message := '@Deleted@=' || SQL%ROWCOUNT || ' - ';
DBMS_OUTPUT.PUT_LINE(Message);
END IF;
-- Get PriceList Info
ResultStr := 'GetPLInfo';
DBMS_OUTPUT.PUT_LINE(ResultStr);
SELECT p.C_Currency_ID, c.StdPrecision,
v.AD_Client_ID, v.AD_Org_ID, v.UpdatedBy,
v.M_DiscountSchema_ID, M_PriceList_Version_Base_ID
INTO v_Currency_ID, v_StdPrecision,
v_Client_ID, v_Org_ID, v_UpdatedBy,
v_DiscountSchema_ID, v_PriceList_Version_Base_ID
FROM M_PriceList p, M_PriceList_Version v, C_Currency c
WHERE p.M_PriceList_ID=v.M_PriceList_ID
AND p.C_Currency_ID=c.C_Currency_ID
AND v.M_PriceList_Version_ID=p_PriceList_Version_ID;
/**
* For All Discount Lines in Sequence
*/
FOR dl IN Cur_DiscountLine (v_DiscountSchema_ID) LOOP
ResultStr := 'Parameter Seq=' || dl.SeqNo;
-- DBMS_OUTPUT.PUT_LINE(ResultStr);
-- Clear Temporary Table
DELETE FROM T_Selection;
-- -----------------------------------
-- Create Selection in temporary table
-- -----------------------------------
IF (v_PriceList_Version_Base_ID IS NULL) THEN
-- Create Selection from M_Product_PO
INSERT INTO T_Selection (T_Selection_ID)
SELECT DISTINCT po.M_Product_ID
FROM M_Product p, M_Product_PO po
WHERE p.M_Product_ID=po.M_Product_ID
AND (p.AD_Client_ID=v_Client_ID OR p.AD_Client_ID=0)
AND p.IsActive='Y' AND po.IsActive='Y' AND po.IsCurrentVendor='Y'
-- Optional Restrictions
AND (dl.M_Product_Category_ID IS NULL OR p.M_Product_Category_ID=dl.M_Product_Category_ID)
AND (dl.C_BPartner_ID IS NULL OR po.C_BPartner_ID=dl.C_BPartner_ID)
AND (dl.M_Product_ID IS NULL OR p.M_Product_ID=dl.M_Product_ID);
ELSE
-- Create Selection from existing PriceList
INSERT INTO T_Selection (T_Selection_ID)
SELECT DISTINCT p.M_Product_ID
FROM M_Product p, M_ProductPrice pp
WHERE p.M_Product_ID=pp.M_Product_ID
AND pp.M_PriceList_Version_ID=v_PriceList_Version_Base_ID
AND p.IsActive='Y' AND pp.IsActive='Y'
-- Optional Restrictions
AND (dl.M_Product_Category_ID IS NULL OR p.M_Product_Category_ID=dl.M_Product_Category_ID)
AND (dl.C_BPartner_ID IS NULL OR EXISTS
(SELECT * FROM M_Product_PO po WHERE po.M_Product_ID=p.M_Product_ID AND po.C_BPartner_ID=dl.C_BPartner_ID))
AND (dl.M_Product_ID IS NULL OR p.M_Product_ID=dl.M_Product_ID);
END IF;
Message := Message || '@Selected@=' || SQL%ROWCOUNT;
-- DBMS_OUTPUT.PUT_LINE(Message);
-- Delete Prices in Selection, so that we can insert
IF (v_PriceList_Version_Base_ID IS NULL
OR v_PriceList_Version_Base_ID <> p_PriceList_Version_ID) THEN
ResultStr := ResultStr || ', Delete';
DELETE M_ProductPrice pp
WHERE pp.M_PriceList_Version_ID = p_PriceList_Version_ID
AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID);
Message := ', @Deleted@=' || SQL%ROWCOUNT;
END IF;
-- --------------------
-- Copy (Insert) Prices
-- --------------------
IF (v_PriceList_Version_Base_ID = p_PriceList_Version_ID) THEN
-- We have Prices already
NULL;
ELSIF (v_PriceList_Version_Base_ID IS NULL) THEN
-- Copy and Convert from Product_PO
ResultStr := ResultStr || ',Copy_PO';
INSERT INTO M_ProductPrice
(M_PriceList_Version_ID, M_Product_ID,
AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
PriceList, PriceStd, PriceLimit)
SELECT
p_PriceList_Version_ID, po.M_Product_ID,
v_Client_ID, v_Org_ID, 'Y', SysDate, v_UpdatedBy, SysDate, v_UpdatedBy,
-- Price List
COALESCE(currencyConvert(po.PriceList,
po.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0),
-- Price Std
COALESCE(currencyConvert(po.PriceList,
po.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0),
-- Price Limit
COALESCE(currencyConvert(po.PricePO,
po.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0)
FROM M_Product_PO po
WHERE EXISTS (SELECT * FROM T_Selection s WHERE po.M_Product_ID=s.T_Selection_ID)
AND po.IsCurrentVendor='Y' AND po.IsActive='Y';
ELSE
-- Copy and Convert from other PriceList_Version
ResultStr := ResultStr || ',Copy_PL';
INSERT INTO M_ProductPrice
(M_PriceList_Version_ID, M_Product_ID,
AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
PriceList, PriceStd, PriceLimit)
SELECT
p_PriceList_Version_ID, pp.M_Product_ID,
v_Client_ID, v_Org_ID, 'Y', SysDate, v_UpdatedBy, SysDate, v_UpdatedBy,
-- Price List
COALESCE(currencyConvert(pp.PriceList,
pl.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0),
-- Price Std
COALESCE(currencyConvert(pp.PriceStd,
pl.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0),
-- Price Limit
COALESCE(currencyConvert(pp.PriceLimit,
pl.C_Currency_ID, v_Currency_ID, dl.ConversionDate, dl.C_ConversionType_ID, v_Client_ID, v_Org_ID),0)
FROM M_ProductPrice pp
INNER JOIN M_PriceList_Version plv ON (pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID)
INNER JOIN M_PriceList pl ON (plv.M_PriceList_ID=pl.M_PriceList_ID)
WHERE pp.M_PriceList_Version_ID=v_PriceList_Version_Base_ID
AND EXISTS (SELECT * FROM T_Selection s WHERE pp.M_Product_ID=s.T_Selection_ID)
AND pp.IsActive='Y';
END IF;
Message := Message || ', @Inserted@=' || SQL%ROWCOUNT;
-- -----------
-- Calculation
-- -----------
ResultStr := ResultStr || ',Calc';
UPDATE M_ProductPrice p
SET PriceList = (DECODE(dl.List_Base, 'S', PriceStd, 'X', PriceLimit, PriceList)
+ dl.List_AddAmt) * (1 - dl.List_Discount/100),
PriceStd = (DECODE(dl.Std_Base, 'L', PriceList, 'X', PriceLimit, PriceStd)
+ dl.Std_AddAmt) * (1 - dl.Std_Discount/100),
PriceLimit = (DECODE(dl.Limit_Base, 'L', PriceList, 'S', PriceStd, PriceLimit)
+ dl.Limit_AddAmt) * (1 - dl.Limit_Discount/100)
WHERE M_PriceList_Version_ID=p_PriceList_Version_ID
AND EXISTS (SELECT * FROM T_Selection s
WHERE s.T_Selection_ID=p.M_Product_ID);
-- --------
-- Rounding (AD_Reference_ID=155)
-- --------
ResultStr := ResultStr || ',Round';
UPDATE M_ProductPrice p
SET PriceList = DECODE(dl.List_Rounding,
'N', PriceList,
'0', ROUND(PriceList, 0), -- Even .00
'D', ROUND(PriceList, 1), -- Dime .10
'T', ROUND(PriceList, -1), -- Ten 10.00
'5', ROUND(PriceList*20,0)/20, -- Nickle .05
'Q', ROUND(PriceList*4,0)/4, -- Quarter .25
ROUND(PriceList, v_StdPrecision)),-- Currency
PriceStd = DECODE(dl.Std_Rounding,
'N', PriceStd,
'0', ROUND(PriceStd, 0), -- Even .00
'D', ROUND(PriceStd, 1), -- Dime .10
'T', ROUND(PriceStd, -1), -- Ten 10.00
'5', ROUND(PriceStd*20,0)/20, -- Nickle .05
'Q', ROUND(PriceStd*4,0)/4, -- Quarter .25
ROUND(PriceStd, v_StdPrecision)), -- Currency
PriceLimit = DECODE(dl.Limit_Rounding,
'N', PriceLimit,
'0', ROUND(PriceLimit, 0), -- Even .00
'D', ROUND(PriceLimit, 1), -- Dime .10
'T', ROUND(PriceLimit, -1), -- Ten 10.00
'5', ROUND(PriceLimit*20,0)/20, -- Nickle .05
'Q', ROUND(PriceLimit*4,0)/4, -- Quarter .25
ROUND(PriceLimit, v_StdPrecision))-- Currency
WHERE M_PriceList_Version_ID=p_PriceList_Version_ID
AND EXISTS (SELECT * FROM T_Selection s
WHERE s.T_Selection_ID=p.M_Product_ID);
Message := Message || ', @Updated@=' || SQL%ROWCOUNT;
-- Fixed Price overwrite
ResultStr := ResultStr || ',Fix';
UPDATE M_ProductPrice p
SET PriceList = DECODE(dl.List_Base, 'F', dl.List_Fixed, PriceList),
PriceStd = DECODE(dl.Std_Base, 'F', dl.Std_Fixed, PriceStd),
PriceLimit = DECODE(dl.Limit_Base, 'F', dl.Limit_Fixed, PriceLimit)
WHERE M_PriceList_Version_ID=p_PriceList_Version_ID
AND EXISTS (SELECT * FROM T_Selection s
WHERE s.T_Selection_ID=p.M_Product_ID);
-- Log Info
INSERT INTO AD_PInstance_Log (AD_PInstance_ID, Log_ID, P_ID, P_NUMBER, P_MSG)
VALUES (PInstance_ID, v_NextNo, null, dl.SeqNo, Message);
--
v_NextNo := v_NextNo + 1;
Message := '';
END LOOP; -- For all DiscountLines
-- Delete Temporary Selection
DELETE FROM T_Selection;
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE(Message);
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished');
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 1, -- success
ErrorMsg = Message
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
ResultStr := ResultStr || ':' || SQLERRM || ' ' || Message;
DBMS_OUTPUT.PUT_LINE(ResultStr);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = ResultStr
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
END M_PriceList_Create;
/

View File

@ -0,0 +1,147 @@
CREATE OR REPLACE PROCEDURE M_Product_BOM_Check
(
PInstance_ID IN NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: M_Product_BOM_Check.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Check BOM Structure (free of cycles)
* Description:
* Tree cannot contain BOMs which are already referenced
************************************************************************/
AS
-- Logistice
ResultStr VARCHAR2(2000);
Message VARCHAR2(2000);
Record_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (PInstance NUMBER) IS
SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Variables
Verified CHAR(1) := 'Y';
IsBOM CHAR(1);
CountNo NUMBER;
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID);
ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
-- Get Parameters
ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (PInstance_ID) LOOP
Record_ID := p.Record_ID;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || Record_ID);
-- Record ID is M_Product_ID of product to be tested
SELECT IsBOM
INTO IsBOM
FROM M_Product
WHERE M_Product_ID=Record_ID;
-- No BOM - should not happen, but no problem
IF (IsBOM = 'N') THEN
GOTO FINISH_PROCESS;
-- Did not find product
ELSIF (IsBOM <> 'Y') THEN
RETURN;
END IF;
-- Checking BOM Structure
ResultStr := 'InsertingRoot';
-- Table to put all BOMs - duplicate will cause exception
DELETE FROM T_Selection2 WHERE Query_ID = 0;
INSERT INTO T_Selection2 (Query_ID, T_Selection_ID) VALUES (0, Record_ID);
-- Table of root modes
DELETE FROM T_Selection;
INSERT INTO T_Selection (T_Selection_ID) VALUES (Record_ID);
LOOP
-- How many do we have?
SELECT COUNT(*)
INTO CountNo
FROM T_Selection;
-- Nothing to do
EXIT WHEN (CountNo = 0);
-- Insert BOM Nodes into "All" table
INSERT INTO T_Selection2 (Query_ID, T_Selection_ID)
SELECT 0, p.M_Product_ID
FROM M_Product p
WHERE IsBOM='Y'
AND EXISTS (SELECT * FROM M_Product_BOM b WHERE p.M_Product_ID=b.M_ProductBOM_ID
AND b.M_Product_ID IN (SELECT T_Selection_ID FROM T_Selection));
-- Insert BOM Nodes into temporary table
DELETE FROM T_Selection2 WHERE Query_ID = 1;
INSERT INTO T_Selection2 (Query_ID, T_Selection_ID)
SELECT 1, p.M_Product_ID
FROM M_Product p
WHERE IsBOM='Y'
AND EXISTS (SELECT * FROM M_Product_BOM b WHERE p.M_Product_ID=b.M_ProductBOM_ID
AND b.M_Product_ID IN (SELECT T_Selection_ID FROM T_Selection));
-- Copy into root table
DELETE FROM T_Selection;
INSERT INTO T_Selection (T_Selection_ID)
SELECT T_Selection_ID
FROM T_Selection2
WHERE Query_ID = 1;
END LOOP;
<<FINISH_PROCESS>>
-- OK
Message := 'OK';
UPDATE M_Product
SET IsVerified = 'Y'
WHERE M_Product_ID=Record_ID;
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 1, -- success
ErrorMsg = Message
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
ResultStr := ResultStr || ': ' || SQLERRM || ' - ' || Message;
DBMS_OUTPUT.PUT_LINE(ResultStr);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = ResultStr
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
--
UPDATE M_Product
SET IsVerified = 'N'
WHERE M_Product_ID=Record_ID;
COMMIT;
--
RETURN;
END M_Product_BOM_Check;
/

View File

@ -0,0 +1,37 @@
CREATE OR REPLACE PROCEDURE M_Product_Delete
(
whereClause IN VARCHAR2 DEFAULT NULL
)
AS
/******************************************************************************
* ** Adempiere Product ** Copyright (c) 1999-2001 Accorto, Inc. USA
* Open Source Software Provided "AS IS" without warranty or liability
* When you use any parts (changed or unchanged), add "Powered by Adempiere" to
* your product name; See license details http://www.adempiere.org/license.html
******************************************************************************
* Delete Products
*/
CURSOR CUR_DEL IS
SELECT M_Product_ID, Value, Name
FROM M_Product
WHERE IsActive='N';
--
SQL_Base VARCHAR2(255) := 'SELECT M_Product_ID FROM M_Product WHERE ';
-- SQL_Where VARCHAR2(255) := 'ValueX IN (SELECT ValueX FROM M_Product GROUP BY ValueX HAVING Count(*) <> 1) AND INSTR(Value,''@'') <> 0';
SQL_Statement VARCHAR2(255);
BEGIN
-- Delete inactive
IF (whereClause IS NULL OR LENGTH(whereClause) = 0) THEN
For d IN CUR_DEL LOOP
BEGIN
DBMS_OUTPUT.PUT('Deleting ' || d.Name || ' - ');
DELETE M_Product
WHERE M_Product_ID=d.M_Product_ID;
DBMS_OUTPUT.PUT_LINE('OK');
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error ' || SQLERRM);
END;
END LOOP;
END IF;
END M_Product_Delete;
/

View File

@ -0,0 +1,298 @@
CREATE OR REPLACE PROCEDURE M_Production_Run
(
PInstance_ID IN NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: M_Production_Run.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Production of BOMs
* Description:
* 1) Creating ProductionLines when IsCreated = 'N'
* 2) Posting the Lines (optionally only when fully stocked)
************************************************************************/
AS
-- Logistice
ResultStr VARCHAR2(2000);
Message VARCHAR2(2000);
Record_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (PInstance NUMBER) IS
SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
MustBeStocked CHAR(1);
IsCreated CHAR(1);
Processed CHAR(1);
Client_ID NUMBER;
Org_ID NUMBER;
--
Line NUMBER;
NextNo NUMBER;
CountNo NUMBER;
-- ProductionPlan
CURSOR CUR_PP IS
SELECT *
FROM M_ProductionPlan
WHERE M_Production_ID=Record_ID
ORDER BY Line, M_Product_ID;
-- BOM Lines
CURSOR CUR_BOM (Product_ID NUMBER) IS
SELECT *
FROM M_Product_BOM
WHERE M_Product_ID=Product_ID
ORDER BY Line;
-- ProductionLines which are non-stocked BOMs (need to be resolved)
CURSOR CUR_PLineBOM (ProductionPlan_ID NUMBER) IS
SELECT pl.M_ProductionLine_ID, pl.Line, pl.M_Product_ID, pl.MovementQty
FROM M_ProductionLine pl, M_Product p
WHERE pl.M_ProductionPlan_ID=ProductionPlan_ID
AND pl.M_Product_ID=p.M_Product_ID
AND pl.Line<>100 -- Origin Line
AND p.IsBOM='Y' AND p.IsStocked='N';
-- Posting
CURSOR CUR_PL_Post IS
SELECT pl.M_ProductionLine_ID, pl.AD_Client_ID, pl.AD_Org_ID, p.MovementDate,
pl.M_Product_ID, pl.M_AttributeSetInstance_ID, pl.MovementQty, pl.M_Locator_ID
FROM M_Production p, M_ProductionLine pl, M_ProductionPlan pp
WHERE p.M_Production_ID=pp.M_Production_ID
AND pp.M_ProductionPlan_ID=pl.M_ProductionPlan_ID
AND pp.M_Production_ID=Record_ID
ORDER BY pp.Line, pl.Line;
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || PInstance_ID);
ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
-- Get Parameters
ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (PInstance_ID) LOOP
Record_ID := p.Record_ID;
IF (p.ParameterName = 'MustBeStocked') THEN
MustBeStocked := p.P_String;
DBMS_OUTPUT.PUT_LINE(' MustBeStocked=' || MustBeStocked);
ELSE
DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
END IF;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || Record_ID);
-- Processing??? Lock ????
-- TODO
/**
* Get Info + Lock
*/
ResultStr := 'ReadingRecord';
SELECT IsCreated, Processed, AD_Client_ID, AD_Org_ID
INTO IsCreated, Processed, Client_ID, Org_ID
FROM M_Production
WHERE M_Production_ID=Record_ID
FOR UPDATE;
/**
* No Action
*/
IF (Processed <> 'N') THEN
Message := '@AlreadyPosted@';
GOTO FINISH_PROCESS;
END IF;
/**************************************************************************
* Create Lines
*/
IF (IsCreated <> 'Y') THEN
-- For every Production Plan
FOR pp IN CUR_PP LOOP
-- Delete prior lines
DELETE M_ProductionLine
WHERE M_ProductionPlan_ID=pp.M_ProductionPlan_ID;
-- DBMS_OUTPUT.PUT_LINE('ProductionPlan=' || pp.M_ProductionPlan_ID);
-- Create BOM Line
ResultStr := 'CreatingLine BOM';
Line := 100; -- OriginLine
AD_Sequence_Next('M_ProductionLine', pp.AD_Client_ID, NextNo);
INSERT INTO M_ProductionLine
(M_ProductionLine_ID, M_ProductionPlan_ID, Line,
AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,
M_Product_ID, MovementQty, M_Locator_ID, Description)
VALUES
(NextNo, pp.M_ProductionPlan_ID, Line,
pp.AD_Client_ID,pp.AD_Org_ID,'Y',SysDate,0,SysDate,0,
pp.M_Product_ID, pp.ProductionQty, pp.M_Locator_ID, pp.Description);
-- Create First Level
FOR bom IN CUR_BOM (pp.M_Product_ID) LOOP
ResultStr := 'CreatingLine Products';
Line := Line + 100;
AD_Sequence_Next('M_ProductionLine', pp.AD_Client_ID, NextNo);
INSERT INTO M_ProductionLine
(M_ProductionLine_ID, M_ProductionPlan_ID, Line,
AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,
M_Product_ID, MovementQty, M_Locator_ID)
VALUES
(NextNo, pp.M_ProductionPlan_ID, Line,
pp.AD_Client_ID,pp.AD_Org_ID,'Y',SysDate,0,SysDate,0,
bom.M_ProductBOM_ID, -pp.ProductionQty*bom.BOMQty, pp.M_Locator_ID);
END LOOP;
-- While we have BOMs
LOOP
-- Are there non-stored BOMs to list details?
ResultStr := 'CreatingLine CheckBOM';
SELECT COUNT(*) INTO CountNo
FROM M_ProductionLine pl, M_Product p
WHERE pl.M_Product_ID=p.M_Product_ID
AND pl.M_ProductionPlan_ID=pp.M_ProductionPlan_ID
AND pl.Line<>100 -- Origin Line
AND p.IsBOM='Y' AND p.IsStocked='N';
-- Nothing to do
EXIT WHEN (CountNo = 0);
--
-- Resolve BOMs in ProductLine which are not stocked
FOR pl IN CUR_PLineBOM (pp.M_ProductionPlan_ID) LOOP
ResultStr := 'CreatingLineBOM Resolution';
Line := pl.Line;
-- Resolve BOM Line in product line
FOR bom IN CUR_BOM (pl.M_Product_ID) LOOP
ResultStr := 'CreatingLine Products2';
Line := Line + 10;
AD_Sequence_Next('M_ProductionLine', pp.AD_Client_ID, NextNo);
INSERT INTO M_ProductionLine
(M_ProductionLine_ID, M_ProductionPlan_ID, Line,
AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,
M_Product_ID, MovementQty, M_Locator_ID)
VALUES
(NextNo, pp.M_ProductionPlan_ID, Line,
pp.AD_Client_ID,pp.AD_Org_ID,'Y',SysDate,0,SysDate,0,
bom.M_ProductBOM_ID, pl.MovementQty*bom.BOMQty, pp.M_Locator_ID);
END LOOP;
-- Delete BOM line
DELETE M_ProductionLine
WHERE M_ProductionLine_ID=pl.M_ProductionLine_ID;
END LOOP;
END LOOP; -- While we have BOMs
END LOOP; -- For every Production Plan
-- Modifying locator to have sufficient stock
-- Indicate that it is Created
UPDATE M_Production
SET IsCreated='Y'
WHERE M_Production_ID=Record_ID;
/**************************************************************************
* Post Lines
*/
ELSE
-- All Production Lines
FOR pl IN CUR_PL_Post LOOP
-- M_ProductionLine_ID, AD_Client_ID, AD_Org_ID, MovementDate, M_Product_ID, MovementQty, M_Locator_ID
-- DBMS_OUTPUT.PUT_LINE('ProductionLine=' || pl.M_ProductionLine_ID);
-- DBMS_OUTPUT.PUT_LINE(' Qty=' || pl.MovementQty || ', OnHand=' || BOM_Qty_OnHand(pl.M_Product_ID, NULL, pl.M_Locator_ID));
-- Check Stock levels for reductions
IF (pl.MovementQty < 0 AND MustBeStocked <> 'N'
AND bomQtyOnHand(pl.M_Product_ID, NULL, pl.M_Locator_ID)+pl.MovementQty < 0) THEN
ROLLBACK;
SELECT '@NotEnoughStocked@: ' || Name INTO Message
FROM M_Product WHERE M_Product_ID=pl.M_Product_ID;
GOTO FINISH_PROCESS;
END IF;
-- Adjust Quantity at Location
UPDATE M_Storage
SET QtyOnHand = QtyOnHand + pl.MovementQty,
Updated = SysDate
WHERE M_Locator_ID = pl.M_Locator_ID
AND M_AttributeSetInstance_ID = COALESCE(pl.M_AttributeSetInstance_ID,0)
AND M_Product_ID = pl.M_Product_ID;
-- Product not on Stock yet
IF (SQL%ROWCOUNT = 0) THEN
INSERT INTO M_Storage
(M_Product_ID, M_Locator_ID, M_AttributeSetInstance_ID,
AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
QtyOnHand, QtyReserved, QtyOrdered)
VALUES
(pl.M_Product_ID, pl.M_Locator_ID, COALESCE(pl.M_AttributeSetInstance_ID,0),
pl.AD_Client_ID, pl.AD_Org_ID, 'Y', SysDate, 0, SysDate, 0,
pl.MovementQty, 0, 0);
END IF;
-- Create Transaction Entry
ResultStr := 'CreateTransaction';
AD_Sequence_Next('M_Transaction', pl.AD_Org_ID, NextNo);
INSERT INTO M_Transaction
(M_Transaction_ID, M_ProductionLine_ID,
AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
MovementType, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID,
MovementDate, MovementQty)
VALUES
(NextNo, pl.M_ProductionLine_ID,
pl.AD_Client_ID, pl.AD_Org_ID, 'Y', SysDate, 0, SysDate, 0,
'P+', pl.M_Locator_ID, pl.M_Product_ID, COALESCE(pl.M_AttributeSetInstance_ID,0), -- not distinguishing between assemby/disassembly
pl.MovementDate, pl.MovementQty);
--
UPDATE M_ProductionLine
SET Processed='Y'
WHERE M_ProductionLine_ID=pl.M_ProductionLine_ID;
END LOOP;
-- Indicate that we are done
UPDATE M_Production
SET Processed='Y'
WHERE M_Production_ID=Record_ID;
UPDATE M_ProductionPlan
SET Processed='Y'
WHERE M_Production_ID=Record_ID;
END IF;
-- Only commit when entire job successful
COMMIT;
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 1, -- success
ErrorMsg = Message
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
ResultStr := ResultStr || ': ' || SQLERRM || ' - ' || Message;
DBMS_OUTPUT.PUT_LINE(ResultStr);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = ResultStr
WHERE AD_PInstance_ID=PInstance_ID;
COMMIT;
RETURN;
END M_Production_Run;
/

View File

@ -0,0 +1,198 @@
CREATE OR REPLACE PROCEDURE T_InventoryValue_Create
(
p_PInstance_ID IN NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: T_InventoryValue_Create.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Inventory Valuation Temporary Table
* Description:
************************************************************************/
AS
-- Logistice
v_ResultStr VARCHAR2(2000);
v_Message VARCHAR2(2000);
v_Result NUMBER := 1; -- 0=failure
v_Record_ID NUMBER;
v_AD_User_ID NUMBER;
-- Parameter
CURSOR Cur_Parameter (pp_PInstance NUMBER) IS
SELECT i.Record_ID, i.AD_User_ID,
p.ParameterName, p.P_String, p.P_Number, p.P_Date
FROM AD_PInstance i, AD_PInstance_Para p
WHERE i.AD_PInstance_ID=pp_PInstance
AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
ORDER BY p.SeqNo;
-- Parameter Variables
p_M_PriceList_Version_ID NUMBER(10);
p_DateValue DATE;
p_M_Warehouse_ID NUMBER(10);
p_C_Currency_ID NUMBER(10);
BEGIN
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID);
v_ResultStr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SysDate,
IsProcessing = 'Y'
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
-- Get Parameters
v_ResultStr := 'ReadingParameters';
FOR p IN Cur_Parameter (p_PInstance_ID) LOOP
v_Record_ID := p.Record_ID;
v_AD_User_ID := p.AD_User_ID;
IF (p.ParameterName = 'M_PriceList_Version_ID') THEN
p_M_PriceList_Version_ID := p.P_Number;
DBMS_OUTPUT.PUT_LINE(' M_PriceList_Version_ID=' || p_M_PriceList_Version_ID);
ELSIF (p.ParameterName = 'DateValue') THEN
p_DateValue := p.P_Date;
DBMS_OUTPUT.PUT_LINE(' DateValue=' || p_DateValue);
ELSIF (p.ParameterName = 'M_Warehouse_ID') THEN
p_M_Warehouse_ID := p.P_Number;
DBMS_OUTPUT.PUT_LINE(' M_Warehouse_ID=' || p_M_Warehouse_ID);
ELSIF (p.ParameterName = 'C_Currency_ID') THEN
p_C_Currency_ID := p.P_Number;
DBMS_OUTPUT.PUT_LINE(' C_Currency_ID=' || p_C_Currency_ID);
ELSE
DBMS_OUTPUT.PUT_LINE('*** Unknown Parameter=' || p.ParameterName);
END IF;
END LOOP; -- Get Parameter
DBMS_OUTPUT.PUT_LINE(' Record_ID=' || v_Record_ID);
-- Clear
-- v_ResultStr := 'ClearTable';
-- DELETE T_InventoryValue WHERE M_Warehouse_ID=p_M_Warehouse_ID;
-- COMMIT;
-- Insert Products
v_ResultStr := 'InsertStockedProducts';
INSERT INTO T_InventoryValue
(AD_Client_ID,AD_Org_ID, AD_PInstance_ID, M_Warehouse_ID,M_Product_ID)
SELECT AD_Client_ID,AD_Org_ID, p_PInstance_ID, p_M_Warehouse_ID,M_Product_ID
FROM M_Product
WHERE IsStocked='Y';
--
IF (SQL%ROWCOUNT = 0) THEN
v_Message := '@Created@ = 0';
GOTO FINISH_PROCESS;
END IF;
-- Update Constants
v_ResultStr := 'UpdateConstants';
UPDATE T_InventoryValue
SET DateValue = TRUNC(p_DateValue) + 0.9993,
M_PriceList_Version_ID = p_M_PriceList_Version_ID,
C_Currency_ID = p_C_Currency_ID
WHERE M_Warehouse_ID = p_M_Warehouse_ID;
-- Get current QtyOnHand
v_ResultStr := 'GetQtyOnHand';
UPDATE T_InventoryValue iv
SET QtyOnHand = (SELECT SUM(QtyOnHand) FROM M_Storage s, M_Locator l
WHERE iv.M_Product_ID=s.M_Product_ID
AND l.M_Locator_ID=s.M_Locator_ID
AND l.M_Warehouse_ID=iv.M_Warehouse_ID)
WHERE iv.M_Warehouse_ID = p_M_Warehouse_ID;
-- Adjust for Valuation Date
v_ResultStr := 'AdjustQtyOnHand';
UPDATE T_InventoryValue iv
SET QtyOnHand =
(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0)
FROM M_Transaction t, M_Locator l
WHERE t.M_Product_ID=iv.M_Product_ID
-- AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID
AND t.MovementDate > iv.DateValue
AND t.M_Locator_ID=l.M_Locator_ID
AND l.M_Warehouse_ID=iv.M_Warehouse_ID)
WHERE iv.M_Warehouse_ID = p_M_Warehouse_ID;
-- Delete Records w/o OnHand Qty
v_ResultStr := 'DeleteZeroQtyOnHand';
DELETE T_InventoryValue
WHERE QtyOnHand=0
OR QtyOnHand IS NULL;
-- Update Prices
v_ResultStr := 'GetPrices';
UPDATE T_InventoryValue iv
SET PricePO =
(SELECT currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue, null, iv.AD_Client_ID, iv.AD_Org_ID)
FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID
AND po.IsCurrentVendor='Y' AND RowNum=1),
PriceList =
(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue, null, iv.AD_Client_ID, iv.AD_Org_ID)
FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp
WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID
AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID
AND plv.M_PriceList_ID=pl.M_PriceList_ID),
PriceStd =
(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue, null, iv.AD_Client_ID, iv.AD_Org_ID)
FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp
WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID
AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID
AND plv.M_PriceList_ID=pl.M_PriceList_ID),
PriceLimit =
(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue, null, iv.AD_Client_ID, iv.AD_Org_ID)
FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp
WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID
AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID
AND plv.M_PriceList_ID=pl.M_PriceList_ID),
CostStandard =
(SELECT currencyConvert(pc.CurrentCostPrice,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue, null, iv.AD_Client_ID, iv.AD_Org_ID)
FROM AD_ClientInfo ci, C_AcctSchema acs, M_Product_Costing pc
WHERE iv.AD_Client_ID=ci.AD_Client_ID AND ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID
AND acs.C_AcctSchema_ID=pc.C_AcctSchema_ID
AND iv.M_Product_ID=pc.M_Product_ID)
WHERE iv.M_Warehouse_ID = p_M_Warehouse_ID;
-- Update Values
v_ResultStr := 'UpdateValue';
UPDATE T_InventoryValue
SET PricePOAmt = QtyOnHand * PricePO,
PriceListAmt = QtyOnHand * PriceList,
PriceStdAmt = QtyOnHand * PriceStd,
PriceLimitAmt = QtyOnHand * PriceLimit,
CostStandardAmt = QtyOnHand * CostStandard
WHERE M_Warehouse_ID = p_M_Warehouse_ID;
v_Message := '@Created@ = ' || SQL%ROWCOUNT;
<<FINISH_PROCESS>>
-- Update AD_PInstance
DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message);
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = v_Result, -- 1=success
ErrorMsg = v_Message
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
RETURN;
EXCEPTION
WHEN OTHERS THEN
v_ResultStr := v_ResultStr || ': ' || SQLERRM || ' - ' || v_Message;
DBMS_OUTPUT.PUT_LINE(v_ResultStr);
ROLLBACK;
UPDATE AD_PInstance
SET Updated = SysDate,
IsProcessing = 'N',
Result = 0, -- failure
ErrorMsg = v_ResultStr
WHERE AD_PInstance_ID=p_PInstance_ID;
COMMIT;
RETURN;
END T_InventoryValue_Create;
/

View File

@ -0,0 +1,55 @@
CREATE OR REPLACE PROCEDURE nextID
(
p_AD_Sequence_ID IN NUMBER,
p_System IN CHAR,
o_NextID OUT NUMBER
)
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2005 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: nextID.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Get Next ID - no Commit
* Description:
* Test via
DECLARE
v_NextID NUMBER;
BEGIN
nextID(2, 'Y', v_NextID);
DBMS_OUTPUT.PUT_LINE(v_NextID);
END;
*
************************************************************************/
AS
BEGIN
IF (p_System = 'Y') THEN
SELECT CurrentNextSys
INTO o_NextID
FROM AD_Sequence
WHERE AD_Sequence_ID=p_AD_Sequence_ID
FOR UPDATE OF CurrentNextSys;
--
UPDATE AD_Sequence
SET CurrentNextSys = CurrentNextSys + IncrementNo
WHERE AD_Sequence_ID=p_AD_Sequence_ID;
ELSE
SELECT CurrentNext
INTO o_NextID
FROM AD_Sequence
WHERE AD_Sequence_ID=p_AD_Sequence_ID
FOR UPDATE OF CurrentNext;
--
UPDATE AD_Sequence
SET CurrentNext = CurrentNext + IncrementNo
WHERE AD_Sequence_ID=p_AD_Sequence_ID;
END IF;
--
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END nextID;
/

View File

@ -0,0 +1,107 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AfterImport.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: After Import
* Description:
* - General Info
* - Create Context
* - Check Imported User and list ivalid objects
* You can ignore import warnings as long as this does not
* return error messages or records.
************************************************************************/
SELECT 'DB_Name=' || SYS_CONTEXT('USERENV', 'DB_NAME')
|| ', Language=' || SYS_CONTEXT('USERENV', 'LANGUAGE')
|| ', Host=' || SYS_CONTEXT('USERENV', 'HOST')
|| ', IP=' || SYS_CONTEXT('USERENV', 'IP_ADDRESS')
|| ', User=' || SYS_CONTEXT('USERENV', 'CURRENT_USER')
|| ', ID=' || SYS_CONTEXT('USERENV', 'CURRENT_USERID')
|| ', Session=' || SYS_CONTEXT('USERENV', 'SESSIONID')
AS "DBInfo"
FROM DUAL
/
SET serveroutput ON
-- Recompile invalids
BEGIN
DBA_Cleanup();
DBA_AfterImport;
-- DBA_Recompile(NULL); -- called in DBA_AfterImport
END;
/
-- Correct DataFile sizing
DECLARE
CURSOR Cur_TS IS
SELECT FILE_NAME, Tablespace_Name, Bytes/1024/1024 as MB
FROM DBA_DATA_FILES
WHERE (TABLESPACE_NAME='USERS' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='INDX' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='TEMP' AND BYTES < 100*1024*1024);
v_CMD VARCHAR2(300);
BEGIN
FOR ts IN Cur_TS LOOP
DBMS_OUTPUT.PUT_LINE('Resize:');
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' RESIZE 100M';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
END LOOP;
END;
/
/** Database Sizing
** Oracle 10g should use Automatic Shared Memory Management - here how to set it to 200MB:
** Example 300MB
SELECT Name, Value, Description, IsDefault FROM v$parameter WHERE Name LIKE '%sga%'
/
ALTER SYSTEM SET sga_target = 314572800 Comment='Adempiere' SCOPE=BOTH
/
ALTER SYSTEM SET statistics_level = TYPICAL Comment='Adempiere' SCOPE=BOTH
/
SELECT Name, Value/1024/1024 "MB", Description, IsDefault, Update_Comment
FROM v$parameter WHERE Name LIKE '%_pool_size' OR Name LIKE 'sga%'
/
ALTER SYSTEM SET open_cursors = 600 Comment='Adempiere' SCOPE=BOTH
/
/** Oracle 9i needs to set explicitly (and restart)
** Example 300MB
ALTER SYSTEM SET sga_max_size=314572800 SCOPE=SPFILE
/
ALTER SYSTEM SET large_pool_size=33554432 SCOPE=SPFILE
/
ALTER SYSTEM SET java_pool_size=67108864 SCOPE=SPFILE
/
/** SELECT 32*1024*1024 FROM DUAL **/
-- Any invalids
SELECT Object_Type "Type", Object_Name "Invalid", Status
FROM User_Objects
WHERE Status <> 'VALID'
/
-- Trigger Info
SELECT Trigger_Name AS Trigger_NotEnabled, Status
FROM User_Triggers
WHERE Status != 'ENABLED'
/
-- Constraint Info
SELECT Constraint_Name AS Constraint_Problem, Status, Validated, Table_Name, Search_Condition, R_Constraint_Name
FROM User_Constraints
WHERE Status <> 'ENABLED' OR Validated <> 'VALIDATED'
/
SELECT *
FROM USER_ERRORS
/
COMMIT
/
EXIT

View File

@ -0,0 +1,94 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BackupCold.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Cold Backup
* Description:
* Generate OS cold Backup script
* Change the parameter variables p_ as required
* Run as system
************************************************************************/
SPOOL BackupCold.bat
DECLARE
p_backupLocation VARCHAR2(255) := 'D:\Backup';
p_unix BOOLEAN := FALSE;
p_useZip BOOLEAN := TRUE;
p_zipCmd VARCHAR(60) := 'wzzip ';
--
v_delimiter VARCHAR(10);
v_remark VARCHAR(10);
v_copy VARCHAR(60);
v_sid VARCHAR(30);
v_cmd VARCHAR2(2000);
--
CURSOR CUR_DataFiles IS
SELECT Name
FROM v$datafile;
CURSOR CUR_CtlFiles IS
SELECT Name
FROM v$controlfile;
BEGIN
-- OS Specifics
IF (p_unix) THEN
v_delimiter := '/';
v_remark := '# ';
v_copy := 'cp ';
ELSE
v_delimiter := '\';
v_remark := 'Rem ';
v_copy := 'copy ';
END IF;
--
SELECT Value
INTO v_sid
FROM v$parameter
WHERE Name ='instance_name';
p_backupLocation := p_backupLocation || v_delimiter || v_sid;
--
DBMS_OUTPUT.PUT_LINE(v_remark || 'Backup script for "' || v_sid || '" to ' || p_backupLocation);
DBMS_OUTPUT.PUT_LINE(v_remark || 'This script is automatically created by ColdBackup.sql and may need to be edited';
DBMS_OUTPUT.NEW_LINE;
--
DBMS_OUTPUT.PUT_LINE(v_remark || 'mkdir ' || p_backupLocation);
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE('sqlplus "system/manager@%AccortoDBService% AS SYSDBA" @%AccortoHome%\util\orastop.sql');
DBMS_OUTPUT.NEW_LINE;
IF (p_useZip) THEN
DBMS_OUTPUT.PUT_LINE(p_zipCmd || p_backupLocation || v_delimiter || v_sid || '.zip ');
DBMS_OUTPUT.PUT(' ');
END IF;
FOR f IN CUR_DataFiles LOOP
IF (p_useZip) THEN
DBMS_OUTPUT.PUT(' ' || f.Name);
ELSE
DBMS_OUTPUT.PUT_LINE(v_copy || f.Name || ' ' || p_backupLocation);
END IF;
END LOOP;
IF (p_useZip) THEN
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT(' ');
END IF;
FOR f IN CUR_CtlFiles LOOP
IF (p_useZip) THEN
DBMS_OUTPUT.PUT(' ' || f.Name);
ELSE
DBMS_OUTPUT.PUT_LINE(v_copy || f.Name || ' ' || p_backupLocation);
END IF;
END LOOP;
IF (p_useZip) THEN
DBMS_OUTPUT.NEW_LINE;
END IF;
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE('sqlplus "system/manager@%AccortoDBService% AS SYSDBA" @%AccortoHome%\util\orastart.sql');
END;
/
SPOOL OFF
EXIT

View File

@ -0,0 +1,21 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BeforeExport.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Before Export
* Description:
* - Delete Temporary Data
************************************************************************/
DELETE T_Report
/
DELETE T_Replenish
/
DELETE T_Spool
/
EXIT

View File

@ -0,0 +1,93 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CheckDB.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: TabeSpace Sizing
* Description:
* Make sure, that Tablespace
* USERS is 150 MB, 10 MB Autoextend
* INDX is 100 MB, 10 MB Autoextend
* TEMP is 100 MB, 10 MB Autoextend
* Set SGA Size (optional)
* Executed with System user and parameter %ADEMPIERE_DB_USER% from RUN_Env
************************************************************************/
-- Check existance
SELECT 'Tablespace USERS does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='USERS');
SELECT 'Tablespace INDX does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='INDX');
SELECT 'Tablespace TEMP does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='TEMP');
/*****
* Changing System Parameters
* directly - (e.g. 400 MB for 10 Users)
ALTER SYSTEM SET SGA_MAX_SIZE=400M COMMENT='400MB' SCOPE=SPFILE;
ALTER SYSTEM SET SHARED_POOL_SIZE=100M SCOPE=SPFILE;
ALTER SYSTEM SET DB_CACHE_SIZE=200M SCOPE=SPFILE;
ALTER SYSTEM SET JAVA_POOL_SIZE=40M SCOPE=SPFILE;
ALTER SYSTEM SET LARGE_POOL_SIZE=10M SCOPE=SPFILE;
** indirectly - sqlplus "system/manager@adempiere AS SYSDBA"
CREATE PFile='pfileAdempiere.ora' FROM SPFile;
* creates file in $ORACLE_HOME\database or $ORACLE_HOME/dbs
* edit file and then overwrite the fila via
CREATE SPFile FROM PFile='pfileAdempiere.ora';
*****/
-- Create System Record - OK, if it fails
-- Schema is parameter.
INSERT INTO &1..AD_System
(AD_System_ID,AD_Client_ID,AD_Org_ID,
IsActive,Created,CreatedBy,Updated,UpdatedBy,
Name, UserName, Info)
SELECT 0,0,0,'Y', SysDate,0,SysDate,0, '?','?','?'
FROM Dual
WHERE NOT EXISTS
(SELECT * FROM &1..AD_System WHERE AD_System_ID=0);
-- Add Info - OK, if fails
UPDATE &1..AD_System
SET Info = (SELECT SYS_CONTEXT('USERENV', 'DB_DOMAIN')
|| ',' || SYS_CONTEXT('USERENV', 'DB_NAME')
|| ',IP=' || SYS_CONTEXT('USERENV', 'IP_ADDRESS')
|| ',' || SYS_CONTEXT('USERENV', 'HOST')
|| ',' || SYS_CONTEXT('USERENV', 'INSTANCE')
|| ',UID=' || SYS_CONTEXT('USERENV', 'CURRENT_USER')
|| ',' || SYS_CONTEXT('USERENV', 'CURRENT_USERID')
|| ',C#=' || (SELECT COUNT(*) FROM &1..AD_Client)
FROM DUAL),
Updated=SysDate;
COMMIT;
set serveroutput on
-- Correct sizing
DECLARE
CURSOR Cur_TS IS
SELECT FILE_NAME, Tablespace_Name, Bytes/1024/1024 as MB
FROM DBA_DATA_FILES
WHERE (TABLESPACE_NAME='USERS' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='INDX' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='TEMP' AND BYTES < 100*1024*1024);
v_CMD VARCHAR2(300);
BEGIN
DBMS_OUTPUT.PUT_LINE('Resize:');
FOR ts IN Cur_TS LOOP
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' RESIZE 100M';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
END LOOP;
END;
/
EXIT

View File

@ -0,0 +1,36 @@
SET ECHO ON
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CreateUser.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Drop User and re-create new
* Description:
* Parameter: UserID UserPwd
* Run as system
************************************************************************/
DROP USER &1 CASCADE
/
CREATE USER &1 IDENTIFIED BY &2
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK
/
GRANT CONNECT TO &1
/
GRANT DBA TO &1
/
GRANT RESOURCE TO &1
/
GRANT UNLIMITED TABLESPACE TO &1
/
ALTER USER &1 DEFAULT ROLE CONNECT, RESOURCE, DBA
/
GRANT CREATE TABLE TO &1
/
EXIT

View File

@ -0,0 +1,23 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Daily.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Daily Tasks
* Description:
* - Recompile
* - Cleanup
************************************************************************/
DECLARE
Result VARCHAR2(2000);
BEGIN
DBA_Recompile(Result);
DBMS_OUTPUT.PUT_LINE(Result);
DBA_Cleanup();
END;
/
EXIT

View File

@ -0,0 +1,18 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Start.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Start Database
* Description:
* Start the script via
* sqlplus "system/$ADEMPIERE_DB_SYSTEM AS SYSDBA" @$ADEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/Start.sql
************************************************************************/
set pause off
set echo on
startup
exit

View File

@ -0,0 +1,19 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Stop.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Stop Database and save configuration in trace
* Description:
* Start the script via
* sqlplus "system/$ADEMPIERE_DB_SYSTEM AS SYSDBA" @$ADEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/Stop.sql
************************************************************************/
set pause off
set echo on
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
shutdown transactional
exit

View File

@ -0,0 +1,4 @@
-- Connection Test
SELECT 'Success ' AS Connection FROM SYSIBM.SYSDUMMY1;

View File

@ -0,0 +1,112 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: AfterImport.sql,v 1.2 2006/05/28 22:52:07 jjanke Exp $
***
* Title: After Import
* Description:
* - General Info
* - Create Context
* - Check Imported User and list ivalid objects
* You can ignore import warnings as long as this does not
* return error messages or records.
************************************************************************/
SELECT 'DB_Name=' || SYS_CONTEXT('USERENV', 'DB_NAME')
|| ', Language=' || SYS_CONTEXT('USERENV', 'LANGUAGE')
|| ', Host=' || SYS_CONTEXT('USERENV', 'HOST')
|| ', IP=' || SYS_CONTEXT('USERENV', 'IP_ADDRESS')
|| ', User=' || SYS_CONTEXT('USERENV', 'CURRENT_USER')
|| ', ID=' || SYS_CONTEXT('USERENV', 'CURRENT_USERID')
|| ', Session=' || SYS_CONTEXT('USERENV', 'SESSIONID')
AS "DBInfo"
FROM DUAL
/
SET serveroutput ON
-- Recompile invalids
BEGIN
DBA_Cleanup();
DBA_AfterImport;
-- DBA_Recompile(NULL); -- called in DBA_AfterImport
END;
/
-- Correct DataFile sizing
DECLARE
CURSOR Cur_TS IS
SELECT FILE_NAME, Tablespace_Name, Bytes/1024/1024 as MB
FROM DBA_DATA_FILES
WHERE (TABLESPACE_NAME='USERS' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='INDX' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='TEMP' AND BYTES < 100*1024*1024);
v_CMD VARCHAR2(300);
BEGIN
FOR ts IN Cur_TS LOOP
DBMS_OUTPUT.PUT_LINE('Resize:');
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' RESIZE 100M';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
END LOOP;
END;
/
/** Database Sizing
** Oracle 10g should use Automatic Shared Memory Management -
** Example 300MB
*
* ALTER SYSTEM documentation
http://download-east.oracle.com/docs/cd/B14117_01/server.101/b10759/statements_2013.htm#SQLRF00902
*
SELECT Name, Value, Description, IsDefault FROM v$parameter
WHERE Name LIKE '%cursor%' OR Name LIKE '%process%' OR NAME LIKE '%servers%' ORDER BY 1
/
SELECT Name, Value/1024/1024 "MB", Description, IsDefault, Update_Comment FROM v$parameter
WHERE Name LIKE '%_pool_size' OR Name LIKE 'sga%'
/
ALTER SYSTEM SET statistics_level = TYPICAL Comment='Adempiere' SCOPE=BOTH
/
ALTER SYSTEM SET sga_target = 314572800 Comment='Adempiere' SCOPE=BOTH
/
ALTER SYSTEM SET open_cursors = 900 Comment='Adempiere' SCOPE=BOTH
/
/** Oracle 9i needs to set explicitly (and restart)
** Example 300MB
ALTER SYSTEM SET sga_max_size=314572800 SCOPE=SPFILE
/
ALTER SYSTEM SET large_pool_size=33554432 SCOPE=SPFILE
/
ALTER SYSTEM SET java_pool_size=67108864 SCOPE=SPFILE
/
/** SELECT 32*1024*1024 FROM DUAL **/
-- Any invalids
SELECT Object_Type "Type", Object_Name "Invalid", Status
FROM User_Objects
WHERE Status <> 'VALID'
/
-- Trigger Info
SELECT Trigger_Name AS Trigger_NotEnabled, Status
FROM User_Triggers
WHERE Status != 'ENABLED'
/
-- Constraint Info
SELECT Constraint_Name AS Constraint_Problem, Status, Validated, Table_Name, Search_Condition, R_Constraint_Name
FROM User_Constraints
WHERE Status <> 'ENABLED' OR Validated <> 'VALIDATED'
/
SELECT *
FROM USER_ERRORS
/
COMMIT
/
EXIT

View File

@ -0,0 +1,94 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BackupCold.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Cold Backup
* Description:
* Generate OS cold Backup script
* Change the parameter variables p_ as required
* Run as system
************************************************************************/
SPOOL BackupCold.bat
DECLARE
p_backupLocation VARCHAR2(255) := 'D:\Backup';
p_unix BOOLEAN := FALSE;
p_useZip BOOLEAN := TRUE;
p_zipCmd VARCHAR(60) := 'wzzip ';
--
v_delimiter VARCHAR(10);
v_remark VARCHAR(10);
v_copy VARCHAR(60);
v_sid VARCHAR(30);
v_cmd VARCHAR2(2000);
--
CURSOR CUR_DataFiles IS
SELECT Name
FROM v$datafile;
CURSOR CUR_CtlFiles IS
SELECT Name
FROM v$controlfile;
BEGIN
-- OS Specifics
IF (p_unix) THEN
v_delimiter := '/';
v_remark := '# ';
v_copy := 'cp ';
ELSE
v_delimiter := '\';
v_remark := 'Rem ';
v_copy := 'copy ';
END IF;
--
SELECT Value
INTO v_sid
FROM v$parameter
WHERE Name ='instance_name';
p_backupLocation := p_backupLocation || v_delimiter || v_sid;
--
DBMS_OUTPUT.PUT_LINE(v_remark || 'Backup script for "' || v_sid || '" to ' || p_backupLocation);
DBMS_OUTPUT.PUT_LINE(v_remark || 'This script is automatically created by ColdBackup.sql and may need to be edited';
DBMS_OUTPUT.NEW_LINE;
--
DBMS_OUTPUT.PUT_LINE(v_remark || 'mkdir ' || p_backupLocation);
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE('sqlplus "system/manager@%AccortoDBService% AS SYSDBA" @%AccortoHome%\util\orastop.sql');
DBMS_OUTPUT.NEW_LINE;
IF (p_useZip) THEN
DBMS_OUTPUT.PUT_LINE(p_zipCmd || p_backupLocation || v_delimiter || v_sid || '.zip ');
DBMS_OUTPUT.PUT(' ');
END IF;
FOR f IN CUR_DataFiles LOOP
IF (p_useZip) THEN
DBMS_OUTPUT.PUT(' ' || f.Name);
ELSE
DBMS_OUTPUT.PUT_LINE(v_copy || f.Name || ' ' || p_backupLocation);
END IF;
END LOOP;
IF (p_useZip) THEN
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT(' ');
END IF;
FOR f IN CUR_CtlFiles LOOP
IF (p_useZip) THEN
DBMS_OUTPUT.PUT(' ' || f.Name);
ELSE
DBMS_OUTPUT.PUT_LINE(v_copy || f.Name || ' ' || p_backupLocation);
END IF;
END LOOP;
IF (p_useZip) THEN
DBMS_OUTPUT.NEW_LINE;
END IF;
DBMS_OUTPUT.NEW_LINE;
DBMS_OUTPUT.PUT_LINE('sqlplus "system/manager@%AccortoDBService% AS SYSDBA" @%AccortoHome%\util\orastart.sql');
END;
/
SPOOL OFF
EXIT

View File

@ -0,0 +1,21 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: BeforeExport.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Before Export
* Description:
* - Delete Temporary Data
************************************************************************/
DELETE T_Report
/
DELETE T_Replenish
/
DELETE T_Spool
/
EXIT

View File

@ -0,0 +1,93 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CheckDB.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: TabeSpace Sizing
* Description:
* Make sure, that Tablespace
* USERS is 150 MB, 10 MB Autoextend
* INDX is 100 MB, 10 MB Autoextend
* TEMP is 100 MB, 10 MB Autoextend
* Set SGA Size (optional)
* Executed with System user and parameter %ADEMPIERE_DB_USER% from RUN_Env
************************************************************************/
-- Check existance
SELECT 'Tablespace USERS does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='USERS');
SELECT 'Tablespace INDX does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='INDX');
SELECT 'Tablespace TEMP does not exist - You need to create it first' AS Missing FROM DUAL
WHERE NOT EXISTS (SELECT * FROM DBA_TABLESPACES WHERE TABLESPACE_NAME='TEMP');
/*****
* Changing System Parameters
* directly - (e.g. 400 MB for 10 Users)
ALTER SYSTEM SET SGA_MAX_SIZE=400M COMMENT='400MB' SCOPE=SPFILE;
ALTER SYSTEM SET SHARED_POOL_SIZE=100M SCOPE=SPFILE;
ALTER SYSTEM SET DB_CACHE_SIZE=200M SCOPE=SPFILE;
ALTER SYSTEM SET JAVA_POOL_SIZE=40M SCOPE=SPFILE;
ALTER SYSTEM SET LARGE_POOL_SIZE=10M SCOPE=SPFILE;
** indirectly - sqlplus "system/manager@adempiere AS SYSDBA"
CREATE PFile='pfileAdempiere.ora' FROM SPFile;
* creates file in $ORACLE_HOME\database or $ORACLE_HOME/dbs
* edit file and then overwrite the fila via
CREATE SPFile FROM PFile='pfileAdempiere.ora';
*****/
-- Create System Record - OK, if it fails
-- Schema is parameter.
INSERT INTO &1..AD_System
(AD_System_ID,AD_Client_ID,AD_Org_ID,
IsActive,Created,CreatedBy,Updated,UpdatedBy,
Name, UserName, Info)
SELECT 0,0,0,'Y', SysDate,0,SysDate,0, '?','?','?'
FROM Dual
WHERE NOT EXISTS
(SELECT * FROM &1..AD_System WHERE AD_System_ID=0);
-- Add Info - OK, if fails
UPDATE &1..AD_System
SET Info = (SELECT SYS_CONTEXT('USERENV', 'DB_DOMAIN')
|| ',' || SYS_CONTEXT('USERENV', 'DB_NAME')
|| ',IP=' || SYS_CONTEXT('USERENV', 'IP_ADDRESS')
|| ',' || SYS_CONTEXT('USERENV', 'HOST')
|| ',' || SYS_CONTEXT('USERENV', 'INSTANCE')
|| ',UID=' || SYS_CONTEXT('USERENV', 'CURRENT_USER')
|| ',' || SYS_CONTEXT('USERENV', 'CURRENT_USERID')
|| ',C#=' || (SELECT COUNT(*) FROM &1..AD_Client)
FROM DUAL),
Updated=SysDate;
COMMIT;
set serveroutput on
-- Correct sizing
DECLARE
CURSOR Cur_TS IS
SELECT FILE_NAME, Tablespace_Name, Bytes/1024/1024 as MB
FROM DBA_DATA_FILES
WHERE (TABLESPACE_NAME='USERS' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='INDX' AND BYTES < 100*1024*1024)
OR (TABLESPACE_NAME='TEMP' AND BYTES < 100*1024*1024);
v_CMD VARCHAR2(300);
BEGIN
DBMS_OUTPUT.PUT_LINE('Resize:');
FOR ts IN Cur_TS LOOP
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' RESIZE 100M';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
v_CMD := 'ALTER DATABASE DATAFILE ''' || ts.FILE_NAME
|| ''' AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED';
DBMS_OUTPUT.PUT_LINE(' executing: ' || v_CMD);
EXECUTE IMMEDIATE v_CMD;
END LOOP;
END;
/
EXIT

View File

@ -0,0 +1,36 @@
SET ECHO ON
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: CreateUser.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Drop User and re-create new
* Description:
* Parameter: UserID UserPwd
* Run as system
************************************************************************/
DROP USER &1 CASCADE
/
CREATE USER &1 IDENTIFIED BY &2
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP
PROFILE DEFAULT
ACCOUNT UNLOCK
/
GRANT CONNECT TO &1
/
GRANT DBA TO &1
/
GRANT RESOURCE TO &1
/
GRANT UNLIMITED TABLESPACE TO &1
/
ALTER USER &1 DEFAULT ROLE CONNECT, RESOURCE, DBA
/
GRANT CREATE TABLE TO &1
/
EXIT

View File

@ -0,0 +1,23 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Daily.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Daily Tasks
* Description:
* - Recompile
* - Cleanup
************************************************************************/
DECLARE
Result VARCHAR2(2000);
BEGIN
DBA_Recompile(Result);
DBMS_OUTPUT.PUT_LINE(Result);
DBA_Cleanup();
END;
/
EXIT

View File

@ -0,0 +1,18 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Start.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Start Database
* Description:
* Start the script via
* sqlplus "system/$ADEMPIERE_DB_SYSTEM AS SYSDBA" @$ADEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/Start.sql
************************************************************************/
set pause off
set echo on
startup
exit

View File

@ -0,0 +1,19 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2003 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: Stop.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Stop Database and save configuration in trace
* Description:
* Start the script via
* sqlplus "system/$ADEMPIERE_DB_SYSTEM AS SYSDBA" @$ADEMPIERE_HOME/utils/$ADEMPIERE_DB_PATH/Stop.sql
************************************************************************/
set pause off
set echo on
ALTER DATABASE BACKUP CONTROLFILE TO TRACE;
shutdown transactional
exit

View File

@ -0,0 +1,5 @@
-- Connection Test
SELECT 'Success ' AS Connection FROM DUAL
/
EXIT

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,199 @@
-- AD_Message Reorg --
--
-- Save Data *******
--
DROP TABLE AD_Message_Old CASCADE CONSTRAINTS
/
DROP TABLE AD_Message_Trl_Old CASCADE CONSTRAINTS
/
CREATE TABLE AD_Message_OLD
AS SELECT * FROM AD_Message ORDER BY AD_Message
/
CREATE TABLE AD_Message_Trl_OLD
AS SELECT * FROM AD_Message_Trl ORDER BY AD_Message
/
-- Delete Unused Column
ALTER TABLE AD_Val_Rule DROP COLUMN AD_Message
/
--
-- Recreate Tables ******
--
DROP TABLE AD_Message CASCADE CONSTRAINTS
/
DROP TABLE AD_Message_Trl CASCADE CONSTRAINTS
/
DROP TABLE AD_Note CASCADE CONSTRAINTS
/
--
-- TABLE: AD_Message
--
CREATE TABLE AD_Message(
AD_Message_ID NUMBER(10, 0) NOT NULL,
AD_Client_ID NUMBER(10, 0) NOT NULL,
AD_Org_ID NUMBER(10, 0) NOT NULL,
IsActive CHAR(1) DEFAULT 'Y' NOT NULL
CHECK (IsActive in ('Y','N')),
Created DATE DEFAULT SYSDATE NOT NULL,
CreatedBy NUMBER(10, 0) NOT NULL,
Updated DATE DEFAULT SYSDATE NOT NULL,
UpdatedBy NUMBER(10, 0) NOT NULL,
Value VARCHAR2(40) NOT NULL,
MsgText VARCHAR2(2000) NOT NULL,
MsgTip VARCHAR2(2000),
MsgType CHAR(1) NOT NULL,
CONSTRAINT AD_Message_Key PRIMARY KEY (AD_Message_ID)
)
/
--
-- TABLE: AD_Message_Trl
--
CREATE TABLE AD_Message_Trl(
AD_Message_ID NUMBER(10, 0) NOT NULL,
AD_Language VARCHAR2(6) NOT NULL,
AD_Client_ID NUMBER(10, 0) NOT NULL,
AD_Org_ID NUMBER(10, 0) NOT NULL,
IsActive CHAR(1) DEFAULT 'Y' NOT NULL
CHECK (IsActive in ('Y','N')),
Created DATE DEFAULT SYSDATE NOT NULL,
CreatedBy NUMBER(10, 0) NOT NULL,
Updated DATE DEFAULT SYSDATE NOT NULL,
UpdatedBy NUMBER(10, 0) NOT NULL,
MsgText VARCHAR2(2000) NOT NULL,
MsgTip VARCHAR2(2000),
IsTranslated CHAR(1) DEFAULT 'N' NOT NULL
CHECK (IsTranslated in ('Y','N')),
CONSTRAINT AD_Message_Trl_Key PRIMARY KEY (AD_Message_ID, AD_Language)
)
/
--
-- TABLE: AD_Note
--
CREATE TABLE AD_Note(
AD_Note_ID NUMBER(10, 0) NOT NULL,
AD_Client_ID NUMBER(10, 0) NOT NULL,
AD_Org_ID NUMBER(10, 0) NOT NULL,
IsActive CHAR(1) DEFAULT 'Y' NOT NULL
CHECK (IsActive in ('Y','N')),
Created DATE DEFAULT SYSDATE NOT NULL,
CreatedBy NUMBER(10, 0) NOT NULL,
Updated DATE DEFAULT SYSDATE NOT NULL,
UpdatedBy NUMBER(10, 0) NOT NULL,
AD_User_ID NUMBER(10, 0),
AD_Message_ID NUMBER(10, 0) NOT NULL,
Reference VARCHAR2(60),
AD_Table_ID NUMBER(10, 0),
Record_ID NUMBER(10, 0),
Text VARCHAR2(2000),
Processed CHAR(1) DEFAULT 'N'
CHECK (Processed in ('Y','N')),
CONSTRAINT AD_Note_Ley PRIMARY KEY (AD_Note_ID)
)
/
COMMENT ON COLUMN AD_Note.AD_Table_ID IS 'AD_Table_ID Definition'
/
--
-- INDEX: AD_Message_Value
--
CREATE UNIQUE INDEX AD_Message_Value ON AD_Message(Value)
/
--
-- TABLE: AD_Message
--
ALTER TABLE AD_Message ADD CONSTRAINT MessageClient
FOREIGN KEY (AD_Client_ID)
REFERENCES AD_Client(AD_Client_ID)
/
ALTER TABLE AD_Message ADD CONSTRAINT MessageOrg
FOREIGN KEY (AD_Org_ID)
REFERENCES AD_Org(AD_Org_ID)
/
--
-- TABLE: AD_Message_Trl
--
ALTER TABLE AD_Message_Trl ADD CONSTRAINT AD_Language_MessageTrl
FOREIGN KEY (AD_Language)
REFERENCES AD_Language(AD_Language)
/
ALTER TABLE AD_Message_Trl ADD CONSTRAINT AD_MessageTrl
FOREIGN KEY (AD_Message_ID)
REFERENCES AD_Message(AD_Message_ID) ON DELETE CASCADE
/
--
-- TABLE: AD_Note
--
ALTER TABLE AD_Note ADD CONSTRAINT ADMessage_ADNote
FOREIGN KEY (AD_Message_ID)
REFERENCES AD_Message(AD_Message_ID)
/
ALTER TABLE AD_Note ADD CONSTRAINT ADTable_ADNote
FOREIGN KEY (AD_Table_ID)
REFERENCES AD_Table(AD_Table_ID)
/
ALTER TABLE AD_Note ADD CONSTRAINT ADUser_ADNote
FOREIGN KEY (AD_User_ID)
REFERENCES AD_User(AD_User_ID)
/
--
-- Re-Populate Data
--
CREATE SEQUENCE TEMP_SEQ START WITH 100
/
UPDATE AD_Message_Old
SET MsgType='I'
WHERE MsgType IS NULL
/
INSERT INTO AD_MESSAGE
(AD_MESSAGE_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
VALUE, MSGTEXT, MSGTIP, MSGTYPE)
SELECT Temp_Seq.NextVal, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
AD_Message, MSGTEXT, MSGTIP, MSGTYPE
FROM AD_Message_Old
/
COMMIT
/
UPDATE AD_Message_Trl t
SET (MSGTEXT, MSGTIP,IsTranslated) =
(SELECT o.MSGTEXT, o.MSGTIP, o.IsTransLated
FROM AD_Message_Trl_Old o, AD_Message m
WHERE m.AD_MESSAGE_ID=t.AD_MESSAGE_ID
AND m.Value=o.AD_Message
AND t.AD_Language=o.AD_Language)
/
COMMIT
/
--
-- Cleanup
--
DROP SEQUENCE TEMP_SEQ
/
DROP TABLE AD_Message_Old CASCADE CONSTRAINTS
/
DROP TABLE AD_Message_Trl_Old CASCADE CONSTRAINTS
/

View File

@ -0,0 +1,72 @@
/**
* Cleanup Data
*/
-- Copy Data from PriceListVersion_Para to DiscountSchema
DECLARE
CURSOR Cur_PLV IS
SELECT DISTINCT M_PriceList_Version_ID FROM M_PriceList_Para;
v_Name VARCHAR(60);
v_CLIENT_ID NUMBER(10);
v_ORG_ID NUMBER(10);
v_VALIDFROM DATE;
v_DiscountSchema_ID NUMBER(10);
BEGIN
FOR plv IN Cur_PLV LOOP
SELECT Name, AD_CLIENT_ID, AD_ORG_ID, VALIDFROM
INTO v_Name, v_CLIENT_ID, v_ORG_ID, v_VALIDFROM
FROM M_PriceList_Version
WHERE M_PriceList_Version_ID=plv.M_PriceList_Version_ID;
--
DBMS_OUTPUT.PUT_LINE(v_Name);
AD_Sequence_Next('M_DiscountSchema', v_Client_ID, v_DiscountSchema_ID);
INSERT INTO M_DISCOUNTSCHEMA
(M_DISCOUNTSCHEMA_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
CREATED, CREATEDBY, UPDATED, UPDATEDBY,
NAME, DESCRIPTION, VALIDFROM,
DISCOUNTTYPE, SCRIPT, FLATDISCOUNT,
ISQUANTITYBASED, CUMULATIVELEVEL, PROCESSING)
VALUES
(v_DISCOUNTSCHEMA_ID, v_CLIENT_ID, v_ORG_ID, 'Y',
SysDate, 0, SysDate, 0,
v_NAME, NULL, v_VALIDFROM,
'P', NULL, NULL,
'Y', NULL, NULL);
--
DECLARE
CURSOR Cur_Para IS
SELECT *
FROM M_PriceList_Para
WHERE M_PriceList_Version_ID=plv.M_PriceList_Version_ID;
v_NextNo NUMBER(10);
BEGIN
FOR p in CUR_Para LOOP
AD_Sequence_Next('M_DiscountSchemaLine', v_Client_ID, v_NextNo);
INSERT INTO M_DISCOUNTSCHEMALINE
(M_DISCOUNTSCHEMALINE_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
M_DISCOUNTSCHEMA_ID, SEQNO,
M_PRODUCT_CATEGORY_ID, C_BPARTNER_ID, M_PRODUCT_ID,
CONVERSIONRATETYPE, CONVERSIONDATE,
LIST_BASE, LIST_ADDAMT, LIST_DISCOUNT, LIST_ROUNDING,
LIST_MINAMT, LIST_MAXAMT,
STD_BASE, STD_ADDAMT, STD_DISCOUNT, STD_ROUNDING,
STD_MINAMT, STD_MAXAMT, LIMIT_BASE, LIMIT_ADDAMT,
LIMIT_DISCOUNT, LIMIT_ROUNDING, LIMIT_MINAMT, LIMIT_MAXAMT)
VALUES
(v_NextNo, p.AD_CLIENT_ID, p.AD_ORG_ID,
p.ISACTIVE, p.CREATED, p.CREATEDBY, p.UPDATED, p.UPDATEDBY,
v_DISCOUNTSCHEMA_ID, p.SEQNO,
p.M_PRODUCT_CATEGORY_ID, p.C_BPARTNER_ID, p.M_PRODUCT_ID,
p.CONVERSIONRATETYPE, p.CONVERSIONDATE,
p.LIST_BASE, p.LIST_ADDAMT, p.LIST_DISCOUNT, p.LIST_ROUNDING,
p.LIST_MINAMT, p.LIST_MAXAMT,
p.STD_BASE, p.STD_ADDAMT, p.STD_DISCOUNT, p.STD_ROUNDING,
p.STD_MINAMT, p.STD_MAXAMT, p.LIMIT_BASE, p.LIMIT_ADDAMT,
p.LIMIT_DISCOUNT, p.LIMIT_ROUNDING, p.LIMIT_MINAMT, p.LIMIT_MAXAMT);
END LOOP;
END;
END LOOP; -- PLV
END;

View File

@ -0,0 +1,123 @@
--
--ER/Studio 4.3 SQL Code Generation
-- Company : ComPiere, Inc.
-- Project : Application Model
-- Author : Jorg Janke
--
-- Date Created : Sunday, November 25, 2001 16:56:39
-- Target DBMS : Oracle 8
--
DROP TABLE M_MatchInv CASCADE CONSTRAINTS
;
DROP TABLE M_MatchPO CASCADE CONSTRAINTS
;
--
-- TABLE: M_MatchInv
--
CREATE TABLE M_MatchInv(
M_MatchInv_ID NUMBER(10, 0) NOT NULL,
AD_Client_ID NUMBER(10, 0) NOT NULL,
AD_Org_ID NUMBER(10, 0) NOT NULL,
IsActive CHAR(1) DEFAULT 'Y' NOT NULL,
Created DATE DEFAULT SysDate NOT NULL,
CreatedBy NUMBER(10, 0) NOT NULL,
Updated DATE DEFAULT SysDate NOT NULL,
UpdatedBy NUMBER(10, 0) NOT NULL,
M_InOutLine_ID NUMBER(10, 0) NOT NULL,
C_InvoiceLine_ID NUMBER(10, 0) NOT NULL,
M_Product_ID NUMBER(10, 0) NOT NULL,
DateTrx DATE NOT NULL,
Qty NUMBER DEFAULT 0 NOT NULL,
Processing CHAR(1) NOT NULL,
Processed CHAR(1) DEFAULT 'N' NOT NULL,
Posted CHAR(1) DEFAULT 'N' NOT NULL,
CHECK (IsActive in ('Y','N')),
CHECK (Processed in ('Y','N')),
CONSTRAINT M_MatchInv_Key PRIMARY KEY (M_MatchInv_ID)
)
;
--
-- TABLE: M_MatchPO
--
CREATE TABLE M_MatchPO(
M_MatchPO_ID NUMBER(10, 0) NOT NULL,
AD_Client_ID NUMBER(10, 0) NOT NULL,
AD_Org_ID NUMBER(10, 0) NOT NULL,
IsActive CHAR(1) DEFAULT 'Y' NOT NULL,
Created DATE DEFAULT SysDate NOT NULL,
CreatedBy NUMBER(10, 0) NOT NULL,
Updated DATE DEFAULT SysDate NOT NULL,
UpdatedBy NUMBER(10, 0) NOT NULL,
M_InOutLine_ID NUMBER(10, 0) NOT NULL,
C_OrderLine_ID NUMBER(10, 0) NOT NULL,
M_Product_ID NUMBER(10, 0) NOT NULL,
DateTrx DATE NOT NULL,
Qty NUMBER DEFAULT 0 NOT NULL,
Processing CHAR(1) NOT NULL,
Processed CHAR(1) DEFAULT 'N' NOT NULL,
Posted CHAR(1) DEFAULT 'N' NOT NULL,
CHECK (IsActive in ('Y','N')),
CHECK (Processed in ('Y','N')),
CONSTRAINT M_MatchPO_Key PRIMARY KEY (M_MatchPO_ID)
)
;
--
-- INDEX: M_MatchInv_Ship
--
CREATE INDEX M_MatchInv_Ship ON M_MatchInv(C_InvoiceLine_ID,M_InOutLine_ID)
;
--
-- INDEX: M_MatchPO_Ship
--
CREATE INDEX M_MatchPO_Ship ON M_MatchPO(C_OrderLine_ID,M_InOutLine_ID)
;
--
-- TABLE: M_MatchInv
--
ALTER TABLE M_MatchInv ADD CONSTRAINT COnvoiceLine_MMatchInv
FOREIGN KEY (C_InvoiceLine_ID)
REFERENCES C_InvoiceLine(C_InvoiceLine_ID)
;
ALTER TABLE M_MatchInv ADD CONSTRAINT MInOutLine_MMatchInv
FOREIGN KEY (M_InOutLine_ID)
REFERENCES M_InOutLine(M_InOutLine_ID)
;
ALTER TABLE M_MatchInv ADD CONSTRAINT MProduct_MMatchInv
FOREIGN KEY (M_Product_ID)
REFERENCES M_Product(M_Product_ID)
;
--
-- TABLE: M_MatchPO
--
ALTER TABLE M_MatchPO ADD CONSTRAINT COrderLine_MMatchPO
FOREIGN KEY (C_OrderLine_ID)
REFERENCES C_OrderLine(C_OrderLine_ID)
;
ALTER TABLE M_MatchPO ADD CONSTRAINT MInOutLine_MMatchPO
FOREIGN KEY (M_InOutLine_ID)
REFERENCES M_InOutLine(M_InOutLine_ID)
;
ALTER TABLE M_MatchPO ADD CONSTRAINT MProduct_MMatchPO
FOREIGN KEY (M_Product_ID)
REFERENCES M_Product(M_Product_ID)
;

733
db/maintain/Maintain.epj Normal file
View File

@ -0,0 +1,733 @@
Begin Project "Maintain", "Maintenance", VC_PROJECT=, AUXPROJPATH=
DATASOURCE=DEV2.Reference
DATABASE=
Begin SubProject "Maintenance", "", PATH=.\maintenance
Begin File "0_Add_New_Column.sql"
PATH=.\maintenance\0_add_new_column.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_Add_New_Field.sql"
PATH=.\maintenance\0_add_new_field.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_CleanUpAD.sql"
PATH=.\maintenance\0_cleanupad.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_DataCheck.sql"
PATH=.\maintenance\0_datacheck.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_SyncNames.sql"
PATH=.\maintenance\0_syncnames.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_TempTable_Create.sql"
PATH=.\maintenance\0_temptable_create.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "0_TempTable_Drop.sql"
PATH=.\maintenance\0_temptable_drop.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "1_Account_Defaults.sql"
PATH=.\maintenance\1_account_defaults.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "2_ObjectCompare.sql"
PATH=.\maintenance\2_objectcompare.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "8_CleanUp.sql"
PATH=.\maintenance\8_CleanUp.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "9_UpdateDBVersion.sql"
PATH=.\maintenance\9_updatedbversion.sql
DESCRIPTION=
INCLUDE=0
BUILDINDEX=-1
OBJECTTYPE=38
End File
Begin File "AD_Element_Check.sql"
PATH=.\maintenance\ad_element_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Element_Copy.sql"
PATH=.\maintenance\ad_element_copy.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Field_Check.sql"
PATH=.\maintenance\ad_field_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Field_ReSeq.sql"
PATH=.\maintenance\ad_field_reseq.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Form_Access.sql"
PATH=.\maintenance\ad_form_access.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Form_Check.sql"
PATH=.\maintenance\ad_form_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Menu_Check.sql"
PATH=.\maintenance\ad_menu_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Org_Check.sql"
PATH=.\maintenance\ad_org_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_PrintFormatItem_Check.sql"
PATH=.\maintenance\AD_PrintFormatItem_Check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Process_Access.sql"
PATH=.\maintenance\ad_process_access.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_ReplicationTable_Check.sql"
PATH=.\maintenance\AD_ReplicationTable_Check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Role_CreateAccess.sql"
PATH=.\maintenance\ad_role_createaccess.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Sequence_Check.sql"
PATH=.\maintenance\ad_sequence_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Task_Access.sql"
PATH=.\maintenance\ad_task_access.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_TreeNode_Check.sql"
PATH=.\maintenance\ad_treenode_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_Window_Access.sql"
PATH=.\maintenance\ad_window_access.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "AD_WorkFlow_Access.sql"
PATH=.\maintenance\ad_workflow_access.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_BPartner_Check.sql"
PATH=.\maintenance\c_bpartner_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_CashLine_Check.sql"
PATH=.\maintenance\c_cashline_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_DocType_Check.sql"
PATH=.\maintenance\c_doctype_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_ElementValue_Check.sql"
PATH=.\maintenance\c_elementvalue_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_ElementValue_Copy.sql"
PATH=.\maintenance\c_elementvalue_copy.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Location_Cleanup.sql"
PATH=.\maintenance\c_location_cleanup.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Order_Check.sql"
PATH=.\maintenance\c_order_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_PaymentTerm_Check.sql"
PATH=.\maintenance\c_paymentterm_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_PeriodControl_Check.sql"
PATH=.\maintenance\c_periodcontrol_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Project_Check.sql"
PATH=.\maintenance\c_project_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_SalesRegion_Check.sql"
PATH=.\maintenance\c_salesregion_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_TaxCategory_Check.sql"
PATH=.\maintenance\c_taxcategory_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_ValidCombbination_Check.sql"
PATH=.\maintenance\c_validcombbination_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_ValidCombbination_Constraints.sql"
PATH=.\maintenance\C_ValidCombbination_Constraints.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_ChangeKey.sql"
PATH=.\maintenance\dba_changekey.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Check.sql"
PATH=.\maintenance\dba_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_DeleteCascade.sql"
PATH=.\maintenance\dba_deletecascade.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Indexes.sql"
PATH=.\maintenance\dba_indexes.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Recompile_Run.sql"
PATH=.\maintenance\dba_recompile_run.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_RecreateTables.sql"
PATH=.\maintenance\dba_recreatetables.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Tables.sql"
PATH=.\maintenance\dba_tables.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Trg_Disable.sql"
PATH=.\maintenance\dba_trg_disable.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DBA_Trg_Enable.sql"
PATH=.\maintenance\dba_trg_enable.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_Product_Check.sql"
PATH=.\maintenance\m_product_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_Product_Delete.sql"
PATH=.\maintenance\m_product_delete.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_Storage_Check.sql"
PATH=.\maintenance\m_storage_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_Storage_CheckReserved.sql"
PATH=.\maintenance\m_storage_checkreserved.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_Transaction_Source.sql"
PATH=.\maintenance\m_transaction_source.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "M_AttributeSet_Check.sql"
PATH=.\maintenance\M_AttributeSet_Check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Invoice_Check.sql"
PATH=.\maintenance\C_Invoice_Check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Payment_Check.sql"
PATH=.\maintenance\C_Payment_Check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "8_DropTrg.sql"
PATH=.\maintenance\8_DropTrg.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "TableColumn.sql"
PATH=.\maintenance\TableColumn.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DB2_Utils.sql"
PATH=.\maintenance\DB2_Utils.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "Translation", "", PATH=.\translation
Begin File "Translation_Check.sql"
PATH=.\translation\translation_check.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Translation-Status.sql"
PATH=.\translation\translation-status.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Translation_Copy.sql"
PATH=.\translation\translation_copy.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DeleteLanguage.sql"
PATH=.\translation\DeleteLanguage.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Dummy_Translation.sql"
PATH=.\translation\Dummy_Translation.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "Other", "", PATH=.\other
Begin File "Apps_Tuning.sql"
PATH=.\other\apps_tuning.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "C_Order_Ovr.sql"
PATH=.\other\c_order_ovr.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "cursors.sql"
PATH=.\other\cursors.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "dbms_job.sql"
PATH=.\other\dbms_job.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "DocStatusAction.sql"
PATH=.\other\docstatusaction.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Fix_CashBook.sql"
PATH=.\other\Fix_CashBook.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "History.sql"
PATH=.\other\history.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Import_Overwrites.sql"
PATH=.\other\import_overwrites.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Java.sql"
PATH=.\other\java.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Java_Drop.sql"
PATH=.\other\java_drop.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Java_List.sql"
PATH=.\other\java_list.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Monitor_Index.sql"
PATH=.\other\monitor_index.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "Performance.sql"
PATH=.\other\performance.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "print_views.sql"
PATH=.\other\print_views.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "RenameColumn.sql"
PATH=.\other\renamecolumn.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "RenameTable.sql"
PATH=.\other\renametable.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "UpdateFK.sql"
PATH=.\other\UpdateFK.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "UpdateWith2Tables.sql"
PATH=.\other\updatewith2tables.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "UserErrors.sql"
PATH=.\other\usererrors.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "History", "", PATH=.\history
Begin File "db_changes.sql"
PATH=.\history\db_changes.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "db_cleanup.sql"
PATH=.\history\db_cleanup.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
Begin File "db_generate.sql"
PATH=.\history\db_generate.sql
DESCRIPTION=Generated Files from ER
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=38
End File
End SubProject
End Project

View File

@ -0,0 +1,112 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_Add_New_Column.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Add New Table Columns
* Description:
* Create new (missing) Tables and Columns when in Database, but not in AD
* You should change the entity type variables from D to User or Application.
*
* SELECT TableName, ColumnName FROM AD_Table t, AD_Column c WHERE TRUNC(c.Created)=TRUNC(SysDate) AND t.AD_Table_ID=c.AD_Table_ID
*
* Next Steps:
* => Run 0_TempTables_Create/Drop <= for 0_CleanUpAD
* - 0_CleanUpAD
* - AD_Element_Check
* - Application:
* Maintain Elements, Table;
* Add Windows/Tabs
* - 0_Add_New_Field
* - 0_SyncNames
* - AD_Menu_Check
* - Access:
* Window (Process, Form, Workflow, Task)
* - Application:
* Maintain Window
* Other:
* - 0_DataCheck
*****************************************************************************/
BEGIN
DBMS_OUTPUT.ENABLE(80000);
/** **/
DBMS_OUTPUT.PUT_LINE('Create missing Tables');
DECLARE
v_EntityType CHAR(1) := 'D'; -- change to User (also below!)
NextNo NUMBER;
CURSOR Cur_Table IS
SELECT Table_Name
FROM User_Tables ut
WHERE NOT EXISTS
(SELECT * FROM AD_Table t WHERE ut.Table_Name=UPPER(t.TableName))
-- No Selection Temporary and no Log tables
AND NOT (Table_Name LIKE 'T_SELECTION%'
OR Table_Name LIKE 'DBA%'
OR Table_Name LIKE '%$%' --
OR Table_Name LIKE 'A_A%_ACCT' OR Table_Name LIKE 'A_A%_ADD%' OR Table_Name LIKE 'A_A%_CHANGE%' OR Table_Name LIKE 'A_A%_USE'
OR Table_Name LIKE 'A_D%' -- Depreciation
OR Table_Name LIKE '%EXPLAIN%');
BEGIN
FOR CT IN Cur_Table LOOP
IF (CT.Table_Name LIKE 'XX%' OR CT.Table_Name LIKE 'CUST%' OR CT.Table_Name LIKE 'EXT%') THEN
v_EntityType := 'U';
END IF;
AD_Sequence_Next('AD_Table', 0, NextNo); -- get ID
INSERT INTO AD_Table
(AD_TABLE_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
Name, TableName, EntityType,
AccessLevel, LoadSeq, IsSecurityEnabled, IsDeleteable, ReplicationType)
VALUES
(NextNo, 0, 0,
'Y', SysDate, 0, SysDate, 0,
InitCap(CT.Table_Name), InitCap(CT.Table_Name), v_EntityType,
'4', 999, 'N', 'Y','L');
DBMS_OUTPUT.PUT_LINE('adding Table ' || InitCap(CT.Table_Name));
END LOOP; -- All new Tables
END;
COMMIT;
/** **/
DBMS_OUTPUT.PUT_LINE('Create missing Columns');
DECLARE
v_EntityType CHAR(1) := 'D'; -- change to User (also above!)
NextNo NUMBER;
CURSOR Cur_Column IS
SELECT Column_Name, Data_Type, COALESCE(Char_Col_Decl_Length, Data_Length) AS Data_Length,
Nullable, AD_Table_ID, Table_Name, EntityType
FROM User_Tab_Columns uc, AD_Table t
WHERE uc.Table_Name=UPPER(t.TableName)
AND NOT EXISTS
(SELECT * FROM AD_Table t, AD_Column c
WHERE t.AD_Table_ID=c.AD_Table_ID
AND uc.Table_Name=UPPER(t.TableName)
AND uc.Column_Name=UPPER(c.ColumnName));
BEGIN
FOR CC IN Cur_Column LOOP
AD_Sequence_Next('AD_Column', 0, NextNo); -- get ID
INSERT INTO AD_COLUMN
(AD_COLUMN_ID, AD_CLIENT_ID, AD_ORG_ID,
ISACTIVE, CREATED, CREATEDBY, UPDATED, UPDATEDBY,
NAME, VERSION, COLUMNNAME,
AD_TABLE_ID, AD_REFERENCE_ID,
FIELDLENGTH, ISKEY, ISPARENT, ISMANDATORY, ISIDENTIFIER,
SEQNO, ISTRANSLATED, ISENCRYPTED, EntityType)
VALUES
(NextNo, 0, 0,
'Y', SysDate, 0, SysDate, 0,
InitCap(CC.Column_Name), 1, InitCap(CC.Column_Name),
CC.AD_Table_ID, DECODE(CC.Data_Type, 'NUMBER', 11, 'CHAR', 20, 'DATE', 15, 10),
CC.Data_Length, 'N', 'N', DECODE(CC.Nullable, 'Y', 'N', 'Y'), 'N',
0, 'N', 'N', CC.EntityType);
DBMS_OUTPUT.PUT_LINE('adding Column ' || InitCap(CC.Table_Name) || ' Column ' || InitCap(CC.Column_Name));
END LOOP; -- All new columns
END;
COMMIT;
END;
/

View File

@ -0,0 +1,65 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_Add_New_Field.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Add new Window Fields
* Description:
* For existing Tabs from Table/Column
* You should change the entity type variables from D to User or Application.
SELECT * FROM AD_Field WHERE Created > SysDate-.1
*
************************************************************************/
BEGIN
DBMS_OUTPUT.ENABLE(80000);
DBMS_OUTPUT.PUT_LINE('For all Tabs create missing Fields');
DECLARE
v_EntityType CHAR(1) := 'D'; -- change to User
--
CURSOR Cur_Tab IS
SELECT t.AD_Table_ID, t.AD_Tab_ID, w.Name || ' - ' || t.Name AS Name
FROM AD_Window w
INNER JOIN AD_Tab t ON (w.AD_Window_ID=t.AD_Window_ID)
WHERE t.IsSortTab='N'
-- AND t.AD_Table_ID != 291 -- C_BPartner (multiple tabs)
-- AND AD_Table_ID NOT IN (SELECT AD_Table_ID FROM AD_Table WHERE TableName LIKE 'I\_%' ESCAPE '\')
ORDER BY w.Name, t.SeqNo;
CURSOR Cur_Column (Tab NUMBER, TableID NUMBER) IS
SELECT Name, Description, AD_Column_ID, FieldLength
FROM AD_Column c
WHERE NOT EXISTS
(SELECT * FROM AD_Field f
WHERE c.AD_Column_ID=f.AD_Column_ID
AND c.AD_Table_ID=TableID
AND f.AD_Tab_ID=Tab)
AND AD_Table_ID=TableID
AND NOT (UPPER(Name) LIKE 'CREATED%' OR UPPER(Name) LIKE 'UPDATED%')
AND IsActive='Y';
--
NextNo NUMBER;
BEGIN
FOR CT IN Cur_Tab LOOP
FOR CC IN Cur_Column (CT.AD_Tab_ID, CT.AD_Table_ID) LOOP
AD_Sequence_Next('AD_Field', 0, NextNo); -- get ID
INSERT INTO AD_Field
(ad_field_id, ad_client_id, ad_org_id,
isactive, created, createdby, updated, updatedby,
name, description, EntityType,
seqno, AD_Tab_ID, AD_Column_ID, DisplayLength, IsCentrallyMaintained)
VALUES
(NextNo, 0, 0,
'Y', SysDate, 0, SysDate, 0,
CC.Name, CC.Description, v_EntityType,
0, CT.AD_Tab_ID, CC.AD_Column_ID, CC.FieldLength, 'Y');
DBMS_OUTPUT.PUT_LINE('Tab ' || CT.Name || ' adding ' || CC.Name);
END LOOP; -- for all columns
END LOOP; -- for all tabs
COMMIT;
END;
COMMIT;
END;

View File

@ -0,0 +1,550 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_CleanUpAD.sql,v 1.2 2006/06/18 00:44:13 jjanke Exp $
***
* Title: Clean up Application Dictionary
* Description:
* => Run TempTables_Create/Drop <= first
* otherwise you'll delete all views
* Please check EVERY statement before execution.
* This is a script desiged for the reference database not extensions.
* (e.g. assigns ownership to system, etc.)
************************************************************************/
SELECT (SELECT COUNT(*) FROM USER_Procedures) "Procedures",
(SELECT COUNT(*) FROM USER_Triggers) "Triggers" FROM DUAL;
SELECT 'Clean up Application Dictionary' FROM DUAL;
-- Create temp table of all colums in AD and DB
SELECT '<<< Create temp table of all colums in AD and DB >>>' FROM DUAL;
CREATE OR REPLACE VIEW temp_db_columns AS
SELECT t.TableName, c.ColumnName, t.AD_Table_ID, c.AD_Column_ID,
uc.Data_Type, COALESCE(uc.Char_Col_Decl_Length,uc.Data_Length) AS DataLength,
uc.Data_Precision, uc.Data_Scale, uc.Nullable, c.ColumnSQL,
CASE WHEN uc.Data_Type IS NULL AND c.ColumnSQL IS NULL THEN 'Y' ELSE 'N' END AS IsNotInDB
FROM AD_Table t
INNER JOIN AD_Column c ON (t.AD_Table_ID=c.AD_Table_ID)
LEFT JOIN User_Tab_Columns uc ON (uc.Table_Name=UPPER(t.TableName)
AND uc.Column_Name=UPPER(c.ColumnName));
-- Delete columns not in DB = translated fields
SELECT Name "Delete fields not in DB", AD_Field_ID
FROM AD_Field f
WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=f.AD_Column_ID AND db.IsNotInDB='N');
DELETE AD_Field_Trl
WHERE AD_Field_ID IN
(SELECT AD_Field_ID FROM AD_Field f WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=f.AD_Column_ID AND db.IsNotInDB='N'));
-- Delete fields not in DB
DELETE AD_Field
WHERE AD_Field_ID IN
(SELECT AD_Field_ID FROM AD_Field f WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=f.AD_Column_ID AND db.IsNotInDB='N'));
-- Delete columns not in DB
SELECT Name "Delete columns not in DB", AD_Column_ID
FROM AD_Column c
WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N');
-- column used in table reference
DELETE AD_Ref_Table
WHERE AD_Key IN
(SELECT AD_Column_ID FROM AD_Column c WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N'));
DELETE AD_Ref_Table
WHERE AD_Display IN
(SELECT AD_Column_ID FROM AD_Column c WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N'));
-- remove references
UPDATE AD_Tab
SET AD_Column_ID = NULL
WHERE AD_Column_ID IN
(SELECT AD_Column_ID FROM AD_Column c WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N'));
DELETE AD_PrintFormatItem
WHERE AD_Column_ID IN
(SELECT AD_Column_ID FROM AD_Column c WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N'));
DELETE AD_Column
WHERE AD_Column_ID IN
(SELECT AD_Column_ID FROM AD_Column c WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Column_ID=c.AD_Column_ID AND db.IsNotInDB='N'));
-- Delete all AD_Tab rows of tables not in DB = translated tabs
SELECT Name "Delete Tabs w tables not in DB", AD_Tab_ID
FROM AD_Tab
WHERE AD_Table_ID IN
(SELECT AD_Table_ID FROM AD_Table t WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Table_ID=t.AD_Table_ID AND db.IsNotInDB='N'));
DELETE AD_Tab_Trl
WHERE AD_Tab_ID IN
(SELECT AD_Tab_ID FROM AD_Tab
WHERE AD_Table_ID IN
(SELECT AD_Table_ID FROM AD_Table t WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Table_ID=t.AD_Table_ID AND db.IsNotInDB='N')));
DELETE AD_Tab
WHERE AD_Table_ID IN
(SELECT AD_Table_ID FROM AD_Table t WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Table_ID=t.AD_Table_ID AND db.IsNotInDB='N'));
-- Delete all AD_Table rows of tables not in DB
SELECT Name "Delete Tables not in DB", AD_Table_ID
FROM AD_Table t
WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Table_ID=t.AD_Table_ID AND db.IsNotInDB='N');
DELETE AD_Table t
WHERE NOT EXISTS
(SELECT * FROM temp_db_columns db WHERE db.AD_Table_ID=t.AD_Table_ID AND db.IsNotInDB='N');
-- Update: IsMandatory
SELECT '<<< Update: IsMandatory >>>' FROM DUAL;
UPDATE AD_Column c
SET IsMandatory = 'Y'
WHERE IsMandatory = 'N'
AND EXISTS
(SELECT * FROM temp_db_columns db
WHERE c.AD_Column_ID=db.AD_Column_ID AND Nullable='N');
-- set AD_Client_ID/AD_Org_ID to TableDirect
SELECT '<<< set AD_Client_ID, AD_Org_ID to TableDir >>>' FROM DUAL;
UPDATE AD_Column
SET AD_Reference_ID = 19
WHERE (UPPER(ColumnName) = 'AD_CLIENT_ID' OR UPPER(ColumnName) = 'AD_ORG_ID')
AND AD_Reference_ID NOT IN (13, 18, 19);
-- set _ID to Type ID (DisplayType)
SELECT '<<< set _ID to Type ID >>>' FROM DUAL;
Update AD_Column
Set AD_Reference_ID = 13 -- ID
WHERE ColumnName LIKE '%\_ID' ESCAPE '\'
AND AD_Reference_ID not in (13, 17, 18, 19, 21, 25, 27, 30, 31, 32, 33, 35)
AND ColumnName NOT IN ('Record_ID', 'Find_ID')
-- Buttons with Process
AND NOT (AD_Reference_ID=28 AND AD_Process_ID IS NOT NULL);
-- set Record_ID/Find_ID
UPDATE AD_Column
SET AD_Reference_ID = 22 -- Number
WHERE ColumnName = 'Find_ID'
AND AD_Reference_ID <> 22;
UPDATE AD_Column
SET AD_Reference_ID = 28 -- Button
WHERE AD_Reference_ID NOT IN (28, 11) -- Integer
AND ColumnName = 'Record_ID';
-- set UpdatedBy, CreatedBy to Table
SELECT '<<< set UpdatedBy, CreatedBy to Table & User >>>' FROM DUAL;
UPDATE AD_Column
SET AD_Reference_ID = 18, -- Table
AD_Reference_Value_ID = 110
WHERE UPPER(ColumnName) IN ('CREATEDBY', 'UPDATEDBY')
AND AD_Reference_ID != 18;
-- set Updated, Created to DateTime
SELECT '<<< set Updated, Created to DateTime >>>' FROM DUAL;
UPDATE AD_Column
SET AD_Reference_ID = 16 -- DateTime
WHERE ColumnName IN ('Created', 'Updated')
AND AD_Reference_ID != 16;
-- set Updated, Created to not updateable
SELECT '<<< set Updated, Created to not updateable >>>' FROM DUAL;
UPDATE AD_Column
SET IsUpdateable = 'N'
WHERE UPPER(ColumnName) IN ('CREATEDBY', 'UPDATEDBY','CREATED', 'UPDATED')
AND IsUpdateable != 'N';
-- set _Acct
SELECT '<<< set _Acct >>>' FROM DUAL;
UPDATE AD_Column
SET AD_Reference_ID = 25,
AD_Reference_Value_ID = NULL
WHERE ColumnName LIKE '%\_Acct' ESCAPE '\'
AND AD_Reference_ID != 25;
-- set IsActive
SELECT '<<< set IsActive >>>' FROM DUAL;
UPDATE AD_Column
SET DefaultValue = 'Y'
WHERE ColumnName = 'IsActive' and DefaultValue IS Null;
-- Set Replication Strategy
SELECT '<<< Set Replication Strategy to Local >>>' FROM DUAL;
UPDATE AD_Table
SET ReplicationType = 'L'
WHERE ReplicationType IS Null;
-- Clean up Field SortNo
SELECT '<<< Clean up Field SortNo >>>' FROM DUAL;
UPDATE AD_Field
SET SortNo = Null
WHERE SortNo = 0;
--
SELECT '<<< Create Identifiers for Column Name for tables w/o identifier >>>' FROM DUAL;
UPDATE AD_Column c
SET IsIdentifier = 'Y',
SeqNo = 1
WHERE ColumnName = 'Name'
AND NOT EXISTS
(SELECT * FROM AD_Table t, AD_Column c2
WHERE t.AD_Table_ID=c2.AD_Table_ID
AND c2.IsIdentifier='Y');
SELECT '<<< Create Identifiers for Column DocumentNo for tables w/o identifier >>>' FROM DUAL;
UPDATE AD_Column c
SET IsIdentifier = 'Y',
SeqNo = 1
WHERE ColumnName = 'DocumentNo'
AND NOT EXISTS
(SELECT * FROM AD_Table t, AD_Column c2
WHERE t.AD_Table_ID=c2.AD_Table_ID
AND c2.IsIdentifier='Y');
SELECT '<<< Create Identifiers for Column Line for tables w/o identifier >>>' FROM DUAL;
UPDATE AD_Column c
SET IsIdentifier = 'Y',
SeqNo = 1
WHERE ColumnName = 'Line'
AND NOT EXISTS
(SELECT * FROM AD_Table t, AD_Column c2
WHERE t.AD_Table_ID=c2.AD_Table_ID
AND c2.IsIdentifier='Y');
-- tables w/o Key
SELECT ColumnName "<<< Create KeyCol >>>"
FROM AD_Column c
WHERE UPPER(ColumnName) = (Select UPPER(TableName) || '_ID' from ad_table t
where c.ad_table_id=t.ad_table_id)
AND NOT EXISTS
(SELECT * FROM AD_Table t INNER JOIN AD_Column c2 ON (t.AD_Table_ID=c2.AD_Table_ID)
WHERE c.AD_Column_ID=c2.AD_Column_ID AND c2.IsKey='Y')
AND c.ColumnName<>'AD_ChangeLog_ID';
UPDATE AD_Column c
SET Iskey = 'Y', AD_Reference_ID=13
WHERE UPPER(ColumnName) = (Select UPPER(TableName) || '_ID' from ad_table t
where c.ad_table_id=t.ad_table_id)
AND NOT EXISTS
(SELECT * FROM AD_Table t INNER JOIN AD_Column c2 ON (t.AD_Table_ID=c2.AD_Table_ID)
WHERE c.AD_Column_ID=c2.AD_Column_ID AND c2.IsKey='Y')
AND c.ColumnName<>'AD_ChangeLog_ID';
SELECT '<<< Key Columns not updateable >>>' FROM DUAL;
UPDATE AD_Column
SET IsUpdateable = 'N'
WHERE IsUpdateable='Y' AND (IsKey='Y' OR IsParent='Y');
SELECT '<<< Parent Fields Read/Only >>>' FROM DUAL;
-- Make Parent Fields r/o for tabs with two parents
UPDATE AD_Field
SET IsReadOnly='Y'
WHERE IsReadOnly='N'
AND AD_Column_ID IN (SELECT AD_Column_ID FROM AD_Column WHERE IsParent='Y');
-- Make Parent Fields r/w for tabs with two parents and the defined actual parent column
UPDATE AD_Field f
SET IsReadOnly='N'
WHERE IsReadOnly='Y'
AND EXISTS
(SELECT * FROM AD_Column c WHERE c.AD_Column_ID=f.AD_Column_ID AND c.IsParent='Y')
AND AD_Tab_ID IN
(SELECT AD_Tab_ID
FROM AD_Tab
WHERE AD_Column_ID IS NOT NULL
-- tables with two parent fields
AND AD_Table_ID IN
(SELECT AD_Table_ID FROM AD_Table t
WHERE (SELECT COUNT(*) FROM AD_Column c WHERE c.AD_Table_ID=t.AD_Table_ID AND IsParent='Y')>1)
);
-- Make Actual Parent fields r/o in tabs with two parent fields
UPDATE AD_Field f
SET IsReadOnly='Y'
WHERE IsReadOnly='N'
AND (AD_Tab_ID, AD_Column_ID) IN
(SELECT AD_Tab_ID, AD_Column_ID
FROM AD_Tab
WHERE AD_Column_ID IS NOT NULL
-- tables with two parent fields
AND AD_Table_ID IN
(SELECT AD_Table_ID FROM AD_Table t
WHERE (SELECT COUNT(*) FROM AD_Column c WHERE c.AD_Table_ID=t.AD_Table_ID AND IsParent='Y')>1)
);
-- Exceptions
UPDATE AD_Field
SET IsReadOnly='N'
WHERE IsReadOnly='Y' AND AD_Field_ID IN (
4394, -- role/org
6523 -- cycle/phase
);
-- Set Client R/O in subsequent tabs
UPDATE AD_Field
SET IsReadOnly='Y'
WHERE AD_Field_ID IN
(SELECT AD_Field_ID
FROM AD_Field f
INNER JOIN AD_Tab t on (f.AD_Tab_ID=t.AD_Tab_ID)
INNER JOIN AD_Column c on (f.AD_Column_ID=c.AD_Column_ID)
WHERE f.IsReadOnly='N'
AND t.TabLevel > 0
AND c.ColumnName='AD_Client_ID');
SELECT '<<< COMMIT >>>' FROM DUAL;
COMMIT;
--
SELECT '<<< Set Validation Rules for TableDir Client & Org >>>' FROM DUAL;
UPDATE AD_Column
SET AD_Val_Rule_ID=104
WHERE UPPER(ColumnName)='AD_ORG_ID' AND AD_Val_Rule_ID IS NULL AND AD_Reference_ID=19;
UPDATE AD_Column
SET IsUpdateable='Y'
WHERE IsUpdateable IS NULL;
UPDATE AD_Column
SET IsUpdateable = 'N'
WHERE (UPPER(ColumnName)='AD_CLIENT_ID' OR UPPER(ColumnName)='AD_ORG_ID')
AND IsUpdateable <> 'N';
---
SELECT '<<< Set Client/Org Login default of primary Tab >>>' FROM DUAL;
UPDATE AD_Column
SET DefaultValue='@#AD_Client_ID@'
WHERE ColumnName = 'AD_Client_ID' AND DefaultValue IS NULL
AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Tab WHERE TabLevel = 0);
UPDATE AD_Column
SET DefaultValue='@#AD_Org_ID@'
WHERE ColumnName = 'AD_Org_ID' AND DefaultValue IS NULL
AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Tab WHERE TabLevel = 0);
SELECT '<<< Set Client/Org default of dependent Tabs >>>' FROM DUAL;
UPDATE AD_Column
SET DefaultValue='@AD_Client_ID@'
WHERE ColumnName = 'AD_Client_ID' AND DefaultValue IS NULL
AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Tab WHERE TabLevel > 0);
UPDATE AD_Column
SET DefaultValue='@AD_Org_ID@'
WHERE ColumnName = 'AD_Org_ID' AND DefaultValue IS NULL
AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Tab WHERE TabLevel > 0);
--
SELECT '<<< Set Updateable if Views >>>' FROM DUAL;
UPDATE AD_Column
SET IsUpdateable='N'
WHERE IsUpdateable='Y'
AND AD_Table_ID IN (SELECT AD_Table_ID FROM AD_Table WHERE IsView='Y');
UPDATE AD_Column c
SET IsAlwaysUpdateable='N'
WHERE IsUpdateable='N' AND (IsAlwaysUpdateable='Y' OR IsAlwaysUpdateable IS NULL);
--
SELECT '<<< Set System ownership >>>' FROM DUAL;
UPDATE AD_Table SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Column SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
--
UPDATE AD_Window SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Tab SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Field SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Window_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Tab_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Field_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
--
UPDATE AD_Reference SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Ref_List SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Ref_Table SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Reference_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Ref_List_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Val_Rule SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
--
UPDATE AD_Element SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Element_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
--
UPDATE AD_Menu SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
UPDATE AD_Menu_Trl SET AD_Client_ID=0, AD_Org_ID=0 WHERE AD_Client_ID!=0 OR AD_Org_ID!=0;
--
SELECT '<<< COMMIT >>>' FROM DUAL;
COMMIT;
--
SELECT '<<< Sync ColumnName & TableName_ID for TableDir >>>' FROM DUAL;
UPDATE AD_Element e
SET ColumnName = (SELECT t.TableName||'_ID' FROM AD_Table t
WHERE UPPER(e.ColumnName)=UPPER(t.TableName)||'_ID'
AND NOT e.ColumnName=t.TableName||'_ID')
WHERE EXISTS (SELECT * FROM AD_Table t
WHERE UPPER(e.ColumnName)=UPPER(t.TableName)||'_ID'
AND NOT e.ColumnName=t.TableName||'_ID');
SELECT '<<< COMMIT >>>' FROM DUAL;
COMMIT;
--
-- Update all: String length
SELECT '<<< Update Field length >>>' FROM DUAL;
-- sets all numeric to 22 and date to 7
UPDATE AD_Column c
SET FieldLength = (SELECT DataLength FROM temp_db_columns db
WHERE c.ad_column_id=db.ad_column_id)
WHERE FieldLength <> (SELECT DataLength FROM temp_db_columns db
WHERE c.ad_column_id=db.ad_column_id);
SELECT '<<< Set Display Length >>>' FROM DUAL;
update ad_field set displaylength = 1 -- Checks, Radio
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id in (20, 24))
and displaylength != 1;
update ad_field set displaylength = 11 -- integer
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id = 11)
and displaylength != 11;
update ad_field set displaylength = 14 -- date fields
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id = 15)
and displaylength != 14;
update ad_field set displaylength = 20 -- datetime
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id = 16)
and displaylength != 20;
update ad_field set displaylength = 26 -- amount, number, quantity
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id in (12, 22, 29, 37))
and displaylength != 26;
update ad_field set displaylength = 26 -- account, location, search
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id in (25, 21, 30, 35))
and displaylength != 26;
update ad_field set displaylength = 14 -- starting point for picks
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id in (13,17,18,19,26,27))
and displaylength != 14;
update ad_field set displaylength = 60 -- Text /Long
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id IN (14,36))
and displaylength NOT IN (20,60);
update ad_field set displaylength = 60 -- Long Strings
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id = 10)
and displaylength > 60;
update ad_field set displaylength = 23 -- starting point for button
where ad_column_id in (select ad_column_id from ad_column where ad_reference_id = 28)
and displaylength != 23;
update ad_field set displaylength = 20 -- document no
where name = 'Document No' and displaylength != 20;
update ad_field set displaylength = 20 -- value, password, alias
where (name like 'Value%' or name = 'Password' or name = 'Alias')
and displaylength > 20;
-- Normalize Length
update ad_field set displaylength = 5
where displaylength != 5 and (displaylength > 1 and displaylength < 6);
update ad_field set displaylength = 11 -- integers = 11
where displaylength is null or displaylength = 0 or displaylength = 10 or displaylength = 12;
update ad_field set displaylength = 17
where displaylength = 16 or displaylength = 18;
update ad_field set displaylength = 20
where displaylength = 19 or displaylength = 21;
update ad_field set displaylength = 23
where displaylength = 22 or displaylength = 24;
update ad_field set displaylength = 26 -- numbers = 26
where displaylength = 25 or displaylength = 27;
update ad_field set displaylength = 29
where displaylength > 29 and displaylength < 35;
select DisplayLength "Odd DisplayLength", Name from ad_field
where displaylength not in (1, 5, 6, 8, 11,14,15,17,20,23,26,29, 40, 60, 2000,4000)
order by 1;
--
-- Set to List where not list/button
UPDATE AD_Column SET AD_Reference_ID=17
WHERE AD_Reference_ID NOT IN (17,28) AND ColumnName IN ('Posted','DocAction');
-- Set to _Posted Status
UPDATE AD_Column SET AD_Reference_Value_ID=234
WHERE AD_Reference_Value_ID IS NULL AND ColumnName='Posted';
-- Set parameters to empty selection
UPDATE AD_Process_Para
SET DefaultValue = '-1'
WHERE ColumnName = 'AD_User_ID'
AND DefaultValue IS NULL;
UPDATE AD_Process_Para
SET DefaultValue = '0'
WHERE ColumnName IN ('C_BP_Group_ID','M_Product_Category_ID','M_Locator_ID')
AND DefaultValue IS NULL;
UPDATE AD_Column
SET DefaultValue='U'
WHERE ColumnName='EntityType' AND (DefaultValue<>'U' OR DefaultValue IS NULL);
UPDATE AD_Column
SET ReadOnlyLogic='@EntityType@=D'
WHERE ColumnName='EntityType' AND ReadOnlyLogic IS NULL;
SELECT '<<< COMMIT >>>' FROM DUAL;
COMMIT;
-- Fini
SELECT '<<< FINI - Dropping Views >>>' FROM DUAL;
DROP VIEW Temp_db_columns;
--
COMMIT;

View File

@ -0,0 +1,216 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_DataCheck.sql,v 1.2 2006/07/03 23:19:11 jjanke Exp $
***
* Title: Data Consistency Check
* Description:
* No updates
************************************************************************/
-- 0 Tables not in Dictionary ----------------------------------------------
SELECT Table_Name "Not in Dictionary" FROM CAT
WHERE Table_Name NOT IN (SELECT UPPER(TableName) FROM AD_Table)
AND Table_Name NOT LIKE '%_V'
AND Table_Name NOT LIKE '%_V_'
AND Table_Name NOT LIKE '%$%'
ORDER BY 1;
-- 1 Windows w/o Tabs ------------------------------------------------------
Select Name "Windows w/o Tabs", IsActive "Active"
from AD_Window w
Where not exists (select * from ad_tab t where w.ad_window_id = t.ad_window_id)
order by 1;
-- 2 Tabs w/o Fields -------------------------------------------------------
Select Name "Tabs w/o Fields"
from AD_Tab t
Where not exists (select * from ad_field f where t.ad_tab_id = f.ad_tab_id)
AND t.IsSortTab='N'
order by 1;
-- 3 Tables not used in Tabs -----------------------------------------------
Select TableName "Tables not used"
From AD_Table t
Where not exists
(Select * from AD_Tab x where t.AD_Table_ID=x.AD_Table_ID)
AND t.IsView='N'
Order by 1;
-- 4 Columns not used on Fields --------------------------------------------
Select t.TableName, c.ColumnName "Columns not used"
From AD_Column c, AD_Table t, AD_Tab x
WHERE c.AD_Table_ID=t.AD_Table_ID
AND t.AD_Table_ID=x.AD_Table_ID
AND not exists
(Select * from AD_Field f where f.AD_Column_ID=c.AD_Column_ID)
AND Not
(ColumnName like 'Created%' or ColumnNAme like 'Updated%' or ColumnName='AD_Org_ID')
Order by 1, 2;
-- 5 Fields w/o corret SeqNo -----------------------------------------------
Select w.Name "Window Name", t.Name "Tab Name", f.Name "Field w/o correct SeqNo"
From AD_Field f, AD_Tab t, AD_Window w
WHERE t.AD_Tab_ID=f.AD_Tab_ID
AND t.AD_Window_ID=w.AD_Window_ID
AND f.IsDisplayed='Y'
AND (f.SeqNo is null OR f.SeqNo = 0)
Order by 1, 2, 3;
-- 6 Windows not in Menu ---------------------------------------------------
Select Name "Windows not in Menu"
From AD_Window w
Where not exists
(Select * from AD_Menu m where w.AD_Window_ID=m.AD_Window_ID);
-- 7 Window/Tabs without Sort Order ----------------------------------------
SELECT w.Name "Window", t.Name "Tab w/o Sort Order"
FROM AD_Window w, AD_Tab t
WHERE w.AD_Window_ID = t.AD_Window_ID
AND AD_Tab_ID NOT IN (SELECT DISTINCT AD_Tab_ID
FROM AD_Field WHERE SortNo <> 0)
AND t.IsTranslationTab!='Y' AND t.IsSortTab='N'
ORDER BY 1;
-- 8 References without details --------------------------------------------
SELECT Name "Table References w/o Detail" FROM AD_Reference
WHERE ValidationType ='T'
AND AD_Reference_ID NOT IN (SELECT AD_Reference_ID FROM AD_Ref_Table);
SELECT Name "List References w/o Detail" FROM AD_Reference
WHERE ValidationType ='L'
AND AD_Reference_ID NOT IN (SELECT AD_Reference_ID FROM AD_Ref_List);
-- 10 References not used ---------------------------------------------------
SELECT Name "Reference not used", ValidationType, AD_Reference_ID
FROM AD_Reference r
WHERE IsActive='Y'
AND NOT EXISTS
(SELECT * FROM AD_Column c
WHERE c.AD_Reference_ID=r.AD_Reference_ID
OR c.AD_Reference_Value_ID=r.AD_Reference_ID)
AND NOT EXISTS
(SELECT * FROM AD_Process_Para p
WHERE p.AD_Reference_ID=r.AD_Reference_ID
OR p.AD_Reference_Value_ID=r.AD_Reference_ID)
AND NOT EXISTS
(SELECT * FROM AD_Attribute a
WHERE a.AD_Reference_ID=r.AD_Reference_ID
OR a.AD_Reference_Value_ID=r.AD_Reference_ID)
ORDER BY 2, 1;
-- 10a Table Reference
SELECT r.AD_Reference_ID, r.Name "Reference"
FROM AD_Ref_Table rt
INNER JOIN AD_Reference r ON (r.AD_Reference_ID=rt.AD_Reference_ID)
INNER JOIN AD_Column ck ON (ck.AD_Column_ID=rt.AD_Key AND ck.AD_Table_ID!=rt.AD_Table_ID)
INNER JOIN AD_Column cd ON (cd.AD_Column_ID=rt.AD_Key AND cd.AD_Table_ID!=rt.AD_Table_ID);
-- 11 Validation rules not used ---------------------------------------------
SELECT Name "Validation not used", AD_Val_Rule_ID
FROM AD_Val_Rule v
WHERE IsActive='Y'
AND NOT EXISTS
(SELECT * FROM AD_Column c
WHERE c.AD_Val_Rule_ID=v.AD_Val_Rule_ID)
AND NOT EXISTS
(SELECT * FROM AD_Table t
WHERE t.AD_Val_Rule_ID=v.AD_Val_Rule_ID)
AND NOT EXISTS
(SELECT * FROM AD_Process_Para p
WHERE p.AD_Val_Rule_ID=v.AD_Val_Rule_ID)
AND NOT EXISTS
(SELECT * FROM AD_Attribute a
WHERE a.AD_Val_Rule_ID=v.AD_Val_Rule_ID)
ORDER BY 1;
-- 12 Processes -------------------------------------------------------------
SELECT Name "Process", ProcedureName "Missing DB Procedure"
FROM AD_Process p
WHERE ProcedureName IS NOT NULL
AND NOT EXISTS
(SELECT * FROM USER_OBJECTS
WHERE OBJECT_NAME = UPPER(p.ProcedureName));
SELECT Value "Process Not Used", Name
FROM AD_Process p
WHERE IsActive='Y'
AND NOT Value LIKE 'Rpt%'
AND NOT EXISTS
(SELECT * FROM AD_Column c WHERE c.AD_Process_ID=p.AD_Process_ID)
AND NOT EXISTS
(SELECT * FROM AD_Tab t WHERE t.AD_Process_ID=p.AD_Process_ID)
AND NOT EXISTS
(SELECT * FROM AD_Menu m WHERE m.AD_Process_ID=p.AD_Process_ID);
-- 14 Tables w/o Key -------------------------------------------------------
SELECT TableName "Tables w/o IsKey"
FROM AD_Table t
WHERE
-- Tables with key columns
NOT EXISTS (SELECT * FROM AD_Column c
WHERE t.AD_Table_ID=c.AD_Table_ID AND c.IsKey='Y')
-- Tables with 2 parents - Association entries
AND NOT EXISTS (SELECT c.AD_Table_ID FROM AD_Column c
WHERE t.AD_Table_ID=c.AD_Table_ID AND c.IsParent='Y'
GROUP BY c.AD_Table_ID HAVING COUNT(*) > 1)
-- No Views
AND IsView='N'
-- tables with more than one key
AND UPPER(TableName) NOT IN -- assuming that they are P type constraints
(SELECT Table_Name FROM USER_Cons_Columns cc
GROUP BY Constraint_Name, Table_Name
HAVING COUNT(*) > 1)
ORDER BY 1;
/**
SELECT TableName "Tables with > 1 Key"
FROM AD_Table t
WHERE IsView='N' AND TableName NOT LIKE '%_Trl' AND TableName NOT LIKE '%_Acct'
AND EXISTS (SELECT c.AD_Table_ID FROM AD_Column c
WHERE t.AD_Table_ID=c.AD_Table_ID AND c.IsParent='Y'
GROUP BY c.AD_Table_ID HAVING COUNT(*) > 1)
ORDER BY 1;
**/
-- 15 Key ColumnName not is sync with TableName -----------------------------
SELECT t.TableName, e.ColumnName "Key ColumnName not in sync"
FROM AD_Table t, AD_Element e
WHERE UPPER(e.ColumnName)=UPPER(t.TableName)||'_ID'
AND NOT e.ColumnName=t.TableName||'_ID';
-- 16 Tables w/o Identifier -------------------------------------------------
SELECT TableName "Tables w/o IsIdentifier"
FROM AD_Table t
WHERE NOT EXISTS
(SELECT * FROM AD_Column c WHERE IsIdentifier = 'Y' AND t.AD_Table_ID=c.AD_Table_ID)
-- No Views
AND IsView='N'
-- tables with more than one key
AND UPPER(TableName) NOT IN -- assuming that they are P type constraints
(SELECT Table_Name FROM USER_Cons_Columns cc
GROUP BY Constraint_Name, Table_Name
HAVING COUNT(*) > 1)
ORDER BY 1;
-- 17 Table Reference w/o Value ----------------------------------------------
SELECT TableName, ColumnName, c.AD_Reference_ID "Table Reference w/o Value",
AD_Reference_Value_ID, c.AD_Val_Rule_ID
FROM AD_Column c
INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID)
WHERE AD_Reference_ID=18 AND AD_Reference_Value_ID IS NULL
ORDER By 1,2;

View File

@ -0,0 +1,52 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_SyncNames.sql,v 1.3 2006/05/28 22:52:07 jjanke Exp $
***
* Title: Synchronize Names
* Description:
* Update Column and Field with Names from Element and Process
* Update Process Parameters from Elements
* Update Workflow Nodes from Windows
*
-- Not centrally maintained fields
SELECT w.Name "Window", t.Name "Tab", f.Name "Field", c.Name "Column"
FROM AD_Field f
INNER JOIN AD_Tab t ON (t.AD_Tab_ID=f.AD_Tab_ID)
INNER JOIN AD_Window w ON (w.AD_Window_ID=t.AD_Window_ID)
INNER JOIN AD_Column c ON (c.AD_Column_ID=f.AD_Column_ID)
WHERE f.IsCentrallyMaintained='N'
ORDER BY 1,2
/
-- Not centrally maintained parameters
SELECT p.Name "Process", pp.Name "Parameter", pp.ColumnName "Par Column", e.Name "Element", e.ColumnName "Ele Column"
FROM AD_Process_Para pp
INNER JOIN AD_Process p ON (p.AD_Process_ID=pp.AD_Process_ID)
LEFT OUTER JOIN AD_Element e ON (e.AD_Element_ID=pp.AD_Element_ID)
WHERE pp.IsCentrallyMaintained='N'
/
-- Duplicate ColumnName - Element is Case sensitive, but database is not
SELECT UPPER(ColumnName)
FROM AD_Element
GROUP BY UPPER(ColumnName)
HAVING COUNT(UPPER(ColumnName)) > 1
/
-- Invalid ColumnName - ORA-00001: unique constraint (ADEMPIERE.AD_COLUMN_NAME) violated
SELECT t.TableName, c.ColumnName, e.ColumnName
FROM AD_Element e
INNER JOIN AD_Column c ON (e.AD_Element_ID=c.AD_Element_ID)
INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID)
WHERE c.ColumnName<>e.ColumnName
/
*
************************************************************************/
BEGIN
AD_Synchronize(null);
COMMIT;
END;
/

View File

@ -0,0 +1,57 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_TempTable_Create.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Create Temp Tables
* Description:
* Create (Temporary) Tables for reporting views
************************************************************************/
DECLARE
CURSOR CUR_Views IS
SELECT View_Name
FROM USER_Views
WHERE NOT
(
View_Name LIKE '%_VT' -- Translation Views
OR View_Name LIKE '%_V1' -- Special Views
OR View_Name LIKE 'AD_%' -- Dictionary Views
OR View_Name LIKE 'O_%' -- Export Views
OR View_Name LIKE 'GL_%' -- GL Views
OR View_Name LIKE 'R_%_V' -- Request Views
OR View_Name IN ('C_INVOICE_V','C_INVOICELINE_V', 'C_PAYMENT_V',
'C_INVOICE_CANDIDATE_V', 'M_INOUT_CANDIDATE_V')
)
ORDER BY 1;
v_Cmd VARCHAR2(2000);
BEGIN
FOR v IN CUR_Views LOOP
DBMS_OUTPUT.PUT('View ' || v.View_Name || ' - ');
v_Cmd := 'CREATE TABLE '
|| v.View_Name || '__ AS SELECT * FROM '
|| v.View_Name || ' WHERE AD_Client_ID=-1';
BEGIN
EXECUTE IMMEDIATE v_Cmd;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT(' CREATE ERROR: ' || v_Cmd || ' ');
END;
--
v_Cmd := 'UPDATE AD_Table SET TableName=TableName || ''__''
WHERE UPPER(TableName)=''' || v.View_Name || '''';
BEGIN
EXECUTE IMMEDIATE v_Cmd;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT(' UPDATE ERROR ');
END;
DBMS_OUTPUT.PUT_LINE (SQL%ROWCOUNT);
END LOOP;
END;
/
COMMIT
/

View File

@ -0,0 +1,52 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 0_TempTable_Drop.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Drop Temporary Tables
* Description:
* Drop (Temporary) Tables for report views
************************************************************************/
DECLARE
CURSOR CUR_Views IS
SELECT View_Name
FROM USER_Views
WHERE NOT
(
View_Name LIKE '%_VT' -- Translation Views
OR View_Name LIKE '%_V1' -- Special Views
OR View_Name LIKE 'AD_%' -- Dictionary Views
OR View_Name LIKE 'O_%' -- Export Views
OR View_Name LIKE 'GL_%' -- GL Views
OR View_Name LIKE 'R_%_V' -- Request Views
OR View_Name IN ('C_INVOICE_V','C_INVOICELINE_V', 'C_PAYMENT_V',
'C_INVOICE_CANDIDATE_V', 'M_INOUT_CANDIDATE_V')
)
ORDER BY 1;
v_Cmd VARCHAR2(2000);
BEGIN
FOR v IN CUR_Views LOOP
DBMS_OUTPUT.PUT('View ' || v.View_Name || ' - ');
BEGIN
v_Cmd := 'DROP TABLE ' || v.View_Name || '__';
EXECUTE IMMEDIATE v_Cmd;
EXCEPTION WHEN OTHERS THEN
DBMS_OUTPUT.PUT('Table not existing - ');
END;
--
v_Cmd := 'UPDATE AD_Table SET TableName=SUBSTR(TableName,1,LENGTH(TableName)-2) '
|| 'WHERE UPPER(TableName)=''' || v.View_Name || '__''';
EXECUTE IMMEDIATE v_Cmd;
DBMS_OUTPUT.PUT_LINE (SQL%ROWCOUNT);
END LOOP;
END;
/
COMMIT
/

View File

@ -0,0 +1,31 @@
/**
* Account Defaults *** DANGEROUS ***
*
DECLARE
-- Accounting Defaults for all clients
CURSOR Cur_Clients IS
SELECT AD_Client_ID FROM AD_Client;
-- All Bus Groups
CURSOR Cur_BP IS
SELECT C_BP_Group_ID FROM C_BP_Group;
-- All Product Categories
CURSOR Cur_PC IS
SELECT M_Product_Category_ID FROM M_Product_Category;
--
BEGIN
-- Accounting Defaults
FOR cc IN Cur_Clients LOOP
DBMS_OUTPUT.PUT_LINE('------------------------');
-- C_AcctSchema_Default_Copy(0, cc.AD_Client_ID); -- DANGEROUS !!!
END LOOP;
-- BPartner Defaults
FOR bp IN Cur_BP LOOP
DBMS_OUTPUT.PUT_LINE('------------------------');
C_BP_Group_Acct_Copy(0, bp.C_BP_Group_ID);
END LOOP;
-- Accounting Defaults
FOR pc IN Cur_PC LOOP
DBMS_OUTPUT.PUT_LINE('------------------------');
M_Product_Category_Acct_Copy(0, pc.M_Product_Category_ID);
END LOOP;
END;

View File

@ -0,0 +1,51 @@
/*************************************************************************
* The contents of this file are subject to the Adempiere License. You may
* obtain a copy of the License at http://www.adempiere.org/license.html
* Software is on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for details. Code: Adempiere ERP+CRM
* Copyright (C) 1999-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
*************************************************************************
* $Id: 2_ObjectCompare.sql,v 1.1 2006/04/21 17:51:58 jjanke Exp $
***
* Title: Compare existance of Objects in Adempiere and Reference
* Description:
************************************************************************/
-- Procedures, ..
SELECT OBJECT_NAME "Object", InitCap(OBJECT_TYPE) "Type", InitCap(OWNER) "Only in"
FROM ALL_OBJECTS a1
WHERE OWNER = 'ADEMPIERE'
AND OBJECT_TYPE NOT IN ('INDEX', 'VIEW', 'LOB')
AND NOT EXISTS (SELECT * FROM ALL_OBJECTS a2
WHERE OWNER = 'REFERENCE' AND a1.OBJECT_NAME=a2.OBJECT_NAME
AND OBJECT_TYPE NOT IN ('INDEX', 'VIEW', 'LOB'))
ORDER BY 2,1;
SELECT OBJECT_NAME "Object", InitCap(OBJECT_TYPE) "Type", InitCap(OWNER) "Only in"
FROM ALL_OBJECTS a1
WHERE OWNER = 'REFERENCE'
AND OBJECT_TYPE NOT IN ('INDEX', 'VIEW', 'LOB')
AND NOT EXISTS (SELECT * FROM ALL_OBJECTS a2
WHERE OWNER = 'ADEMPIERE' AND a1.OBJECT_NAME=a2.OBJECT_NAME
AND OBJECT_TYPE NOT IN ('INDEX', 'VIEW', 'LOB'))
ORDER BY 2,1;
-- Index, Views
SELECT OBJECT_NAME "Object", InitCap(OBJECT_TYPE) "Type", InitCap(OWNER) "Only in"
FROM ALL_OBJECTS a1
WHERE OWNER = 'ADEMPIERE'
AND OBJECT_TYPE IN ('INDEX', 'VIEW')
AND NOT EXISTS (SELECT * FROM ALL_OBJECTS a2
WHERE OWNER = 'REFERENCE' AND a1.OBJECT_NAME=a2.OBJECT_NAME
AND OBJECT_TYPE IN ('INDEX', 'VIEW'))
ORDER BY 2,1;
SELECT OBJECT_NAME "Object", InitCap(OBJECT_TYPE) "Type", InitCap(OWNER) "Only in"
FROM ALL_OBJECTS a1
WHERE OWNER = 'REFERENCE'
AND OBJECT_TYPE IN ('INDEX', 'VIEW')
AND NOT EXISTS (SELECT * FROM ALL_OBJECTS a2
WHERE OWNER = 'ADEMPIERE' AND a1.OBJECT_NAME=a2.OBJECT_NAME
AND OBJECT_TYPE IN ('INDEX', 'VIEW'))
ORDER BY 2,1;

Some files were not shown because too many files have changed in this diff Show More