protected virtual void PMBudget_UOM_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMBudget row = e.Row as PMBudget;

            if (row == null || string.IsNullOrEmpty(row.UOM))
            {
                return;
            }

            var select = new PXSelect <PMTran, Where <PMTran.projectID, Equal <Current <PMBudget.projectID> >,
                                                      And <PMTran.taskID, Equal <Current <PMBudget.projectTaskID> >,
                                                           And <PMTran.costCodeID, Equal <Current <PMBudget.costCodeID> >,
                                                                And <PMTran.inventoryID, Equal <Current <PMBudget.inventoryID> >,
                                                                     And2 <Where <PMTran.accountGroupID, Equal <Current <PMBudget.accountGroupID> >, Or <PMTran.offsetAccountGroupID, Equal <Current <PMBudget.accountGroupID> > > >,
                                                                           And <PMTran.released, Equal <True>,
                                                                                And <PMTran.uOM, NotEqual <Required <PMTran.uOM> > > > > > > > > >(this);

            string uom = (string)e.NewValue;

            if (!string.IsNullOrEmpty(uom))
            {
                PMTran tranInOtherUOM = select.SelectWindowed(0, 1, uom);

                if (tranInOtherUOM != null)
                {
                    var ex = new PXSetPropertyException(Messages.OtherUomUsedInTransaction);
                    ex.ErrorValue = uom;
                    throw ex;
                }
            }
        }
        public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.AllocationReversal;
            reversalDoc.OrigDocNbr   = tran.RefNbr;
            reversalDoc.Description  = "Allocation Reversal to Non-Billable";
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                reverse.Reversed = true;
                pmEntry.Transactions.Insert(reverse);
            }

            tran.Reversed = true;
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
Esempio n. 3
0
        public decimal?GetRate(string rateTableID, string rateTypeID, PMTran tran)
        {
            if (string.IsNullOrEmpty(rateTableID))
            {
                throw new ArgumentNullException(nameof(rateTableID), PXMessages.LocalizeNoPrefix(Messages.ArgumentIsNullOrEmpty));
            }

            trace = new StringBuilder();

            trace.AppendFormat("Calculating Rate. RateTable:{0}, RateType:{1}", rateTableID, rateTypeID);

            List <PMRateDefinition> list;

            if (definitions.TryGetValue(GetDefinitionKey(rateTableID, rateTypeID), out list))
            {
                foreach (PMRateDefinition rd in list)
                {
                    trace.AppendFormat("Start Processing Sequence:{0}", rd.Description);
                    decimal?rate = GetRate(rd, tran);
                    if (rate != null)
                    {
                        trace.AppendFormat("End Processing Sequence. Rate Defined:{0}", rate);
                        return(rate);
                    }
                    else
                    {
                        trace.AppendFormat("End Processing Sequence. Rate Not Defined");
                    }
                }
            }
            return(null);
        }
		public virtual object Evaluate(PMNameNode node, PMTran row)
		{
			if ( node.IsAttribute )
				return engine.Evaluate(node.ObjectName, null, node.FieldName, row);
			else
				return engine.Evaluate(node.ObjectName, node.FieldName, null, row);
		}
        public virtual PMTran ExpenseTransactionFromBudget(PMBudget budget, PMProject project, PMTask task, PMAccountGroup accountGroup, InventoryItem item, PMCostCode costcode)
        {
            PMTran tran = new PMTran();

            tran.AccountGroupID    = budget.AccountGroupID;
            tran.ProjectID         = budget.ProjectID;
            tran.TaskID            = budget.ProjectTaskID;
            tran.InventoryID       = budget.InventoryID;
            tran.AccountID         = item.InventoryID != null ? item.COGSAcctID : accountGroup.AccountID;
            tran.SubID             = item.InventoryID != null ? item.COGSSubID : accountGroup.AccountID;
            tran.TranCuryAmount    = budget.CuryRevisedAmount;
            tran.ProjectCuryAmount = budget.CuryRevisedAmount;
            tran.TranCuryID        = project.CuryID;
            tran.ProjectCuryID     = project.CuryID;
            tran.Qty            = budget.RevisedQty;
            tran.UOM            = budget.UOM;
            tran.BAccountID     = task.CustomerID;
            tran.LocationID     = task.LocationID;
            tran.Billable       = true;
            tran.UseBillableQty = true;
            tran.BillableQty    = budget.RevisedQty;
            tran.Released       = true;

            return(tran);
        }
