public virtual void ActivateTask(PMTask task) { if (task.StartDate == null) { task.StartDate = Accessinfo.BusinessDate; } }
protected virtual bool IsTaskFit(int?rateDefinitionID, int?projectID, int?taskID) { PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(graph, projectID, taskID); if (task == null) { throw new PXException(Messages.TaskNotFound, projectID, taskID); } string cd = task.TaskCD; PXSelectBase <PMTaskRate> select = new PXSelect <PMTaskRate, Where <PMTaskRate.rateDefinitionID, Equal <Required <PMTaskRate.rateDefinitionID> > > >(graph); foreach (PMTaskRate item in select.Select(rateDefinitionID)) { if (IsFit(item.TaskCD.Trim(), cd.Trim())) { trace.AppendFormat(" Checking Task {0}..Match found.", cd.Trim()); return(true); } } trace.AppendFormat(" Checking Task {0}..Match not found.", cd.Trim()); return(false); }
public string GetValidationWarning(int costCodeID) { PMTask task = SelectFrom <PMTask> .Where <PMTask.taskID.IsEqual <@P.AsInt> > .View .Select(_Graph, GetTaskID()); int?accountGroupID = GetAccountGroupID(); if (accountGroupID == null) { Account account = SelectFrom <Account> .Where <Account.accountID.IsEqual <@P.AsInt> > .View .Select(_Graph, GetAccountID()); if (account != null) { accountGroupID = account.AccountGroupID; } } PMAccountGroup accountGroup = SelectFrom <PMAccountGroup> .Where <PMAccountGroup.groupID.IsEqual <@P.AsInt> > .View .Select(_Graph, accountGroupID); PMCostCode costCode = SelectFrom <PMCostCode> .Where <PMCostCode.costCodeID.IsEqual <@P.AsInt> > .View .Select(_Graph, costCodeID); return(string.Format(Messages.CostCodeNotInBudget, costCode.CostCodeCD, task.TaskCD, accountGroup?.GroupCD)); }
protected virtual void PMTask_CompletedPct_FieldSelecting(PXCache sender, PXFieldSelectingEventArgs e) { PMTask row = e.Row as PMTask; if (row != null) { PXSelectBase <PMProjectStatus> select = new PXSelectGroupBy <PMProjectStatus, Where <PMProjectStatus.projectID, Equal <Required <PMTask.projectID> >, And <PMProjectStatus.projectTaskID, Equal <Required <PMTask.taskID> >, And <PMProjectStatus.isProduction, Equal <True> > > >, Aggregate <GroupBy <PMProjectStatus.accountGroupID, GroupBy <PMProjectStatus.projectID, GroupBy <PMProjectStatus.projectTaskID, GroupBy <PMProjectStatus.inventoryID, Sum <PMProjectStatus.amount, Sum <PMProjectStatus.qty, Sum <PMProjectStatus.revisedAmount, Sum <PMProjectStatus.revisedQty, Sum <PMProjectStatus.actualAmount, Sum <PMProjectStatus.actualQty> > > > > > > > > > > >(this); PMProjectStatus ps = select.Select(row.ProjectID, row.TaskID); if (ps != null) { if (ps.RevisedQty > 0) { e.ReturnValue = Convert.ToInt32(100 * ps.ActualQty / ps.RevisedQty); e.ReturnState = PXFieldState.CreateInstance(e.ReturnValue, typeof(decimal?), false, false, 0, 0, 0, 0, "CompletedPct", null, null, null, PXErrorLevel.Undefined, false, true, true, PXUIVisibility.Visible, null, null, null); } } } }
protected virtual bool IsTaskFit(int?rateDefinitionID, int?projectID, int?taskID, out List <string> rateCodes) { rateCodes = new List <string>(); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(graph, projectID, taskID); if (task == null) { throw new PXException(Messages.TaskNotFound, projectID, taskID); } string cd = task.TaskCD; PXSelectBase <PMTaskRate> select = new PXSelect <PMTaskRate, Where <PMTaskRate.rateDefinitionID, Equal <Required <PMTaskRate.rateDefinitionID> > > >(graph); bool result = false; foreach (PMTaskRate item in select.Select(rateDefinitionID)) { if (IsFit(item.TaskCD.Trim(), cd.Trim())) { rateCodes.Add(item.RateCodeID); trace.AppendFormat(" Checking Task {0}..Match found.", cd.Trim()); result = true; } } if (!result) { trace.AppendFormat(" Checking Task {0}..Match not found.", cd.Trim()); } return(result); }
protected virtual void _(Events.FieldDefaulting <PMTimeActivity, PMTimeActivity.projectTaskID> e) { if (e.Row == null) { return; } if (e.Row.ParentTaskNoteID != null) { EPActivityApprove rowParentTask = PXSelect <EPActivityApprove> .Search <EPActivityApprove.noteID>(this, e.Row.ParentTaskNoteID); if (rowParentTask != null && rowParentTask.ProjectID == e.Row.ProjectID) { e.NewValue = rowParentTask.ProjectTaskID; e.Cancel = true; } } EPEarningType earningRow = (EPEarningType)PXSelectorAttribute.Select <EPActivityApprove.earningTypeID>(e.Cache, e.Row); if (e.NewValue == null && earningRow != null && earningRow.ProjectID == e.Row.ProjectID) { PMTask defTask = PXSelectorAttribute.Select(e.Cache, e.Row, e.Cache.GetField(typeof(EPTimeCardSummary.projectTaskID)), earningRow.TaskID) as PMTask; if (defTask != null && defTask.VisibleInTA == true) { e.NewValue = earningRow.TaskID; e.Cancel = true; } } }
protected virtual void PMTask_ProjectID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e) { PMTask row = e.Row as PMTask; if (row != null) { sender.SetDefaultExt <PMTask.customerID>(e.Row); } }
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); }
public TranInfo(PXResult <PMTran, Account, PMProject, PMTask, OffsetAccount, PMAccountGroup, OffsetPMAccountGroup> res) { this.Tran = (PMTran)res; this.Account = (Account)res; this.AccountGroup = (PMAccountGroup)res; this.OffsetAccount = (OffsetAccount)res; this.OffsetAccountGroup = (OffsetPMAccountGroup)res; this.Project = (PMProject)res; this.Task = (PMTask)res; }
protected virtual void PMTask_RowInserted(PXCache sender, PXRowInsertedEventArgs e) { PMTask row = e.Row as PMTask; PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Current <PMTask.projectID> > > > .Select(this); if (row != null && project != null) { row.BillingID = project.BillingID; row.DefaultAccountID = project.DefaultAccountID; row.DefaultSubID = project.DefaultSubID; } }
public virtual List <BillingData> BillTask(PMTask task, DateTime billingDate) { List <BillingData> list = new List <BillingData>(); PXSelectBase <PMBillingRule> billingRuleSelect = new PXSelect <PMBillingRule, Where <PMBillingRule.billingID, Equal <Required <PMBillingRule.billingID> > > >(this); foreach (PMBillingRule rule in billingRuleSelect.Select(task.BillingID)) { list.AddRange(BillTask(task, rule, billingDate)); } return(list); }
public virtual List <PMTran> ReverseWipTask(PMTask task, DateTime billingDate) { List <PMTran> list = new List <PMTran>(); PXSelectBase <PMBillingRule> billingRuleSelect = new PXSelect <PMBillingRule, Where <PMBillingRule.billingID, Equal <Required <PMBillingRule.billingID> >, And <PMBillingRule.wipAccountGroupID, IsNotNull> > >(this); foreach (PMBillingRule rule in billingRuleSelect.Select(task.BillingID)) { list.AddRange(ReverseWipTask(task, rule, billingDate)); } return(list); }
protected virtual void PMTask_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { PMTask row = e.Row as PMTask; if (row != null) { PMProject prj = PXSelect <PMProject, Where <PMProject.contractID, Equal <Current <PMTask.projectID> > > > .SelectSingleBound(this, new object[] { row }); PXUIFieldAttribute.SetEnabled <PMTask.autoIncludeInPrj>(sender, row, prj != null && prj.NonProject != true); //PXUIFieldAttribute.SetVisible<PMTask.projectID>(sender, row, prj != null && prj.NonProject != true); } }
protected virtual void PMTask_CustomerID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { PMTask row = e.Row as PMTask; if (row == null) { return; } PMProject prj = PXSelect <PMProject, Where <PMProject.contractID, Equal <Current <PMTask.projectID> > > > .SelectSingleBound(this, new object[] { row }); if (prj != null && prj.NonProject == true) { e.Cancel = true; } }
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 PMTask_IsActive_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { PMTask row = e.Row as PMTask; if (row != null && e.NewValue != null && ((bool)e.NewValue) == true) { PMProject project = Project.Select(); if (project != null) { if (project.IsActive == false) { e.NewValue = false; sender.RaiseExceptionHandling <PMTask.status>(e.Row, e.NewValue, new PXSetPropertyException(Warnings.ProjectIsNotActive, PXErrorLevel.Warning)); } } } }
protected virtual void PMTask_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) { PMTask row = e.Row as PMTask; PMTask oldRow = e.OldRow as PMTask; if (row == null || oldRow == null) { return; } if (row.IsActive == true && oldRow.IsActive != true) { ActivateTask(row); } if (row.IsCompleted == true && oldRow.IsCompleted != true) { CompleteTask(row); } }
protected virtual List <PMTran> ReverseWipTask(PMTask task, PMBillingRule rule, DateTime billingDate) { List <PMTran> list = new List <PMTran>(); //usage: PXSelectBase <PMTran> select = new PXSelect <PMTran, Where <PMTran.projectID, Equal <Required <PMTran.projectID> >, And <PMTran.taskID, Equal <Required <PMTran.taskID> >, And <PMTran.accountGroupID, Equal <Required <PMTran.accountGroupID> >, And <PMTran.date, Less <Required <PMTran.date> >, And <PMTran.billed, Equal <False>, And <PMTran.released, Equal <True>, And <PMTran.reversed, Equal <False> > > > > > > > >(this); DateTime cuttofDate = billingDate; //all transactions excluding the current day. ContractBillingSchedule schedule = PXSelect <ContractBillingSchedule> .Search <ContractBillingSchedule.contractID>(this, task.ProjectID); if (schedule != null && schedule.Type == BillingType.OnDemand) { cuttofDate = billingDate.AddDays(1); //all transactions including the current day. } else { if (IncludeTodaysTransactions) { cuttofDate = billingDate.AddDays(1); } } foreach (PMTran tran in select.Select(task.ProjectID, task.TaskID, rule.WipAccountGroupID, cuttofDate)) { list.AddRange(ReverseTran(tran)); tran.Billed = true; tran.BilledDate = billingDate; Transactions.Update(tran); } return(list); }
public static void Run(PMAllocator graph, PMTask item, DateTime?date, DateTime?fromDate, DateTime?toDate) { graph.Clear(); graph.FilterStartDate = fromDate; graph.FilterEndDate = toDate; graph.Execute(item); if (graph.Document.Current != null) { graph.Actions.PressSave(); PMSetup setup = PXSelect <PMSetup> .Select(graph); PMRegister doc = graph.Caches[typeof(PMRegister)].Current as PMRegister; if (doc != null && setup.AutoReleaseAllocation == true) { RegisterRelease.Release(doc); } } else { throw new PXSetPropertyException(Warnings.NothingToAllocate, PXErrorLevel.RowWarning); } }
protected virtual void PMTask_RowSelected(PXCache sender, PXRowSelectedEventArgs e) { PMTask row = e.Row as PMTask; if (row != null) { viewTransactions.SetEnabled(row.IsActive == true || row.IsCompleted == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInGL>(sender, e.Row, Setup.Current.VisibleInGL == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInAP>(sender, e.Row, Setup.Current.VisibleInAP == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInAR>(sender, e.Row, Setup.Current.VisibleInAR == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInSO>(sender, e.Row, Setup.Current.VisibleInSO == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInPO>(sender, e.Row, Setup.Current.VisibleInPO == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInEP>(sender, e.Row, Setup.Current.VisibleInEP == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInIN>(sender, e.Row, Setup.Current.VisibleInIN == true); PXUIFieldAttribute.SetEnabled <PMTask.visibleInCA>(sender, e.Row, Setup.Current.VisibleInCA == true); ProjectStatus.Cache.AllowInsert = row.IsCompleted == false && sender.GetStatus(e.Row) != PXEntryStatus.Inserted; ProjectStatus.Cache.AllowDelete = row.IsCompleted == false; ProjectStatus.Cache.AllowUpdate = row.IsCompleted == false; } }
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); } }
protected virtual void _(Events.FieldVerifying <PMTimeActivity, PMTimeActivity.projectTaskID> e) { if (e.NewValue != null && e.NewValue is int) { PMTask task = PXSelect <PMTask> .Search <PMTask.taskID>(this, e.NewValue); if (task != null) { if (task.IsCompleted == true) { var ex = new PXSetPropertyException(PM.Messages.ProjectTaskIsCompleted); ex.ErrorValue = task.TaskCD; throw ex; } if (task.IsCancelled == true) { var ex = new PXSetPropertyException(PM.Messages.ProjectTaskIsCanceled); ex.ErrorValue = task.TaskCD; throw ex; } } } }
protected virtual void _(Events.FieldDefaulting <PMBudget, PMBudget.rate> e) { PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, e.Row.AccountGroupID); if (ag != null) { if (ag.IsExpense == true) { if (e.Row.InventoryID != null && e.Row.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID) { InventoryItem item = (InventoryItem)PXSelectorAttribute.Select <PMCostBudget.inventoryID>(e.Cache, e.Row); e.NewValue = item?.StdCost; } } else { if (e.Row.InventoryID != null && e.Row.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID) { string customerPriceClass = ARPriceClass.EmptyPriceClass; PMTask projectTask = (PMTask)PXSelectorAttribute.Select <PMRevenueBudget.projectTaskID>(e.Cache, e.Row); CR.Location c = (CR.Location)PXSelectorAttribute.Select <PMTask.locationID>(e.Cache, projectTask); if (c != null && !string.IsNullOrEmpty(c.CPriceClassID)) { customerPriceClass = c.CPriceClassID; } CM.CurrencyInfo dummy = new CM.CurrencyInfo(); dummy.CuryID = Accessinfo.BaseCuryID; dummy.BaseCuryID = Accessinfo.BaseCuryID; dummy.CuryRate = 1; e.NewValue = ARSalesPriceMaint.CalculateSalesPrice(Caches[typeof(PMTran)], customerPriceClass, projectTask.CustomerID, e.Row.InventoryID, dummy, e.Row.Qty, e.Row.UOM, Accessinfo.BusinessDate.Value, true); } } } }
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); } EPActivity activity = PXSelect <EPActivity, Where <EPActivity.projectID, Equal <Required <PMTask.projectID> >, And <EPActivity.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); } }
protected virtual List <BillingData> BillTask(PMTask task, PMBillingRule rule, DateTime billingDate) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, task.ProjectID); Customer customer = PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > > .Select(this, project.CustomerID); List <BillingData> list = new List <BillingData>(); Dictionary <int, decimal> availableQty = new Dictionary <int, decimal>(); Dictionary <int, ContractDetail> billingItems = new Dictionary <int, ContractDetail>(); //recurent Billing: PXSelectBase <ContractDetail> selectBilling = new PXSelect <ContractDetail, Where <ContractDetail.contractID, Equal <Required <ContractDetail.contractID> >, And <ContractDetail.taskID, Equal <Required <ContractDetail.taskID> > > > >(this); foreach (ContractDetail billing in selectBilling.Select(task.ProjectID, task.TaskID)) { billingItems.Add(billing.InventoryID.Value, billing); if (billing.Included > 0) { if (billing.ResetUsage == ResetUsageOption.OnBilling) { availableQty.Add(billing.InventoryID.Value, billing.Included.Value); } else { decimal qtyLeft = billing.Included.Value - billing.LastBilledQty ?? 0; if (qtyLeft > 0) { availableQty.Add(billing.InventoryID.Value, qtyLeft); } } } bool bill = false; if (billing.ResetUsage == ResetUsageOption.OnBilling) { bill = true; } else { if (billing.LastBilledDate == null) { bill = true; } } if (bill) { ARTran arTran = new ARTran(); arTran.InventoryID = billing.InventoryID; arTran.TranDesc = billing.Description; arTran.Qty = billing.Included; arTran.UOM = billing.UOM; arTran.ExtPrice = billing.ItemFee; arTran.TranAmt = arTran.ExtPrice; arTran.ProjectID = task.ProjectID; arTran.TaskID = task.TaskID; arTran.Commissionable = false; //todo string subCD = null; #region Set Account and Subaccount if (billing.AccountSource != PMAccountSource.None) { if (rule.AccountSource == PMAccountSource.RecurringBillingItem) { if (billing.AccountID != null) { arTran.AccountID = billing.AccountID; } else { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); throw new PXException(Messages.BillingRuleAccountIsNotConfiguredForBillingRecurent, item.InventoryCD); } } else if (billing.AccountSource == PMAccountSource.Project) { if (project.DefaultAccountID != null) { arTran.AccountID = project.DefaultAccountID; } else { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); throw new PXException(Messages.ProjectAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, project.ContractCD); } } else if (billing.AccountSource == PMAccountSource.Task) { if (task.DefaultAccountID != null) { arTran.AccountID = task.DefaultAccountID; } else { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); throw new PXException(Messages.TaskAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, project.ContractCD, task.TaskCD); } } else if (billing.AccountSource == PMAccountSource.InventoryItem) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); if (item != null) { if (item.SalesAcctID != null) { arTran.AccountID = item.SalesAcctID; } else { throw new PXException(Messages.InventoryAccountIsNotConfiguredForBillingRecurent, item.InventoryCD); } } } else if (billing.AccountSource == PMAccountSource.Customer && customer != null) { CR.Location customerLoc = PXSelect <CR.Location, Where <CR.Location.bAccountID, Equal <Required <CR.Location.bAccountID> >, And <CR.Location.locationID, Equal <Required <CR.Location.locationID> > > > > .Select(this, customer.BAccountID, customer.DefLocationID); if (customerLoc != null) { if (customerLoc.CSalesAcctID != null) { arTran.AccountID = customerLoc.CSalesAcctID; } else { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); throw new PXException(Messages.CustomerAccountIsNotConfiguredForBillingRecurent, item.InventoryCD, customer.AcctCD); } } } if (arTran.AccountID == null && !string.IsNullOrEmpty(billing.SubMask)) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, billing.InventoryID); throw new PXException(Messages.SubAccountCannotBeComposed, item.InventoryCD); } else if (arTran.AccountID != null && !string.IsNullOrEmpty(billing.SubMask)) { subCD = PMRecurentBillSubAccountMaskAttribute.MakeSub <PMBillingRule.subMask>(this, billing.SubMask, new object[] { billing.SubID, project.DefaultSubID, task.DefaultSubID }, new Type[] { typeof(PMBillingRule.subID), typeof(PMProject.defaultSubID), typeof(PMTask.defaultSubID) }); } } #endregion list.Add(new BillingData(arTran, rule, null, subCD, null, null)); billing.LastBilledDate = billingDate; ContractDetail.Update(billing); } } int mult = 1; PMAccountGroup ag = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(this, rule.AccountGroupID); if (ag == null) { throw new PXException(Messages.AccountGroupInBillingRuleNotFound, rule.BillingID, rule.AccountGroupID); } if (ag.Type == GL.AccountType.Liability || ag.Type == GL.AccountType.Income) { mult = -1; } DateTime cuttofDate = billingDate; //all transactions excluding the current day. ContractBillingSchedule schedule = PXSelect <ContractBillingSchedule> .Search <ContractBillingSchedule.contractID>(this, task.ProjectID); if (schedule != null && schedule.Type == BillingType.OnDemand) { cuttofDate = billingDate.AddDays(1); //all transactions including the current day. } else { if (IncludeTodaysTransactions) { cuttofDate = billingDate.AddDays(1); } } List <PMTran> billingBase = SelectBillingBase(task.ProjectID, task.TaskID, rule.AccountGroupID, cuttofDate, rule.IncludeNonBillable == true); foreach (PMTran tran in billingBase) { ARTran arTran = new ARTran(); arTran.BranchID = tran.BranchID; if (tran.InventoryID != PMInventorySelectorAttribute.EmptyInventoryID) { arTran.InventoryID = tran.InventoryID; } arTran.TranDesc = tran.Description; arTran.UOM = tran.UOM; arTran.Qty = tran.BillableQty * mult; arTran.ExtPrice = tran.Amount * mult; if (arTran.Qty != 0) { arTran.UnitPrice = arTran.ExtPrice / arTran.Qty; } else { arTran.UnitPrice = 0; } arTran.TranAmt = arTran.ExtPrice; arTran.ProjectID = task.ProjectID; arTran.TaskID = task.TaskID; arTran.PMTranID = tran.TranID; arTran.Commissionable = false; //todo arTran.Date = tran.Date; string subCD = null; #region Set Account and Subaccount int?employeeSubID = null; if (tran.ResourceID != null) { EP.EPEmployee emp = PXSelect <EP.EPEmployee, Where <EP.EPEmployee.bAccountID, Equal <Required <EP.EPEmployee.bAccountID> > > > .Select(this, tran.ResourceID); if (emp != null) { employeeSubID = emp.SalesSubID; } } if (rule.AccountSource != PMAccountSource.None) { if (rule.AccountSource == PMAccountSource.BillingRule) { if (rule.AccountID != null) { arTran.AccountID = rule.AccountID; } else { throw new PXException(Messages.BillingRuleAccountIsNotConfiguredForBilling, rule.BillingID); } } else if (rule.AccountSource == PMAccountSource.Project) { if (project.DefaultAccountID != null) { arTran.AccountID = project.DefaultAccountID; } else { throw new PXException(Messages.ProjectAccountIsNotConfiguredForBilling, rule.BillingID, project.ContractCD); } } else if (rule.AccountSource == PMAccountSource.Task) { if (task.DefaultAccountID != null) { arTran.AccountID = task.DefaultAccountID; } else { throw new PXException(Messages.TaskAccountIsNotConfiguredForBilling, rule.BillingID, project.ContractCD, task.TaskCD); } } else if (rule.AccountSource == PMAccountSource.InventoryItem) { InventoryItem item = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, tran.InventoryID); if (item != null) { if (item.SalesAcctID != null) { arTran.AccountID = item.SalesAcctID; } else { throw new PXException(Messages.InventoryAccountIsNotConfiguredForBilling, rule.BillingID, item.InventoryCD); } } } else if (rule.AccountSource == PMAccountSource.Customer && customer != null) { CR.Location customerLoc = PXSelect <CR.Location, Where <CR.Location.bAccountID, Equal <Required <CR.Location.bAccountID> >, And <CR.Location.locationID, Equal <Required <CR.Location.locationID> > > > > .Select(this, customer.BAccountID, customer.DefLocationID); if (customerLoc != null) { if (customerLoc.CSalesAcctID != null) { arTran.AccountID = customerLoc.CSalesAcctID; } else { throw new PXException(Messages.CustomerAccountIsNotConfiguredForBilling, rule.BillingID, customer.AcctCD); } } } else if (rule.AccountSource == PMAccountSource.Resource) { EP.EPEmployee emp = PXSelect <EP.EPEmployee, Where <EP.EPEmployee.bAccountID, Equal <Required <EP.EPEmployee.bAccountID> > > > .Select(this, tran.ResourceID); if (emp != null) { if (emp.SalesAcctID != null) { arTran.AccountID = emp.SalesAcctID; } else { throw new PXException(Messages.EmployeeAccountIsNotConfiguredForBilling, rule.BillingID, emp.AcctCD); } } } if (arTran.AccountID == null && !string.IsNullOrEmpty(rule.SubMask)) { throw new PXException(Messages.SubAccountCannotBeComposed, rule.BillingID); } else if (arTran.AccountID != null && !string.IsNullOrEmpty(rule.SubMask)) { subCD = PMBillSubAccountMaskAttribute.MakeSub <PMBillingRule.subMask>(this, rule.SubMask, new object[] { tran.SubID, rule.SubID, project.DefaultSubID, task.DefaultSubID, employeeSubID }, new Type[] { typeof(PMTran.subID), typeof(PMBillingRule.subID), typeof(PMProject.defaultSubID), typeof(PMTask.defaultSubID), typeof(EP.EPEmployee.salesSubID) }); } } #endregion string note = PXNoteAttribute.GetNote(Transactions.Cache, tran); Guid[] files = PXNoteAttribute.GetFileNotes(Transactions.Cache, tran); list.Add(new BillingData(arTran, rule, tran, subCD, note, files)); if (billingItems.ContainsKey(tran.InventoryID.Value)) { if (availableQty.ContainsKey(tran.InventoryID.Value)) { decimal available = availableQty[tran.InventoryID.Value]; if (tran.BillableQty <= available) { //Transaction is already payed for as a post payment included. Thus it should be free. arTran.TranDesc = PXMessages.LocalizeNoPrefix(CT.Messages.PrefixIncludedUsage) + " " + tran.Description; availableQty[tran.InventoryID.Value] -= arTran.Qty.Value; //decrease available qty arTran.UnitPrice = 0; arTran.ExtPrice = 0; arTran.TranAmt = 0; } else { arTran.TranDesc = PXMessages.LocalizeNoPrefix(CT.Messages.PrefixOverused) + " " + tran.Description; arTran.Qty = arTran.Qty - available; availableQty[tran.InventoryID.Value] = 0; //all available qty was used. } } } tran.Billed = true; tran.BilledDate = billingDate; Transactions.Update(tran); } return(list); }
public override string GenerateProformaTag(PMProject project, PMTask task) { return("P"); }
public virtual void RunProjectBalanceVerification(PMProject project) { PXDatabase.Delete <PMTaskTotal>(new PXDataFieldRestrict(typeof(PMTaskTotal.projectID).Name, PXDbType.Int, 4, project.ContractID, PXComp.EQ)); PXDatabase.Delete <PMTaskAllocTotal>(new PXDataFieldRestrict(typeof(PMTaskAllocTotal.projectID).Name, PXDbType.Int, 4, project.ContractID, PXComp.EQ)); PXDatabase.Delete <PMHistory>(new PXDataFieldRestrict(typeof(PMHistory.projectID).Name, PXDbType.Int, 4, project.ContractID, PXComp.EQ)); foreach (PMProjectStatusEx status in PXSelect <PMProjectStatusEx, Where <PMProjectStatusEx.projectID, Equal <Required <PMProjectStatusEx.projectID> > > > .Select(this, project.ContractID)) { PXDatabase.Update <PMProjectStatus>(new PXDataFieldRestrict(typeof(PMProjectStatus.projectID).Name, PXDbType.Int, 4, project.ContractID, PXComp.EQ), new PXDataFieldAssign(typeof(PMProjectStatus.actualAmount).Name, PXDbType.Decimal, 0m), new PXDataFieldAssign(typeof(PMProjectStatus.actualQty).Name, PXDbType.Decimal, 0m)); PMHistory2Accum hist2 = new PMHistory2Accum(); hist2.ProjectID = status.ProjectID; hist2.ProjectTaskID = status.ProjectTaskID; hist2.AccountGroupID = status.AccountGroupID; hist2.InventoryID = status.InventoryID ?? PMProjectStatus.EmptyInventoryID; hist2.PeriodID = status.PeriodID; hist2 = History2.Insert(hist2); hist2.PTDBudgetAmount += status.Amount; hist2.PTDBudgetQty += status.Qty; hist2.BudgetAmount += status.Amount; hist2.BudgetQty += status.Qty; hist2.PTDRevisedAmount += status.RevisedAmount; hist2.PTDRevisedQty += status.RevisedQty; hist2.RevisedAmount += status.RevisedAmount; hist2.RevisedQty += status.RevisedQty; } PXSelectBase <PMTran> select = new PXSelectJoin <PMTran, LeftJoin <Account, On <PMTran.accountID, Equal <Account.accountID> >, InnerJoin <PMProject, On <PMProject.contractID, Equal <PMTran.projectID> >, LeftJoin <PMTask, On <PMTask.projectID, Equal <PMTran.projectID>, And <PMTask.taskID, Equal <PMTran.taskID> > >, LeftJoin <OffsetAccount, On <PMTran.offsetAccountID, Equal <OffsetAccount.accountID> >, LeftJoin <PMAccountGroup, On <PMAccountGroup.groupID, Equal <Account.accountGroupID> >, LeftJoin <OffsetPMAccountGroup, On <OffsetPMAccountGroup.groupID, Equal <OffsetAccount.accountGroupID> > > > > > > >, Where <PMTran.projectID, Equal <Required <PMTran.projectID> >, And <PMTran.released, Equal <True> > > >(this); foreach (PXResult <PMTran, Account, PMProject, PMTask, OffsetAccount, PMAccountGroup, OffsetPMAccountGroup> res in select.Select(project.ContractID)) { PMTran tran = (PMTran)res; Account acc = (Account)res; PMAccountGroup ag = (PMAccountGroup)res; OffsetAccount offsetAcc = (OffsetAccount)res; OffsetPMAccountGroup offsetAg = (OffsetPMAccountGroup)res; PMTask task = (PMTask)res; IList <PMHistory> list = RegisterReleaseProcess.UpdateProjectBalance(this, task, tran, acc, ag, offsetAcc, offsetAg); #region History Update foreach (PMHistory item in list) { 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 = History.Insert(hist); hist.FinPTDAmount += item.FinPTDAmount.GetValueOrDefault(); hist.FinYTDAmount += item.FinYTDAmount.GetValueOrDefault(); hist.FinPTDQty += item.FinPTDQty.GetValueOrDefault(); hist.FinYTDQty += item.FinYTDQty.GetValueOrDefault(); hist.TranPTDAmount += item.TranPTDAmount.GetValueOrDefault(); hist.TranYTDAmount += item.TranYTDAmount.GetValueOrDefault(); hist.TranPTDQty += item.TranPTDQty.GetValueOrDefault(); hist.TranYTDQty += item.TranYTDQty.GetValueOrDefault(); } #endregion } PXSelectBase <PMTran> select2 = new PXSelect <PMTran, Where <PMTran.origProjectID, Equal <Required <PMTran.origProjectID> >, And <PMTran.origTaskID, IsNotNull, And <PMTran.origAccountGroupID, IsNotNull> > > >(this); foreach (PMTran tran in select2.Select(project.ContractID)) { PMTaskAllocTotalAccum tat = new PMTaskAllocTotalAccum(); tat.ProjectID = tran.OrigProjectID; tat.TaskID = tran.OrigTaskID; tat.AccountGroupID = tran.OrigAccountGroupID; tat.InventoryID = tran.InventoryID; tat = AllocationTotals.Insert(tat); tat.Amount += tran.Amount; tat.Quantity += tran.Qty; } foreach (PMProjectStatusAccum item in this.Caches[typeof(PMProjectStatusAccum)].Inserted) { Debug.Print("Task={0} AG={1} Qty={2} Amt={3}", item.ProjectTaskID, item.AccountGroupID, item.ActualQty, item.ActualAmount); } }
public virtual void CompleteTask(PMTask task) { task.EndDate = Accessinfo.BusinessDate; task.CompletedPct = Math.Max(100, task.CompletedPct.GetValueOrDefault()); }
public static IList <PMHistory> UpdateProjectBalance(PXGraph graph, PMTask task, PMTran tran, Account acc, PMAccountGroup ag, Account offsetAcc, PMAccountGroup offsetAg) { List <PMHistory> list = new List <PMHistory>(); if (tran.TaskID != null) { int invert = 1; if (tran.TranType == BatchModule.PM && acc.Type != ag.Type) { //Invert transactions that originated in PM. All other transactions were already inverted when they were transformed from GLTran to PMTran. invert = -1; } if (string.IsNullOrEmpty(ag.Type)) { //offbalance tran. PMAccountGroup tranAG = PXSelect <PMAccountGroup, Where <PMAccountGroup.groupID, Equal <Required <PMAccountGroup.groupID> > > > .Select(graph, tran.AccountGroupID); if (tranAG != null) { //DEBIT ONLY if (tranAG.Type == AccountType.Income || tranAG.Type == AccountType.Liability) { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, tranAG, null, -1 * invert)); } else { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, tranAG, null, 1 * invert)); } } } else { //DEBIT if (acc.Type == AccountType.Income || acc.Type == AccountType.Liability) { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, ag, acc, -1 * invert)); } else { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, ag, acc, 1 * invert)); } } //CREDIT if (offsetAcc != null && offsetAg != null && offsetAcc.AccountID != null && offsetAg.GroupID != null && acc.AccountID != offsetAcc.AccountID) { int offsetInvert = 1; if (offsetAcc.Type != offsetAg.Type) { offsetInvert = -1; } if (offsetAcc.Type == AccountType.Income || offsetAcc.Type == AccountType.Liability) { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, offsetAg, offsetAcc, 1 * offsetInvert)); } else { list.AddRange(RegisterReleaseProcess.UpdateProjectBalance(graph, tran, offsetAg, offsetAcc, -1 * offsetInvert)); } } } return(list); }
public virtual IEnumerable projectStatus() { if (Task.Current == null) { yield break; } Dictionary <string, PMProjectStatusEx> cachedItems = new Dictionary <string, PMProjectStatusEx>(); bool isDirty = false; int cxMax = 0; foreach (PMProjectStatusEx item in ProjectStatus.Cache.Cached) { cxMax = Math.Max(cxMax, item.LineNbr.Value); string key = string.Format("{0}.{1}.{2}.{3}", item.AccountGroupID, item.ProjectID, item.ProjectTaskID, item.InventoryID.GetValueOrDefault()); if (!cachedItems.ContainsKey(key)) { cachedItems.Add(key, item); } if (ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Inserted || ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Updated || ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Notchanged || ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Held) { if (ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Inserted || ProjectStatus.Cache.GetStatus(item) == PXEntryStatus.Updated) { isDirty = true; } yield return(item); } } PXSelectBase <PMProjectStatus> select = new PXSelectJoinGroupBy <PMProjectStatus, InnerJoin <PMTask, On <PMTask.projectID, Equal <PMProjectStatus.projectID>, And <PMTask.taskID, Equal <PMProjectStatus.projectTaskID> > >, InnerJoin <PMAccountGroup, On <PMProjectStatus.accountGroupID, Equal <PMAccountGroup.groupID> > > >, Where <PMProjectStatus.projectID, Equal <Current <PMTask.projectID> >, And <PMProjectStatus.projectTaskID, Equal <Current <PMTask.taskID> > > >, Aggregate <GroupBy <PMProjectStatus.accountGroupID, GroupBy <PMProjectStatus.projectID, GroupBy <PMProjectStatus.projectTaskID, GroupBy <PMProjectStatus.inventoryID, Sum <PMProjectStatus.amount, Sum <PMProjectStatus.qty, Sum <PMProjectStatus.revisedAmount, Sum <PMProjectStatus.revisedQty, Sum <PMProjectStatus.actualAmount, Sum <PMProjectStatus.actualQty> > > > > > > > > > >, OrderBy <Asc <PMAccountGroup.sortOrder> > >(this); int cx = cxMax + 1; foreach (PXResult <PMProjectStatus, PMTask, PMAccountGroup> res in select.Select()) { PMProjectStatus row = (PMProjectStatus)res; PMTask task = (PMTask)res; PMAccountGroup ag = (PMAccountGroup)res; string key = string.Format("{0}.{1}.{2}.{3}", row.AccountGroupID, row.ProjectID, row.ProjectTaskID, row.InventoryID.GetValueOrDefault()); if (!cachedItems.ContainsKey(key)) { PMProjectStatusEx item = new PMProjectStatusEx(); item.LineNbr = cx++; item = (PMProjectStatusEx)ProjectStatus.Cache.Insert(item); item.ProjectID = row.ProjectID; item.ProjectTaskID = row.ProjectTaskID; item.AccountGroupID = row.AccountGroupID; item.InventoryID = row.InventoryID; item.Description = row.Description; item.UOM = row.UOM; item.Rate = row.Rate; item.Qty = row.Qty; item.Amount = row.Amount; item.RevisedQty = row.RevisedQty; item.RevisedAmount = row.RevisedAmount; item.ActualQty = row.ActualQty; item.ActualAmount = row.ActualAmount; PMProjectStatus rowDetail = (PMProjectStatus)PXSelect < PMProjectStatus , Where < PMProjectStatus.isProduction, Equal <True> , And <PMProjectStatus.projectID, Equal <Required <PMProjectStatus.projectID> > , And <PMProjectStatus.projectTaskID, Equal <Required <PMProjectStatus.projectTaskID> > , And <PMProjectStatus.inventoryID, Equal <Required <PMProjectStatus.inventoryID> > , And <PMProjectStatus.accountGroupID, Equal <Required <PMProjectStatus.accountGroupID> > > > > > > > .Select(this, row.ProjectID, row.ProjectTaskID, row.InventoryID, row.AccountGroupID); if (rowDetail != null) { item.IsProduction = true; } item.TaskStatus = task.Status; item.Type = ag.Type; switch (ag.Type) { case AccountType.Asset: item.SortOrder = 1; break; case AccountType.Liability: item.SortOrder = 2; break; case AccountType.Income: item.SortOrder = 3; break; case AccountType.Expense: item.SortOrder = 4; break; } ProjectStatus.Cache.SetStatus(item, PXEntryStatus.Held); yield return(item); } } ProjectStatus.Cache.IsDirty = isDirty; }