📄 mcostdetail.java
字号:
* @param ctx context
* @param M_CostDetail_ID id
* @param trxName trx
*/
public MCostDetail (Properties ctx, int M_CostDetail_ID, String trxName)
{
super (ctx, M_CostDetail_ID, trxName);
if (M_CostDetail_ID == 0)
{
// setC_AcctSchema_ID (0);
// setM_Product_ID (0);
setM_AttributeSetInstance_ID (0);
// setC_OrderLine_ID (0);
// setM_InOutLine_ID(0);
// setC_InvoiceLine_ID (0);
setProcessed (false);
setAmt (Env.ZERO);
setQty (Env.ZERO);
setIsSOTrx (false);
setDeltaAmt (Env.ZERO);
setDeltaQty (Env.ZERO);
}
} // MCostDetail
/**
* Load Constructor
* @param ctx context
* @param rs result set
* @param trxName trx
*/
public MCostDetail (Properties ctx, ResultSet rs, String trxName)
{
super (ctx, rs, trxName);
} // MCostDetail
/**
* New Constructor
* @param as accounting schema
* @param AD_Org_ID org
* @param M_Product_ID product
* @param M_AttributeSetInstance_ID asi
* @param M_CostElement_ID optional cost element for Freight
* @param Amt amt
* @param Qty qty
* @param Description optional description
*/
public MCostDetail (MAcctSchema as, int AD_Org_ID,
int M_Product_ID, int M_AttributeSetInstance_ID,
int M_CostElement_ID, BigDecimal Amt, BigDecimal Qty,
String Description, String trxName)
{
this (as.getCtx(), 0, trxName);
setClientOrg(as.getAD_Client_ID(), AD_Org_ID);
setC_AcctSchema_ID (as.getC_AcctSchema_ID());
setM_Product_ID (M_Product_ID);
setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
//
setM_CostElement_ID(M_CostElement_ID);
//
setAmt (Amt);
setQty (Qty);
setDescription(Description);
} // MCostDetail
/**
* Set Amt
* @param Amt amt
*/
public void setAmt (BigDecimal Amt)
{
if (isProcessed())
throw new IllegalStateException("Cannot change Amt - processed");
if (Amt == null)
super.setAmt (Env.ZERO);
else
super.setAmt (Amt);
} // setAmt
/**
* Set Qty
* @param Qty qty
*/
public void setQty (BigDecimal Qty)
{
if (isProcessed())
throw new IllegalStateException("Cannot change Qty - processed");
if (Qty == null)
super.setQty (Env.ZERO);
else
super.setQty (Qty);
} // setQty
/**
* Is Order
* @return true if order line
*/
public boolean isOrder()
{
return getC_OrderLine_ID() != 0;
} // isOrder
/**
* Is Invoice
* @return true if invoice line
*/
public boolean isInvoice()
{
return getC_InvoiceLine_ID() != 0;
} // isInvoice
/**
* Is Shipment
* @return true if sales order shipment
*/
public boolean isShipment()
{
return isSOTrx() && getM_InOutLine_ID() != 0;
} // isShipment
/**
* Is this a Delta Record (previously processed)?
* @return true if delta is not null
*/
public boolean isDelta()
{
return !(getDeltaAmt().signum() == 0
&& getDeltaQty().signum() == 0);
} // isDelta
/**
* After Save
* @param newRecord new
* @param success success
* @return true
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
return true;
} // afterSave
/**
* Before Delete
* @return false if processed
*/
protected boolean beforeDelete ()
{
return !isProcessed();
} // beforeDelete
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MCostDetail[");
sb.append (get_ID());
if (getC_OrderLine_ID() != 0)
sb.append (",C_OrderLine_ID=").append (getC_OrderLine_ID());
if (getM_InOutLine_ID() != 0)
sb.append (",M_InOutLine_ID=").append (getM_InOutLine_ID());
if (getC_InvoiceLine_ID() != 0)
sb.append (",C_InvoiceLine_ID=").append (getC_InvoiceLine_ID());
if (getC_ProjectIssue_ID() != 0)
sb.append (",C_ProjectIssue_ID=").append (getC_ProjectIssue_ID());
if (getM_MovementLine_ID() != 0)
sb.append (",M_MovementLine_ID=").append (getM_MovementLine_ID());
if (getM_InventoryLine_ID() != 0)
sb.append (",M_InventoryLine_ID=").append (getM_InventoryLine_ID());
if (getM_ProductionLine_ID() != 0)
sb.append (",M_ProductionLine_ID=").append (getM_ProductionLine_ID());
sb.append(",Amt=").append(getAmt())
.append(",Qty=").append(getQty());
if (isDelta())
sb.append(",DeltaAmt=").append(getDeltaAmt())
.append(",DeltaQty=").append(getDeltaQty());
sb.append ("]");
return sb.toString ();
} // toString
/**************************************************************************
* Process Cost Detail Record.
* The record is saved if processed.
* @return true if processed
*/
public synchronized boolean process()
{
if (isProcessed())
{
log.info("already processed");
return true;
}
boolean ok = false;
// get costing level for product
MAcctSchema as = new MAcctSchema (getCtx(), getC_AcctSchema_ID(), null);
String CostingLevel = as.getCostingLevel();
MProduct product = MProduct.get(getCtx(), getM_Product_ID());
MProductCategoryAcct pca = MProductCategoryAcct.get (getCtx(),
product.getM_Product_Category_ID(), getC_AcctSchema_ID(), null);
if (pca.getCostingLevel() != null)
CostingLevel = pca.getCostingLevel();
// Org Element
int Org_ID = getAD_Org_ID();
int M_ASI_ID = getM_AttributeSetInstance_ID();
if (MAcctSchema.COSTINGLEVEL_Client.equals(CostingLevel))
{
Org_ID = 0;
M_ASI_ID = 0;
}
else if (MAcctSchema.COSTINGLEVEL_Organization.equals(CostingLevel))
M_ASI_ID = 0;
else if (MAcctSchema.COSTINGLEVEL_BatchLot.equals(CostingLevel))
Org_ID = 0;
// Create Material Cost elements
if (getM_CostElement_ID() == 0)
{
MCostElement[] ces = MCostElement.getCostingMethods(this);
for (int i = 0; i < ces.length; i++)
{
MCostElement ce = ces[i];
ok = process (as, product, ce, Org_ID, M_ASI_ID);
if (!ok)
break;
}
} // Material Cost elements
else
{
MCostElement ce = MCostElement.get(getCtx(), getM_CostElement_ID());
ok = process (as, product, ce, Org_ID, M_ASI_ID);
}
// Save it
if (ok)
{
setDeltaAmt(null);
setDeltaQty(null);
setProcessed(true);
ok = save();
}
log.info(ok + " - " + toString());
return ok;
} // process
/**
* Process cost detail for cost record
* @param as accounting schema
* @param product product
* @param ce cost element
* @param Org_ID org - corrected for costing level
* @param M_ASI_ID - asi corrected for costing level
* @return true if cost ok
*/
private boolean process (MAcctSchema as, MProduct product, MCostElement ce,
int Org_ID, int M_ASI_ID)
{
MCost cost = MCost.get(product, M_ASI_ID, as,
Org_ID, ce.getM_CostElement_ID());
if (cost == null)
cost = new MCost(product, M_ASI_ID,
as, Org_ID, ce.getM_CostElement_ID());
BigDecimal qty = getQty();
BigDecimal amt = getAmt();
int precision = as.getCostingPrecision();
BigDecimal price = amt;
if (qty.signum() != 0)
price = amt.divide(qty, precision, BigDecimal.ROUND_HALF_UP);
/** All Costing Methods
if (ce.isAverageInvoice())
else if (ce.isAveragePO())
else if (ce.isFifo())
else if (ce.isLifo())
else if (ce.isLastInvoice())
else if (ce.isLastPOPrice())
else if (ce.isStandardCosting())
else if (ce.isUserDefined())
else if (!ce.isCostingMethod())
**/
// *** Purchase Order Detail Record ***
if (getC_OrderLine_ID() != 0)
{
if (ce.isAveragePO())
{
cost.setWeightedAverage(amt, qty);
log.finer("PO - AveragePO - " + cost);
}
else if (ce.isLastPOPrice())
{
if (qty.signum() != 0)
cost.setCurrentCostPrice(price);
else
{
BigDecimal cCosts = cost.getCurrentCostPrice().add(amt);
cost.setCurrentCostPrice(cCosts);
}
cost.add(amt, qty);
log.finer("PO - LastPO - " + cost);
}
else if (ce.isUserDefined())
{
// Interface
log.finer("PO - UserDef - " + cost);
}
else if (!ce.isCostingMethod())
{
log.finer("PO - " + ce + " - " + cost);
}
// else
// log.warning("PO - " + ce + " - " + cost);
}
// *** AP Invoice Detail Record ***
else if (getC_InvoiceLine_ID() != 0)
{
if (ce.isAverageInvoice())
{
cost.setWeightedAverage(amt, qty);
log.finer("Inv - AverageInv - " + cost);
}
else if (ce.isFifo()
|| ce.isLifo())
{
// Real ASI - costing level Org
MCostQueue cq = MCostQueue.get(product, getM_AttributeSetInstance_ID(),
as, Org_ID, ce.getM_CostElement_ID(), get_TrxName());
cq.setCosts(amt, qty, precision);
cq.save();
// Get Costs - costing level Org/ASI
MCostQueue[] cQueue = MCostQueue.getQueue(product, M_ASI_ID,
as, Org_ID, ce, get_TrxName());
if (cQueue != null && cQueue.length > 0)
cost.setCurrentCostPrice(cQueue[0].getCurrentCostPrice());
cost.add(amt, qty);
log.finer("Inv - FiFo/LiFo - " + cost);
}
else if (ce.isLastInvoice())
{
if (qty.signum() != 0)
cost.setCurrentCostPrice(price);
else
{
BigDecimal cCosts = cost.getCurrentCostPrice().add(amt);
cost.setCurrentCostPrice(cCosts);
}
cost.add(amt, qty);
log.finer("Inv - LastInv - " + cost);
}
else if (ce.isStandardCosting())
{
if (cost.getCurrentCostPrice().signum() == 0)
{
cost.setCurrentCostPrice(price);
// seed initial price
if (cost.getCurrentCostPrice().signum() == 0
&& cost.get_ID() == 0)
cost.setCurrentCostPrice(
MCost.getSeedCosts(product, M_ASI_ID,
as, Org_ID, ce.getCostingMethod(), getC_OrderLine_ID()));
}
cost.add(amt, qty);
log.finer("Inv - Standard - " + cost);
}
else if (ce.isUserDefined())
{
// Interface
cost.add(amt, qty);
log.finer("Inv - UserDef - " + cost);
}
else if (!ce.isCostingMethod()) // Cost Adjustments
{
BigDecimal cCosts = cost.getCurrentCostPrice().add(amt);
cost.setCurrentCostPrice(cCosts);
cost.add(amt, qty);
log.finer("Inv - none - " + cost);
}
// else
// log.warning("Inv - " + ce + " - " + cost);
}
// *** Qty Adjustment Detail Record ***
else if (getM_InOutLine_ID() != 0 // AR Shipment Detail Record
|| getM_MovementLine_ID() != 0
|| getM_InventoryLine_ID() != 0
|| getM_ProductionLine_ID() != 0
|| getC_ProjectIssue_ID() != 0)
{
boolean addition = qty.signum() > 0;
//
if (ce.isAverageInvoice())
{
if (addition)
cost.setWeightedAverage(amt, qty);
else
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - AverageInv - " + cost);
}
else if (ce.isAveragePO())
{
if (addition)
cost.setWeightedAverage(amt, qty);
else
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - AveragePO - " + cost);
}
else if (ce.isFifo() || ce.isLifo())
{
if (addition)
{
// Real ASI - costing level Org
MCostQueue cq = MCostQueue.get(product, getM_AttributeSetInstance_ID(),
as, Org_ID, ce.getM_CostElement_ID(), get_TrxName());
cq.setCosts(amt, qty, precision);
cq.save();
}
else
{
// Adjust Queue - costing level Org/ASI
MCostQueue.adjustQty(product, M_ASI_ID,
as, Org_ID, ce, qty.negate(), get_TrxName());
}
// Get Costs - costing level Org/ASI
MCostQueue[] cQueue = MCostQueue.getQueue(product, M_ASI_ID,
as, Org_ID, ce, get_TrxName());
if (cQueue != null && cQueue.length > 0)
cost.setCurrentCostPrice(cQueue[0].getCurrentCostPrice());
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - FiFo/Lifo - " + cost);
}
else if (ce.isLastInvoice())
{
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - LastInv - " + cost);
}
else if (ce.isLastPOPrice())
{
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - LastPO - " + cost);
}
else if (ce.isStandardCosting())
{
if (addition)
{
cost.add(amt, qty);
// Initial
if (cost.getCurrentCostPrice().signum() == 0
&& cost.get_ID() == 0)
cost.setCurrentCostPrice(price);
}
else
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - Standard - " + cost);
}
else if (ce.isUserDefined())
{
// Interface
if (addition)
cost.add(amt, qty);
else
cost.setCurrentQty(cost.getCurrentQty().add(qty));
log.finer("QtyAdjust - UserDef - " + cost);
}
else if (!ce.isCostingMethod())
{
// Should not happen
log.finer("QtyAdjust - ?none? - " + cost);
}
else
log.warning("QtyAdjust - " + ce + " - " + cost);
}
else // unknown or no id
{
log.warning("Unknown Type: " + toString());
return false;
}
return cost.save();
} // process
} // MCostDetail
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -