use of org.compiere.model.MProduct 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.MProduct in project adempiere by adempiere.
the class ScanBar method loadData.
protected void loadData() {
data = new LinkedHashMap<String, Vector>();
for (PO po : getDocumentLines()) {
MProduct product = null;
MAttributeSetInstance asi = null;
String lotNo = null;
String serNo = null;
Integer referenceId = null;
BigDecimal qty = null;
boolean reset = false;
int M_Product_ID = po.get_ValueAsInt(MProduct.COLUMNNAME_M_Product_ID);
int M_AttributeSetInstance_ID = po.get_ValueAsInt(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID);
if (M_Product_ID > 0)
product = MProduct.get(Env.getCtx(), M_Product_ID);
else
continue;
if (M_AttributeSetInstance_ID > 0) {
asi = new MAttributeSetInstance(Env.getCtx(), M_AttributeSetInstance_ID, null);
lotNo = asi.getLot();
serNo = asi.getSerNo();
} else {
M_AttributeSetInstance_ID = 0;
reset = true;
lotNo = null;
serNo = null;
}
if (po instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) po;
referenceId = ioLine.getC_OrderLine_ID();
qty = ioLine.getMovementQty();
}
if (po instanceof MInventoryLine) {
MInventoryLine invenotryLine = (MInventoryLine) po;
qty = invenotryLine.getQtyCount();
}
if (getSource() != null && source.size() > 0) {
ArrayList<Object> values = checkProduct(product, qty, reset);
if (values == null)
throw new AdempiereException("@M_Product_ID@ ; " + product.getName() + " @InValid@");
}
String key = product.getValue();
if (lotNo != null && lotNo.length() > 0)
key = key + lotNo;
if (serNo != null && serNo.length() > 0)
key = key + serNo;
Vector<Object> line = new Vector<Object>(6);
// 0
line.add(product.getValue());
// 1
line.add(product.getName());
// 2
line.add(lotNo);
// 3
line.add(serNo);
// 4
line.add(qty);
// 5
line.add(po.get_ID());
// 6
line.add(referenceId != null ? referenceId.intValue() : 0);
data.put(key, line);
}
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class ScanBar method createLine.
public void createLine() {
int lineNo = DB.getSQLValueEx(null, "SELECT Line FROM " + tableLine.getTableName() + " WHERE " + table.getTableName() + "_ID=?", getRecord_ID());
if (lineNo <= 0)
lineNo = 10;
for (Vector<Object> line : getData().values()) {
String value = (String) line.get(0);
String lotNo = (String) line.get(2);
String serNo = (String) line.get(3);
Boolean isASI = (lotNo != null && lotNo.length() > 0) || (serNo != null && serNo.length() > 0) ? true : false;
BigDecimal qty = (BigDecimal) line.get(4);
int id = (Integer) line.get(5);
Integer referenceId = (Integer) line.get(6);
PO poLine = null;
MAttributeSetInstance asi = null;
MProduct product = new Query(Env.getCtx(), I_M_Product.Table_Name, "Value = ? ", null).setClient_ID().setParameters(value).firstOnly();
String desc = null;
poLine = tableLine.getPO(id, null);
if (product.getM_AttributeSet_ID() > 0 && isASI) {
if (poLine != null && poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID) > 0)
asi = new MAttributeSetInstance(Env.getCtx(), poLine.get_ValueAsInt(I_M_AttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID), null);
else
asi = getAttributeSetInstance(product, lotNo, serNo, getM_Locater_ID(), null);
}
poLine.set_ValueOfColumn(table.getKeyColumns()[0], getRecord_ID());
poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_M_Product_ID, product.get_ID());
poLine.set_ValueOfColumn(I_M_Product.COLUMNNAME_C_UOM_ID, product.getC_UOM_ID());
poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_Line, lineNo);
poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_IsActive, true);
int locatorColumnId = poLine.get_ColumnIndex(I_M_InOutLine.COLUMNNAME_M_Locator_ID);
if (locatorColumnId > 0 && getM_Locater_ID() > 0)
poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_M_Locator_ID, getM_Locater_ID());
if (asi == null && isASI) {
if (asi == null && isASI) {
asi = new MAttributeSetInstance(Env.getCtx(), 0, product.getM_AttributeSet_ID(), null);
if (lotNo != null) {
asi.setLot(lotNo);
desc = lotNo;
}
if (serNo != null) {
asi.setSerNo(serNo);
if (desc != null)
desc = desc + " - " + serNo;
else
desc = serNo;
}
asi.setDescription(desc);
asi.saveEx();
}
}
if (poLine instanceof MInventoryLine) {
MStorage storage = MStorage.get(Env.getCtx(), getM_Locater_ID(), product.getM_Product_ID(), asi == null ? 0 : asi.getM_AttributeSetInstance_ID(), null);
poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyCount, qty);
poLine.set_CustomColumn(I_M_InventoryLine.COLUMNNAME_QtyBook, storage == null ? Env.ZERO : storage.getQtyOnHand());
} else if (poLine instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) poLine;
ioLine.setQty(qty);
ioLine.setC_OrderLine_ID(referenceId);
} else if (poLine instanceof MMovementLine) {
MMovementLine movementLine = (MMovementLine) poLine;
movementLine.setM_LocatorTo_ID(getM_LocaterTo_ID());
movementLine.setMovementQty(qty);
} else
poLine.set_ValueOfColumn(I_M_InOutLine.COLUMNNAME_MovementQty, qty);
poLine.set_ValueOfColumn(MAttributeSetInstance.COLUMNNAME_M_AttributeSetInstance_ID, asi == null ? 0 : asi.get_ID());
if (poLine.is_Changed())
poLine.saveEx();
lineNo = lineNo + 10;
}
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class ScanBar method getMProduct.
public MProduct getMProduct(String barCode) {
MProduct product = getProductByUPC(barCode);
if (product != null)
return product;
product = getProductByValueC(barCode);
if (product != null)
return product;
int prefixPosition = barCode.toUpperCase().indexOf("P");
if (prefixPosition > 0 && prefixPosition <= 3)
product = getProductByValueC(barCode.substring(prefixPosition + 1));
return product;
}
use of org.compiere.model.MProduct in project adempiere by adempiere.
the class CPOS method addOrUpdate.
// addOrUpdateLine
/**
* Save Line
* @param productId
* @param qtyOrdered
* @return
*/
public String addOrUpdate(int productId, BigDecimal qtyOrdered) {
String errorMessage = null;
try {
MProduct product = MProduct.get(ctx, productId);
if (product == null)
return "@No@ @InfoProduct@";
MProductPricing productPricing = new MProductPricing(productId, getC_BPartner_ID(), qtyOrdered, true, null);
productPricing.setM_PriceList_ID(getM_PriceList_ID());
productPricing.calculatePrice();
// Validate if exists a order
if (hasOrder()) {
addOrUpdateLine(product, qtyOrdered, productPricing);
} else {
return "@POS.MustCreateOrder@";
}
} catch (Exception e) {
errorMessage = e.getMessage();
}
//
return errorMessage;
}
Aggregations