protected virtual void _(Events.FieldUpdated <EPActivityApprove, EPActivityApprove.earningTypeID> e)
 {
     if (e.Row.ProjectID == null || ProjectDefaultAttribute.IsNonProject(e.Row.ProjectID))
     {
         e.Cache.SetDefaultExt <EPActivityApprove.projectID>(e.Row);
     }
 }
Пример #2
0
 protected virtual void OnProjectUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
 {
     if (ProjectField != null)
     {
         object projectID = sender.GetValue(e.Row, ProjectField.Name);
         if (projectID == null || ProjectDefaultAttribute.IsNonProject((int?)projectID))
         {
             sender.SetValueExt(e.Row, _FieldName, null);
         }
     }
 }
Пример #3
0
        public IEnumerable ViewTransactions(PXAdapter adapter)
        {
            if (ProjectStatus.Current != null)
            {
                TransactionInquiry target = PXGraph.CreateInstance <TransactionInquiry>();
                target.Filter.Insert(new TransactionInquiry.TranFilter());
                target.Filter.Current.AccountGroupID = ProjectStatus.Current.AccountGroupID;
                target.Filter.Current.ProjectID      = ProjectStatus.Current.ProjectID;
                target.Filter.Current.ProjectTaskID  = ProjectStatus.Current.ProjectTaskID;
                if (ProjectStatus.Current.InventoryID != null && !ProjectDefaultAttribute.IsNonProject(this, ProjectStatus.Current.InventoryID))
                {
                    target.Filter.Current.InventoryID = ProjectStatus.Current.InventoryID;
                }

                throw new PXPopupRedirectException(target, Messages.TransactionInquiry + " - " + Messages.ViewTransactions, false);
            }
            return(adapter.Get());
        }
Пример #4
0
        private bool IsInventoryItemValid(POLine subcontractLine)
        {
            if (subcontractLine.InventoryID == null || !ShouldValidateInventoryItem() ||
                subcontractLine.ProjectID == null || ProjectDefaultAttribute.IsNonProject(subcontractLine.ProjectID))
            {
                return(true);
            }

            var project = GetProject(subcontractLine.ProjectID);

            if (IsNonProjectAccountGroupsAllowed(project) || !IsItemLevel(project))
            {
                return(true);
            }
            var result = IsInventoryItemUsedInProject(subcontractLine, subcontractLine.InventoryID);

            return(result);
        }
Пример #5
0
        private bool IsInventoryItemUsedInProject(POLine subcontractLine, int?inventoryID)
        {
            if (subcontractLine.ProjectID == null || ProjectDefaultAttribute.IsNonProject(subcontractLine.ProjectID))
            {
                return(false);
            }

            var project = GetProject(subcontractLine.ProjectID);

            if (!IsItemLevel(project))
            {
                return(false);
            }

            var query      = new PXSelect <PMCostBudget, Where <PMCostBudget.projectID, Equal <Required <PMCostBudget.projectID> > > >(this);
            var parameters = new List <object>();

            parameters.Add(subcontractLine.ProjectID);

            if (subcontractLine.TaskID.HasValue)
            {
                query.WhereAnd <Where <PMCostBudget.projectTaskID, Equal <Required <PMCostBudget.projectTaskID> > > >();
                parameters.Add(subcontractLine.TaskID);
            }

            var accountGroupID = GetAccountGroup(subcontractLine, inventoryID);

            if (accountGroupID.HasValue)
            {
                query.WhereAnd <Where <PMCostBudget.accountGroupID, Equal <Required <PMCostBudget.accountGroupID> > > >();
                parameters.Add(accountGroupID);
            }

            if (subcontractLine.CostCodeID.HasValue)
            {
                query.WhereAnd <Where <PMCostBudget.costCodeID, Equal <Required <PMCostBudget.costCodeID> > > >();
                parameters.Add(subcontractLine.CostCodeID);
            }

            var result = query.Select(parameters.ToArray()).AsEnumerable()
                         .Any(b => ((PMCostBudget)b).InventoryID == inventoryID);

            return(result);
        }
