* Feature Request [ 1614535 ]
- Beta release for developer testing
This commit is contained in:
parent
145b27f48c
commit
7c8eb551ae
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
||||||
|
lib.dir=../lib
|
||||||
|
schemaoutputfile=../adempiere-model.xml
|
||||||
|
schemafiles=adempiere-model.xml
|
||||||
|
datafile=../adempiere-data.xml
|
||||||
|
sqloutputfile=adempiere-schema.sql
|
||||||
|
fkoutputfile=adempiere-fk.sql
|
||||||
|
alterdatabase=false
|
||||||
|
delimitedsqlidentifiers=true
|
|
@ -0,0 +1,110 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<project default="writeSchemaSqlToFile" name="DdlUtils" basedir=".">
|
||||||
|
<!-- Allow values set at the commandline or in the environment to override the defaults -->
|
||||||
|
<property environment="env" />
|
||||||
|
<!-- Load the jdbc properties as specified by the jdbc.properties.file variable-->
|
||||||
|
<property file="jdbc.properties.fyracle" />
|
||||||
|
<!-- Load the build properties -->
|
||||||
|
<property file="build-ddl.properties" />
|
||||||
|
|
||||||
|
<!-- These properties can be overriden on the commandline using -D -->
|
||||||
|
<property name="catalogpattern" value="" />
|
||||||
|
<property name="schemapattern" value="${ddlutils.schema}" />
|
||||||
|
<property name="platform" value="${ddlutils.platform}" />
|
||||||
|
<property name="alterdatabase" value="false" />
|
||||||
|
|
||||||
|
<!-- The classpath used for running the tasks -->
|
||||||
|
<path id="project-classpath">
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
<include name="**/*.zip" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DdlToDatabaseTask" name="ddlToDatabase" classpathref="project-classpath" />
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask" name="databaseToDdl" classpathref="project-classpath" />
|
||||||
|
|
||||||
|
<target name="createDb">
|
||||||
|
<ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<createdatabase failonerror="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaToDb">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschematodatabase alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="true" createforeignkeys="false" outputfile="${sqloutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeFkSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="false" createforeignkeys="true" outputfile="${fkoutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeSchemaToFile outputfile="${schemaoutputfile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeDataToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeDataToFile outputfile="${datafile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<target name="writeDataToDb">
|
||||||
|
<ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writedatatodatabase datafile="${datafile}" usebatchmode="false" ensureForeignKeyOrder="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
</project>
|
|
@ -0,0 +1,9 @@
|
||||||
|
fyracle.home=c:/Program Files/fyracle-0.8.10
|
||||||
|
|
||||||
|
fyracle.database=${basedir}/adempiere.fdb
|
||||||
|
fyracle.user=sysdba
|
||||||
|
fyracle.password=masterkey
|
||||||
|
|
||||||
|
#it can be deployed locally only now
|
||||||
|
fyracle.host=localhost
|
||||||
|
fyracle.port=3050
|
|
@ -0,0 +1,125 @@
|
||||||
|
<project name="export-data" default="create" basedir=".">
|
||||||
|
<property file="build.properties" />
|
||||||
|
<path id="lib.path">
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
<taskdef resource="net/sf/antcontrib/antlib.xml">
|
||||||
|
<classpath>
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
<target name="create" depends="init,create-database,load-init,create-schema,load-data,load-functions,load-others">
|
||||||
|
</target>
|
||||||
|
<target name="init">
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message=" Fyracle database transfer tool for Compiere ERP" />
|
||||||
|
<echo message=" Jotel sp.j. http://www.jotel.com.pl/compiere-port" />
|
||||||
|
<echo message=" Open Business Solutions" />
|
||||||
|
<echo message=" This util license is GNU GPL License" />
|
||||||
|
<echo message=" Adempiere Licese is GNU GPL License" />
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message="" file="log/plsql.log" append="false" />
|
||||||
|
<echo append="false" file="log/build.log" message="#Build log:${line.separator}${line.separator}" />
|
||||||
|
</target>
|
||||||
|
<target name="create-database">
|
||||||
|
<!-- make backup just in case -->
|
||||||
|
<move file="${fyracle.database}" tofile="backup/adempiere.fdb" failonerror="false" />
|
||||||
|
<copy file="template.fdb" tofile="${fyracle.database}" />
|
||||||
|
</target>
|
||||||
|
<target name="load-init">
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Load init.sql:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/init.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
<target name="create-schema">
|
||||||
|
<echo message="----- Creating tables -----" />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeSchemaSqlToFile" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-schema.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
<target name="load-functions">
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Functions:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../oracle/functions">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Procedures:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../oracle/procedures">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
</target>
|
||||||
|
<target name="load-data">
|
||||||
|
<echo message="----- Loading Adempiere Seed data -----" />
|
||||||
|
<unjar src="../adempiere-data.jar" dest=".." />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeDataToDb" />
|
||||||
|
<delete file="../adempiere-data.xml" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load-others">
|
||||||
|
<echo message="----- Loading other database object -----" />
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Temporary Tables:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/temptables.sql" />
|
||||||
|
</antcall>
|
||||||
|
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Views [1st Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Views [2nd Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Sequences:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../sequences">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<ant antfile="build-ddl.xml" target="writeFkSqlToFile" />
|
||||||
|
<echo file="log/plsql.log" append="true" message="${line.separator}#Create Foreign Keys:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-fk.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load">
|
||||||
|
<echo message="Loading file ${file.name}" />
|
||||||
|
<exec dir="${fyracle.home}\bin" executable="${fyracle.home}/bin/plsql" resultproperty="plsql.result" output="log/plsql.log" append="true">
|
||||||
|
<arg value="${fyracle.database}" />
|
||||||
|
<arg value="${file.name}" />
|
||||||
|
</exec>
|
||||||
|
<echo message="File ${file.name} status ${plsql.result}" />
|
||||||
|
<echo append="true" file="log/build.log">File ${file.name} status ${plsql.result}</echo>
|
||||||
|
<echo append="true" file="log/build.log" message="${line.separator}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/** Get Character at Position */
|
||||||
|
CREATE OR REPLACE FUNCTION charAt
|
||||||
|
(
|
||||||
|
p_string VARCHAR2,
|
||||||
|
p_pos NUMBER
|
||||||
|
)
|
||||||
|
RETURN VARCHAR2
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN SUBSTR(p_string, p_pos, 1);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** GetDate */
|
||||||
|
CREATE OR REPLACE FUNCTION getdate
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN SysDate;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** First Of DD/DY/MM/Q */
|
||||||
|
CREATE OR REPLACE FUNCTION firstOf
|
||||||
|
(
|
||||||
|
p_date DATE,
|
||||||
|
p_datePart VARCHAR2
|
||||||
|
)
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN TRUNC(p_date, p_datePart);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** Add Number of Days */
|
||||||
|
CREATE OR REPLACE FUNCTION addDays
|
||||||
|
(
|
||||||
|
p_date DATE,
|
||||||
|
p_days NUMBER
|
||||||
|
)
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN TRUNC(p_date) + p_days;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
CREATE OR REPLACE FUNCTION daysBetween
|
||||||
|
(
|
||||||
|
p_date1 DATE,
|
||||||
|
p_date2 DATE
|
||||||
|
)
|
||||||
|
RETURN NUMBER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN (TRUNC(p_date1) - TRUNC(p_date2));
|
||||||
|
END;
|
||||||
|
/
|
|
@ -0,0 +1,20 @@
|
||||||
|
# JDBC properties for Fyracle
|
||||||
|
# Note: Properties starting with "datasource." will be fed into the datasource instance of the
|
||||||
|
# class configured via the datasource.class property
|
||||||
|
|
||||||
|
# Use this property to choose the Oracle9 platform (instead of the Oracle8 default one)
|
||||||
|
ddlutils.platform=Oracle9
|
||||||
|
|
||||||
|
#
|
||||||
|
# Using the plain DBCP datasource
|
||||||
|
#
|
||||||
|
|
||||||
|
datasource.class=org.apache.commons.dbcp.BasicDataSource
|
||||||
|
datasource.driverClassName=org.firebirdsql.jdbc.FBDriver
|
||||||
|
datasource.url=jdbc:firebirdsql:oracle:localhost/3050:${basedir}/adempiere.fdb
|
||||||
|
datasource.username=sysdba
|
||||||
|
datasource.password=masterkey
|
||||||
|
|
||||||
|
# For oracle, we should limit the schema to the one of the user
|
||||||
|
# Note that Oracle requires this to be uppercase, even when using delimited identifiers
|
||||||
|
ddlutils.schema=ADEMPIERE
|
|
@ -0,0 +1,2 @@
|
||||||
|
Folder to store log generated from build
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,20 @@
|
||||||
|
DROP TABLE T_Selection CASCADE CONSTRAINTS;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
|
@ -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
|
|
@ -0,0 +1,8 @@
|
||||||
|
lib.dir=../lib
|
||||||
|
schemaoutputfile=../adempiere-model.xml
|
||||||
|
schemafiles=adempiere-model.xml
|
||||||
|
datafile=../adempiere-data.xml
|
||||||
|
sqloutputfile=adempiere-schema.sql
|
||||||
|
fkoutputfile=adempiere-fk.sql
|
||||||
|
alterdatabase=false
|
||||||
|
delimitedsqlidentifiers=true
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<project default="writeSchemaSqlToFile" name="DdlUtils" basedir=".">
|
||||||
|
<!-- Allow values set at the commandline or in the environment to override the defaults -->
|
||||||
|
<property environment="env" />
|
||||||
|
<!-- Load the jdbc properties as specified by the jdbc.properties.file variable-->
|
||||||
|
<property file="jdbc.properties.oracle10" />
|
||||||
|
<!-- Load the build properties -->
|
||||||
|
<property file="build-ddl.properties" />
|
||||||
|
|
||||||
|
<!-- These properties can be overriden on the commandline using -D -->
|
||||||
|
<property name="catalogpattern" value="" />
|
||||||
|
<property name="schemapattern" value="${ddlutils.schema}" />
|
||||||
|
<property name="platform" value="${ddlutils.platform}" />
|
||||||
|
|
||||||
|
|
||||||
|
<!-- The classpath used for running the tasks -->
|
||||||
|
<path id="project-classpath">
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
<include name="**/*.zip" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DdlToDatabaseTask" name="ddlToDatabase" classpathref="project-classpath" />
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask" name="databaseToDdl" classpathref="project-classpath" />
|
||||||
|
|
||||||
|
<target name="writeSchemaToDb">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschematodatabase alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="true" createforeignkeys="false" outputfile="${sqloutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeFkSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="false" createforeignkeys="true" outputfile="${fkoutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeSchemaToFile outputfile="${schemaoutputfile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeDataToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeDataToFile outputfile="${datafile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<target name="writeDataToDb">
|
||||||
|
<ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writedatatodatabase datafile="${datafile}" usebatchmode="false" ensureForeignKeyOrder="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
</project>
|
|
@ -0,0 +1,4 @@
|
||||||
|
oracle.home=C:/oracle/product/10.2.0/db_1
|
||||||
|
|
||||||
|
oracle.connect.param=adempiere/adempiere@orcl
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
<project name="create-db" default="create" basedir=".">
|
||||||
|
<property file="build.properties" />
|
||||||
|
<path id="lib.path">
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
<taskdef resource="net/sf/antcontrib/antlib.xml">
|
||||||
|
<classpath>
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<target name="create" depends="init,load-functions,create-schema,load-data,load-others">
|
||||||
|
</target>
|
||||||
|
<target name="init">
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message=" Oracle database create tool for Adempiere ERP" />
|
||||||
|
<echo message=" Adempiere Licese is GNU GPL License" />
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message="" file="log/sqlplus.log" append="false" />
|
||||||
|
<echo append="false" file="log/build.log" message="#Build log:${line.separator}${line.separator}" />
|
||||||
|
</target>
|
||||||
|
<target name="create-schema">
|
||||||
|
<echo message="----- Creating tables -----" />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeSchemaSqlToFile" />
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Tables:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-schema.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
<target name="load-data">
|
||||||
|
<echo message="----- Loading Adempiere Seed data -----" />
|
||||||
|
<unjar src="../adempiere-data.jar" dest=".." />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeDataToDb" />
|
||||||
|
<delete file="../adempiere-data.xml" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load-functions">
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Functions:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/init.sql" />
|
||||||
|
</antcall>
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="functions">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Procedures:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="procedures">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load-others">
|
||||||
|
<echo message="----- Loading other database objects -----" />
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Temporary Tables:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/temptables.sql" />
|
||||||
|
</antcall>
|
||||||
|
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Views [1st Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Views [2nd Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Sequences:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../sequences">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<ant antfile="build-ddl.xml" target="writeFkSqlToFile" />
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Create Foreign Keys:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-fk.sql" />
|
||||||
|
</antcall>
|
||||||
|
|
||||||
|
<echo file="log/sqlplus.log" append="true" message="${line.separator}#Cleanup and Recompile:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/AfterImport.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load">
|
||||||
|
<echo message="Loading file ${file.name}" />
|
||||||
|
<exec dir="${oracle.home}/bin" executable="${oracle.home}/bin/sqlplus" resultproperty="sqlplus.result" output="log/sqlplus.log" append="true">
|
||||||
|
<arg line="${oracle.connect.param}" />
|
||||||
|
<arg line="@${file.name}" />
|
||||||
|
</exec>
|
||||||
|
<echo message="File ${file.name} status ${sqlplus.result}" />
|
||||||
|
<echo append="true" file="log/build.log">File ${file.name} status ${sqlplus.result}</echo>
|
||||||
|
<echo append="true" file="log/build.log" message="${line.separator}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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
|
||||||
|
/******************************************************************************
|
||||||
|
* ** Compiere 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 Compiere" to
|
||||||
|
* your product name; See license details http://www.compiere.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;
|
||||||
|
/
|
|
@ -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
|
||||||
|
/******************************************************************************
|
||||||
|
* ** Compiere 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 Compiere" to
|
||||||
|
* your product name; See license details http://www.compiere.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;
|
||||||
|
/
|
|
@ -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
|
||||||
|
/******************************************************************************
|
||||||
|
* ** Compiere 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 Compiere" to
|
||||||
|
* your product name; See license details http://www.compiere.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;
|
||||||
|
/
|
|
@ -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
|
||||||
|
/******************************************************************************
|
||||||
|
* ** Compiere 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 Compiere" to
|
||||||
|
* your product name; See license details http://www.compiere.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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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 Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
||||||
|
|
|
@ -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;
|
||||||
|
/
|
|
@ -0,0 +1,84 @@
|
||||||
|
CREATE OR REPLACE FUNCTION productAttribute
|
||||||
|
(
|
||||||
|
p_M_AttributeSetInstance_ID IN NUMBER
|
||||||
|
)
|
||||||
|
RETURN VARCHAR2
|
||||||
|
/*************************************************************************
|
||||||
|
* The contents of this file are subject to the Compiere License. You may
|
||||||
|
* obtain a copy of the License at http://www.compiere.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: Compiere 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 VARCHAR2(2000) := NULL;
|
||||||
|
v_NameAdd VARCHAR2(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, '#'), COALESCE(a.SerNoCharEOverwrite, ''),
|
||||||
|
COALESCE(a.LotCharSOverwrite, '«'), COALESCE(a.LotCharEOverwrite, '»')
|
||||||
|
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;
|
||||||
|
/
|
|
@ -0,0 +1,55 @@
|
||||||
|
/** Get Character at Position */
|
||||||
|
CREATE OR REPLACE FUNCTION charAt
|
||||||
|
(
|
||||||
|
p_string VARCHAR2,
|
||||||
|
p_pos NUMBER
|
||||||
|
)
|
||||||
|
RETURN VARCHAR2
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN SUBSTR(p_string, p_pos, 1);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** GetDate */
|
||||||
|
CREATE OR REPLACE FUNCTION getdate
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN SysDate;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** First Of DD/DY/MM/Q */
|
||||||
|
CREATE OR REPLACE FUNCTION firstOf
|
||||||
|
(
|
||||||
|
p_date DATE,
|
||||||
|
p_datePart VARCHAR2
|
||||||
|
)
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN TRUNC(p_date, p_datePart);
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
/** Add Number of Days */
|
||||||
|
CREATE OR REPLACE FUNCTION addDays
|
||||||
|
(
|
||||||
|
p_date DATE,
|
||||||
|
p_days NUMBER
|
||||||
|
)
|
||||||
|
RETURN DATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN TRUNC(p_date) + p_days;
|
||||||
|
END;
|
||||||
|
/
|
||||||
|
CREATE OR REPLACE FUNCTION daysBetween
|
||||||
|
(
|
||||||
|
p_date1 DATE,
|
||||||
|
p_date2 DATE
|
||||||
|
)
|
||||||
|
RETURN NUMBER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
RETURN (TRUNC(p_date1) - TRUNC(p_date2));
|
||||||
|
END;
|
||||||
|
/
|
|
@ -0,0 +1,31 @@
|
||||||
|
# JDBC properties for Oracle10
|
||||||
|
# Note: Properties starting with "datasource." will be fed into the datasource instance of the
|
||||||
|
# class configured via the datasource.class property
|
||||||
|
|
||||||
|
# Use this property to choose the Oracle10 platform (instead of the Oracle8 default one)
|
||||||
|
ddlutils.platform=Oracle10
|
||||||
|
|
||||||
|
#
|
||||||
|
# Using the plain DBCP datasource
|
||||||
|
#
|
||||||
|
|
||||||
|
datasource.class=org.apache.commons.dbcp.BasicDataSource
|
||||||
|
datasource.driverClassName=oracle.jdbc.driver.OracleDriver
|
||||||
|
datasource.url=jdbc:oracle:thin:@localhost:1521:orcl
|
||||||
|
datasource.username=adempiere
|
||||||
|
datasource.password=adempiere
|
||||||
|
|
||||||
|
#
|
||||||
|
# Or the Oracle datasource
|
||||||
|
#
|
||||||
|
|
||||||
|
#datasource.class=oracle.jdbc.pool.OracleDataSource
|
||||||
|
#datasource.URL=jdbc:oracle:thin:@leesf:1521:orcl
|
||||||
|
#datasource.user=adempiere
|
||||||
|
#datasource.password=adempiere
|
||||||
|
#datasource.connectionCachingEnabled=true
|
||||||
|
|
||||||
|
|
||||||
|
# For oracle, we should limit the schema to the one of the user
|
||||||
|
# Note that Oracle requires this to be uppercase, even when using delimited identifiers
|
||||||
|
ddlutils.schema=ADEMPIERE
|
|
@ -0,0 +1,2 @@
|
||||||
|
Folder to store log generated from build
|
||||||
|
|
|
@ -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 || 'VARCHAR2(' || 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 || 'VARCHAR2(' || 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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -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;
|
||||||
|
/
|
|
@ -0,0 +1,20 @@
|
||||||
|
DROP TABLE T_Selection CASCADE CONSTRAINTS;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
lib.dir=../lib
|
||||||
|
schemaoutputfile=../adempiere-model.xml
|
||||||
|
schemafiles=adempiere-model.xml
|
||||||
|
datafile=../adempiere-data.xml
|
||||||
|
sqloutputfile=adempiere-schema.sql
|
||||||
|
fkoutputfile=adempiere-fk.sql
|
||||||
|
alterdatabase=false
|
||||||
|
delimitedsqlidentifiers=true
|
|
@ -0,0 +1,111 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
or more contributor license agreements. See the NOTICE file
|
||||||
|
distributed with this work for additional information
|
||||||
|
regarding copyright ownership. The ASF licenses this file
|
||||||
|
to you under the Apache License, Version 2.0 (the
|
||||||
|
"License"); you may not use this file except in compliance
|
||||||
|
with the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing,
|
||||||
|
software distributed under the License is distributed on an
|
||||||
|
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
KIND, either express or implied. See the License for the
|
||||||
|
specific language governing permissions and limitations
|
||||||
|
under the License.
|
||||||
|
-->
|
||||||
|
<project default="writeSchemaSqlToFile" name="DdlUtils" basedir=".">
|
||||||
|
<!-- Allow values set at the commandline or in the environment to override the defaults -->
|
||||||
|
<property environment="env" />
|
||||||
|
<!-- Load the jdbc properties as specified by the jdbc.properties.file variable-->
|
||||||
|
<property file="jdbc.properties.postgresql" />
|
||||||
|
<!-- Load the build properties -->
|
||||||
|
<property file="build-ddl.properties" />
|
||||||
|
|
||||||
|
<!-- These properties can be overriden on the commandline using -D -->
|
||||||
|
<property name="catalogpattern" value="" />
|
||||||
|
<property name="schemapattern" value="${ddlutils.schema}" />
|
||||||
|
<property name="platform" value="${ddlutils.platform}" />
|
||||||
|
|
||||||
|
<!-- The classpath used for running the tasks -->
|
||||||
|
<path id="project-classpath">
|
||||||
|
<fileset dir="${lib.dir}">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
<include name="**/*.zip" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DdlToDatabaseTask" name="ddlToDatabase" classpathref="project-classpath" />
|
||||||
|
<taskdef classname="org.apache.ddlutils.task.DatabaseToDdlTask" name="databaseToDdl" classpathref="project-classpath" />
|
||||||
|
|
||||||
|
<target name="createDb">
|
||||||
|
<ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<createdatabase failonerror="false">
|
||||||
|
<parameter name="ENCODING" value="'UTF8'" />
|
||||||
|
</createdatabase>
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaToDb">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschematodatabase alterdatabase="${alterdatabase}" dodrops="true" failonerror="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="true" createforeignkeys="false" outputfile="${sqloutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeFkSqlToFile">
|
||||||
|
<ddlToDatabase validatexml="false" usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writeschemasqltofile alterdatabase="${alterdatabase}" dodrops="false" failonerror="false" createtables="false" createforeignkeys="true" outputfile="${fkoutputfile}" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeSchemaToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeSchemaToFile outputfile="${schemaoutputfile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="writeDataToFile">
|
||||||
|
<databaseToDdl usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<writeDataToFile outputfile="${datafile}" />
|
||||||
|
</databaseToDdl>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
|
||||||
|
<target name="writeDataToDb">
|
||||||
|
<ddlToDatabase usedelimitedsqlidentifiers="${delimitedsqlidentifiers}" catalogpattern="${catalogpattern}" schemapattern="${schemapattern}" databasetype="${platform}">
|
||||||
|
<database driverclassname="${datasource.driverClassName}" url="${datasource.url}" username="${datasource.username}" password="${datasource.password}" />
|
||||||
|
<fileset dir="..">
|
||||||
|
<include name="${schemafiles}" />
|
||||||
|
</fileset>
|
||||||
|
|
||||||
|
<writedatatodatabase datafile="${datafile}" usebatchmode="true" batchSize="20" ensureForeignKeyOrder="false" />
|
||||||
|
</ddlToDatabase>
|
||||||
|
</target>
|
||||||
|
</project>
|
|
@ -0,0 +1,6 @@
|
||||||
|
postgresql.home=C:/Program Files/PostgreSQL/8.2
|
||||||
|
|
||||||
|
postgresql.database=adempiere
|
||||||
|
postgresql.user=adempiere
|
||||||
|
postgresql.password=adempiere1
|
||||||
|
sqlj.jar.url=file:///d:/Opensource/Applications/Adempiere/sqlj/sqlj.jar
|
|
@ -0,0 +1,118 @@
|
||||||
|
<project name="create-db" default="create" basedir=".">
|
||||||
|
<property file="build.properties" />
|
||||||
|
<path id="lib.path">
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
<taskdef resource="net/sf/antcontrib/antlib.xml">
|
||||||
|
<classpath>
|
||||||
|
<fileset dir="../lib">
|
||||||
|
<include name="**/*.jar" />
|
||||||
|
</fileset>
|
||||||
|
</classpath>
|
||||||
|
</taskdef>
|
||||||
|
|
||||||
|
<target name="create" depends="init,create-database,load-functions,create-schema,load-data,load-others">
|
||||||
|
</target>
|
||||||
|
<target name="init">
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message=" PostgreSQL database create tool for Adempiere ERP" />
|
||||||
|
<echo message=" Adempiere Licese is GNU GPL License" />
|
||||||
|
<echo message="============================================================" />
|
||||||
|
<echo message="" file="log/psql.log" append="false" />
|
||||||
|
<echo append="false" file="log/build.log" message="#Build log:${line.separator}${line.separator}" />
|
||||||
|
</target>
|
||||||
|
<target name="create-database">
|
||||||
|
<ant antfile="build-ddl.xml" target="createDb" />
|
||||||
|
</target>
|
||||||
|
<target name="create-schema">
|
||||||
|
<echo message="----- Creating tables -----" />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeSchemaSqlToFile" />
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Tables:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-schema.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
<target name="load-data">
|
||||||
|
<echo message="----- Loading Adempiere Seed data -----" />
|
||||||
|
<unjar src="../adempiere-data.jar" dest=".." />
|
||||||
|
<ant antfile="build-ddl.xml" target="writeDataToDb" />
|
||||||
|
<delete file="../adempiere-data.xml" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load-functions">
|
||||||
|
<echo append="false" file="load_sqlj_functions.sql">
|
||||||
|
CREATE SCHEMA adempiere;
|
||||||
|
</echo>
|
||||||
|
<echo append="true" file="load_sqlj_functions.sql">
|
||||||
|
SET search_path TO adempiere,sqlj;
|
||||||
|
</echo>
|
||||||
|
<echo append="true" file="load_sqlj_functions.sql">
|
||||||
|
SELECT sqlj.install_jar('${sqlj.jar.url}', 'sqlj', true);
|
||||||
|
</echo>
|
||||||
|
<echo append="true" file="load_sqlj_functions.sql">
|
||||||
|
SELECT sqlj.set_classpath('adempiere', 'sqlj');
|
||||||
|
</echo>
|
||||||
|
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Functions and Operators:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/load_sqlj_functions.sql" />
|
||||||
|
</antcall>
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/init.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load-others">
|
||||||
|
<echo message="----- Loading other database objects -----" />
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Views [1st Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Views [2nd Pass]:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../views">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Sequences:${line.separator}${line.separator}" />
|
||||||
|
<foreach param="file.name" target="load">
|
||||||
|
<path>
|
||||||
|
<fileset dir="../sequences">
|
||||||
|
<include name="**" />
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
<ant antfile="build-ddl.xml" target="writeFkSqlToFile" />
|
||||||
|
<echo file="log/psql.log" append="true" message="${line.separator}#Create Foreign Keys:${line.separator}${line.separator}" />
|
||||||
|
<antcall target="load">
|
||||||
|
<param name="file.name" value="${basedir}/adempiere-fk.sql" />
|
||||||
|
</antcall>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="load">
|
||||||
|
<echo message="Loading file ${file.name}" />
|
||||||
|
<exec dir="${postgresql.home}/bin" executable="${postgresql.home}/bin/psql" resultproperty="psql.result" output="log/psql.log" append="true">
|
||||||
|
<arg line="${postgresql.database}" />
|
||||||
|
<arg line="${postgresql.user}" />
|
||||||
|
<arg line="-f ${file.name}" />
|
||||||
|
<env key="PGPASSWORD" value="${postgresql.password}" />
|
||||||
|
</exec>
|
||||||
|
<echo message="File ${file.name} status ${psql.result}" />
|
||||||
|
<echo append="true" file="log/build.log">File ${file.name} status ${psql.result}</echo>
|
||||||
|
<echo append="true" file="log/build.log" message="${line.separator}" />
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</project>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/** Change Numeric for Integer */
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.ID (record NUMERIC)
|
||||||
|
RETURNS INTEGER AS $$
|
||||||
|
DECLARE
|
||||||
|
ID integer := 0;
|
||||||
|
BEGIN
|
||||||
|
ID := CAST(record AS INTEGER);
|
||||||
|
--RAISE NOTICE 'Quantity here is %', ID;
|
||||||
|
RETURN ID;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.getdate()
|
||||||
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN now();
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
/**TIMESTAMP WITH TIME ZONE **/
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.addDays (day TIMESTAMP WITH TIME ZONE, days DECIMAL)
|
||||||
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN adempiere.addDays(day,adempiere.ID(days));
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.subtractdays (day TIMESTAMP WITH TIME ZONE, days DECIMAL)
|
||||||
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN adempiere.addDays(day,adempiere.ID(days * -1));
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.addDays (day TIMESTAMP WITH TIME ZONE, days INTEGER)
|
||||||
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN adempiere.addDays(day,Idays);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION adempiere.subtractdays (day TIMESTAMP WITH TIME ZONE, days INTEGER)
|
||||||
|
RETURNS TIMESTAMP WITH TIME ZONE AS $$
|
||||||
|
BEGIN
|
||||||
|
RETURN adempiere.addDays(day,days * -1);
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql VOLATILE;
|
||||||
|
|
||||||
|
DROP OPERATOR adempiere.+ (timestamptz, INTEGER);
|
||||||
|
CREATE OPERATOR adempiere.+ ( PROCEDURE = adempiere.adddays,
|
||||||
|
LEFTARG = TIMESTAMPTZ, RIGHTARG = INTEGER,
|
||||||
|
COMMUTATOR = +);
|
||||||
|
|
||||||
|
DROP OPERATOR adempiere.- (timestamptz, INTEGER);
|
||||||
|
CREATE OPERATOR adempiere.- ( PROCEDURE = adempiere. subtractdays,
|
||||||
|
LEFTARG = TIMESTAMPTZ, RIGHTARG = INTEGER,
|
||||||
|
COMMUTATOR = -);
|
|
@ -0,0 +1,34 @@
|
||||||
|
# JDBC properties for PostgreSQL
|
||||||
|
# Note: Properties starting with "datasource." will be fed into the datasource instance of the
|
||||||
|
# class configured via the datasource.class property
|
||||||
|
|
||||||
|
# Use this property if ddlutils does not recognize the platform from the settings
|
||||||
|
ddlutils.platform=PostgreSQL
|
||||||
|
|
||||||
|
#
|
||||||
|
# Using the plain DBCP datasource
|
||||||
|
#
|
||||||
|
|
||||||
|
datasource.class=org.apache.commons.dbcp.BasicDataSource
|
||||||
|
datasource.driverClassName=org.postgresql.Driver
|
||||||
|
datasource.url=jdbc:postgresql://localhost/adempiere
|
||||||
|
datasource.username=adempiere
|
||||||
|
datasource.password=adempiere1
|
||||||
|
|
||||||
|
#
|
||||||
|
# PostgreSQL comes with its own DataSource implementations which can be configured like this:
|
||||||
|
#
|
||||||
|
|
||||||
|
#datasource.class=org.postgresql.ds.PGSimpleDataSource
|
||||||
|
# or this one for pooling:
|
||||||
|
#datasource.class=org.postgresql.ds.PGPoolingDataSource
|
||||||
|
|
||||||
|
#datasource.serverName=localhost
|
||||||
|
#datasource.databaseName=ddlutils
|
||||||
|
#datasource.user=
|
||||||
|
#datasource.password=
|
||||||
|
|
||||||
|
# additional properties for the pooling datasource:
|
||||||
|
#datasource.dataSourceName=pooling datasource
|
||||||
|
#datasource.initialConnections=5
|
||||||
|
#datasource.maxConnections=20
|
|
@ -0,0 +1,2 @@
|
||||||
|
Folder to store log generated from build
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
DROP SEQUENCE AD_Error_Seq;
|
||||||
|
|
||||||
|
CREATE SEQUENCE AD_Error_Seq START WITH 1 INCREMENT BY 1;
|
||||||
|
|
||||||
|
DROP SEQUENCE AD_PInstance_Seq;
|
||||||
|
|
||||||
|
CREATE SEQUENCE AD_PInstance_Seq START WITH 1 INCREMENT BY 1;
|
||||||
|
|
||||||
|
DROP SEQUENCE T_Spool_Seq;
|
||||||
|
|
||||||
|
CREATE SEQUENCE T_Spool_Seq START WITH 1 INCREMENT BY 1;
|
||||||
|
|
||||||
|
DROP SEQUENCE W_BASKET_SEQ;
|
||||||
|
|
||||||
|
CREATE SEQUENCE W_BASKET_SEQ START WITH 1 INCREMENT BY 1;
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_CHANGELOG_V
|
||||||
|
(AD_SESSION_ID, AD_CHANGELOG_ID, TABLENAME, RECORD_ID, COLUMNNAME,
|
||||||
|
OLDVALUE, NEWVALUE, NAME, CREATED)
|
||||||
|
AS
|
||||||
|
SELECT l.AD_Session_ID, l.AD_ChangeLog_ID,
|
||||||
|
t.TableName, l.Record_ID, c.ColumnName,
|
||||||
|
l.OldValue, l.NewValue,
|
||||||
|
u.Name, l.Created
|
||||||
|
FROM AD_ChangeLog l
|
||||||
|
INNER JOIN AD_Table t ON (l.AD_Table_ID=t.AD_Table_ID)
|
||||||
|
INNER JOIN AD_Column c ON (l.AD_Column_ID=c.AD_Column_ID)
|
||||||
|
INNER JOIN AD_User u ON (l.CreatedBy=u.AD_User_ID)
|
||||||
|
ORDER BY l.AD_Session_ID, l.AD_ChangeLog_ID, t.TableName, l.Record_ID, c.ColumnName;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_FIELD_V
|
||||||
|
(AD_WINDOW_ID, AD_TAB_ID, AD_FIELD_ID, AD_TABLE_ID, AD_COLUMN_ID,
|
||||||
|
NAME, DESCRIPTION, HELP, ISDISPLAYED, DISPLAYLOGIC,
|
||||||
|
DISPLAYLENGTH, SEQNO, SORTNO, ISSAMELINE, ISHEADING,
|
||||||
|
ISFIELDONLY, ISREADONLY, ISENCRYPTEDFIELD, OBSCURETYPE, COLUMNNAME,
|
||||||
|
COLUMNSQL, FIELDLENGTH, VFORMAT, DEFAULTVALUE, ISKEY,
|
||||||
|
ISPARENT, ISMANDATORY, ISIDENTIFIER, ISTRANSLATED, AD_REFERENCE_VALUE_ID,
|
||||||
|
CALLOUT, AD_REFERENCE_ID, AD_VAL_RULE_ID, AD_PROCESS_ID, ISALWAYSUPDATEABLE,
|
||||||
|
READONLYLOGIC, ISUPDATEABLE, ISENCRYPTEDCOLUMN, ISSELECTIONCOLUMN, TABLENAME,
|
||||||
|
VALUEMIN, VALUEMAX, FIELDGROUP, VALIDATIONCODE)
|
||||||
|
AS
|
||||||
|
SELECT t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID,
|
||||||
|
f.Name, f.Description, f.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength,
|
||||||
|
f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly,
|
||||||
|
f.IsEncrypted AS IsEncryptedField, f.ObscureType,
|
||||||
|
c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat, c.DefaultValue, c.IsKey, c.IsParent,
|
||||||
|
COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory,
|
||||||
|
c.IsIdentifier, c.IsTranslated, c.AD_Reference_Value_ID,
|
||||||
|
c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID,
|
||||||
|
c.AD_Val_Rule_ID, c.AD_Process_ID, c.IsAlwaysUpdateable,
|
||||||
|
c.ReadOnlyLogic, c.IsUpdateable, c.IsEncrypted AS IsEncryptedColumn,
|
||||||
|
c.IsSelectionColumn,
|
||||||
|
tbl.TableName, c.ValueMin, c.ValueMax,
|
||||||
|
fg.Name AS FieldGroup, vr.Code AS ValidationCode
|
||||||
|
FROM AD_Field f
|
||||||
|
INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||||
|
LEFT OUTER JOIN AD_FieldGroup fg ON (f.AD_FieldGroup_ID = fg.AD_FieldGroup_ID)
|
||||||
|
LEFT OUTER JOIN AD_Column c ON (f.AD_Column_ID = c.AD_Column_ID)
|
||||||
|
INNER JOIN AD_Table tbl ON (c.AD_Table_ID = tbl.AD_Table_ID)
|
||||||
|
INNER JOIN AD_Reference r ON (c.AD_Reference_ID = r.AD_Reference_ID)
|
||||||
|
LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID)
|
||||||
|
WHERE f.IsActive = 'Y'
|
||||||
|
AND c.IsActive = 'Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_FIELD_VT
|
||||||
|
(AD_LANGUAGE, AD_WINDOW_ID, AD_TAB_ID, AD_FIELD_ID, AD_TABLE_ID,
|
||||||
|
AD_COLUMN_ID, NAME, DESCRIPTION, HELP, ISDISPLAYED,
|
||||||
|
DISPLAYLOGIC, DISPLAYLENGTH, SEQNO, SORTNO, ISSAMELINE,
|
||||||
|
ISHEADING, ISFIELDONLY, ISREADONLY, ISENCRYPTEDFIELD, OBSCURETYPE,
|
||||||
|
COLUMNNAME, COLUMNSQL, FIELDLENGTH, VFORMAT, DEFAULTVALUE,
|
||||||
|
ISKEY, ISPARENT, ISMANDATORY, ISIDENTIFIER, ISTRANSLATED,
|
||||||
|
AD_REFERENCE_VALUE_ID, CALLOUT, AD_REFERENCE_ID, AD_VAL_RULE_ID, AD_PROCESS_ID,
|
||||||
|
ISALWAYSUPDATEABLE, READONLYLOGIC, ISUPDATEABLE, ISENCRYPTEDCOLUMN, ISSELECTIONCOLUMN,
|
||||||
|
TABLENAME, VALUEMIN, VALUEMAX, FIELDGROUP, VALIDATIONCODE)
|
||||||
|
AS
|
||||||
|
SELECT trl.AD_Language, t.AD_Window_ID, f.AD_Tab_ID, f.AD_Field_ID, tbl.AD_Table_ID, f.AD_Column_ID,
|
||||||
|
trl.Name, trl.Description, trl.Help, f.IsDisplayed, f.DisplayLogic, f.DisplayLength,
|
||||||
|
f.SeqNo, f.SortNo, f.IsSameLine, f.IsHeading, f.IsFieldOnly, f.IsReadOnly,
|
||||||
|
f.IsEncrypted AS IsEncryptedField, f.ObscureType,
|
||||||
|
c.ColumnName, c.ColumnSQL, c.FieldLength, c.VFormat, c.DefaultValue, c.IsKey, c.IsParent,
|
||||||
|
COALESCE(f.IsMandatory, c.IsMandatory) AS IsMandatory,
|
||||||
|
c.IsIdentifier, c.IsTranslated, c.AD_Reference_Value_ID,
|
||||||
|
c.Callout, COALESCE(f.AD_Reference_ID, c.AD_Reference_ID) AS AD_Reference_ID,
|
||||||
|
c.AD_Val_Rule_ID, c.AD_Process_ID, c.IsAlwaysUpdateable,
|
||||||
|
c.ReadOnlyLogic, c.IsUpdateable, c.IsEncrypted AS IsEncryptedColumn, c.IsSelectionColumn,
|
||||||
|
tbl.TableName, c.ValueMin, c.ValueMax,
|
||||||
|
fgt.Name AS FieldGroup, vr.Code AS ValidationCode
|
||||||
|
FROM AD_Field f
|
||||||
|
INNER JOIN AD_Field_Trl trl ON (f.AD_Field_ID = trl.AD_Field_ID)
|
||||||
|
INNER JOIN AD_Tab t ON (f.AD_Tab_ID = t.AD_Tab_ID)
|
||||||
|
LEFT OUTER JOIN AD_FieldGroup_Trl fgt ON
|
||||||
|
(f.AD_FieldGroup_ID = fgt.AD_FieldGroup_ID AND trl.AD_Language=fgt.AD_Language)
|
||||||
|
LEFT OUTER JOIN AD_Column c ON (f.AD_Column_ID = c.AD_Column_ID)
|
||||||
|
INNER JOIN AD_Table tbl ON (c.AD_Table_ID = tbl.AD_Table_ID)
|
||||||
|
INNER JOIN AD_Reference r ON (c.AD_Reference_ID = r.AD_Reference_ID)
|
||||||
|
LEFT OUTER JOIN AD_Val_Rule vr ON (c.AD_Val_Rule_ID=vr.AD_Val_Rule_ID)
|
||||||
|
WHERE f.IsActive = 'Y'
|
||||||
|
AND c.IsActive = 'Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_ORG_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, VALUE, NAME, DESCRIPTION,
|
||||||
|
ISSUMMARY, C_LOCATION_ID, DUNS, TAXID, SUPERVISOR_ID,
|
||||||
|
PARENT_ORG_ID, AD_ORGTYPE_ID, M_WAREHOUSE_ID, C_BPARTNER_ID)
|
||||||
|
AS
|
||||||
|
SELECT o.AD_Client_ID, o.AD_Org_ID,
|
||||||
|
o.IsActive, o.Created, o.CreatedBy, o.Updated, o.UpdatedBy,
|
||||||
|
o.Value, o.Name, o.Description, o.IsSummary,
|
||||||
|
i.C_Location_ID, i.DUNS, i.TaxID,
|
||||||
|
i.Supervisor_ID, i.Parent_Org_ID,
|
||||||
|
i.AD_OrgType_ID, i.M_Warehouse_ID,
|
||||||
|
bp.C_BPartner_ID
|
||||||
|
FROM AD_Org o
|
||||||
|
INNER JOIN AD_OrgInfo i ON (o.AD_Org_ID=i.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner bp ON (o.AD_Org_ID=bp.AD_OrgBP_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_TAB_V
|
||||||
|
(AD_TAB_ID, AD_WINDOW_ID, AD_TABLE_ID, NAME, DESCRIPTION,
|
||||||
|
HELP, SEQNO, ISSINGLEROW, HASTREE, ISINFOTAB,
|
||||||
|
REPLICATIONTYPE, TABLENAME, ACCESSLEVEL, ISSECURITYENABLED, ISDELETEABLE,
|
||||||
|
ISHIGHVOLUME, ISVIEW, HASASSOCIATION, ISTRANSLATIONTAB, ISREADONLY,
|
||||||
|
AD_IMAGE_ID, TABLEVEL, WHERECLAUSE, ORDERBYCLAUSE, COMMITWARNING,
|
||||||
|
READONLYLOGIC, DISPLAYLOGIC, AD_COLUMN_ID, AD_PROCESS_ID, ISSORTTAB,
|
||||||
|
ISINSERTRECORD, ISADVANCEDTAB, AD_COLUMNSORTORDER_ID, AD_COLUMNSORTYESNO_ID, INCLUDED_TAB_ID)
|
||||||
|
AS
|
||||||
|
SELECT t.AD_Tab_ID, t.AD_Window_ID, t.AD_Table_ID, t.Name, t.Description,
|
||||||
|
t.Help, t.SeqNo, t.IsSingleRow, t.HasTree, t.IsInfoTab, tbl.ReplicationType,
|
||||||
|
tbl.TableName, tbl.AccessLevel, tbl.IsSecurityEnabled, tbl.IsDeleteable,
|
||||||
|
tbl.IsHighVolume, tbl.IsView, 'N' AS HasAssociation, -- compatibility
|
||||||
|
t.IsTranslationTab, t.IsReadOnly, t.AD_Image_ID, t.TabLevel,
|
||||||
|
t.WhereClause, t.OrderByClause, t.CommitWarning, t.ReadOnlyLogic, t.DisplayLogic,
|
||||||
|
t.AD_Column_ID, t.AD_Process_ID, t.IsSortTab, t.IsInsertRecord, t.IsAdvancedTab,
|
||||||
|
t.AD_ColumnSortOrder_ID, t.AD_ColumnSortYesNo_ID, t.Included_Tab_ID
|
||||||
|
FROM AD_Tab t
|
||||||
|
INNER JOIN AD_Table tbl ON (t.AD_Table_ID = tbl.AD_Table_ID)
|
||||||
|
WHERE t.IsActive='Y'
|
||||||
|
AND tbl.IsActive='Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_TAB_VT
|
||||||
|
(AD_LANGUAGE, AD_TAB_ID, AD_WINDOW_ID, AD_TABLE_ID, NAME,
|
||||||
|
DESCRIPTION, HELP, SEQNO, ISSINGLEROW, HASTREE,
|
||||||
|
ISINFOTAB, REPLICATIONTYPE, TABLENAME, ACCESSLEVEL, ISSECURITYENABLED,
|
||||||
|
ISDELETEABLE, ISHIGHVOLUME, ISVIEW, HASASSOCIATION, ISTRANSLATIONTAB,
|
||||||
|
ISREADONLY, AD_IMAGE_ID, TABLEVEL, WHERECLAUSE, ORDERBYCLAUSE,
|
||||||
|
COMMITWARNING, READONLYLOGIC, DISPLAYLOGIC, AD_COLUMN_ID, AD_PROCESS_ID,
|
||||||
|
ISSORTTAB, ISINSERTRECORD, ISADVANCEDTAB, AD_COLUMNSORTORDER_ID, AD_COLUMNSORTYESNO_ID,
|
||||||
|
INCLUDED_TAB_ID)
|
||||||
|
AS
|
||||||
|
SELECT trl.AD_Language, t.AD_Tab_ID, t.AD_Window_ID, t.AD_Table_ID, trl.Name, trl.Description,
|
||||||
|
trl.Help, t.SeqNo, t.IsSingleRow, t.HasTree, t.IsInfoTab, tbl.ReplicationType,
|
||||||
|
tbl.TableName, tbl.AccessLevel, tbl.IsSecurityEnabled, tbl.IsDeleteable,
|
||||||
|
tbl.IsHighVolume, tbl.IsView, 'N' AS HasAssociation, -- compatibility
|
||||||
|
t.IsTranslationTab, t.IsReadOnly, t.AD_Image_ID, t.TabLevel,
|
||||||
|
t.WhereClause, t.OrderByClause, trl.CommitWarning, t.ReadOnlyLogic, t.DisplayLogic,
|
||||||
|
t.AD_Column_ID, t.AD_Process_ID, t.IsSortTab, t.IsInsertRecord, t.IsAdvancedTab,
|
||||||
|
t.AD_ColumnSortOrder_ID, t.AD_ColumnSortYesNo_ID, t.Included_Tab_ID
|
||||||
|
FROM AD_Tab t
|
||||||
|
INNER JOIN AD_Table tbl ON (t.AD_Table_ID = tbl.AD_Table_ID)
|
||||||
|
INNER JOIN AD_Tab_Trl trl ON (t.AD_Tab_ID = trl.AD_Tab_ID)
|
||||||
|
WHERE t.IsActive='Y'
|
||||||
|
AND tbl.IsActive='Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_USER_ROLES_V
|
||||||
|
(NAME, ROLENAME)
|
||||||
|
AS
|
||||||
|
SELECT u.Name, r.Name AS RoleName
|
||||||
|
FROM AD_User_Roles ur
|
||||||
|
INNER JOIN AD_User u ON (ur.AD_User_ID=u.AD_User_ID)
|
||||||
|
INNER JOIN AD_Role r ON (ur.AD_Role_ID=r.AD_Role_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
CREATE OR REPLACE VIEW AD_WINDOW_VT
|
||||||
|
(AD_LANGUAGE, AD_WINDOW_ID, NAME, DESCRIPTION, HELP,
|
||||||
|
WINDOWTYPE, AD_COLOR_ID, AD_IMAGE_ID, ISACTIVE, WINWIDTH,
|
||||||
|
WINHEIGHT, ISSOTRX)
|
||||||
|
AS
|
||||||
|
SELECT trl.AD_Language,
|
||||||
|
bt.AD_Window_ID, trl.Name, trl.Description, trl.Help, bt.WindowType,
|
||||||
|
bt.AD_Color_ID, bt.AD_Image_ID, bt.IsActive, bt.WinWidth, bt.WinHeight,
|
||||||
|
bt.IsSOTrx
|
||||||
|
FROM AD_Window bt
|
||||||
|
INNER JOIN AD_Window_Trl trl ON (bt.AD_Window_ID=trl.AD_Window_ID)
|
||||||
|
WHERE bt.IsActive='Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
CREATE OR REPLACE VIEW C_DUNNING_HEADER_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_DUNNINGRUN_ID, C_DUNNINGRUNENTRY_ID,
|
||||||
|
DUNNINGDATE, PRINTNAME, DOCUMENTNOTE, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
SALESREP_ID, SALESREP_NAME, BPGREETING, NAME, NAME2,
|
||||||
|
BPCONTACTGREETING, TITLE, PHONE, CONTACTNAME, C_LOCATION_ID,
|
||||||
|
REFERENCENO, POSTAL, AMT, QTY, NOTE)
|
||||||
|
AS
|
||||||
|
SELECT dr.AD_Client_ID, dr.AD_Org_ID, dr.IsActive, dr.Created, dr.CreatedBy, dr.Updated, dr.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language, dr.C_DunningRun_ID, C_DunningRunEntry_ID,
|
||||||
|
dr.DunningDate, dl.PrintName, dl.Note AS DocumentNote,
|
||||||
|
dre.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
dre.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, bp.ReferenceNo, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
dre.Amt, dre.Qty, dre.Note
|
||||||
|
FROM C_DunningRun dr
|
||||||
|
INNER JOIN C_DunningLevel dl ON (dr.C_DunningLevel_ID=dl.C_DunningLevel_ID)
|
||||||
|
INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (dre.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (dre.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (dre.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpcg on (bpc.C_Greeting_ID=bpcg.C_Greeting_ID)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (dr.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (dre.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
CREATE OR REPLACE VIEW C_DUNNING_HEADER_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_DUNNINGRUN_ID, C_DUNNINGRUNENTRY_ID,
|
||||||
|
DUNNINGDATE, PRINTNAME, DOCUMENTNOTE, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
SALESREP_ID, SALESREP_NAME, BPGREETING, NAME, NAME2,
|
||||||
|
BPCONTACTGREETING, TITLE, PHONE, CONTACTNAME, C_LOCATION_ID,
|
||||||
|
REFERENCENO, POSTAL, AMT, QTY, NOTE)
|
||||||
|
AS
|
||||||
|
SELECT dr.AD_Client_ID, dr.AD_Org_ID, dr.IsActive, dr.Created, dr.CreatedBy, dr.Updated, dr.UpdatedBy,
|
||||||
|
dlt.AD_Language, dr.C_DunningRun_ID, C_DunningRunEntry_ID,
|
||||||
|
dr.DunningDate, dlt.PrintName, dlt.Note AS DocumentNote,
|
||||||
|
dre.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
dre.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, bp.ReferenceNo, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
dre.Amt, dre.Qty, dre.Note
|
||||||
|
FROM C_DunningRun dr
|
||||||
|
INNER JOIN C_DunningLevel dl ON (dr.C_DunningLevel_ID=dl.C_DunningLevel_ID)
|
||||||
|
INNER JOIN C_DunningLevel_Trl dlt ON (dl.C_DunningLevel_ID=dlt.C_DunningLevel_ID)
|
||||||
|
INNER JOIN C_DunningRunEntry dre ON (dr.C_DunningRun_ID=dre.C_DunningRun_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (dre.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID
|
||||||
|
AND dlt.AD_Language=bpg.AD_Language)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (dre.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (dre.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpcg on (bpc.C_Greeting_ID=bpcg.C_Greeting_ID
|
||||||
|
AND dlt.AD_Language=bpcg.AD_Language)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (dr.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (dre.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
CREATE OR REPLACE VIEW C_DUNNING_LINE_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_DUNNINGRUNLINE_ID, C_DUNNINGRUNENTRY_ID,
|
||||||
|
AMT, CONVERTEDAMT, DAYSDUE, TIMESDUNNED, INTERESTAMT,
|
||||||
|
FEEAMT, TOTALAMT, C_INVOICE_ID, ISSOTRX, DOCUMENTNO,
|
||||||
|
DOCSTATUS, DATETRX, C_DOCTYPE_ID, DOCUMENTTYPE, DESCRIPTION,
|
||||||
|
C_CURRENCY_ID, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, USER1_ID,
|
||||||
|
USER2_ID, DATEACCT, C_CONVERSIONTYPE_ID, AD_ORGTRX_ID, POREFERENCE,
|
||||||
|
DATEORDERED, DATEINVOICED, ISINDISPUTE, PAYMENTTERM, C_CHARGE_ID,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID,
|
||||||
|
ISPAID, ISALLOCATED, TENDERTYPE, DISCOUNTAMT)
|
||||||
|
AS
|
||||||
|
SELECT drl.AD_Client_ID, drl.AD_Org_ID, drl.IsActive, drl.Created, drl.CreatedBy, drl.Updated, drl.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
drl.C_DunningRunLine_ID, drl.C_DunningRunEntry_ID,
|
||||||
|
drl.Amt, drl.ConvertedAmt, drl.DaysDue, drl.TimesDunned,
|
||||||
|
drl.InterestAmt, drl.FeeAmt, drl.TotalAmt,
|
||||||
|
drl.C_Invoice_ID,
|
||||||
|
COALESCE(i.IsSOTrx,p.IsReceipt) AS IsSOTrx,
|
||||||
|
COALESCE(i.DocumentNo,p.DocumentNo) AS DocumentNo,
|
||||||
|
COALESCE(i.DocStatus,p.DocStatus) AS DocStatus,
|
||||||
|
COALESCE(i.DateInvoiced, p.DateTrx) AS DateTrx,
|
||||||
|
COALESCE(i.C_DocType_ID,p.C_DocType_ID) AS C_DocType_ID,
|
||||||
|
COALESCE(dt.PrintName,dtp.PrintName) AS DocumentType,
|
||||||
|
COALESCE(i.Description,p.Description) AS Description,
|
||||||
|
COALESCE(i.C_Currency_ID,p.C_Currency_ID) AS C_Currency_ID,
|
||||||
|
COALESCE(i.C_Campaign_ID,p.C_Campaign_ID) AS C_Campaign_ID,
|
||||||
|
COALESCE(i.C_Project_ID,p.C_Project_ID) AS C_Project_ID,
|
||||||
|
COALESCE(i.C_Activity_ID,p.C_Activity_ID) AS C_Activity_ID,
|
||||||
|
COALESCE(i.User1_ID,p.User1_ID) AS User1_ID,
|
||||||
|
COALESCE(i.User2_ID,p.User2_ID) AS User2_ID,
|
||||||
|
COALESCE(i.DateAcct,p.DateAcct) AS DateAcct,
|
||||||
|
COALESCE(i.C_ConversionType_ID,i.C_ConversionType_ID) AS C_ConversionType_ID,
|
||||||
|
COALESCE(i.AD_OrgTrx_ID,p.AD_OrgTrx_ID) AS AD_OrgTrx_ID,
|
||||||
|
i.POReference, i.DateOrdered,
|
||||||
|
i.DateInvoiced, i.IsInDispute,
|
||||||
|
pt.Name AS PaymentTerm,
|
||||||
|
i.C_Charge_ID, i.ChargeAmt,
|
||||||
|
i.TotalLines, i.GrandTotal, i.GrandTotal AS AmtInWords,
|
||||||
|
i.M_PriceList_ID, i.IsPaid,
|
||||||
|
p.IsAllocated, p.TenderType, p.DiscountAmt
|
||||||
|
FROM C_DunningRunLine drl
|
||||||
|
LEFT OUTER JOIN C_Invoice i ON (drl.C_Invoice_ID=i.C_Invoice_ID)
|
||||||
|
LEFT OUTER JOIN C_DocType dt ON (i.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
LEFT OUTER JOIN C_PaymentTerm pt ON (i.C_PaymentTerm_ID=pt.C_PaymentTerm_ID)
|
||||||
|
LEFT OUTER JOIN C_Payment p ON (drl.C_Payment_ID=p.C_Payment_ID)
|
||||||
|
LEFT OUTER JOIN C_DocType dtp ON (p.C_DocType_ID=dtp.C_DocType_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
CREATE OR REPLACE VIEW C_DUNNING_LINE_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_DUNNINGRUNLINE_ID, C_DUNNINGRUNENTRY_ID,
|
||||||
|
AMT, CONVERTEDAMT, DAYSDUE, TIMESDUNNED, INTERESTAMT,
|
||||||
|
FEEAMT, TOTALAMT, C_INVOICE_ID, ISSOTRX, DOCUMENTNO,
|
||||||
|
DOCSTATUS, DATETRX, C_DOCTYPE_ID, DOCUMENTTYPE, DESCRIPTION,
|
||||||
|
C_CURRENCY_ID, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, USER1_ID,
|
||||||
|
USER2_ID, DATEACCT, C_CONVERSIONTYPE_ID, AD_ORGTRX_ID, POREFERENCE,
|
||||||
|
DATEORDERED, DATEINVOICED, ISINDISPUTE, PAYMENTTERM, C_CHARGE_ID,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID,
|
||||||
|
ISPAID, ISALLOCATED, TENDERTYPE, DISCOUNTAMT)
|
||||||
|
AS
|
||||||
|
SELECT drl.AD_Client_ID, drl.AD_Org_ID, drl.IsActive, drl.Created, drl.CreatedBy, drl.Updated, drl.UpdatedBy,
|
||||||
|
COALESCE(dt.AD_Language,dtp.AD_Language) AS AD_Language,
|
||||||
|
drl.C_DunningRunLine_ID, drl.C_DunningRunEntry_ID,
|
||||||
|
drl.Amt, drl.ConvertedAmt, drl.DaysDue, drl.TimesDunned,
|
||||||
|
drl.InterestAmt, drl.FeeAmt, drl.TotalAmt,
|
||||||
|
drl.C_Invoice_ID,
|
||||||
|
COALESCE(i.IsSOTrx,p.IsReceipt) AS IsSOTrx,
|
||||||
|
COALESCE(i.DocumentNo,p.DocumentNo) AS DocumentNo,
|
||||||
|
COALESCE(i.DocStatus,p.DocStatus) AS DocStatus,
|
||||||
|
COALESCE(i.DateInvoiced, p.DateTrx) AS DateTrx,
|
||||||
|
COALESCE(i.C_DocType_ID,p.C_DocType_ID) AS C_DocType_ID,
|
||||||
|
COALESCE(dt.PrintName,dtp.PrintName) AS DocumentType,
|
||||||
|
COALESCE(i.Description,p.Description) AS Description,
|
||||||
|
COALESCE(i.C_Currency_ID,p.C_Currency_ID) AS C_Currency_ID,
|
||||||
|
COALESCE(i.C_Campaign_ID,p.C_Campaign_ID) AS C_Campaign_ID,
|
||||||
|
COALESCE(i.C_Project_ID,p.C_Project_ID) AS C_Project_ID,
|
||||||
|
COALESCE(i.C_Activity_ID,p.C_Activity_ID) AS C_Activity_ID,
|
||||||
|
COALESCE(i.User1_ID,p.User1_ID) AS User1_ID,
|
||||||
|
COALESCE(i.User2_ID,p.User2_ID) AS User2_ID,
|
||||||
|
COALESCE(i.DateAcct,p.DateAcct) AS DateAcct,
|
||||||
|
COALESCE(i.C_ConversionType_ID,i.C_ConversionType_ID) AS C_ConversionType_ID,
|
||||||
|
COALESCE(i.AD_OrgTrx_ID,p.AD_OrgTrx_ID) AS AD_OrgTrx_ID,
|
||||||
|
i.POReference, i.DateOrdered,
|
||||||
|
i.DateInvoiced, i.IsInDispute,
|
||||||
|
pt.Name AS PaymentTerm,
|
||||||
|
i.C_Charge_ID, i.ChargeAmt,
|
||||||
|
i.TotalLines, i.GrandTotal, i.GrandTotal AS AmtInWords,
|
||||||
|
i.M_PriceList_ID, i.IsPaid,
|
||||||
|
p.IsAllocated, p.TenderType, p.DiscountAmt
|
||||||
|
FROM C_DunningRunLine drl
|
||||||
|
LEFT OUTER JOIN C_Invoice i ON (drl.C_Invoice_ID=i.C_Invoice_ID)
|
||||||
|
LEFT OUTER JOIN C_DocType_Trl dt ON (i.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
LEFT OUTER JOIN C_PaymentTerm_Trl pt ON (i.C_PaymentTerm_ID=pt.C_PaymentTerm_ID
|
||||||
|
AND pt.AD_Language=dt.AD_Language)
|
||||||
|
LEFT OUTER JOIN C_Payment p ON (drl.C_Payment_ID=p.C_Payment_ID)
|
||||||
|
LEFT OUTER JOIN C_DocType_Trl dtp ON (p.C_DocType_ID=dtp.C_DocType_ID)
|
||||||
|
WHERE COALESCE(dt.AD_Language,dtp.AD_Language)=COALESCE(dtp.AD_Language,dt.AD_Language);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICELINE_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, C_INVOICELINE_ID, C_INVOICE_ID, SALESREP_ID,
|
||||||
|
C_BPARTNER_ID, M_PRODUCT_ID, DOCUMENTNO, DATEINVOICED, DATEACCT,
|
||||||
|
ISSOTRX, DOCSTATUS, LINENETAMT, LINELISTAMT, LINELIMITAMT,
|
||||||
|
LINEDISCOUNTAMT, LINEOVERLIMITAMT, QTYINVOICED, QTYENTERED, LINE,
|
||||||
|
C_ORDERLINE_ID, C_UOM_ID, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID,
|
||||||
|
C_PROJECTPHASE_ID, C_PROJECTTASK_ID)
|
||||||
|
AS
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID,
|
||||||
|
il.C_InvoiceLine_ID, i.C_Invoice_ID, i.SalesRep_ID,
|
||||||
|
i.C_BPartner_ID, il.M_Product_ID,
|
||||||
|
i.DocumentNo, i.DateInvoiced, i.DateAcct,
|
||||||
|
i.IsSOTrx, i.DocStatus,
|
||||||
|
ROUND(i.Multiplier*LineNetAmt, 2) AS LineNetAmt,
|
||||||
|
ROUND(i.Multiplier*PriceList*QtyInvoiced, 2) AS LineListAmt,
|
||||||
|
CASE WHEN COALESCE(il.PriceLimit, 0)=0 THEN ROUND(i.Multiplier*LineNetAmt,2) ELSE ROUND(i.Multiplier*PriceLimit*QtyInvoiced,2) END AS LineLimitAmt,
|
||||||
|
ROUND(i.Multiplier*PriceList*QtyInvoiced-LineNetAmt,2) AS LineDiscountAmt,
|
||||||
|
CASE WHEN COALESCE(il.PriceLimit,0)=0 THEN 0 ELSE ROUND(i.Multiplier*LineNetAmt-PriceLimit*QtyInvoiced,2) END AS LineOverLimitAmt,
|
||||||
|
il.QtyInvoiced, il.QtyEntered,
|
||||||
|
il.Line, il.C_OrderLine_ID, il.C_UOM_ID,
|
||||||
|
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
|
||||||
|
FROM C_Invoice_v i, C_InvoiceLine il
|
||||||
|
WHERE i.C_Invoice_ID=il.C_Invoice_ID;
|
||||||
|
|
||||||
|
--COMMENT ON TABLE C_INVOICELINE_V IS 'Invoice Line Summary for Reporting Views - Corrected for Credit Memos';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_CANDIDATE_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, C_BPARTNER_ID, C_ORDER_ID, DOCUMENTNO,
|
||||||
|
DATEORDERED, C_DOCTYPE_ID, TOTALLINES)
|
||||||
|
AS
|
||||||
|
SELECT
|
||||||
|
o.AD_Client_ID, o.AD_Org_ID, o.C_BPartner_ID, o.C_Order_ID,
|
||||||
|
o.DocumentNo, o.DateOrdered, o.C_DocType_ID,
|
||||||
|
SUM((l.QtyOrdered-l.QtyInvoiced)*l.PriceActual) AS TotalLines
|
||||||
|
FROM C_Order o
|
||||||
|
INNER JOIN C_OrderLine l ON (o.C_Order_ID=l.C_Order_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_InvoiceSchedule si ON (bp.C_InvoiceSchedule_ID=si.C_InvoiceSchedule_ID)
|
||||||
|
WHERE o.DocStatus IN ('CO','CL','IP') -- Standard Orders are IP
|
||||||
|
-- not Offers and open Walkin-Receipts
|
||||||
|
AND o.C_DocType_ID IN (SELECT C_DocType_ID FROM C_DocType
|
||||||
|
WHERE DocBaseType='SOO' AND DocSubTypeSO NOT IN ('ON','OB','WR'))
|
||||||
|
-- we need to invoice
|
||||||
|
AND l.QtyOrdered <> l.QtyInvoiced
|
||||||
|
--
|
||||||
|
AND (
|
||||||
|
-- Immediate
|
||||||
|
o.InvoiceRule='I'
|
||||||
|
-- Order compete ** not supported **
|
||||||
|
OR o.InvoiceRule='O'
|
||||||
|
-- Delivery
|
||||||
|
OR (o.InvoiceRule='D' AND l.QtyInvoiced<>l.QtyDelivered)
|
||||||
|
-- Order Schedule, but none defined on Business Partner level
|
||||||
|
OR (o.InvoiceRule='S' AND bp.C_InvoiceSchedule_ID IS NULL)
|
||||||
|
-- Schedule defined at BP
|
||||||
|
OR (o.InvoiceRule='S' AND bp.C_InvoiceSchedule_ID IS NOT NULL AND
|
||||||
|
(
|
||||||
|
-- Daily or none
|
||||||
|
(si.InvoiceFrequency IS NULL OR si.InvoiceFrequency='D')
|
||||||
|
-- Weekly
|
||||||
|
OR (si.InvoiceFrequency='W')
|
||||||
|
-- Bi-Monthly
|
||||||
|
OR (si.InvoiceFrequency='T'
|
||||||
|
AND ((TRUNC(o.DateOrdered) <= firstOf(getdate(),'MM')+si.InvoiceDayCutoff-1
|
||||||
|
AND TRUNC(getdate()) >= firstOf(o.DateOrdered,'MM')+si.InvoiceDay-1)
|
||||||
|
OR (TRUNC(o.DateOrdered) <= firstOf(getdate(),'MM')+si.InvoiceDayCutoff+14
|
||||||
|
AND TRUNC(getdate()) >= firstOf(o.DateOrdered,'MM')+si.InvoiceDay+14))
|
||||||
|
)
|
||||||
|
-- Monthly
|
||||||
|
OR (si.InvoiceFrequency='M'
|
||||||
|
AND TRUNC(o.DateOrdered) <= firstOf(getdate(),'MM')+si.InvoiceDayCutoff-1 -- after cutoff
|
||||||
|
AND TRUNC(getdate()) >= firstOf(o.DateOrdered,'MM')+si.InvoiceDay-1) -- after invoice day
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
GROUP BY o.AD_Client_ID, o.AD_Org_ID, o.C_BPartner_ID, o.C_Order_ID,
|
||||||
|
o.DocumentNo, o.DateOrdered, o.C_DocType_ID;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_HEADER_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_INVOICE_ID, ISSOTRX,
|
||||||
|
DOCUMENTNO, DOCSTATUS, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
DOCUMENTTYPE, DOCUMENTTYPENOTE, C_ORDER_ID, SALESREP_ID, SALESREP_NAME,
|
||||||
|
DATEINVOICED, BPGREETING, NAME, NAME2, BPCONTACTGREETING,
|
||||||
|
TITLE, PHONE, CONTACTNAME, C_LOCATION_ID, REFERENCENO,
|
||||||
|
POSTAL, DESCRIPTION, POREFERENCE, DATEORDERED, C_CURRENCY_ID,
|
||||||
|
PAYMENTTERM, PAYMENTTERMNOTE, C_CHARGE_ID, CHARGEAMT, TOTALLINES,
|
||||||
|
GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID, ISTAXINCLUDED, C_CAMPAIGN_ID,
|
||||||
|
C_PROJECT_ID, C_ACTIVITY_ID, ISPAID)
|
||||||
|
AS
|
||||||
|
SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
i.C_Invoice_ID, i.IsSOTrx, i.DocumentNo, i.DocStatus, i.C_DocType_ID,
|
||||||
|
i.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
dt.PrintName AS DocumentType, dt.DocumentNote AS DocumentTypeNote,
|
||||||
|
i.C_Order_ID, i.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
i.DateInvoiced,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, bp.ReferenceNo, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
i.Description,
|
||||||
|
i.POReference,
|
||||||
|
i.DateOrdered,
|
||||||
|
i.C_Currency_ID,
|
||||||
|
pt.Name AS PaymentTerm, pt.DocumentNote AS PaymentTermNote,
|
||||||
|
i.C_Charge_ID, i.ChargeAmt,
|
||||||
|
i.TotalLines,
|
||||||
|
i.GrandTotal, i.GrandTotal AS AmtInWords,
|
||||||
|
i.M_PriceList_ID,
|
||||||
|
i.IsTaxIncluded,
|
||||||
|
i.C_Campaign_ID,
|
||||||
|
i.C_Project_ID,
|
||||||
|
i.C_Activity_ID,
|
||||||
|
i.IsPaid
|
||||||
|
FROM C_Invoice i
|
||||||
|
INNER JOIN C_DocType dt ON (i.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
INNER JOIN C_PaymentTerm pt ON (i.C_PaymentTerm_ID=pt.C_PaymentTerm_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (i.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (i.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (i.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpcg on (bpc.C_Greeting_ID=bpcg.C_Greeting_ID)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (i.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (i.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_HEADER_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_INVOICE_ID, ISSOTRX,
|
||||||
|
DOCUMENTNO, DOCSTATUS, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
DOCUMENTTYPE, DOCUMENTTYPENOTE, C_ORDER_ID, SALESREP_ID, SALESREP_NAME,
|
||||||
|
DATEINVOICED, BPGREETING, NAME, NAME2, BPCONTACTGREETING,
|
||||||
|
TITLE, PHONE, CONTACTNAME, C_LOCATION_ID, REFERENCENO,
|
||||||
|
POSTAL, DESCRIPTION, POREFERENCE, DATEORDERED, C_CURRENCY_ID,
|
||||||
|
PAYMENTTERM, PAYMENTTERMNOTE, C_CHARGE_ID, CHARGEAMT, TOTALLINES,
|
||||||
|
GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID, ISTAXINCLUDED, C_CAMPAIGN_ID,
|
||||||
|
C_PROJECT_ID, C_ACTIVITY_ID, ISPAID)
|
||||||
|
AS
|
||||||
|
SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
dt.AD_Language,
|
||||||
|
i.C_Invoice_ID, i.IsSOTrx, i.DocumentNo, i.DocStatus, i.C_DocType_ID,
|
||||||
|
i.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
dt.PrintName AS DocumentType, dt.DocumentNote AS DocumentTypeNote,
|
||||||
|
i.C_Order_ID, i.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
i.DateInvoiced,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, bp.ReferenceNo, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
i.Description,
|
||||||
|
i.POReference,
|
||||||
|
i.DateOrdered,
|
||||||
|
i.C_Currency_ID,
|
||||||
|
pt.Name AS PaymentTerm, pt.DocumentNote AS PaymentTermNote,
|
||||||
|
i.C_Charge_ID, i.ChargeAmt,
|
||||||
|
i.TotalLines,
|
||||||
|
i.GrandTotal, i.GrandTotal AS AmtInWords,
|
||||||
|
i.M_PriceList_ID,
|
||||||
|
i.IsTaxIncluded,
|
||||||
|
i.C_Campaign_ID,
|
||||||
|
i.C_Project_ID,
|
||||||
|
i.C_Activity_ID,
|
||||||
|
i.IsPaid
|
||||||
|
FROM C_Invoice i
|
||||||
|
INNER JOIN C_DocType_Trl dt ON (i.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
INNER JOIN C_PaymentTerm_Trl pt ON (i.C_PaymentTerm_ID=pt.C_PaymentTerm_ID AND dt.AD_Language=pt.AD_Language)
|
||||||
|
INNER JOIN C_BPartner bp ON (i.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID AND dt.AD_Language=bpg.AD_Language)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (i.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (i.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpcg on (bpc.C_Greeting_ID=bpcg.C_Greeting_ID AND dt.AD_Language=bpcg.AD_Language)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (i.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (i.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_LINETAX_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_INVOICE_ID, C_INVOICELINE_ID,
|
||||||
|
C_TAX_ID, TAXAMT, LINETOTALAMT, TAXINDICATOR, LINE,
|
||||||
|
M_PRODUCT_ID, QTYINVOICED, QTYENTERED, UOMSYMBOL, NAME,
|
||||||
|
DESCRIPTION, DOCUMENTNOTE, UPC, SKU, PRODUCTVALUE,
|
||||||
|
RESOURCEDESCRIPTION, PRICELIST, PRICEENTEREDLIST, DISCOUNT, PRICEACTUAL,
|
||||||
|
PRICEENTERED, LINENETAMT, M_ATTRIBUTESETINSTANCE_ID, M_ATTRIBUTESET_ID, SERNO,
|
||||||
|
LOT, M_LOT_ID, GUARANTEEDATE, PRODUCTDESCRIPTION, IMAGEURL,
|
||||||
|
C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, C_PROJECTPHASE_ID, C_PROJECTTASK_ID)
|
||||||
|
AS
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
il.C_Tax_ID, il.TaxAmt, il.LineTotalAmt, t.TaxIndicator,
|
||||||
|
il.Line, p.M_Product_ID,
|
||||||
|
CASE WHEN il.QtyInvoiced<>0 OR il.M_Product_ID IS NOT NULL THEN il.QtyInvoiced END AS QtyInvoiced,
|
||||||
|
CASE WHEN il.QtyEntered<>0 OR il.M_Product_ID IS NOT NULL THEN il.QtyEntered END AS QtyEntered,
|
||||||
|
CASE WHEN il.QtyEntered<>0 OR il.M_Product_ID IS NOT NULL THEN uom.UOMSymbol END AS UOMSymbol,
|
||||||
|
COALESCE(c.Name,p.Name||productAttribute(il.M_AttributeSetInstance_ID), il.Description) AS Name, -- main line
|
||||||
|
CASE WHEN COALESCE(c.Name,p.Name) IS NOT NULL THEN il.Description END AS Description, -- second line
|
||||||
|
p.DocumentNote, -- third line
|
||||||
|
p.UPC, p.SKU, COALESCE(pp.VendorProductNo,p.Value) AS ProductValue,
|
||||||
|
ra.Description AS ResourceDescription, -- forth line
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList<>0
|
||||||
|
THEN il.PriceList END AS PriceList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList<>0 AND il.QtyEntered<>0
|
||||||
|
THEN il.PriceList*il.QtyInvoiced/il.QtyEntered END AS PriceEnteredList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList>il.PriceActual AND il.PriceList<>0
|
||||||
|
THEN (il.PriceList-il.PriceActual)/il.PriceList*100 END AS Discount,
|
||||||
|
CASE WHEN il.PriceActual<>0 OR il.M_Product_ID IS NOT NULL THEN il.PriceActual END AS PriceActual,
|
||||||
|
CASE WHEN il.PriceEntered<>0 OR il.M_Product_ID IS NOT NULL THEN il.PriceEntered END AS PriceEntered,
|
||||||
|
CASE WHEN il.LineNetAmt<>0 OR il.M_Product_ID IS NOT NULL THEN il.LineNetAmt END AS LineNetAmt,
|
||||||
|
il.M_AttributeSetInstance_ID, asi.M_AttributeSet_ID,
|
||||||
|
asi.SerNo, asi.Lot, asi.M_Lot_ID,asi.GuaranteeDate,
|
||||||
|
p.Description as ProductDescription, p.ImageURL,
|
||||||
|
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
|
||||||
|
FROM C_InvoiceLine il
|
||||||
|
INNER JOIN C_UOM uom ON (il.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN C_Invoice i ON (il.C_Invoice_ID=i.C_Invoice_ID)
|
||||||
|
LEFT OUTER JOIN C_Tax t ON (il.C_Tax_ID=t.C_Tax_ID)
|
||||||
|
LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID)
|
||||||
|
LEFT OUTER JOIN C_Charge c ON (il.C_Charge_ID=c.C_Charge_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner_Product pp ON (il.M_Product_ID=pp.M_Product_ID AND i.C_BPartner_ID=pp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN S_ResourceAssignment ra ON (il.S_ResourceAssignment_ID=ra.S_ResourceAssignment_ID)
|
||||||
|
LEFT OUTER JOIN M_AttributeSetInstance asi ON (il.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)
|
||||||
|
UNION -- bom lines
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
il.C_Tax_ID, il.TaxAmt, il.LineTotalAmt, t.TaxIndicator,
|
||||||
|
il.Line+(b.Line/100) AS Line, p.M_Product_ID,
|
||||||
|
il.QtyInvoiced*b.BOMQty AS QtyInvoiced,
|
||||||
|
il.QtyEntered*b.BOMQty AS QtyEntered,
|
||||||
|
uom.UOMSymbol,
|
||||||
|
p.Name, -- main
|
||||||
|
b.Description,
|
||||||
|
p.DocumentNote, p.UPC, p.SKU, p.Value AS ProductValue,
|
||||||
|
null, null, null, null, null, null, null,
|
||||||
|
il.M_AttributeSetInstance_ID, asi.M_AttributeSet_ID, asi.SerNo, asi.Lot, asi.M_Lot_ID,asi.GuaranteeDate,
|
||||||
|
p.Description as ProductDescription, p.ImageURL,
|
||||||
|
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
|
||||||
|
FROM M_Product_BOM b -- BOM lines
|
||||||
|
INNER JOIN C_InvoiceLine il ON (b.M_Product_ID=il.M_Product_ID)
|
||||||
|
INNER JOIN M_Product bp ON (bp.M_Product_ID=il.M_Product_ID -- BOM Product
|
||||||
|
AND bp.IsBOM='Y' AND bp.IsVerified='Y' AND bp.IsInvoicePrintDetails='Y')
|
||||||
|
INNER JOIN M_Product p ON (b.M_ProductBOM_ID=p.M_Product_ID) -- BOM line product
|
||||||
|
INNER JOIN C_UOM uom ON (p.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
LEFT OUTER JOIN C_Tax t ON (il.C_Tax_ID=t.C_Tax_ID)
|
||||||
|
LEFT OUTER JOIN M_AttributeSetInstance asi ON (il.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)
|
||||||
|
UNION -- comment lines
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
'en_US', il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
null, null, null, null,
|
||||||
|
il.Line, null,
|
||||||
|
null, null, null,
|
||||||
|
il.Description,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null
|
||||||
|
FROM C_InvoiceLine il
|
||||||
|
WHERE il.C_UOM_ID IS NULL
|
||||||
|
UNION -- empty line
|
||||||
|
SELECT AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
|
||||||
|
'en_US', C_Invoice_ID, null,
|
||||||
|
null, null, null, null,
|
||||||
|
9998, null,
|
||||||
|
null, null, null,
|
||||||
|
null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null
|
||||||
|
FROM C_Invoice
|
||||||
|
UNION -- tax lines
|
||||||
|
SELECT it.AD_Client_ID, it.AD_Org_ID, it.IsActive, it.Created, it.CreatedBy, it.Updated, it.UpdatedBy,
|
||||||
|
'en_US', it.C_Invoice_ID, null,
|
||||||
|
it.C_Tax_ID, null, null, t.TaxIndicator,
|
||||||
|
9999, null,
|
||||||
|
null, null, null,
|
||||||
|
t.Name,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN it.TaxAmt ELSE it.TaxBaseAmt END,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN it.TaxAmt ELSE it.TaxBaseAmt END,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN NULL ELSE it.TaxAmt END,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null
|
||||||
|
FROM C_InvoiceTax it
|
||||||
|
INNER JOIN C_Tax t ON (it.C_Tax_ID=t.C_Tax_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_LINETAX_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_INVOICE_ID, C_INVOICELINE_ID,
|
||||||
|
C_TAX_ID, TAXAMT, LINETOTALAMT, TAXINDICATOR, LINE,
|
||||||
|
M_PRODUCT_ID, QTYINVOICED, QTYENTERED, UOMSYMBOL, NAME,
|
||||||
|
DESCRIPTION, DOCUMENTNOTE, UPC, SKU, PRODUCTVALUE,
|
||||||
|
RESOURCEDESCRIPTION, PRICELIST, PRICEENTEREDLIST, DISCOUNT, PRICEACTUAL,
|
||||||
|
PRICEENTERED, LINENETAMT, M_ATTRIBUTESETINSTANCE_ID, M_ATTRIBUTESET_ID, SERNO,
|
||||||
|
LOT, M_LOT_ID, GUARANTEEDATE, PRODUCTDESCRIPTION, IMAGEURL,
|
||||||
|
C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, C_PROJECTPHASE_ID, C_PROJECTTASK_ID)
|
||||||
|
AS
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
uom.AD_Language,
|
||||||
|
il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
il.C_Tax_ID, il.TaxAmt, il.LineTotalAmt, t.TaxIndicator,
|
||||||
|
il.Line, p.M_Product_ID,
|
||||||
|
CASE WHEN il.QtyInvoiced<>0 OR il.M_Product_ID IS NOT NULL THEN il.QtyInvoiced END AS QtyInvoiced,
|
||||||
|
CASE WHEN il.QtyEntered<>0 OR il.M_Product_ID IS NOT NULL THEN il.QtyEntered END AS QtyEntered,
|
||||||
|
CASE WHEN il.QtyEntered<>0 OR il.M_Product_ID IS NOT NULL THEN uom.UOMSymbol END AS UOMSymbol,
|
||||||
|
COALESCE(c.Name,COALESCE(pt.Name,p.Name)||productAttribute(il.M_AttributeSetInstance_ID), il.Description) AS Name, -- main line
|
||||||
|
CASE WHEN COALESCE(c.Name,pt.Name,p.Name) IS NOT NULL THEN il.Description END AS Description, -- second line
|
||||||
|
COALESCE(pt.DocumentNote,p.DocumentNote) AS DocumentNote, -- third line
|
||||||
|
p.UPC, p.SKU, COALESCE(pp.VendorProductNo,p.Value) AS ProductValue,
|
||||||
|
ra.Description AS ResourceDescription, -- forth line
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList<>0
|
||||||
|
THEN il.PriceList END AS PriceList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList<>0 AND il.QtyEntered<>0
|
||||||
|
THEN il.PriceList*il.QtyInvoiced/il.QtyEntered END AS PriceEnteredList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND il.PriceList>il.PriceActual AND il.PriceList<>0
|
||||||
|
THEN (il.PriceList-il.PriceActual)/il.PriceList*100 END AS Discount,
|
||||||
|
CASE WHEN il.PriceActual<>0 OR il.M_Product_ID IS NOT NULL THEN il.PriceActual END AS PriceActual,
|
||||||
|
CASE WHEN il.PriceEntered<>0 OR il.M_Product_ID IS NOT NULL THEN il.PriceEntered END AS PriceEntered,
|
||||||
|
CASE WHEN il.LineNetAmt<>0 OR il.M_Product_ID IS NOT NULL THEN il.LineNetAmt END AS LineNetAmt,
|
||||||
|
il.M_AttributeSetInstance_ID, asi.M_AttributeSet_ID, asi.SerNo, asi.Lot, asi.M_Lot_ID,asi.GuaranteeDate,
|
||||||
|
pt.Description as ProductDescription, p.ImageURL,
|
||||||
|
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
|
||||||
|
FROM C_InvoiceLine il
|
||||||
|
INNER JOIN C_UOM_Trl uom ON (il.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN C_Invoice i ON (il.C_Invoice_ID=i.C_Invoice_ID)
|
||||||
|
LEFT OUTER JOIN C_Tax_Trl t ON (il.C_Tax_ID=t.C_Tax_ID AND uom.AD_Language=t.AD_Language)
|
||||||
|
LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID)
|
||||||
|
LEFT OUTER JOIN C_Charge c ON (il.C_Charge_ID=c.C_Charge_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner_Product pp ON (il.M_Product_ID=pp.M_Product_ID AND i.C_BPartner_ID=pp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN M_Product_Trl pt ON (il.M_Product_ID=pt.M_Product_ID AND uom.AD_Language=pt.AD_Language)
|
||||||
|
LEFT OUTER JOIN S_ResourceAssignment ra ON (il.S_ResourceAssignment_ID=ra.S_ResourceAssignment_ID)
|
||||||
|
LEFT OUTER JOIN M_AttributeSetInstance asi ON (il.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)
|
||||||
|
UNION -- bom lines
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
uom.AD_Language,
|
||||||
|
il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
il.C_Tax_ID, il.TaxAmt, il.LineTotalAmt, t.TaxIndicator,
|
||||||
|
il.Line+(b.Line/100) AS Line, p.M_Product_ID,
|
||||||
|
il.QtyInvoiced*b.BOMQty AS QtyInvoiced,
|
||||||
|
il.QtyEntered*b.BOMQty AS QtyEntered,
|
||||||
|
uom.UOMSymbol,
|
||||||
|
COALESCE(pt.Name,p.Name) AS Name, -- main
|
||||||
|
b.Description,
|
||||||
|
COALESCE(pt.DocumentNote,p.DocumentNote) AS DocumentNote, p.UPC, p.SKU, p.Value AS ProductValue,
|
||||||
|
null, null, null, null, null, null, null,
|
||||||
|
il.M_AttributeSetInstance_ID, asi.M_AttributeSet_ID, asi.SerNo, asi.Lot, asi.M_Lot_ID,asi.GuaranteeDate,
|
||||||
|
pt.Description as ProductDescription, p.ImageURL,
|
||||||
|
il.C_Campaign_ID, il.C_Project_ID, il.C_Activity_ID, il.C_ProjectPhase_ID, il.C_ProjectTask_ID
|
||||||
|
FROM M_Product_BOM b -- BOM lines
|
||||||
|
INNER JOIN C_InvoiceLine il ON (b.M_Product_ID=il.M_Product_ID)
|
||||||
|
INNER JOIN M_Product bp ON (bp.M_Product_ID=il.M_Product_ID -- BOM Product
|
||||||
|
AND bp.IsBOM='Y' AND bp.IsVerified='Y' AND bp.IsInvoicePrintDetails='Y')
|
||||||
|
INNER JOIN M_Product p ON (b.M_ProductBOM_ID=p.M_Product_ID) -- BOM line product
|
||||||
|
INNER JOIN C_UOM_Trl uom ON (p.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN M_Product_Trl pt ON (b.M_ProductBOM_ID=pt.M_Product_ID AND uom.AD_Language=pt.AD_Language)
|
||||||
|
LEFT OUTER JOIN C_Tax t ON (il.C_Tax_ID=t.C_Tax_ID)
|
||||||
|
LEFT OUTER JOIN M_AttributeSetInstance asi ON (il.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)
|
||||||
|
UNION -- comment line
|
||||||
|
SELECT il.AD_Client_ID, il.AD_Org_ID, il.IsActive, il.Created, il.CreatedBy, il.Updated, il.UpdatedBy,
|
||||||
|
l.AD_Language, il.C_Invoice_ID, il.C_InvoiceLine_ID,
|
||||||
|
null, null, null, null,
|
||||||
|
il.Line, null,
|
||||||
|
null, null, null,
|
||||||
|
il.Description,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_InvoiceLine il, AD_Language l
|
||||||
|
WHERE il.C_UOM_ID IS NULL
|
||||||
|
AND l.IsBaseLanguage='N' AND l.IsSystemLanguage='Y'
|
||||||
|
UNION -- empty line
|
||||||
|
SELECT i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
AD_Language, i.C_Invoice_ID, null,
|
||||||
|
null, null, null, null,
|
||||||
|
9998, null,
|
||||||
|
null, null, null,
|
||||||
|
null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_Invoice i, AD_Language l
|
||||||
|
WHERE l.IsBaseLanguage='N' AND l.IsSystemLanguage='Y'
|
||||||
|
UNION -- tax lines
|
||||||
|
SELECT it.AD_Client_ID, it.AD_Org_ID, it.IsActive, it.Created, it.CreatedBy, it.Updated, it.UpdatedBy,
|
||||||
|
t.AD_Language, it.C_Invoice_ID, null,
|
||||||
|
it.C_Tax_ID, null, null, t.TaxIndicator,
|
||||||
|
9999, null,
|
||||||
|
null, null, null,
|
||||||
|
t.Name,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN it.TaxAmt ELSE it.TaxBaseAmt END,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN it.TaxAmt ELSE it.TaxBaseAmt END,
|
||||||
|
CASE WHEN it.IsTaxIncluded='Y' THEN NULL ELSE it.TaxAmt END,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_InvoiceTax it
|
||||||
|
INNER JOIN C_Tax_Trl t ON (it.C_Tax_ID=t.C_Tax_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_V
|
||||||
|
(C_INVOICE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
|
||||||
|
CREATEDBY, UPDATED, UPDATEDBY, ISSOTRX, DOCUMENTNO,
|
||||||
|
DOCSTATUS, DOCACTION, PROCESSING, PROCESSED, C_DOCTYPE_ID,
|
||||||
|
C_DOCTYPETARGET_ID, C_ORDER_ID, DESCRIPTION, ISAPPROVED, ISTRANSFERRED,
|
||||||
|
SALESREP_ID, DATEINVOICED, DATEPRINTED, DATEACCT, C_BPARTNER_ID,
|
||||||
|
C_BPARTNER_LOCATION_ID, AD_USER_ID, POREFERENCE, DATEORDERED, C_CURRENCY_ID,
|
||||||
|
C_CONVERSIONTYPE_ID, PAYMENTRULE, C_PAYMENTTERM_ID, C_CHARGE_ID, M_PRICELIST_ID,
|
||||||
|
C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, ISPRINTED, ISDISCOUNTPRINTED,
|
||||||
|
ISPAID, ISINDISPUTE, ISPAYSCHEDULEVALID, C_INVOICEPAYSCHEDULE_ID, INVOICECOLLECTIONTYPE,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, MULTIPLIER, MULTIPLIERAP,
|
||||||
|
DOCBASETYPE)
|
||||||
|
AS
|
||||||
|
SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
|
||||||
|
i.C_DocTypeTarget_ID, i.C_Order_ID, i.Description, i.IsApproved, i.IsTransferred,
|
||||||
|
i.SalesRep_ID, i.DateInvoiced, i.DatePrinted, i.DateAcct, i.C_BPartner_ID, i.C_BPartner_Location_ID,
|
||||||
|
i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
|
||||||
|
i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
|
||||||
|
i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
|
||||||
|
i.IsPayScheduleValid, null AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.ChargeAmt*-1 ELSE i.ChargeAmt END AS ChargeAmt,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.TotalLines*-1 ELSE i.TotalLines END AS TotalLines,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.GrandTotal*-1 ELSE i.GrandTotal END AS GrandTotal,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END AS Multiplier,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS MultiplierAP,
|
||||||
|
d.DocBaseType
|
||||||
|
FROM C_Invoice i
|
||||||
|
INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
|
||||||
|
WHERE i.IsPayScheduleValid<>'Y'
|
||||||
|
UNION
|
||||||
|
SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
|
||||||
|
i.C_DocTypeTarget_ID, i.C_Order_ID, i.Description, i.IsApproved, i.IsTransferred,
|
||||||
|
i.SalesRep_ID, i.DateInvoiced, i.DatePrinted, i.DateAcct, i.C_BPartner_ID, i.C_BPartner_Location_ID,
|
||||||
|
i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
|
||||||
|
i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
|
||||||
|
i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
|
||||||
|
i.IsPayScheduleValid, ips.C_InvoicePaySchedule_ID, i.InvoiceCollectionType,
|
||||||
|
null AS ChargeAmt,
|
||||||
|
null AS TotalLines,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN ips.DueAmt*-1 ELSE ips.DueAmt END AS GrandTotal,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END AS Multiplier,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS MultiplierAP,
|
||||||
|
d.DocBaseType
|
||||||
|
FROM C_Invoice i
|
||||||
|
INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID)
|
||||||
|
INNER JOIN C_InvoicePaySchedule ips ON (i.C_Invoice_ID=ips.C_Invoice_ID)
|
||||||
|
WHERE i.IsPayScheduleValid='Y'
|
||||||
|
AND ips.IsValid='Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
CREATE OR REPLACE VIEW C_INVOICE_V1
|
||||||
|
(C_INVOICE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
|
||||||
|
CREATEDBY, UPDATED, UPDATEDBY, ISSOTRX, DOCUMENTNO,
|
||||||
|
DOCSTATUS, DOCACTION, PROCESSING, PROCESSED, C_DOCTYPE_ID,
|
||||||
|
C_DOCTYPETARGET_ID, C_ORDER_ID, DESCRIPTION, ISAPPROVED, ISTRANSFERRED,
|
||||||
|
SALESREP_ID, DATEINVOICED, DATEPRINTED, DATEACCT, C_BPARTNER_ID,
|
||||||
|
C_BPARTNER_LOCATION_ID, AD_USER_ID, POREFERENCE, DATEORDERED, C_CURRENCY_ID,
|
||||||
|
C_CONVERSIONTYPE_ID, PAYMENTRULE, C_PAYMENTTERM_ID, C_CHARGE_ID, M_PRICELIST_ID,
|
||||||
|
C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, ISPRINTED, ISDISCOUNTPRINTED,
|
||||||
|
ISPAID, ISINDISPUTE, ISPAYSCHEDULEVALID, C_INVOICEPAYSCHEDULE_ID, INVOICECOLLECTIONTYPE,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, MULTIPLIER, MULTIPLIERAP,
|
||||||
|
DOCBASETYPE)
|
||||||
|
AS
|
||||||
|
SELECT i.C_Invoice_ID, i.AD_Client_ID, i.AD_Org_ID, i.IsActive, i.Created, i.CreatedBy, i.Updated, i.UpdatedBy,
|
||||||
|
i.IsSOTrx, i.DocumentNo, i.DocStatus, i.DocAction, i.Processing, i.Processed, i.C_DocType_ID,
|
||||||
|
i.C_DocTypeTarget_ID, i.C_Order_ID, i.Description, i.IsApproved, i.IsTransferred,
|
||||||
|
i.SalesRep_ID, i.DateInvoiced, i.DatePrinted, i.DateAcct, i.C_BPartner_ID, i.C_BPartner_Location_ID,
|
||||||
|
i.AD_User_ID, i.POReference, i.DateOrdered, i.C_Currency_ID, i.C_ConversionType_ID, i.PaymentRule,
|
||||||
|
i.C_PaymentTerm_ID, i.C_Charge_ID, i.M_PriceList_ID, i.C_Campaign_ID, i.C_Project_ID,
|
||||||
|
i.C_Activity_ID, i.IsPrinted, i.IsDiscountPrinted, i.IsPaid, i.IsInDispute,
|
||||||
|
i.IsPayScheduleValid, null AS C_InvoicePaySchedule_ID, i.InvoiceCollectionType,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.ChargeAmt*-1 ELSE i.ChargeAmt END AS ChargeAmt,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.TotalLines*-1 ELSE i.TotalLines END AS TotalLines,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN i.GrandTotal*-1 ELSE i.GrandTotal END AS GrandTotal,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,3)='C' THEN -1 ELSE 1 END AS Multiplier,
|
||||||
|
CASE WHEN charAt(d.DocBaseType,2)='P' THEN -1 ELSE 1 END AS MultiplierAP,
|
||||||
|
d.DocBaseType
|
||||||
|
FROM C_Invoice i
|
||||||
|
INNER JOIN C_DocType d ON (i.C_DocType_ID=d.C_DocType_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
CREATE OR REPLACE VIEW C_ORDER_HEADER_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_ORDER_ID, ISSOTRX,
|
||||||
|
DOCUMENTNO, DOCSTATUS, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
M_WAREHOUSE_ID, WAREHOUSE_LOCATION_ID, DOCUMENTTYPE, DOCUMENTTYPENOTE, SALESREP_ID,
|
||||||
|
SALESREP_NAME, DATEORDERED, DATEPROMISED, BPGREETING, NAME,
|
||||||
|
NAME2, BPCONTACTGREETING, TITLE, PHONE, CONTACTNAME,
|
||||||
|
C_LOCATION_ID, POSTAL, REFERENCENO, BILL_BPARTNER_ID, BILL_LOCATION_ID,
|
||||||
|
BILL_USER_ID, BILL_BPVALUE, BILL_BPTAXID, BILL_NAME, BILL_NAME2,
|
||||||
|
BILL_TITLE, BILL_PHONE, BILL_CONTACTNAME, BILL_C_LOCATION_ID, DESCRIPTION,
|
||||||
|
POREFERENCE, C_CURRENCY_ID, PAYMENTTERM, PAYMENTTERMNOTE, C_CHARGE_ID,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID,
|
||||||
|
ISTAXINCLUDED, VOLUME, WEIGHT, C_CAMPAIGN_ID, C_PROJECT_ID,
|
||||||
|
C_ACTIVITY_ID, M_SHIPPER_ID, DELIVERYRULE, DELIVERYVIARULE, PRIORITYRULE,
|
||||||
|
INVOICERULE)
|
||||||
|
AS
|
||||||
|
SELECT o.AD_Client_ID, o.AD_Org_ID, o.IsActive, o.Created, o.CreatedBy, o.Updated, o.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
o.C_Order_ID, o.IsSOTrx, o.DocumentNo, o.DocStatus, o.C_DocType_ID,
|
||||||
|
o.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
o.M_Warehouse_ID, wh.C_Location_ID AS Warehouse_Location_ID,
|
||||||
|
dt.PrintName AS DocumentType, dt.DocumentNote AS DocumentTypeNote,
|
||||||
|
o.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
o.DateOrdered, o.DatePromised,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
bp.ReferenceNo,
|
||||||
|
-- Bill to
|
||||||
|
o.Bill_BPartner_ID, o.Bill_Location_ID, o.Bill_User_ID,
|
||||||
|
bbp.Value AS Bill_BPValue, bbp.TaxID AS Bill_BPTaxID,
|
||||||
|
bbp.Name AS Bill_Name, bbp.Name2 AS Bill_Name2,
|
||||||
|
bbpc.Title AS Bill_Title, bbpc.Phone AS Bill_Phone,
|
||||||
|
NULLIF (bbpc.Name, bbp.Name) AS Bill_ContactName,
|
||||||
|
bbpl.C_Location_ID AS Bill_C_Location_ID,
|
||||||
|
o.Description,
|
||||||
|
o.POReference,
|
||||||
|
o.C_Currency_ID,
|
||||||
|
pt.Name AS PaymentTerm, pt.DocumentNote AS PaymentTermNote,
|
||||||
|
o.C_Charge_ID, o.ChargeAmt,
|
||||||
|
o.TotalLines,
|
||||||
|
o.GrandTotal, o.GrandTotal AS AmtInWords,
|
||||||
|
o.M_PriceList_ID,
|
||||||
|
o.IsTaxIncluded, o.Volume, o.Weight,
|
||||||
|
o.C_Campaign_ID, o.C_Project_ID, o.C_Activity_ID,
|
||||||
|
o.M_Shipper_ID, o.DeliveryRule, o.DeliveryViaRule, o.PriorityRule, o.InvoiceRule
|
||||||
|
FROM C_Order o
|
||||||
|
INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
INNER JOIN M_Warehouse wh ON (o.M_Warehouse_ID=wh.M_Warehouse_ID)
|
||||||
|
INNER JOIN C_PaymentTerm pt ON (o.C_PaymentTerm_ID=pt.C_PaymentTerm_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpg ON (bp.C_Greeting_ID=bpg.C_Greeting_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (o.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (o.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpcg ON (bpc.C_Greeting_ID=bpcg.C_Greeting_ID)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (o.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (o.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner bbp ON (o.Bill_BPartner_ID=bbp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bbpl ON (o.Bill_Location_ID=bbpl.C_BPartner_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bbpc ON (o.Bill_User_ID=bbpc.AD_User_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
CREATE OR REPLACE VIEW C_ORDER_HEADER_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_ORDER_ID, ISSOTRX,
|
||||||
|
DOCUMENTNO, DOCSTATUS, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, ORG_LOCATION_ID, TAXID,
|
||||||
|
M_WAREHOUSE_ID, WAREHOUSE_LOCATION_ID, DOCUMENTTYPE, DOCUMENTTYPENOTE, SALESREP_ID,
|
||||||
|
SALESREP_NAME, DATEORDERED, DATEPROMISED, BPGREETING, NAME,
|
||||||
|
NAME2, BPCONTACTGREETING, TITLE, PHONE, CONTACTNAME,
|
||||||
|
C_LOCATION_ID, POSTAL, REFERENCENO, BILL_BPARTNER_ID, BILL_LOCATION_ID,
|
||||||
|
BILL_USER_ID, BILL_BPVALUE, BILL_BPTAXID, BILL_NAME, BILL_NAME2,
|
||||||
|
BILL_TITLE, BILL_PHONE, BILL_CONTACTNAME, BILL_C_LOCATION_ID, DESCRIPTION,
|
||||||
|
POREFERENCE, C_CURRENCY_ID, PAYMENTTERM, PAYMENTTERMNOTE, C_CHARGE_ID,
|
||||||
|
CHARGEAMT, TOTALLINES, GRANDTOTAL, AMTINWORDS, M_PRICELIST_ID,
|
||||||
|
ISTAXINCLUDED, VOLUME, WEIGHT, C_CAMPAIGN_ID, C_PROJECT_ID,
|
||||||
|
C_ACTIVITY_ID, M_SHIPPER_ID, DELIVERYRULE, DELIVERYVIARULE, PRIORITYRULE,
|
||||||
|
INVOICERULE)
|
||||||
|
AS
|
||||||
|
SELECT o.AD_Client_ID, o.AD_Org_ID, o.IsActive, o.Created, o.CreatedBy, o.Updated, o.UpdatedBy,
|
||||||
|
dt.AD_Language,
|
||||||
|
o.C_Order_ID, o.IsSOTrx, o.DocumentNo, o.DocStatus, o.C_DocType_ID,
|
||||||
|
o.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID,
|
||||||
|
o.M_Warehouse_ID, wh.C_Location_ID AS Warehouse_Location_ID,
|
||||||
|
dt.PrintName AS DocumentType, dt.DocumentNote AS DocumentTypeNote,
|
||||||
|
o.SalesRep_ID, COALESCE(ubp.Name, u.Name) AS SalesRep_Name,
|
||||||
|
o.DateOrdered, o.DatePromised,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpcg.Greeting AS BPContactGreeting,
|
||||||
|
bpc.Title, bpc.Phone,
|
||||||
|
NULLIF (bpc.Name, bp.Name) AS ContactName,
|
||||||
|
bpl.C_Location_ID, l.Postal || l.Postal_Add AS Postal,
|
||||||
|
bp.ReferenceNo,
|
||||||
|
-- Bill to
|
||||||
|
o.Bill_BPartner_ID, o.Bill_Location_ID, o.Bill_User_ID,
|
||||||
|
bbp.Value AS Bill_BPValue, bbp.TaxID AS Bill_BPTaxID,
|
||||||
|
bbp.Name AS Bill_Name, bbp.Name2 AS Bill_Name2,
|
||||||
|
bbpc.Title AS Bill_Title, bbpc.Phone AS Bill_Phone,
|
||||||
|
NULLIF (bbpc.Name, bbp.Name) AS Bill_ContactName,
|
||||||
|
bbpl.C_Location_ID AS Bill_C_Location_ID,
|
||||||
|
o.Description,
|
||||||
|
o.POReference,
|
||||||
|
o.C_Currency_ID,
|
||||||
|
pt.Name AS PaymentTerm, pt.DocumentNote AS PaymentTermNote,
|
||||||
|
o.C_Charge_ID, o.ChargeAmt,
|
||||||
|
o.TotalLines,
|
||||||
|
o.GrandTotal, o.GrandTotal AS AmtInWords,
|
||||||
|
o.M_PriceList_ID,
|
||||||
|
o.IsTaxIncluded, o.Volume, o.Weight,
|
||||||
|
o.C_Campaign_ID, o.C_Project_ID, o.C_Activity_ID,
|
||||||
|
o.M_Shipper_ID, o.DeliveryRule, o.DeliveryViaRule, o.PriorityRule, o.InvoiceRule
|
||||||
|
FROM C_Order o
|
||||||
|
INNER JOIN C_DocType_Trl dt ON (o.C_DocType_ID=dt.C_DocType_ID)
|
||||||
|
INNER JOIN M_Warehouse wh ON (o.M_Warehouse_ID=wh.M_Warehouse_ID)
|
||||||
|
INNER JOIN C_PaymentTerm_Trl pt ON (o.C_PaymentTerm_ID=pt.C_PaymentTerm_ID AND dt.AD_Language=pt.AD_Language)
|
||||||
|
INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpg ON (bp.C_Greeting_ID=bpg.C_Greeting_ID AND dt.AD_Language=bpg.AD_Language)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (o.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
INNER JOIN C_Location l ON (bpl.C_Location_ID=l.C_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bpc ON (o.AD_User_ID=bpc.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpcg ON (bpc.C_Greeting_ID=bpcg.C_Greeting_ID AND dt.AD_Language=bpcg.AD_Language)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (o.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_User u ON (o.SalesRep_ID=u.AD_User_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner ubp ON (u.C_BPartner_ID=ubp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner bbp ON (o.Bill_BPartner_ID=bbp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bbpl ON (o.Bill_Location_ID=bbpl.C_BPartner_Location_ID)
|
||||||
|
LEFT OUTER JOIN AD_User bbpc ON (o.Bill_User_ID=bbpc.AD_User_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
CREATE OR REPLACE VIEW C_ORDER_LINETAX_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_ORDER_ID, C_ORDERLINE_ID,
|
||||||
|
C_TAX_ID, TAXINDICATOR, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, BPNAME,
|
||||||
|
C_LOCATION_ID, LINE, M_PRODUCT_ID, QTYORDERED, QTYENTERED,
|
||||||
|
UOMSYMBOL, NAME, DESCRIPTION, DOCUMENTNOTE, UPC,
|
||||||
|
SKU, PRODUCTVALUE, RESOURCEDESCRIPTION, PRICELIST, PRICEENTEREDLIST,
|
||||||
|
DISCOUNT, PRICEACTUAL, PRICEENTERED, LINENETAMT, PRODUCTDESCRIPTION,
|
||||||
|
IMAGEURL, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, C_PROJECTPHASE_ID,
|
||||||
|
C_PROJECTTASK_ID)
|
||||||
|
AS
|
||||||
|
SELECT ol.AD_Client_ID, ol.AD_Org_ID, ol.IsActive, ol.Created, ol.CreatedBy, ol.Updated, ol.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
ol.C_Order_ID, ol.C_OrderLine_ID, ol.C_Tax_ID, t.TaxIndicator,
|
||||||
|
ol.C_BPartner_ID, ol.C_BPartner_Location_ID, bp.Name AS BPName, bpl.C_Location_ID,
|
||||||
|
ol.Line, p.M_Product_ID,
|
||||||
|
CASE WHEN ol.QtyOrdered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.QtyOrdered END AS QtyOrdered,
|
||||||
|
CASE WHEN ol.QtyEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.QtyEntered END AS QtyEntered,
|
||||||
|
CASE WHEN ol.QtyEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN uom.UOMSymbol END AS UOMSymbol,
|
||||||
|
COALESCE(c.Name,p.Name||productAttribute(ol.M_AttributeSetInstance_ID), ol.Description) AS Name, -- main line
|
||||||
|
CASE WHEN COALESCE(c.Name,p.Name) IS NOT NULL THEN ol.Description END AS Description, -- second line
|
||||||
|
p.DocumentNote, -- third line
|
||||||
|
p.UPC, p.SKU, COALESCE(pp.VendorProductNo,p.Value) AS ProductValue,
|
||||||
|
ra.Description AS ResourceDescription, -- forth line
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList<>0
|
||||||
|
THEN ol.PriceList END AS PriceList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList<>0 AND ol.QtyEntered<>0
|
||||||
|
THEN ol.PriceList*ol.QtyOrdered/ol.QtyEntered END AS PriceEnteredList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList>ol.PriceActual AND ol.PriceList<>0
|
||||||
|
THEN (ol.PriceList-ol.PriceActual)/ol.PriceList*100 END AS Discount,
|
||||||
|
CASE WHEN ol.PriceActual<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.PriceActual END AS PriceActual,
|
||||||
|
CASE WHEN ol.PriceEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.PriceEntered END AS PriceEntered,
|
||||||
|
CASE WHEN ol.LineNetAmt<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.LineNetAmt END AS LineNetAmt,
|
||||||
|
p.Description as ProductDescription, p.ImageURL,
|
||||||
|
ol.C_Campaign_ID, ol.C_Project_ID, ol.C_Activity_ID, ol.C_ProjectPhase_ID, ol.C_ProjectTask_ID
|
||||||
|
FROM C_OrderLine ol
|
||||||
|
INNER JOIN C_UOM uom ON (ol.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN C_Order i ON (ol.C_Order_ID=i.C_Order_ID)
|
||||||
|
LEFT OUTER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)
|
||||||
|
LEFT OUTER JOIN S_ResourceAssignment ra ON (ol.S_ResourceAssignment_ID=ra.S_ResourceAssignment_ID)
|
||||||
|
LEFT OUTER JOIN C_Charge c ON (ol.C_Charge_ID=c.C_Charge_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner_Product pp ON (ol.M_Product_ID=pp.M_Product_ID AND i.C_BPartner_ID=pp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (ol.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (ol.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
LEFT OUTER JOIN C_Tax t ON (ol.C_Tax_ID=t.C_Tax_ID)
|
||||||
|
UNION
|
||||||
|
SELECT ol.AD_Client_ID, ol.AD_Org_ID, ol.IsActive, ol.Created, ol.CreatedBy, ol.Updated, ol.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
ol.C_Order_ID, ol.C_OrderLine_ID, ol.C_Tax_ID, null,
|
||||||
|
null, null, null, null,
|
||||||
|
ol.Line+(b.Line/100) AS Line, p.M_Product_ID,
|
||||||
|
ol.QtyOrdered*b.BOMQty AS QtyInvoiced, ol.QtyEntered*b.BOMQty AS QtyEntered, uom.UOMSymbol,
|
||||||
|
p.Name, -- main
|
||||||
|
b.Description,
|
||||||
|
p.DocumentNote, p.UPC, p.SKU, p.Value AS ProductValue,
|
||||||
|
null, null, null, null, null, null, null, p.Description as ProductDescription, p.ImageURL,
|
||||||
|
ol.C_Campaign_ID, ol.C_Project_ID, ol.C_Activity_ID, ol.C_ProjectPhase_ID, ol.C_ProjectTask_ID
|
||||||
|
FROM M_Product_BOM b -- BOM lines
|
||||||
|
INNER JOIN C_OrderLine ol ON (b.M_Product_ID=ol.M_Product_ID)
|
||||||
|
INNER JOIN M_Product bp ON (bp.M_Product_ID=ol.M_Product_ID -- BOM Product
|
||||||
|
AND bp.IsBOM='Y' AND bp.IsVerified='Y' AND bp.IsInvoicePrintDetails='Y')
|
||||||
|
INNER JOIN M_Product p ON (b.M_ProductBOM_ID=p.M_Product_ID) -- BOM line product
|
||||||
|
INNER JOIN C_UOM uom ON (p.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
UNION
|
||||||
|
SELECT AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
|
||||||
|
'en_US', C_Order_ID, null, null, null,
|
||||||
|
null,
|
||||||
|
null, null, null,
|
||||||
|
null, null, null, null,
|
||||||
|
null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_Order
|
||||||
|
UNION
|
||||||
|
SELECT ot.AD_Client_ID, ot.AD_Org_ID, ot.IsActive, ot.Created, ot.CreatedBy, ot.Updated, ot.UpdatedBy,
|
||||||
|
'en_US', ot.C_Order_ID, null, ot.C_Tax_ID, t.TaxIndicator,
|
||||||
|
null, null, null, null,
|
||||||
|
null, null,
|
||||||
|
null, null, null,
|
||||||
|
t.Name,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN ot.TaxAmt ELSE ot.TaxBaseAmt END,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN ot.TaxAmt ELSE ot.TaxBaseAmt END,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN NULL ELSE ot.TaxAmt END,
|
||||||
|
null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_OrderTax ot
|
||||||
|
INNER JOIN C_Tax t ON (ot.C_Tax_ID=t.C_Tax_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
CREATE OR REPLACE VIEW C_ORDER_LINETAX_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_ORDER_ID, C_ORDERLINE_ID,
|
||||||
|
C_TAX_ID, TAXINDICATOR, C_BPARTNER_ID, C_BPARTNER_LOCATION_ID, BPNAME,
|
||||||
|
C_LOCATION_ID, LINE, M_PRODUCT_ID, QTYORDERED, QTYENTERED,
|
||||||
|
UOMSYMBOL, NAME, DESCRIPTION, DOCUMENTNOTE, UPC,
|
||||||
|
SKU, PRODUCTVALUE, RESOURCEDESCRIPTION, PRICELIST, PRICEENTEREDLIST,
|
||||||
|
DISCOUNT, PRICEACTUAL, PRICEENTERED, LINENETAMT, PRODUCTDESCRIPTION,
|
||||||
|
IMAGEURL, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID, C_PROJECTPHASE_ID,
|
||||||
|
C_PROJECTTASK_ID)
|
||||||
|
AS
|
||||||
|
SELECT ol.AD_Client_ID, ol.AD_Org_ID, ol.IsActive, ol.Created, ol.CreatedBy, ol.Updated, ol.UpdatedBy,
|
||||||
|
uom.AD_Language,
|
||||||
|
ol.C_Order_ID, ol.C_OrderLine_ID, ol.C_Tax_ID, t.TaxIndicator,
|
||||||
|
ol.C_BPartner_ID, ol.C_BPartner_Location_ID, bp.Name AS BPName, bpl.C_Location_ID,
|
||||||
|
ol.Line, p.M_Product_ID,
|
||||||
|
CASE WHEN ol.QtyOrdered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.QtyOrdered END AS QtyOrdered,
|
||||||
|
CASE WHEN ol.QtyEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.QtyEntered END AS QtyEntered,
|
||||||
|
CASE WHEN ol.QtyEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN uom.UOMSymbol END AS UOMSymbol,
|
||||||
|
COALESCE(c.Name,p.Name||productAttribute(ol.M_AttributeSetInstance_ID), ol.Description) AS Name, -- main line
|
||||||
|
CASE WHEN COALESCE(c.Name,pt.Name, p.Name) IS NOT NULL THEN ol.Description END AS Description, -- second line
|
||||||
|
COALESCE(pt.DocumentNote, p.DocumentNote) AS DocumentNote, -- third line
|
||||||
|
p.UPC, p.SKU, COALESCE(pp.VendorProductNo,p.Value) AS ProductValue,
|
||||||
|
ra.Description AS ResourceDescription, -- forth line
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList<>0
|
||||||
|
THEN ol.PriceList END AS PriceList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList<>0 AND ol.QtyEntered<>0
|
||||||
|
THEN ol.PriceList*ol.QtyOrdered/ol.QtyEntered END AS PriceEnteredList,
|
||||||
|
CASE WHEN i.IsDiscountPrinted='Y' AND ol.PriceList>ol.PriceActual AND ol.PriceList<>0
|
||||||
|
THEN (ol.PriceList-ol.PriceActual)/ol.PriceList*100 END AS Discount,
|
||||||
|
CASE WHEN ol.PriceActual<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.PriceActual END AS PriceActual,
|
||||||
|
CASE WHEN ol.PriceEntered<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.PriceEntered END AS PriceEntered,
|
||||||
|
CASE WHEN ol.LineNetAmt<>0 OR ol.M_Product_ID IS NOT NULL THEN ol.LineNetAmt END AS LineNetAmt,
|
||||||
|
pt.Description as ProductDescription, p.ImageURL,
|
||||||
|
ol.C_Campaign_ID, ol.C_Project_ID, ol.C_Activity_ID, ol.C_ProjectPhase_ID, ol.C_ProjectTask_ID
|
||||||
|
FROM C_OrderLine ol
|
||||||
|
INNER JOIN C_UOM_Trl uom ON (ol.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN C_Order i ON (ol.C_Order_ID=i.C_Order_ID)
|
||||||
|
LEFT OUTER JOIN M_Product p ON (ol.M_Product_ID=p.M_Product_ID)
|
||||||
|
LEFT OUTER JOIN M_Product_Trl pt ON (ol.M_Product_ID=pt.M_Product_ID AND uom.AD_Language=pt.AD_Language)
|
||||||
|
LEFT OUTER JOIN S_ResourceAssignment ra ON (ol.S_ResourceAssignment_ID=ra.S_ResourceAssignment_ID)
|
||||||
|
LEFT OUTER JOIN C_Charge c ON (ol.C_Charge_ID=c.C_Charge_ID)
|
||||||
|
LEFT OUTER JOIN C_BPartner_Product pp ON (ol.M_Product_ID=pp.M_Product_ID AND i.C_BPartner_ID=pp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (ol.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
INNER JOIN C_BPartner_Location bpl ON (ol.C_BPartner_Location_ID=bpl.C_BPartner_Location_ID)
|
||||||
|
LEFT OUTER JOIN C_Tax_Trl t ON (ol.C_Tax_ID=t.C_Tax_ID AND uom.AD_Language=t.AD_Language)
|
||||||
|
UNION
|
||||||
|
SELECT ol.AD_Client_ID, ol.AD_Org_ID, ol.IsActive, ol.Created, ol.CreatedBy, ol.Updated, ol.UpdatedBy,
|
||||||
|
uom.AD_Language,
|
||||||
|
ol.C_Order_ID, ol.C_OrderLine_ID, ol.C_Tax_ID, null,
|
||||||
|
null, null, null, null,
|
||||||
|
ol.Line+(b.Line/100) AS Line, p.M_Product_ID,
|
||||||
|
ol.QtyOrdered*b.BOMQty AS QtyInvoiced, ol.QtyEntered*b.BOMQty AS QtyEntered, uom.UOMSymbol,
|
||||||
|
COALESCE(pt.Name, p.Name) AS Name, -- main
|
||||||
|
b.Description,
|
||||||
|
COALESCE(pt.DocumentNote, p.DocumentNote) AS DocumentNote, p.UPC, p.SKU, p.Value AS ProductValue,
|
||||||
|
null, null, null, null, null, null, null, pt.Description AS ProductDescription, p.ImageURL,
|
||||||
|
ol.C_Campaign_ID, ol.C_Project_ID, ol.C_Activity_ID, ol.C_ProjectPhase_ID, ol.C_ProjectTask_ID
|
||||||
|
FROM M_Product_BOM b -- BOM lines
|
||||||
|
INNER JOIN C_OrderLine ol ON (b.M_Product_ID=ol.M_Product_ID)
|
||||||
|
INNER JOIN M_Product bp ON (bp.M_Product_ID=ol.M_Product_ID -- BOM Product
|
||||||
|
AND bp.IsBOM='Y' AND bp.IsVerified='Y' AND bp.IsInvoicePrintDetails='Y')
|
||||||
|
INNER JOIN M_Product p ON (b.M_ProductBOM_ID=p.M_Product_ID) -- BOM line product
|
||||||
|
INNER JOIN C_UOM_Trl uom ON (p.C_UOM_ID=uom.C_UOM_ID)
|
||||||
|
INNER JOIN M_Product_Trl pt ON (b.M_ProductBOM_ID=pt.M_Product_ID AND uom.AD_Language=pt.AD_Language)
|
||||||
|
UNION
|
||||||
|
SELECT o.AD_Client_ID, o.AD_Org_ID, o.IsActive, o.Created, o.CreatedBy, o.Updated, o.UpdatedBy,
|
||||||
|
l.AD_Language, o.C_Order_ID, null, null, null,
|
||||||
|
null,
|
||||||
|
null, null, null,
|
||||||
|
null, null, null, null,
|
||||||
|
null, null,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null, null, null, null, null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_Order o, AD_Language l
|
||||||
|
WHERE l.IsBaseLanguage='N' AND l.IsSystemLanguage='Y'
|
||||||
|
UNION
|
||||||
|
SELECT ot.AD_Client_ID, ot.AD_Org_ID, ot.IsActive, ot.Created, ot.CreatedBy, ot.Updated, ot.UpdatedBy,
|
||||||
|
t.AD_Language, ot.C_Order_ID, null, ot.C_Tax_ID, t.TaxIndicator,
|
||||||
|
null, null, null, null,
|
||||||
|
null, null,
|
||||||
|
null, null, null,
|
||||||
|
t.Name,
|
||||||
|
null, null, null, null, null, null,
|
||||||
|
null, null, null,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN ot.TaxAmt ELSE ot.TaxBaseAmt END,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN ot.TaxAmt ELSE ot.TaxBaseAmt END,
|
||||||
|
CASE WHEN ot.IsTaxIncluded='Y' THEN NULL ELSE ot.TaxAmt END,
|
||||||
|
null, null,
|
||||||
|
null,null,null,null,null
|
||||||
|
FROM C_OrderTax ot
|
||||||
|
INNER JOIN C_Tax_Trl t ON (ot.C_Tax_ID=t.C_Tax_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PAYMENT_V
|
||||||
|
(C_PAYMENT_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED,
|
||||||
|
CREATEDBY, UPDATED, UPDATEDBY, DOCUMENTNO, DATETRX,
|
||||||
|
ISRECEIPT, C_DOCTYPE_ID, TRXTYPE, C_BANKACCOUNT_ID, C_BPARTNER_ID,
|
||||||
|
C_INVOICE_ID, C_BP_BANKACCOUNT_ID, C_PAYMENTBATCH_ID, TENDERTYPE, CREDITCARDTYPE,
|
||||||
|
CREDITCARDNUMBER, CREDITCARDVV, CREDITCARDEXPMM, CREDITCARDEXPYY, MICR,
|
||||||
|
ROUTINGNO, ACCOUNTNO, CHECKNO, A_NAME, A_STREET,
|
||||||
|
A_CITY, A_STATE, A_ZIP, A_IDENT_DL, A_IDENT_SSN,
|
||||||
|
A_EMAIL, VOICEAUTHCODE, ORIG_TRXID, PONUM, C_CURRENCY_ID,
|
||||||
|
C_CONVERSIONTYPE_ID, PAYAMT, DISCOUNTAMT, WRITEOFFAMT, TAXAMT,
|
||||||
|
OVERUNDERAMT, MULTIPLIERAP, ISOVERUNDERPAYMENT, ISAPPROVED, R_PNREF,
|
||||||
|
R_RESULT, R_RESPMSG, R_AUTHCODE, R_AVSADDR, R_AVSZIP,
|
||||||
|
R_INFO, PROCESSING, OPROCESSING, DOCSTATUS, DOCACTION,
|
||||||
|
ISPREPAYMENT, C_CHARGE_ID, ISRECONCILED, ISALLOCATED, ISONLINE,
|
||||||
|
PROCESSED, POSTED, C_CAMPAIGN_ID, C_PROJECT_ID, C_ACTIVITY_ID)
|
||||||
|
AS
|
||||||
|
SELECT C_Payment_ID, AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
|
||||||
|
DocumentNo, DateTrx, IsReceipt, C_DocType_ID, TrxType,
|
||||||
|
C_BankAccount_ID, C_BPartner_ID, C_Invoice_ID, C_BP_BankAccount_ID, C_PaymentBatch_ID,
|
||||||
|
TenderType, CreditCardType, CreditCardNumber, CreditCardVV, CreditCardExpMM, CreditCardExpYY,
|
||||||
|
Micr, RoutingNo, AccountNo, CheckNo,
|
||||||
|
A_Name, A_Street, A_City, A_State, A_Zip, A_Ident_DL, A_Ident_SSN, A_EMail,
|
||||||
|
VoiceAuthCode, Orig_TrxID, PONum,
|
||||||
|
C_Currency_ID, C_ConversionType_ID,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN PayAmt ELSE PayAmt*-1 END AS PayAmt,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN DiscountAmt ELSE DiscountAmt*-1 END AS DiscountAmt,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN WriteOffAmt ELSE WriteOffAmt*-1 END AS WriteOffAmt,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN TaxAmt ELSE TaxAmt*-1 END AS TaxAmt,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN OverUnderAmt ELSE OverUnderAmt*-1 END AS OverUnderAmt,
|
||||||
|
CASE IsReceipt WHEN 'Y' THEN 1 ELSE -1 END AS MultiplierAP,
|
||||||
|
IsOverUnderPayment, IsApproved,
|
||||||
|
R_PnRef, R_Result, R_RespMsg, R_AuthCode, R_AvsAddr, R_AvsZip, R_Info,
|
||||||
|
Processing, OProcessing, DocStatus, DocAction,
|
||||||
|
IsPrepayment, C_Charge_ID,
|
||||||
|
IsReconciled, IsAllocated, IsOnline, Processed, Posted,
|
||||||
|
C_Campaign_ID, C_Project_ID, C_Activity_ID
|
||||||
|
FROM C_Payment;
|
||||||
|
|
||||||
|
--COMMENT ON TABLE C_PAYMENT_V IS 'Payment Information corrected for AP/AR';
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PAYSELECTION_CHECK_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, AD_LANGUAGE, C_PAYSELECTION_ID, C_PAYSELECTIONCHECK_ID,
|
||||||
|
ORG_LOCATION_ID, TAXID, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, BPGREETING, NAME,
|
||||||
|
NAME2, C_LOCATION_ID, REFERENCENO, POREFERENCE, PAYDATE,
|
||||||
|
PAYAMT, AMTINWORDS, QTY, PAYMENTRULE, DOCUMENTNO)
|
||||||
|
AS
|
||||||
|
SELECT psc.AD_Client_ID, psc.AD_Org_ID,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
psc.C_PaySelection_ID, psc.C_PaySelectionCheck_ID,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID, 0 AS C_DocType_ID,
|
||||||
|
bp.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpartnerRemitLocation(bp.C_BPartner_ID) AS C_Location_ID,
|
||||||
|
bp.ReferenceNo, bp.POReference,
|
||||||
|
ps.PayDate,
|
||||||
|
psc.PayAmt, psc.PayAmt AS AmtInWords,
|
||||||
|
psc.Qty, psc.PaymentRule, psc.DocumentNo
|
||||||
|
FROM C_PaySelectionCheck psc
|
||||||
|
INNER JOIN C_PaySelection ps ON (psc.C_PaySelection_ID=ps.C_PaySelection_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (psc.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
LEFT OUTER JOIN C_Greeting bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (psc.AD_Org_ID=oi.AD_Org_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PAYSELECTION_CHECK_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, AD_LANGUAGE, C_PAYSELECTION_ID, C_PAYSELECTIONCHECK_ID,
|
||||||
|
ORG_LOCATION_ID, TAXID, C_DOCTYPE_ID, C_BPARTNER_ID, BPVALUE,
|
||||||
|
BPTAXID, NAICS, DUNS, BPGREETING, NAME,
|
||||||
|
NAME2, C_LOCATION_ID, REFERENCENO, POREFERENCE, PAYDATE,
|
||||||
|
PAYAMT, AMTINWORDS, QTY, PAYMENTRULE, DOCUMENTNO)
|
||||||
|
AS
|
||||||
|
SELECT psc.AD_Client_ID, psc.AD_Org_ID,
|
||||||
|
l.AD_Language,
|
||||||
|
psc.C_PaySelection_ID, psc.C_PaySelectionCheck_ID,
|
||||||
|
oi.C_Location_ID AS Org_Location_ID, oi.TaxID, 0 AS C_DocType_ID,
|
||||||
|
bp.C_BPartner_ID, bp.Value AS BPValue, bp.TaxID AS BPTaxID, bp.NAICS, bp.DUNS,
|
||||||
|
bpg.Greeting AS BPGreeting,
|
||||||
|
bp.Name, bp.Name2,
|
||||||
|
bpartnerRemitLocation(bp.C_BPartner_ID) AS C_Location_ID,
|
||||||
|
bp.ReferenceNo, bp.POReference,
|
||||||
|
ps.PayDate,
|
||||||
|
psc.PayAmt, psc.PayAmt AS AmtInWords,
|
||||||
|
psc.Qty, psc.PaymentRule, psc.DocumentNo
|
||||||
|
FROM C_PaySelectionCheck psc
|
||||||
|
INNER JOIN C_PaySelection ps ON (psc.C_PaySelection_ID=ps.C_PaySelection_ID)
|
||||||
|
INNER JOIN C_BPartner bp ON (psc.C_BPartner_ID=bp.C_BPartner_ID)
|
||||||
|
INNER JOIN AD_OrgInfo oi ON (psc.AD_Org_ID=oi.AD_Org_ID)
|
||||||
|
LEFT OUTER JOIN AD_Language l ON (l.IsSystemLanguage='Y')
|
||||||
|
LEFT OUTER JOIN C_Greeting_Trl bpg on (bp.C_Greeting_ID=bpg.C_Greeting_ID AND bpg.AD_Language=l.AD_Language);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PAYSELECTION_REMITTANCE_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, AD_LANGUAGE, C_PAYSELECTION_ID, C_PAYSELECTIONLINE_ID,
|
||||||
|
C_PAYSELECTIONCHECK_ID, PAYMENTRULE, LINE, OPENAMT, PAYAMT,
|
||||||
|
DISCOUNTAMT, DIFFERENCEAMT, C_BPARTNER_ID, DOCUMENTNO, DATEINVOICED,
|
||||||
|
GRANDTOTAL, AMTINWORDS)
|
||||||
|
AS
|
||||||
|
SELECT psl.AD_Client_ID, psl.AD_Org_ID,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
psl.C_PaySelection_ID, psl.C_PaySelectionLine_ID,
|
||||||
|
psl.C_PaySelectionCheck_ID,
|
||||||
|
psl.PaymentRule, psl.Line, psl.OpenAmt, psl.PayAmt, psl.DiscountAmt, psl.DifferenceAmt,
|
||||||
|
i.C_BPartner_ID, i.DocumentNo, i.DateInvoiced, i.GrandTotal, i.GrandTotal AS AmtInWords
|
||||||
|
FROM C_PaySelectionLine psl
|
||||||
|
INNER JOIN C_Invoice i ON (psl.C_Invoice_ID=i.C_Invoice_ID);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PAYSELECTION_REMITTANCE_VT
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, AD_LANGUAGE, C_PAYSELECTION_ID, C_PAYSELECTIONLINE_ID,
|
||||||
|
C_PAYSELECTIONCHECK_ID, PAYMENTRULE, LINE, OPENAMT, PAYAMT,
|
||||||
|
DISCOUNTAMT, DIFFERENCEAMT, C_BPARTNER_ID, DOCUMENTNO, DATEINVOICED,
|
||||||
|
GRANDTOTAL, AMTINWORDS)
|
||||||
|
AS
|
||||||
|
SELECT psl.AD_Client_ID, psl.AD_Org_ID,
|
||||||
|
l.AD_Language,
|
||||||
|
psl.C_PaySelection_ID, psl.C_PaySelectionLine_ID,
|
||||||
|
psl.C_PaySelectionCheck_ID,
|
||||||
|
psl.PaymentRule, psl.Line, psl.OpenAmt, psl.PayAmt, psl.DiscountAmt, psl.DifferenceAmt,
|
||||||
|
i.C_BPartner_ID, i.DocumentNo, i.DateInvoiced, i.GrandTotal, i.GrandTotal AS AmtInWords
|
||||||
|
FROM C_PaySelectionLine psl
|
||||||
|
INNER JOIN C_Invoice i ON (psl.C_Invoice_ID=i.C_Invoice_ID)
|
||||||
|
INNER JOIN AD_Language l ON (l.IsSystemLanguage='Y');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE OR REPLACE VIEW C_PROJECT_DETAILS_V
|
||||||
|
(AD_CLIENT_ID, AD_ORG_ID, ISACTIVE, CREATED, CREATEDBY,
|
||||||
|
UPDATED, UPDATEDBY, AD_LANGUAGE, C_PROJECT_ID, C_PROJECTLINE_ID,
|
||||||
|
LINE, PLANNEDQTY, PLANNEDPRICE, PLANNEDAMT, PLANNEDMARGINAMT,
|
||||||
|
COMMITTEDAMT, M_PRODUCT_ID, NAME, DESCRIPTION, DOCUMENTNOTE,
|
||||||
|
UPC, SKU, PRODUCTVALUE, M_PRODUCT_CATEGORY_ID, INVOICEDAMT,
|
||||||
|
INVOICEDQTY, COMMITTEDQTY)
|
||||||
|
AS
|
||||||
|
SELECT pl.AD_Client_ID, pl.AD_Org_ID, pl.IsActive, pl.Created, pl.CreatedBy, pl.Updated, pl.UpdatedBy,
|
||||||
|
'en_US' AS AD_Language,
|
||||||
|
pj.C_Project_ID, pl.C_ProjectLine_ID,
|
||||||
|
pl.Line,
|
||||||
|
pl.PlannedQty, pl.PlannedPrice, pl.PlannedAmt, pl.PlannedMarginAmt,
|
||||||
|
pl.CommittedAmt,
|
||||||
|
pl.M_Product_ID,
|
||||||
|
COALESCE(p.Name, pl.Description) AS Name, -- main line
|
||||||
|
CASE WHEN p.Name IS NOT NULL THEN pl.Description END AS Description, -- second line
|
||||||
|
p.DocumentNote, -- third line
|
||||||
|
p.UPC, p.SKU, p.Value AS ProductValue,
|
||||||
|
pl.M_Product_Category_ID,
|
||||||
|
pl.InvoicedAmt, pl.InvoicedQty, pl.CommittedQty
|
||||||
|
FROM C_ProjectLine pl
|
||||||
|
INNER JOIN C_Project pj ON (pl.C_Project_ID=pj.C_Project_ID)
|
||||||
|
LEFT OUTER JOIN M_Product p ON (pl.M_Product_ID=p.M_Product_ID)
|
||||||
|
WHERE pl.IsPrinted='Y';
|
||||||
|
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue