com.knowgate.hipergate
Class AbstractOrder

java.lang.Object
  extended bycom.knowgate.dataobjs.DBPersist
      extended bycom.knowgate.hipergate.AbstractOrder
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
DespatchAdvice, Invoice, Order

public abstract class AbstractOrder
extends DBPersist

An abstract super class for Order and Invoice classes

Version:
3.0

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  DBPersist oBuyer
           
protected  DBSubset oLines
           
protected  DBPersist oSeller
           
protected  java.lang.String sLinesTable
           
protected  java.lang.String sPrimaryKey
           
 
Fields inherited from class com.knowgate.dataobjs.DBPersist
AllVals, sAuditCls, sAuditUsr, sTransactId
 
Constructor Summary
protected AbstractOrder(java.lang.String sTableName, java.lang.String sLinesName, java.lang.String sKeyName, java.lang.String sAuditClass)
           
 
Method Summary
 int addProduct(JDCConnection oConn, java.lang.String sProductId, float fQuantity)
          Add Product from Catalog to an Order or Invoice line
 int addProduct(JDCConnection oConn, java.lang.String sProductId, java.lang.String sProductNm, java.math.BigDecimal dSalePr, float fQuantity, java.math.BigDecimal dTotalPr, float fTax, short iTaxIncluded, java.lang.String sPromotion, java.lang.String sOptions)
          Add Product to Order or Invoice line
 int addProduct(JDCConnection oConn, java.lang.String sProductId, java.lang.String sProductNm, float fQuantity, java.lang.String sPromotion, java.lang.String sOptions)
          Add a Product from a Catalog to an Order or Invoice line
 java.math.BigDecimal computeSubtotal()
          Sum over pr_sale price taking quantities into account
 java.math.BigDecimal computeSubtotal(JDCConnection oConn)
          Get total price for all lines without taxes
 java.math.BigDecimal computeTaxes()
          Get total tax amount for all lines
 java.math.BigDecimal computeTaxes(JDCConnection oConn)
           
 java.math.BigDecimal computeTotal()
          Compute Invoce total
 Address getBillAddress(JDCConnection oConn)
          Get billing address for this order
 java.lang.String getCurrencyFormat()
           
protected  java.lang.StringBuffer getDecimalFormated(java.lang.String sColumnName)
           
 DBSubset getLines()
          Get order lines as a DBSubset
abstract  DBSubset getLines(JDCConnection oConn)
           
 java.util.Locale getLocale()
           
 boolean load(JDCConnection oConn, java.lang.Object[] PKVals)
          Load the internal value set from a register at a database table
 void removeAllProducts(JDCConnection oConn)
          Remove all products from invoice or order (empty basket)
 void removeProduct(JDCConnection oConn, java.lang.String sProductId)
          Remove Product from Order given its GUID
 void setCurrencyFormat(java.lang.String sFormat)
           
 void setLocale(java.util.Locale oLoc)
           
 void setLocale(java.lang.String sLanguage)
           
 void setLocale(java.lang.String sLanguage, java.lang.String sCountry)
           
 
Methods inherited from class com.knowgate.dataobjs.DBPersist
allcaps, allcaps, changelog, clear, clone, containsKey, containsValue, delete, entrySet, exists, get, get, getAuditClassName, getCreationDate, getDate, getDateFormated, getDateShort, getDecimal, getDecimalFormated, getDouble, getDoubleFormated, getFloat, getFloatFormated, getInt, getInteger, getItemMap, getItems, getShort, getString, getStringNull, getTable, getTable, getTableName, getTime, getTimeOfDay, getTimestamp, getUIdFromName, isEmpty, isNull, iterator, keySet, load, parseXML, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, put, putAll, putAll, remove, remove, replace, replace, replace, replace, setAuditTransact, setAuditUser, size, store, toLowerCase, toUpperCase, toXML, toXML, toXML, values
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

oLines

protected DBSubset oLines

oBuyer

protected DBPersist oBuyer

oSeller

protected DBPersist oSeller

sLinesTable

protected java.lang.String sLinesTable

sPrimaryKey

protected java.lang.String sPrimaryKey
Constructor Detail

AbstractOrder

protected AbstractOrder(java.lang.String sTableName,
                        java.lang.String sLinesName,
                        java.lang.String sKeyName,
                        java.lang.String sAuditClass)
Method Detail

getCurrencyFormat

public java.lang.String getCurrencyFormat()

setCurrencyFormat

public void setCurrencyFormat(java.lang.String sFormat)
                       throws java.lang.NullPointerException
Throws:
java.lang.NullPointerException

getDecimalFormated

protected java.lang.StringBuffer getDecimalFormated(java.lang.String sColumnName)

setLocale

public void setLocale(java.util.Locale oLoc)

setLocale

public void setLocale(java.lang.String sLanguage,
                      java.lang.String sCountry)

setLocale

public void setLocale(java.lang.String sLanguage)

getLocale

public java.util.Locale getLocale()

getBillAddress

public Address getBillAddress(JDCConnection oConn)
                       throws java.sql.SQLException

Get billing address for this order

Address is loaded from value of gu_bill_addr column. If gu_bill_addr is null then this function returns null.

Parameters:
oConn - JDCConnection
Returns:
Address object instance or null if gu_bill_addr is null
Throws:
java.sql.SQLException

getLines

public DBSubset getLines()
                  throws java.lang.IllegalStateException
Get order lines as a DBSubset

