|
|
|
|
@ -266,7 +266,7 @@ public class MID_CreateFromOrder extends CreateFrom {
|
|
|
|
|
} 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)")
|
|
|
|
|
@ -274,13 +274,13 @@ public class MID_CreateFromOrder extends CreateFrom {
|
|
|
|
|
.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 =?")
|
|
|
|
|
.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;
|
|
|
|
|
|
|
|
|
|
@ -291,7 +291,7 @@ public class MID_CreateFromOrder extends CreateFrom {
|
|
|
|
|
pstmt.setInt(++count, AD_Client_ID);
|
|
|
|
|
// pstmt.setString(++count, DocAction.STATUS_Completed);
|
|
|
|
|
pstmt.setInt(++count, M_Warehouse_ID);
|
|
|
|
|
//pstmt.setInt(++count, C_BPartner_ID);
|
|
|
|
|
pstmt.setString(++count, isSOTrxParam);
|
|
|
|
|
rs = pstmt.executeQuery();
|
|
|
|
|
while (rs.next())
|
|
|
|
|
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
|
|
|
|
|
@ -346,7 +346,7 @@ public class MID_CreateFromOrder extends CreateFrom {
|
|
|
|
|
BigDecimal qtyOrdered = qty;
|
|
|
|
|
// BigDecimal qtyOrdered = sisapo;
|
|
|
|
|
KeyNamePair pp = (KeyNamePair)miniTable.getValueAt(i, 1); // 1-Line
|
|
|
|
|
if(!isSOTrx){
|
|
|
|
|
if(!isSOTrx || isSOTrx){
|
|
|
|
|
|
|
|
|
|
int requisitionLineID = pp.getKey();
|
|
|
|
|
MRequisitionLine reqLine = new MRequisitionLine(Env.getCtx(), requisitionLineID, null);
|
|
|
|
|
@ -470,114 +470,115 @@ public class MID_CreateFromOrder extends CreateFrom {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// } 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);
|
|
|
|
|
|