use of org.compiere.model.Query in project adempiere by adempiere.
the class PromotionRule method addDiscountLine.
private static void addDiscountLine(MOrder order, MOrderLine ol, BigDecimal discount, BigDecimal qty, int C_Charge_ID, I_M_Promotion promotion) throws Exception {
MOrderLine nol;
if (discount.scale() > 2)
discount = discount.setScale(2, BigDecimal.ROUND_HALF_UP);
String description = promotion.getName();
if (ol != null)
description += (", " + ol.getName());
//Look for same order line. If found, just update qty
nol = new Query(Env.getCtx(), MTable.get(order.getCtx(), MOrderLine.Table_ID), "C_OrderLine.C_Order_ID=? AND C_Charge_ID=? AND M_Promotion_ID=? AND priceactual=? AND Description='" + description + "'" + " AND C_OrderLine.IsActive='Y'", order.get_TrxName()).setParameters(ol.getC_Order_ID(), C_Charge_ID, promotion.getM_Promotion_ID(), discount.negate()).firstOnly();
if (nol != null) {
// just add one to he Order line
nol.setQty(nol.getQtyEntered().add(qty));
nol.saveEx();
return;
}
// SHW: new order line
nol = new MOrderLine(order.getCtx(), 0, order.get_TrxName());
nol.setC_Order_ID(order.getC_Order_ID());
nol.setOrder(order);
nol.setC_Charge_ID(C_Charge_ID);
nol.setQty(qty);
nol.setPriceActual(discount.negate());
// SHW
nol.setC_UOM_ID(ol.getC_UOM_ID());
if (ol != null && Integer.toString(ol.getLine()).endsWith("0")) {
for (int i = 0; i < 9; i++) {
int line = ol.getLine() + i + 1;
int r = DB.getSQLValue(order.get_TrxName(), "SELECT C_OrderLine_ID FROM C_OrderLine WHERE C_Order_ID = ? AND Line = ?", order.getC_Order_ID(), line);
if (r <= 0) {
nol.setLine(line);
break;
}
}
}
nol.setDescription(description);
nol.set_ValueOfColumn("M_Promotion_ID", promotion.getM_Promotion_ID());
if (promotion.getC_Campaign_ID() > 0) {
nol.setC_Campaign_ID(promotion.getC_Campaign_ID());
}
if (!nol.save())
throw new AdempiereException("Failed to add discount line to order");
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class PayPrint method loadPaymentRuleInfo.
/**
* PaymentRule changed - load DocumentNo, NoPayments,
* enable/disable EFT, Print
*/
public String loadPaymentRuleInfo(int paySelectionId, String paymentRule) {
Integer paymentCount = new Query(Env.getCtx(), MPaySelectionCheck.Table_Name, MPaySelectionCheck.COLUMNNAME_C_PaySelection_ID + "=?", null).setClient_ID().setParameters(paySelectionId).count();
noPayments = String.valueOf(paymentCount);
String msg = null;
//"SELECT CurrentNext FROM C_BankAccountDoc WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive=?
StringBuilder sql = new StringBuilder();
sql.append("SELECT ").append(X_C_BankAccountDoc.COLUMNNAME_CurrentNext).append(" FROM ").append(X_C_BankAccountDoc.Table_Name).append(" WHERE ").append(X_C_BankAccountDoc.COLUMNNAME_C_BankAccount_ID).append("=? AND ").append(X_C_BankAccountDoc.COLUMNNAME_PaymentRule).append("=? AND ").append(X_C_BankAccountDoc.COLUMNNAME_IsActive).append("=?");
List<Object> parameters = new ArrayList<>();
parameters.add(bankAccountId);
parameters.add(paymentRule);
parameters.add(true);
// DocumentNo
documentNo = DB.getSQLValueEx(null, sql.toString(), parameters.toArray());
if (documentNo == -1) {
log.log(Level.SEVERE, "VPayPrint.loadPaymentRuleInfo - No active BankAccountDoc for C_BankAccount_ID=" + bankAccountId + " AND PaymentRule=" + paymentRule);
msg = "VPayPrintNoDoc";
}
return msg;
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class CostResult method getCost.
public MCost getCost(int M_Product_ID) {
MCostElement ce = getMaterialElement(trxName);
String whereClause = "M_Product_ID=? AND M_CostElement_ID=? AND M_CostType_ID=? ";
ArrayList<Object> parameters = new ArrayList();
parameters.add(M_Product_ID);
parameters.add(ce.getM_CostElement_ID());
parameters.add(as.getM_CostType_ID());
return new Query(getCtx(), I_M_Cost.Table_Name, whereClause, trxName).setClient_ID().setParameters(parameters).first();
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class InventoryTestException method assertMTransaction.
private void assertMTransaction(MMDocument doc, String trxName) {
final MLocator locator = InventoryUtil.getCreateLocator(-1, doc.LocatorValue, doc.LocatorValue);
final MProduct product = InventoryUtil.getCreateProduct(doc);
final int M_ASI_ID;
if (Util.isEmpty(doc.ASI, true)) {
M_ASI_ID = -1;
} else {
M_ASI_ID = doc.scenario.getM_ASI_ID(doc.ASI);
}
//
ArrayList<Object> params = new ArrayList<Object>();
String whereClause = MTransaction.COLUMNNAME_M_Product_ID + "=?" + " AND " + MTransaction.COLUMNNAME_M_Locator_ID + "=?";
params.add(product.get_ID());
params.add(locator.get_ID());
if (M_ASI_ID > 0) {
whereClause += " AND " + MTransaction.COLUMNNAME_M_AttributeSetInstance_ID + "=?";
params.add(M_ASI_ID);
}
//
MTransaction trx = new Query(getCtx(), MTransaction.Table_Name, whereClause, trxName).setParameters(params).setOrderBy(// fetch lasts first
MTransaction.COLUMNNAME_M_Transaction_ID + " DESC").first();
//
assertNotNull("No MTransaction found", trx);
assertEquals("MTransaction.MovementQty not match", doc.Qty, trx.getMovementQty());
if (doc.Date != null) {
assertEquals("MTransaction.MovementDate not match", doc.Date, trx.getMovementDate());
}
//
// TODO: check MCostDetail...
}
use of org.compiere.model.Query in project adempiere by adempiere.
the class LiberoValidator method updateMPPOrder.
// getAD_Client_ID
private void updateMPPOrder(MInOutLine outline) {
MPPOrder order = null;
BigDecimal qtyShipment = Env.ZERO;
MInOut inout = outline.getParent();
String movementType = inout.getMovementType();
int orderLineId = 0;
if (MInOut.MOVEMENTTYPE_CustomerShipment.equals(movementType)) {
orderLineId = outline.getC_OrderLine_ID();
qtyShipment = outline.getMovementQty();
} else if (MInOut.MOVEMENTTYPE_CustomerReturns.equals(movementType)) {
MRMALine rmaline = new MRMALine(outline.getCtx(), outline.getM_RMALine_ID(), null);
MInOutLine line = (MInOutLine) rmaline.getM_InOutLine();
orderLineId = line.getC_OrderLine_ID();
qtyShipment = outline.getMovementQty().negate();
}
final String whereClause = " C_OrderLine_ID = ? " + " AND DocStatus IN (?,?)" + " AND EXISTS (SELECT 1 FROM PP_Order_BOM " + " WHERE PP_Order_BOM.PP_Order_ID=PP_Order.PP_Order_ID AND PP_Order_BOM.BOMType =? )";
order = new Query(outline.getCtx(), MPPOrder.Table_Name, whereClause, outline.get_TrxName()).setParameters(orderLineId, MPPOrder.DOCSTATUS_InProgress, MPPOrder.DOCSTATUS_Completed, MPPOrderBOM.BOMTYPE_Make_To_Kit).firstOnly();
if (order == null || order.get_ID() <= 0)
return;
if (MPPOrder.DOCSTATUS_InProgress.equals(order.getDocStatus())) {
order.completeIt();
order.setDocStatus(MPPOrder.ACTION_Complete);
order.setDocAction(MPPOrder.DOCACTION_Close);
order.saveEx();
}
if (MPPOrder.DOCSTATUS_Completed.equals(order.getDocStatus())) {
String description = order.getDescription() != null ? order.getDescription() : "" + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_M_InOut_ID) + " : " + Msg.translate(inout.getCtx(), MInOut.COLUMNNAME_DocumentNo);
order.setDescription(description);
order.updateMakeToKit(qtyShipment);
order.saveEx();
}
if (order.getQtyToDeliver().signum() == 0) {
order.closeIt();
order.setDocStatus(MPPOrder.DOCACTION_Close);
order.setDocAction(MPPOrder.DOCACTION_None);
order.saveEx();
}
return;
}
Aggregations