Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/RCandidate'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vienna-PRU committed Dec 2, 2022
2 parents 0ccb94a + 9a15ef2 commit 1c53fde
Show file tree
Hide file tree
Showing 13 changed files with 2,748 additions and 2,445 deletions.
4 changes: 3 additions & 1 deletion ModelLibrary/Classes/CostingCheck.cs
Expand Up @@ -52,6 +52,9 @@ public class CostingCheck
private StringBuilder query = new StringBuilder();
public int M_Transaction_ID = 0, M_TransactionTo_ID = 0;
public string errorMessage = String.Empty;
public decimal? onHandQty = null;
public bool IsCostCalculationfromProcess = false;
public decimal? currentQtyonQueue = null;

/// <summary>
/// Constructor
Expand Down Expand Up @@ -152,7 +155,6 @@ public void ResetProperty()
Fifo_ID = 0;
costinglevel = String.Empty;
MMPolicy = String.Empty;
isReversal = null;
isMatchFromForm = "N";
movementDate = null;
query.Clear();
Expand Down
83 changes: 70 additions & 13 deletions ModelLibrary/Model/MCostDetail.cs
Expand Up @@ -242,6 +242,7 @@ public bool UpdateProductCost(String windowName, MCostDetail cd, MAcctSchema acc
int costElementId = 0;
MClient client = MClient.Get(GetCtx(), cd.GetAD_Client_ID());
int M_Warehouse_ID = 0; // is used to calculate cost with warehouse level or not
costingCheck.IsCostCalculationfromProcess = optionalStrCd == "process" ? true : false;

if (product != null)
{
Expand Down Expand Up @@ -1229,7 +1230,7 @@ AND CAST(cel.M_Ref_CostElement AS INTEGER) IN (SELECT M_CostElement_ID FROM M_C

if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(C_LandedCostAllocation_ID) FROM C_LandedCostAllocation WHERE C_InvoiceLine_ID = " + GetC_InvoiceLine_ID(), null, Get_Trx())) <= 0)
{
if (GetC_OrderLine_ID() == 0) // if invoice created without orderline then no impact on cost
if (GetC_OrderLine_ID() == 0) // if invoice created without orderline then no impact on cost (Treat as Discount)
{
// 20-4-2016
if (windowName == "Invoice(APC)")
Expand All @@ -1239,8 +1240,7 @@ AND CAST(cel.M_Ref_CostElement AS INTEGER) IN (SELECT M_CostElement_ID FROM M_C
cost.SetCumulatedAmt(Decimal.Add(cost.GetCumulatedAmt(), amt));
if (Env.Signum(cost.GetCumulatedQty()) != 0)
{
price = Decimal.Round(Decimal.Divide(cost.GetCumulatedAmt(), cost.GetCumulatedQty()), precision, MidpointRounding.AwayFromZero);
cost.SetCurrentCostPrice(price);
cost.SetCurrentCostPrice(Decimal.Round(Decimal.Divide(cost.GetCumulatedAmt(), cost.GetCumulatedQty()), precision, MidpointRounding.AwayFromZero));
}
else
{
Expand All @@ -1250,9 +1250,8 @@ AND CAST(cel.M_Ref_CostElement AS INTEGER) IN (SELECT M_CostElement_ID FROM M_C
else if (ce.IsWeightedAverageCost() || ce.IsWeightedAveragePO())
{
cost.SetCumulatedAmt(Decimal.Add(cost.GetCumulatedAmt(), amt));
price = Decimal.Round(Decimal.Divide(
Decimal.Add(Decimal.Multiply(cost.GetCurrentCostPrice(), cost.GetCurrentQty()), amt), cost.GetCurrentQty()), precision);
cost.SetCurrentCostPrice(price);
cost.SetCurrentCostPrice(Decimal.Round(Decimal.Divide(
Decimal.Add(Decimal.Multiply(cost.GetCurrentCostPrice(), cost.GetCurrentQty()), amt), cost.GetCurrentQty()), precision));
}
else if (ce.IsStandardCosting() || ce.IsLastInvoice() || ce.IsLastPOPrice())
{
Expand All @@ -1261,22 +1260,80 @@ AND CAST(cel.M_Ref_CostElement AS INTEGER) IN (SELECT M_CostElement_ID FROM M_C
else if (ce.IsFifo() || ce.IsLifo())
{
cost.SetCumulatedAmt(Decimal.Add(cost.GetCumulatedAmt(), amt));
}

if (costingCheck != null && costingCheck.invoiceline != null && !costingCheck.invoiceline.IsCostImmediate())
{

// we have to reduce price
if (amt < 0 && price > 0)
{
price = decimal.Negate(price);
}

// get Cost Queue List Detail
MCostQueue[] cQueue = MCostQueue.GetQueue(product, M_ASI_ID,
mas, Org_ID, ce, Get_TrxName(), cost.GetM_Warehouse_ID());
if (cQueue != null && cQueue.Length > 0)
//DevOps Task-1851
List<MCostElement> lstCostElement = new List<MCostElement>();
if (!costingCheck.IsCostCalculationfromProcess)
{
lstCostElement.Add(MCostElement.Get(GetCtx(), costingCheck.Lifo_ID));
lstCostElement.Add(MCostElement.Get(GetCtx(), costingCheck.Fifo_ID));
}
else if (ce.IsFifo() || ce.IsLifo())
{
lstCostElement.Add(ce);
}

for (int cel = 0; cel < lstCostElement.Count; cel++)
{
cost.SetCurrentCostPrice(Decimal.Round((cQueue[0].GetCurrentCostPrice() + price), precision));
// get Cost Queue List Detail
MCostQueue[] cQueue = MCostQueue.GetQueueforDiscount(product, cd.GetM_AttributeSetInstance_ID(),
mas, cd.GetAD_Org_ID(), lstCostElement[cel], Get_TrxName(), cd.GetM_Warehouse_ID(), costingCheck);
if (cQueue != null && cQueue.Length > 0)
{
decimal remainningQty = cd.GetQty();
decimal queueAmt = 0;
for (int cq = 0; cq < cQueue.Length; cq++)
{
if (cQueue[cq].GetCurrentQty() > Math.Abs(remainningQty) && cQueue[cq].GetCurrentQty() != 0)
{
queueAmt = Decimal.Round(((cQueue[cq].GetCurrentCostPrice() * cQueue[cq].GetCurrentQty()) +
(price * Math.Abs(remainningQty))) / cQueue[cq].GetCurrentQty(), precision);
remainningQty = 0;
}
else if(cQueue[cq].GetCurrentQty() != 0)
{
queueAmt = Decimal.Round(((cQueue[cq].GetCurrentCostPrice() * cQueue[cq].GetCurrentQty()) +
(price * cQueue[cq].GetCurrentQty())) / cQueue[cq].GetCurrentQty(), precision);
remainningQty += cQueue[cq].GetCurrentQty();
}
if (cq == 0 && ce.GetM_CostElement_ID() == cQueue[cq].GetM_CostElement_ID())
{
cost.SetCurrentCostPrice(queueAmt);
}
if (lstCostElement[cel].IsFifo())
{
costingCheck.currentQtyonQueue = cQueue[cq].GetCurrentQty();
}
// Create Cost Queue Transactional Record
if (!MCostQueueTransaction.CreateCostQueueTransaction(GetCtx(), cd.GetAD_Client_ID(), cd.GetAD_Org_ID(),
cQueue[cq].GetM_CostQueue_ID(), cd, cd.GetQty(), costingCheck))
{
return false;
}

DB.ExecuteQuery("Update M_CostQueue SET CurrentCostPrice = " + (queueAmt) +
@" WHERE M_CostQueue_ID = " + cQueue[cq].GetM_CostQueue_ID(), null, Get_Trx());
if (remainningQty == 0)
{
break;
}
}
}

DB.ExecuteQuery("Update M_CostQueue SET CurrentCostPrice = " + (cQueue[0].GetCurrentCostPrice() + price) +
@" WHERE M_CostQueue_ID = " + cQueue[0].GetM_CostQueue_ID(), null, Get_Trx());
if (costingCheck.currentQtyonQueue == null)
{
costingCheck.currentQtyonQueue = 0;
}
}
}
//change 3-5-2016
Expand Down

0 comments on commit 1c53fde

Please sign in to comment.