use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class AverageInvoiceCostingMethod method updateAmountCost.
/**
* Update Cost Amt
*/
public void updateAmountCost() {
if (movementQuantity.signum() > 0) {
costDetail.setCostAmt(costDetail.getAmt().subtract(costDetail.getCostAdjustment()));
costDetail.setCostAmtLL(costDetail.getAmtLL().subtract(costDetail.getCostAdjustmentLL()));
} else if (movementQuantity.signum() < 0) {
costDetail.setCostAmt(costDetail.getAmt().add(adjustCost));
costDetail.setCostAmtLL(costDetail.getAmtLL().add(adjustCostLowerLevel));
}
costDetail.setCumulatedQty(getNewAccumulatedQuantity(lastCostDetail));
costDetail.setCumulatedAmt(getNewAccumulatedAmount(lastCostDetail));
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(currentCostPrice);
costDetail.setCurrentCostPriceLL(currentCostPriceLowerLevel);
// set the id for model
final String idColumnName = CostEngine.getIDColumnName(model);
costDetail.set_ValueOfColumn(idColumnName, CostEngine.getIDColumn(model));
if (model instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) model;
costDetail.setC_OrderLine_ID(ioLine.getC_OrderLine_ID());
// IMPORTANT : reset possible provision purchase cost processed
costDetail.setC_InvoiceLine_ID(0);
}
if (model instanceof MMatchInv && costDetail.getM_InOutLine_ID() == 0) {
MMatchInv iMatch = (MMatchInv) model;
costDetail.setM_InOutLine_ID(iMatch.getM_InOutLine_ID());
}
if (model instanceof MMatchPO && costDetail.getM_InOutLine_ID() == 0) {
MMatchPO poMatch = (MMatchPO) model;
costDetail.setM_InOutLine_ID(poMatch.getM_InOutLine_ID());
}
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costDetail.setM_InOutLine_ID(allocation.getM_InOutLine_ID());
costDetail.setC_InvoiceLine_ID(allocation.getC_InvoiceLine_ID());
costDetail.setC_LandedCostAllocation_ID(allocation.getC_LandedCostAllocation_ID());
costDetail.setProcessed(false);
}
costDetail.saveEx();
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class AveragePOCostingMethod method updateAmountCost.
/**
* Update Cost Amt
*/
public void updateAmountCost() {
if (movementQuantity.signum() > 0) {
costDetail.setCostAmt(costDetail.getAmt().subtract(costDetail.getCostAdjustment()));
costDetail.setCostAmtLL(costDetail.getAmtLL().subtract(costDetail.getCostAdjustmentLL()));
} else if (movementQuantity.signum() < 0) {
costDetail.setCostAmt(costDetail.getAmt().add(adjustCost));
costDetail.setCostAmtLL(costDetail.getAmtLL().add(adjustCostLowerLevel));
}
costDetail.setCumulatedQty(getNewAccumulatedQuantity(lastCostDetail));
costDetail.setCumulatedAmt(getNewAccumulatedAmount(lastCostDetail));
costDetail.setCumulatedAmtLL(getNewAccumulatedAmountLowerLevel(lastCostDetail));
costDetail.setCurrentCostPrice(currentCostPrice);
costDetail.setCurrentCostPriceLL(currentCostPriceLowerLevel);
// set the id for model
final String idColumnName = CostEngine.getIDColumnName(model);
costDetail.set_ValueOfColumn(idColumnName, CostEngine.getIDColumn(model));
if (model instanceof MInOutLine) {
MInOutLine ioLine = (MInOutLine) model;
costDetail.setC_OrderLine_ID(ioLine.getC_OrderLine_ID());
// IMPORTANT : reset possible provision purchase cost processed
costDetail.setC_InvoiceLine_ID(0);
}
if (model instanceof MMatchPO && costDetail.getM_InOutLine_ID() == 0) {
MMatchPO poMatch = (MMatchPO) model;
costDetail.setM_InOutLine_ID(poMatch.getM_InOutLine_ID());
}
if (model instanceof MLandedCostAllocation) {
MLandedCostAllocation allocation = (MLandedCostAllocation) model;
costDetail.setM_InOutLine_ID(allocation.getM_InOutLine_ID());
costDetail.setC_InvoiceLine_ID(allocation.getC_InvoiceLine_ID());
costDetail.setProcessed(false);
}
costDetail.saveEx();
}
use of org.compiere.model.MInOutLine in project adempiere by adempiere.
the class AveragePOCostingMethod method adjustCostDetail.
/**
* Recalculate Cost Detail
* @param costDetail
*/
public void adjustCostDetail(MCostDetail costDetail) {
Properties ctx = costDetail.getCtx();
String trxName = costDetail.get_TrxName();
int transactionId = costDetail.getM_Transaction_ID();
int clientId = costDetail.getAD_Client_ID();
MTransaction transaction = new MTransaction(ctx, transactionId, trxName);
MCostType costType = (MCostType) costDetail.getM_CostType();
MCostElement costElement = (MCostElement) costDetail.getM_CostElement();
MAcctSchema accountSchema = (MAcctSchema) costDetail.getC_AcctSchema();
CostEngineFactory.getCostEngine(accountSchema.getAD_Client_ID()).clearAccounting(accountSchema, transaction);
if (MTransaction.MOVEMENTTYPE_VendorReceipts.equals(transaction.getMovementType())) {
MInOutLine line = (MInOutLine) transaction.getDocumentLine();
if (MCostElement.COSTELEMENTTYPE_Material.equals(costElement.getCostElementType())) {
if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, line, true);
} else if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() != 0 && costDetail.getC_OrderLine_ID() > 0) {
List<MMatchPO> orderMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : orderMatches) {
if (match.getM_InOutLine_ID() == line.getM_InOutLine_ID() && match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
} else if (costDetail.getM_InOutLine_ID() > 0 && costDetail.getQty().signum() == 0 && costDetail.getC_OrderLine_ID() > 0) {
List<MMatchPO> poMatches = MMatchPO.getInOutLine(line);
for (MMatchPO match : poMatches) {
if (match.getM_Product_ID() == transaction.getM_Product_ID()) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, match, true);
}
}
}
}
for (MLandedCostAllocation allocation : MLandedCostAllocation.getOfInOutline(line, costElement.getM_CostElement_ID())) {
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, allocation, true);
}
} else
CostEngineFactory.getCostEngine(clientId).createCostDetail(accountSchema, costType, costElement, transaction, transaction.getDocumentLine(), true);
}
use of org.compiere.model.MInOutLine 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.MInOutLine in project adempiere by adempiere.
the class InOutCreateInvoice method doIt.
// prepare
/**
* Create Invoice.
* @return document no
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("M_InOut_ID=" + p_M_InOut_ID + ", M_PriceList_ID=" + p_M_PriceList_ID + ", InvoiceDocumentNo=" + p_InvoiceDocumentNo);
if (p_M_InOut_ID == 0)
throw new IllegalArgumentException("No Shipment");
//
MInOut ship = new MInOut(getCtx(), p_M_InOut_ID, get_TrxName());
if (ship.get_ID() == 0)
throw new IllegalArgumentException("Shipment not found");
if (!MInOut.DOCSTATUS_Completed.equals(ship.getDocStatus()))
throw new IllegalArgumentException("Shipment not completed");
MInvoice invoice = new MInvoice(ship, null);
// Should not override pricelist for RMA
if (p_M_PriceList_ID != 0 && ship.getM_RMA_ID() == 0)
invoice.setM_PriceList_ID(p_M_PriceList_ID);
if (p_InvoiceDocumentNo != null && p_InvoiceDocumentNo.length() > 0)
invoice.setDocumentNo(p_InvoiceDocumentNo);
if (!invoice.save())
throw new IllegalArgumentException("Cannot save Invoice");
MInOutLine[] shipLines = ship.getLines(false);
for (int i = 0; i < shipLines.length; i++) {
MInOutLine sLine = shipLines[i];
MInvoiceLine line = new MInvoiceLine(invoice);
line.setShipLine(sLine);
if (sLine.sameOrderLineUOM())
line.setQtyEntered(sLine.getQtyEntered());
else
line.setQtyEntered(sLine.getMovementQty());
line.setQtyInvoiced(sLine.getMovementQty());
if (!line.save())
throw new IllegalArgumentException("Cannot save Invoice Line");
}
return invoice.getDocumentNo();
}
Aggregations