Esempio n. 6
0
        /// <summary>
        /// Increases the counter of unbilled transactions.
        /// Billed and Reversed transactions are ignored.
        /// Note: Although the method will add all necessary caches to the views collection of the graph to be saved on persist.
        /// This will work only if the graph is persisted within the context of current request. If there will be graph load/unload
        /// between this call and the Persist please add the required Caches to the graph manualy.
        /// </summary>
        public static void AddToUnbilledSummary(PXGraph graph, PMTran tran)
        {
            if (tran.Billed == true || tran.ExcludedFromBilling == true)
            {
                return;
            }

            UpdateUnbilledSummary(graph, tran, false);
        }
        protected virtual List <PMTran> CreateExpenseTransactions(PMTask task, out DateTime?lastDate)
        {
            lastDate = null;

            PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus,
                                                                      InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >,
                                                                                 InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >,
                                                                                            LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >,
                                                                      Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >,
                                                                             And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >,
                                                                                  And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this);

            List <PMTran> trans = new List <PMTran>();

            foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID))
            {
                PMProjectStatus ps   = (PMProjectStatus)res;
                InventoryItem   item = (InventoryItem)res;

                PMTran tran = new PMTran();
                tran.AccountGroupID = ps.AccountGroupID;
                tran.ProjectID      = ps.ProjectID;
                tran.TaskID         = ps.ProjectTaskID;
                tran.InventoryID    = ps.InventoryID;
                tran.AccountID      = item.InventoryID != null ? item.COGSAcctID : null;
                tran.SubID          = item.InventoryID != null ? item.COGSSubID : null;
                tran.Amount         = ps.Amount;
                tran.Qty            = ps.Qty;
                tran.UOM            = ps.UOM;
                tran.BAccountID     = task.CustomerID;
                tran.LocationID     = task.LocationID;
                tran.Billable       = true;
                tran.UseBillableQty = true;
                tran.BillableQty    = ps.RevisedQty;
                tran.Date           = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID);
                tran.StartDate      = tran.Date;
                tran.EndDate        = tran.Date;
                tran.FinPeriodID    = ps.PeriodID;
                tran.TranPeriodID   = ps.PeriodID;
                tran.Released       = true;

                if (lastDate != null)
                {
                    if (lastDate < tran.Date)
                    {
                        lastDate = tran.Date;
                    }
                }
                else
                {
                    lastDate = tran.Date;
                }
                trans.Add(Transactions.Insert(tran));
            }

            return(trans);
        }
Esempio n. 8
0
        /// <summary>
        /// Decreases the counter of unbilled transactions.
        /// Only Billed or Reversed transactions are processed.
        /// Note: Although the method will add all necessary caches to the views collection of the graph to be saved on persist.
        /// This will work only if the graph is persisted within the context of current request. If there will be graph load/unload
        /// between this call and the Persist please add the required Caches to the graph manualy.
        /// </summary>
        public static void SubtractFromUnbilledSummary(PXGraph graph, PMTran tran)
        {
            if (tran.Billed != true && tran.ExcludedFromBilling != true)
            {
                return;
            }

            UpdateUnbilledSummary(graph, tran, true);
        }
Esempio n. 9
0
 public BillingData(ARTran tran, PMBillingRule rule, PMTran pmTran, string subCD, string note, Guid[] files)
 {
     this.Tran   = tran;
     this.Rule   = rule;
     this.PMTran = pmTran;
     this.SubCD  = subCD;
     this.Note   = note;
     this.Files  = files;
 }
Esempio n. 10
0
        /// <summary>
        /// Increases the counter of unbilled transactions.
        /// Billed and Reversed transactions are ignored.
        /// </summary>
        public static void AddToUnbilledSummary(PXGraph graph, PMTran tran)
        {
            if (tran.Billed == true || tran.Reversed == true)
            {
                return;
            }

            UpdateUnbilledSummary(graph, tran, false);
        }