Пример #6
0
        protected virtual void INTran_ReasonCode_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            INTran row = e.Row as INTran;

            if (row != null)
            {
                ReasonCode reasoncd = PXSelect <ReasonCode, Where <ReasonCode.reasonCodeID, Equal <Optional <ReasonCode.reasonCodeID> > > > .Select(this, e.NewValue);

                if (reasoncd != null && row.ProjectID != null && !ProjectDefaultAttribute.IsNonProject(this, row.ProjectID))
                {
                    PX.Objects.GL.Account account = PXSelect <PX.Objects.GL.Account, Where <PX.Objects.GL.Account.accountID, Equal <Required <PX.Objects.GL.Account.accountID> > > > .Select(this, reasoncd.AccountID);

                    if (account != null && account.AccountGroupID == null)
                    {
                        sender.RaiseExceptionHandling <INTran.reasonCode>(e.Row, account.AccountCD, new PXSetPropertyException(PM.Messages.NoAccountGroup, PXErrorLevel.Warning, account.AccountCD));
                    }
                }

                e.Cancel = (reasoncd != null) &&
                           (row.TranType != INTranType.Issue && row.TranType != INTranType.Receipt && reasoncd.Usage == ReasonCodeUsages.Sales || reasoncd.Usage == row.DocType);
            }
        }
        public virtual void Bill(CustomersList customer, EPCustomerBilling.BillingFilter filter)
        {
            ARInvoiceEntry arGraph = PXGraph.CreateInstance <ARInvoiceEntry>();
            RegisterEntry  pmGraph = PXGraph.CreateInstance <RegisterEntry>();

            arGraph.Clear();
            pmGraph.Clear();

            PMRegister pmDoc = null;
            ARInvoice  arDoc = null;

            List <ARRegister>            doclist = new List <ARRegister>();
            List <EPExpenseClaimDetails> listOfDirectBilledClaims = new List <EPExpenseClaimDetails>();

            PXSelectBase <EPExpenseClaimDetails> select = new PXSelectJoin <EPExpenseClaimDetails,
                                                                            LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>, And <Where <Contract.baseType, Equal <Contract.ContractBaseType>, Or <Contract.nonProject, Equal <True> > > > >
                                                                                      , LeftJoin <Account, On <EPExpenseClaimDetails.expenseAccountID, Equal <Account.accountID> > >
                                                                                      >,
                                                                            Where <EPExpenseClaimDetails.released, Equal <boolTrue>,
                                                                                   And <EPExpenseClaimDetails.billable, Equal <boolTrue>,
                                                                                        And <EPExpenseClaimDetails.billed, Equal <boolFalse>,
                                                                                             And <EPExpenseClaimDetails.customerID, Equal <Required <EPExpenseClaimDetails.customerID> >,
                                                                                                  And <EPExpenseClaimDetails.customerLocationID, Equal <Required <EPExpenseClaimDetails.customerLocationID> >,
                                                                                                       And <EPExpenseClaimDetails.expenseDate, LessEqual <Required <EPExpenseClaimDetails.expenseDate> >,
                                                                                                            And <Where <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>, Or <EPExpenseClaimDetails.contractID, IsNull> > > > > > > > >,
                                                                            OrderBy <Asc <EPExpenseClaimDetails.branchID> > >(this);

            arGraph.RowPersisted.AddHandler <ARInvoice>(
                delegate(PXCache sender, PXRowPersistedEventArgs e)
            {
                if (e.TranStatus == PXTranStatus.Open)
                {
                    foreach (EPExpenseClaimDetails row in listOfDirectBilledClaims.Select(claimdetail => Transactions.Locate(claimdetail)))
                    {
                        row.ARDocType = ((ARInvoice)e.Row).DocType;
                        row.ARRefNbr  = ((ARInvoice)e.Row).RefNbr;
                    }
                }
            });


            decimal signOperation = 1m;

            decimal tipQty = 1m;

            foreach (PXResult <EPExpenseClaimDetails, Contract, Account> res in select.Select(customer.CustomerID, customer.LocationID, filter.EndDate))
            {
                EPExpenseClaimDetails row = (EPExpenseClaimDetails)res;

                if (row.ContractID != null && !ProjectDefaultAttribute.IsNonProject(row.ContractID))
                {
                    if (pmDoc == null)
                    {
                        pmDoc             = (PMRegister)pmGraph.Document.Cache.Insert();
                        pmDoc.OrigDocType = PMOrigDocType.ExpenseClaim;
                        pmDoc.OrigDocNbr  = row.RefNbr;
                    }

                    PMTran usage = InsertPMTran(pmGraph, res);
                    if (usage.Released == true)                     //contract trans are created as released
                    {
                        UsageMaint.AddUsage(pmGraph.Transactions.Cache, usage.ProjectID, usage.InventoryID, usage.BillableQty ?? 0m, usage.UOM);
                    }
                }
                else
                {
                    if (arDoc == null || arDoc.BranchID != row.BranchID)
                    {
                        if (arDoc != null)
                        {
                            arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                            arGraph.Document.Update(arDoc);
                            arGraph.Save.Press();
                            listOfDirectBilledClaims.Clear();
                        }
                        EPExpenseClaimDetails summDetail = PXSelectJoinGroupBy <EPExpenseClaimDetails,
                                                                                LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>, And <Where <Contract.baseType, Equal <Contract.ContractBaseType>, Or <Contract.nonProject, Equal <True> > > > >
                                                                                          >,
                                                                                Where <EPExpenseClaimDetails.released, Equal <boolTrue>,
                                                                                       And <EPExpenseClaimDetails.billable, Equal <boolTrue>,
                                                                                            And <EPExpenseClaimDetails.billed, Equal <boolFalse>,
                                                                                                 And <EPExpenseClaimDetails.customerID, Equal <Required <EPExpenseClaimDetails.customerID> >,
                                                                                                      And <EPExpenseClaimDetails.customerLocationID, Equal <Required <EPExpenseClaimDetails.customerLocationID> >,
                                                                                                           And <EPExpenseClaimDetails.expenseDate, LessEqual <Required <EPExpenseClaimDetails.expenseDate> >,
                                                                                                                And <EPExpenseClaimDetails.branchID, Equal <Required <EPExpenseClaimDetails.branchID> >,
                                                                                                                     And <Where <Contract.nonProject, Equal <True>, Or <EPExpenseClaimDetails.contractID, IsNull> > > > > > > > > >
                                                                                , Aggregate <Sum <EPExpenseClaimDetails.curyTranAmt> >
                                                                                > .Select(this, customer.CustomerID, customer.LocationID, filter.EndDate, row.BranchID);

                        if (summDetail.CuryTranAmt < 0)
                        {
                            signOperation = -1;
                        }
                        else
                        {
                            signOperation = 1;
                        }

                        arDoc = (ARInvoice)arGraph.Document.Cache.Insert();
                        //arDocList.Add(arDoc);
                        if (signOperation < 0)
                        {
                            arGraph.Document.Cache.SetValueExt <ARInvoice.docType>(arDoc, AR.ARDocType.CreditMemo);
                        }
                        else
                        {
                            arGraph.Document.Cache.SetValueExt <ARInvoice.docType>(arDoc, AR.ARDocType.Invoice);
                        }
                        arGraph.Document.Cache.SetValueExt <ARInvoice.customerID>(arDoc, row.CustomerID);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arDoc, row.CustomerLocationID);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.docDate>(arDoc, filter.InvoiceDate);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.branchID>(arDoc, row.BranchID);
                        arDoc.OrigModule  = BatchModule.EP;
                        arDoc.OrigRefNbr  = row.RefNbr;
                        arDoc             = arGraph.Document.Update(arDoc);
                        arDoc.FinPeriodID = filter.InvFinPeriodID;
                        if (Setup.Current.AutomaticReleaseAR == true)
                        {
                            arDoc.Hold = false;
                        }
                        doclist.Add(arDoc);
                    }

                    //insert ARTran
                    InsertARTran(arGraph, row, signOperation);
                    if ((row.CuryTipAmt ?? 0) != 0)
                    {
                        if (signOperation < 0 == row.ClaimCuryTranAmtWithTaxes < 0)
                        {
                            tipQty = 1;
                        }
                        else
                        {
                            tipQty = -1;
                        }
                        InsertARTran(arGraph, row, signOperation, tipQty, true);
                    }
                    listOfDirectBilledClaims.Add(row);
                }

                row.Billed = true;
                Transactions.Update(row);
            }

            if (arDoc != null)
            {
                arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                arGraph.Document.Update(arDoc);
                arGraph.Save.Press();
            }

            if (pmDoc != null)
            {
                pmGraph.Save.Press();
            }

            this.Persist(typeof(EPExpenseClaimDetails), PXDBOperation.Update);

            if (Setup.Current.AutomaticReleaseAR == true)
            {
                ARDocumentRelease.ReleaseDoc(doclist, false);
            }
        }
