move branch adempire311 to trunk

This commit is contained in:
vpj-cd 2006-11-17 03:14:06 +00:00
parent 9802eea0be
commit 0145080dfc
50 changed files with 158512 additions and 0 deletions

7
sqlj/.classpath Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/lib/oracle.jar"/>
<classpathentry kind="output" path="build"/>
</classpath>

22
sqlj/.project Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sqlj</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.ibm.etools.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@ -0,0 +1,4 @@
#Sat Apr 22 20:31:20 PDT 2006
eclipse.preferences.version=1
xdoclet.build.policy=automatic
xdoclet.jdk.support=jdk5

View File

@ -0,0 +1,12 @@
#Fri Feb 04 21:49:30 EST 2005
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.compliance=1.3
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1
org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
org.eclipse.jdt.core.compiler.source=1.3
org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore

View File

@ -0,0 +1,3 @@
#Thu Sep 29 20:01:57 PDT 2005
eclipse.preferences.version=1
internal.default.compliance=default

24
sqlj/RUN_build.bat Normal file
View File

@ -0,0 +1,24 @@
@Title Build SQLJ
@Rem $Header: /cvsroot/adempiere/sqlj/RUN_build.bat,v 1.5 2005/09/16 00:50:04 jjanke Exp $
@Rem
@Rem Note that the SQLJ build is not part of the normal build cycle.
@Rem You need to build the sqlj.jar file either with this script
@Rem or with the 'compile' script for older Java versions
@Rem You then deploy it with the database dependent 'create' script
@CALL ..\utils_dev\myDevEnv.bat
@IF NOT %ADEMPIERE_ENV%==Y GOTO NOBUILD
@echo Cleanup ...
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main clean
@echo Building ...
@"%JAVA_HOME%\bin\java" -Dant.home="." %ANT_PROPERTIES% org.apache.tools.ant.Main sqljDist
@Echo Done ...
@sleep 60
@exit
:NOBUILD
@Echo Check myDevEnv.bat (copy from myDevEnvTemplate.bat)
@Pause

26
sqlj/RUN_build.sh Executable file
View File

@ -0,0 +1,26 @@
# Module compiling script
# Ported from Windows script
echo Title Build SQLJ
# $Header: /cvsroot/compiere/sqlj/RUN_build.bat,v 1.4 2005/02/03 07:10:24 jjanke Exp $
#
# Note that the SQLJ build is not part of the normal build cycle.
# You need to build the sqlj.jar file either with this script
# or with the 'compile' script for older Java versions
# You then deploy it with the database dependent 'create' script
SAVED_DIR=`pwd` #save current dir
cd `dirname $0`/../utils_dev #change dir to place where script resides - doesn not work with sym links
UTILS_DEV=`pwd` #this is compiere source
cd $SAVED_DIR #back to the saved directory
. $UTILS_DEV/myDevEnv.sh #call environment
echo done
if [ ! $COMPIERE_ENV==Y ] ; then
echo "Can't set developemeent environemnt - check myDevEnv.sh"
exit 1
fi
echo running Ant
$JAVA_HOME/bin/java -Dant.home="." $ANT_PROPERTIES org.apache.tools.ant.Main clean
echo Building ...
$JAVA_HOME/bin/java -Dant.home="." $ANT_PROPERTIES org.apache.tools.ant.Main sqljDist

29
sqlj/SQL J.epj Normal file
View File

@ -0,0 +1,29 @@
Begin Project "SQL J", "", VC_PROJECT=, AUXPROJPATH=
DATASOURCE=
DATABASE=
Begin SubProject "oracle", "", PATH=.\oracle
Begin File "createSQLJ.sql"
PATH=.\oracle\createSQLJ.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
Begin SubProject "sybase", "", PATH=.\sybase
Begin File "createSQLJ.sql"
PATH=.\sybase\createSQLJ.sql
DESCRIPTION=
INCLUDE=1
BUILDINDEX=-1
OBJECTTYPE=-1
End File
End SubProject
End Project

75
sqlj/build.xml Normal file
View File

@ -0,0 +1,75 @@
<!-- ============================================= -->
<!-- Base -->
<!-- ============================================= -->
<!-- $Header: /cvs/adempiere/sqlj/build.xml,v 1.1 2006/04/21 18:04:47 jjanke Exp $ -->
<project name="sqlj" default="sqljDist" basedir=".">
<property name="src" value="src"/>
<property name="build.dir" value="build"/>
<property name="dist.dir" value="."/>
<property environment="env"/>
<path id="project.class.path">
<pathelement path="${classpath}"/>
</path>
<target name="sqljInit" description="initialization target">
<echo message="=========== Build SQLJ"/>
<!-- create the time stamp -->
<tstamp/>
<!-- create the build directory structure used by compile -->
<mkdir dir="${build.dir}"/>
<!--begin vpj-cd e-evolution PostgreSQL-->
<copy file="postgresql/sqlj.ddr" tofile="./${build.dir}/deployment/sqlj.ddr" failonerror="no"/>
<!--end vpj-cd e-evolution PostgreSQL-->
</target>
<!-- =========================================== -->
<!-- Compile -->
<!-- =========================================== -->
<target name="sqljCompile" depends="sqljInit">
<javac srcdir="${src}" destdir="${build.dir}"
deprecation="on"
source="1.3" target="1.1" optimize="off"
debug="on">
<classpath refid="project.class.path"/>
</javac>
</target>
<!-- =========================================== -->
<!-- Distribution -->
<!-- =========================================== -->
<target name="sqljDist" depends="sqljCompile">
<jar jarfile="${dist.dir}/sqlj.jar"
basedir="${build.dir}"
compress="no">
<manifest>
<attribute name="Specification-Title" value="Adempiere SQLJ Functions"/>
<attribute name="Specification-Version" value="sqlj"/>
<attribute name="Specification-Vendor" value="Adempiere"/>
<attribute name="Implementation-Title" value="sqlj ${env.ADEMPIERE_VERSION}"/>
<attribute name="Implementation-Version" value="${env.ADEMPIERE_VERSION} ${DSTAMP}-${TSTAMP}"/>
<attribute name="Implementation-Vendor" value="${env.ADEMPIERE_VENDOR}"/>
<attribute name="Implementation-URL" value="http://www.adempiere.com"/>
<!--begin vpj-cd e-evolution PostgreSQL-->
<section name="deployment/sqlj.ddr">
<attribute name="SQLJDeploymentDescriptor" value="true"/>
</section>
<!--end vpj-cd e-evolution PostgreSQL-->
</manifest>
</jar>
</target>
<target name="clean">
<!-- Delete the ${build.dir} directory trees -->
<delete dir="${build.dir}"/>
<delete file="${dist.dir}/sqlj.jar" failonerror="false"/>
</target>
</project>

18
sqlj/compile.bat Normal file
View File

@ -0,0 +1,18 @@
@Title Compile + Jar SQLJ
@Rem @version $Id: compile.bat,v 1.5 2005/02/04 17:23:33 jjanke Exp $
@Rem
@Rem Note that some databases require an older Java version
@Rem and that the Zip is uncompressed
@Rem
@Rem Oracle: 1.4.2 - (you can use RUN_Build)
@Rem Sybase: 1.2.2 -
@Rem
@SET PATH=C:\jdk1.2.2\bin;%PATH%
@SET JAVA_HOME=C:\jdk1.2.2
@java -version
javac -sourcepath src -d lib src/org/adempiere/sqlj/Adempiere.java src/org/adempiere/sqlj/Product.java src/org/adempiere/sqlj/Currency.java src/org/adempiere/sqlj/BPartner.java src/org/adempiere/sqlj/Invoice.java src/org/adempiere/sqlj/Payment.java src/org/adempiere/sqlj/PaymentTerm.java src/org/adempiere/sqlj/Account.java
jar cf0 sqlj.jar -C lib org/adempiere/sqlj
pause

7
sqlj/db2/RUN_sqlj.bat Normal file
View File

@ -0,0 +1,7 @@
@if (%ADEMPIERE_HOME%) == () (CALL ..\myEnvironment.bat Server) else (CALL %ADEMPIERE_HOME%\utils\myEnvironment.bat Server)
@Title Create DB2 SQLJ - %ADEMPIERE_HOME% (%ADEMPIERE_DB_NAME%)
@Rem
call create %ADEMPIERE_DB_USER%/%ADEMPIERE_DB_PASSWORD%
@pause

8
sqlj/db2/RUN_sqlj.sh Normal file
View File

@ -0,0 +1,8 @@
if [ $ADEMPIERE_HOME ]; then
cd $ADEMPIERE_HOME/utils
fi
. ./myEnvironment.sh Server
echo Create DB2 SQLJ - $ADEMPIERE_HOME \($ADEMPIERE_DB_NAME\)
sh $ADEMPIERE_DB_PATH/create.sh $ADEMPIERE_DB_USER/$ADEMPIERE_DB_PASSWORD

11
sqlj/db2/create.bat Normal file
View File

@ -0,0 +1,11 @@
@Rem Create DB2 SQLJ
@Rem
@Rem Parameter: <adempiereDBuser>/<adempiereDBpassword>
@Echo .
@Echo Load DB2 SQLJ ...
@db2cmd db2 "CALL sqlj.install_jar('%ADEMPIERE_HOME%\lib\sqlj.jar', 'adempiere_sqlj')"
@Echo .
@Echo Create DB2 Functions ...
@db2cmd db2 -f%ADEMPIERE_HOME%\utils\db2\createSQLJ.sql

11
sqlj/db2/create.sh Normal file
View File

@ -0,0 +1,11 @@
# Create DB2 SQLJ
#
# Parameter: <adempiereDBuser>/<adempiereDBpassword>
echo .
echo Load DB2 SQLJ ...
db2 "CALL sqlj.install_jar('$ADEMPIERE_HOME/lib/sqlj.jar', 'adempiere_sqlj')"
echo .
echo Create DB2 Functions ...
db2 -f$ADEMPIERE_HOME/utils/db2/createSQLJ.sql

433
sqlj/db2/createSQLJ.sql Normal file
View File