Esempio n. 11
0
        protected virtual void ARTran_RowDeleted(PXCache sender, PXRowDeletedEventArgs e)
        {
            if (Base.Document.Current.IsRetainageDocument != true && ((ARTran)e.Row).TaskID != null && Base.Document.Current.ProformaExists != true)
            {
                AddToInvoiced((ARTran)e.Row, GetProjectedAccountGroup((ARTran)e.Row), -1 * (int)ARDocType.SignAmount(((ARTran)e.Row).TranType).GetValueOrDefault(1));

                var select = new PXSelect <PMTran, Where <PMTran.aRTranType, Equal <Required <PMTran.aRTranType> >,
                                                          And <PMTran.aRRefNbr, Equal <Required <PMTran.aRRefNbr> >,
                                                               And <PMTran.refLineNbr, Equal <Required <PMTran.refLineNbr> > > > > >(Base);

                string tranType = ((ARTran)e.Row).TranType;
                string refNbr   = ((ARTran)e.Row).RefNbr;
                int?   lineNbr  = ((ARTran)e.Row).LineNbr;

                if (tranType == ARDocType.CreditMemo && !string.IsNullOrEmpty(Base.Document.Current.OrigRefNbr))
                {
                    tranType = Base.Document.Current.OrigDocType;
                    refNbr   = Base.Document.Current.OrigRefNbr;
                    lineNbr  = ((ARTran)e.Row).OrigLineNbr;
                }

                PMTran original = select.SelectWindowed(0, 1, tranType, refNbr, lineNbr);

                if (original == null)                                                                                                                                                 //progressive line
                {
                    SubtractAmountToInvoice(((ARTran)e.Row), GetProjectedAccountGroup((ARTran)e.Row), -1 * (int)ARDocType.SignAmount(((ARTran)e.Row).TranType).GetValueOrDefault(1)); //Restoring AmountToInvoice
                }
            }

            if (e.Row != null)
            {
                if (!isARInvoiceDeleting)
                {
                    foreach (PM.PMTran pMRef in Base.RefContractUsageTran.Select(((ARTran)e.Row).TranType, ((ARTran)e.Row).RefNbr, ((ARTran)e.Row).LineNbr))
                    {
                        if (pMRef != null)
                        {
                            pMRef.ARRefNbr   = null;
                            pMRef.ARTranType = null;
                            pMRef.RefLineNbr = null;
                            if (Base.Document.Current != null && Base.Document.Current.ProformaExists != true)
                            {
                                pMRef.Billed         = false;
                                pMRef.BilledDate     = null;
                                pMRef.InvoicedQty    = 0;
                                pMRef.InvoicedAmount = 0;
                                PM.RegisterReleaseProcess.AddToUnbilledSummary(Base, pMRef);
                            }

                            Base.RefContractUsageTran.Update(pMRef);
                        }
                    }
                }
            }
        }
 public virtual object Evaluate(PMNameNode node, PMTran row)
 {
     if (node.IsAttribute)
     {
         return(engine.Evaluate(node.ObjectName, null, node.FieldName, row));
     }
     else
     {
         return(engine.Evaluate(node.ObjectName, node.FieldName, null, row));
     }
 }