Пример #8
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);
        }
Пример #9
0
        public List <Batch> Release(JournalEntry je, PMRegister doc, out List <PMTask> allocTasks)
        {
            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.");

            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);

                    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.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 == PMProject.ProjectBaseType.Project &&
                            !string.IsNullOrEmpty(t.AccountGroup.Type) && t.AccountGroup.Type != PMAccountType.OffBalance && !ProjectDefaultAttribute.IsNonProject(this, t.Tran.ProjectID))
                        {
                            GLTran tran1 = new GLTran();
                            tran1.TranDate      = t.Tran.TranDate;
                            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.TranDesc      = t.Tran.Description;
                            tran1.ReferenceID   = t.Tran.BAccountID;
                            tran1.InventoryID   = t.Tran.InventoryID == PMProjectStatus.EmptyInventoryID ? null : t.Tran.InventoryID;
                            tran1.Qty           = t.Tran.Qty;
                            tran1.UOM           = t.Tran.UOM;
                            tran1.TranType      = t.Tran.TranType;
                            tran1.CuryCreditAmt = 0;
                            tran1.CreditAmt     = 0;
                            tran1.CuryDebitAmt  = t.Tran.Amount;
                            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.TranDate;
                            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(this);
                            tran2.TaskID        = t.OffsetAccountGroup.GroupID != null ? t.Tran.TaskID : null;
                            tran2.TranDesc      = t.Tran.Description;
                            tran2.ReferenceID   = t.Tran.BAccountID;
                            tran2.InventoryID   = t.Tran.InventoryID == PMProjectStatus.EmptyInventoryID ? null : t.Tran.InventoryID;
                            tran2.Qty           = t.Tran.Qty;
                            tran2.UOM           = t.Tran.UOM;
                            tran2.TranType      = t.Tran.TranType;
                            tran2.CuryCreditAmt = t.Tran.Amount;
                            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 == PMProject.ProjectBaseType.Project && t.Project.NonProject != true)
                            {
                                throw new PXException(Messages.AccountGroupIsRequired, doc.RefNbr);
                            }
                        }

                        IList <PMHistory> historyList = UpdateProjectBalance(je, t.Tran, t.Account, t.AccountGroup, t.OffsetAccount, t.OffsetAccountGroup);
                        if (!isGL)
                        {
                            #region History Update

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

                                hist = (PMHistoryAccum)je.Caches[typeof(PMHistoryAccum)].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();
                            }

                            #endregion
                        }

                        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.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.Persist(typeof(PMHistoryAccum), PXDBOperation.Insert);                        //only non-gl balance is updated
                        je.Save.Press();
                        batches.Add(je.BatchModule.Current);
                    }
                    else
                    {
                        je.Persist(typeof(PMTran), PXDBOperation.Update);
                        je.Persist(typeof(PMProjectStatusAccum), PXDBOperation.Insert);
                        je.Persist(typeof(PMTaskTotal), 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;
                je.Caches[typeof(PMRegister)].Update(doc);

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


                ts.Complete();
            }

            return(batches);
        }
