use of org.compiere.model.MInOutLine 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.MInOutLine in project adempiere by adempiere.
the class ReverseTheSalesTransaction method cancelShipments.
private void cancelShipments(MInOut[] sourceShipments) {
for (MInOut sourceShipment : sourceShipments) {
MRMA rma = new MRMA(getCtx(), 0, get_TrxName());
rma.setM_InOut_ID(sourceShipment.getM_InOut_ID());
rma.setAD_Org_ID(sourceShipment.getAD_Org_ID());
rma.setM_RMAType_ID(getRMATypeId());
rma.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
rma.setName(sourceShipment.getDocumentInfo());
rma.setIsSOTrx(true);
rma.setSalesRep_ID(sourceShipment.getSalesRep_ID());
rma.setC_DocType_ID(MDocType.getDocTypeBaseOnSubType(sourceShipment.getAD_Org_ID(), MDocType.DOCBASETYPE_SalesOrder, MDocType.DOCSUBTYPESO_ReturnMaterial));
rma.setDocStatus(DocAction.STATUS_Drafted);
rma.setDocAction(DocAction.ACTION_Complete);
rma.saveEx();
MInOut customerReturn = new MInOut(getCtx(), 0, get_TrxName());
PO.copyValues(sourceShipment, customerReturn);
customerReturn.setDocumentNo(null);
customerReturn.setM_RMA_ID(rma.getM_RMA_ID());
customerReturn.setIsSOTrx(true);
customerReturn.setC_BPartner_ID(sourceShipment.getC_BPartner_ID());
customerReturn.setC_Order_ID(-1);
for (MDocType documentType : MDocType.getOfDocBaseType(getCtx(), MDocType.DOCBASETYPE_MaterialReceipt)) if (documentType.isSOTrx())
customerReturn.setC_DocType_ID();
customerReturn.setMovementType(MInOut.MOVEMENTTYPE_CustomerReturns);
customerReturn.setDocStatus(DocAction.STATUS_Drafted);
customerReturn.setDocAction(DocAction.ACTION_Complete);
customerReturn.setProcessed(false);
customerReturn.saveEx();
for (MInOutLine sourceShipmentLine : sourceShipment.getLines()) {
MRMALine rmaLine = new MRMALine(getCtx(), 0, get_TrxName());
rmaLine.setM_RMA_ID(rma.getM_RMA_ID());
rmaLine.setAD_Org_ID(sourceShipmentLine.getAD_Org_ID());
rmaLine.setM_InOutLine_ID(sourceShipmentLine.getM_InOutLine_ID());
rmaLine.setQty(sourceShipmentLine.getMovementQty());
rmaLine.saveEx();
MInOutLine customerReturnLine = new MInOutLine(getCtx(), 0, get_TrxName());
customerReturnLine.setM_InOut_ID(customerReturn.getM_InOut_ID());
customerReturnLine.setM_RMALine_ID(rmaLine.getM_RMALine_ID());
customerReturnLine.setM_Product_ID(rmaLine.getM_Product_ID());
customerReturnLine.setM_Locator_ID(sourceShipmentLine.getM_Locator_ID());
customerReturnLine.setMovementQty(rmaLine.getQty());
customerReturnLine.saveEx();
}
rma.processIt(DocAction.ACTION_Complete);
rma.saveEx();
addLog(rma.getDocumentInfo());
if (customerReturn.getC_DocType().isShipConfirm() && isShipReceiptConfirmation()) {
customerReturn.processIt(DocAction.STATUS_InProgress);
customerReturn.saveEx();
for (MInOutConfirm confirm : customerReturn.getConfirmations(true)) {
for (MInOutLineConfirm confirmLine : confirm.getLines(true)) {
confirmLine.setConfirmedQty(confirmLine.getTargetQty());
confirmLine.saveEx();
}
confirm.processIt(DocAction.ACTION_Complete);
confirm.saveEx();
addLog(confirm.getDocumentInfo());
}
}
customerReturn.processIt(DocAction.STATUS_Completed);
customerReturn.saveEx();
addLog(customerReturn.getDocumentInfo());
customerReturns.add(customerReturn);
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class Doc_InOut method loadLines.
// loadDocumentDetails
/**
* Load InOut Line
* @param inout shipment/receipt
* @return DocLine Array
*/
private DocLine[] loadLines(MInOut inout) {
ArrayList<DocLine> list = new ArrayList<DocLine>();
MInOutLine[] lines = inout.getLines(false);
for (int i = 0; i < lines.length; i++) {
MInOutLine line = lines[i];
if (line.isDescription() || line.getM_Product_ID() == 0 || line.getMovementQty().signum() == 0) {
log.finer("Ignored: " + line);
continue;
}
DocLine docLine = new DocLine(line, this);
BigDecimal Qty = line.getMovementQty();
docLine.setReversalLine_ID(line.getReversalLine_ID());
// sets Trx and Storage Qty
docLine.setQty(Qty, getDocumentType().equals(DOCTYPE_MatShipment));
//Define if Outside Processing
String sql = "SELECT PP_Cost_Collector_ID FROM C_OrderLine WHERE C_OrderLine_ID=? AND PP_Cost_Collector_ID IS NOT NULL";
int PP_Cost_Collector_ID = DB.getSQLValueEx(getTrxName(), sql, new Object[] { line.getC_OrderLine_ID() });
docLine.setPP_Cost_Collector_ID(PP_Cost_Collector_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.MInOutLine in project adempiere by adempiere.
the class Doc_MatchPO method createFacts.
// getBalance
/**
* Create Facts (the accounting logic) for
* MXP.
* <pre>
* Product PPV <difference>
* PPV_Offset <difference>
* </pre>
* @param as accounting schema
* @return Fact
*/
public ArrayList<Fact> createFacts(MAcctSchema as) {
ArrayList<Fact> facts = new ArrayList<Fact>();
//
if (// Nothing to do if no Product
getM_Product_ID() == 0 || getQty().signum() == 0 || // No posting if not matched to Shipment
m_M_InOutLine_ID == 0) {
log.fine("No Product/Qty - M_Product_ID=" + getM_Product_ID() + ",Qty=" + getQty());
return facts;
}
// create Fact Header
Fact fact = new Fact(this, as, Fact.POST_Actual);
setC_Currency_ID(as.getC_Currency_ID());
boolean isInterOrg = isInterOrg(as);
// Purchase Order Line
BigDecimal poCost = m_oLine.getPriceCost();
if (poCost == null || poCost.signum() == 0)
poCost = m_oLine.getPriceActual();
MInOutLine receiptLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
MInOut inOut = receiptLine.getParent();
boolean isReturnTrx = inOut.getMovementType().equals(X_M_InOut.MOVEMENTTYPE_VendorReturns);
// calculate po cost
// Delivered so far
poCost = poCost.multiply(getQty());
// Different currency
if (m_oLine.getC_Currency_ID() != as.getC_Currency_ID()) {
MOrder order = m_oLine.getParent();
Timestamp dateAcct = order.getDateAcct();
BigDecimal rate = MConversionRate.getRate(order.getC_Currency_ID(), as.getC_Currency_ID(), dateAcct, order.getC_ConversionType_ID(), m_oLine.getAD_Client_ID(), m_oLine.getAD_Org_ID());
if (rate == null) {
p_Error = "Purchase Order not convertible - " + as.getName();
return null;
}
poCost = poCost.multiply(rate);
if (poCost.scale() > as.getCostingPrecision())
poCost = poCost.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP);
}
// Calculate PPV for standard costing
//get standard cost and also make sure cost for other costing method is updated
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MCostType ct = MCostType.get(as, getM_Product_ID(), getAD_Org_ID());
String costingMethod = ct.getCostingMethod();
MInOutLine ioLine = new MInOutLine(getCtx(), m_M_InOutLine_ID, getTrxName());
BigDecimal costs = Env.ZERO;
for (MTransaction transaction : MTransaction.getByInOutLine(ioLine)) {
MCostElement element = MCostElement.getByMaterialCostElementType(transaction);
MCostDetail cd = MCostDetail.getByTransaction(ioLine, transaction, as.getC_AcctSchema_ID(), ct.getM_CostType_ID(), element.getM_CostElement_ID());
if (cd != null)
costs = costs.add(MCostDetail.getTotalCost(cd, as));
}
if (MCostType.COSTINGMETHOD_StandardCosting.equals(costingMethod)) {
// No Costs yet - no PPV
if (costs == null || costs.signum() == 0) {
// TODO make these a translatable message
p_Error = "No Standard Cost information was found for " + product.getName() + ". Please add a standard cost for material and repost this document.";
log.log(Level.SEVERE, p_Error);
return null;
}
// Difference
BigDecimal difference = poCost.subtract(costs.setScale(as.getCostingPrecision(), BigDecimal.ROUND_HALF_UP));
// Nothing to post
if (difference.signum() == 0) {
log.log(Level.FINE, "No Cost Difference for M_Product_ID=" + getM_Product_ID());
return facts;
}
// Product PPV
FactLine cr = fact.createLine(null, m_pc.getAccount(ProductCost.ACCTTYPE_P_PPV, as), as.getC_Currency_ID(), isReturnTrx ? difference.negate() : difference);
if (cr != null) {
cr.setQty(isReturnTrx ? getQty().negate() : getQty());
cr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
cr.setC_Activity_ID(m_oLine.getC_Activity_ID());
cr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
cr.setC_Project_ID(m_oLine.getC_Project_ID());
cr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
cr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
cr.setC_UOM_ID(m_oLine.getC_UOM_ID());
cr.setUser1_ID(m_oLine.getUser1_ID());
cr.setUser2_ID(m_oLine.getUser2_ID());
cr.setUser3_ID(m_oLine.getUser3_ID());
cr.setUser4_ID(m_oLine.getUser4_ID());
}
// PPV Offset
FactLine dr = fact.createLine(null, getAccount(Doc.ACCTTYPE_PPVOffset, as), as.getC_Currency_ID(), isReturnTrx ? difference : difference.negate());
if (dr != null) {
dr.setQty(isReturnTrx ? getQty() : getQty().negate());
dr.setC_BPartner_ID(m_oLine.getC_BPartner_ID());
dr.setC_Activity_ID(m_oLine.getC_Activity_ID());
dr.setC_Campaign_ID(m_oLine.getC_Campaign_ID());
dr.setC_Project_ID(m_oLine.getC_Project_ID());
dr.setC_ProjectPhase_ID(m_oLine.getC_ProjectPhase_ID());
dr.setC_ProjectTask_ID(m_oLine.getC_ProjectTask_ID());
dr.setC_UOM_ID(m_oLine.getC_UOM_ID());
dr.setUser1_ID(m_oLine.getUser1_ID());
dr.setUser2_ID(m_oLine.getUser2_ID());
dr.setUser3_ID(m_oLine.getUser3_ID());
dr.setUser4_ID(m_oLine.getUser4_ID());
}
// Avoid usage of clearing accounts
// If both accounts Purchase Price Variance and Purchase Price Variance Offset are equal
// then remove the posting
// PPV
MAccount acct_db = dr.getAccount();
// PPV Offset
MAccount acct_cr = cr.getAccount();
if ((!as.isPostIfClearingEqual()) && acct_db.equals(acct_cr) && (!isInterOrg)) {
BigDecimal debit = dr.getAmtSourceDr();
BigDecimal credit = cr.getAmtSourceCr();
if (debit.compareTo(credit) == 0) {
fact.remove(dr);
fact.remove(cr);
}
}
// End Avoid usage of clearing accounts
//
facts.add(fact);
return facts;
} else {
return facts;
}
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class GenerateCostDetail method generateCostDetail.
public void generateCostDetail(MAcctSchema accountSchema, MCostType costType, MCostElement costElement, MTransaction transaction) {
//Create Cost Detail for this Transaction
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
// invoices
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
//get purchase matches
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
orderMatches.stream().forEach(match -> {
if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
});
//get invoice matches
List<MMatchInv> invoiceMatches = MMatchInv.getInOutLine(line);
invoiceMatches.forEach(match -> {
if (match.getM_Product_ID() == transaction.getM_Product_ID() && match.getDateAcct().after(getAccountDate()) && match.getDateAcct().before(getAccountDateTo())) {
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
});
}
//get landed allocation cost
MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID()).stream().forEach(allocation -> {
if (allocation.getDateAcct().after(getAccountDate()) && allocation.getDateAcct().before(getAccountDateTo()))
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
});
}
}
Aggregations