--HG--
branch : EDII
This commit is contained in:
hodianto 2018-11-21 07:58:42 +07:00
parent 8c37381e56
commit a6fb38f51d
6 changed files with 136 additions and 124 deletions

View File

@ -4,6 +4,7 @@ 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;
@ -603,7 +604,9 @@ public abstract class MID_CreateFromInvoice extends CreateFrom {
invoice.validatePaySchedule();
invoice.saveEx();
}
invoice.set_ValueOfColumn("RegisterDate", (Timestamp) p_order.get_Value("RegisterDate") == null ? null : (Timestamp)p_order.get_Value("RegisterDate"));
invoice.set_ValueOfColumn("RegisterNo", p_order.get_ValueAsString("RegisterNo") == null ? null : p_order.get_ValueAsString("RegisterNo"));
invoice.set_ValueOfColumn("MID_AJUDocumentType_ID", p_order.get_ValueAsInt("MID_AJUDocumentType_ID"));
invoice.set_ValueOfColumn("noaju1", p_order.get_ValueAsString("noaju1") == null ? null : p_order.get_ValueAsString("noaju1"));
invoice.set_ValueOfColumn("noaju2", p_order.get_ValueAsString("noaju2") == null ? null : p_order.get_ValueAsString("noaju2"));
invoice.set_ValueOfColumn("noaju3", p_order.get_ValueAsString("noaju3") == null ? null : p_order.get_ValueAsString("noaju3"));

View File

@ -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);

View File

@ -317,15 +317,9 @@ public class MID_WCreateFromOrder extends MID_CreateFromOrder implements EventLi
int C_Order_ID = Env.getContextAsInt(Env.getCtx(), p_WindowNo, "C_Order_ID");
MOrder order = new MOrder(Env.getCtx(),C_Order_ID,null);
if (!order.isSOTrx()){
ArrayList<KeyNamePair> list = loadRequisitionData(C_BPartner_ID, M_Warehouse_ID);
for(KeyNamePair knp : list)
requisitionField.addItem(knp);
}else{
ArrayList<KeyNamePair> list = loadRequisitionSOData(C_BPartner_ID, M_Warehouse_ID);
for(KeyNamePair knp : list)
requisitionField.addItem(knp);
}
requisitionField.setSelectedIndex(0);
requisitionField.addActionListener(this);

View File

@ -105,6 +105,8 @@ public class MID_MAssetAddition extends MAssetAddition implements DocOptions{
if(getA_Asset_ID()>0) {
MAsset asset = new MAsset(getCtx(), getA_Asset_ID(), get_TrxName());
asset.setIsActive(false);
asset.setIsDepreciated(false);
asset.setA_Asset_Status(MAsset.A_ASSET_STATUS_Retired);
asset.saveEx();
}
}

View File

@ -25,13 +25,12 @@ public class MID_MRequisition extends MRequisition implements DocOptions{
// TODO Auto-generated constructor stub
}
public boolean recalculateTax() {
public boolean recalculateTax(String trxName) {
BigDecimal totalTaxAmt = DB.getSQLValueBD(get_TrxName(), "SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?", new Object[] { getM_Requisition_ID() });
BigDecimal totalLines = DB.getSQLValueBD(get_TrxName(), "SELECT COALESCE(SUM(LineNetAmt),0) FROM M_RequisitionLine WHERE M_Requisition_ID =?", new Object[] { getM_Requisition_ID() });
setTotalLines(totalLines);
set_Value("TaxAmt", totalTaxAmt);
set_Value("GrandTotal", totalLines.add(totalTaxAmt));
saveEx();
return true;
}

View File

@ -5,6 +5,7 @@ import java.util.Properties;
import org.compiere.model.MRequisition;
import org.compiere.model.MRequisitionLine;
import org.compiere.util.DB;
public class MID_MRequisitionLine extends MRequisitionLine{
@ -28,7 +29,19 @@ public class MID_MRequisitionLine extends MRequisitionLine{
@Override
protected boolean afterSave(boolean newRecord, boolean success) {
MID_MRequisition requisition = new MID_MRequisition(getCtx(), getM_Requisition_ID(), get_TrxName());
// super.afterSave(newRecord, success);
return requisition.recalculateTax();
super.afterSave(newRecord, success);
// requisition.recalculateTax(get_TrxName());
String sql = "UPDATE M_Requisition SET TaxAmt = "
+ "(SELECT COALESCE(SUM(TaxAmt),0) FROM M_RequisitionLine RL WHERE RL.M_Requisition_ID = M_Requisition.M_Requisition_ID) "
+ " WHERE M_Requisition_ID ="+getM_Requisition_ID();
DB.executeUpdateEx(sql, get_TrxName());
sql = "UPDATE M_Requisition SET GrandTotal = "
+ "(SELECT COALESCE(SUM(TaxAmt+LineNetAmt),0) FROM M_RequisitionLine RL WHERE RL.M_Requisition_ID = M_Requisition.M_Requisition_ID) "
+ " WHERE M_Requisition_ID ="+getM_Requisition_ID();
DB.executeUpdateEx(sql, get_TrxName());
return true;
}
}