Пример #10
0
        protected virtual void EPExpenseClaimDetails_ExpenseAccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            EPExpenseClaimDetails row = e.Row as EPExpenseClaimDetails;

            if (row != null && row.ContractID != null)
            {
                Contract contract = PXSelect <Contract> .Search <Contract.contractID>(this, row.ContractID);

                if (contract != null && contract.BaseType == PMProject.ProjectBaseType.Project && !ProjectDefaultAttribute.IsNonProject(this, row.ContractID))
                {
                    Account account = PXSelect <Account> .Search <Account.accountID>(this, row.ExpenseAccountID);

                    if (account.AccountGroupID == null)
                    {
                        sender.RaiseExceptionHandling <EPExpenseClaimDetails.expenseAccountID>(e.Row, account.AccountCD,
                                                                                               new PXSetPropertyException(Messages.AccountGroupIsNotAssignedForAccount, account.AccountCD.Trim(), PXErrorLevel.Error));
                    }
                }
            }
        }
Пример #11
0
        public virtual void Bill(CustomersList customer, PX.Objects.EP.EPCustomerBilling.BillingFilter filter)
        {
            ARInvoiceEntry arGraph = PXGraph.CreateInstance <ARInvoiceEntry>();
            RegisterEntry  pmGraph = PXGraph.CreateInstance <RegisterEntry>();

            arGraph.Clear();
            pmGraph.Clear();

            PMRegister pmDoc = null;
            ARInvoice  arDoc = null;

            List <ARRegister>            doclist = new List <ARRegister>();
            List <EPExpenseClaimDetails> listOfDirectBilledClaims = new List <EPExpenseClaimDetails>();

            PXSelectBase <EPExpenseClaimDetails> select = new PXSelectJoin <EPExpenseClaimDetails,
                                                                            InnerJoin <EPExpenseClaim, On <EPExpenseClaimDetails.refNbr, Equal <EPExpenseClaim.refNbr> > >,
                                                                            Where <EPExpenseClaimDetails.released, Equal <boolTrue>,
                                                                                   And <EPExpenseClaimDetails.billable, Equal <boolTrue>,
                                                                                        And <EPExpenseClaimDetails.billed, Equal <boolFalse>,
                                                                                             And <EPExpenseClaimDetails.customerID, Equal <Required <EPExpenseClaimDetails.customerID> >,
                                                                                                  And <EPExpenseClaimDetails.customerLocationID, Equal <Required <EPExpenseClaimDetails.customerLocationID> >,
                                                                                                       And <EPExpenseClaimDetails.expenseDate, LessEqual <Required <EPExpenseClaimDetails.expenseDate> > > > > > > >,
                                                                            OrderBy <Asc <EPExpenseClaimDetails.customerID, Asc <EPExpenseClaimDetails.customerLocationID> > > >(this);

            foreach (PXResult <EPExpenseClaimDetails, EPExpenseClaim> res in select.Select(customer.CustomerID, customer.LocationID, filter.EndDate))
            {
                EPExpenseClaimDetails row = (EPExpenseClaimDetails)res;
                EPExpenseClaim        doc = (EPExpenseClaim)res;

                if (row.ContractID != null && !ProjectDefaultAttribute.IsNonProject(this, row.ContractID))
                {
                    if (pmDoc == null)
                    {
                        pmDoc             = (PMRegister)pmGraph.Document.Cache.Insert();
                        pmDoc.OrigDocType = PMOrigDocType.ExpenseClaim;
                        pmDoc.OrigDocNbr  = doc.RefNbr;
                    }

                    InsertPMTran(pmGraph, row, doc, Setup.Current.CopyNotesPM == true, Setup.Current.CopyFilesPM == true);
                }
                else
                {
                    if (arDoc == null ||
                        arDoc.CustomerID != row.CustomerID ||
                        arDoc.CustomerLocationID != row.CustomerLocationID)
                    {
                        if (arDoc != null)
                        {
                            arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                            arGraph.Document.Update(arDoc);
                            arGraph.Save.Press();
                        }
                        arDoc                    = (ARInvoice)arGraph.Document.Cache.Insert();
                        arDoc.DocType            = AR.ARDocType.Invoice;
                        arDoc.CustomerID         = row.CustomerID;
                        arDoc.CustomerLocationID = row.CustomerLocationID;
                        arDoc                    = arGraph.Document.Update(arDoc);
                        arGraph.Document.Cache.RaiseFieldUpdated <AR.ARInvoice.customerID>(arDoc, null);
                        if (Setup.Current.AutomaticReleaseAR == true)
                        {
                            arDoc.Hold = false;
                        }
                        doclist.Add(arDoc);
                    }

                    //insert ARTran
                    InsertARTran(arGraph, row, Setup.Current.CopyNotesAR == true, Setup.Current.CopyFilesAR == true);
                    listOfDirectBilledClaims.Add(row);
                }

                row.Billed = true;
                Transactions.Update(row);
            }

            if (arDoc != null)
            {
                arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                arGraph.Document.Update(arDoc);

                arGraph.RowPersisted.AddHandler <ARInvoice>(
                    delegate(PXCache sender, PXRowPersistedEventArgs e)
                {
                    if (e.TranStatus == PXTranStatus.Open)
                    {
                        foreach (EPExpenseClaimDetails claimdetail in listOfDirectBilledClaims)
                        {
                            EPExpenseClaimDetails row = Transactions.Locate(claimdetail);

                            row.ARDocType = ((ARInvoice)e.Row).DocType;
                            row.ARRefNbr  = ((ARInvoice)e.Row).RefNbr;
                        }
                    }
                });

                arGraph.Save.Press();
            }
            if (pmDoc != null)
            {
                pmGraph.Save.Press();
            }

            this.Persist(typeof(EPExpenseClaimDetails), PXDBOperation.Update);

            if (Setup.Current.AutomaticReleaseAR == true)
            {
                ARDocumentRelease.ReleaseDoc(doclist, false);
            }
        }
