use of org.compiere.model.MMovementLine 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.MMovementLine 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.MMovementLine in project adempiere by adempiere.
the class InventoryUtil method createMovement.
public static MMovement createMovement(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);
MLocator locatorTo = getCreateLocator(AD_Org_ID, doc.LocatorValueTo, doc.LocatorValueTo);
//
MMovement m = new MMovement(ctx, 0, trxName);
m.setAD_Org_ID(AD_Org_ID);
m.setMovementDate(doc.Date);
m.saveEx();
//
MMovementLine line = new MMovementLine(m);
line.setM_Product_ID(product.get_ID());
line.setM_Locator_ID(locator.get_ID());
line.setM_LocatorTo_ID(locatorTo.get_ID());
line.setMovementQty(doc.Qty);
line.saveEx();
//
doc.document = m;
processDocument(doc, MMovement.DOCACTION_Complete, MMovement.DOCSTATUS_Completed);
checkLineCosts(doc, line, false);
return m;
}
use of org.compiere.model.MMovementLine in project adempiere by adempiere.
the class OrderDistributionReceipt method generate.
// saveSelection
/**************************************************************************
* Generate Movements
*/
public String generate(MiniTable miniTable, IStatusBar statusBar, String docActionSelected) {
String info = "";
log.info("DD_Order_ID=" + m_DD_Order_ID);
log.info("MovementDate" + m_MovementDate);
String trxName = Trx.createTrxName("MVG");
Trx trx = Trx.get(trxName, true);
// prevents from being called twice
setSelectionActive(false);
statusBar.setStatusLine(Msg.translate(Env.getCtx(), "M_Movement_ID"));
statusBar.setStatusDB(String.valueOf(getSelection().size()));
Properties m_ctx = Env.getCtx();
Timestamp movementDate = (Timestamp) m_MovementDate;
MDDOrder order = new MDDOrder(m_ctx, Integer.parseInt(m_DD_Order_ID.toString()), trxName);
MMovement movement = new MMovement(order, movementDate);
movement.saveEx();
ArrayList<Integer> ids = getSelection();
int i = 0;
for (int DD_OrderLine_ID : ids) {
MDDOrderLine oline = new MDDOrderLine(m_ctx, DD_OrderLine_ID, trxName);
MMovementLine line = new MMovementLine(movement);
line.setM_Product_ID(oline.getM_Product_ID());
BigDecimal QtyDeliver = (BigDecimal) miniTable.getValueAt(i, 1);
if (QtyDeliver == null | QtyDeliver.compareTo(oline.getQtyInTransit()) > 0)
throw new AdempiereException("Error in Qty");
line.setOrderLine(oline, QtyDeliver, true);
line.saveEx();
i++;
}
// Fails if there is a confirmation
if (!movement.processIt(MMovement.ACTION_Complete))
log.warning("Failed: " + movement);
movement.setDocStatus(MMovement.DOCACTION_Complete);
movement.setDocAction(MMovement.ACTION_Close);
movement.saveEx();
return info;
}
use of org.compiere.model.MMovementLine in project adempiere by adempiere.
the class ReplenishReportProduction method createMovements.
// createRequisition
/**
* Create Inventory Movements
*/
private void createMovements() {
int noMoves = 0;
String info = "";
//
MClient client = null;
MMovement move = null;
int M_Warehouse_ID = 0;
int M_WarehouseSource_ID = 0;
MWarehouse whSource = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenish("M_WarehouseSource_ID IS NOT NULL AND C_BPartner_ID > 0");
for (int i = 0; i < replenishs.length; i++) {
X_T_Replenish replenish = replenishs[i];
if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
client = MClient.get(getCtx(), whSource.getAD_Client_ID());
//
if (move == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
M_Warehouse_ID = replenish.getM_Warehouse_ID();
move = new MMovement(getCtx(), 0, get_TrxName());
move.setC_DocType_ID(p_C_DocType_ID);
move.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
// Set Org
move.setAD_Org_ID(whSource.getAD_Org_ID());
if (!move.save())
return;
log.fine(move.toString());
noMoves++;
info += " - " + move.getDocumentNo();
}
// To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
// From: Look-up Storage
MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
String MMPolicy = product.getMMPolicy();
MStorage[] storages = MStorage.getWarehouse(getCtx(), whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0, true, null, MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
//
BigDecimal target = replenish.getQtyToOrder();
for (int j = 0; j < storages.length; j++) {
MStorage storage = storages[j];
if (storage.getQtyOnHand().signum() <= 0)
continue;
BigDecimal moveQty = target;
if (storage.getQtyOnHand().compareTo(moveQty) < 0)
moveQty = storage.getQtyOnHand();
//
MMovementLine line = new MMovementLine(move);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setMovementQty(moveQty);
if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
// from
line.setM_Locator_ID(storage.getM_Locator_ID());
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
// to
line.setM_LocatorTo_ID(M_LocatorTo_ID);
line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
line.save();
//
target = target.subtract(moveQty);
if (target.signum() == 0)
break;
}
}
if (replenishs.length == 0) {
m_info = "No Source Warehouse";
log.warning(m_info);
} else {
m_info = "#" + noMoves + info;
log.info(m_info);
}
}
Aggregations