Returns:
DBSubset The columns returned depend on the implementation of getLines(JDCConnection) at derived clases
Throws:
java.lang.IllegalStateException - If this method is called without having loaded the order lines first.

getLines

public abstract DBSubset getLines(JDCConnection oConn)
                           throws java.sql.SQLException
Throws:
java.sql.SQLException

load

public boolean load(JDCConnection oConn,
                    java.lang.Object[] PKVals)
             throws java.sql.SQLException
Description copied from class: DBPersist

Load the internal value set from a register at a database table

Overrides:
load in class DBPersist
Parameters:
oConn - Database Connection
PKVals - Primary key values in order of appearance
Returns:
true if a register was found, false if no register was found with such primary key.
Throws:
java.sql.SQLException

addProduct

public int addProduct(JDCConnection oConn,
                      java.lang.String sProductId,
                      java.lang.String sProductNm,
                      java.math.BigDecimal dSalePr,
                      float fQuantity,
                      java.math.BigDecimal dTotalPr,
                      float fTax,
                      short iTaxIncluded,
                      java.lang.String sPromotion,
                      java.lang.String sOptions)
               throws java.sql.SQLException,
                      java.lang.IllegalArgumentException,
                      java.lang.NullPointerException

Add Product to Order or Invoice line

This method may be used to add order lines for products not present at k_products table.

Parameters:
oConn - Database Connection
sProductId - Product GUID (optional, if not set a new one will be automatically assigned).
sProductNm - Product Name
dSalePr - Product Unitary Sale Price
fQuantity - Quantity ordered
dTotalPr - Total Price for Quantity including taxes
fTax - Percentage of tax rate applicable
iTaxIncluded - 1 if tax is included in unitary price, 0 if tax is not included.
sPromotion - Promotional Text
sOptions - Additional Options
Returns:
Line Number Added
Throws:
java.sql.SQLException
java.lang.IllegalArgumentException - If sProductId does not exist
java.lang.NullPointerException

addProduct

public int addProduct(JDCConnection oConn,
                      java.lang.String sProductId,
                      java.lang.String sProductNm,
                      float fQuantity,
                      java.lang.String sPromotion,
                      java.lang.String sOptions)
               throws java.sql.SQLException,
                      java.lang.IllegalArgumentException,
                      java.lang.NullPointerException

Add a Product from a Catalog to an Order or Invoice line

This method takes into account pr_sale, pr_list, dt_start and dt_end fields.
There are two possible prices, list price or sale (bargain) price.
Sale price is returned if it exists at database and given date is between dt_start and dt_end.
Otherwise List price is returned.
Product Price is taken from k_products table following these rules:

Parameters:
oConn - Database Conenction
sProductId - Product GUID (required)
sProductNm - Product Name
fQuantity - Quantity ordered.
sPromotion - Promotional Text
sOptions - Additional Options
Returns:
Line Number Added
Throws:
java.sql.SQLException
java.lang.IllegalArgumentException - If sProductId does not exist
java.lang.NullPointerException

addProduct

public int addProduct(JDCConnection oConn,
                      java.lang.String sProductId,
                      float fQuantity)
               throws java.sql.SQLException,
                      java.lang.IllegalArgumentException,
                      java.lang.NullPointerException

Add Product from Catalog to an Order or Invoice line

Parameters:
oConn - Database Connection
sProductId - Product GUID
fQuantity - Quantity
Returns:
Line Number Added
Throws:
java.sql.SQLException
java.lang.IllegalArgumentException
java.lang.NullPointerException

removeProduct

public void removeProduct(JDCConnection oConn,
                          java.lang.String sProductId)
                   throws java.sql.SQLException

Remove Product from Order given its GUID

Parameters:
oConn - Database Connection
sProductId - GUID of product to be removed.
Throws:
java.sql.SQLException

removeAllProducts

public void removeAllProducts(JDCConnection oConn)
                       throws java.sql.SQLException

Remove all products from invoice or order (empty basket)

Parameters:
oConn - Database Connection
Throws:
java.sql.SQLException

computeSubtotal

public java.math.BigDecimal computeSubtotal()
                                     throws java.lang.IllegalStateException

Sum over pr_sale price taking quantities into account

This method will compute the sum of order line prices without taxes or other charges

Returns:
BigDecimal
Throws:
java.lang.IllegalStateException - if order lines have not been previously loaded

computeSubtotal

public java.math.BigDecimal computeSubtotal(JDCConnection oConn)
                                     throws java.sql.SQLException

Get total price for all lines without taxes

Parameters:
oConn - JDCConnection
Returns:
BigDecimal Sum over pr_sale price taking quantities into account
Throws:
java.sql.SQLException

computeTaxes

public java.math.BigDecimal computeTaxes()
                                  throws java.lang.IllegalStateException

Get total tax amount for all lines

Returns:
BigDecimal SUM(pr_sale*nu_quantity*pct_tax_rate)
Throws:
java.lang.IllegalStateException

computeTaxes

public java.math.BigDecimal computeTaxes(JDCConnection oConn)
                                  throws java.sql.SQLException
Throws:
java.sql.SQLException

computeTotal

public java.math.BigDecimal computeTotal()
                                  throws java.lang.IllegalStateException

Compute Invoce total

Sum of all line subtotals including taxes.

Returns:
BigDecimal computeSubtotal()+computeTaxes()
Throws:
java.lang.IllegalStateException - if order lines have not been previously loaded