Esempio n. 13
0
        protected virtual bool IsNonGL(PMTran tran)
        {
            if (tran.IsNonGL == true)
            {
                return(true);
            }

            if (tran.AccountID == null && tran.OffsetAccountID == null)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 14
0
        protected virtual IList <PMTran> ReverseTranNonGL(PMTran tran)
        {
            List <PMTran> list = new List <PMTran>();

            //debit:
            PMTran debit = new PMTran();

            debit.AccountGroupID       = tran.AccountGroupID;
            debit.OffsetAccountGroupID = tran.OffsetAccountGroupID;
            debit.ProjectID            = tran.ProjectID;
            debit.Date        = tran.Date;
            debit.FinPeriodID = tran.FinPeriodID;
            debit.TaskID      = tran.TaskID;
            debit.InventoryID = tran.InventoryID;
            debit.Description = tran.Description;
            debit.UOM         = tran.UOM;
            debit.Qty         = -tran.Qty;
            debit.Billable    = tran.Billable;
            debit.BillableQty = -tran.BillableQty;
            debit.Amount      = -tran.Amount;
            debit.Allocated   = true;
            debit.Billed      = true;
            debit.IsNonGL     = true;
            list.Add(debit);

            //credit:
            if (tran.OffsetAccountGroupID != null)
            {
                PMTran credit = new PMTran();
                credit.AccountGroupID = tran.OffsetAccountGroupID;
                credit.ProjectID      = tran.ProjectID;
                credit.TaskID         = tran.TaskID;
                credit.InventoryID    = tran.InventoryID;
                credit.Description    = tran.Description;
                credit.Date           = tran.Date;
                credit.FinPeriodID    = tran.FinPeriodID;
                credit.UOM            = tran.UOM;
                credit.Qty            = tran.Qty;
                credit.Billable       = tran.Billable;
                credit.BillableQty    = tran.BillableQty;
                credit.Amount         = tran.Amount;
                credit.Allocated      = true;
                credit.Billed         = true;
                credit.IsNonGL        = true;
                list.Add(credit);
            }

            return(list);
        }
Esempio n. 15
0
		public RateEngine(PXGraph graph, string rateTypeID, PMTran tran)
		{
			if (graph == null)
				throw new ArgumentNullException("graph");

			if (string.IsNullOrEmpty(rateTypeID))
				throw new ArgumentNullException("rateTypeID", "Argument is null or an empty string");
						
			if (tran == null)
				throw new ArgumentNullException("tran");

			this.graph = graph;
			this.rateTypeID = rateTypeID;
			this.tran = tran;
		}
Esempio n. 16
0
        public virtual IList <PMTran> ReverseTran(PMTran tran)
        {
            List <PMTran> list = new List <PMTran>();

            if (IsNonGL(tran))
            {
                list.AddRange(ReverseTranNonGL(tran));
            }
            else
            {
                list.Add(ReverseTranGL(tran));
            }

            return(list);
        }
        protected virtual void PMTran_AccountID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMTran row = e.Row as PMTran;

            if (row != null && e.NewValue != null)
            {
                Account item = PXSelect <Account, Where2 <Match <Current <AccessInfo.userName> >, And <Account.accountID, Equal <Required <Account.accountID> > > > > .Select(sender.Graph, e.NewValue);

                if (row != null && item != null && (item.AccountGroupID == null || item.AccountGroupID != row.AccountGroupID))
                {
                    PMAccountGroup accountGroup = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(sender.Graph, row.AccountGroupID);

                    throw new PXException(PM.Messages.AccountIsNotAssociatedWithAccountGroup, item.AccountCD, accountGroup.GroupCD);
                }
            }
        }
        protected virtual bool IsUnbilled(PMTran tran, string billingID)
        {
            if (billable == null)
            {
                PXResultset <PMBillingRule> rules = PXSelect <PMBillingRule> .Select(this);

                billable = new List <string>(rules.Count);

                foreach (PMBillingRule rule in rules)
                {
                    billable.Add(string.Format("{0}.{1}", rule.BillingID, rule.AccountGroupID));
                }
            }

            return(billable.Contains(string.Format("{0}.{1}", billingID, tran.AccountGroupID)));
        }
Esempio n. 19
0
        protected virtual void PMTask_BillingID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMTask row = e.Row as PMTask;

            if (row != null)
            {
                PMTran allocatedTran = PXSelect <PMTran, Where <PMTran.billingID, NotEqual <Required <PMTran.billingID> >,
                                                                And <PMTran.allocated, Equal <True>,
                                                                     And <PMTran.projectID, Equal <Current <PMTask.projectID> >,
                                                                          And <PMTran.taskID, Equal <Current <PMTask.taskID> > > > > > > .SelectWindowed(this, 0, 1, e.NewValue);

                if (allocatedTran != null)
                {
                    sender.RaiseExceptionHandling <PMTask.billingID>(e.Row, e.NewValue, new PXSetPropertyException(Warnings.HasAllocatedTrans, PXErrorLevel.Warning, allocatedTran.BillingID));
                }
            }
        }
        protected virtual void PMTran_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            PMTran row = e.Row as PMTran;

            if (row != null)
            {
                PMAccountGroup accGroup = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMTran.accountGroupID> > > > .Select(this, row.AccountGroupID);

                if (accGroup.Type == GL.AccountType.Income || accGroup.Type == GL.AccountType.Liability)
                {
                    row.AmountNormal = row.Amount * -1;
                }
                else
                {
                    row.AmountNormal = row.Amount;
                }
            }
        }