@ -0,0 +1,433 @@
/**
* Create SQL Java Functions (DB2)
*/
-- Oracle equvalents are in comments above for temporary reference.
--CREATE OR REPLACE FUNCTION adempiereVersion
-- RETURN VARCHAR2
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Adempiere.getVersion() return java.lang.String';
CREATE FUNCTION adempiereVersion()
RETURNS VARCHAR
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getVersion';
--CREATE OR REPLACE FUNCTION adempiereProperties
-- RETURN VARCHAR2
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Adempiere.getProperties() return java.lang.String';
CREATE FUNCTION adempiereProperties()
RETURNS VARCHAR
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getProperties';
--CREATE OR REPLACE FUNCTION adempiereProperty(p_key VARCHAR2)
-- RETURN VARCHAR2
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Adempiere.getProperty(java.lang.String) return java.lang.String';
CREATE FUNCTION adempiereProperty(p_key VARCHAR)
RETURNS VARCHAR
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getProperty';
/** Product **/
--CREATE OR REPLACE FUNCTION productAttribute (M_AttributeSetInstance_ID NUMBER)
-- RETURN NVARCHAR2
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.attributeName(int) return java.lang.String';
CREATE FUNCTION productAttribute (M_AttributeSetInstance_ID FLOAT)
RETURNS VARCHAR
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.attributeName';
--CREATE OR REPLACE FUNCTION bomPriceLimit (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomPriceLimit(int,int) return java.math.BigDecimal';
CREATE FUNCTION bomPriceLimit (M_Product_ID FLOAT, M_PriceList_Version_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceLimit';
--CREATE OR REPLACE FUNCTION bomPriceList (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomPriceList(int,int) return java.math.BigDecimal';
CREATE FUNCTION bomPriceList (M_Product_ID FLOAT, M_PriceList_Version_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceList';
--CREATE OR REPLACE FUNCTION bomPriceStd (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomPriceStd(int,int) return java.math.BigDecimal';
CREATE FUNCTION bomPriceStd (M_Product_ID FLOAT, M_PriceList_Version_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceStd';
--CREATE OR REPLACE FUNCTION bomQtyAvailable (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
-- M_Locator_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomQtyAvailable(int,int,int) return --java.math.BigDecimal';
CREATE FUNCTION bomQtyAvailable (M_Product_ID FLOAT, M_Warehouse_ID FLOAT, M_Locator_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyAvailable';
--CREATE OR REPLACE FUNCTION bomQtyOnHand (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
-- M_Locator_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomQtyOnHand(int,int,int) return java.math.BigDecimal';
CREATE FUNCTION bomQtyOnHand (M_Product_ID FLOAT, M_Warehouse_ID FLOAT, M_Locator_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyOnHand';
--CREATE OR REPLACE FUNCTION bomQtyOrdered (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
-- M_Locator_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomQtyOrdered(int,int,int) return --java.math.BigDecimal';
CREATE FUNCTION bomQtyOrdered (M_Product_ID FLOAT, M_Warehouse_ID FLOAT, M_Locator_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyOrdered';
--CREATE OR REPLACE FUNCTION bomQtyReserved (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
-- M_Locator_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Product.bomQtyReserved(int,int,int) return --java.math.BigDecimal';
CREATE FUNCTION bomQtyReserved (M_Product_ID FLOAT, M_Warehouse_ID FLOAT, M_Locator_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyReserved';
/** Currency **/
--CREATE OR REPLACE FUNCTION currencyBase (Amount NUMBER, C_CurrencyFrom_ID NUMBER,
-- ConversionDate DATE, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Currency.base--(java.math.BigDecimal,int,java.sql.Timestamp,int,int) return java.math.BigDecimal';
CREATE FUNCTION currencyBase (Amount FLOAT, C_CurrencyFrom_ID FLOAT, ConversionDate TIMESTAMP, AD_Client_ID FLOAT, AD_Org_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.base';
--CREATE OR REPLACE FUNCTION currencyConvert (Amount NUMBER, C_CurrencyFrom_ID NUMBER,
-- C_CurrencyTo_ID NUMBER,
-- ConversionDate DATE, C_ConversionType_ID NUMBER, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Currency.convert--(java.math.BigDecimal,int,int,java.sql.Timestamp,int,int,int) return java.math.BigDecimal';
CREATE FUNCTION currencyBase (Amount FLOAT, C_CurrencyFrom_ID FLOAT, ConversionDate TIMESTAMP, C_CurrencyTo_ID FLOAT, ConversionDate TIMESTAMP, C_ConversionType_ID FLOAT, AD_Client_ID FLOAT, AD_Org_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.convert';
--CREATE OR REPLACE FUNCTION currencyRate (C_CurrencyFrom_ID NUMBER, C_CurrencyTo_ID NUMBER,
-- ConversionDate DATE, C_ConversionType_ID NUMBER, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Currency.rate(int,int,java.sql.Timestamp,int,int,int) return --java.math.BigDecimal';
CREATE FUNCTION currencyRate (C_CurrencyFrom_ID FLOAT, C_CurrencyTo_ID FLOAT, ConversionDate TIMESTAMP, C_ConversionType_ID FLOAT, AD_Client_ID FLOAT, AD_Org_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.rate';
--CREATE OR REPLACE FUNCTION currencyRound (Amt NUMBER, C_CurrencyTo_ID NUMBER, IsCosting --VARCHAR2)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Currency.round(java.math.BigDecimal,int,java.lang.String) --return java.math.BigDecimal';
CREATE FUNCTION currencyRound (Amt FLOAT, C_CurrencyTo_ID FLOAT, IsCosting VARCHAR)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.round';
/** BPartner **/
CREATE OR REPLACE FUNCTION bpartnerRemitLocation (p_C_BPartner_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.BPartner.remitLocation(int) return int';
CREATE FUNCTION bpartnerRemitLocation (p_C_BPartner_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.BPartner.remitLocation';
/** Invoice **/
--CREATE OR REPLACE FUNCTION invoiceOpen (p_C_Invoice_ID NUMBER, p_C_InvoicePaySchedule_ID --NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Invoice.open(int,int) return java.math.BigDecimal';
CREATE FUNCTION invoiceOpen (p_C_Invoice_ID FLOAT, p_C_InvoicePaySchedule_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.open';
--CREATE OR REPLACE FUNCTION invoicePaid (p_C_Invoice_ID NUMBER, p_C_Currency_ID NUMBER,
-- p_MultiplierAP NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Invoice.paid(int,int,int) return java.math.BigDecimal';
CREATE FUNCTION invoicePaid (p_C_Invoice_ID FLOAT, p_C_Currency_ID FLOAT, p_MultiplierAP FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.paid';
--CREATE OR REPLACE FUNCTION invoiceDiscount (p_C_Invoice_ID NUMBER, p_PayDate Date,
-- p_C_InvoicePaySchedule_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Invoice.discount(int,java.sql.Timestamp,int) return --java.math.BigDecimal';
CREATE FUNCTION invoiceDiscount (p_C_Invoice_ID FLOAT, p_PayDate TIMESTAMP, p_C_InvoicePaySchedule_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.discount';
/** Payment Term **/
--CREATE OR REPLACE FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID NUMBER, p_DocDate DATE,
-- p_PayDate DATE)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.PaymentTerm.dueDays(int,java.sql.Timestamp,java.sql.Timestamp) --return int';
CREATE FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID FLOAT, p_DocDate TIMESTAMP, p_PayDate TIMESTAMP)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.dueDays';
--CREATE OR REPLACE FUNCTION paymentTermDiscount (p_Amount NUMBER, p_C_Currency_ID NUMBER,
-- p_C_PaymentTerm_ID NUMBER, p_DocDate DATE, p_PayDate DATE)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.PaymentTerm.discount--(java.math.BigDecimal,int,int,java.sql.Timestamp,java.sql.Timestamp) return --java.math.BigDecimal';
CREATE FUNCTION paymentTermDiscount (p_Amount FLOAT, p_C_Currency_ID FLOAT, p_C_PaymentTerm_ID FLOAT, p_DocDate TIMESTAMP, p_PayDate TIMESTAMP)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.discount';
--CREATE OR REPLACE FUNCTION paymentTermDueDate (p_C_PaymentTerm_ID NUMBER, p_DocDate DATE)
-- RETURN DATE
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.PaymentTerm.dueDate(int,java.sql.Timestamp) return --java.sql.Timestamp';
CREATE FUNCTION paymentTermDueDate (p_C_PaymentTerm_ID FLOAT, p_DocDate TIMESTAMP)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.dueDate';
/** Payment **/
--CREATE OR REPLACE FUNCTION paymentAllocated (p_C_Payment_ID NUMBER, p_C_Currency_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Payment.allocated(int,int) return java.math.BigDecimal';
CREATE FUNCTION paymentTermDueDate (p_C_Payment_ID FLOAT, p_C_Currency_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Payment.allocated';
--CREATE OR REPLACE FUNCTION paymentAvailable (p_C_Payment_ID NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Payment.available(int) return java.math.BigDecimal';
CREATE FUNCTION paymentAvailable (p_C_Payment_ID FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Payment.available';
/** Account **/
--CREATE OR REPLACE FUNCTION acctBalance (p_Account_ID NUMBER, p_AmtDr NUMBER, p_AmtCr NUMBER)
-- RETURN NUMBER
-- AS LANGUAGE JAVA
-- NAME 'org.compiere.sqlj.Account.balance(int,java.math.BigDecimal,java.math.BigDecimal) --return java.math.BigDecimal';
CREATE FUNCTION paymentAvailable (p_Account_ID FLOAT, p_AmtDr FLOAT, p_AmtCr FLOAT)
RETURNS FLOAT
LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Account.balance';
--
--Below this is not translated yet
--
/** General **/
--BEGIN
-- dbms_java.grant_permission('ADEMPIERE','SYS:java.util.PropertyPermission', '*', 'read,write');
--END;
--Don't know if we have to do any corresponding action in DB2 for the above command.
/** 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;
CREATE FUNCTION charAt (p_string VARCHAR, p_pos FLOAT)
RETURNS VARCHAR
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN SUBSTR(p_string, p_pos, 1);
/** GetDate */
--CREATE OR REPLACE FUNCTION getdate
-- RETURN DATE
--AS
--BEGIN
-- RETURN SysDate;
--END;
CREATE FUNCTION getdate ()
RETURNS TIMESTAMP
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN CURRENT TIMESTAMP;
/** 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;
CREATE FUNCTION firstOf (p_date TIMESTAMP, p_datePart VARCHAR)
RETURNS TIMESTAMP
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN TRUNC(p_date, p_datePart);
/** 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 FUNCTION addDays (p_date TIMESTAMP, p_days FLOAT)
RETURNS TIMESTAMP
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN TRUNC(p_date) + p_days;
/** Difference in Days */
--CREATE OR REPLACE FUNCTION daysBetween
--(
-- p_date1 DATE,
-- p_date2 DATE
--)
-- RETURN NUMBER
--AS
--BEGIN
-- RETURN TRUNC(p_date1) - TRUNC(p_date2);
--END;
CREATE FUNCTION daysBetween (p_date1 TIMESTAMP, p_date2 TIMESTAMP)
RETURNS FLOAT
LANGUAGE SQL
CONTAINS SQL
NO EXTERNAL ACTION
DETERMINISTIC
RETURN TRUNC(p_date1) - TRUNC(p_date2);
--SELECT adempiereVersion(), adempiereProperty('java.vendor'),
-- TRUNC(getdate()) FROM DUAL
SELECT adempiereVersion(), adempiereProperty('java.vendor'), TRUNC(getdate())
FROM FROM SYSIBM.SYSDUMMY1!;
EXIT

10
sqlj/derby/RUN_sqlj.bat Normal file
View File

@ -0,0 +1,10 @@
@if (%ADEMPIERE_HOME%) == () (CALL ..\myEnvironment.bat Server) else (CALL %ADEMPIERE_HOME%\utils\myEnvironment.bat Server)
@Title Create Oracle SQLJ - %ADEMPIERE_HOME% (%ADEMPIERE_DB_NAME%)
@Rem
@Rem Author + Copyright 1999-2005 Jorg Janke
@Rem $Id: RUN_sqlj.bat,v 1.1 2005/04/27 05:21:46 jjanke Exp $
@Rem
call create %ADEMPIERE_DB_USER%/%ADEMPIERE_DB_PASSWORD%
@pause

10
sqlj/derby/RUN_sqlj.sh Normal file
View File

@ -0,0 +1,10 @@
# Author + Copyright 1999-2005 Jorg Janke
# $Id: RUN_sqlj.sh,v 1.1 2005/05/31 07:28:21 jjanke Exp $
if [ $ADEMPIERE_HOME ]; then
cd $ADEMPIERE_HOME/utils
fi
. ./myEnvironment.sh Server
echo Create Oracle SQLJ - $ADEMPIERE_HOME \($ADEMPIERE_DB_NAME\)
sh $ADEMPIERE_DB_PATH/create.sh $ADEMPIERE_DB_USER/$ADEMPIERE_DB_PASSWORD

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

14
sqlj/derby/create.bat Normal file
View File

@ -0,0 +1,14 @@
@Rem Create Derby SQLJ
@Rem
@Rem
@Rem runDefault first
@Rem
@Echo on
@if !"%SQLJPATH%"==! call setDefault.bat
@Echo Load Derby SQLJ and functions...
@REM SET CLASSPATH=
@java -Dij.driver=org.apache.derby.jdbc.ClientDriver -Dij.connection.Adempiere=jdbc:derby:%Derby_path%\Adempiere;create=true -Dij.user=%IJ_USER% -Dij.password=%IJ_PASSWORD% org.apache.derby.tools.ij < %SQLJPATH%\derby\createSQLJ.sql
pause

15
sqlj/derby/create.sh Normal file
View File

@ -0,0 +1,15 @@
# Create Oracle SQLJ
# Author + Copyright 1999-2005 Jorg Janke
# $Id: create.sh,v 1.3 2005/06/28 18:55:38 jjanke Exp $
#
# Parameter: <adempiereDBuser>/<adempiereDBpassword>
# unset CLASSPATH=
echo .
echo Load Oracle SQLJ ...
loadjava -user $1@$ADEMPIERE_DB_NAME -verbose -force -resolve $ADEMPIERE_HOME/lib/sqlj.jar
echo .
echo Create Oracle Functions ...
sqlplus $1@$ADEMPIERE_DB_NAME @$ADEMPIERE_HOME/utils/oracle/createSQLJ.sql

308
sqlj/derby/createSQLJ.sql Normal file
View File

@ -0,0 +1,308 @@
--
-- Create SQL Java Functions (Derby)
--
-- Author + Copyright 1999-2005 Jorg Janke
-- 09-28-2006 Jinglun Zhang modified from sqlj/oracle, ignore drop errors
--
-- load sqlj.jar to Derby
Call SQLJ.REMOVE_JAR ('adempiere_sqlj',0);
Call SQLJ.INSTALL_JAR ('c:\adempiere\adempiere-all2\sqlj\sqlj.jar', 'adempiere_sqlj', 0);
call SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.database.classpath','ADEMPIERE.adempiere_sqlj');
-- drop/create functions
DROP FUNCTION adempiereVersion;
CREATE FUNCTION adempiereVersion()
RETURNS VARCHAR(255)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getVersion';
DROP FUNCTION adempiereProperties;
CREATE FUNCTION adempiereProperties()
RETURNS VARCHAR(1022)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getProperties';
DROP FUNCTION adempiereProperty;
CREATE FUNCTION adempiereProperty(p_key VARCHAR(255))
RETURNS VARCHAR(1022)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getProperty';
-- Product --
DROP FUNCTION productAttribute;
CREATE FUNCTION productAttribute (M_AttributeSetInstance_ID int)
RETURNS VARCHAR(255)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.attributeName';
DROP FUNCTION bomPriceLimit;
CREATE FUNCTION bomPriceLimit (M_Product_ID int, M_PriceList_Version_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceLimit';
DROP FUNCTION bomPriceList;
CREATE FUNCTION bomPriceList (M_Product_ID int, M_PriceList_Version_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceList';
DROP FUNCTION bomPriceStd;
CREATE FUNCTION bomPriceStd (M_Product_ID int, M_PriceList_Version_ID int)
RETURNS Decimal(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomPriceStd';
DROP FUNCTION bomQtyAvailable;
CREATE FUNCTION bomQtyAvailable (M_Product_ID int, M_Warehouse_ID int,
M_Locator_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyAvailable';
DROP FUNCTION bomQtyOnHand;
CREATE FUNCTION bomQtyOnHand (M_Product_ID int, M_Warehouse_ID int,
M_Locator_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyOnHand';
DROP FUNCTION bomQtyOrdered;
CREATE FUNCTION bomQtyOrdered (M_Product_ID int, M_Warehouse_ID int,
M_Locator_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyOrdered';
DROP FUNCTION bomQtyReserved;
CREATE FUNCTION bomQtyReserved (M_Product_ID int, M_Warehouse_ID int,
M_Locator_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Product.bomQtyReserved';
-- Currency --
DROP FUNCTION currencyBase;
CREATE FUNCTION currencyBase (Amount DECIMAL(31,5), C_CurrencyFrom_ID int,
ConversionDate TIMESTAMP, AD_Client_ID int, AD_Org_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.base';
DROP FUNCTION currencyConvert;
--CREATE FUNCTION currencyConvert (Amount DOUBLE, C_CurrencyFrom_ID int,
-- C_CurrencyTo_ID int,
-- ConversionDate TIMESTAMP, C_ConversionType_ID int, AD_Client_ID int, AD_Org_ID int)
-- RETURNS DOUBLE
CREATE FUNCTION currencyConvert (Amount DECIMAL(31,5), C_CurrencyFrom_ID int,
C_CurrencyTo_ID int,
ConversionDate TIMESTAMP, C_ConversionType_ID int, AD_Client_ID int, AD_Org_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.convert';
DROP FUNCTION currencyRate;
CREATE FUNCTION currencyRate (C_CurrencyFrom_ID int, C_CurrencyTo_ID int,
ConversionDate TIMESTAMP, C_ConversionType_ID int, AD_Client_ID int, AD_Org_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.rate';
DROP FUNCTION currencyRound;
CREATE FUNCTION currencyRound (Amt DECIMAL(31,5), C_CurrencyTo_ID int, IsCosting VARCHAR(2))
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Currency.round';
-- BPartner --
DROP FUNCTION bpartnerRemitLocation;
CREATE FUNCTION bpartnerRemitLocation (p_C_BPartner_ID int)
RETURNS int
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.BPartner.remitLocation';
-- Invoice --
DROP FUNCTION invoiceOpen;
CREATE FUNCTION invoiceOpen (p_C_Invoice_ID int, p_C_InvoicePaySchedule_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.open';
DROP FUNCTION invoicePaid;
CREATE FUNCTION invoicePaid (p_C_Invoice_ID int, p_C_Currency_ID int,
p_MultiplierAP int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.paid';
DROP FUNCTION invoiceDiscount;
CREATE FUNCTION invoiceDiscount (p_C_Invoice_ID int, p_PayDate TIMESTAMP,
p_C_InvoicePaySchedule_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Invoice.discount';
-- Payment Term --
DROP FUNCTION paymentTermDueDays;
CREATE FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID int, p_DocDate TIMESTAMP,
p_PayDate TIMESTAMP)
RETURNS int
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.dueDays';
DROP FUNCTION paymentTermDiscount;
CREATE FUNCTION paymentTermDiscount (p_Amount DECIMAL(31,5), p_C_Currency_ID int,
p_C_PaymentTerm_ID int, p_DocDate TIMESTAMP, p_PayDate TIMESTAMP)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.discount';
DROP FUNCTION paymentTermDueDate;
CREATE FUNCTION paymentTermDueDate (p_C_PaymentTerm_ID int, p_DocDate TIMESTAMP)
RETURNS TIMESTAMP
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.PaymentTerm.dueDate';
-- Payment --
DROP FUNCTION paymentAllocated;
CREATE FUNCTION paymentAllocated (p_C_Payment_ID int, p_C_Currency_ID int)
RETURNS DECIMAL(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Payment.allocated';
DROP FUNCTION paymentAvailable;
CREATE FUNCTION paymentAvailable (p_C_Payment_ID int)
RETURNS Decimal(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Payment.available';
-- Account --
DROP FUNCTION acctBalance;
CREATE FUNCTION acctBalance (p_Account_ID int, p_AmtDr Decimal(31,5), p_AmtCr Decimal(31,5))
RETURNS Decimal(31,5)
PARAMETER STYLE JAVA LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Account.balance';
-- General --
--BEGIN
-- dbms_java.grant_permission('ADEMPIERE','SYS:java.util.PropertyPermission', '*', 'read,write');
--END;
-- Get Character at Position
DROP FUNCTION charAt;
CREATE FUNCTION charAt
(
p_string VARCHAR(2046),
p_pos int
)
RETURNS CHAR
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.charAt';
-- GetDate
DROP FUNCTION getdate;
CREATE FUNCTION getdate()
RETURNS TIMESTAMP
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getDate';
-- First Of DD/DY/MM/Q
DROP FUNCTION firstOf;
CREATE FUNCTION firstOf
(
p_date TIMESTAMP,
p_datePart VARCHAR(26)
)
RETURNS TIMESTAMP
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.firstOf';
-- Add Number of Days
DROP FUNCTION addDays;
CREATE FUNCTION addDays
(
p_date TIMESTAMP,
p_days int
)
RETURNS TIMESTAMP
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.addDays';
-- Difference in Days
DROP FUNCTION getDaysBetween;
CREATE FUNCTION getDaysBetween
(
p_date1 TIMESTAMP,
p_date2 TIMESTAMP
)
RETURNS int
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getDaysBetween';
-- Truncate Date
DROP FUNCTION trunc;
CREATE FUNCTION trunc
(
p_dateTime TIMESTAMP
)
RETURNS TIMESTAMP
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.trunc';
-- convert number to chars
DROP FUNCTION getChars;
CREATE FUNCTION getChars
(
p_number DECIMAL(31,5)
)
RETURNS VARCHAR(38)
PARAMETER STYLE JAVA NO SQL LANGUAGE JAVA
EXTERNAL NAME 'org.compiere.sqlj.Adempiere.getChars';
SELECT adempiereVersion(), adempiereProperty('java.vendor'),
getdate() FROM sysibm.sysdummy1;

View File

@ -0,0 +1,4 @@
Rem Set default for Derby
set SQLJPATH=c:\adempiere\adempiere-all2\sqlj
set derby_path=c:\adempiere\adempiere-all2\derby

1427
sqlj/derby/viewErrors.txt Normal file

File diff suppressed because it is too large Load Diff

10
sqlj/oracle/RUN_sqlj.bat Normal file
View File

@ -0,0 +1,10 @@
@if (%ADEMPIERE_HOME%) == () (CALL ..\myEnvironment.bat Server) else (CALL %ADEMPIERE_HOME%\utils\myEnvironment.bat Server)
@Title Create Oracle SQLJ - %ADEMPIERE_HOME% (%ADEMPIERE_DB_NAME%)
@Rem
@Rem Author + Copyright 1999-2005 Jorg Janke
@Rem $Id: RUN_sqlj.bat,v 1.1 2005/04/27 05:21:46 jjanke Exp $
@Rem
call create %ADEMPIERE_DB_USER%/%ADEMPIERE_DB_PASSWORD%
@pause

10
sqlj/oracle/RUN_sqlj.sh Normal file
View File

@ -0,0 +1,10 @@
# Author + Copyright 1999-2005 Jorg Janke
# $Id: RUN_sqlj.sh,v 1.1 2005/05/31 07:28:21 jjanke Exp $
if [ $ADEMPIERE_HOME ]; then
cd $ADEMPIERE_HOME/utils
fi
. ./myEnvironment.sh Server
echo Create Oracle SQLJ - $ADEMPIERE_HOME \($ADEMPIERE_DB_NAME\)
sh $ADEMPIERE_DB_PATH/create.sh $ADEMPIERE_DB_USER/$ADEMPIERE_DB_PASSWORD

16
sqlj/oracle/create.bat Normal file
View File

@ -0,0 +1,16 @@
@Rem Create Oracle SQLJ
@Rem Author + Copyright 1999-2005 Jorg Janke
@Rem $Id: create.bat,v 1.8 2005/05/31 07:28:22 jjanke Exp $
@Rem
@Rem Parameter: <adempiereDBuser>/<adempiereDBpassword>
@Rem
@Echo .
@Echo Load Oracle SQLJ ...
@SET CLASSPATH=
@call loadjava -user %1@%ADEMPIERE_DB_NAME% -verbose -force -resolve %ADEMPIERE_HOME%\lib\sqlj.jar
@Echo .
@Echo Create Oracle Functions ...
@sqlplus %1@%ADEMPIERE_DB_NAME% @%ADEMPIERE_HOME%\utils\oracle\createSQLJ.sql

15
sqlj/oracle/create.sh Normal file
View File

@ -0,0 +1,15 @@
# Create Oracle SQLJ
# Author + Copyright 1999-2005 Jorg Janke
# $Id: create.sh,v 1.3 2005/06/28 18:55:38 jjanke Exp $
#
# Parameter: <adempiereDBuser>/<adempiereDBpassword>
# unset CLASSPATH=
echo .
echo Load Oracle SQLJ ...
loadjava -user $1@$ADEMPIERE_DB_NAME -verbose -force -resolve $ADEMPIERE_HOME/lib/sqlj.jar
echo .
echo Create Oracle Functions ...
sqlplus $1@$ADEMPIERE_DB_NAME @$ADEMPIERE_HOME/utils/oracle/createSQLJ.sql

230
sqlj/oracle/createSQLJ.sql Normal file
View File

@ -0,0 +1,230 @@
/**
* Create SQL Java Functions (Oracle)
*
* Author + Copyright 1999-2005 Jorg Janke
* $Header: /cvs/adempiere/sqlj/oracle/createSQLJ.sql,v 1.1 2006/04/21 18:04:47 jjanke Exp $
*/
CREATE OR REPLACE FUNCTION adempiereVersion
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Adempiere.getVersion() return java.lang.String';
/
CREATE OR REPLACE FUNCTION adempiereProperties
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Adempiere.getProperties() return java.lang.String';
/
CREATE OR REPLACE FUNCTION adempiereProperty(p_key VARCHAR2)
RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Adempiere.getProperty(java.lang.String) return java.lang.String';
/
/** Product **/
CREATE OR REPLACE FUNCTION productAttribute (M_AttributeSetInstance_ID NUMBER)
RETURN NVARCHAR2
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.attributeName(int) return java.lang.String';
/
CREATE OR REPLACE FUNCTION bomPriceLimit (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomPriceLimit(int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomPriceList (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomPriceList(int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomPriceStd (M_Product_ID NUMBER, M_PriceList_Version_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomPriceStd(int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomQtyAvailable (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
M_Locator_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomQtyAvailable(int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomQtyOnHand (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
M_Locator_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomQtyOnHand(int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomQtyOrdered (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
M_Locator_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomQtyOrdered(int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION bomQtyReserved (M_Product_ID NUMBER, M_Warehouse_ID NUMBER,
M_Locator_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Product.bomQtyReserved(int,int,int) return java.math.BigDecimal';
/
/** Currency **/
CREATE OR REPLACE FUNCTION currencyBase (Amount NUMBER, C_CurrencyFrom_ID NUMBER,
ConversionDate DATE, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Currency.base(java.math.BigDecimal,int,java.sql.Timestamp,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION currencyConvert (Amount NUMBER, C_CurrencyFrom_ID NUMBER,
C_CurrencyTo_ID NUMBER,
ConversionDate DATE, C_ConversionType_ID NUMBER, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Currency.convert(java.math.BigDecimal,int,int,java.sql.Timestamp,int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION currencyRate (C_CurrencyFrom_ID NUMBER, C_CurrencyTo_ID NUMBER,
ConversionDate DATE, C_ConversionType_ID NUMBER, AD_Client_ID NUMBER, AD_Org_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Currency.rate(int,int,java.sql.Timestamp,int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION currencyRound (Amt NUMBER, C_CurrencyTo_ID NUMBER, IsCosting VARCHAR2)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Currency.round(java.math.BigDecimal,int,java.lang.String) return java.math.BigDecimal';
/
/** BPartner **/
CREATE OR REPLACE FUNCTION bpartnerRemitLocation (p_C_BPartner_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.BPartner.remitLocation(int) return int';
/
/** Invoice **/
CREATE OR REPLACE FUNCTION invoiceOpen (p_C_Invoice_ID NUMBER, p_C_InvoicePaySchedule_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Invoice.open(int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION invoicePaid (p_C_Invoice_ID NUMBER, p_C_Currency_ID NUMBER,
p_MultiplierAP NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Invoice.paid(int,int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION invoiceDiscount (p_C_Invoice_ID NUMBER, p_PayDate Date,
p_C_InvoicePaySchedule_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Invoice.discount(int,java.sql.Timestamp,int) return java.math.BigDecimal';
/
/** Payment Term **/
CREATE OR REPLACE FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID NUMBER, p_DocDate DATE,
p_PayDate DATE)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.PaymentTerm.dueDays(int,java.sql.Timestamp,java.sql.Timestamp) return int';
/
CREATE OR REPLACE FUNCTION paymentTermDiscount (p_Amount NUMBER, p_C_Currency_ID NUMBER,
p_C_PaymentTerm_ID NUMBER, p_DocDate DATE, p_PayDate DATE)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.PaymentTerm.discount(java.math.BigDecimal,int,int,java.sql.Timestamp,java.sql.Timestamp) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION paymentTermDueDate (p_C_PaymentTerm_ID NUMBER, p_DocDate DATE)
RETURN DATE
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.PaymentTerm.dueDate(int,java.sql.Timestamp) return java.sql.Timestamp';
/
/** Payment **/
CREATE OR REPLACE FUNCTION paymentAllocated (p_C_Payment_ID NUMBER, p_C_Currency_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Payment.allocated(int,int) return java.math.BigDecimal';
/
CREATE OR REPLACE FUNCTION paymentAvailable (p_C_Payment_ID NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Payment.available(int) return java.math.BigDecimal';
/
/** Account **/
CREATE OR REPLACE FUNCTION acctBalance (p_Account_ID NUMBER, p_AmtDr NUMBER, p_AmtCr NUMBER)
RETURN NUMBER
AS LANGUAGE JAVA
NAME 'org.compiere.sqlj.Account.balance(int,java.math.BigDecimal,java.math.BigDecimal) return java.math.BigDecimal';
/
/** General **/
BEGIN
dbms_java.grant_permission('ADEMPIERE','SYS:java.util.PropertyPermission', '*', 'read,write');
END;
/
/** 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;
/
/** Difference in Days */
CREATE OR REPLACE FUNCTION daysBetween
(
p_date1 DATE,
p_date2 DATE
)
RETURN NUMBER
AS
BEGIN
RETURN TRUNC(p_date1) - TRUNC(p_date2);
END;
/
SELECT --adempiereVersion(), adempiereProperty('java.vendor'),
TRUNC(getdate()) FROM DUAL
/
EXIT

View File

@ -0,0 +1,8 @@
ALTER TABLE AD_Menu RENAME COLUMN Action to ActionRun;
ALTER TABLE AD_WF_Node RENAME COLUMN Action to ActionRun;
ALTER TABLE AD_WF_Node RENAME COLUMN Limit to DurationLimit;
--ALTER TABLE MPC_Order_Node RENAME COLUMN Action to ActionRun;
ALTER TABLE AD_Workflow RENAME COLUMN Limit to DurationLimit;
--select table_name,column_name,data_type,data_length,
-- data_precision,data_scale,nullable,column_id
-- from user_tab_columns WHERE COLUMN_NAME = 'Action';

3146
sqlj/postgresql/View253b.sql Executable file

File diff suppressed because it is too large Load Diff

2853
sqlj/postgresql/Views252d.sql Executable file

File diff suppressed because it is too large Load Diff

3121
sqlj/postgresql/Views311.sql Executable file

File diff suppressed because it is too large Load Diff

357
sqlj/postgresql/alias.sql Executable file
View File

@ -0,0 +1,357 @@
/** 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;
-- TIMESTAMP
/*
CREATE OR REPLACE FUNCTION addDays (day TIMESTAMP , days DECIMAL)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
RETURN addDays(CAST (day AS TIMESTAMP WITH TIME ZONE),ID(days));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP , days DECIMAL)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
RETURN addDays(CAST (day AS TIMESTAMP WITH TIME ZONE),ID(days * -1));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION addDays (day TIMESTAMP , days INTEGER)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
RETURN addDays(CAST (day AS TIMESTAMP WITH TIME ZONE),ID(days));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION subtractdays (day TIMESTAMP , days INTEGER)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
RETURN addDays(CAST (day AS TIMESTAMP WITH TIME ZONE),ID(days * -1));
END;
$$ LANGUAGE plpgsql VOLATILE;*/
/** Product **/
/*CREATE OR REPLACE FUNCTION adempiere.productAttribute (M_AttributeSetInstance_ID NUMERIC)
RETURNS VARCHAR AS $$
BEGIN
RETURN adempiere.productAttribute(adempiere.ID(M_AttributeSetInstance_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomPriceLimit (M_Product_ID NUMERIC, M_PriceList_Version_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomPriceLimit(adempiere.ID(M_Product_ID),ID(M_PriceList_Version_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomPriceList (M_Product_ID NUMERIC, M_PriceList_Version_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomPriceList(adempiere.ID(M_Product_ID),adempiere.ID(M_PriceList_Version_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomPriceStd (M_Product_ID NUMERIC, M_PriceList_Version_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomPriceStd(adempiere.ID(M_Product_ID),adempiere.ID(M_PriceList_Version_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomQtyAvailable (M_Product_ID NUMERIC, M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomQtyAvailable(adempiere.ID(M_Product_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyOnHand (M_Product_ID NUMERIC, M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN bomQtyOnHand(adempiere.ID(M_Product_ID),ID(M_Warehouse_ID),ID(M_Locator_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomQtyOrdered (M_Product_ID NUMERIC, M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomQtyOrdered(adempiere.ID(M_Product_ID),adempiere.ID(M_Warehouse_adempiere.ID),adempiere.ID(M_Locator_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomQtyReserved (M_Product_ID NUMERIC, M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.bomQtyReserved(adempiere.ID(M_Product_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bomQtyAvailable(M_Product_ID NUMERIC, M_AttributeSetInstance_ID NUMERIC,M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS
$BODY$
BEGIN
RETURN adempiere.bomQtyAvailable(adempiere.ID(M_Product_ID),adempiere.ID(M_AttributeSetInstance_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
--ALTER FUNCTION adempiere.bomqtyavailable("numeric", "numeric", "numeric", "numeric") OWNER TO adempiere;
CREATE OR REPLACE FUNCTION adempiere.bomQtyOnHand(M_Product_ID NUMERIC, M_AttributeSetInstance_ID NUMERIC,M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS
$BODY$
BEGIN
RETURN adempiere.bomQtyOnHand(adempiere.ID(M_Product_ID), adempiere.ID(M_AttributeSetInstance_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
--ALTER FUNCTION adempiere.bomqtyonhand("numeric", "numeric", "numeric", "numeric") OWNER TO adempiere;
CREATE OR REPLACE FUNCTION adempiere.bomQtyOrdered(M_Product_ID NUMERIC, M_AttributeSetInstance_ID NUMERIC,M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS
$BODY$
BEGIN
RETURN adempiere.bomQtyOrdered(adempiere.ID(M_Product_ID), adempiere.ID(M_AttributeSetInstance_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
--ALTER FUNCTION adempiere.bomqtyordered("numeric", "numeric", "numeric", "numeric") OWNER TO adempiere;
CREATE OR REPLACE FUNCTION adempiere.bomQtyReserved(M_Product_ID NUMERIC, M_AttributeSetInstance_ID INTEGER,M_Warehouse_ID NUMERIC, M_Locator_ID NUMERIC)
RETURNS NUMERIC AS
$BODY$
BEGIN
RETURN adempiere.bomQtyReserved(adempiere.ID(M_Product_ID), adempiere.ID(M_AttributeSetInstance_ID),adempiere.ID(M_Warehouse_ID),adempiere.ID(M_Locator_ID));
END;
$BODY$
LANGUAGE plpgsql VOLATILE;
--ALTER FUNCTION adempiere.bomqtyreserved("numeric", "numeric", "numeric", "numeric") OWNER TO adempiere;
*
CREATE OR REPLACE FUNCTION adempiere.currencyBase (Amount NUMERIC, C_CurrencyFrom_ID NUMERIC,
ConversionDate TIMESTAMP WITH TIME ZONE, AD_Client_ID NUMERIC, AD_Org_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.currencyBase (Amount,adempiere.ID(C_CurrencyFrom_ID),ConversionDate,adempiere.ID(AD_Client_ID),adempiere.ID(AD_Org_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.currencyConvert (Amount NUMERIC, C_CurrencyFrom_ID NUMERIC, C_CurrencyTo_ID NUMERIC,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID NUMERIC, AD_Client_ID NUMERIC, AD_Org_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.currencyConvert (Amount ,adempiere.ID(C_CurrencyFrom_ID),adempiere.ID(C_CurrencyTo_ID),ConversionDate,adempiere.ID(C_ConversionType_ID),adempiere.ID(AD_Client_ID),adempiere.ID(AD_Org_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.currencyRate (C_CurrencyFrom_ID NUMERIC, C_CurrencyTo_ID NUMERIC,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID NUMERIC, AD_Client_ID NUMERIC, AD_Org_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.currencyRate (adempiere.ID(C_CurrencyFrom_ID), adempiere.ID(C_CurrencyTo_ID),ConversionDate,adempiere.ID(C_ConversionType_ID),adempiere.ID(AD_Client_ID),adempiere.ID(AD_Org_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.bpartnerRemitLocation (p_C_BPartner_ID NUMERIC)
RETURNS INTEGER AS $$
BEGIN
RETURN adempiere.partnerRemitLocation (adempiere.ID(p_C_BPartner_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.invoiceOpen (p_C_Invoice_ID NUMERIC, p_C_InvoicePaySchedule_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.invoiceOpen (adempiere.ID(p_C_Invoice_ID),adempiere.ID(p_C_InvoicePaySchedule_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.invoicePaid (p_C_Invoice_ID NUMERIC, p_C_Currency_ID NUMERIC, p_MultiplierAP NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.invoicePaid (adempiere.ID(p_C_Invoice_ID),adempiere.ID(p_C_Currency_ID),adempiere.ID(p_MultiplierAP));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.invoiceDiscount (p_C_Invoice_ID NUMERIC, p_PayDate TIMESTAMP WITH TIME ZONE, p_C_InvoicePaySchedule_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.invoiceDiscount (adempiere.ID(p_C_Invoice_ID), p_PayDate , adempiere.ID(p_C_InvoicePaySchedule_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.paymentTermDueDays (p_C_PaymentTerm_ID NUMERIC, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE)
RETURNS INTEGER AS $$
BEGIN
RETURN adempiere.paymentTermDueDays (adempiere.ID(p_C_PaymentTerm_ID), p_DocDate , p_PayDate);
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.paymentTermDueDate (p_C_PaymentTerm_ID NUMERIC, p_DocDate TIMESTAMP WITH TIME ZONE)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
RETURN adempiere.paymentTermDueDays (adempiere.ID(p_C_PaymentTerm_ID), p_DocDate );
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.paymentTermDiscount (p_Amount NUMERIC, p_C_PaymentTerm_ID NUMERIC, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.paymentTermDiscount (p_Amount, adempiere.ID(p_C_PaymentTerm_ID), p_DocDate , p_PayDate );
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.paymentAllocated (p_C_Payment_ID NUMERIC, p_C_Currency_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.paymentAllocated (adempiere.ID(p_C_Payment_ID),adempiere.ID(p_C_Currency_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.paymentAvailable (p_C_Payment_ID NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.paymentAvailable (adempiere.ID(p_C_Payment_ID));
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.acctBalance (p_Account_ID NUMERIC, p_AmtDr NUMERIC, p_AmtCr NUMERIC)
RETURNS NUMERIC AS $$
BEGIN
RETURN adempiere.acctBalance (adempiere.ID(p_Account_ID), p_AmtDr , p_AmtCr);
END;
$$ LANGUAGE plpgsql VOLATILE;
CREATE OR REPLACE FUNCTION adempiere.documentNo (p_MPC_MRP_ID NUMERIC)
RETURNS VARCHAR AS $$
BEGIN
RETURN adempiere.documentNo(adempiere.ID(p_MPC_MRP_ID));
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 = -);
/*DROP OPERATOR adempiere.+ (interval, numeric);
CREATE OPERATOR adempiere.+ ( PROCEDURE = adempiere.adddays,
LEFTARG = INTERVAL, RIGHTARG = NUMERIC,
COMMUTATOR = +);
DROP OPERATOR adempiere.- (interval, numeric);
CREATE OPERATOR adempiere.- ( PROCEDURE = adempiere.subtractdays,
LEFTARG = INTERVAL, RIGHTARG = NUMERIC,
COMMUTATOR = -);
*/
/*
DROP OPERATOR adempiere.+ (interval, integer);
CREATE OPERATOR adempiere.+ ( PROCEDURE = adempiere.adddays,
LEFTARG = INTERVAL, RIGHTARG = INTEGER,
COMMUTATOR = +);
DROP OPERATOR adempiere.- (interval, integer);
CREATE OPERATOR adempiere.- ( PROCEDURE = adempiere.subtractdays,
LEFTARG = INTERVAL, RIGHTARG = INTEGER,
COMMUTATOR = -);
*/
/*CREATE OR REPLACE FUNCTION nextID ( p_AD_Sequence_ID NUMERIC, p_System CHAR)
RETURNS NUMERIC AS $$
DECLARE
o_NextID INTEGER := -1;
BEGIN
IF (p_System = 'Y') THEN
LOCK TABLE AD_Sequence IN ACCESS EXCLUSIVE MODE;
--LOCK TABLE films IN SHARE ROW EXCLUSIVE MODE;
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;
--COMMIT;
RETURN o_NextID;
ELSE
LOCK TABLE AD_Sequence IN ACCESS EXCLUSIVE MODE;
--LOCK TABLE films IN SHARE ROW EXCLUSIVE MODE;
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;
--COMMIT;
RETURN o_NextID;
END IF;
--
RAICE EXCEPTION 'Failed to update' ;
RETURN null;
END;
$$ LANGUAGE plpgsql;
*/

247
sqlj/postgresql/createDDL.sql Executable file
View File

@ -0,0 +1,247 @@
------------------
-- Created by: Andre Whittick Nasser, OCP
-- Email: andre_nasser@yahoo.com.br
-- Website: www.geocities.com/andre_nasser
-- Date: Oct 24, 2001
-- Description: Reverse Engineer your existing schema objects
------------------
set termout off
set feedback off
set serveroutput on size 1000000
spool table.sql
begin
dbms_output.put_line('--');
dbms_output.put_line('-- DROP TABLES --');
dbms_output.put_line('--');
for rt in (select tname from tab order by tname) loop
dbms_output.put_line('DROP TABLE '||rt.tname||' CASCADE CONSTRAINTS;');
end loop;
end;
/
declare
v_tname varchar2(30);
v_cname char(32);
v_type char(20);
v_null varchar2(10);
v_maxcol number;
v_virg varchar2(1);
begin
dbms_output.put_line('--');
dbms_output.put_line('-- CREATE TABLES --');
dbms_output.put_line('--');
for rt in (select table_name from user_tables order by 1) loop
v_tname:=rt.table_name;
v_virg:=',';
dbms_output.put_line('CREATE TABLE '||v_tname||' (');
for rc in (select table_name,column_name,data_type,data_length,
data_precision,data_scale,nullable,column_id
from user_tab_columns tc
where tc.table_name=rt.table_name
order by table_name,column_id) loop
v_cname:=rc.column_name;
if rc.data_type='VARCHAR2' then
v_type:='VARCHAR2('||rc.data_length||')';
elsif rc.data_type='NUMBER' and rc.data_precision is null
and
rc.data_scale=0 then
v_type:='INTEGER';
elsif rc.data_type='NUMBER' and rc.data_precision is null
and
rc.data_scale is null then
v_type:='NUMBER';
elsif rc.data_type='NUMBER' and rc.data_scale='0' then
v_type:='NUMBER('||rc.data_precision||')';
elsif rc.data_type='NUMBER' and rc.data_scale<>'0' then
v_type:='NUMBER('||rc.data_precision||','||rc.data_scale||')';
elsif rc.data_type='CHAR' then
v_type:='CHAR('||rc.data_length||')';
else v_type:=rc.data_type;
end if;
if rc.nullable='Y' then
v_null:='NULL';
else
v_null:='NOT NULL';
end if;
select max(column_id)
into v_maxcol
from user_tab_columns c
where c.table_name=rt.table_name;
if rc.column_id=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (v_cname||v_type||v_null||v_virg);
end loop;
dbms_output.put_line(');');
end loop;
end;
/
spool off
spool index.sql
declare
v_virg varchar2(1);
v_maxcol number;
begin
dbms_output.put_line('--');
dbms_output.put_line('-- PRIMARY KEYS --');
dbms_output.put_line('--');
for rcn in (select table_name,constraint_name
from user_constraints
where constraint_type='P'
order by table_name) loop
dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD ');
dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
dbms_output.put_line ('PRIMARY KEY (');
v_virg:=',';
for rcl in (select column_name,position
from user_cons_columns cl
where cl.constraint_name=rcn.constraint_name
order by position) loop
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.constraint_name;
if rcl.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
dbms_output.put_line(');');
--dbms_output.put_line('USING INDEX );');
end loop;
end;
/
declare
v_virg varchar2(1);
v_maxcol number;
v_tname varchar2(30);
begin
dbms_output.put_line('--');
dbms_output.put_line('-- FOREIGN KEYS --');
dbms_output.put_line('--');
for rcn in (select table_name,constraint_name,delete_rule,r_constraint_name
from dba_constraints
where constraint_type='R' AND OWNER = 'COMPIERE'
order by table_name) loop
--dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD (');
dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD ');
dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
dbms_output.put_line ('FOREIGN KEY (');
v_virg:=',';
for rcl in (select column_name,position
from user_cons_columns cl
where cl.constraint_name=rcn.constraint_name
order by position) loop
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.constraint_name;
if rcl.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
select table_name
into v_tname
from user_constraints c
where c.constraint_name=rcn.r_constraint_name;
dbms_output.put_line(') REFERENCES '||v_tname||' (');
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.r_constraint_name;
v_virg:=',';
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.r_constraint_name;
for rcr in (select column_name,position
from user_cons_columns cl
where rcn.r_constraint_name=cl.constraint_name
order by position) loop
if rcr.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcr.column_name||v_virg);
end loop;
dbms_output.put_line(' ) ');
if rcn.delete_rule='CASCADE' then
dbms_output.put_line(' ON DELETE CASCADE ; ');
else
dbms_output.put_line('; ');
end if;
end loop;
end;
/
begin
dbms_output.put_line('--');
dbms_output.put_line('-- DROP SEQUENCES --');
dbms_output.put_line('--');
for rs in (select sequence_name
from user_sequences
where sequence_name like 'SQ%'
order by sequence_name) loop
dbms_output.put_line('DROP SEQUENCE '||rs.sequence_name||';');
end loop;
dbms_output.put_line('--');
dbms_output.put_line('-- CREATE SEQUENCES --');
dbms_output.put_line('--');
for rs in (select sequence_name
from user_sequences
where sequence_name like 'SQ%'
order by sequence_name) loop
dbms_output.put_line('CREATE SEQUENCE '||rs.sequence_name||' NOCYCLE;');
end loop;
end;
/
declare
v_virg varchar2(1);
v_maxcol number;
begin
dbms_output.put_line('--');
dbms_output.put_line('-- INDEXES --');
dbms_output.put_line('--');
for rid in (select index_name, table_name
from user_indexes
where index_name not in (select constraint_name from
user_constraints)
and index_type<>'LOB'
order by index_name) loop
v_virg:=',';
dbms_output.put_line('CREATE INDEX '||rid.index_name||' ON
'||rid.table_name||' (');
for rcl in (select column_name,column_position
from user_ind_columns cl
where cl.index_name=rid.index_name
order by column_position) loop
select max(column_position)
into v_maxcol
from user_ind_columns c
where c.index_name=rid.index_name;
if rcl.column_position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
dbms_output.put_line(');');
end loop;
end;
/
spool off
set feedback on
set termout on
-- End of script

18408
sqlj/postgresql/index.sql Executable file

File diff suppressed because it is too large Load Diff

15625
sqlj/postgresql/kompieredata252d.sql Executable file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

232
sqlj/postgresql/sqlj.ddr Executable file
View File

@ -0,0 +1,232 @@
SQLActions[ ] = {
"BEGIN INSTALL
--CREATE SCHEMA fun;
BEGIN PostgreSQL SET search_path TO adempiere END PostgreSQL;
CREATE OR REPLACE FUNCTION adempiereVersion()
RETURNS VARCHAR
AS 'org.compiere.sqlj.Adempiere.getVersion()'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION adempiereProperties()
RETURNS VARCHAR
AS 'org.compiere.sqlj.Adempiere.getProperties()'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION adempiereProperty(p_key VARCHAR)
RETURNS VARCHAR
AS 'org.compiere.sqlj.Adempiere.getProperty(java.lang.String)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION TRUNC(datetime TIMESTAMP WITH TIME ZONE)
RETURNS TIMESTAMP WITH TIME ZONE
AS 'org.compiere.sqlj.Adempiere.trunc(java.sql.Timestamp)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION firstOf(datetime TIMESTAMP WITH TIME ZONE ,xx VARCHAR)
RETURNS TIMESTAMP WITH TIME ZONE
AS 'org.compiere.sqlj.Adempiere.firstOf(java.sql.Timestamp,java.lang.String)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION daysBetween(datetime1 TIMESTAMP WITH TIME ZONE , datetime2 TIMESTAMP WITH TIME ZONE)
RETURNS INTEGER
AS 'org.compiere.sqlj.Adempiere.getDaysBetween(java.sql.Timestamp,java.sql.Timestamp)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION addDays(day TIMESTAMP WITH TIME ZONE, days INTEGER)
RETURNS TIMESTAMP WITH TIME ZONE
AS 'org.compiere.sqlj.Adempiere.addDays(java.sql.Timestamp,int)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION charAt(source VARCHAR, pos INTEGER)
RETURNS VARCHAR
AS 'org.compiere.sqlj.Adempiere.charAt (java.lang.String,int)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION nextID(AD_Sequence_ID INTEGER, System VARCHAR)
RETURNS INTEGER
AS 'org.compiere.sqlj.Adempiere.nextID(int,java.lang.String)'
LANGUAGE java VOLATILE;;
/** Product **/
CREATE OR REPLACE FUNCTION productAttribute (M_AttributeSetInstance_ID INTEGER)
RETURNS VARCHAR
AS 'org.compiere.sqlj.Product.attributeName(int)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION bomPriceLimit (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomPriceLimit(int,int)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION bomPriceList (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomPriceList(int,int)'
LANGUAGE java VOLATILE;;
CREATE OR REPLACE FUNCTION bomPriceStd (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomPriceStd(int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyAvailable (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyAvailable(int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyAvailable (M_Product_ID INTEGER , M_AttributeSetInstance_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyAvailable(int,int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyOnHand (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyOnHand(int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyOnHand (M_Product_ID INTEGER, M_AttributeSetInstance_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyOnHand(int,int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyOrdered (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyOrdered(int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyOrdered (M_Product_ID INTEGER, M_AttributeSetInstance_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyOrdered(int,int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyReserved (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyReserved(int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION bomQtyReserved (M_Product_ID INTEGER, M_AttributeSetInstance_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Product.bomQtyReserved(int,int,int,int)'
LANGUAGE java VOLATILE;
/** Currency **/
CREATE OR REPLACE FUNCTION currencyBase (Amount NUMERIC, C_CurrencyFrom_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, AD_Client_ID INTEGER, AD_Org_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Currency.base(java.math.BigDecimal,int,java.sql.Timestamp,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION currencyConvert (Amount NUMERIC, C_CurrencyFrom_ID INTEGER, C_CurrencyTo_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID INTEGER, AD_Client_ID INTEGER, AD_Org_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Currency.convert(java.math.BigDecimal,int,int,java.sql.Timestamp,int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION currencyRate (C_CurrencyFrom_ID INTEGER, C_CurrencyTo_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID INTEGER, AD_Client_ID INTEGER, AD_Org_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Currency.rate(int,int,java.sql.Timestamp,int,int,int)'
LANGUAGE java VOLATILE;
/** BPartner **/
CREATE OR REPLACE FUNCTION bpartnerRemitLocation (p_C_BPartner_ID INTEGER)
RETURNS INTEGER
AS 'org.compiere.sqlj.BPartner.remitLocation(int)'
LANGUAGE java VOLATILE;
/** Invoice **/
CREATE OR REPLACE FUNCTION invoiceOpen (p_C_Invoice_ID INTEGER, p_C_InvoicePaySchedule_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Invoice.open(int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION invoicePaid (p_C_Invoice_ID INTEGER, p_C_Currency_ID INTEGER, p_MultiplierAP INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Invoice.paid(int,int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION invoiceDiscount (p_C_Invoice_ID INTEGER, p_PayDate TIMESTAMP WITH TIME ZONE, p_C_InvoicePaySchedule_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Invoice.discount(int,java.sql.Timestamp,int)'
LANGUAGE java VOLATILE;
/** Payment Term **/
CREATE OR REPLACE FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID INTEGER, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE)
RETURNS INTEGER
AS 'org.compiere.sqlj.PaymentTerm.dueDays(int,java.sql.Timestamp,java.sql.Timestamp)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION paymentTermDueDate (p_C_PaymentTerm_ID INTEGER, p_DocDate TIMESTAMP WITH TIME ZONE)
RETURNS TIMESTAMP WITH TIME ZONE
AS 'org.compiere.sqlj.PaymentTerm.dueDate(int,java.sql.Timestamp)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION paymentTermDiscount (p_Amount NUMERIC, p_C_PaymentTerm_ID INTEGER, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE)
RETURNS NUMERIC
AS 'org.compiere.sqlj.PaymentTerm.discount(java.math.BigDecimal,int,java.sql.Timestamp,java.sql.Timestamp)'
LANGUAGE java VOLATILE;
/** Payment **/
CREATE OR REPLACE FUNCTION paymentAllocated (p_C_Payment_ID INTEGER, p_C_Currency_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Payment.allocated(int,int)'
LANGUAGE java VOLATILE;
CREATE OR REPLACE FUNCTION paymentAvailable (p_C_Payment_ID INTEGER)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Payment.available(int)'
LANGUAGE java VOLATILE;
/** Account **/
CREATE OR REPLACE FUNCTION acctBalance (p_Account_ID INTEGER, p_AmtDr NUMERIC, p_AmtCr NUMERIC)
RETURNS NUMERIC
AS 'org.compiere.sqlj.Account.balance(int,java.math.BigDecimal,java.math.BigDecimal)'
LANGUAGE java VOLATILE;
/** Manufacturing e-evolution **/
CREATE OR REPLACE FUNCTION documentNo (p_MPC_MRP_ID INTEGER)
RETURNS VARCHAR
AS 'org.compiere.sqlj.Manufacturing.documentNo(int)'
LANGUAGE java VOLATILE;
END INSTALL",
"BEGIN REMOVE
--DROP SCHEMA fun CASCADE;
--DROP FUNCTION adempiereVersion();
--DROP FUNCTION adempiereProperties();
--DROP FUNCTION adempiereProperty(p_key VARCHAR);
--DROP FUNCTION TRUNC(datetime TIMESTAMP WITH TIME ZONE);
--DROP FUNCTION firstOf(datetime TIMESTAMP WITH TIME ZONE ,xx VARCHAR);
--DROP FUNCTION daysBetween(datetime1 TIMESTAMP WITH TIME ZONE , datetime2 TIMESTAMP WITH TIME ZONE);
--DROP FUNCTION addDays(day TIMESTAMP WITH TIME ZONE, days INTEGER);
--DROP FUNCTION charAt(source VARCHAR, pos NUMERIC);
--DROP FUNCTION productAttribute (M_AttributeSetInstance_ID INTEGER);
--DROP FUNCTION bomPriceLimit (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
--DROP FUNCTION bomPriceList (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
--DROP FUNCTION bomPriceStd (M_Product_ID INTEGER, M_PriceList_Version_ID INTEGER);
--DROP FUNCTION bomQtyAvailable (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER);
--DROP FUNCTION bomQtyOnHand (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER);
--DROP FUNCTION bomQtyOrdered (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER);
--DROP FUNCTION bomQtyReserved (M_Product_ID INTEGER, M_Warehouse_ID INTEGER, M_Locator_ID INTEGER);
--DROP FUNCTION currencyBase (Amount DECIMAL, C_CurrencyFrom_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, AD_Client_ID INTEGER, AD_Org_ID INTEGER);
--DROP FUNCTION currencyConvert (Amount NUMERIC, C_CurrencyFrom_ID INTEGER, C_CurrencyTo_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID INTEGER, AD_Client_ID NUMERIC, AD_Org_ID INTEGER);
--DROP FUNCTION currencyRate (C_CurrencyFrom_ID INTEGER, C_CurrencyTo_ID INTEGER,
ConversionDate TIMESTAMP WITH TIME ZONE, C_ConversionType_ID INTEGER, AD_Client_ID INTEGER, AD_Org_ID INTEGER);
--DROP FUNCTION bpartnerRemitLocation (p_C_BPartner_ID INTEGER);
--DROP FUNCTION invoiceOpen (p_C_Invoice_ID INTEGER, p_C_InvoicePaySchedule_ID INTEGER);
--DROP FUNCTION invoicePaid (p_C_Invoice_ID INTEGER, p_C_Currency_ID INTEGER, p_MultiplierAP NUMERIC);
--DROP FUNCTION invoiceDiscount (p_C_Invoice_ID INTEGER, p_PayDate TIMESTAMP WITH TIME ZONE, p_C_InvoicePaySchedule_ID INTEGER);
--DROP FUNCTION paymentTermDueDays (p_C_PaymentTerm_ID INTEGER, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE);
--DROP FUNCTION paymentTermDiscount (p_Amount NUMERIC, p_C_PaymentTerm_ID INTEGER, p_DocDate TIMESTAMP WITH TIME ZONE, p_PayDate TIMESTAMP WITH TIME ZONE);
--DROP FUNCTION paymentAllocated (p_C_Payment_ID INTEGER, p_C_Currency_ID INTEGER);
--DROP FUNCTION paymentAvailable (p_C_Payment_ID INTEGER);
--DROP FUNCTION acctBalance (p_Account_ID INTEGER, p_AmtDr NUMERIC, p_AmtCr NUMERIC);
END REMOVE"
}

4
sqlj/postgresql/sqlj.manifest Executable file
View File

@ -0,0 +1,4 @@
Manifest-Version: 1.0
Name: deployment/sqlj.ddr
SQLJDeploymentDescriptor: TRUE

187
sqlj/postgresql/viewsmpc.sql Executable file
View File

@ -0,0 +1,187 @@
CREATE TABLE compiere.MPC_Order_Node_Trl
(
ad_language varchar(6) NOT NULL,
mpc_order_node_id int4 NOT NULL,
mpc_order_id int4 NOT NULL,
ad_client_id int4 NOT NULL,
ad_org_id int4 NOT NULL,
isactive char(1) NOT NULL DEFAULT 'Y'::bpchar,
created timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone,
createdby int4 NOT NULL,
updated timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone,
updatedby int4 NOT NULL,
name varchar(60) NOT NULL,
description varchar(255),
help varchar(2000),
istranslated char(1) NOT NULL DEFAULT 'N'::bpchar,
CONSTRAINT mpc_order_node_trl_key PRIMARY KEY (ad_language, mpc_order_node_id),
CONSTRAINT ad_language_ordernodetrl FOREIGN KEY (ad_language) REFERENCES compiere.ad_language (ad_language) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT mpc_ordernodetrl FOREIGN KEY (mpc_order_node_id, mpc_order_id) REFERENCES compiere.mpc_order_node (mpc_order_node_id, mpc_order_id) ON UPDATE NO ACTION ON DELETE CASCADE
)
WITH OIDS;
CREATE TABLE compiere.mpc_order_workflow_trl
(
mpc_order_workflow_id int4 NOT NULL,
mpc_order_id int4 NOT NULL,
ad_language varchar(6) NOT NULL,
ad_client_id int4 NOT NULL,
ad_org_id int4 NOT NULL,
isactive char(1) NOT NULL DEFAULT 'Y'::bpchar,
created timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone,
createdby int4 NOT NULL,
updated timestamp NOT NULL DEFAULT ('now'::text)::timestamp(6) with time zone,
updatedby int4 NOT NULL,
name varchar(60) NOT NULL,
description varchar(255),
help varchar(2000),
istranslated char(1) NOT NULL DEFAULT 'N'::bpchar,
CONSTRAINT mpc_order_workflow_trl_key PRIMARY KEY (ad_language, mpc_order_workflow_id),
CONSTRAINT ad_language_workflowtrl FOREIGN KEY (ad_language) REFERENCES compiere.ad_language (ad_language) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT mpc_order_workflowtrl FOREIGN KEY (mpc_order_workflow_id, mpc_order_id) REFERENCES compiere.mpc_order_workflow (mpc_order_workflow_id, mpc_order_id) ON UPDATE NO ACTION ON DELETE CASCADE
)
WITH OIDS;
CREATE OR REPLACE VIEW RV_MPC_Order AS
SELECT o.AD_Client_ID, o.AD_Org_ID,o.IsActive,o.Created, o.CreatedBy, o.Updated, o.UpdatedBy,
o.MPC_Order_ID, o.DocumentNo,o.DocStatus,o.M_Warehouse_ID,o.M_Product_ID,o.QtyEntered,
o.QtyReject,o.QtyScrap,o.QtyBatchs, o.QtyBatchSize,o.DateOrdered, o.DatePromised,o.DateStart,
o.DateStartSchedule,o.DateFinish,o.DateFinishSchedule,o.DateConfirm,o.DateDelivered,o.Lot,
o.MPC_Product_BOM_ID,o.AD_Workflow_ID, (select p.Weight from M_Product p where p.M_Product_ID=o.M_Product_ID) as Weight
FROM MPC_Order o;
CREATE OR REPLACE VIEW RV_MPC_Order_BOMLine AS
SELECT
obl.AD_Client_ID ,
obl.AD_Org_ID ,
obl.CreatedBy ,
obl.UpdatedBY ,
obl.Updated ,
obl.Created ,
obl.IsActive ,
obl.MPC_Order_BOM_ID,
obl.MPC_Order_BOMLine_ID ,
obl.MPC_Order_ID ,
obl.IsCritical ,
obl.ComponentType,
obl.M_Product_ID ,
obl.C_UOM_ID ,
ROUND(obl.QtyRequiered ,4) AS QtyRequiered ,
ROUND(BOMQtyReserved(obl.M_Product_ID,obl.M_Warehouse_ID,0), 4) AS QtyReserved ,
ROUND(BOMQtyAvailable(obl.M_Product_ID,obl.M_Warehouse_ID,0),4) AS QtyAvailable ,
ROUND(BOMQtyOnHand(obl.M_Product_ID,obl.M_Warehouse_ID,0),4) AS QtyOnHand ,
obl.M_Warehouse_ID ,
ROUND(obl.QtyBom,4) AS QtyBom,
obl.isQtyPercentage ,
ROUND(obl.QtyBatch,4) AS QtyBatch,
CASE WHEN o.QtyBatchs = 0 THEN 1 ELSE ROUND( obl.QtyRequiered / o.QtyBatchs, 4) END AS QtyBatchSize
--DECODE(o.QtyBatchs , 0 , 0 , ROUND( obl.QtyRequiered / o.QtyBatchs, 4) ) AS QtyBatchSize
FROM MPC_Order_BOMLine obl INNER JOIN MPC_Order o ON (o.MPC_Order_ID = obl.MPC_Order_ID);
--DROP VIEW RV_MPC_Order_Storage;
CREATE OR REPLACE VIEW RV_MPC_Order_Storage AS
SELECT
obl.AD_Client_ID ,
obl.AD_Org_ID ,
obl.CreatedBy ,
obl.UpdatedBY ,
obl.Updated ,
obl.Created ,
obl.IsActive ,
obl.MPC_Order_BOM_ID,
obl.MPC_Order_BOMLine_ID ,
obl.MPC_Order_ID ,
obl.IsCritical ,
obl.M_Product_ID ,
(Select p.Name FROM M_Product p Where p.M_Product_ID=o.M_Product_ID) as Name,
obl.C_UOM_ID ,
s.QtyOnhand ,
ROUND(obl.QtyRequiered ,4) AS QtyRequiered ,
CASE WHEN o.QtyBatchs = 0 THEN 1 ELSE ROUND( obl.QtyRequiered / o.QtyBatchs, 4) END AS QtyBatchSize,
--DECODE(o.QtyBatchs , 0 , 0 , ROUND( obl.QtyRequiered / o.QtyBatchs, 4) ) AS QtyBatchSize,
ROUND(BOMQtyReserved(obl.M_Product_ID,obl.M_Warehouse_ID,0), 4) AS QtyReserved ,
ROUND(BOMQtyAvailable(obl.M_Product_ID,obl.M_Warehouse_ID,0),4) AS QtyAvailable ,
obl.M_Warehouse_ID ,
obl.QtyBom ,
obl.isQtyPercentage ,
ROUND(obl.QtyBatch,4) AS QtyBatch ,
l.M_Locator_ID ,
s.m_attributesetinstance_id,
l.x ,
l.y ,
l.z
FROM MPC_Order_BOMLine obl INNER JOIN MPC_Order o ON (o.MPC_Order_ID = obl.MPC_Order_ID) LEFT OUTER JOIN M_Storage s ON ( s.M_Product_ID = obl.M_Product_ID AND s.QtyOnHand <> 0 AND obl.M_Warehouse_ID = (SELECT ld.M_Warehouse_ID FROM M_Locator ld WHERE s.M_Locator_ID=ld.M_Locator_ID)) LEFT OUTER JOIN M_Locator l ON (l.M_Locator_ID = s.M_Locator_ID) ORDER BY obl.M_Product_ID
;
CREATE OR REPLACE VIEW RV_MPC_Order_Transactions AS
SELECT DISTINCT o.AD_Client_ID,o.AD_Org_ID, o.IsActive, o.Created, o.CreatedBy, o.UpdatedBy, o.Updated,o.DocumentNo,ol.M_Product_ID, mt.M_Locator_ID,mt.MovementDate,o.MPC_Order_ID,
o.QtyDelivered, o.QtyScrap ,ol.QtyDelivered AS QtyDeliveredLine , (o.QtyDelivered * ol.QtyBatch)/100 AS QtyIssueShouldbe,
ol.QtyScrap AS QtyScrapLine , (o.QtyScrap * ol.QtyBatch)/100 AS QtyIssueScrapShouldBe , mt.CreatedBy AS CreatedByIssue, mt.UpdatedBy AS UpdatedByIssue,
(SELECT SUM(t.MovementQty) FROM M_Transaction t WHERE t.MPC_Order_BOMLine_ID=ol.MPC_Order_BOMLine_ID) AS QtyToDeliver,
((((o.QtyDelivered + o.QtyScrap) * ol.QtyBatch)/100) + (SELECT SUM(t.MovementQty) FROM M_Transaction t WHERE t.MPC_Order_BOMLine_ID = ol.MPC_Order_BOMLine_ID)) AS DifferenceQty
FROM MPC_Order o INNER JOIN MPC_Order_BOMLine ol ON (ol.MPC_Order_ID=o.MPC_Order_ID) LEFT JOIN M_Transaction mt ON( mt.MPC_Order_BOMLine_ID = ol.MPC_Order_BOMLine_ID)
;
--DROP VIEW RV_MPC_PRODUCT_BOMLINE ;
--DROP VIEW RV_MPC_PRODUCT_BOMLINE ;
CREATE OR REPLACE VIEW RV_MPC_PRODUCT_BOMLINE AS
SELECT
t.SeqNo,
t.LevelNo,
t.Levels,
t.AD_Client_ID ,
t.AD_Org_ID ,
t.CreatedBy ,
t.UpdatedBy ,
t.Updated ,
t.Created ,
t.AD_PInstance_ID,
bl.IsActive ,
bl.MPC_Product_BOM_ID,
bl.MPC_Product_BOMLine_ID ,
bl.Description,
bl.IsCritical ,
bl.ComponentType,
t.M_Product_ID ,
bl.C_UOM_ID ,
bl.IssueMethod,
bl.Line,
bl.M_AttributeSetInstance_ID,
bl.Scrap,
bl.ValidFrom,
bl.ValidTo,
bl.QtyBom,
bl.QtyBatch,
bl.isQtyPercentage
FROM MPC_Product_BOMLine bl RIGHT JOIN T_BOMLine t ON (t.MPC_Product_BOMLine_ID = bl.MPC_Product_BOMLine_ID) ORDER BY SeqNo ;
create view compiere.mpc_order_receipt_issue as
select
obl.mpc_order_bomline_id,
obl.iscritical,
p.value,
obl.m_product_id,
mos.name as productname,
mos.m_attributesetinstance_id,
asi.description as instancename,
mos.c_uom_id,
u.name as uomname,
obl.qtyrequiered,
obl.qtyreserved as qtyreserved_order,
mos.qtyonhand,
mos.qtyreserved as qtyreserved_storage,
mos.qtyavailable,
mos.m_locator_id,
mos.m_warehouse_id,
w.name as warehousename,
mos.qtybom,
mos.isqtypercentage,
mos.qtybatch,
obl.ComponentType,
mos.QtyRequiered - obl.QtyDelivered AS QtyOpen,
obl.mpc_order_id
from compiere.rv_mpc_order_storage mos
inner join compiere.mpc_order_bomline obl on mos.mpc_order_bomline_id = obl.mpc_order_bomline_id
inner join compiere.m_attributesetinstance asi on mos.m_attributesetinstance_id = asi.m_attributesetinstance_id
inner join compiere.c_uom u on mos.c_uom_id = u.c_uom_id
inner join compiere.m_product p on mos.m_product_id = p.m_product_id
inner join compiere.m_warehouse w on mos.m_warehouse_id = w.m_warehouse_id;

View File

@ -0,0 +1,85 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
/**
* SQLJ Account related Functions
*
* @author Jorg Janke
* @version $Id: Account.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class Account
{
/**
* Get Balance based on Account Sign and Type.
* Acct_Balance - acctBalance
* If an account is specified and found
* - If the account sign is Natural it sets it based on Account Type
* @param p_Account_ID account
* @param p_AmtDr debit
* @param p_AmtCr credit
* @return cr or dr balance
* @throws SQLException
*/
public static BigDecimal balance (int p_Account_ID, BigDecimal p_AmtDr, BigDecimal p_AmtCr)
throws SQLException
{
BigDecimal AmtDr = p_AmtDr;
if (AmtDr == null)
AmtDr = Adempiere.ZERO;
BigDecimal AmtCr = p_AmtCr;
if (AmtCr == null)
AmtCr = Adempiere.ZERO;
BigDecimal balance = AmtDr.subtract(AmtCr);
//
if (p_Account_ID != 0)
{
String sql = "SELECT AccountType, AccountSign "
+ "FROM C_ElementValue "
+ "WHERE C_ElementValue_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_Account_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
String AccountType = rs.getString(1);
String AccountSign = rs.getString(2);
// Natural Account Sign -> D/C
if (AccountSign.equals("N"))
{
if (AccountType.equals("A") || AccountType.equals("E"))
AccountSign = "D";
else
AccountSign = "C";
}
// Debit Balance
if (AccountSign.equals("C"))
balance = AmtCr.subtract(AmtDr);
}
rs.close();
pstmt.close();
}
//
return balance;
} // balance
} // Account

View File

@ -0,0 +1,524 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.io.*;
import java.math.*;
import java.sql.*;
import java.util.*;
/**
* SQLJ Adempiere Control and Utility Class
*
* @author Jorg Janke
* @version $Id: Adempiere.java,v 1.4 2006/10/02 19:49:59 jjanke Exp $
*/
public class Adempiere implements Serializable
{
/**
* Get Version
* @return version
*/
public static String getVersion()
{
return "Adempiere SQLJ 1.0";
} // version
/**
* Get Environment Info
* @return properties
*/
public static String getProperties()
{
StringBuffer sb = new StringBuffer();
Enumeration en = System.getProperties().keys();
while (en.hasMoreElements())
{
if (sb.length() != 0)
sb.append(" - ");
String key = (String)en.nextElement();
String value = System.getProperty(key);
sb.append(key).append("=").append(value);
}
return sb.toString();
} // environment
/**
* Get Environment Info
* @param key key
* @return property info
* @throws SQLException
*/
public static String getProperty (String key) throws SQLException
{
if (key == null || key.length() == 0)
return "null";
return System.getProperty(key, "NotFound");
} // environment
/** Oracle Server */
public static final String TYPE_ORACLE = "oracle";
/** Derby Server */
public static final String TYPE_DERBY = "derby";
/** DB2 Server */
public static final String TYPE_DB2 = "db2";
//begin e-evolution vpj-cd 02/02/2005 PostgreSQL
/** PostgreSQL **/
public static final String TYPE_POSTGRESQL = "PostgreSQL";
public static final String TYPE_EDB = "EDB";
//end e-evolution vpj-cd 02/02/2005 PostgreSQL
/** Server Type */
public static String s_type = null;
/**
* Get Server Type
* @return server type
*/
public static String getServerType()
{
if (s_type == null)
{
String vendor = System.getProperty("java.vendor");
if (vendor.startsWith("Oracle"))
s_type = TYPE_ORACLE;
else if (vendor.startsWith("Derby"))
s_type = TYPE_DERBY;
else
s_type = "??";
}
return s_type;
} // getServerType
/**
* Is this Oracle ?
* @return true if Oracle
*/
static boolean isOracle()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_ORACLE.equals(s_type);
return false;
} // isOracle
/**
* Is this Derby ?
* @return true if Derby
*/
static boolean isDerby()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_DERBY.equals(s_type);
return false;
} // isDerby
//begin vpj-cd e-evolution 02/22/2005 PostgreSQL
/**
* Is this PostgreSQL ?
* @return true if Sybase
*/
static boolean isPostgreSQL()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_POSTGRESQL.equals(s_type);
return false;
}
// isEDB
static boolean isEDB()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_EDB.equals(s_type);
return false;
} // isEDB
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
/**
* Get Connection URL
* @return connection URL
*/
static String getConnectionURL()
{
if (s_url != null)
return s_url;
if (isOracle())
s_url = "jdbc:default:connection:";
else if (isDerby())
s_url = "jdbc:default:connection";
//begin vpj-cd e-evolution 02/22/2005 PostgreSQL
else if (isPostgreSQL())
return "jdbc:default:connection";
else if (isEDB())
return "jdbc:default:connection";
return "jdbc:default:connection";
//
//return s_url;
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
} // getConnectionURL
/** Connection URL */
protected static String s_url = null;
/** Connection User */
protected static String s_uid = null;
/** Connection Password */
protected static String s_pwd = null;
/**
* Get Server side Connection
* @return connection
* @throws SQLException
*/
private static Connection getConnection() throws SQLException
{
if (s_uid != null && s_pwd != null)
return DriverManager.getConnection(getConnectionURL(), s_uid, s_pwd);
return DriverManager.getConnection(getConnectionURL());
} // getConnection
/**
* Prepare Statement (Forward, ReadOnly)
* @param sql sql
* @return prepared statement
* @throws SQLException
*/
static PreparedStatement prepareStatement (String sql) throws SQLException
{
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
} // prepareStatement
/**
* Prepare Statement
* @param sql sql
* @param resultSetType result set type
* @param resultSetCurrency result type currency
* @return prepared statement
* @throws SQLException
*/
static PreparedStatement prepareStatement (String sql, int resultSetType, int resultSetCurrency)
throws SQLException
{
if (s_conn == null)
s_conn = getConnection();
try
{
return s_conn.prepareStatement(sql, resultSetType, resultSetCurrency);
}
catch (Exception e) // connection not good anymore
{
}
// get new Connection
s_conn = getConnection();
return s_conn.prepareStatement(sql);
} //
/**
* Get SQL int Value with param
* @param sql sql command
* @param param1 parameter
* @return value or -1 if not found
* @throws SQLException
*/
static int getSQLValue (String sql, int param1) throws SQLException
{
int retValue = -1;
PreparedStatement pstmt = prepareStatement(sql);
pstmt.setInt(1, param1);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getInt(1);
rs.close();
pstmt.close();
return retValue;
} // getSQLValue
/** Permanently open Connection */
private static Connection s_conn = null;
/** Zero 0 */
public static final BigDecimal ZERO = new BigDecimal((double)0.0);
/** One 1 */
public static final BigDecimal ONE = new BigDecimal((double)1.0);
/** Hundred 100 */
public static final BigDecimal HUNDRED = new BigDecimal((double)100.0);
/**
* Truncate Date
* @param p_dateTime date
* @return day
*/
public static Timestamp trunc (Timestamp p_dateTime)
{
Timestamp time = p_dateTime;
if (time == null)
time = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(time);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // trunc
/**
* Truncate Date
* @param p_dateTime date
* @param XX date part - Supported: DD(default),DY,MM,Q
* @return day (first)
*/
public static Timestamp firstOf (Timestamp p_dateTime, String XX)
{
Timestamp time = p_dateTime;
if (time == null)
time = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(time);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
if ("MM".equals(XX)) // Month
cal.set(Calendar.DAY_OF_MONTH, 1);
else if ("DY".equals(XX)) // Week
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
else if ("Q".equals(XX)) // Quarter
{
cal.set(Calendar.DAY_OF_MONTH, 1);
int mm = cal.get(Calendar.MONTH); // January = 0
if (mm < Calendar.APRIL)
cal.set(Calendar.MONTH, Calendar.JANUARY);
else if (mm < Calendar.JULY)
cal.set(Calendar.MONTH, Calendar.APRIL);
else if (mm < Calendar.OCTOBER)
cal.set(Calendar.MONTH, Calendar.JULY);
else
cal.set(Calendar.MONTH, Calendar.OCTOBER);
}
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // trunc
/**
* Calculate the number of days between start and end.
* @param start start date
* @param end end date
* @return number of days (0 = same)
*/
static public int getDaysBetween (Timestamp start, Timestamp end)
{
boolean negative = false;
if (end.before(start))
{
negative = true;
Timestamp temp = start;
start = end;
end = temp;
}
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(start);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
GregorianCalendar calEnd = new GregorianCalendar();
calEnd.setTime(end);
calEnd.set(Calendar.HOUR_OF_DAY, 0);
calEnd.set(Calendar.MINUTE, 0);
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MILLISECOND, 0);
// System.out.println("Start=" + start + ", End=" + end + ", dayStart=" + cal.get(Calendar.DAY_OF_YEAR) + ", dayEnd=" + calEnd.get(Calendar.DAY_OF_YEAR));
// in same year
if (cal.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))
{
if (negative)
return (calEnd.get(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR)) * -1;
return calEnd.get(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR);
}
// not very efficient, but correct
int counter = 0;
while (calEnd.after(cal))
{
cal.add (Calendar.DAY_OF_YEAR, 1);
counter++;
}
if (negative)
return counter * -1;
return counter;
} // getDaysBetween
/**
* Return Day + offset (truncates)
* @param day Day
* @param offset day offset
* @return Day + offset at 00:00
*/
static public Timestamp addDays (Timestamp day, int offset)
{
if (day == null)
day = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
if (offset != 0)
cal.add(Calendar.DAY_OF_YEAR, offset); // may have a problem with negative (before 1/1)
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // addDays
/**
* Next Business Day.
* (Only Sa/Su -> Mo)
* @param day day
* @return next business dat if day is "off"
*/
static public Timestamp nextBusinessDay (Timestamp day)
{
if (day == null)
day = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
int dow = cal.get(Calendar.DAY_OF_WEEK);
if (dow == Calendar.SATURDAY)
cal.add(Calendar.DAY_OF_YEAR, 2);
else if (dow == Calendar.SUNDAY)
cal.add(Calendar.DAY_OF_YEAR, 1);
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // nextBusinessDay
/**
* Character At Position
* @param source source
* @param posIndex position 1 = first
* @return substring or null
*/
public static String charAt (String source, int posIndex)
{
if (source == null || source.length() == 0 || posIndex < 0 || posIndex >= source.length())
return null;
try
{
return (source.substring(posIndex+1, posIndex+2));
}
catch (Exception e)
{}
return null;
} // charAt
/**
* Mext ID
* @param AD_Sequence_ID sequence
* @param System system
* @return ID or -1
* @throws SQLException
*/
public static int nextID (int AD_Sequence_ID, String System)
throws SQLException
{
boolean isSystem = System != null && "Y".equals(System);
int retValue = -1;
StringBuffer sql = new StringBuffer ("SELECT CurrentNext");
if (isSystem)
sql.append("Sys");
sql.append(",IncrementNo FROM AD_Sequence WHERE AD_Sequence_ID=?");
PreparedStatement pstmt = prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
retValue = rs.getInt(1);
int incrementNo = rs.getInt(2);
rs.updateInt(2, retValue + incrementNo);
pstmt.getConnection().commit();
}
rs.close();
pstmt.close();
//
return retValue;
} // nextID
/**
* get current Date (Timestamp)
* @return Timestamp
*
*/
//jz not found anywhere, add it
public static Timestamp getDate()
{
return new Timestamp(new java.util.Date().getTime());
} // getDate
/**
* get chars from a number
* @param n int
* @return String
*
*/
/*jz not found anywhere, add it
public static String getChars(int n)
{
return Integer.toString(n);
} // getDate
/**
* get chars from a number
* @param d double
* @return String
*
*/
//jz not found anywhere, add it
public static String getChars(BigDecimal d)
{
return d.toString();
} // getDate
} // Adempiere

View File

@ -0,0 +1,56 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.sql.*;
/**
* SQLJ Business Partner related Functions
*
* @author Jorg Janke
* @version $Id: BPartner.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class BPartner
{
/**
* Return first Remit Location of BPartner.
* C_BPartner_RemitLocation - bpartnerRemitLocation
* @param p_C_BPartner_ID business partner
* @return remit to location
* @throws SQLException
*/
public static int remitLocation (int p_C_BPartner_ID)
throws SQLException
{
int C_Location_ID = 0;
String sql = "SELECT IsRemitTo, C_Location_ID "
+ "FROM C_BPartner_Location "
+ "WHERE C_BPartner_ID=? "
+ "ORDER BY IsRemitTo DESC";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_BPartner_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
C_Location_ID = rs.getInt(2);
rs.close();
pstmt.close();
//
return C_Location_ID;
} // remitLocation
} // BPartner

View File

@ -0,0 +1,524 @@
/******************************************************************************
* Product: Compiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.io.*;
import java.math.*;
import java.sql.*;
import java.util.*;
/**
* SQLJ Compiere Control and Utility Class
*
* @author Jorg Janke
* @version $Id: Compiere.java,v 1.4 2006/10/02 19:49:59 jjanke Exp $
*/
public class Compiere implements Serializable
{
/**
* Get Version
* @return version
*/
public static String getVersion()
{
return "Compiere SQLJ 1.0";
} // version
/**
* Get Environment Info
* @return properties
*/
public static String getProperties()
{
StringBuffer sb = new StringBuffer();
Enumeration en = System.getProperties().keys();
while (en.hasMoreElements())
{
if (sb.length() != 0)
sb.append(" - ");
String key = (String)en.nextElement();
String value = System.getProperty(key);
sb.append(key).append("=").append(value);
}
return sb.toString();
} // environment
/**
* Get Environment Info
* @param key key
* @return property info
* @throws SQLException
*/
public static String getProperty (String key) throws SQLException
{
if (key == null || key.length() == 0)
return "null";
return System.getProperty(key, "NotFound");
} // environment
/** Oracle Server */
public static final String TYPE_ORACLE = "oracle";
/** Derby Server */
public static final String TYPE_DERBY = "derby";
/** DB2 Server */
public static final String TYPE_DB2 = "db2";
//begin e-evolution vpj-cd 02/02/2005 PostgreSQL
/** PostgreSQL **/
public static final String TYPE_POSTGRESQL = "PostgreSQL";
public static final String TYPE_EDB = "EDB";
//end e-evolution vpj-cd 02/02/2005 PostgreSQL
/** Server Type */
public static String s_type = null;
/**
* Get Server Type
* @return server type
*/
public static String getServerType()
{
if (s_type == null)
{
String vendor = System.getProperty("java.vendor");
if (vendor.startsWith("Oracle"))
s_type = TYPE_ORACLE;
else if (vendor.startsWith("Derby"))
s_type = TYPE_DERBY;
else
s_type = "??";
}
return s_type;
} // getServerType
/**
* Is this Oracle ?
* @return true if Oracle
*/
static boolean isOracle()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_ORACLE.equals(s_type);
return false;
} // isOracle
/**
* Is this Derby ?
* @return true if Derby
*/
static boolean isDerby()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_DERBY.equals(s_type);
return false;
} // isDerby
//begin vpj-cd e-evolution 02/22/2005 PostgreSQL
/**
* Is this PostgreSQL ?
* @return true if Sybase
*/
static boolean isPostgreSQL()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_POSTGRESQL.equals(s_type);
return false;
}
// isEDB
static boolean isEDB()
{
if (s_type == null)
getServerType();
if (s_type != null)
return TYPE_EDB.equals(s_type);
return false;
} // isEDB
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
/**
* Get Connection URL
* @return connection URL
*/
static String getConnectionURL()
{
if (s_url != null)
return s_url;
if (isOracle())
s_url = "jdbc:default:connection:";
else if (isDerby())
s_url = "jdbc:default:connection";
//begin vpj-cd e-evolution 02/22/2005 PostgreSQL
else if (isPostgreSQL())
return "jdbc:default:connection";
else if (isEDB())
return "jdbc:default:connection";
return "jdbc:default:connection";
//
//return s_url;
//end vpj-cd e-evolution 02/22/2005 PostgreSQL
} // getConnectionURL
/** Connection URL */
protected static String s_url = null;
/** Connection User */
protected static String s_uid = null;
/** Connection Password */
protected static String s_pwd = null;
/**
* Get Server side Connection
* @return connection
* @throws SQLException
*/
private static Connection getConnection() throws SQLException
{
if (s_uid != null && s_pwd != null)
return DriverManager.getConnection(getConnectionURL(), s_uid, s_pwd);
return DriverManager.getConnection(getConnectionURL());
} // getConnection
/**
* Prepare Statement (Forward, ReadOnly)
* @param sql sql
* @return prepared statement
* @throws SQLException
*/
static PreparedStatement prepareStatement (String sql) throws SQLException
{
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
} // prepareStatement
/**
* Prepare Statement
* @param sql sql
* @param resultSetType result set type
* @param resultSetCurrency result type currency
* @return prepared statement
* @throws SQLException
*/
static PreparedStatement prepareStatement (String sql, int resultSetType, int resultSetCurrency)
throws SQLException
{
if (s_conn == null)
s_conn = getConnection();
try
{
return s_conn.prepareStatement(sql, resultSetType, resultSetCurrency);
}
catch (Exception e) // connection not good anymore
{
}
// get new Connection
s_conn = getConnection();
return s_conn.prepareStatement(sql);
} //
/**
* Get SQL int Value with param
* @param sql sql command
* @param param1 parameter
* @return value or -1 if not found
* @throws SQLException
*/
static int getSQLValue (String sql, int param1) throws SQLException
{
int retValue = -1;
PreparedStatement pstmt = prepareStatement(sql);
pstmt.setInt(1, param1);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
retValue = rs.getInt(1);
rs.close();
pstmt.close();
return retValue;
} // getSQLValue
/** Permanently open Connection */
private static Connection s_conn = null;
/** Zero 0 */
public static final BigDecimal ZERO = new BigDecimal((double)0.0);
/** One 1 */
public static final BigDecimal ONE = new BigDecimal((double)1.0);
/** Hundred 100 */
public static final BigDecimal HUNDRED = new BigDecimal((double)100.0);
/**
* Truncate Date
* @param p_dateTime date
* @return day
*/
public static Timestamp trunc (Timestamp p_dateTime)
{
Timestamp time = p_dateTime;
if (time == null)
time = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(time);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // trunc
/**
* Truncate Date
* @param p_dateTime date
* @param XX date part - Supported: DD(default),DY,MM,Q
* @return day (first)
*/
public static Timestamp firstOf (Timestamp p_dateTime, String XX)
{
Timestamp time = p_dateTime;
if (time == null)
time = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(time);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
if ("MM".equals(XX)) // Month
cal.set(Calendar.DAY_OF_MONTH, 1);
else if ("DY".equals(XX)) // Week
cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
else if ("Q".equals(XX)) // Quarter
{
cal.set(Calendar.DAY_OF_MONTH, 1);
int mm = cal.get(Calendar.MONTH); // January = 0
if (mm < Calendar.APRIL)
cal.set(Calendar.MONTH, Calendar.JANUARY);
else if (mm < Calendar.JULY)
cal.set(Calendar.MONTH, Calendar.APRIL);
else if (mm < Calendar.OCTOBER)
cal.set(Calendar.MONTH, Calendar.JULY);
else
cal.set(Calendar.MONTH, Calendar.OCTOBER);
}
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // trunc
/**
* Calculate the number of days between start and end.
* @param start start date
* @param end end date
* @return number of days (0 = same)
*/
static public int getDaysBetween (Timestamp start, Timestamp end)
{
boolean negative = false;
if (end.before(start))
{
negative = true;
Timestamp temp = start;
start = end;
end = temp;
}
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(start);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
GregorianCalendar calEnd = new GregorianCalendar();
calEnd.setTime(end);
calEnd.set(Calendar.HOUR_OF_DAY, 0);
calEnd.set(Calendar.MINUTE, 0);
calEnd.set(Calendar.SECOND, 0);
calEnd.set(Calendar.MILLISECOND, 0);
// System.out.println("Start=" + start + ", End=" + end + ", dayStart=" + cal.get(Calendar.DAY_OF_YEAR) + ", dayEnd=" + calEnd.get(Calendar.DAY_OF_YEAR));
// in same year
if (cal.get(Calendar.YEAR) == calEnd.get(Calendar.YEAR))
{
if (negative)
return (calEnd.get(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR)) * -1;
return calEnd.get(Calendar.DAY_OF_YEAR) - cal.get(Calendar.DAY_OF_YEAR);
}
// not very efficient, but correct
int counter = 0;
while (calEnd.after(cal))
{
cal.add (Calendar.DAY_OF_YEAR, 1);
counter++;
}
if (negative)
return counter * -1;
return counter;
} // getDaysBetween
/**
* Return Day + offset (truncates)
* @param day Day
* @param offset day offset
* @return Day + offset at 00:00
*/
static public Timestamp addDays (Timestamp day, int offset)
{
if (day == null)
day = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
if (offset != 0)
cal.add(Calendar.DAY_OF_YEAR, offset); // may have a problem with negative (before 1/1)
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // addDays
/**
* Next Business Day.
* (Only Sa/Su -> Mo)
* @param day day
* @return next business dat if day is "off"
*/
static public Timestamp nextBusinessDay (Timestamp day)
{
if (day == null)
day = new Timestamp(System.currentTimeMillis());
//
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(day);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
//
int dow = cal.get(Calendar.DAY_OF_WEEK);
if (dow == Calendar.SATURDAY)
cal.add(Calendar.DAY_OF_YEAR, 2);
else if (dow == Calendar.SUNDAY)
cal.add(Calendar.DAY_OF_YEAR, 1);
//
java.util.Date temp = cal.getTime();
return new Timestamp (temp.getTime());
} // nextBusinessDay
/**
* Character At Position
* @param source source
* @param posIndex position 1 = first
* @return substring or null
*/
public static String charAt (String source, int posIndex)
{
if (source == null || source.length() == 0 || posIndex < 0 || posIndex >= source.length())
return null;
try
{
return (source.substring(posIndex+1, posIndex+2));
}
catch (Exception e)
{}
return null;
} // charAt
/**
* Mext ID
* @param AD_Sequence_ID sequence
* @param System system
* @return ID or -1
* @throws SQLException
*/
public static int nextID (int AD_Sequence_ID, String System)
throws SQLException
{
boolean isSystem = System != null && "Y".equals(System);
int retValue = -1;
StringBuffer sql = new StringBuffer ("SELECT CurrentNext");
if (isSystem)
sql.append("Sys");
sql.append(",IncrementNo FROM AD_Sequence WHERE AD_Sequence_ID=?");
PreparedStatement pstmt = prepareStatement(sql.toString(),
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
retValue = rs.getInt(1);
int incrementNo = rs.getInt(2);
rs.updateInt(2, retValue + incrementNo);
pstmt.getConnection().commit();
}
rs.close();
pstmt.close();
//
return retValue;
} // nextID
/**
* get current Date (Timestamp)
* @return Timestamp
*
*/
//jz not found anywhere, add it
public static Timestamp getDate()
{
return new Timestamp(new java.util.Date().getTime());
} // getDate
/**
* get chars from a number
* @param n int
* @return String
*
*/
/*jz not found anywhere, add it
public static String getChars(int n)
{
return Integer.toString(n);
} // getDate
/**
* get chars from a number
* @param d double
* @return String
*
*/
//jz not found anywhere, add it
public static String getChars(BigDecimal d)
{
return d.toString();
} // getDate
} // Compiere

View File

@ -0,0 +1,296 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
/**
* SQLJ Currency related Functions
*
* @author Jorg Janke
* @version $Id: Currency.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class Currency
{
/**
* Convert Amount to base Currency.
* (default conversion type)
* Previously: C_Base_Convert - Now: currencyBase
* @param p_Amount amount
* @param p_C_CurrencyFrom_ID from currency
* @param p_ConversionDate conversion date
* @param p_AD_Client_ID client
* @param p_AD_Org_ID org
* @return rate or null
* @throws SQLException
*/
public static BigDecimal base (BigDecimal p_Amount,
int p_C_CurrencyFrom_ID, Timestamp p_ConversionDate,
int p_AD_Client_ID, int p_AD_Org_ID)
throws SQLException
{
// Return NULL
if (p_Amount == null || p_C_CurrencyFrom_ID == 0)
return null;
// Return Amount
if (p_Amount.signum() == 0)
return p_Amount;
// Base Currency
String sql = "SELECT ac.C_Currency_ID "
+ "FROM AD_ClientInfo ci"
+ " INNER JOIN C_AcctSchema ac ON (ci.C_AcctSchema1_ID=ac.C_AcctSchema_ID) "
+ "WHERE ci.AD_Client_ID=?";
int C_CurrencyTo_ID = Adempiere.getSQLValue(sql, p_AD_Client_ID);
// Return Amount
if (p_C_CurrencyFrom_ID == C_CurrencyTo_ID)
return p_Amount;
//
return convert(p_Amount, p_C_CurrencyFrom_ID, C_CurrencyTo_ID,
p_ConversionDate, 0, p_AD_Client_ID, p_AD_Org_ID);
} // base
/**
* Convert Amount to Currency.
* Previously: currencyConvert - Now: currencyConvert
* @param p_Amount amount
* @param p_C_CurrencyFrom_ID from currency
* @param p_C_CurrencyTo_ID to currency
* @param p_ConversionDate conversion date
* @param p_C_ConversionType_ID conversion type
* @param p_AD_Client_ID client
* @param p_AD_Org_ID org
* @return rate or null
* @throws SQLException
*/
public static BigDecimal convert (BigDecimal p_Amount,
int p_C_CurrencyFrom_ID, int p_C_CurrencyTo_ID,
Timestamp p_ConversionDate, int p_C_ConversionType_ID,
int p_AD_Client_ID, int p_AD_Org_ID)
throws SQLException
{
// Return NULL
if (p_Amount == null || p_C_CurrencyFrom_ID == 0 || p_C_CurrencyTo_ID == 0)
return null;
// Return Amount
if (p_Amount.signum() == 0 || p_C_CurrencyFrom_ID == p_C_CurrencyTo_ID)
return p_Amount;
// Get Rate
BigDecimal rate = rate (p_C_CurrencyFrom_ID, p_C_CurrencyTo_ID,
p_ConversionDate, p_C_ConversionType_ID, p_AD_Client_ID, p_AD_Org_ID);
if (rate == null)
return null;
// Round
return round(p_Amount.multiply(rate), p_C_CurrencyTo_ID, null);
} // convert
/**
* Get Conversion Rate.
* Previously: C_Currency_Rate - Now: currencyRate
* @param p_C_CurrencyFrom_ID from currency
* @param p_C_CurrencyTo_ID to currency
* @param p_ConversionDate conversion date
* @param p_C_ConversionType_ID conversion type
* @param p_AD_Client_ID client
* @param p_AD_Org_ID org
* @return rate or null
* @throws SQLException
*/
public static BigDecimal rate (int p_C_CurrencyFrom_ID, int p_C_CurrencyTo_ID,
Timestamp p_ConversionDate, int p_C_ConversionType_ID,
int p_AD_Client_ID, int p_AD_Org_ID)
throws SQLException
{
// No Conversion
if (p_C_CurrencyFrom_ID == p_C_CurrencyTo_ID)
return Adempiere.ONE;
// Get Defaults
Timestamp ConversionDate = p_ConversionDate;
if (ConversionDate == null)
ConversionDate = new Timestamp(System.currentTimeMillis());
ConversionDate = Adempiere.trunc(ConversionDate);
//
int C_ConversionType_ID = p_C_ConversionType_ID;
if (C_ConversionType_ID == 0)
{
String sql = "SELECT C_ConversionType_ID "
+ "FROM C_ConversionType "
+ "WHERE IsDefault='Y'"
+ " AND AD_Client_ID IN (0,?) "
+ "ORDER BY AD_Client_ID DESC";
C_ConversionType_ID = Adempiere.getSQLValue(sql, p_AD_Client_ID);
}
/** Get Euro Currency Info
String sql = "SELECT IsEuro, IsEMUMember, EMUEntryDate, EMURate "
+ "FROM C_Currency "
+ "WHERE C_Currency_ID=?";
-- 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
-- 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
BigDecimal rate = null;
String sql = "SELECT MultiplyRate "
+ "FROM C_Conversion_Rate "
+ "WHERE C_Currency_ID=? AND C_Currency_ID_To=?" // from/to
+ " AND C_ConversionType_ID=?"
+ " AND TRUNC(ValidFrom) <= ?"
+ " AND TRUNC(ValidTo) >= ?"
+ " AND AD_Client_ID IN (0,?) AND AD_Org_ID IN (0,?) "
+ "ORDER BY AD_Client_ID DESC, AD_Org_ID DESC, ValidFrom DESC";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_CurrencyFrom_ID);
pstmt.setInt(2, p_C_CurrencyTo_ID);
pstmt.setInt(3, C_ConversionType_ID);
pstmt.setTimestamp(4, ConversionDate);
pstmt.setTimestamp(5, ConversionDate);
pstmt.setInt(6, p_AD_Client_ID);
pstmt.setInt(7, p_AD_Org_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
rate = rs.getBigDecimal(1);
}
rs.close();
pstmt.close();
// Not found
if (rate == null)
return null;
/** 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 rate;
} // rate
/**
* Round amount to Currency precision.
SELECT ISO_CODE, currencyRound(111.111111, C_Currency_ID, 'N') "Std", currencyRound(111.111111, C_Currency_ID, 'Y') "Cost" FROM C_Currency WHERE C_Currency_ID IN (100,113)
* @param p_Amount amount
* @param p_C_Currency_ID currency
* @param p_Costing Y if costing precision
* @return rounded amount
* @throws SQLException
*/
public static BigDecimal round (BigDecimal p_Amount, int p_C_Currency_ID,
String p_Costing)
throws SQLException
{
if (p_Amount == null)
return null;
if (p_Amount.signum() == 0 || p_C_Currency_ID == 0)
return p_Amount;
//
boolean costing = p_Costing != null && "Y".equals(p_Costing);
//
BigDecimal result = p_Amount;
String sql = "SELECT StdPrecision, CostingPrecision "
+ "FROM C_Currency "
+ "WHERE C_Currency_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Currency_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
int index = costing ? 2 : 1;
int prec = rs.getInt(index);
if (result.scale() > prec)
result = result.setScale(prec, BigDecimal.ROUND_HALF_UP);
}
rs.close();
pstmt.close();
//
return result;
} // round
/**
* Test
* @param args ignored
SELECT p.DateTrx,p.DocumentNo,p.C_Payment_ID,c.ISO_Code,p.PayAmt,
currencyConvert(p.PayAmt,p.C_Currency_ID,100,p.DateTrx,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID) xPayAmt,
paymentAvailable(C_Payment_ID) Available,
currencyConvert(paymentAvailable(C_Payment_ID),p.C_Currency_ID,100,p.DateTrx,p.C_ConversionType_ID,p.AD_Client_ID,p.AD_Org_ID) xAvailable,
p.MultiplierAP
FROM C_Payment_v p
INNER JOIN C_Currency c ON (p.C_Currency_ID=c.C_Currency_ID)
ORDER BY p.DateTrx,p.DocumentNo
*
public static void main (String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Adempiere.s_type = Adempiere.TYPE_ORACLE;
Adempiere.s_url = "jdbc:oracle:thin:@//dev1:1521/dev1.adempiere.org";
Adempiere.s_uid = "adempiere";
Adempiere.s_pwd = "adempiere";
System.out.println(Currency.convert(new BigDecimal(102), 102, 100, null, 0, 11, 0));
}
catch (SQLException e)
{
e.printStackTrace();
}
} // main /* */
} // Currency

View File

@ -0,0 +1,367 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
/**
* SQLJ Invoice related Functions
*
* @author Jorg Janke
* @version $Id: Invoice.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class Invoice
{
/**
* Open Invoice Amount.
* - incoiceOpen
* @param p_C_Invoice_ID invoice
* @param p_C_InvoicePaySchedule_ID payment schedule
* @return open amount
* @throws SQLException
*/
public static BigDecimal open (int p_C_Invoice_ID, int p_C_InvoicePaySchedule_ID)
throws SQLException
{
// Invoice info
int C_Currency_ID = 0;
int C_ConversionType_ID = 0;
BigDecimal GrandTotal = null;
BigDecimal MultiplierAP = null;
BigDecimal MultiplierCM = null;
//
String sql = "SELECT MAX(C_Currency_ID),MAX(C_ConversionType_ID),"
+ " SUM(GrandTotal), MAX(MultiplierAP), MAX(Multiplier) "
+ "FROM C_Invoice_v " // corrected for CM / Split Payment
+ "WHERE C_Invoice_ID=?";
if (p_C_InvoicePaySchedule_ID != 0)
sql += " AND C_InvoicePaySchedule_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Invoice_ID);
if (p_C_InvoicePaySchedule_ID != 0)
pstmt.setInt(2, p_C_InvoicePaySchedule_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
C_Currency_ID = rs.getInt(1);
C_ConversionType_ID = rs.getInt(2);
GrandTotal = rs.getBigDecimal(3);
MultiplierAP = rs.getBigDecimal(4);
MultiplierCM = rs.getBigDecimal(5);
}
rs.close();
pstmt.close();
// No Invoice
if (GrandTotal == null)
return null;
BigDecimal paidAmt = allocatedAmt(p_C_Invoice_ID, C_Currency_ID,
C_ConversionType_ID, MultiplierAP);
BigDecimal TotalOpenAmt = GrandTotal.subtract(paidAmt);
/**
GrandTotal Paid TotalOpen Remaining Due x
100 0 100 =0
1a =50-0 50 x
1b =0-50 =0 50
2a =0-50 =0 50
2b =50-0 50 x
--
100 10 100 =10
1a =50-10 50 x
1b =10-50 =0 50
2a =10-50 =0 50
2b =50-0 50 x
--
100 60 100 =60
1a =50-60 =0 50 x
1b =60-50 50
2a =60-50 =10 50
2b =50-10 50 x
--
**/
// Do we have a Payment Schedule ?
if (p_C_InvoicePaySchedule_ID > 0) // if not valid = lists invoice amount
{
TotalOpenAmt = GrandTotal;
BigDecimal remainingAmt = paidAmt;
sql = "SELECT C_InvoicePaySchedule_ID, DueAmt "
+ "FROM C_InvoicePaySchedule "
+ "WHERE C_Invoice_ID=?"
+ " AND IsValid='Y' "
+ "ORDER BY DueDate";
pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Invoice_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
int C_InvoicePaySchedule_ID = rs.getInt(1);
BigDecimal DueAmt = rs.getBigDecimal(2);
//
if (C_InvoicePaySchedule_ID == p_C_InvoicePaySchedule_ID)
{
if (DueAmt.signum() > 0) // positive
{
if (DueAmt.compareTo(remainingAmt) < 0) // paid more
TotalOpenAmt = Adempiere.ZERO;
else
TotalOpenAmt = DueAmt.multiply(MultiplierCM)
.subtract(remainingAmt);
}
else
{
if (DueAmt.compareTo(remainingAmt) > 0) // paid more
TotalOpenAmt = Adempiere.ZERO;
else
TotalOpenAmt = DueAmt.multiply(MultiplierCM)
.add(remainingAmt);
}
}
else
{
if (DueAmt.signum() > 0) // positive
{
remainingAmt = remainingAmt.subtract(DueAmt);
if (remainingAmt.signum() < 0)
remainingAmt = Adempiere.ZERO;
}
else
{
remainingAmt = remainingAmt.add(DueAmt);
if (remainingAmt.signum() < 0)
remainingAmt = Adempiere.ZERO;
}
}
}
rs.close();
pstmt.close();
} // Invoice Schedule
// Rounding
TotalOpenAmt = Currency.round(TotalOpenAmt, C_Currency_ID, null);
// Ignore Penny if there is a payment
if (paidAmt.signum() != 0)
{
double open = TotalOpenAmt.doubleValue();
if (open >= -0.01 && open <= 0.01)
TotalOpenAmt = Adempiere.ZERO;
}
//
return TotalOpenAmt;
} // open
/**
* Get Invoice paid(allocated) amount.
* - invoicePaid
* @param p_C_Invoice_ID invoice
* @param p_C_Currency_ID currency
* @param p_MultiplierAP multiplier
* @return paid amount
* @throws SQLException
*/
public static BigDecimal paid (int p_C_Invoice_ID, int p_C_Currency_ID, int p_MultiplierAP)
throws SQLException
{
// Invalid Parameters
if (p_C_Invoice_ID == 0 || p_C_Currency_ID == 0)
return null;
// Parameters
BigDecimal MultiplierAP = new BigDecimal((double)p_MultiplierAP);
if (p_MultiplierAP == 0)
MultiplierAP = Adempiere.ONE;
int C_ConversionType_ID = 0;
// Calculate Allocated Amount
BigDecimal paymentAmt = allocatedAmt(p_C_Invoice_ID,
p_C_Currency_ID, C_ConversionType_ID, MultiplierAP);
return Currency.round(paymentAmt, p_C_Currency_ID, null);
} // paid
/**
* Get Allocated Amt (not directly used)
* @param C_Invoice_ID invoice
* @param C_Currency_ID currency
* @param C_ConversionType_ID conversion type
* @param MultiplierAP multiplier
* @return allocated amount
* @throws SQLException
*/
public static BigDecimal allocatedAmt(int C_Invoice_ID,
int C_Currency_ID, int C_ConversionType_ID, BigDecimal MultiplierAP)
throws SQLException
{
// Calculate Allocated Amount
BigDecimal paidAmt = Adempiere.ZERO;
String sql = "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=?"
+ " AND a.IsActive='Y'";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, C_Invoice_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int AD_Client_ID = rs.getInt(1);
int AD_Org_ID = rs.getInt(2);
BigDecimal Amount = rs.getBigDecimal(3);
BigDecimal DiscountAmt = rs.getBigDecimal(4);
BigDecimal WriteOffAmt = rs.getBigDecimal(5);
int C_CurrencyFrom_ID = rs.getInt(6);
Timestamp DateTrx = rs.getTimestamp(7);
//
BigDecimal invAmt = Amount.add(DiscountAmt).add(WriteOffAmt);
BigDecimal allocation = Currency.convert(invAmt.multiply(MultiplierAP),
C_CurrencyFrom_ID, C_Currency_ID, DateTrx, C_ConversionType_ID,
AD_Client_ID, AD_Org_ID);
if (allocation != null)
paidAmt = paidAmt.add(allocation);
}
rs.close();
pstmt.close();
//
return paidAmt;
} // getAllocatedAmt
/**
* Get Invoice discount.
* C_Invoice_Discount - invoiceDiscount
* @param p_C_Invoice_ID invoice
* @param p_PayDate pay date
* @param p_C_InvoicePaySchedule_ID pay schedule
* @return discount amount or null
* @throws SQLException
*/
public static BigDecimal discount (int p_C_Invoice_ID,
Timestamp p_PayDate, int p_C_InvoicePaySchedule_ID)
throws SQLException
{
// Parameters
if (p_C_Invoice_ID == 0)
return null;
Timestamp PayDate = p_PayDate;
if (PayDate == null)
PayDate = new Timestamp (System.currentTimeMillis());
PayDate = Adempiere.trunc(PayDate);
// Invoice Info
boolean IsDiscountLineAmt = false;
BigDecimal GrandTotal = null;
BigDecimal TotalLines = null;
int C_PaymentTerm_ID = 0;
Timestamp DateInvoiced = null;
boolean IsPayScheduleValid = false;
int C_Currency_ID = 0;
String sql = "SELECT ci.IsDiscountLineAmt, i.GrandTotal, i.TotalLines, "
+ " i.C_PaymentTerm_ID, i.DateInvoiced, i.IsPayScheduleValid, i.C_Currency_ID "
+ "FROM C_Invoice i"
+ " INNER JOIN AD_ClientInfo ci ON (ci.AD_Client_ID=i.AD_Client_ID) "
+ "WHERE i.C_Invoice_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Invoice_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
IsDiscountLineAmt = "Y".equals(rs.getString(1));
GrandTotal = rs.getBigDecimal(2);
TotalLines = rs.getBigDecimal(3);
C_PaymentTerm_ID = rs.getInt(4);
DateInvoiced = rs.getTimestamp(5);
IsPayScheduleValid = "Y".equals(rs.getString(6));
C_Currency_ID = rs.getInt(7);
}
rs.close();
pstmt.close();
// Not found
if (GrandTotal == null)
//vpj-cd return null;
return Adempiere.ZERO;
// What Amount is the Discount Base?
BigDecimal amount = GrandTotal;
if (IsDiscountLineAmt)
amount = TotalLines;
// Anything to discount?
if (amount.signum() == 0)
return Adempiere.ZERO;
// Valid Payment Schedule (has discount)
if (IsPayScheduleValid && p_C_InvoicePaySchedule_ID > 0)
{
BigDecimal discount = Adempiere.ZERO;
sql = "SELECT DiscountAmt "
+ "FROM C_InvoicePaySchedule "
+ "WHERE C_InvoicePaySchedule_ID=?"
+ " AND TRUNC(DiscountDate) <= ?";
pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_InvoicePaySchedule_ID);
pstmt.setTimestamp(2, PayDate);
rs = pstmt.executeQuery();
if (rs.next())
discount = rs.getBigDecimal(1);
rs.close();
pstmt.close();
//
return discount;
}
// return discount amount
return PaymentTerm.discount (amount, C_Currency_ID,
C_PaymentTerm_ID, DateInvoiced, PayDate);
} // discount
/**
* Test
* @param args
*
public static void main (String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Adempiere.s_type = Adempiere.TYPE_ORACLE;
Adempiere.s_url = "jdbc:oracle:thin:@//dev1:1521/dev1.adempiere.org";
Adempiere.s_uid = "adempiere";
Adempiere.s_pwd = "adempiere";
// System.out.println(Invoice.open(1000000, 1000004));
// System.out.println(Invoice.open(1000000, 1000005));
// System.out.println(Invoice.open(1000001, 1000006));
// System.out.println(Invoice.open(1000001, 1000007));
System.out.println(Invoice.paid(101, 100, 1));
System.out.println(Invoice.paid(1000000, 100, 1));
System.out.println(Invoice.paid(1000001, 100, 1));
System.out.println(Invoice.paid(1000002, 100, 1));
}
catch (SQLException e)
{
e.printStackTrace();
}
} // main /* */
} // Invoice

View File

@ -0,0 +1,152 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
/**
* SQLJ Payment related Functions
*
* @author Jorg Janke
* @version $Id: Payment.java,v 1.2 2006/07/30 00:59:07 jjanke Exp $
*/
public class Payment
{
/**
* Get allocated Payment amount.
* - paymentAllocated
* @param p_C_Payment_ID payment
* @param p_C_Currency_ID currency
* @return allocated amount
* @throws SQLException
*/
public static BigDecimal allocated (int p_C_Payment_ID, int p_C_Currency_ID)
throws SQLException
{
// Charge - nothing available
String sql = "SELECT C_Charge_ID "
+ "FROM C_Payment "
+ "WHERE C_Payment_ID=?";
int C_Charge_ID = Adempiere.getSQLValue(sql, p_C_Payment_ID);
if (C_Charge_ID > 0)
return Adempiere.ZERO;
int C_ConversionType_ID = 0;
// Calculate Allocated Amount
BigDecimal allocatedAmt = getAllocatedAmt(p_C_Payment_ID,
p_C_Currency_ID, C_ConversionType_ID);
// Round
return Currency.round(allocatedAmt, p_C_Currency_ID, null);
} // allocated
/**
* Get available Payment amount in payment currency
* @param p_C_Payment_ID payment
* @return available amt
* @throws SQLException
*/
public static BigDecimal available (int p_C_Payment_ID)
throws SQLException
{
if (p_C_Payment_ID == 0)
return null;
//
int C_Currency_ID = 0;
int C_ConversionType_ID = 0;
BigDecimal PayAmt = null;
int C_Charge_ID = 0;
//
String sql = "SELECT C_Currency_ID, C_ConversionType_ID, PayAmt, C_Charge_ID "
+ "FROM C_Payment_v " // corrected for AP/AR
+ "WHERE C_Payment_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Payment_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
C_Currency_ID = rs.getInt(1);
C_ConversionType_ID = rs.getInt(2);
PayAmt = rs.getBigDecimal(3);
C_Charge_ID = rs.getInt(4);
}
rs.close();
pstmt.close();
// Not found
if (PayAmt == null)
return null;
// Charge - nothing available
if (C_Charge_ID != 0)
return Adempiere.ZERO;
// Calculate Allocated Amount
BigDecimal allocatedAmt = getAllocatedAmt(p_C_Payment_ID,
C_Currency_ID, C_ConversionType_ID);
BigDecimal available = PayAmt.subtract(allocatedAmt);
// Round
return Currency.round(available, C_Currency_ID, null);
} // available
/**
* Get Allocated Amt
* @param p_C_Payment_ID payment
* @param p_C_Currency_ID currency
* @param p_C_ConversionType_ID conversion type
* @return allocated amount in currency
* @throws SQLException
*/
static BigDecimal getAllocatedAmt(int p_C_Payment_ID,
int p_C_Currency_ID, int p_C_ConversionType_ID)
throws SQLException
{
// Calculate Allocated Amount
BigDecimal allocatedAmt = Adempiere.ZERO;
String sql = "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=?"
+ " AND a.IsActive='Y'";
// AND al.C_Invoice_ID IS NOT NULL;
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Payment_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
int AD_Client_ID = rs.getInt(1);
int AD_Org_ID = rs.getInt(2);
BigDecimal amount = rs.getBigDecimal(3);
int C_CurrencyFrom_ID = rs.getInt(4);
Timestamp DateTrx = rs.getTimestamp(5);
//
BigDecimal allocation = Currency.convert(amount, //.multiply(MultiplierAP),
C_CurrencyFrom_ID, p_C_Currency_ID, DateTrx,p_C_ConversionType_ID,
AD_Client_ID, AD_Org_ID);
if (allocation != null)
allocatedAmt = allocatedAmt.add(allocation);
}
rs.close();
pstmt.close();
//
return allocatedAmt;
} // getAllocatedAmt
} // Payment

View File

@ -0,0 +1,348 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
import java.util.*;
/**
* SQLJ Payment Term related Functions
*
* @author Jorg Janke
* @version $Id: PaymentTerm.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class PaymentTerm
{
/**
* Get Due Days.
SELECT Name, paymentTermDueDays(C_PaymentTerm_ID, SysDate, SysDate) "DueDays" FROM C_PaymentTerm
* @param p_C_PaymentTerm_ID payment term
* @param p_DocDate document date
* @param p_PayDate payment date (or today)
* @return days due
* @throws SQLException
*/
public static int dueDays (int p_C_PaymentTerm_ID,
Timestamp p_DocDate, Timestamp p_PayDate)
throws SQLException
{
// Parameter
if (p_C_PaymentTerm_ID == 0 || p_DocDate == null)
return 0;
// Pay Date
Timestamp PayDate = p_PayDate;
if (PayDate == null)
PayDate = new Timestamp(System.currentTimeMillis());
PayDate = Adempiere.trunc(PayDate);
// Get Due Date
Timestamp DueDate = null;
String sql = "SELECT * "
+ "FROM C_PaymentTerm "
+ "WHERE C_PaymentTerm_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_PaymentTerm_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
boolean IsDueFixed = "Y".equals(rs.getString("IsDueFixed"));
//
if (IsDueFixed)
{
int FixMonthDay = rs.getInt("FixMonthDay");
int FixMonthOffset = rs.getInt("FixMonthOffset");
int FixMonthCutoff = rs.getInt("FixMonthCutoff");
//
DueDate = calculateDateDue (p_DocDate, FixMonthDay, FixMonthOffset, FixMonthCutoff);
}
else
{
int NetDays = rs.getInt("NetDays");
DueDate = Adempiere.addDays(p_DocDate, NetDays);
}
}
rs.close();
pstmt.close();
//
if (DueDate == null)
return 0;
return Adempiere.getDaysBetween(DueDate, PayDate);
} // dueDays
/**
* Get Due Days of invoice
* @param p_C_Invoice_ID Invoice
* @param p_PayDate paument date (or today)
* @return days due
* @throws SQLException
*/
public static int invoiceDueDays (int p_C_Invoice_ID, Timestamp p_PayDate)
throws SQLException
{
// Parameter
if (p_C_Invoice_ID == 0)
return 0;
int retValue = 0;
String sql = "SELECT C_PaymentTerm_ID, DateInvoiced "
+ "FROM C_Invoice "
+ "WHERE C_Invoice_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Invoice_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
int C_PaymentTerm_ID = rs.getInt(1);
Timestamp DocDate = rs.getTimestamp(2);
retValue = dueDays(C_PaymentTerm_ID, DocDate, p_PayDate);
}
rs.close();
pstmt.close();
return retValue;
} // invoiceDueDays
/**
* Get Due Date.
SELECT Name, paymentTermDueDate(C_PaymentTerm_ID, SysDate) "DueDate" FROM C_PaymentTerm
* @param p_C_PaymentTerm_ID payment term
* @param p_DocDate document date
* @return due date
* @throws SQLException
*/
public static Timestamp dueDate (int p_C_PaymentTerm_ID,
Timestamp p_DocDate)
throws SQLException
{
// Parameter
if (p_C_PaymentTerm_ID == 0 || p_DocDate == null)
return null;
// Due Date
Timestamp DueDate = Adempiere.trunc(p_DocDate);
// Get Due Date
String sql = "SELECT * "
+ "FROM C_PaymentTerm "
+ "WHERE C_PaymentTerm_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_PaymentTerm_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
boolean IsDueFixed = "Y".equals(rs.getString("IsDueFixed"));
//
if (IsDueFixed)
{
int FixMonthDay = rs.getInt("FixMonthDay");
int FixMonthOffset = rs.getInt("FixMonthOffset");
int FixMonthCutoff = rs.getInt("FixMonthCutoff");
//
DueDate = calculateDateDue (p_DocDate, FixMonthDay, FixMonthOffset, FixMonthCutoff);
}
else
{
int NetDays = rs.getInt("NetDays");
if (NetDays != 0)
DueDate = Adempiere.addDays(DueDate, NetDays);
}
}
rs.close();
pstmt.close();
//
return DueDate;
} // dueDate
/**
* Get Invoice Due Date
* @param p_C_Invoice_ID payment term
* @return due date
* @throws SQLException
*/
public static Timestamp invoiceDueDate (int p_C_Invoice_ID)
throws SQLException
{
// Parameter
if (p_C_Invoice_ID == 0)
return null;
// Due Date
Timestamp DueDate = null;
String sql = "SELECT C_PaymentTerm_ID, DateInvoiced "
+ "FROM C_Invoice "
+ "WHERE C_Invoice_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_Invoice_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
int C_PaymentTerm_ID = rs.getInt(1);
Timestamp DocDate = rs.getTimestamp(2);
DueDate = dueDate(C_PaymentTerm_ID, DocDate);
}
rs.close();
pstmt.close();
//
return DueDate;
} // invoiceDueDate
/**
* Calculate Date
* @param DocDate document date
* @param FixMonthDay day
* @param FixMonthOffset offset
* @param FixMonthCutoff cuttof
* @return date due
*/
private static Timestamp calculateDateDue (Timestamp DocDate, int FixMonthDay, int FixMonthOffset, int FixMonthCutoff)
{
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(DocDate);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
// Cutoff
int maxDayCut = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
if (FixMonthCutoff > maxDayCut) // 28-Feb
cal.set(Calendar.DAY_OF_MONTH, maxDayCut);
else
cal.set(Calendar.DAY_OF_MONTH, FixMonthCutoff);
if (DocDate.after(cal.getTime()))
FixMonthOffset += 1;
cal.add(Calendar.MONTH, FixMonthOffset);
// Due Date
int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
if (FixMonthDay > maxDay) // 32 -> 28
cal.set(Calendar.DAY_OF_MONTH, maxDay);
else if (FixMonthDay >= 30 && maxDay > FixMonthDay) // 30 -> 31
cal.set(Calendar.DAY_OF_MONTH, maxDay);
else
cal.set(Calendar.DAY_OF_MONTH, FixMonthDay);
//
java.util.Date temp = cal.getTime();
return new Timestamp(temp.getTime());
} // calculateDateDue
/**
* Get Discount amount.
SELECT C_PaymentTerm_ID, Name, paymentTermDiscount(111.1111, 100, C_PaymentTerm_ID, SysDate, SysDate) "DiscountUSD", paymentTermDiscount(111.1111, 100, C_PaymentTerm_ID, SysDate, SysDate) "DiscountJPY" FROM C_PaymentTerm
* @param p_Amount amount
* @param p_C_Currency_ID currency
* @param p_C_PaymentTerm_ID payment term
* @param p_DocDate document date
* @param p_PayDate payment date
* @return discount amount
* @throws SQLException
*/
public static BigDecimal discount (BigDecimal p_Amount, int p_C_Currency_ID,
int p_C_PaymentTerm_ID,
Timestamp p_DocDate, Timestamp p_PayDate)
throws SQLException
{
// No Data - No Discount
if (p_Amount == null || p_C_PaymentTerm_ID == 0 || p_DocDate == null)
return null;
if (p_Amount.signum() == 0)
return Adempiere.ZERO;
// Parameters
Timestamp PayDate = p_PayDate;
if (PayDate == null)
PayDate = new Timestamp (System.currentTimeMillis());
PayDate = Adempiere.trunc(PayDate);
//
BigDecimal discount = null;
String sql = "SELECT * "
+ "FROM C_PaymentTerm "
+ "WHERE C_PaymentTerm_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_C_PaymentTerm_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
int DiscountDays = rs.getInt("DiscountDays");
int DiscountDays2 = rs.getInt("DiscountDays2");
int GraceDays = rs.getInt("GraceDays");
boolean IsNextBusinessDay = "Y".equals(rs.getString("IsNextBusinessDay"));
BigDecimal Discount = rs.getBigDecimal("Discount");
BigDecimal Discount2 = rs.getBigDecimal("Discount2");
//
Timestamp Discount1Date = Adempiere.addDays(p_DocDate, DiscountDays + GraceDays);
Timestamp Discount2Date = Adempiere.addDays(p_DocDate, DiscountDays2 + GraceDays);
// Next Business Day
if (IsNextBusinessDay)
{
Discount1Date = Adempiere.nextBusinessDay(Discount1Date);
Discount2Date = Adempiere.nextBusinessDay(Discount2Date);
}
// Discount 1
if (!PayDate.after(Discount1Date))
discount = p_Amount.multiply(Discount);
// Discount 2
else if (!PayDate.after(Discount2Date))
discount = p_Amount.multiply(Discount2);
else
discount = Adempiere.ZERO;
// Divide
if (discount.signum() != 0)
{
discount = discount.divide(Adempiere.HUNDRED, 6, BigDecimal.ROUND_HALF_UP);
discount = Currency.round(discount, p_C_Currency_ID, "N");
}
}
rs.close();
pstmt.close();
//
return discount;
} // discount
/**
* Test
* @param args ignored
*
public static void main (String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Adempiere.s_type = Adempiere.TYPE_ORACLE;
Adempiere.s_url = "jdbc:oracle:thin:@//dev:1521/dev.adempiere.org";
// Adempiere.s_url = "jdbc:oracle:thin:@//dev1:1521/dev1.adempiere.org";
Adempiere.s_uid = "adempiere";
Adempiere.s_pwd = "adempiere";
//
Timestamp today = new Timestamp(System.currentTimeMillis());
// System.out.println(PaymentTerm.dueDays(1000000, today, today));
// System.out.println(PaymentTerm.dueDate(1000000, today));
// System.out.println(PaymentTerm.invoiceDueDate(1000008));
System.out.println(PaymentTerm.discount(new BigDecimal(111.11111), 100, 106, today, today));
System.out.println(PaymentTerm.discount(new BigDecimal(111.11111), 113, 106, today, today));
}
catch (SQLException e)
{
e.printStackTrace();
}
} // main /* */
} // PaymentTerm

View File

@ -0,0 +1,456 @@
/******************************************************************************
* Product: Adempiere ERP & CRM Smart Business Solution *
* Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. *
* This program is free software; you can redistribute it and/or modify it *
* under the terms version 2 of the GNU General Public License as published *
* by the Free Software Foundation. This program is distributed in the hope *
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., *
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
* For the text or an alternative of this public license, you may reach us *
* ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA *
* or via info@compiere.org or http://www.compiere.org/license.html *
*****************************************************************************/
package org.compiere.sqlj;
import java.math.*;
import java.sql.*;
/**
* SQLJ Product related Functions
*
* @author Jorg Janke
* @version $Id: Product.java,v 1.3 2006/07/30 00:59:07 jjanke Exp $
*/
public class Product
{
/**
* Get Product Attribute Instance Name.
* Previously: M_Attribute_Name - Now: productAttribute
* 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);
* @param p_M_AttributeSetInstance_ID instance
* @return Name or ""
* @throws SQLException
*/
public static String attributeName (int p_M_AttributeSetInstance_ID)
throws SQLException
{
if (p_M_AttributeSetInstance_ID == 0)
return "";
//
StringBuffer sb = new StringBuffer();
// Get Base Info
String sql = "SELECT asi.Lot, asi.SerNo, asi.GuaranteeDate "
+ "FROM M_AttributeSetInstance asi "
+ "WHERE asi.M_AttributeSetInstance_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_AttributeSetInstance_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
String lot = rs.getString(1);
if (lot != null && lot.length() > 0)
sb.append(lot).append(" ");
String serNo = rs.getString(2);
if (serNo != null && serNo.length() > 0)
sb.append("#").append(serNo).append(" ");
Date guarantee = rs.getDate(3);
if (guarantee != null)
sb.append(guarantee).append(" ");
}
rs.close();
pstmt.close();
// Get Instance Info
sql = "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=?";
pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_AttributeSetInstance_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
sb.append(rs.getString(1)) // value
.append(":").append(rs.getString(2)) // name
.append(" ");
}
rs.close();
pstmt.close();
if (sb.length() == 0)
return "";
sb.insert(0, " (");
sb.append(")");
return sb.toString();
} // getAttributeName
/**************************************************************************
* Get BOM Price Limit
* Previously: BOM_PriceLimit - Now: bomPriceLimit
* @param p_M_Product_ID
* @param p_M_PriceList_Version_ID
* @return Price Limit
* @throws SQLException
*/
public static BigDecimal bomPriceLimit (int p_M_Product_ID, int p_M_PriceList_Version_ID)
throws SQLException
{
return bomPrice(p_M_Product_ID, p_M_PriceList_Version_ID, "PriceLimit");
} // bomPriceLimit
/**
* Get BOM Price List
* Previously: BOM_PriceList - Now: bomPriceList
* @param p_M_Product_ID
* @param p_M_PriceList_Version_ID
* @return Price List
* @throws SQLException
*/
public static BigDecimal bomPriceList (int p_M_Product_ID, int p_M_PriceList_Version_ID)
throws SQLException
{
return bomPrice(p_M_Product_ID, p_M_PriceList_Version_ID, "PriceList");
} // bomPriceList
/**
* Get BOM Price Std
* Previously: BOM_PriceStd - Now: bomPriceStd
* @param p_M_Product_ID
* @param p_M_PriceList_Version_ID
* @return Price Std
* @throws SQLException
*/
public static BigDecimal bomPriceStd (int p_M_Product_ID, int p_M_PriceList_Version_ID)
throws SQLException
{
return bomPrice(p_M_Product_ID, p_M_PriceList_Version_ID, "PriceStd");
} // bomPriceStd
/**
* Get BOM Price
* @param p_M_Product_ID
* @param p_M_PriceList_Version_ID
* @param p_what variable name
* @return Price
* @throws SQLException
*/
static BigDecimal bomPrice (int p_M_Product_ID, int p_M_PriceList_Version_ID, String p_what)
throws SQLException
{
BigDecimal price = null;
// Try to get price from PriceList directly
String sql = "SELECT " + p_what
+ " FROM M_ProductPrice "
+ "WHERE M_PriceList_Version_ID=? AND M_Product_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_PriceList_Version_ID);
pstmt.setInt(2, p_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
price = rs.getBigDecimal(1);
rs.close();
pstmt.close();
// Loop through BOM
if (price == null || price.signum() == 0)
{
price = Adempiere.ZERO;
sql = "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=?";
pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_Product_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
int M_ProductBOM_ID = rs.getInt(1);
BigDecimal qty = rs.getBigDecimal(2);
BigDecimal productPrice = bomPrice(M_ProductBOM_ID, p_M_PriceList_Version_ID, p_what);
productPrice = productPrice.multiply(qty);
price = price.add(productPrice);
}
rs.close();
pstmt.close();
}
return price;
} // bomPrice
/**************************************************************************
* Get BOM Quantity Available
* Previously: BOM_Qty_Available - Now: bomQtyAvailable
* @param p_M_Product_ID product
* @param p_M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @return Quantity Available
* @throws SQLException
*/
public static BigDecimal bomQtyAvailable (int p_M_Product_ID,
int p_M_Warehouse_ID, int p_M_Locator_ID)
throws SQLException
{
return bomQty(p_M_Product_ID, p_M_Warehouse_ID, p_M_Locator_ID, "QtyOnHand")
.subtract(bomQty(p_M_Product_ID, p_M_Warehouse_ID, p_M_Locator_ID, "QtyReserved"));
} // bomQtyAvailable
/**
* Get BOM Quantity OnHand
* Previously: BOM_Qty_OnHand - Now: bomQtyOnHand
* @param p_M_Product_ID product
* @param p_M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @return Quantity Available
* @throws SQLException
*/
public static BigDecimal bomQtyOnHand (int p_M_Product_ID,
int p_M_Warehouse_ID, int p_M_Locator_ID)
throws SQLException
{
return bomQty(p_M_Product_ID, p_M_Warehouse_ID, p_M_Locator_ID, "QtyOnHand");
} // bomQtyOnHand
/**
* Get BOM Quantity Ordered
* Previously: BOM_Qty_Ordered - Now: bomQtyOrdered
* @param p_M_Product_ID product
* @param p_M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @return Quantity Ordered
* @throws SQLException
*/
public static BigDecimal bomQtyOrdered (int p_M_Product_ID,
int p_M_Warehouse_ID, int p_M_Locator_ID)
throws SQLException
{
return bomQty(p_M_Product_ID, p_M_Warehouse_ID, p_M_Locator_ID, "QtyOrdered");
} // bomQtyOrdered
/**
* Get BOM Quantity Reserved
* Previously: BOM_Qty_Reserved - Now: bomQtyReserved
* @param p_M_Product_ID product
* @param p_M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @return Qyantity Reserved
* @throws SQLException
*/
public static BigDecimal bomQtyReserved (int p_M_Product_ID,
int p_M_Warehouse_ID, int p_M_Locator_ID)
throws SQLException
{
return bomQty(p_M_Product_ID, p_M_Warehouse_ID, p_M_Locator_ID, "QtyReserved");
} // bomQtyReserved
/**
* Get BOM Quantity
* @param p_M_Product_ID product
* @param p_M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @param p_what variable name
* @return Quantity
* @throws SQLException
*/
static BigDecimal bomQty (int p_M_Product_ID,
int p_M_Warehouse_ID, int p_M_Locator_ID, String p_what)
throws SQLException
{
// Check Parameters
int M_Warehouse_ID = p_M_Warehouse_ID;
if (M_Warehouse_ID == 0)
{
if (p_M_Locator_ID == 0)
return Adempiere.ZERO;
else
{
String sql = "SELECT M_Warehouse_ID "
+ "FROM M_Locator "
+ "WHERE M_Locator_ID=?";
M_Warehouse_ID = Adempiere.getSQLValue(sql, p_M_Locator_ID);
}
}
// begin globalqss 2005-10-11
// if (M_Warehouse_ID == 0)
if (M_Warehouse_ID == 0 || M_Warehouse_ID == -1)
// end globalqss 2005-10-11
return Adempiere.ZERO;
// Check, if product exists and if it is stocked
boolean isBOM = false;
String ProductType = null;
boolean isStocked = false;
String sql = "SELECT IsBOM, ProductType, IsStocked "
+ "FROM M_Product "
+ "WHERE M_Product_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
isBOM = "Y".equals(rs.getString(1));
ProductType = rs.getString(2);
isStocked = "Y".equals(rs.getString(3));
}
rs.close();
pstmt.close();
// No Product
if (ProductType == null)
return Adempiere.ZERO;
// Unlimited capacity if no item
if (!isBOM && (!ProductType.equals("I") || !isStocked))
return UNLIMITED;
// Get Qty
if (isStocked)
return getStorageQty(p_M_Product_ID, M_Warehouse_ID, p_M_Locator_ID, p_what);
// Go through BOM
BigDecimal quantity = UNLIMITED;
BigDecimal productQuantity = null;
sql = "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=?";
pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_Product_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
int M_ProductBOM_ID = rs.getInt(1);
BigDecimal bomQty = rs.getBigDecimal(2);
isBOM = "Y".equals(rs.getString(3));
isStocked = "Y".equals(rs.getString(4));
ProductType = rs.getString(5);
// Stocked Items "leaf node"
if (ProductType.equals("I") && isStocked)
{
// Get ProductQty
productQuantity = getStorageQty(M_ProductBOM_ID, M_Warehouse_ID, p_M_Locator_ID, p_what);
// Get Rounding Precision
int uomPrecision = getUOMPrecision(M_ProductBOM_ID);
// How much can we make with this product
productQuantity = productQuantity.setScale(uomPrecision)
.divide(bomQty, uomPrecision, BigDecimal.ROUND_HALF_UP);
// How much can we make overall
if (productQuantity.compareTo(quantity) < 0)
quantity = productQuantity;
}
else if (isBOM) // Another BOM
{
productQuantity = bomQty (M_ProductBOM_ID, M_Warehouse_ID, p_M_Locator_ID, p_what);
// How much can we make overall
if (productQuantity.compareTo(quantity) < 0)
quantity = productQuantity;
}
}
rs.close();
pstmt.close();
if (quantity.signum() != 0)
{
int uomPrecision = getUOMPrecision(p_M_Product_ID);
return quantity.setScale(uomPrecision, BigDecimal.ROUND_HALF_UP);
}
return Adempiere.ZERO;
} // bomQtyOnHand
/** Unlimited Quantity */
private static final BigDecimal UNLIMITED = new BigDecimal((double)99999.0);
/**
* Get Storage Qty
* @param p_M_Product_ID product
* @param M_Warehouse_ID warehouse
* @param p_M_Locator_ID locator
* @param p_what variable name
* @return quantity or zero
* @throws SQLException
*/
static BigDecimal getStorageQty (int p_M_Product_ID,
int M_Warehouse_ID, int p_M_Locator_ID, String p_what)
throws SQLException
{
BigDecimal quantity = null;
String sql = "SELECT SUM(" + p_what + ") "
+ "FROM M_Storage s "
+ "WHERE M_Product_ID=?";
if (p_M_Locator_ID != 0)
sql += " AND s.M_Locator_ID=?";
else
sql += " AND EXISTS (SELECT * FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID"
+ " AND l.M_Warehouse_ID=?)";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_Product_ID);
if (p_M_Locator_ID != 0)
pstmt.setInt(2, p_M_Locator_ID);
else
pstmt.setInt(2, M_Warehouse_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
quantity = rs.getBigDecimal(1);
rs.close();
pstmt.close();
// Not found
if (quantity == null)
return Adempiere.ZERO;
return quantity;
} // getStorageQty
/**
* Get UOM Precision for Product
* @param p_M_Product_ID product
* @return precision or 0
* @throws SQLException
*/
static int getUOMPrecision (int p_M_Product_ID) throws SQLException
{
int precision = 0;
String sql = "SELECT u.StdPrecision "
+ "FROM C_UOM u"
+ " INNER JOIN M_Product p ON (u.C_UOM_ID=p.C_UOM_ID) "
+ "WHERE p.M_Product_ID=?";
PreparedStatement pstmt = Adempiere.prepareStatement(sql);
pstmt.setInt(1, p_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
precision = rs.getInt(1);
rs.close();
pstmt.close();
return precision;
} // getStdPrecision
/**
* Test
* @param args
*
public static void main (String[] args)
{
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Adempiere.s_type = Adempiere.TYPE_ORACLE;
Adempiere.s_url = "jdbc:oracle:thin:@//dev1:1521/dev1.adempiere.org";
Adempiere.s_uid = "adempiere";
Adempiere.s_pwd = "adempiere";
// System.out.println(Product.bomQtyOnHand(p_M_Product_ID, 0, p_M_Locator_ID));
}
catch (SQLException e)
{
e.printStackTrace();
}
} // main /* */
} // Product