コード例 #1
0
 public Result(IList <PMHistory> history, PMBudget status, PMTaskTotal taskTotal, PMForecastHistory forecast)
 {
     this.History         = history;
     this.Status          = status;
     this.TaskTotal       = taskTotal;
     this.ForecastHistory = forecast;
 }
        protected override bool PrepareInsert(PXCache sender, object row, PXAccumulatorCollection columns)
        {
            if (!base.PrepareInsert(sender, row, columns))
            {
                return(false);
            }

            PMTaskTotal item = (PMTaskTotal)row;

            columns.Update <PMTaskTotal.asset>(item.Asset, PXDataFieldAssign.AssignBehavior.Summarize);
            columns.Update <PMTaskTotal.liability>(item.Liability, PXDataFieldAssign.AssignBehavior.Summarize);
            columns.Update <PMTaskTotal.income>(item.Income, PXDataFieldAssign.AssignBehavior.Summarize);
            columns.Update <PMTaskTotal.expense>(item.Expense, PXDataFieldAssign.AssignBehavior.Summarize);

            return(true);
        }
コード例 #3
0
        public List <Batch> Release(JournalEntry je, PMRegister doc, out List <PMTask> allocTasks)
        {
            doc = OnBeforeRelease(doc);

            allocTasks = new List <PMTask>();

            List <Batch> batches = new List <Batch>();
            Dictionary <string, PMTask> tasksToAutoAllocate = new Dictionary <string, PMTask>();
            List <PMTran> sourceForAllocation = new List <PMTran>();
            Dictionary <string, List <TranInfo> > transByFinPeriod = GetTransByBranchAndFinPeriod(doc);

            Debug.Assert(transByFinPeriod.Count > 0, "Failed to select transactions by finperiod in PMRegister Release.");

            ProjectBalance pb = CreateProjectBalance();

            using (var ts = new PXTransactionScope())
            {
                foreach (KeyValuePair <string, List <TranInfo> > kv in transByFinPeriod)
                {
                    string[] parts    = kv.Key.Split('.');
                    int?     branchID = parts[0] == "0" ? null : (int?)int.Parse(parts[0]);

                    je.Clear(PXClearOption.ClearAll);

                    CurrencyInfo info = new CurrencyInfo();
                    info.CuryID      = parts[2];
                    info.CuryEffDate = Accessinfo.BusinessDate;
                    info             = je.currencyinfo.Insert(info);

                    Batch newbatch = new Batch();
                    newbatch.Module      = doc.Module;
                    newbatch.Status      = BatchStatus.Unposted;
                    newbatch.Released    = true;
                    newbatch.Hold        = false;
                    newbatch.BranchID    = branchID;
                    newbatch.FinPeriodID = parts[1];
                    newbatch.CuryID      = parts[2];
                    newbatch.CuryInfoID  = info.CuryInfoID;
                    newbatch.Description = doc.Description;
                    je.BatchModule.Insert(newbatch);

                    bool tranAdded = false;
                    foreach (TranInfo t in kv.Value)
                    {
                        bool isGL = false;

                        if (t.Tran.Released != true && t.Tran.IsNonGL != true && t.Project.BaseType == CT.CTPRType.Project &&
                            !string.IsNullOrEmpty(t.AccountGroup.Type) && t.AccountGroup.Type != PMAccountType.OffBalance && !ProjectDefaultAttribute.IsNonProject(t.Tran.ProjectID) &&
                            t.Tran.AccountID != null && t.Tran.SubID != null && t.Tran.OffsetAccountID != null && t.Tran.OffsetSubID != null)
                        {
                            GLTran tran1 = new GLTran();
                            tran1.TranDate      = t.Tran.Date;
                            tran1.TranPeriodID  = t.Tran.TranPeriodID;
                            tran1.SummPost      = false;
                            tran1.BranchID      = t.Tran.BranchID;
                            tran1.PMTranID      = t.Tran.TranID;
                            tran1.ProjectID     = t.Tran.ProjectID;
                            tran1.TaskID        = t.Tran.TaskID;
                            tran1.CostCodeID    = t.Tran.CostCodeID;
                            tran1.TranDesc      = t.Tran.Description;
                            tran1.ReferenceID   = t.Tran.BAccountID;
                            tran1.InventoryID   = t.Tran.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID ? null : t.Tran.InventoryID;
                            tran1.Qty           = t.Tran.Qty;
                            tran1.UOM           = t.Tran.UOM;
                            tran1.TranType      = t.Tran.TranType;
                            tran1.CuryInfoID    = t.Tran.BaseCuryInfoID;
                            tran1.CuryCreditAmt = 0;
                            tran1.CreditAmt     = 0;
                            tran1.CuryDebitAmt  = t.Tran.TranCuryAmount;
                            tran1.DebitAmt      = t.Tran.Amount;
                            tran1.AccountID     = t.Tran.AccountID;
                            tran1.SubID         = t.Tran.SubID;
                            tran1.Released      = true;
                            je.GLTranModuleBatNbr.Insert(tran1);

                            GLTran tran2 = new GLTran();
                            tran2.TranDate      = t.Tran.Date;
                            tran2.TranPeriodID  = t.Tran.TranPeriodID;
                            tran2.SummPost      = false;
                            tran2.BranchID      = t.Tran.BranchID;
                            tran2.PMTranID      = t.Tran.TranID;
                            tran2.ProjectID     = t.OffsetAccountGroup.GroupID != null ? t.Tran.ProjectID : ProjectDefaultAttribute.NonProject();
                            tran2.TaskID        = t.OffsetAccountGroup.GroupID != null ? t.Tran.TaskID : null;
                            tran2.CostCodeID    = tran2.TaskID != null ? t.Tran.CostCodeID : null;
                            tran2.TranDesc      = t.Tran.Description;
                            tran2.ReferenceID   = t.Tran.BAccountID;
                            tran2.InventoryID   = t.Tran.InventoryID == PMInventorySelectorAttribute.EmptyInventoryID ? null : t.Tran.InventoryID;
                            tran2.Qty           = t.Tran.Qty;
                            tran2.UOM           = t.Tran.UOM;
                            tran2.TranType      = t.Tran.TranType;
                            tran2.CuryInfoID    = t.Tran.BaseCuryInfoID;
                            tran2.CuryCreditAmt = t.Tran.TranCuryAmount;
                            tran2.CreditAmt     = t.Tran.Amount;
                            tran2.CuryDebitAmt  = 0;
                            tran2.DebitAmt      = 0;
                            tran2.AccountID     = t.Tran.OffsetAccountID;
                            tran2.SubID         = t.Tran.OffsetSubID;
                            tran2.Released      = true;
                            je.GLTranModuleBatNbr.Insert(tran2);

                            tranAdded       = true;
                            isGL            = true;
                            t.Tran.BatchNbr = je.BatchModule.Current.BatchNbr;
                        }

                        if (!isGL)
                        {
                            if (t.Tran.AccountGroupID == null && t.Project.BaseType == CT.CTPRType.Project && t.Project.NonProject != true)
                            {
                                throw new PXException(Messages.AccountGroupIsRequired, doc.RefNbr);
                            }
                        }

                        if (t.Tran.ExcludedFromBalance != true)
                        {
                            JournalEntryProjectExt        xje      = je.GetExtension <JournalEntryProjectExt>();
                            IList <ProjectBalance.Result> balances = pb.Calculate(t.Project, t.Tran, t.Account, t.AccountGroup, t.OffsetAccount, t.OffsetAccountGroup);
                            foreach (ProjectBalance.Result balance in balances)
                            {
                                if (balance.Status != null)
                                {
                                    PMBudgetAccum ps = new PMBudgetAccum();
                                    ps.ProjectID      = balance.Status.ProjectID;
                                    ps.ProjectTaskID  = balance.Status.ProjectTaskID;
                                    ps.AccountGroupID = balance.Status.AccountGroupID;
                                    ps.InventoryID    = balance.Status.InventoryID;
                                    ps.CostCodeID     = balance.Status.CostCodeID;
                                    ps.UOM            = balance.Status.UOM;
                                    ps.IsProduction   = balance.Status.IsProduction;
                                    ps.Type           = balance.Status.Type;
                                    ps.Description    = balance.Status.Description;
                                    ps.CuryInfoID     = balance.Status.CuryInfoID;

                                    ps                   = xje.ProjectBudget.Insert(ps);
                                    ps.ActualQty        += balance.Status.ActualQty.GetValueOrDefault();
                                    ps.CuryActualAmount += balance.Status.CuryActualAmount.GetValueOrDefault();
                                    ps.ActualAmount     += balance.Status.ActualAmount.GetValueOrDefault();
                                }

                                if (balance.ForecastHistory != null)
                                {
                                    PMForecastHistoryAccum forecast = new PMForecastHistoryAccum();
                                    forecast.ProjectID      = balance.ForecastHistory.ProjectID;
                                    forecast.ProjectTaskID  = balance.ForecastHistory.ProjectTaskID;
                                    forecast.AccountGroupID = balance.ForecastHistory.AccountGroupID;
                                    forecast.InventoryID    = balance.ForecastHistory.InventoryID;
                                    forecast.CostCodeID     = balance.ForecastHistory.CostCodeID;
                                    forecast.PeriodID       = balance.ForecastHistory.PeriodID;

                                    forecast = xje.ForecastHistory.Insert(forecast);

                                    forecast.ActualQty        += balance.ForecastHistory.ActualQty.GetValueOrDefault();
                                    forecast.CuryActualAmount += balance.ForecastHistory.CuryActualAmount.GetValueOrDefault();
                                    forecast.ActualAmount     += balance.ForecastHistory.ActualAmount.GetValueOrDefault();
                                }

                                if (balance.TaskTotal != null)
                                {
                                    PMTaskTotal ta = new PMTaskTotal();
                                    ta.ProjectID = balance.TaskTotal.ProjectID;
                                    ta.TaskID    = balance.TaskTotal.TaskID;

                                    ta                = xje.ProjectTaskTotals.Insert(ta);
                                    ta.CuryAsset     += balance.TaskTotal.CuryAsset.GetValueOrDefault();
                                    ta.Asset         += balance.TaskTotal.Asset.GetValueOrDefault();
                                    ta.CuryLiability += balance.TaskTotal.CuryLiability.GetValueOrDefault();
                                    ta.Liability     += balance.TaskTotal.Liability.GetValueOrDefault();
                                    ta.CuryIncome    += balance.TaskTotal.CuryIncome.GetValueOrDefault();
                                    ta.Income        += balance.TaskTotal.Income.GetValueOrDefault();
                                    ta.CuryExpense   += balance.TaskTotal.CuryExpense.GetValueOrDefault();
                                    ta.Expense       += balance.TaskTotal.Expense.GetValueOrDefault();
                                }

                                if (!isGL)
                                {
                                    foreach (PMHistory item in balance.History)
                                    {
                                        PMHistoryAccum hist = new PMHistoryAccum();
                                        hist.ProjectID      = item.ProjectID;
                                        hist.ProjectTaskID  = item.ProjectTaskID;
                                        hist.AccountGroupID = item.AccountGroupID;
                                        hist.InventoryID    = item.InventoryID;
                                        hist.CostCodeID     = item.CostCodeID;
                                        hist.PeriodID       = item.PeriodID;
                                        hist.BranchID       = item.BranchID;

                                        hist = (PMHistoryAccum)je.Caches[typeof(PMHistoryAccum)].Insert(hist);
                                        hist.FinPTDCuryAmount  += item.FinPTDCuryAmount.GetValueOrDefault();
                                        hist.FinPTDAmount      += item.FinPTDAmount.GetValueOrDefault();
                                        hist.FinYTDCuryAmount  += item.FinYTDCuryAmount.GetValueOrDefault();
                                        hist.FinYTDAmount      += item.FinYTDAmount.GetValueOrDefault();
                                        hist.FinPTDQty         += item.FinPTDQty.GetValueOrDefault();
                                        hist.FinYTDQty         += item.FinYTDQty.GetValueOrDefault();
                                        hist.TranPTDCuryAmount += item.TranPTDCuryAmount.GetValueOrDefault();
                                        hist.TranPTDAmount     += item.TranPTDAmount.GetValueOrDefault();
                                        hist.TranYTDCuryAmount += item.TranYTDCuryAmount.GetValueOrDefault();
                                        hist.TranYTDAmount     += item.TranYTDAmount.GetValueOrDefault();
                                        hist.TranPTDQty        += item.TranPTDQty.GetValueOrDefault();
                                        hist.TranYTDQty        += item.TranYTDQty.GetValueOrDefault();
                                    }
                                }
                            }
                        }

                        AddToUnbilledSummary(je, t.Tran);

                        t.Tran.Released = true;
                        je.Caches[typeof(PMTran)].Update(t.Tran);

                        sourceForAllocation.Add(t.Tran);
                        if (t.Tran.Allocated != true && t.Tran.ExcludedFromAllocation != true && t.Project.AutoAllocate == true)
                        {
                            if (!tasksToAutoAllocate.ContainsKey(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID)))
                            {
                                tasksToAutoAllocate.Add(string.Format("{0}.{1}", t.Task.ProjectID, t.Task.TaskID), t.Task);
                            }
                        }
                    }

                    if (tranAdded)
                    {
                        je.Save.Press();
                        batches.Add(je.BatchModule.Current);
                    }
                    else
                    {
                        je.Persist(typeof(PMTran), PXDBOperation.Update);
                        je.Persist(typeof(PMBudgetAccum), PXDBOperation.Insert);
                        je.Persist(typeof(PMForecastHistoryAccum), PXDBOperation.Insert);
                        je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert);
                        je.Persist(typeof(PMTaskAllocTotalAccum), PXDBOperation.Insert);
                        je.Persist(typeof(PMHistoryAccum), PXDBOperation.Insert);                        //only non-gl balance is updated
                        je.Persist(typeof(PMUnbilledDailySummaryAccum), PXDBOperation.Insert);
                        je.SelectTimeStamp();
                    }
                }

                allocTasks.AddRange(tasksToAutoAllocate.Values);

                doc.Released = true;
                doc.Status   = PMRegister.status.Released;
                je.Caches[typeof(PMRegister)].Update(doc);

                je.Persist(typeof(PMTran), PXDBOperation.Update);
                je.Persist(typeof(PMRegister), PXDBOperation.Update);
                je.Persist(typeof(PMBudgetAccum), PXDBOperation.Insert);
                je.Persist(typeof(PMForecastHistoryAccum), PXDBOperation.Insert);
                je.Persist(typeof(PMTaskAllocTotalAccum), PXDBOperation.Insert);
                je.Persist(typeof(PMTaskTotal), PXDBOperation.Insert);


                ts.Complete();
            }

            return(batches);
        }