Esempio n. 21
0
        public string GetTrace(PMTran tran)
        {
            //Add transaction properties:
            PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(graph, tran.AccountGroupID);

            if (ag != null)
            {
                trace.AppendFormat(" PMTran.AccountGroup={0} ", ag.GroupCD);
            }

            IN.InventoryItem inventoryItem = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(graph, tran.InventoryID);

            if (inventoryItem != null)
            {
                trace.AppendFormat(" PMTran.InventoryID={0} ", inventoryItem.InventoryCD);
            }

            return(trace.ToString());
        }
Esempio n. 22
0
        protected virtual PMTran ReverseTranGL(PMTran tran)
        {
            Account offsetAccount = PXSelect <Account, Where <Account.accountID, Equal <Required <Account.accountID> > > > .Select(this, tran.OffsetAccountID);

            if (offsetAccount != null && offsetAccount.AccountGroupID != null)
            {
                //Debit-Credit reversal
                PMTran rvrs = PXCache <PMTran> .CreateCopy(tran);

                rvrs.TranID          = null;
                rvrs.TranType        = null;
                rvrs.RefNbr          = null;
                rvrs.RefLineNbr      = null;
                rvrs.BatchNbr        = null;
                rvrs.TranDate        = null;
                rvrs.TranPeriodID    = null;
                rvrs.Released        = null;
                rvrs.AccountID       = tran.OffsetAccountID;
                rvrs.SubID           = tran.OffsetSubID;
                rvrs.OffsetAccountID = tran.AccountID;
                rvrs.OffsetSubID     = tran.SubID;
                rvrs.AccountGroupID  = offsetAccount.AccountGroupID;
                return(rvrs);
            }
            else
            {
                //-ve reversal
                PMTran rvrs = PXCache <PMTran> .CreateCopy(tran);

                rvrs.TranID       = null;
                rvrs.TranType     = null;
                rvrs.RefNbr       = null;
                rvrs.RefLineNbr   = null;
                rvrs.BatchNbr     = null;
                rvrs.TranDate     = null;
                rvrs.TranPeriodID = null;
                rvrs.Released     = null;
                rvrs.Amount      *= -1;
                rvrs.Qty         *= -1;
                rvrs.BillableQty *= -1;
                return(rvrs);
            }
        }
        public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.AllocationReversal;
            reversalDoc.OrigDocNbr   = tran.RefNbr;
            reversalDoc.Description  = PXMessages.LocalizeNoPrefix(Messages.AllocationReversalNonBilling);
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                reverse.Reversed     = true;
                reverse.Date         = null;
                reverse.FinPeriodID  = null;
                reverse.TranDate     = null;
                reverse.TranPeriodID = null;

                pmEntry.Transactions.Insert(reverse);
            }

            tran.Reversed = true;
            PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran);
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
Esempio n. 24
0
        public virtual IEnumerable ViewAllocation(PXAdapter adapter)
        {
            PMAllocationAuditTran audit = PXSelect <PMAllocationAuditTran, Where <PMAllocationAuditTran.sourceTranID, Equal <Current <PMTran.tranID> > > > .SelectSingleBound(this, new object[] { Transactions.Current });

            if (audit != null)
            {
                PMTran allocation = PXSelect <PMTran, Where <PMTran.tranID, Equal <Required <PMTran.tranID> > > > .Select(this, audit.TranID);

                if (allocation != null)
                {
                    RegisterEntry graph = CreateInstance <RegisterEntry>();
                    graph.Document.Current = graph.Document.Search <PMRegister.refNbr>(allocation.RefNbr, allocation.TranType);
                    throw new PXRedirectRequiredException(graph, "PMTransactiosn")
                          {
                              Mode = PXBaseRedirectException.WindowMode.NewWindow
                          };
                }
            }

            return(adapter.Get());
        }
