use of org.compiere.model.MInventoryLine 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.MInventoryLine in project adempiere by adempiere.
the class Doc_Inventory method loadLines.
// loadDocumentDetails
/**
* Load Invoice Line
* @param inventory inventory
* @return DocLine Array
*/
private DocLine[] loadLines(MInventory inventory) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MInventoryLine[] lines = inventory.getLines(false);
for (int i = 0; i < lines.length; i++) {
MInventoryLine line = lines[i];
// nothing to post
if (line.getQtyBook().compareTo(line.getQtyCount()) == 0 && line.getQtyInternalUse().signum() == 0)
continue;
//
DocLine docLine = new DocLine(line, this);
BigDecimal Qty = line.getQtyInternalUse();
if (Qty.signum() != 0)
// Internal Use entered positive
Qty = Qty.negate();
else {
BigDecimal QtyBook = line.getQtyBook();
BigDecimal QtyCount = line.getQtyCount();
Qty = QtyCount.subtract(QtyBook);
}
// -5 => -5
docLine.setQty(Qty, false);
docLine.setReversalLine_ID(line.getReversalLine_ID());
log.fine(docLine.toString());
list.add(docLine);
}
// Return Array
DocLine[] dls = new DocLine[list.size()];
list.toArray(dls);
return dls;
}
use of org.compiere.model.MInventoryLine in project adempiere by adempiere.
the class CostEngine method clearAccounting.
/**
* clear Accounting
* @param accountSchema
* @param transaction
*/
public void clearAccounting(MAcctSchema accountSchema, MTransaction transaction) {
if (transaction.getM_InOutLine_ID() > 0) {
MInOutLine line = (MInOutLine) transaction.getM_InOutLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
// get Purchase matches
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
// get invoice matches
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
for (MMatchInv match : invoiceMatches) {
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), match, transaction.getM_Product_ID(), line.getDateAcct()))
return;
}
} else if (transaction.getC_ProjectIssue_ID() > 0) {
MProjectIssue line = (MProjectIssue) transaction.getC_ProjectIssue();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getMovementDate()))
return;
} else if (transaction.getM_InventoryLine_ID() > 0) {
MInventoryLine line = (MInventoryLine) transaction.getM_InventoryLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_MovementLine_ID() > 0) {
MMovementLine line = (MMovementLine) transaction.getM_MovementLine();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), line.getParent(), transaction.getM_Product_ID(), line.getDateAcct()))
return;
} else if (transaction.getM_ProductionLine_ID() > 0) {
MProductionLine line = (MProductionLine) transaction.getM_ProductionLine();
MProduction production = (MProduction) line.getM_ProductionPlan().getM_Production();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), production, transaction.getM_Product_ID(), production.getMovementDate()))
return;
} else if (transaction.getPP_Cost_Collector_ID() > 0) {
MPPCostCollector costCollector = (MPPCostCollector) transaction.getPP_Cost_Collector();
if (!clearAccounting(accountSchema, accountSchema.getM_CostType(), costCollector, costCollector.getM_Product_ID(), costCollector.getDateAcct()))
;
return;
} else {
log.info("Document does not exist :" + transaction);
}
}
use of org.compiere.model.MInventoryLine in project adempiere by adempiere.
the class AbstractCostingMethod method clearAccounting.
public void clearAccounting(MCostDetail cost) {
// Only can delete if period is open
MTransaction trx = new MTransaction(cost.getCtx(), cost.getM_Transaction_ID(), cost.get_TrxName());
IDocumentLine documentLine = trx.getDocumentLine();
MDocType docType = MDocType.get(cost.getCtx(), documentLine.getC_DocType_ID());
Boolean openPeriod = MPeriod.isOpen(cost.getCtx(), cost.getDateAcct(), docType.getDocBaseType(), cost.getAD_Org_ID());
if (!openPeriod)
return;
String sqldelete = "DELETE FROM Fact_Acct WHERE Record_ID =? AND AD_Table_ID=?";
int tableId = 0;
int recordId = 0;
if (cost.getC_OrderLine_ID() != 0) {
MOrderLine line = (MOrderLine) cost.getC_OrderLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InOutLine_ID() != 0) {
MInOutLine line = (MInOutLine) cost.getM_InOutLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_InventoryLine_ID() != 0) {
MInventoryLine line = (MInventoryLine) cost.getM_InventoryLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_MovementLine_ID() != 0) {
MMovementLine line = (MMovementLine) cost.getM_MovementLine();
line.getParent().setPosted(false);
line.getParent().saveEx();
recordId = line.getParent().get_ID();
tableId = line.getParent().get_Table_ID();
}
if (cost.getM_ProductionLine_ID() != 0) {
}
if (cost.getPP_Cost_Collector_ID() != 0) {
MPPCostCollector costCollector = (MPPCostCollector) cost.getPP_Cost_Collector();
costCollector.setPosted(false);
costCollector.saveEx();
recordId = costCollector.get_ID();
tableId = costCollector.get_Table_ID();
}
int no = DB.executeUpdateEx(sqldelete, new Object[] { recordId, tableId }, cost.get_TrxName());
}
use of org.compiere.model.MInventoryLine in project adempiere by adempiere.
the class InventoryUtil method createInventory.
public static MInventory createInventory(MMDocument doc, String trxName) {
Properties ctx = Env.getCtx();
int AD_Org_ID = getFirst_Org_ID();
MProduct product = getCreateProduct(doc);
MLocator locator = getCreateLocator(AD_Org_ID, doc.LocatorValue, doc.LocatorValue);
//
MInventory inv = new MInventory(ctx, 0, trxName);
inv.setAD_Org_ID(AD_Org_ID);
//inv.setIsInternalUseInventory(true); // TODO: arhipac: teo_sarca - add this column to trunk
inv.setMovementDate(doc.Date);
inv.setM_Warehouse_ID(locator.getM_Warehouse_ID());
setGeneratedTag(inv);
inv.saveEx();
//
MInventoryLine line = new MInventoryLine(inv, locator.get_ID(), product.get_ID(), 0, null, null);
line.setQtyInternalUse(doc.Qty);
line.setC_Charge_ID(getCreateCharge("junit-charge").get_ID());
line.saveEx();
//
doc.document = inv;
processDocument(doc, MInventory.DOCACTION_Complete, MInventory.DOCSTATUS_Completed);
if (!Util.isEmpty(doc.ASI)) {
line.load(trxName);
doc.scenario.registerASICode(doc.ASI, line.getM_AttributeSetInstance_ID(), line.getQtyInternalUse().signum() <= 0);
}
checkLineCosts(doc, line, doc.Qty.signum() >= 0);
return inv;
}
Aggregations