use of org.compiere.model.MLocator in project adempiere by adempiere.
the class WMRuleEngine method getLocator.
/**
* Get Locator based on strategy and product id , area type id , section id
* @param strategy strategy
* @param productId Product
* @param warehouseAreaTypeId Area Type
* @param warehouseSectionTypeId Section Type
* @return List of Locators
*/
public static List<MLocator> getLocator(MWMStrategy strategy, int productId, int warehouseAreaTypeId, int warehouseSectionTypeId) {
ArrayList<MLocator> targetLocators = new ArrayList();
WMRuleEngine engine = WMRuleEngine.get();
for (MWMStrategyDetail detail : strategy.getStrategyDetail()) {
MWMRule rule = (MWMRule) detail.getWM_Rule();
WMRuleInterface implementation = engine.getWMRuleFactory(engine.getClassName(rule));
List<MLocator> locators = implementation.getLocator(strategy.getCtx(), productId, strategy.getM_Warehouse_ID(), warehouseAreaTypeId, warehouseSectionTypeId, strategy.get_TrxName());
for (MLocator locator : locators) {
targetLocators.add(locator);
}
}
return targetLocators;
}
use of org.compiere.model.MLocator in project adempiere by adempiere.
the class CostDimension method isSameCostDimension.
public static boolean isSameCostDimension(MAcctSchema as, MTransaction trxFrom, MTransaction trxTo) {
if (trxFrom.getM_Product_ID() != trxTo.getM_Product_ID()) {
throw new AdempiereException("Same product is needed - " + trxFrom + ", " + trxTo);
}
MProduct product = MProduct.get(trxFrom.getCtx(), trxFrom.getM_Product_ID());
String CostingLevel = product.getCostingLevel(as, trxFrom.getAD_Org_ID());
MLocator locatorFrom = MLocator.get(trxFrom.getCtx(), trxFrom.getM_Locator_ID());
MLocator locatorTo = MLocator.get(trxTo.getCtx(), trxTo.getM_Locator_ID());
int Org_ID = locatorFrom.getAD_Org_ID();
int Org_ID_To = locatorTo.getAD_Org_ID();
int ASI_ID = trxFrom.getM_AttributeSetInstance_ID();
int ASI_ID_To = trxTo.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Warehouse.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
}
//
return Org_ID == Org_ID_To && ASI_ID == ASI_ID_To;
}
use of org.compiere.model.MLocator in project adempiere by adempiere.
the class CostDimension method isSameCostDimension.
public static boolean isSameCostDimension(MAcctSchema as, IDocumentLine model) {
MProduct product = MProduct.get(model.getCtx(), model.getM_Product_ID());
MLocator locator = MLocator.get(model.getCtx(), model.getM_LocatorTo_ID());
String CostingLevel = product.getCostingLevel(as, model.getAD_Org_ID());
int Org_ID = model.getAD_Org_ID();
int Org_ID_To = locator.getAD_Org_ID();
int ASI_ID = model.getM_AttributeSetInstance_ID();
int ASI_ID_To = model.getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_Warehouse.equals(CostingLevel)) {
ASI_ID = 0;
ASI_ID_To = 0;
} else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel)) {
Org_ID = 0;
Org_ID_To = 0;
}
//
return Org_ID == Org_ID_To && ASI_ID == ASI_ID_To;
}
use of org.compiere.model.MLocator in project adempiere by adempiere.
the class InOutCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// Valid Record Identifier
if (getRecord_ID() == 0)
return "";
AtomicInteger referenceId = new AtomicInteger(0);
AtomicInteger created = new AtomicInteger(0);
// Get Shipment
MInOut inout = new MInOut(getCtx(), getRecord_ID(), get_TrxName());
log.config(inout + ", C_Locator_ID=" + getLocator());
// Get Default Locator
MLocator defaultLocator = MLocator.getDefault((MWarehouse) inout.getM_Warehouse());
List<Integer> recordIds = getSelectionKeys();
String createFromType = recordIds.size() > 0 ? getSelectionAsString(recordIds.get(0), "CF_CreateFromType") : null;
log.fine("CreateFromType=" + createFromType);
if (createFromType == null || createFromType.length() == 0)
throw new AdempiereException("@CreateFromType@ @NotFound@");
// Loop
recordIds.stream().forEach(key -> {
int productId = getSelectionAsInt(key, "CF_M_Product_ID");
int chargeId = getSelectionAsInt(key, "CF_C_Charge_ID");
int uomId = getSelectionAsInt(key, "CF_C_UOM_ID");
int locatorId = getSelectionAsInt(key, "CF_M_Locator_ID");
BigDecimal qtyEntered = getSelectionAsBigDecimal(key, "CF_QtyEntered");
locatorId = getValidLocator(locatorId, defaultLocator);
MInvoiceLine invoiceLine = null;
int precision = 2;
if (productId != 0) {
MProduct product = MProduct.get(getCtx(), productId);
precision = product.getUOMPrecision();
}
qtyEntered = qtyEntered.setScale(precision, BigDecimal.ROUND_HALF_DOWN);
log.fine("Line QtyEntered=" + qtyEntered + ", Product=" + productId + ", Key=" + key);
MInOutLine inOutLine = new MInOutLine(inout);
inOutLine.setM_Product_ID(productId, uomId);
inOutLine.setQty(qtyEntered);
if (createFromType.equals(ORDER)) {
MOrderLine orderLine = new MOrderLine(getCtx(), key, get_TrxName());
referenceId.set(orderLine.getC_Order_ID());
inOutLine.setC_OrderLine_ID(key);
if (orderLine.getQtyEntered().compareTo(orderLine.getQtyOrdered()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(orderLine.getQtyOrdered()).divide(orderLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(orderLine.getC_UOM_ID());
}
inOutLine.setM_AttributeSetInstance_ID(orderLine.getM_AttributeSetInstance_ID());
inOutLine.setDescription(orderLine.getDescription());
inOutLine.setC_Project_ID(orderLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(orderLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(orderLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(orderLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(orderLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(orderLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(orderLine.getUser1_ID());
inOutLine.setUser2_ID(orderLine.getUser2_ID());
inOutLine.setUser3_ID(orderLine.getUser3_ID());
inOutLine.setUser4_ID(orderLine.getUser4_ID());
} else if (createFromType.equals(INVOICE)) {
invoiceLine = new MInvoiceLine(getCtx(), key, get_TrxName());
MInvoice invoice = invoiceLine.getParent();
referenceId.getAndSet(invoice.getC_Invoice_ID());
if (invoice.isCreditMemo()) {
qtyEntered = qtyEntered.negate();
inOutLine.setQty(qtyEntered);
}
if (invoiceLine.getQtyEntered().compareTo(invoiceLine.getQtyInvoiced()) != 0) {
inOutLine.setMovementQty(qtyEntered.multiply(invoiceLine.getQtyInvoiced()).divide(invoiceLine.getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP));
inOutLine.setC_UOM_ID(invoiceLine.getC_UOM_ID());
}
inOutLine.setDescription(invoiceLine.getDescription());
inOutLine.setC_Project_ID(invoiceLine.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(invoiceLine.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(invoiceLine.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(invoiceLine.getC_Activity_ID());
inOutLine.setC_Campaign_ID(invoiceLine.getC_Campaign_ID());
inOutLine.setAD_OrgTrx_ID(invoiceLine.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(invoiceLine.getUser1_ID());
inOutLine.setUser2_ID(invoiceLine.getUser2_ID());
inOutLine.setUser3_ID(invoiceLine.getUser3_ID());
inOutLine.setUser4_ID(invoiceLine.getUser4_ID());
} else if (createFromType.equals(RMA)) {
MRMALine rmal = new MRMALine(getCtx(), key, get_TrxName());
referenceId.set(rmal.getM_RMA_ID());
inOutLine.setM_RMALine_ID(key);
inOutLine.setQtyEntered(qtyEntered);
inOutLine.setDescription(rmal.getDescription());
inOutLine.setM_AttributeSetInstance_ID(rmal.getM_AttributeSetInstance_ID());
inOutLine.setC_Project_ID(rmal.getC_Project_ID());
inOutLine.setC_ProjectPhase_ID(rmal.getC_ProjectPhase_ID());
inOutLine.setC_ProjectTask_ID(rmal.getC_ProjectTask_ID());
inOutLine.setC_Activity_ID(rmal.getC_Activity_ID());
inOutLine.setAD_OrgTrx_ID(rmal.getAD_OrgTrx_ID());
inOutLine.setUser1_ID(rmal.getUser1_ID());
inOutLine.setUser2_ID(rmal.getUser2_ID());
inOutLine.setUser3_ID(rmal.getUser3_ID());
inOutLine.setUser4_ID(rmal.getUser4_ID());
}
if (chargeId != 0)
inOutLine.setC_Charge_ID(chargeId);
inOutLine.setM_Locator_ID(locatorId);
inOutLine.saveEx();
if (invoiceLine != null) {
invoiceLine.setM_InOutLine_ID(inOutLine.getM_InOutLine_ID());
invoiceLine.saveEx();
}
created.updateAndGet(createNo -> createNo + 1);
});
// Add reference to Order / Invoice / RMA
addReference(inout, createFromType, referenceId.get());
//
return "@Created@ " + created.get();
}
use of org.compiere.model.MLocator in project adempiere by adempiere.
the class MovementGenerate method generate.
// doIt
/**
* Generate Shipments
* @param pstmt Order Query
* @return info
*/
private String generate(PreparedStatement pstmt) {
MClient client = MClient.get(getCtx());
try {
ResultSet rs = pstmt.executeQuery();
while (// Order
rs.next()) {
MDDOrder order = new MDDOrder(getCtx(), rs, get_TrxName());
// New Header different Shipper, Shipment Location
if (!p_ConsolidateDocument || (m_movement != null && (m_movement.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_movement.getM_Shipper_ID() != order.getM_Shipper_ID()))) {
completeMovement();
}
log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
//
Timestamp minGuaranteeDate = m_movementDate;
boolean completeOrder = MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
// OrderLine WHERE
String where = " " + p_M_Warehouse_ID + " IN (SELECT l.M_Warehouse_ID FROM M_Locator l WHERE l.M_Locator_ID=M_Locator_ID) ";
if (p_DatePromised != null)
where += " AND (TRUNC(DatePromised)<=" + DB.TO_DATE(p_DatePromised, true) + " OR DatePromised IS NULL)";
// Exclude Auto Delivery if not Force
if (!MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
where += " AND (DD_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE DD_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
// Exclude Unconfirmed
if (!p_IsUnconfirmedInOut)
where += " AND NOT EXISTS (SELECT * FROM M_MovementLine iol" + " INNER JOIN M_Movement io ON (iol.M_Movement_ID=io.M_Movement_ID) " + "WHERE iol.DD_OrderLine_ID=DD_OrderLine.DD_OrderLine_ID AND io.DocStatus IN ('IP','WC'))";
// Deadlock Prevention - Order by M_Product_ID
MDDOrderLine[] lines = order.getLines(where, "M_Product_ID");
for (int i = 0; i < lines.length; i++) {
MDDOrderLine line = lines[i];
MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
log.fine("check: " + line);
BigDecimal onHand = Env.ZERO;
//BigDecimal toDeliver = line.getQtyOrdered()
//.subtract(line.getQtyDelivered());
BigDecimal toDeliver = line.getConfirmedQty();
MProduct product = line.getProduct();
// Nothing to Deliver
if (product != null && toDeliver.signum() == 0)
continue;
// or it's a charge - Bug#: 1603966
if (line.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
continue;
// Check / adjust for confirmations
BigDecimal unconfirmedShippedQty = Env.ZERO;
if (p_IsUnconfirmedInOut && product != null && toDeliver.signum() != 0) {
String where2 = "EXISTS (SELECT * FROM M_Movement io WHERE io.M_Movement_ID=M_MovementLine.M_Movement_ID AND io.DocStatus IN ('IP','WC'))";
MMovementLine[] iols = MMovementLine.getOfOrderLine(getCtx(), line.getDD_OrderLine_ID(), where2, null);
for (int j = 0; j < iols.length; j++) unconfirmedShippedQty = unconfirmedShippedQty.add(iols[j].getMovementQty());
String logInfo = "Unconfirmed Qty=" + unconfirmedShippedQty + " - ToDeliver=" + toDeliver + "->";
toDeliver = toDeliver.subtract(unconfirmedShippedQty);
logInfo += toDeliver;
if (toDeliver.signum() < 0) {
toDeliver = Env.ZERO;
logInfo += " (set to 0)";
}
// Adjust On Hand
onHand = onHand.subtract(unconfirmedShippedQty);
log.fine(logInfo);
}
// Comments & lines w/o product & services
if ((product == null || !product.isStocked()) && (// comments
line.getQtyOrdered().signum() == 0 || // lines w/o product
toDeliver.signum() != 0)) {
if (// printed later
!MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
createLine(order, line, toDeliver, null, false);
continue;
}
// Stored Product
MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
MStorage[] storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
onHand = onHand.add(storage.getQtyOnHand());
}
boolean fullLine = onHand.compareTo(toDeliver) >= 0 || toDeliver.signum() < 0;
// Complete Order
if (completeOrder && !fullLine) {
log.fine("Failed CompleteOrder - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
completeOrder = false;
break;
} else // Complete Line
if (fullLine && MDDOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + line);
//
createLine(order, line, toDeliver, storages, false);
} else // Availability
if (MDDOrder.DELIVERYRULE_Availability.equals(order.getDeliveryRule()) && (onHand.signum() > 0 || toDeliver.signum() < 0)) {
BigDecimal deliver = toDeliver;
if (deliver.compareTo(onHand) > 0)
deliver = onHand;
log.fine("Available - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, false);
} else // Force
if (MDDOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
BigDecimal deliver = toDeliver;
log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + line);
//
createLine(order, line, deliver, storages, true);
} else // Manual
if (MDDOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + line);
else
log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + line);
}
// Complete Order successful
if (completeOrder && MDDOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
for (int i = 0; i < lines.length; i++) {
MDDOrderLine line = lines[i];
MLocator l = new MLocator(getCtx(), line.getM_Locator_ID(), get_TrxName());
if (l.getM_Warehouse_ID() != p_M_Warehouse_ID)
continue;
MProduct product = line.getProduct();
BigDecimal toDeliver = line.getQtyOrdered().subtract(line.getQtyDelivered());
//
MStorage[] storages = null;
if (product != null && product.isStocked()) {
MProductCategory pc = MProductCategory.get(order.getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
storages = getStorages(l.getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(), product.getM_AttributeSet_ID(), line.getM_AttributeSetInstance_ID() == 0, minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
}
//
createLine(order, line, toDeliver, storages, false);
}
}
m_line += 1000;
}
// while order
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, m_sql, e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
completeMovement();
return "@Created@ = " + m_created;
}
Aggregations