594 lines
27 KiB
Java
594 lines
27 KiB
Java
package andromedia.midsuit.form;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.Timestamp;
|
|
import java.util.ArrayList;
|
|
import java.util.Vector;
|
|
import java.util.logging.Level;
|
|
|
|
import org.adempiere.exceptions.AdempiereException;
|
|
import org.compiere.apps.IStatusBar;
|
|
import org.compiere.grid.CreateFrom;
|
|
import org.compiere.minigrid.IMiniTable;
|
|
import org.compiere.model.GridTab;
|
|
import org.compiere.model.MInvoiceLine;
|
|
import org.compiere.model.MOrder;
|
|
import org.compiere.model.MOrderLine;
|
|
import org.compiere.model.MOrg;
|
|
import org.compiere.model.MPriceList;
|
|
import org.compiere.model.MProductPricing;
|
|
import org.compiere.model.MRequisition;
|
|
import org.compiere.model.MRequisitionLine;
|
|
import org.compiere.model.MTax;
|
|
import org.compiere.model.MUOMConversion;
|
|
import org.compiere.model.Query;
|
|
import org.compiere.process.DocAction;
|
|
import org.compiere.util.DB;
|
|
import org.compiere.util.Env;
|
|
import org.compiere.util.KeyNamePair;
|
|
import org.compiere.util.Msg;
|
|
|
|
import andromedia.midsuit.model.MID_MRequisitionTrxLine;
|
|
|
|
public class MID_CreateFromOrder extends CreateFrom {
|
|
/*
|
|
* create by yonk
|
|
*
|
|
*/
|
|
|
|
public String desc = "";
|
|
MOrg org = new MOrg(Env.getCtx(), Env.getAD_Org_ID(Env.getCtx()), null);
|
|
|
|
public MID_CreateFromOrder(GridTab mTab) {
|
|
super(mTab);
|
|
if (log.isLoggable(Level.INFO)) log.info(mTab.toString());
|
|
}
|
|
|
|
@Override
|
|
public Object getWindow() {
|
|
return null;
|
|
}
|
|
|
|
protected Vector<String> getOISColumnNames()
|
|
{
|
|
// Header Info
|
|
Vector<String> columnNames = new Vector<String>(7);
|
|
columnNames.add(Msg.getMsg(Env.getCtx(), "Select"));
|
|
columnNames.add("Line");
|
|
columnNames.add(Msg.translate(Env.getCtx(), "M_Product_ID"));
|
|
columnNames.add(Msg.translate(Env.getCtx(), "C_Charge_ID"));
|
|
columnNames.add(Msg.translate(Env.getCtx(), "Quantity"));
|
|
columnNames.add(Msg.translate(Env.getCtx(), "DateRequired"));
|
|
columnNames.add(Msg.translate(Env.getCtx(), "C_UOM_ID"));
|
|
columnNames.add(Msg.translate(Env.getCtx(), "SisaPO"));
|
|
return columnNames;
|
|
}
|
|
|
|
@Override
|
|
public boolean dynInit() throws Exception {
|
|
log.config("");
|
|
setTitle(Msg.getElement(Env.getCtx(), "C_Order_ID", false) + " .. " + Msg.translate(Env.getCtx(), "CreateFrom"));
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void info(IMiniTable miniTable, IStatusBar statusBar) {
|
|
|
|
}
|
|
|
|
protected Vector<Vector<Object>> getRequisitionData(int M_Requisition_ID, int M_Product_ID, Timestamp dateRequired, int C_Charge_ID, int salesRepID, boolean IsSOTrx)
|
|
{
|
|
//int C_Order_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "C_Order_ID");
|
|
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
|
|
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "C_Order_ID");
|
|
/**
|
|
* 1 M_RequisitionLine_ID
|
|
* 2 Line
|
|
* 3 Product Name
|
|
* 4 Qty Entered
|
|
*/
|
|
String isSOTrxParam = isSOTrx ? "Y":"N";
|
|
StringBuilder sqlStmt = new StringBuilder();
|
|
sqlStmt.append("SELECT rl.M_RequisitionLine_ID, rl.Line, "); //1..2
|
|
sqlStmt.append("CASE WHEN rl.M_Product_ID IS NOT NULL THEN (SELECT p.Value||'-'||p.Name FROM M_Product p WHERE p.M_Product_ID = rl.M_Product_ID) END as ProductName, "); //3
|
|
sqlStmt.append("rl.qty as Qty, mr.DateRequired, "); //4..5
|
|
sqlStmt.append("CASE WHEN rl.C_UOM_ID IS NOT NULL THEN (SELECT u.Name FROM C_UOM u WHERE u.C_UOM_ID = rl.C_UOM_ID) END AS uomName, "); //7
|
|
sqlStmt.append("CASE WHEN rl.C_Charge_ID IS NOT NULL THEN (SELECT c.Name FROM C_Charge c WHERE c.C_Charge_ID = rl.C_Charge_ID) END as ChargeName, ");
|
|
sqlStmt.append("COALESCE(rl.qty - COALESCE(ol.QtyOrdered,0), 0) as sisapo ");
|
|
sqlStmt.append("FROM M_RequisitionLine rl ");
|
|
sqlStmt.append("INNER JOIN M_Requisition mr ON mr.M_Requisition_ID=rl.M_Requisition_ID ");
|
|
sqlStmt.append(" LEFT JOIN (SELECT M_RequisitionLine_ID, COALESCE(SUM(QtyOrdered),0) as QtyOrdered FROM C_OrderLine");
|
|
sqlStmt.append(" GROUP BY M_RequisitionLine_ID) ol ON (ol.M_RequisitionLine_ID=rl.M_RequisitionLine_ID)");
|
|
sqlStmt.append(" WHERE rl.AD_Client_ID=? AND mr.DocStatus=? and mr.IsSOTrx=? ");
|
|
sqlStmt.append(" AND (rl.qty > ol.QtyOrdered OR COALESCE(rl.qty - COALESCE(ol.QtyOrdered,0), 0) > 0)");
|
|
|
|
if (M_Requisition_ID > 0) {
|
|
sqlStmt.append("AND rl.M_Requisition_ID=? ");
|
|
MRequisition req = new MRequisition(Env.getCtx(), M_Requisition_ID, null);
|
|
desc = req.getDescription();
|
|
}
|
|
|
|
if (M_Product_ID > 0) {
|
|
sqlStmt.append("AND rl.M_Product_ID=? ");
|
|
}
|
|
|
|
if (dateRequired != null) {
|
|
sqlStmt.append("AND mr.DateRequired=? ");
|
|
}
|
|
|
|
if (C_Charge_ID > 0) {
|
|
sqlStmt.append("AND rl.C_Charge_ID=? ");
|
|
}
|
|
|
|
sqlStmt.append(" ORDER BY rl.line");
|
|
|
|
try
|
|
{
|
|
int count = 1;
|
|
PreparedStatement pstmt = DB.prepareStatement(sqlStmt.toString(), null);
|
|
pstmt.setInt(count, Env.getAD_Client_ID(Env.getCtx())); count++;
|
|
pstmt.setString(count, DocAction.STATUS_Completed); count++;
|
|
pstmt.setString(count, isSOTrxParam);
|
|
if (M_Requisition_ID > 0) {
|
|
count++;
|
|
pstmt.setInt(count, M_Requisition_ID);
|
|
}
|
|
|
|
if (M_Product_ID > 0) {
|
|
count++;
|
|
pstmt.setInt(count, M_Product_ID);
|
|
}
|
|
|
|
if (dateRequired != null) {
|
|
count++;
|
|
pstmt.setTimestamp(count, dateRequired);
|
|
}
|
|
|
|
if (C_Charge_ID > 0) {
|
|
count++;
|
|
pstmt.setInt(count, C_Charge_ID);
|
|
}
|
|
|
|
ResultSet rs = pstmt.executeQuery();
|
|
while (rs.next())
|
|
{
|
|
if(rs.getBigDecimal(8).signum()<=0)
|
|
continue;
|
|
|
|
Vector<Object> line = new Vector<Object>(7);
|
|
line.add(new Boolean(false)); // 0-Selection
|
|
|
|
KeyNamePair lineKNPair = new KeyNamePair(rs.getInt(1), rs.getString(2)); // 1-Line
|
|
line.add(lineKNPair);
|
|
line.add(rs.getString(3)); //2-Product
|
|
line.add(rs.getString(7)); //3-Charge
|
|
BigDecimal qty = rs.getBigDecimal(4);
|
|
line.add((BigDecimal)rs.getBigDecimal(8)); // 4 - Qty
|
|
Timestamp p_dateRequired = rs.getTimestamp(5);
|
|
line.add(p_dateRequired); //5 - DateRequired
|
|
line.add(rs.getString(6)); // 7 - UOM
|
|
line.add((BigDecimal)rs.getBigDecimal(8)); //9 - SisaPO
|
|
data.add(line);
|
|
}
|
|
rs.close();
|
|
pstmt.close();
|
|
}
|
|
catch (SQLException e)
|
|
{
|
|
log.log(Level.SEVERE, sqlStmt.toString(), e);
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
protected ArrayList<KeyNamePair> loadRequisitionSOData (int C_BPartner_ID, int M_Warehouse_ID)
|
|
{
|
|
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "C_Order_ID");
|
|
MOrder order = new MOrder(Env.getCtx(), C_Order_ID, null);
|
|
|
|
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
|
|
int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "AD_Client_ID");
|
|
|
|
// Display
|
|
StringBuilder display = new StringBuilder("r.DocumentNo");
|
|
//.append(DB.TO_CHAR("r.TotaLines", DisplayType.Amount, Env.getAD_Language(Env.getCtx())));
|
|
|
|
// Add By animfalahuddin
|
|
StringBuilder project = new StringBuilder(" AND true");
|
|
|
|
if(order.getC_Project_ID() > 0 && org.get_ValueAsBoolean("IsProjectBased")) {
|
|
project = new StringBuilder(" AND r.C_Project_ID = " + order.getC_Project_ID());
|
|
} else if (org.get_ValueAsBoolean("IsProjectBased")) {
|
|
project = new StringBuilder(" AND r.C_Project_ID is null");
|
|
}
|
|
|
|
StringBuilder sql = new StringBuilder("SELECT DISTINCT r.MID_Requisition_ID,").append(display)
|
|
.append(" FROM MID_Requisition r ")
|
|
.append(" LEFT JOIN MID_RequisitionLine rl ON (rl.MID_Requisition_ID=r.MID_Requisition_ID)")
|
|
.append(" LEFT JOIN (SELECT MID_RequisitionLine_ID, SUM(QtyOrdered) as QtyOrdered FROM C_OrderLine")
|
|
.append(" GROUP BY MID_RequisitionLine_ID) ol ON (ol.MID_RequisitionLine_ID=rl.MID_RequisitionLine_ID)")
|
|
.append(" WHERE EXISTS (SELECT 1 FROM MID_RequisitionLine l WHERE r.MID_Requisition_ID=l.MID_Requisition_ID")
|
|
//.append(" AND l.AD_Client_ID=? AND r.DocStatus=?) AND r.C_BPartner_ID =?");
|
|
.append(" AND l.AD_Client_ID=? AND r.DocStatus='CO') ")
|
|
.append(" AND (rl.qty > ol.QtyOrdered OR COALESCE(rl.qty - COALESCE(ol.QtyOrdered,0), 0) > 0)")
|
|
.append(project)
|
|
.append(" GROUP BY r.MID_Requisition_ID");
|
|
|
|
sql = sql.append(" ORDER BY r.DocumentNo DESC");
|
|
|
|
PreparedStatement pstmt = null;
|
|
ResultSet rs = null;
|
|
try
|
|
{
|
|
int count = 0;
|
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
|
pstmt.setInt(++count, AD_Client_ID);
|
|
// pstmt.setString(++count, DocAction.STATUS_Completed);
|
|
// pstmt.setInt(++count, M_Warehouse_ID);
|
|
//pstmt.setInt(++count, C_BPartner_ID);
|
|
rs = pstmt.executeQuery();
|
|
while (rs.next())
|
|
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
|
|
}
|
|
catch (SQLException e)
|
|
{
|
|
log.log(Level.SEVERE, sql.toString(), e);
|
|
}
|
|
finally
|
|
{
|
|
DB.close(rs, pstmt);
|
|
rs = null; pstmt = null;
|
|
}
|
|
|
|
return list;
|
|
} // initBPartnerOIS
|
|
|
|
protected ArrayList<KeyNamePair> loadRequisitionData (int C_BPartner_ID, int M_Warehouse_ID)
|
|
{
|
|
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "C_Order_ID");
|
|
MOrder order = new MOrder(Env.getCtx(), C_Order_ID, null);
|
|
|
|
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
|
|
int AD_Client_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "AD_Client_ID");
|
|
|
|
// Display
|
|
StringBuilder display = new StringBuilder("r.DocumentNo");
|
|
//.append(DB.TO_CHAR("r.TotaLines", DisplayType.Amount, Env.getAD_Language(Env.getCtx())));
|
|
|
|
// Add By @animfalahuddin
|
|
StringBuilder project = new StringBuilder(" AND true");
|
|
|
|
if(order.getC_Project_ID() > 0 && org.get_ValueAsBoolean("IsProjectBased")) {
|
|
project = new StringBuilder(" AND r.C_Project_ID = " + order.getC_Project_ID());
|
|
} else if (org.get_ValueAsBoolean("IsProjectBased")) {
|
|
project = new StringBuilder(" AND r.C_Project_ID is null");
|
|
}
|
|
String isSOTrxParam = isSOTrx ? "Y":"N";
|
|
StringBuilder sql = new StringBuilder("SELECT DISTINCT r.M_Requisition_ID,").append(display)
|
|
.append(" FROM M_Requisition r ")
|
|
.append(" LEFT JOIN M_RequisitionLine rl ON (rl.M_Requisition_ID=r.M_Requisition_ID)")
|
|
.append(" LEFT JOIN (SELECT M_RequisitionLine_ID, SUM(QtyOrdered) as QtyOrdered FROM C_OrderLine")
|
|
.append(" GROUP BY M_RequisitionLine_ID) ol ON (ol.M_RequisitionLine_ID=rl.M_RequisitionLine_ID)")
|
|
.append(" WHERE EXISTS (SELECT 1 FROM M_RequisitionLine l WHERE r.M_Requisition_ID=l.M_Requisition_ID")
|
|
//.append(" AND l.AD_Client_ID=? AND r.DocStatus=?) AND r.C_BPartner_ID =?");
|
|
.append(" AND l.AD_Client_ID=? AND r.DocStatus='CO') AND r.M_Warehouse_ID =? AND r.IsSOTrx=?")
|
|
.append(" AND (rl.qty > ol.QtyOrdered OR COALESCE(rl.qty - COALESCE(ol.QtyOrdered,0), 0) > 0)")
|
|
.append(project)
|
|
.append(" GROUP BY r.M_Requisition_ID");
|
|
|
|
sql = sql.append(" ORDER BY r.DocumentNo DESC");
|
|
log.severe(isSOTrxParam);
|
|
PreparedStatement pstmt = null;
|
|
ResultSet rs = null;
|
|
|
|
try
|
|
{
|
|
int count = 0;
|
|
pstmt = DB.prepareStatement(sql.toString(), null);
|
|
pstmt.setInt(++count, AD_Client_ID);
|
|
// pstmt.setString(++count, DocAction.STATUS_Completed);
|
|
pstmt.setInt(++count, M_Warehouse_ID);
|
|
pstmt.setString(++count, isSOTrxParam);
|
|
rs = pstmt.executeQuery();
|
|
while (rs.next())
|
|
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
|
|
}
|
|
catch (SQLException e)
|
|
{
|
|
log.log(Level.SEVERE, sql.toString(), e);
|
|
}
|
|
finally
|
|
{
|
|
DB.close(rs, pstmt);
|
|
rs = null; pstmt = null;
|
|
}
|
|
|
|
return list;
|
|
} // initBPartnerOIS
|
|
|
|
|
|
protected void configureMiniTable (IMiniTable miniTable)
|
|
{
|
|
miniTable.setColumnClass(0, Boolean.class, false); // 0-Selection
|
|
miniTable.setColumnClass(1, String.class, true); // 1-Line
|
|
miniTable.setColumnClass(2, String.class, true); // 2-Product
|
|
miniTable.setColumnClass(3, String.class, true); // 3-Charge
|
|
miniTable.setColumnClass(4, BigDecimal.class, false); // 4-Qty
|
|
miniTable.setColumnClass(5, Timestamp.class, true); // 5-DateRequired
|
|
miniTable.setColumnClass(6, String.class, true); // 7-UOM
|
|
//miniTable.setColumnClass(8, BigDecimal.class, true); // 8-QtyRequired
|
|
miniTable.setColumnClass(8, BigDecimal.class, false); // 9-SisaPO
|
|
|
|
|
|
// Table UI
|
|
miniTable.autoSize();
|
|
}
|
|
|
|
@Override
|
|
public boolean save(IMiniTable miniTable, String trxName) {
|
|
log.config("");
|
|
String desc = "";
|
|
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), getGridTab().getWindowNo(), "C_Order_ID");
|
|
MOrder order = new MOrder(Env.getCtx(), C_Order_ID, null);
|
|
|
|
|
|
//Add by @solrizal Line Number
|
|
for (int i = 0; i < miniTable.getRowCount(); i++)
|
|
{
|
|
if (((Boolean)miniTable.getValueAt(i, 0)).booleanValue())
|
|
{
|
|
MOrderLine orderLine = new MOrderLine(order);
|
|
BigDecimal qty = (BigDecimal)miniTable.getValueAt(i, 4); // 4 - Qty
|
|
BigDecimal sisapo = (BigDecimal)miniTable.getValueAt(i, 7); // 9 - SisaPO
|
|
BigDecimal qtyOrdered = qty;
|
|
// BigDecimal qtyOrdered = sisapo;
|
|
KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 1); // 1-Line
|
|
if(!isSOTrx || isSOTrx){
|
|
|
|
int requisitionLineID = pp.getKey();
|
|
MRequisitionLine reqLine = new MRequisitionLine(Env.getCtx(), requisitionLineID, null);
|
|
|
|
StringBuilder sql = new StringBuilder();
|
|
|
|
if (reqLine.getC_UOM_ID()>0 && reqLine.getM_Product_ID() > 0) {
|
|
if(reqLine.getC_UOM_ID()!=reqLine.getM_Product().getC_UOM_ID())
|
|
// qtyOrdered = MUOMConversion.convertProductTo (Env.getCtx(), reqLine.getM_Product_ID(), reqLine.getC_UOM_ID(), qty);
|
|
qtyOrdered = MUOMConversion.convertProductFrom(Env.getCtx(), reqLine.getM_Product_ID(), reqLine.getC_UOM_ID(), qty);
|
|
if (qtyOrdered == null)
|
|
qtyOrdered = Env.ZERO;
|
|
}
|
|
|
|
BigDecimal Qty = reqLine.getQty();
|
|
boolean IsSOTrx = order.isSOTrx();
|
|
MProductPricing pricing = new MProductPricing (reqLine.getM_Product_ID(), order.getC_BPartner_ID(), Qty, IsSOTrx);
|
|
|
|
int M_PriceList_ID = order.getM_PriceList_ID();
|
|
pricing.setM_PriceList_ID(M_PriceList_ID);
|
|
|
|
String sqlString = "SELECT plv.M_PriceList_Version_ID "
|
|
+ "FROM M_PriceList_Version plv "
|
|
+ "WHERE plv.M_PriceList_ID=? " // 1
|
|
+ " AND plv.ValidFrom <= ? "
|
|
+ "ORDER BY plv.ValidFrom DESC";
|
|
// Use newest price list - may not be future
|
|
|
|
int M_PriceList_Version_ID = DB.getSQLValueEx(null, sqlString,order.getM_PriceList_ID(), order.getDateOrdered());
|
|
|
|
pricing.setM_PriceList_Version_ID(M_PriceList_Version_ID);
|
|
pricing.setPriceDate(order.getDateOrdered());
|
|
|
|
orderLine.setPriceEntered(pricing.getPriceStd().subtract(pricing.getPriceStd().multiply(orderLine.getDiscount())));
|
|
orderLine.setPriceActual(pricing.getPriceStd());
|
|
orderLine.setPriceList(pricing.getPriceList());
|
|
orderLine.setPriceLimit(pricing.getPriceLimit());
|
|
|
|
|
|
|
|
//@Hodianto Change Default Price List
|
|
MPriceList priceList = new MPriceList(Env.getCtx(), M_PriceList_ID, null);
|
|
if(priceList.get_ValueAsBoolean("isLastPriceUsed")){
|
|
int invoiceLineID = new Query(Env.getCtx(), MInvoiceLine.Table_Name, "C_InvoiceLine.M_Product_ID =?", null)
|
|
.addJoinClause("JOIN C_Invoice i ON i.C_Invoice_ID = C_InvoiceLine.C_Invoice_ID ")
|
|
.setParameters(new Object[]{reqLine.getM_Product_ID() })
|
|
.setOrderBy("i.DateInvoiced DESC")
|
|
.setOnlyActiveRecords(true)
|
|
.firstId();
|
|
|
|
if(invoiceLineID>0){
|
|
MInvoiceLine invoiceLine = new MInvoiceLine(Env.getCtx(),invoiceLineID,null);
|
|
orderLine.setPriceEntered(invoiceLine.getPriceEntered());
|
|
orderLine.setPriceActual(invoiceLine.getPriceEntered());
|
|
orderLine.setPriceList(invoiceLine.getPriceEntered());
|
|
orderLine.setPriceLimit(invoiceLine.getPriceEntered());
|
|
}
|
|
}
|
|
orderLine.setLineNetAmt();
|
|
|
|
if(orderLine.getC_Tax_ID()>0){
|
|
MTax tax = (MTax) orderLine.getC_Tax();
|
|
orderLine.set_ValueNoCheck("TotalLines", orderLine.getLineNetAmt()
|
|
.add(orderLine.getLineNetAmt().multiply(tax.getRate()).divide(Env.ONEHUNDRED)));
|
|
}else{
|
|
orderLine.set_ValueNoCheck("TotalLines",orderLine.getLineNetAmt());
|
|
}
|
|
|
|
if(reqLine.getC_Charge_ID()>0)
|
|
orderLine.setC_Charge_ID(reqLine.getC_Charge_ID());
|
|
else
|
|
orderLine.setM_Product_ID(reqLine.getM_Product_ID());
|
|
|
|
if(reqLine.getC_BPartner_ID()>0)
|
|
orderLine.set_ValueOfColumn("C_BPartner_Requisition_ID",reqLine.getC_BPartner_ID());
|
|
|
|
if(reqLine.getC_Charge_ID()>0)
|
|
orderLine.setC_Charge_ID(reqLine.getC_Charge_ID());
|
|
else
|
|
orderLine.setM_Product_ID(reqLine.getM_Product_ID());
|
|
|
|
int a = reqLine.getC_UOM_ID();
|
|
orderLine.setC_UOM_ID(reqLine.getC_UOM_ID());
|
|
// orderLine.setQtyEntered(qty);
|
|
orderLine.setQtyEntered(Qty);
|
|
//orderLine.setC_Tax_ID(order.getC_Tax_ID());
|
|
orderLine.setQtyOrdered(qtyOrdered);
|
|
// orderLine.setLine(reqLine.getLine());
|
|
orderLine.setPriceEntered(reqLine.getPriceActual());
|
|
orderLine.setDiscount(Env.ZERO);
|
|
|
|
//Add by @solrizal increment LIne Number by 10
|
|
orderLine.set_ValueOfColumn("PriceRequisition", reqLine.getPriceActual());
|
|
|
|
orderLine.set_ValueOfColumn("DiscAmt", Env.ZERO);
|
|
orderLine.set_ValueOfColumn("M_Requisition_ID", reqLine.getM_Requisition_ID());
|
|
orderLine.set_ValueOfColumn("M_RequisitionLine_ID", reqLine.get_ID());
|
|
|
|
orderLine.set_ValueOfColumn("IsTrackAsAsset", reqLine.get_ValueAsBoolean("IsTrackAsAsset"));
|
|
|
|
orderLine.setDescription(reqLine.getDescription()==null? "" : reqLine.getDescription());
|
|
orderLine.set_ValueNoCheck("Comments", reqLine.get_Value("Comments"));
|
|
// orderLine.set_ValueOfColumn("Comments", reqLine.get_Value("Comments"));
|
|
|
|
// Add By @animfalahuddin
|
|
if(org.get_ValueAsBoolean("IsProjectBased")) {
|
|
orderLine.set_ValueNoCheck("Construction_C_Order_ID", reqLine.get_Value("Construction_C_Order_ID") != null ? reqLine.get_ValueAsInt("Construction_C_Order_ID") : null);
|
|
orderLine.set_ValueNoCheck("SAP_ExpenseCode_ID", reqLine.get_Value("SAP_ExpenseCode_ID") != null ? reqLine.get_ValueAsInt("SAP_ExpenseCode_ID") : null);
|
|
orderLine.set_ValueNoCheck("C_Project_ID", reqLine.get_Value("C_Project_ID") != null ? reqLine.get_ValueAsInt("C_Project_ID") : null);
|
|
orderLine.set_ValueNoCheck("C_ProjectPhase_ID", reqLine.get_Value("C_ProjectPhase_ID") != null ? reqLine.get_ValueAsInt("C_ProjectPhase_ID") : null);
|
|
}
|
|
|
|
if(!orderLine.save()){
|
|
// String sqlDelete = "DELETE FROM C_OrderLine WHERE C_Order_ID=?";
|
|
// int line = DB.executeUpdate(sqlDelete, order.getC_Order_ID(), null);
|
|
throw new AdempiereException("Cannot create order line for product "+reqLine.getM_Product().getName());
|
|
}
|
|
orderLine.saveEx();
|
|
if(reqLine.getM_Requisition().getDescription()==null || reqLine.getM_Requisition().getDescription().equals("null"))
|
|
desc = desc + "";
|
|
else
|
|
desc = desc + reqLine.getM_Requisition().getDescription() +"; ";
|
|
|
|
|
|
MRequisition req = (MRequisition) reqLine.getM_Requisition();
|
|
if(req.get_ValueAsInt("C_BPartner_ID")>0)
|
|
order.setC_BPartner_ID(req.get_ValueAsInt("C_BPartner_ID"));
|
|
}
|
|
// } else {
|
|
// //Is SO Trx = Y
|
|
// int requisitionLineID = pp.getKey();
|
|
// MID_MRequisitionTrxLine reqLine = new MID_MRequisitionTrxLine(Env.getCtx(), requisitionLineID, null);
|
|
//
|
|
// StringBuilder sql = new StringBuilder();
|
|
//
|
|
// if (reqLine.getC_UOM_ID()>0 && reqLine.getM_Product_ID() > 0) {
|
|
// if(reqLine.getC_UOM_ID()!=reqLine.getM_Product().getC_UOM_ID())
|
|
//// qtyOrdered = MUOMConversion.convertProductTo (Env.getCtx(), reqLine.getM_Product_ID(), reqLine.getC_UOM_ID(), qty);
|
|
// qtyOrdered = MUOMConversion.convertProductTo(Env.getCtx(), reqLine.getM_Product_ID(), reqLine.getC_UOM_ID(), qty);
|
|
// if (qtyOrdered == null)
|
|
// qtyOrdered = Env.ZERO;
|
|
// }
|
|
//
|
|
// BigDecimal Qty = reqLine.getQty();
|
|
// boolean IsSOTrx = order.isSOTrx();
|
|
// MProductPricing pricing = new MProductPricing (reqLine.getM_Product_ID(), order.getC_BPartner_ID(), Qty, IsSOTrx);
|
|
//
|
|
// int M_PriceList_ID = order.getM_PriceList_ID();
|
|
// pricing.setM_PriceList_ID(M_PriceList_ID);
|
|
//
|
|
// String sqlString = "SELECT plv.M_PriceList_Version_ID "
|
|
// + "FROM M_PriceList_Version plv "
|
|
// + "WHERE plv.M_PriceList_ID=? " // 1
|
|
// + " AND plv.ValidFrom <= ? "
|
|
// + "ORDER BY plv.ValidFrom DESC";
|
|
// // Use newest price list - may not be future
|
|
//
|
|
// int M_PriceList_Version_ID = DB.getSQLValueEx(null, sqlString,order.getM_PriceList_ID(), order.getDateOrdered());
|
|
//
|
|
// pricing.setM_PriceList_Version_ID(M_PriceList_Version_ID);
|
|
// pricing.setPriceDate(order.getDateOrdered());
|
|
//
|
|
//// orderLine.setPriceEntered(pricing.getPriceStd().subtract(pricing.getPriceStd().multiply(orderLine.getDiscount())));
|
|
//// orderLine.setPriceActual(pricing.getPriceStd());
|
|
//// orderLine.setPriceList(pricing.getPriceList());
|
|
//// orderLine.setPriceLimit(pricing.getPriceLimit());
|
|
// orderLine.setPrice(reqLine.getPriceActual());
|
|
// //@Hodianto Change Default Price List
|
|
// MPriceList priceList = new MPriceList(Env.getCtx(), M_PriceList_ID, null);
|
|
// if(priceList.get_ValueAsBoolean("isLastPriceUsed")){
|
|
// int invoiceLineID = new Query(Env.getCtx(), MInvoiceLine.Table_Name, "C_InvoiceLine.M_Product_ID =?", null)
|
|
// .addJoinClause("JOIN C_Invoice i ON i.C_Invoice_ID = C_InvoiceLine.C_Invoice_ID ")
|
|
// .setParameters(new Object[]{reqLine.getM_Product_ID() })
|
|
// .setOrderBy("i.DateInvoiced DESC")
|
|
// .setOnlyActiveRecords(true)
|
|
// .firstId();
|
|
//
|
|
// if(invoiceLineID>0){
|
|
// MInvoiceLine invoiceLine = new MInvoiceLine(Env.getCtx(),invoiceLineID,null);
|
|
// orderLine.setPriceEntered(invoiceLine.getPriceEntered());
|
|
// orderLine.setPriceActual(invoiceLine.getPriceEntered());
|
|
// orderLine.setPriceList(invoiceLine.getPriceEntered());
|
|
// orderLine.setPriceLimit(invoiceLine.getPriceEntered());
|
|
// }
|
|
// }
|
|
// orderLine.setLineNetAmt();
|
|
//
|
|
// if(orderLine.getC_Tax_ID()>0){
|
|
// MTax tax = (MTax) orderLine.getC_Tax();
|
|
// orderLine.set_ValueNoCheck("TotalLines", orderLine.getLineNetAmt()
|
|
// .add(orderLine.getLineNetAmt().multiply(tax.getRate()).divide(Env.ONEHUNDRED)));
|
|
// }else{
|
|
// orderLine.set_ValueNoCheck("TotalLines",orderLine.getLineNetAmt());
|
|
// }
|
|
//
|
|
// if(reqLine.getC_Charge_ID()>0)
|
|
// orderLine.setC_Charge_ID(reqLine.getC_Charge_ID());
|
|
// else
|
|
// orderLine.setM_Product_ID(reqLine.getM_Product_ID());
|
|
//
|
|
// if(reqLine.getC_BPartner_ID()>0)
|
|
// orderLine.set_ValueOfColumn("C_BPartner_Requisition_ID",reqLine.getC_BPartner_ID());
|
|
//
|
|
// if(reqLine.getC_Charge_ID()>0)
|
|
// orderLine.setC_Charge_ID(reqLine.getC_Charge_ID());
|
|
// else
|
|
// orderLine.setM_Product_ID(reqLine.getM_Product_ID());
|
|
//
|
|
// int a = reqLine.getC_UOM_ID();
|
|
// orderLine.setC_UOM_ID(reqLine.getC_UOM_ID());
|
|
//// orderLine.setQtyEntered(qty);
|
|
// orderLine.setQtyEntered(qtyOrdered);
|
|
// //orderLine.setC_Tax_ID(order.getC_Tax_ID());
|
|
// orderLine.setQtyOrdered(qtyOrdered);
|
|
//// orderLine.setLine(reqLine.getLine());
|
|
//
|
|
// //Add by @solrizal increment LIne Number by 10
|
|
// orderLine.set_ValueOfColumn("PriceRequisition", reqLine.getPriceActual());
|
|
//
|
|
// orderLine.set_ValueOfColumn("DiscAmt", Env.ZERO);
|
|
// orderLine.set_ValueOfColumn("MID_Requisition_ID", reqLine.getMID_Requisition_ID());
|
|
// orderLine.set_ValueOfColumn("MID_RequisitionLine_ID", reqLine.getMID_RequisitionLine_ID());
|
|
//
|
|
// orderLine.set_ValueOfColumn("IsTrackAsAsset", reqLine.get_ValueAsBoolean("IsTrackAsAsset"));
|
|
//
|
|
// orderLine.setDescription(reqLine.getDescription()==null? "" : reqLine.getDescription());
|
|
// orderLine.set_ValueNoCheck("Comments", reqLine.get_Value("Comments"));
|
|
//// orderLine.set_ValueOfColumn("Comments", reqLine.get_Value("Comments"));
|
|
//
|
|
// if(!orderLine.save()){
|
|
//// String sqlDelete = "DELETE FROM C_OrderLine WHERE C_Order_ID=?";
|
|
//// int line = DB.executeUpdate(sqlDelete, order.getC_Order_ID(), null);
|
|
// throw new AdempiereException("Cannot create order line for product "+reqLine.getM_Product().getName());
|
|
// }
|
|
// orderLine.saveEx();
|
|
// }
|
|
}
|
|
}
|
|
// order.setDescription(order.getDescription()==null? desc : order.getDescription()+";"+desc);
|
|
order.saveEx();
|
|
return true;
|
|
}
|
|
|
|
}
|