コード例 #4
0
        /// <summary>
        /// Updates Project Status Balance using PMProjectStatusAccum.
        /// </summary>
        public static IList <PMHistory> UpdateProjectBalance(PXGraph graph, PMTran pmt, PMAccountGroup ag, Account acc, int mult)
        {
            List <PMHistory> list = new List <PMHistory>();
            PXSelectBase <PMProjectStatus> selectProjectStatus = new PXSelect <PMProjectStatus,
                                                                               Where <PMProjectStatus.accountGroupID, Equal <Required <PMProjectStatus.accountGroupID> >,
                                                                                      And <PMProjectStatus.projectID, Equal <Required <PMProjectStatus.projectID> >,
                                                                                           And <PMProjectStatus.projectTaskID, Equal <Required <PMProjectStatus.projectTaskID> >,
                                                                                                And <PMProjectStatus.inventoryID, Equal <Required <PMProjectStatus.inventoryID> > > > > > >(graph); // select any without restricting by FinPeriod

            int             inventoryID = PMProjectStatus.EmptyInventoryID;
            PMProjectStatus status      = null;

            if (pmt.InventoryID != null)
            {
                status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, pmt.InventoryID);
                if (status == null)
                {
                    status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, PMProjectStatus.EmptyInventoryID);
                }
                else
                {
                    inventoryID = status.InventoryID ?? PMProjectStatus.EmptyInventoryID;
                }
            }
            else
            {
                status = selectProjectStatus.Select(ag.GroupID, pmt.ProjectID, pmt.TaskID, PMProjectStatus.EmptyInventoryID);
            }

            string  UOM       = null;
            decimal rollupQty = 0;

            if (status == null)
            {
                //Status does not exist for given Inventory and <Other> is not present.
            }
            else
            {
                if (status.InventoryID == PMProjectStatus.EmptyInventoryID)
                {
                    //<Other> item is present. Update only if UOMs are same.
                    decimal convertedQty;
                    if (IN.INUnitAttribute.TryConvertGlobalUnits(graph, pmt.UOM, status.UOM, pmt.Qty.GetValueOrDefault(), IN.INPrecision.QUANTITY, out convertedQty))
                    {
                        rollupQty = convertedQty;
                        UOM       = status.UOM;
                    }
                }
                else
                {
                    UOM = status.UOM;

                    //Item matches. Convert to UOM of ProjectStatus.
                    if (status.UOM != pmt.UOM)
                    {
                        decimal inBase = IN.INUnitAttribute.ConvertToBase(graph.Caches[pmt.GetType()], pmt.InventoryID, pmt.UOM, pmt.Qty ?? 0, IN.INPrecision.QUANTITY);

                        try
                        {
                            rollupQty = IN.INUnitAttribute.ConvertFromBase(graph.Caches[pmt.GetType()], pmt.InventoryID, status.UOM, inBase, IN.INPrecision.QUANTITY);
                        }
                        catch (PX.Objects.IN.PXUnitConversionException ex)
                        {
                            IN.InventoryItem item = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(graph, pmt.InventoryID);

                            string msg = PXMessages.LocalizeFormatNoPrefixNLA(Messages.UnitConversionNotDefinedForItemOnBudgetUpdate, item.BaseUnit, status.UOM, item.InventoryCD);

                            throw new PXException(msg, ex);
                        }
                    }
                    else
                    {
                        rollupQty = pmt.Qty ?? 0;
                    }
                }
            }

            if (pmt.TaskID != null && (rollupQty != 0 || pmt.Amount != 0)) //TaskID will be null for Contract
            {
                PMProjectStatusAccum ps = new PMProjectStatusAccum();
                ps.PeriodID       = pmt.FinPeriodID;
                ps.ProjectID      = pmt.ProjectID;
                ps.ProjectTaskID  = pmt.TaskID;
                ps.AccountGroupID = ag.GroupID;
                ps.InventoryID    = inventoryID;
                ps.UOM            = UOM;
                if (status != null)
                {
                    ps.IsProduction = status.IsProduction;
                }

                ps = (PMProjectStatusAccum)graph.Caches[typeof(PMProjectStatusAccum)].Insert(ps);

                decimal amt = mult * pmt.Amount.GetValueOrDefault();

                ps.ActualQty    += rollupQty * mult;
                ps.ActualAmount += amt;

                graph.Views.Caches.Add(typeof(PMProjectStatusAccum));

                #region PMTask Totals Update

                PMTaskTotal ta = new PMTaskTotal();
                ta.ProjectID = pmt.ProjectID;
                ta.TaskID    = pmt.TaskID;

                ta = (PMTaskTotal)graph.Caches[typeof(PMTaskTotal)].Insert(ta);

                string accType = null;
                int    multFix = 1;             //flip back the sign if it was changed because of ag.Type<>acc.type
                if (pmt.TranType == BatchModule.PM && acc != null && !string.IsNullOrEmpty(acc.Type))
                {
                    //Only transactions that originated in PM were inverted and require to be fixed.
                    accType = ag.Type;

                    if (acc.Type != ag.Type)
                    {
                        multFix = -1;
                    }
                }
                else
                {
                    accType = ag.Type;
                }

                switch (accType)
                {
                case AccountType.Asset:
                    ta.Asset += amt * multFix;
                    break;

                case AccountType.Liability:
                    ta.Liability += amt * multFix;
                    break;

                case AccountType.Income:
                    ta.Income += amt * multFix;
                    break;

                case AccountType.Expense:
                    ta.Expense += amt * multFix;
                    break;
                }

                graph.Views.Caches.Add(typeof(PMTaskTotal));

                #endregion
                #region History
                PMHistory hist = new PMHistory();
                hist.ProjectID      = pmt.ProjectID;
                hist.ProjectTaskID  = pmt.TaskID;
                hist.AccountGroupID = ag.GroupID;
                hist.InventoryID    = pmt.InventoryID ?? PMProjectStatus.EmptyInventoryID;
                hist.PeriodID       = pmt.FinPeriodID;
                decimal baseQty = 0;
                list.Add(hist);
                if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && rollupQty != 0)
                {
                    baseQty = mult * PX.Objects.IN.INUnitAttribute.ConvertToBase(graph.Caches[typeof(PMHistory)], pmt.InventoryID, UOM, rollupQty, PX.Objects.IN.INPrecision.QUANTITY);
                }
                hist.FinPTDAmount = amt;
                hist.FinYTDAmount = amt;
                hist.FinPTDQty    = baseQty;
                hist.FinYTDQty    = baseQty;
                if (pmt.FinPeriodID == pmt.TranPeriodID)
                {
                    hist.TranPTDAmount = amt;
                    hist.TranYTDAmount = amt;
                    hist.TranPTDQty    = baseQty;
                    hist.TranYTDQty    = baseQty;
                }
                else
                {
                    PMHistory tranHist = new PMHistory();
                    tranHist.ProjectID      = pmt.ProjectID;
                    tranHist.ProjectTaskID  = pmt.TaskID;
                    tranHist.AccountGroupID = ag.GroupID;
                    tranHist.InventoryID    = pmt.InventoryID ?? PM.PMProjectStatus.EmptyInventoryID;
                    tranHist.PeriodID       = pmt.TranPeriodID;
                    list.Add(tranHist);
                    tranHist.TranPTDAmount = amt;
                    tranHist.TranYTDAmount = amt;
                    tranHist.TranPTDQty    = baseQty;
                    tranHist.TranYTDQty    = baseQty;
                }
                #endregion
            }
            return(list);
        }
