Revert to before revision becuase break the trunk

This commit is contained in:
vpj-cd 2007-06-08 17:26:56 +00:00
parent 162658d40f
commit d446128737
1 changed files with 69 additions and 101 deletions

View File

@ -183,9 +183,6 @@ public class MOrderLine extends X_C_OrderLine
private boolean m_IsSOTrx = true; private boolean m_IsSOTrx = true;
// Product Pricing // Product Pricing
private MProductPricing m_productPrice = null; private MProductPricing m_productPrice = null;
/** Tax */
private MTax m_tax = null;
/** Cached Currency Precision */ /** Cached Currency Precision */
private Integer m_precision = null; private Integer m_precision = null;
@ -193,15 +190,6 @@ public class MOrderLine extends X_C_OrderLine
private MProduct m_product = null; private MProduct m_product = null;
/** Parent */ /** Parent */
private MOrder m_parent = null; private MOrder m_parent = null;
/**
* Set Precision
* @param precision The precision to set.
*/
protected void setPrecision (int precision)
{
m_precision = new Integer(precision);
} // setPrecision
/** /**
* Set Defaults from Order. * Set Defaults from Order.
@ -350,46 +338,12 @@ public class MOrderLine extends X_C_OrderLine
*/ */
public void setLineNetAmt () public void setLineNetAmt ()
{ {
BigDecimal bd = getPriceActual().multiply(getQtyOrdered()); BigDecimal bd = getPriceActual().multiply(getQtyOrdered());
boolean documentLevel = getTax().isDocumentLevel(); if (bd.scale() > getPrecision())
bd = bd.setScale(getPrecision(), BigDecimal.ROUND_HALF_UP);
// juddm: Tax Exempt & Tax Included in Price List & not Document Level - Adjust Line Amount
// http://sourceforge.net/tracker/index.php?func=detail&aid=1733602&group_id=176962&atid=879332
if (isTaxIncluded() && !documentLevel) {
BigDecimal taxStdAmt = Env.ZERO, taxThisAmt = Env.ZERO;
MTax orderTax = getTax();
// get the standard tax
MTax stdTax = new MTax (getCtx(), getProduct().getC_Tax_ID(), get_TrxName());
log.fine("stdTax rate is " + stdTax.getRate());
log.fine("orderTax rate is " + orderTax.getRate());
taxThisAmt = taxThisAmt.add(orderTax.calculateTax(bd, isTaxIncluded(), getPrecision()));
taxStdAmt = taxStdAmt.add(stdTax.calculateTax(bd, isTaxIncluded(), getPrecision()));
bd = bd.subtract(taxStdAmt).add(taxThisAmt);
log.fine("Special Tax Override: Tax Amt: " + taxThisAmt + " Standard Tax Amt: " + taxStdAmt + " Line Net Amt: " + bd);
}
if (bd.scale() > getPrecision())
bd = bd.setScale(getPrecision(), BigDecimal.ROUND_HALF_UP);
super.setLineNetAmt (bd); super.setLineNetAmt (bd);
} // setLineNetAmt } // setLineNetAmt
/**
* Get Tax
* @return tax
*/
protected MTax getTax()
{
if (m_tax == null)
m_tax = MTax.get(getCtx(), getC_Tax_ID());
return m_tax;
} // getTax
/** /**
* Get Currency Precision from Currency * Get Currency Precision from Currency
* @return precision * @return precision
@ -814,43 +768,42 @@ public class MOrderLine extends X_C_OrderLine
&& getM_AttributeSetInstance_ID() != 0 && getM_AttributeSetInstance_ID() != 0
&& (newRecord || is_ValueChanged("M_Product_ID") && (newRecord || is_ValueChanged("M_Product_ID")
|| is_ValueChanged("M_AttributeSetInstance_ID") || is_ValueChanged("M_AttributeSetInstance_ID")
|| is_ValueChanged("M_Warehouse_ID"))) || is_ValueChanged("M_Warehouse_ID")))
{ {
MProduct product = getProduct(); MProduct product = getProduct();
if (product.isStocked()) if (product.isStocked())
{ {
int M_AttributeSet_ID = product.getM_AttributeSet_ID(); int M_AttributeSet_ID = product.getM_AttributeSet_ID();
boolean isInstance = M_AttributeSet_ID != 0; boolean isInstance = M_AttributeSet_ID != 0;
if (isInstance) if (isInstance)
{ {
MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID); MAttributeSet mas = MAttributeSet.get(getCtx(), M_AttributeSet_ID);
isInstance = mas.isInstanceAttribute(); isInstance = mas.isInstanceAttribute();
} }
// Max // Max
if (isInstance) if (isInstance)
{ {
MStorage[] storages = MStorage.getWarehouse(getCtx(), MStorage[] storages = MStorage.getWarehouse(getCtx(),
getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(), getM_Warehouse_ID(), getM_Product_ID(), getM_AttributeSetInstance_ID(),
M_AttributeSet_ID, false, null, true, get_TrxName()); M_AttributeSet_ID, false, null, true, get_TrxName());
BigDecimal qty = Env.ZERO; BigDecimal qty = Env.ZERO;
for (int i = 0; i < storages.length; i++) for (int i = 0; i < storages.length; i++)
{ {
if (storages[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID()) if (storages[i].getM_AttributeSetInstance_ID() == getM_AttributeSetInstance_ID())
qty = qty.add(storages[i].getQtyOnHand()); qty = qty.add(storages[i].getQtyOnHand());
} }
if (getQtyOrdered().compareTo(qty) > 0) if (getQtyOrdered().compareTo(qty) > 0)
{ {
log.warning("Qty - Stock=" + qty + ", Ordered=" + getQtyOrdered()); log.warning("Qty - Stock=" + qty + ", Ordered=" + getQtyOrdered());
//log.saveError("QtyInsufficient", "=" + qty); log.saveError("QtyInsufficient", "=" + qty);
//return false; return false;
return true; }
} }
} } // stocked
} // stocked } // SO instance
} // SO instance
// FreightAmt Not used
// FreightAmt Not used if (Env.ZERO.compareTo(getFreightAmt()) != 0)
if (Env.ZERO.compareTo(getFreightAmt()) != 0)
setFreightAmt(Env.ZERO); setFreightAmt(Env.ZERO);
// Set Tax // Set Tax
@ -913,15 +866,9 @@ public class MOrderLine extends X_C_OrderLine
if (!newRecord && is_ValueChanged("C_Tax_ID")) if (!newRecord && is_ValueChanged("C_Tax_ID"))
{ {
// Recalculate Tax for old Tax // Recalculate Tax for old Tax
MOrderTax tax = MOrderTax.get (this, getPrecision(), if (!getParent().isProcessed())
true, get_TrxName()); // old Tax if (!updateOrderTax(true))
if (tax != null)
{
if (!tax.calculateTaxFromLines())
return false; return false;
if (!tax.save(get_TrxName()))
return false;
}
} }
return updateHeaderTax(); return updateHeaderTax();
} // afterSave } // afterSave
@ -944,6 +891,30 @@ public class MOrderLine extends X_C_OrderLine
return updateHeaderTax(); return updateHeaderTax();
} // afterDelete } // afterDelete
/**
* Recalculate order tax
* @param oldTax true if the old C_Tax_ID should be used
* @return true if success, false otherwise
*
* @author teo_sarca [ 1583825 ]
*/
private boolean updateOrderTax(boolean oldTax) {
MOrderTax tax = MOrderTax.get (this, getPrecision(), oldTax, get_TrxName());
if (tax != null) {
if (!tax.calculateTaxFromLines())
return false;
if (tax.getTaxAmt().signum() != 0) {
if (!tax.save(get_TrxName()))
return false;
}
else {
if (!tax.is_new() && !tax.delete(false, get_TrxName()))
return false;
}
}
return true;
}
/** /**
* Update Tax & Header * Update Tax & Header
* @return true if header updated * @return true if header updated
@ -951,12 +922,9 @@ public class MOrderLine extends X_C_OrderLine
private boolean updateHeaderTax() private boolean updateHeaderTax()
{ {
// Recalculate Tax for this Tax // Recalculate Tax for this Tax
MOrderTax tax = MOrderTax.get (this, getPrecision(), if (!getParent().isProcessed())
false, get_TrxName()); // current Tax if (!updateOrderTax(false))
if (!tax.calculateTaxFromLines()) return false;
return false;
if (!tax.save(get_TrxName()))
return false;
// Update Order Header // Update Order Header
String sql = "UPDATE C_Order i" String sql = "UPDATE C_Order i"