Пример #12
0
        public virtual void Bill(CustomersList customer, EPCustomerBilling.BillingFilter filter)
        {
            ARInvoiceEntry arGraph = PXGraph.CreateInstance <ARInvoiceEntry>();
            RegisterEntry  pmGraph = PXGraph.CreateInstance <RegisterEntry>();

            arGraph.Clear();
            pmGraph.Clear();

            PMRegister pmDoc = null;
            ARInvoice  arDoc = null;

            List <ARRegister>            doclist = new List <ARRegister>();
            List <EPExpenseClaimDetails> listOfDirectBilledClaims = new List <EPExpenseClaimDetails>();

            PXSelectBase <EPExpenseClaimDetails> select = new PXSelectJoin <EPExpenseClaimDetails,
                                                                            LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>,
                                                                                                    And <Where <Contract.baseType, Equal <CTPRType.contract>,
                                                                                                                Or <Contract.nonProject, Equal <True> > > > >,
                                                                                      LeftJoin <Account, On <EPExpenseClaimDetails.expenseAccountID, Equal <Account.accountID> > > >,
                                                                            Where <EPExpenseClaimDetails.released, Equal <boolTrue>,
                                                                                   And <EPExpenseClaimDetails.billable, Equal <boolTrue>,
                                                                                        And <EPExpenseClaimDetails.billed, Equal <boolFalse>,
                                                                                             And <EPExpenseClaimDetails.customerID, Equal <Required <EPExpenseClaimDetails.customerID> >,
                                                                                                  And <EPExpenseClaimDetails.customerLocationID, Equal <Required <EPExpenseClaimDetails.customerLocationID> >,
                                                                                                       And <EPExpenseClaimDetails.expenseDate, LessEqual <Required <EPExpenseClaimDetails.expenseDate> >,
                                                                                                            And <Where <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>,
                                                                                                                        Or <EPExpenseClaimDetails.contractID, IsNull> > > > > > > > >,
                                                                            OrderBy <Asc <EPExpenseClaimDetails.branchID> > >(this);

            arGraph.RowPersisted.AddHandler <ARInvoice>(
                delegate(PXCache sender, PXRowPersistedEventArgs e)
            {
                if (e.TranStatus == PXTranStatus.Open)
                {
                    foreach (EPExpenseClaimDetails row in listOfDirectBilledClaims.Select(claimdetail => Transactions.Locate(claimdetail)))
                    {
                        row.ARDocType = ((ARInvoice)e.Row).DocType;
                        row.ARRefNbr  = ((ARInvoice)e.Row).RefNbr;
                    }
                }
            });

            decimal signOperation = 1m;
            decimal tipQty        = 1m;

            var resultset = select.Select(customer.CustomerID, customer.LocationID, filter.EndDate).AsEnumerable();

            FinPeriodUtils.ValidateFinPeriod <EPExpenseClaimDetails>(
                resultset.RowCast <EPExpenseClaimDetails>(),
                m => filter.InvFinPeriodID,
                m => m.BranchID.SingleToArray());

            foreach (PXResult <EPExpenseClaimDetails, Contract, Account> res in resultset)
            {
                EPExpenseClaimDetails row = (EPExpenseClaimDetails)res;

                if (row.ContractID != null && !ProjectDefaultAttribute.IsNonProject(row.ContractID))
                {
                    if (pmDoc == null)
                    {
                        EPExpenseClaim claim = PXSelect <EPExpenseClaim, Where <EPExpenseClaim.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(this, row.RefNbr);

                        pmDoc             = (PMRegister)pmGraph.Document.Cache.Insert();
                        pmDoc.OrigDocType = PMOrigDocType.ExpenseClaim;
                        pmDoc.OrigNoteID  = claim.NoteID;
                    }

                    PMTran usage = InsertPMTran(pmGraph, res);
                    if (usage.Released == true)                     //contract trans are created as released
                    {
                        UsageMaint.AddUsage(pmGraph.Transactions.Cache, usage.ProjectID, usage.InventoryID, usage.BillableQty ?? 0m, usage.UOM);
                    }
                }
                else
                {
                    if (arDoc == null || arDoc.BranchID != row.BranchID)
                    {
                        if (arDoc != null)
                        {
                            arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                            arGraph.Document.Update(arDoc);
                            arGraph.Save.Press();
                            listOfDirectBilledClaims.Clear();
                        }

                        EPExpenseClaimDetails summDetail = PXSelectJoinGroupBy <EPExpenseClaimDetails,
                                                                                LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID>,
                                                                                                        And <Where <Contract.baseType, Equal <CTPRType.contract>,
                                                                                                                    Or <Contract.nonProject, Equal <True> > > > > >,
                                                                                Where <EPExpenseClaimDetails.released, Equal <boolTrue>,
                                                                                       And <EPExpenseClaimDetails.billable, Equal <boolTrue>,
                                                                                            And <EPExpenseClaimDetails.billed, Equal <boolFalse>,
                                                                                                 And <EPExpenseClaimDetails.customerID, Equal <Required <EPExpenseClaimDetails.customerID> >,
                                                                                                      And <EPExpenseClaimDetails.customerLocationID, Equal <Required <EPExpenseClaimDetails.customerLocationID> >,
                                                                                                           And <EPExpenseClaimDetails.expenseDate, LessEqual <Required <EPExpenseClaimDetails.expenseDate> >,
                                                                                                                And <EPExpenseClaimDetails.branchID, Equal <Required <EPExpenseClaimDetails.branchID> >,
                                                                                                                     And <Where <Contract.nonProject, Equal <True>,
                                                                                                                                 Or <EPExpenseClaimDetails.contractID, IsNull> > > > > > > > > >,
                                                                                Aggregate <Sum <EPExpenseClaimDetails.curyTranAmt> > >
                                                           .Select(this, customer.CustomerID, customer.LocationID, filter.EndDate, row.BranchID);

                        signOperation = summDetail.CuryTranAmt < 0 ? -1 : 1;

                        // OrigModule should be set before Insert() method
                        // to organize proper defaulting for any other fields
                        // which depend on OrigModule value.
                        //
                        arDoc            = new ARInvoice();
                        arDoc.OrigModule = BatchModule.EP;
                        arGraph.Document.Cache.SetValueExt <ARInvoice.docType>(arDoc,
                                                                               signOperation < 0 ? ARDocType.CreditMemo : ARDocType.Invoice);

                        arDoc = (ARInvoice)arGraph.Document.Cache.Insert(arDoc);

                        arGraph.Document.Cache.SetValueExt <ARInvoice.customerID>(arDoc, row.CustomerID);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arDoc, row.CustomerLocationID);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.docDate>(arDoc, filter.InvoiceDate);
                        arGraph.Document.Cache.SetValueExt <ARInvoice.branchID>(arDoc, row.BranchID);
                        arDoc.OrigRefNbr  = row.RefNbr;
                        arDoc             = arGraph.Document.Update(arDoc);
                        arDoc.FinPeriodID = filter.InvFinPeriodID;
                        doclist.Add(arDoc);
                    }

                    // Insert ARTran.
                    //
                    InsertARTran(arGraph, row, signOperation);
                    if ((row.CuryTipAmt ?? 0) != 0)
                    {
                        tipQty = signOperation < 0 == row.ClaimCuryTranAmtWithTaxes < 0 ? 1 : -1;
                        InsertARTran(arGraph, row, signOperation, tipQty, true);
                    }

                    listOfDirectBilledClaims.Add(row);
                }

                row.Billed = true;
                Transactions.Update(row);
            }

            if (arDoc != null)
            {
                arDoc.CuryOrigDocAmt = arDoc.CuryDocBal;
                if (arGraph.ARSetup.Current.HoldEntry == false || Setup.Current.AutomaticReleaseAR == true)
                {
                    arDoc = PXCache <ARInvoice> .CreateCopy(arDoc);

                    arDoc.Hold = false;
                    arDoc      = arGraph.Document.Update(arDoc);
                }
                arGraph.Document.Update(arDoc);
                arGraph.Save.Press();
            }

            if (pmDoc != null)
            {
                pmGraph.Save.Press();
            }

            Persist(typeof(EPExpenseClaimDetails), PXDBOperation.Update);

            if (Setup.Current.AutomaticReleaseAR == true)
            {
                ARDocumentRelease.ReleaseDoc(doclist, false);
            }
        }