Esempio n. 25
0
        public RateEngine(PXGraph graph, string rateTypeID, PMTran tran)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }

            if (string.IsNullOrEmpty(rateTypeID))
            {
                throw new ArgumentNullException(nameof(rateTypeID), PXMessages.LocalizeNoPrefix(Messages.ArgumentIsNullOrEmpty));
            }

            if (tran == null)
            {
                throw new ArgumentNullException(nameof(tran));
            }

            this.graph      = graph;
            this.rateTypeID = rateTypeID;
            this.tran       = tran;
        }
        public RateEngine(PXGraph graph, string rateTypeID, PMTran tran)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            if (string.IsNullOrEmpty(rateTypeID))
            {
                throw new ArgumentNullException("rateTypeID", Messages.ArgumentNullEmptyError);
            }

            if (tran == null)
            {
                throw new ArgumentNullException("tran");
            }

            this.graph      = graph;
            this.rateTypeID = rateTypeID;
            this.tran       = tran;
        }
        public virtual List <PMTran> CreateExpenseTransactions(int?projectID)
        {
            PXSelectBase <PMBudget> select = new PXSelectJoin <PMBudget,
                                                               InnerJoin <PMProject, On <PMProject.contractID, Equal <PMBudget.projectID> >,
                                                                          InnerJoin <PMTask, On <PMTask.projectID, Equal <PMBudget.projectID>, And <PMTask.taskID, Equal <PMBudget.projectTaskID> > >,
                                                                                     InnerJoin <PMAccountGroup, On <PMBudget.accountGroupID, Equal <PMAccountGroup.groupID> >,
                                                                                                InnerJoin <PMCostCode, On <PMBudget.costCodeID, Equal <PMCostCode.costCodeID> >,
                                                                                                           LeftJoin <InventoryItem, On <PMBudget.inventoryID, Equal <InventoryItem.inventoryID> > > > > > >,
                                                               Where <PMBudget.projectID, Equal <Required <PMTask.projectID> >,
                                                                      And <PMAccountGroup.type, Equal <AccountType.expense> > > >(this);

            List <PMTran> trans = new List <PMTran>();

            foreach (PXResult <PMBudget, PMProject, PMTask, PMAccountGroup, PMCostCode, InventoryItem> res in select.Select(projectID))
            {
                PMTran tran = ExpenseTransactionFromBudget(res, res, res, res, res, res);

                trans.Add(Transactions.Insert(tran));
            }

            return(trans);
        }
Esempio n. 28
0
        private static void UpdateUnbilledSummary(PXGraph graph, PMTran tran, bool reverse)
        {
            if (tran.ProjectID == null || tran.TaskID == null || tran.AccountGroupID == null || tran.Date == null)
            {
                return;
            }

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

            int counter = reverse ? -1 : 1;

            PMUnbilledDailySummaryAccum unbilled = new PMUnbilledDailySummaryAccum();

            unbilled.ProjectID      = tran.ProjectID;
            unbilled.TaskID         = tran.TaskID;
            unbilled.AccountGroupID = tran.AccountGroupID;
            unbilled.Date           = tran.Date;
            unbilled = (PMUnbilledDailySummaryAccum)graph.Caches[typeof(PMUnbilledDailySummaryAccum)].Insert(unbilled);

            unbilled.Billable    += tran.Billable == true ? counter : 0;
            unbilled.NonBillable += tran.Billable == true ? 0 : counter;
        }
Esempio n. 29
0
        protected virtual void RunAutoBudget(PMTask task)
        {
            PXSelectBase <PMProjectStatus> select = new PXSelectJoin <PMProjectStatus,
                                                                      InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >,
                                                                                 InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> >,
                                                                                            LeftJoin <InventoryItem, On <PMProjectStatus.inventoryID, Equal <InventoryItem.inventoryID> > > > >,
                                                                      Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >,
                                                                             And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >,
                                                                                  And <PMAccountGroup.type, Equal <AccountType.expense> > > > >(this);

            List <PMTran> trans = new List <PMTran>();

            foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup, InventoryItem> res in select.Select(task.ProjectID, task.TaskID))
            {
                PMProjectStatus ps   = (PMProjectStatus)res;
                InventoryItem   item = (InventoryItem)res;

                PMTran tran = new PMTran();
                tran.AccountGroupID = ps.AccountGroupID;
                tran.ProjectID      = ps.ProjectID;
                tran.TaskID         = ps.ProjectTaskID;
                tran.InventoryID    = ps.InventoryID;
                tran.AccountID      = item.InventoryID != null ? item.SalesAcctID : null;
                tran.Amount         = ps.RevisedAmount;
                tran.Qty            = ps.RevisedQty;
                tran.UOM            = ps.UOM;
                tran.BAccountID     = task.CustomerID;
                tran.LocationID     = task.LocationID;
                tran.Billable       = true;
                tran.BillableQty    = ps.RevisedQty;
                tran.Date           = FinPeriodIDAttribute.PeriodEndDate(this, ps.PeriodID);
                tran.StartDate      = tran.Date;
                tran.EndDate        = tran.Date;
                tran.FinPeriodID    = ps.PeriodID;
                tran.TranPeriodID   = ps.PeriodID;

                trans.Add(tran);
            }
        }
