use of org.compiere.model.MStorage in project adempiere by adempiere.
the class SB_InOutGenerateFromOrderLine method generate.
// doIt
/**
* Generate Shipments
* @param pstmt Order Query
* @return info
*/
private String generate(MOrder order) {
try {
if (!p_ConsolidateDocument || (m_shipment != null && (m_shipment.getC_BPartner_Location_ID() != order.getC_BPartner_Location_ID() || m_shipment.getM_Shipper_ID() != order.getM_Shipper_ID())))
completeShipment();
log.fine("check: " + order + " - DeliveryRule=" + order.getDeliveryRule());
//
Timestamp minGuaranteeDate = m_movementDate;
boolean completeOrder = MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule());
// OrderLine WHERE
String where = "";
// Exclude Auto Delivery if not Force
if (!MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule()))
where += " AND (C_OrderLine.M_Product_ID IS NULL" + " OR EXISTS (SELECT * FROM M_Product p " + "WHERE C_OrderLine.M_Product_ID=p.M_Product_ID" + " AND IsExcludeAutoDelivery='N'))";
// Deadlock Prevention - Order by M_Product_ID
MOrderLine[] lines = order.getLines(where, "C_BPartner_Location_ID, M_Product_ID");
for (MOrderLine oLine : lines) {
if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
continue;
log.fine("check: " + oLine);
BigDecimal onHand = Env.ZERO;
BigDecimal toDeliver = getQtyToDeliver(oLine);
if (toDeliver.compareTo(Env.ZERO) == 0)
continue;
MProduct product = oLine.getProduct();
// Nothing to Deliver
if (product != null && toDeliver.signum() == 0)
continue;
// or it's a charge - Bug#: 1603966
if (oLine.getC_Charge_ID() != 0 && toDeliver.signum() == 0)
continue;
// Check / adjust for confirmations
BigDecimal unconfirmedShippedQty = Env.ZERO;
// Comments & lines w/o product & services
if ((product == null || !product.isStocked()) && (// comments
oLine.getQtyOrdered().signum() == 0 || // lines w/o product
toDeliver.signum() != 0)) {
if (// printed later
!MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule()))
createLine(order, oLine, toDeliver, null, false);
continue;
}
// Stored Product
String MMPolicy = product.getMMPolicy();
MStorage[] storages = getStorages(oLine.getM_Warehouse_ID(), oLine.getM_Product_ID(), oLine.getM_AttributeSetInstance_ID(), 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 + " - " + oLine);
completeOrder = false;
break;
} else // Complete Line
if (fullLine && MOrder.DELIVERYRULE_CompleteLine.equals(order.getDeliveryRule())) {
log.fine("CompleteLine - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ", ToDeliver=" + toDeliver + " - " + oLine);
//
createLine(order, oLine, toDeliver, storages, false);
} else // Availability
if (MOrder.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 + " - " + oLine);
//
createLine(order, oLine, deliver, storages, false);
} else // Force
if (MOrder.DELIVERYRULE_Force.equals(order.getDeliveryRule())) {
BigDecimal deliver = toDeliver;
log.fine("Force - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + ", Delivering=" + deliver + " - " + oLine);
//
createLine(order, oLine, deliver, storages, true);
} else // Manual
if (MOrder.DELIVERYRULE_Manual.equals(order.getDeliveryRule()))
log.fine("Manual - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + ") - " + oLine);
else
log.fine("Failed: " + order.getDeliveryRule() + " - OnHand=" + onHand + " (Unconfirmed=" + unconfirmedShippedQty + "), ToDeliver=" + toDeliver + " - " + oLine);
}
// Complete Order successful
if (completeOrder && MOrder.DELIVERYRULE_CompleteOrder.equals(order.getDeliveryRule())) {
for (MOrderLine oLine : lines) {
MProduct product = oLine.getProduct();
BigDecimal toDeliver = oLine.getQtyOrdered().subtract(oLine.getQtyDelivered());
//
MStorage[] storages = null;
if (product != null && product.isStocked()) {
String MMPolicy = product.getMMPolicy();
storages = getStorages(oLine.getM_Warehouse_ID(), oLine.getM_Product_ID(), oLine.getM_AttributeSetInstance_ID(), minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy));
}
//
createLine(order, oLine, toDeliver, storages, false);
}
}
m_line += 1000;
} catch (Exception e) {
log.log(Level.SEVERE, m_sql, e);
}
completeShipment();
return "@Created@ = " + m_created;
}
use of org.compiere.model.MStorage in project adempiere by adempiere.
the class HTMLMessenger method getStorageInfo.
public String getStorageInfo(MProduct p, MAttributeSetInstance asi) {
StorageReasoner mr = new StorageReasoner();
int[] ids = mr.getPOIDs(MLocator.Table_Name, null, null);
MWarehouse warehouse = null;
MStorage storage = null;
MLocator locator = null;
StringBuffer sb = new StringBuffer(STORAGE_HEADER_INFO_PATTERN);
Object[] obj = null;
BigDecimal sumQtyOnHand = BigDecimal.ZERO;
BigDecimal sumQtyReserved = BigDecimal.ZERO;
BigDecimal sumQtyOrdered = BigDecimal.ZERO;
int count = 0;
for (int i = 0; i < ids.length; i++) {
storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null);
if (storage == null) {
continue;
}
count++;
warehouse = new MWarehouse(Env.getCtx(), storage.getM_Warehouse_ID(), null);
locator = new MLocator(Env.getCtx(), storage.getM_Locator_ID(), null);
sumQtyOnHand = sumQtyOnHand.add(storage.getQtyOnHand());
sumQtyReserved = sumQtyReserved.add(storage.getQtyReserved());
sumQtyOrdered = sumQtyOrdered.add(storage.getQtyOrdered());
// the quantities of specific locator
obj = new Object[] { locator.getX() + " - " + locator.getY() + " - " + locator.getZ(), warehouse.getName(), storage.getQtyOnHand(), storage.getQtyReserved(), storage.getQtyOrdered(), storage.getQtyOnHand().subtract(storage.getQtyReserved()) };
sb.append(MessageFormat.format(STORAGE_LINE_INFO_PATTERN, obj));
}
// the sum of the single quantities, if there is more than one line
if (count > 1) {
obj = new Object[] { sumQtyOnHand, sumQtyReserved, sumQtyOrdered, sumQtyOnHand.subtract(sumQtyReserved) };
sb.append(MessageFormat.format(STORAGE_SUM_LINE_INFO_PATTERN, obj));
}
double available = sumQtyOnHand.subtract(sumQtyReserved).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
if (count == 0 || (available <= 0.00d)) {
sb.append(MessageFormat.format(STORAGE_NOINVENTORY_INFO_PATTERN, obj));
}
sb.append(STORAGE_FOOTER_INFO_PATTERN);
return sb.toString();
}
use of org.compiere.model.MStorage in project adempiere by adempiere.
the class StorageReasoner method getSumQtyAvailable.
public BigDecimal getSumQtyAvailable(MProduct p, MAttributeSetInstance asi) {
int[] ids = getPOIDs(MLocator.Table_Name, null, null);
MStorage storage = null;
Object[] obj = null;
BigDecimal sumQtyAvailable = BigDecimal.ZERO;
int count = 0;
for (int i = 0; i < ids.length; i++) {
storage = MStorage.get(Env.getCtx(), ids[i], p.get_ID(), asi.get_ID(), null);
if (storage == null) {
continue;
}
count++;
sumQtyAvailable = sumQtyAvailable.add(storage.getQtyOnHand().subtract(storage.getQtyReserved()));
}
return sumQtyAvailable;
}
use of org.compiere.model.MStorage in project adempiere by adempiere.
the class ReleaseInOutBound method createDistributionOrder.
/**
* get Out Bound Order Lines from Smart Browser
* @return
*/
/*private List <MWMInOutBoundLine> getOutBoundOrderLine()
{
StringBuilder whereClause = new StringBuilder();
whereClause.append("EXISTS (SELECT 1 FROM WM_InOutBound o WHERE o.WM_InOutBound_ID=WM_InOutBoundLine.WM_InOutBound_ID AND o.Processed='N' AND o.DocAction NOT IN ('CO','CL','VO')) AND ");
whereClause.append("EXISTS (SELECT T_Selection_ID FROM T_Selection WHERE T_Selection.AD_PInstance_ID=? AND T_Selection.T_Selection_ID=WM_InOutBoundLine.WM_InOutboundLine_ID)");
return new Query(getCtx(), I_WM_InOutBoundLine.Table_Name, whereClause.toString(), get_TrxName())
.setClient_ID()
.setParameters(getAD_PInstance_ID())
.list();
}*/
/**
* create Distribution Order to performance a Pick List
* @param outBoundOrderLine Out bound Line
* @return Quantity that was not covert for inventory
*/
protected BigDecimal createDistributionOrder(MWMInOutBoundLine outBoundOrderLine) {
WMRuleEngine engineRule = WMRuleEngine.get();
List<MStorage> storageList = engineRule.getStorage(outBoundOrderLine, getWarehouseAreaTypeId(), getWarehouseSectionTypeId());
int shipperId = 0;
BigDecimal qtySupply = BigDecimal.ZERO;
if (storageList != null && storageList.size() > 0) {
//get the warehouse in transit
MWarehouse[] wsts = MWarehouse.getInTransitForOrg(getCtx(), outBoundLocator.getAD_Org_ID());
if (wsts == null || wsts.length == 0)
throw new AdempiereException("@M_Warehouse_ID@ @IsInTransit@ @NotFound@");
//Org Must be linked to BPartner
MOrg org = MOrg.get(getCtx(), outBoundLocator.getAD_Org_ID());
int partnerId = org.getLinkedC_BPartner_ID(get_TrxName());
if (partnerId == 0)
throw new NoBPartnerLinkedforOrgException(org);
MBPartner partner = MBPartner.get(getCtx(), partnerId);
if (orderDistribution == null) {
orderDistribution = new MDDOrder(getCtx(), 0, get_TrxName());
orderDistribution.setAD_Org_ID(outBoundLocator.getAD_Org_ID());
orderDistribution.setC_BPartner_ID(partnerId);
if (getDocumentTypeId() > 0) {
orderDistribution.setC_DocType_ID(getDocumentTypeId());
} else {
orderDistribution.setC_DocType_ID(MDocType.getDocType(X_C_DocType.DOCBASETYPE_DistributionOrder));
}
orderDistribution.setM_Warehouse_ID(wsts[0].get_ID());
if (getDocumentAction() != null)
orderDistribution.setDocAction(getDocumentAction());
else
orderDistribution.setDocAction(X_DD_Order.DOCACTION_Prepare);
MUser[] users = MUser.getOfBPartner(getCtx(), partner.getC_BPartner_ID(), get_TrxName());
if (users == null || users.length == 0)
throw new AdempiereException("@AD_User_ID@ @NotFound@ @Value@ - @C_BPartner_ID@ : " + partner.getValue() + " - " + partner.getName());
orderDistribution.setAD_User_ID(users[0].getAD_User_ID());
orderDistribution.setDateOrdered(getToday());
orderDistribution.setDatePromised(getToday());
orderDistribution.setM_Shipper_ID(shipperId);
orderDistribution.setIsInDispute(false);
orderDistribution.setIsInTransit(false);
orderDistribution.setSalesRep_ID(getAD_User_ID());
orderDistribution.saveEx();
}
storageList.stream().forEach(storage -> {
MDDOrderLine orderLine = new MDDOrderLine(orderDistribution);
orderLine.setM_Locator_ID(storage.getM_Locator_ID());
orderLine.setM_LocatorTo_ID(outBoundLocator.getM_Locator_ID());
orderLine.setC_UOM_ID(outBoundOrderLine.getC_UOM_ID());
orderLine.setM_Product_ID(outBoundOrderLine.getM_Product_ID());
orderLine.setDateOrdered(getToday());
orderLine.setDatePromised(outBoundOrderLine.getPickDate());
orderLine.setWM_InOutBoundLine_ID(outBoundOrderLine.getWM_InOutBoundLine_ID());
orderLine.setIsInvoiced(false);
orderLine.saveEx();
});
} else {
qtySupply = outBoundOrderLine.getQtyToPick().subtract(qtySupply);
}
return qtySupply;
}
use of org.compiere.model.MStorage in project adempiere by adempiere.
the class GenerateShipmentOutBound method createShipment.
/**
* Create Shipment to Out Bound Order
* @param outBoundLine
*/
public void createShipment(MWMInOutBoundLine outBoundLine) {
// Generate Shipment based on Outbound Order
if (outBoundLine.getC_OrderLine_ID() > 0) {
MOrderLine orderLine = outBoundLine.getOrderLine();
if (outBoundLine.getPickedQty().subtract(orderLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderLine.getQtyDelivered());
MInOut shipment = getShipment(orderLine);
MInOutLine shipmentLine = new MInOutLine(outBoundLine.getCtx(), 0, outBoundLine.get_TrxName());
shipmentLine.setM_InOut_ID(shipment.getM_InOut_ID());
shipmentLine.setM_Locator_ID(standing.getM_Locator_ID());
shipmentLine.setM_Product_ID(outBoundLine.getM_Product_ID());
shipmentLine.setQtyEntered(qtyDelivered);
shipmentLine.setMovementQty(qtyDelivered);
shipmentLine.setC_OrderLine_ID(orderLine.getC_OrderLine_ID());
shipmentLine.saveEx();
}
// Generate Delivery Movement
if (outBoundLine.getDD_OrderLine_ID() > 0) {
MDDOrderLine distributionOrderLine = (MDDOrderLine) outBoundLine.getDD_OrderLine();
if (distributionOrders.get(distributionOrderLine.getDD_Order_ID()) == null)
distributionOrders.put(distributionOrderLine.getDD_Order_ID(), distributionOrderLine.getDD_Order());
distributionOrderLine.setConfirmedQty(outBoundLine.getPickedQty());
distributionOrderLine.saveEx();
}
// Generate Delivery Manufacturing Order
if (outBoundLine.getPP_Order_BOMLine_ID() > 0) {
MPPOrderBOMLine orderBOMLine = (MPPOrderBOMLine) outBoundLine.getPP_Order_BOMLine();
if (outBoundLine.getPickedQty().subtract(orderBOMLine.getQtyDelivered()).signum() <= 0 && !isIncludeNotAvailable())
return;
MLocator standing = getStandingLocator(outBoundLine);
MStorage[] storage = MStorage.getAll(getCtx(), orderBOMLine.getM_Product_ID(), standing.getM_Locator_ID(), get_TrxName());
BigDecimal qtyDelivered = getQtyDelivered(outBoundLine, orderBOMLine.getQtyDelivered());
List<MPPCostCollector> issues = MPPOrder.createIssue(orderBOMLine.getParent(), orderBOMLine, getMovementDate(), qtyDelivered, BigDecimal.ZERO, BigDecimal.ZERO, storage, true);
issues.stream().forEach(costCollector -> {
if (manufacturingIssues.get(costCollector.getPP_Cost_Collector_ID()) == null)
manufacturingIssues.put(costCollector.getPP_Cost_Collector_ID(), costCollector);
});
}
}
Aggregations