コード例 #5
0
 public Result(IList <PMHistory> history, PMBudget status, PMTaskTotal taskTotal)
 {
     this.History   = history;
     this.Status    = status;
     this.TaskTotal = taskTotal;
 }
コード例 #6
0
        public virtual Result Calculate(PMTran pmt, PMAccountGroup ag, Account acc, int mult)
        {
            PMBudget status = SelectProjectBalance(pmt);

            int?      inventoryID = status != null ? status.InventoryID : PMInventorySelectorAttribute.EmptyInventoryID;
            int?      costCodeID  = status != null ? status.CostCodeID : CostCodeAttribute.GetDefaultCostCode();
            RollupQty rollup      = null;

            if (settings.CostBudgetUpdateMode == CostBudgetUpdateModes.Detailed && ag.IsExpense == true && pmt.InventoryID != settings.EmptyInventoryID)
            {
                if (status == null || status.InventoryID == settings.EmptyInventoryID)
                {
                    rollup      = new RollupQty(pmt.UOM, pmt.Qty);
                    inventoryID = pmt.InventoryID;
                    if (pmt.CostCodeID != null)
                    {
                        costCodeID = pmt.CostCodeID;
                    }
                }
            }

            if (rollup == null)
            {
                rollup = CalculateRollupQty(pmt, status);
            }

            List <PMHistory> list = new List <PMHistory>();

            PMTaskTotal ta = null;
            PMBudget    ps = null;

            if (pmt.TaskID != null && (rollup.Qty != 0 || pmt.Amount != 0))             //TaskID will be null for Contract
            {
                ps                = new PMBudget();
                ps.ProjectID      = pmt.ProjectID;
                ps.ProjectTaskID  = pmt.TaskID;
                ps.AccountGroupID = ag.GroupID;
                if (ag.Type == PMAccountType.OffBalance)
                {
                    ps.Type = ag.IsExpense == true ? GL.AccountType.Expense : ag.Type;
                }
                else
                {
                    ps.Type = ag.Type;
                }
                ps.InventoryID = inventoryID;
                ps.CostCodeID  = costCodeID;
                ps.UOM         = rollup.UOM;
                if (status != null)
                {
                    ps.IsProduction = status.IsProduction;
                }

                decimal amt = mult * pmt.Amount.GetValueOrDefault();

                if (!string.IsNullOrEmpty(ps.UOM))
                {
                    ps.ActualQty = rollup.Qty;                     // commented out otherwise invoice produces -ve Qty. * mult;
                }
                ps.ActualAmount = amt;

                #region PMTask Totals Update

                ta           = new PMTaskTotal();
                ta.ProjectID = pmt.ProjectID;
                ta.TaskID    = pmt.TaskID;

                string accType = null;
                int    multFix = 1;             //flip back the sign if it was changed because of ag.Type<>acc.type
                if (pmt.TranType == BatchModule.PM && acc != null && !string.IsNullOrEmpty(acc.Type))
                {
                    //Only transactions that originated in PM were inverted and require to be fixed.
                    accType = ag.Type;

                    if (acc.Type != ag.Type)
                    {
                        multFix = -1;
                    }
                }
                else
                {
                    accType = ag.Type;
                }

                switch (accType)
                {
                case AccountType.Asset:
                    ta.Asset = amt * multFix;
                    break;

                case AccountType.Liability:
                    ta.Liability = amt * multFix;
                    break;

                case AccountType.Income:
                    ta.Income = amt * multFix;
                    break;

                case AccountType.Expense:
                    ta.Expense = amt * multFix;
                    break;
                }

                #endregion

                #region History
                PMHistory hist = new PMHistory();
                hist.ProjectID      = pmt.ProjectID;
                hist.ProjectTaskID  = pmt.TaskID;
                hist.AccountGroupID = ag.GroupID;
                hist.InventoryID    = pmt.InventoryID ?? PMInventorySelectorAttribute.EmptyInventoryID;
                hist.CostCodeID     = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();
                hist.PeriodID       = pmt.FinPeriodID;
                decimal baseQty = 0;
                list.Add(hist);
                if (pmt.InventoryID != null && pmt.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID && pmt.Qty != 0 && !string.IsNullOrEmpty(rollup.UOM))
                {
                    if (PXAccess.FeatureInstalled <FeaturesSet.multipleUnitMeasure>())
                    {
                        baseQty = mult * 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)
                        {
                            baseQty = mult * IN.INUnitAttribute.ConvertGlobalUnits(graph, pmt.UOM, initem.BaseUnit, pmt.Qty ?? 0, IN.INPrecision.QUANTITY);
                        }
                    }
                }
                hist.FinPTDAmount = amt;
                hist.FinYTDAmount = amt;
                hist.FinPTDQty    = baseQty;
                hist.FinYTDQty    = baseQty;
                if (pmt.FinPeriodID == pmt.TranPeriodID)
                {
                    hist.TranPTDAmount = amt;
                    hist.TranYTDAmount = amt;
                    hist.TranPTDQty    = baseQty;
                    hist.TranYTDQty    = baseQty;
                }
                else
                {
                    PMHistory tranHist = new PMHistory();
                    tranHist.ProjectID      = pmt.ProjectID;
                    tranHist.ProjectTaskID  = pmt.TaskID;
                    tranHist.AccountGroupID = ag.GroupID;
                    tranHist.InventoryID    = pmt.InventoryID ?? PM.PMInventorySelectorAttribute.EmptyInventoryID;
                    tranHist.CostCodeID     = pmt.CostCodeID ?? CostCodeAttribute.GetDefaultCostCode();
                    tranHist.PeriodID       = pmt.TranPeriodID;
                    list.Add(tranHist);
                    tranHist.TranPTDAmount = amt;
                    tranHist.TranYTDAmount = amt;
                    tranHist.TranPTDQty    = baseQty;
                    tranHist.TranYTDQty    = baseQty;
                }
                #endregion
            }
            return(new Result(list, ps, ta));
        }
        public virtual void ProcessTransaction(PMProject project, PXResult <PMTran, Account, OffsetAccount, PMAccountGroup, OffsetPMAccountGroup> res, ProjectBalance pb)
        {
            PMTran               tran      = (PMTran)res;
            Account              acc       = (Account)res;
            PMAccountGroup       ag        = (PMAccountGroup)res;
            OffsetAccount        offsetAcc = (OffsetAccount)res;
            OffsetPMAccountGroup offsetAg  = (OffsetPMAccountGroup)res;

            IList <ProjectBalance.Result> balances = pb.Calculate(project, tran, acc, ag, offsetAcc, offsetAg);

            foreach (ProjectBalance.Result balance in balances)
            {
                if (balance.Status != null)
                {
                    PMBudgetAccum ps = new PMBudgetAccum();
                    ps.ProjectID      = balance.Status.ProjectID;
                    ps.ProjectTaskID  = balance.Status.ProjectTaskID;
                    ps.AccountGroupID = balance.Status.AccountGroupID;
                    ps.InventoryID    = balance.Status.InventoryID;
                    ps.CostCodeID     = balance.Status.CostCodeID;
                    ps.UOM            = balance.Status.UOM;
                    ps.IsProduction   = balance.Status.IsProduction;
                    ps.Type           = balance.Status.Type;
                    ps.Description    = balance.Status.Description;

                    ps = Budget.Insert(ps);

                    ps.ActualQty    += balance.Status.ActualQty.GetValueOrDefault();
                    ps.ActualAmount += balance.Status.ActualAmount.GetValueOrDefault();
                }

                if (balance.TaskTotal != null)
                {
                    PMTaskTotal ta = new PMTaskTotal();
                    ta.ProjectID = balance.TaskTotal.ProjectID;
                    ta.TaskID    = balance.TaskTotal.TaskID;

                    ta            = TaskTotals.Insert(ta);
                    ta.Asset     += balance.TaskTotal.Asset.GetValueOrDefault();
                    ta.Liability += balance.TaskTotal.Liability.GetValueOrDefault();
                    ta.Income    += balance.TaskTotal.Income.GetValueOrDefault();
                    ta.Expense   += balance.TaskTotal.Expense.GetValueOrDefault();
                }


                foreach (PMHistory item in balance.History)
                {
                    PMHistoryAccum hist = new PMHistoryAccum();
                    hist.ProjectID      = item.ProjectID;
                    hist.ProjectTaskID  = item.ProjectTaskID;
                    hist.AccountGroupID = item.AccountGroupID;
                    hist.InventoryID    = item.InventoryID;
                    hist.CostCodeID     = item.CostCodeID;
                    hist.PeriodID       = item.PeriodID;

                    hist = History.Insert(hist);
                    hist.FinPTDAmount  += item.FinPTDAmount.GetValueOrDefault();
                    hist.FinYTDAmount  += item.FinYTDAmount.GetValueOrDefault();
                    hist.FinPTDQty     += item.FinPTDQty.GetValueOrDefault();
                    hist.FinYTDQty     += item.FinYTDQty.GetValueOrDefault();
                    hist.TranPTDAmount += item.TranPTDAmount.GetValueOrDefault();
                    hist.TranYTDAmount += item.TranYTDAmount.GetValueOrDefault();
                    hist.TranPTDQty    += item.TranPTDQty.GetValueOrDefault();
                    hist.TranYTDQty    += item.TranYTDQty.GetValueOrDefault();
                }
            }
        }
コード例 #8
0
        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));
        }