protected override bool PrepareInsert(PXCache sender, object row, PXAccumulatorCollection columns) { if (!base.PrepareInsert(sender, row, columns)) { return(false); } PMForecastHistory item = (PMForecastHistory)row; columns.Update <PMForecastHistory.actualQty>(item.ActualQty, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.curyActualAmount>(item.CuryActualAmount, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.actualAmount>(item.ActualAmount, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.changeOrderQty>(item.ChangeOrderQty, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.curyChangeOrderAmount>(item.CuryChangeOrderAmount, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.draftChangeOrderQty>(item.DraftChangeOrderQty, PXDataFieldAssign.AssignBehavior.Summarize); columns.Update <PMForecastHistory.curyDraftChangeOrderAmount>(item.CuryDraftChangeOrderAmount, PXDataFieldAssign.AssignBehavior.Summarize); return(true); }
public Result(IList <PMHistory> history, PMBudget status, PMTaskTotal taskTotal, PMForecastHistory forecast) { this.History = history; this.Status = status; this.TaskTotal = taskTotal; this.ForecastHistory = forecast; }
public virtual Result Calculate(PMProject project, PMTran pmt, PMAccountGroup ag, string accountType, int amountSign, int qtySign) { PMBudgetLite target = null; bool isExisting; target = service.SelectProjectBalance(pmt, ag, project, out isExisting); var rollupQty = CalculateRollupQty(pmt, target); List <PMHistory> list = new List <PMHistory>(); PMTaskTotal ta = null; PMBudget ps = null; PMForecastHistory forecast = null; if (pmt.TaskID != null && (rollupQty != 0 || pmt.Amount != 0)) //TaskID will be null for Contract { ps = new PMBudget(); ps.ProjectID = target.ProjectID; ps.ProjectTaskID = target.TaskID; ps.AccountGroupID = target.AccountGroupID; ps.Type = target.Type; ps.InventoryID = target.InventoryID; ps.CostCodeID = target.CostCodeID; ps.UOM = target.UOM; ps.IsProduction = target.IsProduction; ps.Description = target.Description; if (ps.CuryInfoID == null) { ps.CuryInfoID = project.CuryInfoID; } decimal amt = amountSign * pmt.Amount.GetValueOrDefault(); decimal curyAmt = amountSign * pmt.ProjectCuryAmount.GetValueOrDefault(); ps.ActualQty = rollupQty * qtySign; ps.ActualAmount = amt; ps.CuryActualAmount = curyAmt; #region PMTask Totals Update ta = new PMTaskTotal(); ta.ProjectID = ps.ProjectID; ta.TaskID = ps.TaskID; string accType = ag.IsExpense == true ? AccountType.Expense : ag.Type; switch (accType) { case AccountType.Asset: ta.CuryAsset = curyAmt; ta.Asset = amt; break; case AccountType.Liability: ta.CuryLiability = curyAmt; ta.Liability = amt; break; case AccountType.Income: ta.CuryIncome = curyAmt; ta.Income = amt; break; case AccountType.Expense: ta.CuryExpense = curyAmt; ta.Expense = amt; break; } #endregion #region History PMHistory hist = new PMHistory(); hist.ProjectID = ps.ProjectID; hist.ProjectTaskID = ps.TaskID; hist.AccountGroupID = ps.AccountGroupID; hist.InventoryID = pmt.InventoryID ?? ps.InventoryID; hist.CostCodeID = pmt.CostCodeID ?? ps.CostCodeID; hist.PeriodID = pmt.FinPeriodID; hist.BranchID = pmt.BranchID; decimal baseQty = 0; list.Add(hist); if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && pmt.Qty != 0) { if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>()) { baseQty = qtySign * IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(PMHistory)], pmt.InventoryID, pmt.UOM, pmt.Qty.Value, PX.Objects.IN.INPrecision.QUANTITY); } else { IN.InventoryItem initem = PXSelectorAttribute.Select <PMTran.inventoryID>(graph.Caches[typeof(PMTran)], pmt) as IN.InventoryItem; if (initem != null && !string.IsNullOrEmpty(pmt.UOM)) { baseQty = qtySign * IN.INUnitAttribute.ConvertGlobalUnits(graph, pmt.UOM, initem.BaseUnit, pmt.Qty ?? 0, IN.INPrecision.QUANTITY); } } } hist.FinPTDCuryAmount = curyAmt; hist.FinPTDAmount = amt; hist.FinYTDCuryAmount = curyAmt; hist.FinYTDAmount = amt; hist.FinPTDQty = baseQty; hist.FinYTDQty = baseQty; if (pmt.FinPeriodID == pmt.TranPeriodID) { hist.TranPTDCuryAmount = curyAmt; hist.TranPTDAmount = amt; hist.TranYTDCuryAmount = curyAmt; hist.TranYTDAmount = amt; hist.TranPTDQty = baseQty; hist.TranYTDQty = baseQty; } else { PMHistory tranHist = new PMHistory(); tranHist.ProjectID = ps.ProjectID; tranHist.ProjectTaskID = ps.TaskID; tranHist.AccountGroupID = ps.AccountGroupID; tranHist.InventoryID = pmt.InventoryID ?? PM.PMInventorySelectorAttribute.EmptyInventoryID; tranHist.CostCodeID = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode(); tranHist.PeriodID = pmt.TranPeriodID; tranHist.BranchID = pmt.BranchID; list.Add(tranHist); tranHist.TranPTDCuryAmount = curyAmt; tranHist.TranPTDAmount = amt; tranHist.TranYTDCuryAmount = curyAmt; tranHist.TranYTDAmount = amt; tranHist.TranPTDQty = baseQty; tranHist.TranYTDQty = baseQty; } #endregion forecast = new PMForecastHistory(); forecast.ProjectID = ps.ProjectID; forecast.ProjectTaskID = ps.ProjectTaskID; forecast.AccountGroupID = ps.AccountGroupID; forecast.InventoryID = ps.InventoryID; forecast.CostCodeID = ps.CostCodeID; forecast.PeriodID = pmt.TranPeriodID; forecast.ActualQty = ps.ActualQty; forecast.CuryActualAmount = ps.CuryActualAmount; forecast.ActualAmount = ps.ActualAmount; } return(new Result(list, ps, ta, forecast)); }