IDEMPIERE-954 Problem with Online Shipping Sales Order Rate Inquiry process

This commit is contained in:
Elaine Tan 2013-05-23 15:46:43 +08:00
parent 460e5f2eac
commit 1b1c7cb9d1
2 changed files with 96 additions and 32 deletions

View File

@ -14,9 +14,6 @@
package org.adempiere.model; package org.adempiere.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import org.compiere.model.MProduct;
/** /**
* *
@ -29,7 +26,7 @@ public class ShippingPackage
private BigDecimal height; private BigDecimal height;
private BigDecimal length; private BigDecimal length;
private BigDecimal width; private BigDecimal width;
private ArrayList<MProduct> products; private String description;
public BigDecimal getWeight() { public BigDecimal getWeight() {
return weight; return weight;
@ -63,11 +60,11 @@ public class ShippingPackage
this.width = width; this.width = width;
} }
public ArrayList<MProduct> getProducts() { public String getDescription() {
return products; return description;
} }
public void setProducts(ArrayList<MProduct> products) { public void setDescription(String description) {
this.products = products; this.description = description;
} }
} }

View File

@ -15,7 +15,10 @@ package org.adempiere.process;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
@ -38,6 +41,7 @@ import org.compiere.model.MUOM;
import org.compiere.process.ProcessInfoLog; import org.compiere.process.ProcessInfoLog;
import org.compiere.process.ProcessInfoParameter; import org.compiere.process.ProcessInfoParameter;
import org.compiere.process.SvrProcess; import org.compiere.process.SvrProcess;
import org.compiere.util.DisplayType;
/** /**
* *
@ -228,9 +232,10 @@ public class SalesOrderRateInquiryProcess extends SvrProcess
BigDecimal FreightAmt = BigDecimal.ZERO; BigDecimal FreightAmt = BigDecimal.ZERO;
BigDecimal TotalWeight = BigDecimal.ZERO; BigDecimal TotalWeight = BigDecimal.ZERO;
DecimalFormat df = DisplayType.getNumberFormat(DisplayType.Quantity);
ArrayList<ShippingPackage> packages = new ArrayList<ShippingPackage>(); ArrayList<ShippingPackage> packages = new ArrayList<ShippingPackage>();
BigDecimal TotalPackageWeight = BigDecimal.ZERO; ArrayList<Object[]> items = new ArrayList<Object[]>();
ArrayList<MProduct> products = new ArrayList<MProduct>();
MOrderLine[] ols = m_order.getLines(false, MOrderLine.COLUMNNAME_Line); MOrderLine[] ols = m_order.getLines(false, MOrderLine.COLUMNNAME_Line);
for (MOrderLine ol : ols) for (MOrderLine ol : ols)
{ {
@ -254,49 +259,111 @@ public class SalesOrderRateInquiryProcess extends SvrProcess
if (product.isOwnBox()) if (product.isOwnBox())
{ {
ArrayList<MProduct> ownBoxProducts = new ArrayList<MProduct>();
ownBoxProducts.add(product);
BigDecimal remainingQty = qty; BigDecimal remainingQty = qty;
for(int i = 0; i < qty.doubleValue(); i++) while (remainingQty.compareTo(BigDecimal.ZERO) > 0)
{ {
remainingQty = remainingQty.subtract(BigDecimal.ONE); BigDecimal itemQty = new BigDecimal(Math.min(remainingQty.doubleValue(), 1));
ShippingPackage shippingPackage = new ShippingPackage(); ShippingPackage shippingPackage = new ShippingPackage();
shippingPackage.setWeight(weight.multiply(remainingQty)); shippingPackage.setWeight(weight.multiply(itemQty));
shippingPackage.setProducts(ownBoxProducts); shippingPackage.setDescription(df.format(itemQty) + " x " + product.getValue());
shippingPackage.setHeight(product.getShelfHeight()); shippingPackage.setHeight(product.getShelfHeight());
shippingPackage.setWidth(new BigDecimal(product.getShelfWidth())); shippingPackage.setWidth(new BigDecimal(product.getShelfWidth()));
shippingPackage.setLength(new BigDecimal(product.getShelfDepth())); shippingPackage.setLength(new BigDecimal(product.getShelfDepth()));
packages.add(shippingPackage); packages.add(shippingPackage);
remainingQty = remainingQty.subtract(BigDecimal.ONE);
} }
} }
else else
{ {
products.add(product); BigDecimal remainingQty = qty;
while (remainingQty.compareTo(BigDecimal.ZERO) > 0)
if ((weight.multiply(qty)).add(TotalPackageWeight).compareTo(WeightPerPackage) > 0)
{ {
ShippingPackage shippingPackage = new ShippingPackage(); BigDecimal itemQty = new BigDecimal(Math.min(remainingQty.doubleValue(), 1));
shippingPackage.setWeight(TotalPackageWeight); items.add(new Object[] {product, itemQty});
shippingPackage.setProducts(products); remainingQty = remainingQty.subtract(BigDecimal.ONE);
packages.add(shippingPackage);
products.clear();
TotalPackageWeight = weight.multiply(qty);
} }
else
TotalPackageWeight = TotalPackageWeight.add(weight.multiply(qty));
} }
TotalWeight = TotalWeight.add(weight.multiply(qty)); TotalWeight = TotalWeight.add(weight.multiply(qty));
} }
} }
Hashtable<MProduct, BigDecimal> packageItems = new Hashtable<MProduct, BigDecimal>();
BigDecimal TotalPackageWeight = BigDecimal.ZERO;
for (Object[] item : items)
{
MProduct product = (MProduct) item[0];
BigDecimal qty = (BigDecimal) item[1];
BigDecimal itemWeight = product.getWeight().multiply(qty);
if (itemWeight.compareTo(WeightPerPackage) >= 0)
{
ArrayList<MProduct> ownBoxProducts = new ArrayList<MProduct>();
ownBoxProducts.add(product);
ShippingPackage shippingPackage = new ShippingPackage();
shippingPackage.setWeight(itemWeight);
shippingPackage.setDescription(df.format(qty) + " x " + product.getValue());
shippingPackage.setHeight(product.getShelfHeight());
shippingPackage.setWidth(new BigDecimal(product.getShelfWidth()));
shippingPackage.setLength(new BigDecimal(product.getShelfDepth()));
packages.add(shippingPackage);
}
else if ((itemWeight.add(TotalPackageWeight)).compareTo(WeightPerPackage) > 0)
{
ShippingPackage shippingPackage = new ShippingPackage();
shippingPackage.setWeight(TotalPackageWeight);
String description = "";
Enumeration<MProduct> en = packageItems.keys();
while (en.hasMoreElements())
{
MProduct packageProduct = en.nextElement();
BigDecimal packageQty = packageItems.get(packageProduct);
description += df.format(packageQty) + " x " + packageProduct.getValue() + ", ";
}
if (description.length() > 0)
description = description.substring(0, description.length() - 2);
shippingPackage.setDescription(description);
packages.add(shippingPackage);
packageItems.clear();
TotalPackageWeight = BigDecimal.ZERO;
TotalPackageWeight = TotalPackageWeight.add(itemWeight);
BigDecimal packageQty = packageItems.get(product);
if (packageQty == null)
packageQty = BigDecimal.ZERO;
packageItems.put(product, packageQty.add(qty));
}
else
{
TotalPackageWeight = TotalPackageWeight.add(itemWeight);
BigDecimal packageQty = packageItems.get(product);
if (packageQty == null)
packageQty = BigDecimal.ZERO;
packageItems.put(product, packageQty.add(qty));
}
}
if (TotalPackageWeight.compareTo(BigDecimal.ZERO) > 0) if (TotalPackageWeight.compareTo(BigDecimal.ZERO) > 0)
{ {
ShippingPackage shippingPackage = new ShippingPackage(); ShippingPackage shippingPackage = new ShippingPackage();
shippingPackage.setWeight(TotalPackageWeight); shippingPackage.setWeight(TotalPackageWeight);
shippingPackage.setProducts(products);
String description = "";
Enumeration<MProduct> en = packageItems.keys();
while (en.hasMoreElements())
{
MProduct packageProduct = en.nextElement();
BigDecimal packageQty = packageItems.get(packageProduct);
description += df.format(packageQty) + " x " + packageProduct.getValue() + ", ";
}
if (description.length() > 0)
description = description.substring(0, description.length() - 2);
shippingPackage.setDescription(description);
packages.add(shippingPackage); packages.add(shippingPackage);
} }
@ -398,7 +465,7 @@ public class SalesOrderRateInquiryProcess extends SvrProcess
stl.setAD_Org_ID(m_order.getAD_Org_ID()); stl.setAD_Org_ID(m_order.getAD_Org_ID());
stl.setC_UOM_Length_ID(ci.getC_UOM_Length_ID()); stl.setC_UOM_Length_ID(ci.getC_UOM_Length_ID());
stl.setC_UOM_Weight_ID(ci.getC_UOM_Weight_ID()); stl.setC_UOM_Weight_ID(ci.getC_UOM_Weight_ID());
// stl.setDescription(getDescription()); stl.setDescription(shippingPackage.getDescription());
stl.setHeight(shippingPackage.getHeight()); stl.setHeight(shippingPackage.getHeight());
stl.setIsActive(m_order.isActive()); stl.setIsActive(m_order.isActive());
stl.setLength(shippingPackage.getLength()); stl.setLength(shippingPackage.getLength());