Esempio n. 30
0
        protected virtual void PMTask_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            PMTask row = e.Row as PMTask;

            if (row == null)
            {
                return;
            }

            if (row.IsActive == true && row.IsCancelled == false)
            {
                throw new PXException(Messages.OnlyPlannedCanbeDeleted);
            }

            //validate that all child records can be deleted:

            PMTran tran = PXSelect <PMTran, Where <PMTran.projectID, Equal <Required <PMTask.projectID> >, And <PMTran.taskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (tran != null)
            {
                throw new PXException(Messages.HasTranData);
            }

            PMTimeActivity activity = PXSelect <PMTimeActivity, Where <PMTimeActivity.projectID, Equal <Required <PMTask.projectID> >, And <PMTimeActivity.projectTaskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (activity != null)
            {
                throw new PXException(Messages.HasActivityData);
            }

            EP.EPTimeCardItem timeCardItem = PXSelect <EP.EPTimeCardItem, Where <EP.EPTimeCardItem.projectID, Equal <Required <PMTask.projectID> >, And <EP.EPTimeCardItem.taskID, Equal <Required <PMTask.taskID> > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.TaskID);

            if (timeCardItem != null)
            {
                throw new PXException(Messages.HasTimeCardItemData);
            }
        }
Esempio n. 31
0
        public static void ReverseAllocatedTran(PMTran tran)
        {
            RegisterEntry pmEntry = PXGraph.CreateInstance <RegisterEntry>();

            pmEntry.FieldVerifying.AddHandler <PMTran.projectID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.taskID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });
            pmEntry.FieldVerifying.AddHandler <PMTran.inventoryID>((PXCache sender, PXFieldVerifyingEventArgs e) => { e.Cancel = true; });

            PMRegister origDoc = PXSelectReadonly <PMRegister, Where <PMRegister.refNbr, Equal <Required <PMRegister.refNbr> > > > .Select(pmEntry, tran.RefNbr);

            PMRegister reversalDoc = (PMRegister)pmEntry.Document.Cache.Insert();

            reversalDoc.OrigDocType  = PMOrigDocType.Reversal;
            reversalDoc.OrigNoteID   = origDoc.NoteID;
            reversalDoc.Description  = PXMessages.LocalizeNoPrefix(Messages.AllocationReversal);
            pmEntry.Document.Current = reversalDoc;

            PMBillEngine engine = PXGraph.CreateInstance <PMBillEngine>();

            foreach (PMTran reverse in engine.ReverseTran(tran))
            {
                pmEntry.Transactions.Insert(reverse);
            }
            tran.ExcludedFromBilling       = true;
            tran.ExcludedFromBillingReason = PXMessages.LocalizeNoPrefix(Messages.ExcludedFromBillingAsReversed);
            PM.RegisterReleaseProcess.SubtractFromUnbilledSummary(pmEntry, tran);
            pmEntry.Transactions.Update(tran);

            pmEntry.Save.Press();

            PMSetup setup = PXSelect <PMSetup> .Select(pmEntry);

            if (setup.AutoReleaseAllocation == true)
            {
                RegisterRelease.Release(reversalDoc);
            }
        }
 public TranNotePair(PMTran tran, Note note)
 {
     this.Tran = tran;
     this.Note = note;
 }
Esempio n. 33
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);
        }