public virtual IEnumerable AddNewProjectTask(PXAdapter adapter) { var campaign = CampaignCurrent.Current; if (campaign != null && campaign.ProjectID.HasValue) { var graph = PXGraph.CreateInstance <ProjectTaskEntry>(); graph.Clear(); var task = new PMTask(); graph.Task.Cache.SetValue <PMTask.projectID>(task, campaign.ProjectID); object taskID = campaign.CampaignID; graph.Task.Cache.RaiseFieldUpdating <PMTask.taskCD>(task, ref taskID); graph.Task.Cache.SetValue <PMTask.taskCD>(task, taskID); task = (PMTask)graph.Task.Cache.CreateCopy(graph.Task.Insert(task)); graph.Task.Cache.SetValue <PMTask.description>(task, campaign.CampaignName); graph.Task.Cache.SetValue <PMTask.plannedStartDate>(task, campaign.StartDate); graph.Task.Cache.SetValue <PMTask.startDate>(task, campaign.StartDate); graph.Task.Cache.SetValue <PMTask.plannedEndDate>(task, campaign.EndDate); graph.Task.Cache.SetValue <PMTask.endDate>(task, campaign.EndDate); graph.Task.Update(task); PXRedirectHelper.TryRedirect(graph, task, PXRedirectHelper.WindowMode.NewWindow); } return(adapter.Get()); }
public virtual void ValidateProjectAndProjectTask(EPExpenseClaimDetails info) { if (info != null) { string errProjectMsg = PXUIFieldAttribute.GetError <EPExpenseClaimDetails.contractID>(ClaimDetails.Cache, info); if (!string.IsNullOrEmpty(errProjectMsg) && errProjectMsg.Equals(PXLocalizer.Localize(PM.Messages.ProjectExpired))) { PXUIFieldAttribute.SetError <EPExpenseClaimDetails.contractID>(ClaimDetails.Cache, info, null); } if (info.ContractID != null) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <EPExpenseClaimDetails.contractID> > > > .SelectWindowed(this, 0, 1, info.ContractID); if (project != null && project.ExpireDate != null && info.ExpenseDate != null) { if (info.ExpenseDate > project.ExpireDate) { ClaimDetails.Cache.RaiseExceptionHandling <EPExpenseClaimDetails.contractID>( info, info.ContractID, new PXSetPropertyException( PM.Messages.ProjectExpired, PXErrorLevel.Warning)); } } } string errProjTaskMsg = PXUIFieldAttribute.GetError <EPExpenseClaimDetails.taskID>(ClaimDetails.Cache, info); if (!string.IsNullOrEmpty(errProjTaskMsg) && (errProjTaskMsg.Equals(PXLocalizer.Localize(PM.Messages.ProjectTaskExpired)) || errProjTaskMsg.Equals(PXLocalizer.Localize(PM.Messages.TaskIsCompleted)))) { PXUIFieldAttribute.SetError <EPExpenseClaimDetails.taskID>(ClaimDetails.Cache, info, null); } if (info.TaskID != null) { PMTask projectTask = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <EPExpenseClaimDetails.taskID> > > > .SelectWindowed(this, 0, 1, info.TaskID); if (projectTask != null && projectTask.EndDate != null && info.ExpenseDate != null) { if (info.ExpenseDate > projectTask.EndDate && projectTask.Status != ProjectTaskStatus.Completed) { ClaimDetails.Cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>( info, info.TaskID, new PXSetPropertyException( PM.Messages.ProjectTaskExpired, PXErrorLevel.Warning)); } else if (projectTask.Status == ProjectTaskStatus.Completed) { ClaimDetails.Cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>( info, info.TaskID, new PXSetPropertyException( PM.Messages.TaskIsCompleted, PXErrorLevel.Warning)); } } } } }
protected virtual void PMTimeActivity_ProjectTaskID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e) { PMTimeActivity row = (PMTimeActivity)e.Row; if (row == null) { return; } if (e.NewValue != null && e.NewValue is int) { PMTask task = PXSelect <PMTask> .Search <PMTask.taskID>(sender.Graph, 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 INTran_TaskID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { INTran row = e.Row as INTran; if (row == null) { return; } if (PM.ProjectAttribute.IsPMVisible(this, BatchModule.IN)) { if (row.LocationID != null) { PXResultset <INLocation> result = PXSelectJoin <INLocation, LeftJoin <PMTask, On <PMTask.projectID, Equal <INLocation.projectID>, And <PMTask.taskID, Equal <INLocation.taskID> > > >, Where <INLocation.siteID, Equal <Required <INLocation.siteID> >, And <INLocation.locationID, Equal <Required <INLocation.locationID> > > > > .Select(sender.Graph, row.SiteID, row.LocationID); foreach (PXResult <INLocation, PMTask> res in result) { PMTask task = (PMTask)res; if (task != null && task.TaskCD != null && task.VisibleInIN == true && task.IsActive == true) { e.NewValue = task.TaskCD; return; } } } } }
public static TGTimecardTask MapFromToggl(PXGraph graph, TogglMap record) { PXGraph _graph = graph; int? _projectID = null; int? _taskID = null; PMProject project = PXSelectReadonly <PMProject, Where <PMProject.contractCD, Equal <Required <PMProject.contractCD> > > > .Select(_graph, record.ProjectName); if (project == null) { project = PXSelectReadonly <PMProject, Where <PMProject.nonProject, Equal <True> > > .Select(_graph); } _projectID = project.ContractID; //Tasks are always related to a project PMTask task = PXSelectReadonly <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskCD, Equal <Required <PMTask.taskCD> > > > > .Select(_graph, new object[] { _projectID, record.TaskName }); if (task != null) { _taskID = task.TaskID; } return(new TGTimecardTask() { Selected = false, Date = record.Date, ProjectName = record.ProjectName, ProjectID = _projectID, TaskName = record.TaskName, ProjectTaskID = _taskID, Description = record.Description, Duration = (record.Duration / 60) }); }
protected virtual void EPExpenseClaimDetails_SalesSubID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e) { if (location.Current != null && ((EPExpenseClaimDetails)e.Row).SalesAccountID != null) { InventoryItem item = (InventoryItem)PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, ((EPExpenseClaimDetails)e.Row).InventoryID); Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <EPExpenseClaim.branchID> > > > .Select(this); Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(this, ((EPExpenseClaimDetails)e.Row).ContractID); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(this, ((EPExpenseClaimDetails)e.Row).ContractID, ((EPExpenseClaimDetails)e.Row).TaskID); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(sender, e.Row); int?employee_SubID = (int?)Caches[typeof(EPEmployee)].GetValue <EPEmployee.salesSubID>(EPEmployee.Current); int?item_SubID = (int?)Caches[typeof(InventoryItem)].GetValue <InventoryItem.salesSubID>(item); int?company_SubID = (int?)Caches[typeof(Location)].GetValue <Location.cMPSalesSubID>(companyloc); int?project_SubID = (int?)Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)Caches[typeof(Location)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); object value = SubAccountSalesMaskAttribute.MakeSub <EPSetup.salesSubMask>(this, EPSETUP.SalesSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.salesSubID), typeof(InventoryItem.salesSubID), typeof(Location.cMPSalesSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); sender.RaiseFieldUpdating <EPExpenseClaimDetails.salesSubID>(e.Row, ref value); e.NewValue = (int?)value; e.Cancel = true; } }
private PMQuoteTask InsertQuoteTask(PMQuote quote, PMTask task) { var quoteTask = CreateQuoteTask(quote, task); quoteTask = Base.Tasks.Insert(quoteTask); quoteTask.Type = task.Type; return(quoteTask); }
public void ValidateProjectTask(PMTask projectTask) { if (projectTask.Status.IsIn(ProjectTaskStatus.Planned, ProjectTaskStatus.Canceled) && (IsTaskUsedInCostDocument(projectTask.TaskID) || IsTaskUsedInRevenueDocument(projectTask.TaskID))) { throw new Exception(ProjectAccountingMessages.TaskCannotBeDeleted); } }
/// <summary> /// Inserts in the Smartsheet project Subtasks defined in the Project Template Task from Acumatica /// </summary> /// <param name="projectEntryGraph"></param> /// <param name="smartsheetClient"></param> /// <param name="sheet"></param> /// <param name="ssRowSet"></param> /// <param name="smartSheetHelperObject"></param> /// <param name="columnMap"></param> /// <param name="ssTaskIDPosition"></param> public void InsertAcumaticaSubTasks(ProjectEntry projectEntryGraph, SmartsheetClient smartsheetClient, Sheet sheet, IList <Row> ssRowSet, SmartsheetHelper smartSheetHelperObject, Dictionary <string, long> columnMap, int ssTaskIDPosition, PXResultset <PMSSMapping> templateMappingSet) { if (projectEntryGraph.Project.Current != null && projectEntryGraph.Project.Current.TemplateID != null) { PXResultset <PMTask> templateTasksSet = PXSelect < PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> > > > .Select(projectEntryGraph, projectEntryGraph.Project.Current.TemplateID); foreach (PMTask templateTask in templateTasksSet) { PMTask actualTask = PXSelect < PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskCD, Equal <Required <PMTask.taskCD> > > > > .Select(projectEntryGraph, projectEntryGraph.Project.Current.ContractID, templateTask.TaskCD.Trim()); if (actualTask == null) { continue; } PMTaskSSExt pmTemplateTaskSSExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(templateTask); PXResultset <PMSubTask> templateSubTasksSet = PXSelect < PMSubTask, Where <PMSubTask.projectID, Equal <Required <PMSubTask.projectID> >, And <PMSubTask.taskID, Equal <Required <PMSubTask.taskID> > > >, OrderBy < Asc <PMSubTask.position> > > .Select(projectEntryGraph, templateTask.ProjectID, templateTask.TaskID); int dependencyStartDateOffset = 0; long dependencySibling = 0; foreach (Row ssRow in ssRowSet) { if (ssRow.Cells[ssTaskIDPosition].Value != null && string.Equals(ssRow.Cells[ssTaskIDPosition].Value.ToString().Trim(), templateTask.TaskCD.Trim(), StringComparison.OrdinalIgnoreCase)) { foreach (PMSubTask subTaskRow in templateSubTasksSet) { dependencySibling = smartSheetHelperObject.AddSubTasks(smartsheetClient, projectEntryGraph, columnMap, sheet, actualTask, pmTemplateTaskSSExtRow, subTaskRow, ssRow.Id, dependencyStartDateOffset, dependencySibling, templateMappingSet); } } } } } return; }
public virtual PMTask CopyTask(PMTask originalTask, int projectId, ProjectEntry.DefaultFromTemplateSettings settings, Func <PMTask, int, ProjectEntry.DefaultFromTemplateSettings, PMTask> baseHandler) { var targetTask = baseHandler(originalTask, projectId, settings); targetTask.Type = originalTask.Type; return(targetTask); }
private static PMQuoteTask CreateQuoteTask(PMQuote quote, PMTask task) { return(new PMQuoteTask { QuoteID = quote.QuoteID, TaskCD = task.TaskCD, Description = task.Description, IsDefault = task.IsDefault, TaxCategoryID = task.TaxCategoryID }); }
/// <summary> /// Verifies the content of the Acumatica Project /// </summary> /// <param name="projectEntryGraph"></param> public void ProjectValidation(ProjectEntry projectEntryGraph) { PMTask pmTaskRow = (PMTask)projectEntryGraph.Tasks.Select() .Where(t => ((PMTask)t).StartDate == null || ((PMTask)t).EndDate == null).FirstOrDefault(); if (pmTaskRow != null) { throw new PXException(SmartsheetConstants.Messages.ALL_DATES_MUST_BE_SET); } return; }
public DocLineExt(PXResult <FSAppointmentDet, FSAppointment, FSServiceOrder, FSSrvOrdType, FSPostDoc, FSPostInfo, PMTask> appointmentDetLine) { this.docLine = (IDocLine)(FSAppointmentDet)appointmentDetLine; this.fsPostDoc = (FSPostDoc)appointmentDetLine; this.fsServiceOrder = (FSServiceOrder)appointmentDetLine; this.fsSrvOrdType = (FSSrvOrdType)appointmentDetLine; this.fsAppointment = (FSAppointment)appointmentDetLine; this.fsPostInfo = (FSPostInfo)appointmentDetLine; this.fsSODet = null; this.fsSODetSplit = null; this.inItemPlan = null; this.pmTask = (PMTask)appointmentDetLine; }
public DocLineExt(PXResult <FSSODet, FSServiceOrder, FSSrvOrdType, FSSODetSplit, INItemPlan, PMTask> soDetLine) { this.docLine = (IDocLine)(FSSODet)soDetLine; this.fsPostDoc = null; this.fsServiceOrder = (FSServiceOrder)soDetLine; this.fsSrvOrdType = (FSSrvOrdType)soDetLine; this.fsAppointment = null; this.fsPostInfo = null; this.fsSODet = (FSSODet)soDetLine; this.fsSODetSplit = (FSSODetSplit)soDetLine; this.inItemPlan = (INItemPlan)soDetLine; this.pmTask = (PMTask)soDetLine; }
/// <summary> /// Adds subtasks to the Smartsheet project /// </summary> /// <param name="smartsheetClient"></param> /// <param name="columnMap"></param> /// <param name="sheet"></param> /// <param name="taskRow"></param> /// <param name="pmTemplateTaskSSExtRow"></param> /// <param name="subTaskRow"></param> /// <param name="columnID"></param> /// <param name="dependencyStartDateOffset"></param> /// <param name="dependencySibling"></param> /// <returns></returns> public long AddSubTasks(SmartsheetClient smartsheetClient, Dictionary <string, long> columnMap, Sheet sheet, PMTask taskRow, PMTaskSSExt pmTemplateTaskSSExtRow, PMSubTask subTaskRow, long?columnID, int dependencyStartDateOffset, long dependencySibling) { List <Cell> newCells = new List <Cell>(); Cell currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.TASK_NAME], subTaskRow.SubTaskCD).Build(); currentCell.Format = SmartsheetConstants.CellFormat.LARGE_GRAY_BACKGROUND; newCells.Add(currentCell); if (pmTemplateTaskSSExtRow.UsrEnableSubtaskDependency == true) { DateTime adjustedStartDate = taskRow.StartDate.Value.AddDays((double)dependencyStartDateOffset); currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.START], adjustedStartDate).Build(); newCells.Add(currentCell); } else { currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.START], taskRow.StartDate).Build(); newCells.Add(currentCell); } currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.DURATION], subTaskRow.Duration.ToString()).Build(); newCells.Add(currentCell); currentCell = new Cell.AddCellBuilder(columnMap[SmartsheetConstants.GanttTemplateMapping.COMMENTS], subTaskRow.Description).Build(); newCells.Add(currentCell); Row currentRow = new Row.AddRowBuilder(null, true, null, null, null).SetCells(newCells).Build(); currentRow.ParentId = (long)columnID; currentRow.Format = SmartsheetConstants.CellFormat.GRAY_BACKGROUND; List <Row> newSSRows = new List <Row>(); newSSRows.Add(currentRow); IList <Row> ssRows = smartsheetClient.SheetResources.RowResources.AddRows((long)sheet.Id, newSSRows); return((long)ssRows[0].Id); }
/// <summary> /// Method build sales or expense sub account by mask for receipt /// </summary> /// <typeparam name="SubMaskField"><see=EPSetup.salesSubMask/> or <see=EPSetup.expenseSubMask/></typeparam> /// <typeparam name="CompanySubField">Field of receipt with company sub account (<see=Location.cMPSalesSubID/> or <see=Location.cMPExpenseSubID/>)</typeparam> /// <typeparam name="EmployeeSubField">Field of receipt with employee sub account (<see=EPEmployee.salesSubID/> or <see=EPEmployee.expenseSubID/>)</typeparam> /// <typeparam name="ItemSubField">Field of receipt with inventory item sub account (<see=InventoryItem.salesSubID/> or <see=InventoryItem.cOGSSubID/>)</typeparam> /// <param name="receiptCache">Cache of receipt</param> /// <param name="receipt">Receipt for which build sub account</param> /// <param name="subMask">Mask from <see=EPSetup/></param> /// <returns>Sub account by mask</returns> public static object MakeSubAccountByMaskForReceipt <SubMaskField, CompanySubField, EmployeeSubField, ItemSubField>(PXCache receiptCache, EPExpenseClaimDetails receipt, string subMask) where SubMaskField : IBqlField where CompanySubField : IBqlField where EmployeeSubField : IBqlField where ItemSubField : IBqlField { object value = null; InventoryItem item = (InventoryItem)PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(receiptCache.Graph, receipt.InventoryID); Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <EPExpenseClaimDetails.branchID> > > > .Select(receiptCache.Graph, receipt); Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(receiptCache.Graph, receipt.ContractID); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(receiptCache.Graph, receipt.ContractID, receipt.TaskID); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(receiptCache, receipt); EPEmployee employee = (EPEmployee)PXSelect <EPEmployee> .Search <EPEmployee.bAccountID>(receiptCache.Graph, receipt != null?receipt.EmployeeID : null); int?employee_SubID = (int?)receiptCache.Graph.Caches[typeof(EPEmployee)].GetValue <EmployeeSubField>(employee); int?item_SubID = (int?)receiptCache.Graph.Caches[typeof(InventoryItem)].GetValue <ItemSubField>(item); int?company_SubID = (int?)receiptCache.Graph.Caches[typeof(Location)].GetValue <CompanySubField>(companyloc); int?project_SubID = (int?)receiptCache.Graph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)receiptCache.Graph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)receiptCache.Graph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); value = SubAccountMaskAttribute.MakeSub <SubMaskField>(receiptCache.Graph, subMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EmployeeSubField), typeof(ItemSubField), typeof(CompanySubField), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); return(value); }
protected virtual void PMTask_StartDate_FieldUpdating(PXCache sender, PXFieldUpdatingEventArgs e) { if (e.Row == null) { return; } PMTask pmTaskRow = (PMTask)e.Row; PMTaskSSExt pmTaskExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(pmTaskRow); if (pmTaskExtRow.Duration != null && pmTaskExtRow.Duration >= 1 && e.NewValue != null) { SmartsheetHelper smartSheetHelperObject = new SmartsheetHelper(); DateTime endDateRow = smartSheetHelperObject.CalculateWorkingDays((DateTime)e.NewValue, (int)pmTaskExtRow.Duration); pmTaskRow.EndDate = endDateRow; } }
private void FillProjectTaskInfo(ComplianceDocument complianceDocument, PMTask task) { var type = task.Type; if (type != null) { if (type == ProjectTaskType.Cost || type == ProjectTaskType.CostRevenue) { complianceDocument.CostTaskID = task.TaskID; } if (type == ProjectTaskType.Revenue || type == ProjectTaskType.CostRevenue) { complianceDocument.RevenueTaskID = task.TaskID; } } complianceDocument.ProjectID = task.ProjectID; complianceDocument.CustomerID = task.CustomerID; complianceDocument.CustomerName = GetCustomerName(complianceDocument.CustomerID); }
public void ValidateProjectTaskType(PXCache cache, PMTask projectTask) { var status = cache.GetStatus(projectTask); if (status == PXEntryStatus.Updated) { if (projectTask.Type == ProjectTaskType.Cost && IsTaskUsedInRevenueDocument(projectTask.TaskID)) { cache.RaiseException <PMTask.type>(projectTask, string.Format(ProjectAccountingMessages.TaskTypeCannotBeChanged, PmMessages.TaskType_Revenue), projectTask.Type); } if (projectTask.Type == ProjectTaskType.Revenue && IsTaskUsedInCostDocument(projectTask.TaskID)) { cache.RaiseException <PMTask.type>(projectTask, string.Format(ProjectAccountingMessages.TaskTypeCannotBeChanged, PmMessages.TaskType_Expense), projectTask.Type); } } }
protected virtual void EPActivityApprove_ProjectTaskID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e) { EPActivityApprove row = (EPActivityApprove)e.Row; if (row == null) { return; } if (Filter.Current.ProjectTaskID != null) { e.NewValue = Filter.Current.ProjectTaskID; e.Cancel = true; return; } if (row.ParentTaskNoteID != null) { EPActivityApprove rowParentTask = PXSelect <EPActivityApprove> .Search <EPActivityApprove.noteID>(this, row.ParentTaskNoteID); if (rowParentTask != null && rowParentTask.ProjectID == row.ProjectID) { e.NewValue = rowParentTask.ProjectTaskID; e.Cancel = true; } } EPEarningType earningRow = (EPEarningType)PXSelectorAttribute.Select <EPActivityApprove.earningTypeID>(cache, row); if (e.NewValue == null && earningRow != null && earningRow.ProjectID == row.ProjectID) { PMTask defTask = PXSelectorAttribute.Select(cache, e.Row, cache.GetField(typeof(EPTimeCardSummary.projectTaskID)), earningRow.TaskID) as PMTask; if (defTask != null && defTask.VisibleInEP == true) { e.NewValue = earningRow.TaskID; e.Cancel = true; } } }
public virtual void GeneratePMTasks(PreventiveMaintenance pm, long?assetId) { if (assetId == null) { return; } if (pm.IsNew == true) { var assetType = _assetRepository.GetById(assetId).AssetType.Name; var taskGroup = _taskGroupRepository.GetAll() .Where(t => t.AssetTypes.Contains(assetType)) .FirstOrDefault(); if (taskGroup != null) { pm.TaskGroupId = taskGroup.Id; var tasks = taskGroup.Tasks.ToList(); foreach (var task in tasks) { var pmTask = new PMTask { Sequence = task.Sequence, Description = task.Description }; pm.PMTasks.Add(pmTask); } _preventiveMaintenanceRepository.Update(pm); this._dbContext.SaveChanges(); //copy attachments, need to copy after saving PMTasks //so we can have toEntityId for (int i = 0; i < tasks.Count; i++) { _attachmentService.CopyAttachments(tasks[i].Id, EntityType.Task, pm.PMTasks.ToList()[i].Id, EntityType.PMTask); } } } }
private List <PMHistory> GetPeriodsToCalculate(PMProject project, PMTask task, PMAccountGroup accountGroup, InventoryItem item, RMDataSource ds, RMDataSourceGL dsGL) { Dictionary <string, PMHistory> periodsForKey = null; var key = new PMHistoryKeyTuple(project.ContractID.Value, task.TaskCD, accountGroup.GroupID.Value, item.InventoryID.Value); if (!_pmhistoryPeriodsByKey.TryGetValue(key, out periodsForKey)) { return(null); } if (ds.AmountType == BalanceType.Amount || ds.AmountType == BalanceType.Quantity || ds.AmountType == BalanceType.BudgetAmount || ds.AmountType == BalanceType.BudgetQuantity || ds.AmountType == BalanceType.RevisedAmount || ds.AmountType == BalanceType.RevisedQuantity) { //These amounts are calculated against start of project dsGL.StartPeriod = _reportPeriods.PerWildcard; dsGL.StartPeriodOffset = 0; dsGL.StartPeriodYearOffset = 0; } return(_reportPeriods.GetPeriodsForRegularAmount(dsGL, periodsForKey)); }
protected virtual void EPExpenseClaimDetails_RowPersisting(PXCache cache, PXRowPersistingEventArgs e) { EPExpenseClaimDetails row = e.Row as EPExpenseClaimDetails; if ((bool)((EPExpenseClaimDetails)e.Row).Billable == true & ((EPExpenseClaimDetails)e.Row).CustomerID == null) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.customerID>(e.Row, null, new PXSetPropertyException(Messages.CustomerRequired)); } if (((EPExpenseClaimDetails)e.Row).CustomerID != null & ((EPExpenseClaimDetails)e.Row).CustomerLocationID == null) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.customerLocationID>(e.Row, null, new PXSetPropertyException(Messages.CustomerLocationRequired)); } if (row.ContractID != null) { PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ContractID); if (project.CustomerID != null && row.CustomerID != null) { if (project.CustomerID != row.CustomerID) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.contractID>(e.Row, null, new PXSetPropertyException(Messages.CustomerDoesNotMatchProject)); } } if ((bool)((EPExpenseClaimDetails)e.Row).Billable && row.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(this, row.TaskID); if (task != null && !(bool)task.VisibleInAP) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>(e.Row, task.TaskCD, new PXSetPropertyException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP)); } } } }
protected virtual void EPExpenseClaimDetails_RowSelected(PXCache cache, PXRowSelectedEventArgs e) { EPExpenseClaimDetails row = (EPExpenseClaimDetails)e.Row; if (row != null) { EPExpenseClaim claim = (EPExpenseClaim)PXSelect <EPExpenseClaim, Where <EPExpenseClaim.refNbr, Equal <Required <EPExpenseClaimDetails.refNbr> > > > .SelectSingleBound(this, new object[] { null }, row.RefNbr); bool enabledApprovalReceipt = PXAccess.FeatureInstalled <FeaturesSet.approvalWorkflow>() && epsetup.Current.ClaimDetailsAssignmentMapID != null; bool legacyClaim = row.LegacyReceipt == true && !String.IsNullOrEmpty(row.RefNbr); bool enabledEditReceipt = (row.Hold == true || !enabledApprovalReceipt) && !legacyClaim; bool enabledRefNbr = true; bool enabledEmployeeAndBranch = enabledEditReceipt && !(row.ClaimCuryInfoID == null && cache.AllowUpdate && !string.IsNullOrEmpty(row.RefNbr)); bool enabledFinancialDetails = (row.Rejected != true) && (row.Released != true); bool NonProject = (CurrentContract.SelectSingle()?.ContractCD ?? PMSetup.DefaultNonProjectCode).Trim() == PMSetup.DefaultNonProjectCode; bool claimReleased = false; if (claim != null) { bool enabledEditClaim = (row.HoldClaim == true); enabledEditReceipt = enabledEditReceipt && enabledEditClaim; enabledRefNbr = enabledEditClaim; enabledEmployeeAndBranch = false; enabledFinancialDetails = enabledFinancialDetails && enabledEditClaim; claimReleased = claim.Released == true; } enabledRefNbr = enabledRefNbr && row.LegacyReceipt == false; Approval.AllowSelect = enabledApprovalReceipt; Delete.SetEnabled(enabledEditReceipt && claim == null); PXUIFieldAttribute.SetEnabled(cache, row, enabledEditReceipt); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.claimDetailID>(cache, row, true); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.refNbr>(cache, row, enabledRefNbr); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.employeeID>(cache, row, enabledEmployeeAndBranch); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.branchID>(cache, row, enabledEmployeeAndBranch); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseAccountID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.expenseSubID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesAccountID>(cache, row, enabledFinancialDetails && (row.Billable == true)); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.salesSubID>(cache, row, enabledFinancialDetails && (row.Billable == true)); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCategoryID>(cache, row, enabledFinancialDetails); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.customerID>(cache, row, NonProject && !claimReleased); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.customerLocationID>(cache, row, NonProject && !claimReleased); action.SetEnabled("Submit", cache.GetStatus(row) != PXEntryStatus.Inserted && row.Hold == true); if (row.ContractID != null && (bool)row.Billable && row.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(this, row.TaskID); if (task != null && !(bool)task.VisibleInAP) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.taskID>(e.Row, task.TaskCD, new PXSetPropertyException(PM.Messages.TaskInvisibleInModule, task.TaskCD, GL.BatchModule.AP)); } } CurrencyInfo info = (CurrencyInfo)PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Current <EPExpenseClaimDetails.curyInfoID> > > > .SelectSingleBound(this, new object[] { row }); if (info != null && info.CuryRateTypeID != null && info.CuryEffDate != null && row.ExpenseDate != null && info.CuryEffDate < row.ExpenseDate) { CurrencyRateType ratetype = (CurrencyRateType)PXSelectorAttribute.Select <CurrencyInfo.curyRateTypeID>(currencyinfo.Cache, info); if (ratetype != null && ratetype.RateEffDays > 0 && ((TimeSpan)(row.ExpenseDate - info.CuryEffDate)).Days > ratetype.RateEffDays) { PXRateIsNotDefinedForThisDateException exc = new PXRateIsNotDefinedForThisDateException(info.CuryRateTypeID, info.BaseCuryID, info.CuryID, (DateTime)row.ExpenseDate); cache.RaiseExceptionHandling <EPExpenseClaimDetails.expenseDate>(e.Row, ((EPExpenseClaimDetails)e.Row).ExpenseDate, exc); } } string message = PXUIFieldAttribute.GetError <CurrencyInfo.curyID>(currencyinfo.Cache, info); if (string.IsNullOrEmpty(message) && info != null && info.CuryRate == null) { message = CM.Messages.RateNotFound; } if (string.IsNullOrEmpty(message)) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, null); } else { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyID>(e.Row, null, new PXSetPropertyException(message, PXErrorLevel.Warning)); } bool allowEdit = this.Accessinfo.UserID == row.CreatedByID; if (Employee.Current != null) { if (!allowEdit && this.Accessinfo.UserID == Employee.Current.UserID) { allowEdit = true; } if (!allowEdit) { EPWingman wingMan = PXSelectJoin <EPWingman, InnerJoin <EPEmployee, On <EPWingman.wingmanID, Equal <EPEmployee.bAccountID> > >, Where <EPWingman.employeeID, Equal <Required <EPWingman.employeeID> >, And <EPEmployee.userID, Equal <Required <EPEmployee.userID> > > > > .Select(this, row.EmployeeID, Accessinfo.UserID); if (wingMan != null) { allowEdit = true; } } } //Another conditions in automation steps if (!allowEdit) { action.SetEnabled(MsgNotLocalizable.PutOnHold, false); } bool taxSettingsEnabled = enabledEditReceipt && (epsetup.Current.AllowMixedTaxSettingInClaims == true || CurrentClaimDetails.Current.RefNbr == null); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxZoneID>(cache, row, taxSettingsEnabled); ValidateProjectAndProjectTask(row); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCalcMode>(cache, row, taxSettingsEnabled); PXUIFieldAttribute.SetEnabled <EPExpenseClaimDetails.taxCategoryID>(cache, row, enabledEditReceipt); PXUIFieldAttribute.SetVisible <EPExpenseClaimDetails.curyTipAmt>(ClaimDetails.Cache, null, epsetup.Current.NonTaxableTipItem.HasValue || (row.CuryTipAmt ?? 0) != 0); Taxes.Cache.SetAllEditPermissions(enabledEditReceipt); RaiseOrHideError <EPExpenseClaimDetails.refNbr>(cache, row, legacyClaim && row.Released == false, Messages.LegacyClaim, PXErrorLevel.Warning, row.RefNbr); RaiseOrHideError <EPExpenseClaimDetails.claimDetailID>(cache, row, row.LegacyReceipt == true && row.Released == false && !String.IsNullOrEmpty(row.TaxZoneID), Messages.LegacyReceipt, PXErrorLevel.Warning); EPEmployee employeeRow = Employee.Select(); string taxZoneID = EPClaimReceiptController.GetTaxZoneID(this, employeeRow); bool notMatchtaxZone = String.IsNullOrEmpty(row.TaxZoneID) && !String.IsNullOrEmpty(taxZoneID); RaiseOrHideError <EPExpenseClaimDetails.taxZoneID>(cache, row, notMatchtaxZone && row.Released == false, Messages.TaxZoneEmpty, PXErrorLevel.Warning); if (UseTaxes.Select().Count != 0) { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyTaxTotal>(row, row.CuryTaxTotal, new PXSetPropertyException(TX.Messages.UseTaxExcludedFromTotals, PXErrorLevel.Warning)); } else { cache.RaiseExceptionHandling <EPExpenseClaimDetails.curyTaxTotal>(row, row.CuryTaxTotal, null); } } }
public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow) { if (docLinesGrouped.Count == 0) { return; } bool?initialHold = false; FSServiceOrder fsServiceOrderRow = docLinesGrouped[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLinesGrouped[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLinesGrouped[0].fsPostDoc; FSAppointment fsAppointmentRow = docLinesGrouped[0].fsAppointment; Base.FieldDefaulting.AddHandler <ARInvoice.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); ARInvoice arInvoiceRow = new ARInvoice(); if (invtMult >= 0) { arInvoiceRow.DocType = ARInvoiceType.Invoice; } else { arInvoiceRow.DocType = ARInvoiceType.CreditMemo; } arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.InvoiceNbr = fsServiceOrderRow.CustPORefNbr; arInvoiceRow = Base.Document.Insert(arInvoiceRow); initialHold = arInvoiceRow.Hold; arInvoiceRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, arInvoiceRow); Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, true); Base.Document.Cache.SetValueExt <ARInvoice.customerID>(arInvoiceRow, fsServiceOrderRow.BillCustomerID); Base.Document.Cache.SetValueExt <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceOrderRow.BillLocationID); Base.Document.Cache.SetValueExt <ARInvoice.curyID>(arInvoiceRow, fsServiceOrderRow.CuryID); Base.Document.Cache.SetValueExt <ARInvoice.taxZoneID>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceOrderRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExt <ARInvoice.termsID>(arInvoiceRow, fsSrvOrdTypeRow.DfltTermIDARSO); } if (fsServiceOrderRow.ProjectID != null) { Base.Document.Cache.SetValueExt <ARInvoice.projectID>(arInvoiceRow, fsServiceOrderRow.ProjectID); } Base.Document.Cache.SetValueExt <ARInvoice.docDesc>(arInvoiceRow, fsServiceOrderRow.DocDesc); arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow = Base.Document.Update(arInvoiceRow); InvoicingFunctions.SetAddress(Base, fsServiceOrderRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, arInvoiceRow); } IDocLine docLine = null; ARTran arTranRow = null; FSxARTran fsxARTranRow = null; int? acctID; foreach (DocLineExt docLineExt in docLinesGrouped) { docLine = docLineExt.docLine; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.inventoryID>(arTranRow, docLine.InventoryID); Base.Transactions.Cache.SetValueExt <ARTran.uOM>(arTranRow, docLine.UOM); if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { PMTask pmTaskRow = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(graphProcess, docLine.ProjectTaskID); Base.Transactions.Cache.SetValueExt <ARTran.taskID>(arTranRow, pmTaskRow.TaskCD); } Base.Transactions.Cache.SetValueExt <ARTran.qty>(arTranRow, docLine.GetQty(FieldType.BillableField)); Base.Transactions.Cache.SetValueExt <ARTran.tranDesc>(arTranRow, docLine.TranDesc); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExt <ARTran.salesPersonID>(arTranRow, fsAppointmentRow == null ? fsServiceOrderRow.SalesPersonID : fsAppointmentRow.SalesPersonID); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = (int?)ServiceOrderCore.Get_TranAcctID_DefaultValue( graphProcess, fsSrvOrdTypeRow.SalesAcctSource, docLine.InventoryID, fsServiceOrderRow); } Base.Transactions.Cache.SetValueExt <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExt <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID( graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSrvOrdTypeRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceOrderRow.BranchLocationID, fsServiceOrderRow.SalesPersonID, docLine.IsService); } Base.Transactions.Cache.SetValueExt <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice * invtMult); Base.Transactions.Cache.SetValueExt <ARTran.taxCategoryID>(arTranRow, docLine.TaxCategoryID); //Base.Transactions.Cache.SetValueExt<ARTran.curyExtPrice>(arTranRow, docLine.GetTranAmt(FieldType.BillableField) * invtMult); Base.Transactions.Cache.SetValueExt <ARTran.commissionable>(arTranRow, fsAppointmentRow?.Commissionable ?? fsServiceOrderRow.Commissionable ?? false); Base.Transactions.Cache.SetValueExt <ARTran.costCodeID>(arTranRow, docLine.CostCodeID); fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = docLine.BillingBy; fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; fsxARTranRow.BillCustomerID = fsServiceOrderRow.BillCustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.BillLocationID; fsxARTranRow.SODetID = docLine.PostSODetID; fsxARTranRow.AppointmentID = docLine.PostAppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxARTranRow.AppDetID = docLine.PostAppDetID; fsxARTranRow.Mem_PreviousPostID = docLine.PostID; fsxARTranRow.Mem_TableSource = docLine.SourceTable; SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, arTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); if (onTransactionInserted != null) { onTransactionInserted(Base, arTranRow); } } arInvoiceRow = Base.Document.Update(arInvoiceRow); if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExt <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } if (initialHold != true) { Base.Document.Cache.SetValueExt <ARInvoice.hold>(arInvoiceRow, false); } arInvoiceRow = Base.Document.Update(arInvoiceRow); }
public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow) { if (docLinesGrouped.Count == 0) { return; } bool?initialHold = false; FSServiceOrder fsServiceOrderRow = docLinesGrouped[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLinesGrouped[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLinesGrouped[0].fsPostDoc; FSAppointment fsAppointmentRow = docLinesGrouped[0].fsAppointment; Vendor vendorRow = SharedFunctions.GetVendorRow(graphProcess, fsServiceOrderRow.BillCustomerID); if (vendorRow == null) { throw new PXException(TX.Error.AP_POSTING_VENDOR_NOT_FOUND); } Base.FieldDefaulting.AddHandler <APInvoice.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); APInvoice apInvoiceRow = new APInvoice(); if (invtMult >= 0) { apInvoiceRow.DocType = APDocType.DebitAdj; AutoNumberHelper.CheckAutoNumbering(Base, Base.APSetup.SelectSingle().DebitAdjNumberingID); } else { apInvoiceRow.DocType = APDocType.Invoice; AutoNumberHelper.CheckAutoNumbering(Base, Base.APSetup.SelectSingle().InvoiceNumberingID); } apInvoiceRow.DocDate = invoiceDate; apInvoiceRow.FinPeriodID = invoiceFinPeriodID; apInvoiceRow = PXCache <APInvoice> .CreateCopy(Base.Document.Insert(apInvoiceRow)); initialHold = apInvoiceRow.Hold; apInvoiceRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, apInvoiceRow); apInvoiceRow.VendorID = fsServiceOrderRow.BillCustomerID; apInvoiceRow.VendorLocationID = fsServiceOrderRow.BillLocationID; apInvoiceRow.CuryID = fsServiceOrderRow.CuryID; apInvoiceRow.TaxZoneID = fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID; apInvoiceRow.TaxCalcMode = fsAppointmentRow != null ? fsAppointmentRow.TaxCalcMode : fsServiceOrderRow.TaxCalcMode; apInvoiceRow.SuppliedByVendorLocationID = fsServiceOrderRow.BillLocationID; string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, null, fsServiceOrderRow.BillCustomerID); if (termsID == null) { termsID = fsSrvOrdTypeRow.DfltTermIDAP; } apInvoiceRow.FinPeriodID = invoiceFinPeriodID; apInvoiceRow.TermsID = termsID; apInvoiceRow.DocDesc = fsServiceOrderRow.DocDesc; apInvoiceRow.Hold = true; apInvoiceRow = Base.Document.Update(apInvoiceRow); apInvoiceRow.TaxCalcMode = PX.Objects.TX.TaxCalculationMode.TaxSetting; apInvoiceRow = Base.Document.Update(apInvoiceRow); InvoicingFunctions.SetContactAndAddress(Base, fsServiceOrderRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, apInvoiceRow); } IDocLine docLine = null; APTran apTranRow = null; FSxAPTran fsxAPTranRow = null; PMTask pmTaskRow = null; foreach (DocLineExt docLineExt in docLinesGrouped) { docLine = docLineExt.docLine; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; apTranRow = new APTran(); apTranRow = Base.Transactions.Insert(apTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.branchID>(apTranRow, docLine.BranchID); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.inventoryID>(apTranRow, docLine.InventoryID); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.uOM>(apTranRow, docLine.UOM); pmTaskRow = docLineExt.pmTask; if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed) { throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD); } if (docLine.AcctID != null) { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.accountID>(apTranRow, docLine.AcctID); } if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.subID>(apTranRow, docLine.SubID); } catch (PXException) { apTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID(graphProcess, Base.Transactions.Cache, null, apTranRow, null, fsSrvOrdTypeRow, apTranRow.BranchID, apTranRow.InventoryID, apInvoiceRow.VendorLocationID, fsServiceOrderRow.BranchLocationID, fsServiceOrderRow.SalesPersonID, docLine.IsService); } if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.taskID>(apTranRow, docLine.ProjectTaskID); } Base.Transactions.Cache.SetValueExtIfDifferent <APTran.qty>(apTranRow, docLine.GetQty(FieldType.BillableField)); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.tranDesc>(apTranRow, docLine.TranDesc); apTranRow = Base.Transactions.Update(apTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.curyUnitCost>(apTranRow, docLine.CuryUnitPrice * invtMult); if (docLine.ProjectID != null) { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.projectID>(apTranRow, docLine.ProjectID); } Base.Transactions.Cache.SetValueExtIfDifferent <APTran.taxCategoryID>(apTranRow, docLine.TaxCategoryID); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.costCodeID>(apTranRow, docLine.CostCodeID); if (docLine.IsBillable == false) { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.manualDisc>(apTranRow, true); Base.Transactions.Cache.SetValueExtIfDifferent <APTran.curyDiscAmt>(apTranRow, docLine.GetQty(FieldType.BillableField) * docLine.CuryUnitPrice * invtMult); } else { Base.Transactions.Cache.SetValueExtIfDifferent <APTran.discPct>(apTranRow, docLine.DiscPct); } fsxAPTranRow = Base.Transactions.Cache.GetExtension <FSxAPTran>(apTranRow); fsxAPTranRow.Source = docLine.BillingBy; fsxAPTranRow.SOID = fsServiceOrderRow.SOID; fsxAPTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; fsxAPTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxAPTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; fsxAPTranRow.SODetID = docLine.PostSODetID; fsxAPTranRow.AppointmentID = docLine.PostAppointmentID; fsxAPTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxAPTranRow.AppDetID = docLine.PostAppDetID; if (docLine.BillingBy == ID.Billing_By.APPOINTMENT) { //// TODO AC-142850 ////fsxAPTranRow.AppointmentDate = new DateTime( //// fsAppointmentRow.ActualDateTimeBegin.Value.Year, //// fsAppointmentRow.ActualDateTimeBegin.Value.Month, //// fsAppointmentRow.ActualDateTimeBegin.Value.Day, //// 0, //// 0, //// 0); } fsxAPTranRow.Mem_PreviousPostID = docLine.PostID; fsxAPTranRow.Mem_TableSource = docLine.SourceTable; SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, apTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.DocLineRef = apTranRow = Base.Transactions.Update(apTranRow); if (onTransactionInserted != null) { onTransactionInserted(Base, apTranRow); } } apInvoiceRow = Base.Document.Update(apInvoiceRow); if (Base.APSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExtIfDifferent <APInvoice.curyOrigDocAmt>(apInvoiceRow, apInvoiceRow.CuryDocBal); } if (initialHold != true) { Base.Document.Cache.SetValueExtIfDifferent <APInvoice.hold>(apInvoiceRow, false); } apInvoiceRow = Base.Document.Update(apInvoiceRow); }
public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow) { if (docLinesGrouped.Count == 0) { return; } bool?initialHold = false; FSServiceOrder fsServiceOrderRow = docLines[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLines[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLines[0].fsPostDoc; FSAppointment fsAppointmentRow = docLines[0].fsAppointment; Base.FieldDefaulting.AddHandler <ARInvoice.branchID>((sender, e) => { e.NewValue = fsServiceOrderRow.BranchID; e.Cancel = true; }); ARInvoice arInvoiceRow = new ARInvoice(); if (invtMult >= 0) { arInvoiceRow.DocType = ARInvoiceType.Invoice; AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().InvoiceNumberingID); } else { arInvoiceRow.DocType = ARInvoiceType.CreditMemo; AutoNumberHelper.CheckAutoNumbering(Base, Base.ARSetup.SelectSingle().CreditAdjNumberingID); } arInvoiceRow.DocDate = invoiceDate; arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow.InvoiceNbr = fsServiceOrderRow.CustPORefNbr; arInvoiceRow = Base.Document.Insert(arInvoiceRow); initialHold = arInvoiceRow.Hold; arInvoiceRow.NoteID = null; PXNoteAttribute.GetNoteIDNow(Base.Document.Cache, arInvoiceRow); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, true); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerID>(arInvoiceRow, fsServiceOrderRow.BillCustomerID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.customerLocationID>(arInvoiceRow, fsServiceOrderRow.BillLocationID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyID>(arInvoiceRow, fsServiceOrderRow.CuryID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxZoneID>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxZoneID : fsServiceOrderRow.TaxZoneID); Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.taxCalcMode>(arInvoiceRow, fsAppointmentRow != null ? fsAppointmentRow.TaxCalcMode : fsServiceOrderRow.TaxCalcMode); string termsID = InvoicingFunctions.GetTermsIDFromCustomerOrVendor(graphProcess, fsServiceOrderRow.BillCustomerID, null); if (termsID != null) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, termsID); } else { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.termsID>(arInvoiceRow, fsSrvOrdTypeRow.DfltTermIDARSO); } if (fsServiceOrderRow.ProjectID != null) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.projectID>(arInvoiceRow, fsServiceOrderRow.ProjectID); } Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.docDesc>(arInvoiceRow, fsServiceOrderRow.DocDesc); arInvoiceRow.FinPeriodID = invoiceFinPeriodID; arInvoiceRow = Base.Document.Update(arInvoiceRow); InvoicingFunctions.SetContactAndAddress(Base, fsServiceOrderRow); if (onDocumentHeaderInserted != null) { onDocumentHeaderInserted(Base, arInvoiceRow); } IDocLine docLine = null; ARTran arTranRow = null; FSxARTran fsxARTranRow = null; PMTask pmTaskRow = null; List <SharedClasses.SOARLineEquipmentComponent> componentList = new List <SharedClasses.SOARLineEquipmentComponent>(); int?acctID; int?pivotAppointmentDetID = -1; foreach (DocLineExt docLineExt in docLines) { docLine = docLineExt.docLine; if (docLineExt.fsAppointment != null) { if (pivotAppointmentDetID != docLineExt.docLine.LineID) { pivotAppointmentDetID = docLineExt.docLine.LineID; } else { continue; } } FSSODetSplit fsSODetSplitRow = docLineExt.fsSODetSplit; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; arTranRow = new ARTran(); arTranRow = Base.Transactions.Insert(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.branchID>(arTranRow, docLine.BranchID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.inventoryID>(arTranRow, docLine.InventoryID); pmTaskRow = docLineExt.pmTask; if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed) { throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD); } if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taskID>(arTranRow, docLine.ProjectTaskID); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.uOM>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.UOM : docLine.UOM); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.siteID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.SiteID : docLine.SiteID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.locationID>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.LocationID : docLine.SiteLocationID); if (docLine.IsService == true || fsAppointmentRow != null) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, docLine.GetQty(FieldType.BillableField)); } else { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.qty>(arTranRow, fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 ? fsSODetSplitRow.Qty : docLine.GetQty(FieldType.BillableField)); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.tranDesc>(arTranRow, docLine.TranDesc); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.salesPersonID>(arTranRow, fsAppointmentRow == null ? fsServiceOrderRow.SalesPersonID : fsAppointmentRow.SalesPersonID); if (docLine.AcctID != null) { acctID = docLine.AcctID; } else { acctID = ServiceOrderCore.Get_TranAcctID_DefaultValue(graphProcess, fsSrvOrdTypeRow.SalesAcctSource, docLine.InventoryID, docLine.SiteID, fsServiceOrderRow); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.accountID>(arTranRow, acctID); if (docLine.SubID != null) { try { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.subID>(arTranRow, docLine.SubID); } catch (PXException) { arTranRow.SubID = null; } } else { InvoicingFunctions.SetCombinedSubID(graphProcess, Base.Transactions.Cache, arTranRow, null, null, fsSrvOrdTypeRow, arTranRow.BranchID, arTranRow.InventoryID, arInvoiceRow.CustomerLocationID, fsServiceOrderRow.BranchLocationID, fsServiceOrderRow.SalesPersonID, docLine.IsService); } Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualPrice>(arTranRow, docLine.ManualPrice); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyUnitPrice>(arTranRow, docLine.CuryUnitPrice * invtMult); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.taxCategoryID>(arTranRow, docLine.TaxCategoryID); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.commissionable>(arTranRow, fsAppointmentRow?.Commissionable ?? fsServiceOrderRow.Commissionable ?? false); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.costCodeID>(arTranRow, docLine.CostCodeID); if (docLine.IsBillable == false) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.manualDisc>(arTranRow, true); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyDiscAmt>(arTranRow, docLine.GetQty(FieldType.BillableField) * docLine.CuryUnitPrice * invtMult); } else { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.curyExtPrice>(arTranRow, ((docLine.CuryBillableExtPrice * invtMult) / docLine.GetQty(FieldType.BillableField)) * arTranRow.Qty); Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.discPct>(arTranRow, docLine.DiscPct); } if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr); } else if (fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr); } fsxARTranRow = Base.Transactions.Cache.GetExtension <FSxARTran>(arTranRow); fsxARTranRow.Source = docLine.BillingBy; fsxARTranRow.SOID = fsServiceOrderRow.SOID; fsxARTranRow.ServiceOrderDate = fsServiceOrderRow.OrderDate; fsxARTranRow.BillCustomerID = fsServiceOrderRow.CustomerID; fsxARTranRow.CustomerLocationID = fsServiceOrderRow.LocationID; fsxARTranRow.SODetID = docLine.PostSODetID; fsxARTranRow.AppointmentID = docLine.PostAppointmentID; fsxARTranRow.AppointmentDate = fsAppointmentRow?.ExecutionDate; fsxARTranRow.AppDetID = docLine.PostAppDetID; fsxARTranRow.Mem_PreviousPostID = docLine.PostID; fsxARTranRow.Mem_TableSource = docLine.SourceTable; SharedFunctions.CopyNotesAndFiles(Base.Transactions.Cache, arTranRow, docLine, fsSrvOrdTypeRow); fsPostDocRow.DocLineRef = arTranRow = Base.Transactions.Update(arTranRow); if (fsAppointmentRow != null && !string.IsNullOrEmpty(docLine.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, docLine.LotSerialNbr); } else if (fsSODetSplitRow != null && fsSODetSplitRow.SplitLineNbr > 0 && !string.IsNullOrEmpty(fsSODetSplitRow.LotSerialNbr)) { Base.Transactions.Cache.SetValueExtIfDifferent <ARTran.lotSerialNbr>(arTranRow, fsSODetSplitRow.LotSerialNbr); } if (PXAccess.FeatureInstalled <FeaturesSet.equipmentManagementModule>()) { if (docLine.EquipmentAction != null) { Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentAction>(arTranRow, docLine.EquipmentAction); Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.sMEquipmentID>(arTranRow, docLine.SMEquipmentID); Base.Transactions.Cache.SetValueExtIfDifferent <FSxARTran.equipmentLineRef>(arTranRow, docLine.EquipmentLineRef); fsxARTranRow.Comment = docLine.Comment; if (docLine.EquipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT || ((docLine.EquipmentAction == ID.Equipment_Action.CREATING_COMPONENT || docLine.EquipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT || docLine.EquipmentAction == ID.Equipment_Action.NONE) && string.IsNullOrEmpty(docLine.NewTargetEquipmentLineNbr) == false)) { componentList.Add(new SharedClasses.SOARLineEquipmentComponent(docLine, arTranRow, fsxARTranRow)); } else { fsxARTranRow.ComponentID = docLine.ComponentID; } } } if (onTransactionInserted != null) { onTransactionInserted(Base, arTranRow); } } if (componentList.Count > 0) { //Assigning the NewTargetEquipmentLineNbr field value for the component type records foreach (SharedClasses.SOARLineEquipmentComponent currLineModel in componentList.Where(x => x.equipmentAction == ID.Equipment_Action.SELLING_TARGET_EQUIPMENT)) { foreach (SharedClasses.SOARLineEquipmentComponent currLineComponent in componentList.Where(x => (x.equipmentAction == ID.Equipment_Action.CREATING_COMPONENT || x.equipmentAction == ID.Equipment_Action.UPGRADING_COMPONENT || x.equipmentAction == ID.Equipment_Action.NONE))) { if (currLineComponent.sourceNewTargetEquipmentLineNbr == currLineModel.sourceLineRef) { currLineComponent.fsxARTranRow.ComponentID = currLineComponent.componentID; currLineComponent.fsxARTranRow.NewTargetEquipmentLineNbr = currLineModel.currentLineRef; } } } } arInvoiceRow = Base.Document.Update(arInvoiceRow); if (Base.ARSetup.Current.RequireControlTotal == true) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.curyOrigDocAmt>(arInvoiceRow, arInvoiceRow.CuryDocBal); } if (initialHold != true || quickProcessFlow != PXQuickProcess.ActionFlow.NoFlow) { Base.Document.Cache.SetValueExtIfDifferent <ARInvoice.hold>(arInvoiceRow, false); } arInvoiceRow = Base.Document.Update(arInvoiceRow); }
public static void ReleaseDoc(EPExpenseClaim claim) { APInvoiceEntry docgraph = PXGraph.CreateInstance <APInvoiceEntry>(); ExpenseClaimEntry expenseclaim = PXGraph.CreateInstance <ExpenseClaimEntry>(); if (claim.FinPeriodID == null) { throw new PXException(Messages.ReleaseClaimWithoutFinPeriod); } //docgraph.FieldVerifying.AddHandler<APInvoice.vendorLocationID>(APInterceptor); EPEmployee employee = PXSelect <EPEmployee, Where <EPEmployee.bAccountID, Equal <Required <EPExpenseClaim.employeeID> > > > .Select(docgraph, claim.EmployeeID); Location emplocation = PXSelect <Location, Where <Location.bAccountID, Equal <Required <EPExpenseClaim.employeeID> >, And <Location.locationID, Equal <Required <EPExpenseClaim.locationID> > > > > .Select(docgraph, claim.EmployeeID, claim.LocationID); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(docgraph); APSetup apsetup = PXSelectReadonly <APSetup> .Select(docgraph); docgraph.vendor.Current = employee; docgraph.location.Current = emplocation; CurrencyInfo infoOriginal = PXSelect <CurrencyInfo, Where <CurrencyInfo.curyInfoID, Equal <Required <EPExpenseClaim.curyInfoID> > > > .Select(docgraph, claim.CuryInfoID); CurrencyInfo info = PXCache <CurrencyInfo> .CreateCopy(infoOriginal); info.CuryInfoID = null; info = docgraph.currencyinfo.Insert(info); APInvoice invoice = new APInvoice(); invoice.CuryInfoID = info.CuryInfoID; invoice.Hold = true; invoice.Released = false; invoice.Printed = false; invoice.OpenDoc = true; invoice.DocDate = claim.DocDate; invoice.InvoiceNbr = claim.RefNbr; invoice.DocDesc = claim.DocDesc; invoice.VendorID = claim.EmployeeID; invoice.CuryID = info.CuryID; invoice.VendorLocationID = claim.LocationID; invoice.APAccountID = emplocation != null ? emplocation.APAccountID : null; invoice.APSubID = emplocation != null ? emplocation.APSubID : null; invoice.TaxZoneID = claim.TaxZoneID; invoice = docgraph.Document.Insert(invoice); PXCache claimcache = docgraph.Caches[typeof(EPExpenseClaim)]; PXCache claimdetailcache = docgraph.Caches[typeof(EPExpenseClaimDetails)]; if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimcache, claim); if (note != null) { PXNoteAttribute.SetNote(docgraph.Document.Cache, invoice, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimcache, claim); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Document.Cache, invoice, files); } } using (PXConnectionScope cs = new PXConnectionScope()) { using (PXTransactionScope ts = new PXTransactionScope()) { TaxAttribute.SetTaxCalc <APTran.taxCategoryID, APTaxAttribute>(docgraph.Transactions.Cache, null, TaxCalc.ManualCalc); foreach (PXResult <EPExpenseClaimDetails, Contract> res in PXSelectJoin <EPExpenseClaimDetails, LeftJoin <Contract, On <EPExpenseClaimDetails.contractID, Equal <Contract.contractID> > >, Where <EPExpenseClaimDetails.refNbr, Equal <Required <EPExpenseClaim.refNbr> > > > .Select(docgraph, claim.RefNbr)) { EPExpenseClaimDetails claimdetail = (EPExpenseClaimDetails)res; Contract contract = (Contract)res; if (claimdetail.TaskID != null) { PMTask task = PXSelect <PMTask, Where <PMTask.taskID, Equal <Required <PMTask.taskID> > > > .Select(expenseclaim, claimdetail.TaskID); if (task != null && !(bool)task.VisibleInAP) { throw new PXException(PM.Messages.TaskInvisibleInModule, task.TaskCD, BatchModule.AP); } } APTran tran = new APTran(); tran.InventoryID = claimdetail.InventoryID; tran.TranDesc = claimdetail.TranDesc; tran.CuryUnitCost = claimdetail.CuryUnitCost; tran.Qty = claimdetail.Qty; tran.UOM = claimdetail.UOM; tran.NonBillable = claimdetail.Billable != true; tran.CuryLineAmt = claimdetail.CuryTranAmt; tran.Date = claimdetail.ExpenseDate; if (contract.BaseType == PM.PMProject.ProjectBaseType.Project) { tran.ProjectID = claimdetail.ContractID; } else { tran.ProjectID = PM.ProjectDefaultAttribute.NonProject(docgraph); } tran.TaskID = claimdetail.TaskID; tran.AccountID = claimdetail.ExpenseAccountID; tran.SubID = claimdetail.ExpenseSubID; tran.TaxCategoryID = claimdetail.TaxCategoryID; tran = docgraph.Transactions.Insert(tran); if (epsetup.CopyNotesAP == true) { string note = PXNoteAttribute.GetNote(claimdetailcache, claimdetail); if (note != null) { PXNoteAttribute.SetNote(docgraph.Transactions.Cache, tran, note); } } if (epsetup.CopyFilesAP == true) { Guid[] files = PXNoteAttribute.GetFileNotes(claimdetailcache, claimdetail); if (files != null && files.Length > 0) { PXNoteAttribute.SetFileNotes(docgraph.Transactions.Cache, tran, files); } } claimdetail.Released = true; expenseclaim.ExpenseClaimDetails.Update(claimdetail); } foreach (EPTaxTran tax in PXSelect <EPTaxTran, Where <EPTaxTran.refNbr, Equal <Required <EPTaxTran.refNbr> > > > .Select(docgraph, claim.RefNbr)) { APTaxTran new_aptax = new APTaxTran(); new_aptax.TaxID = tax.TaxID; new_aptax = docgraph.Taxes.Insert(new_aptax); if (new_aptax != null) { new_aptax = PXCache <APTaxTran> .CreateCopy(new_aptax); new_aptax.TaxRate = tax.TaxRate; new_aptax.CuryTaxableAmt = tax.CuryTaxableAmt; new_aptax.CuryTaxAmt = tax.CuryTaxAmt; new_aptax = docgraph.Taxes.Update(new_aptax); } } invoice.CuryOrigDocAmt = invoice.CuryDocBal; invoice.Hold = false; docgraph.Document.Update(invoice); docgraph.Save.Press(); claim.Status = EPClaimStatus.Released; claim.Released = true; claim.APRefNbr = invoice.RefNbr; claim.APDocType = invoice.DocType; expenseclaim.ExpenseClaim.Update(claim); #region EP History Update EPHistory hist = new EPHistory(); hist.EmployeeID = invoice.VendorID; hist.FinPeriodID = invoice.FinPeriodID; hist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(hist); hist.FinPtdClaimed += invoice.DocBal; hist.FinYtdClaimed += invoice.DocBal; if (invoice.FinPeriodID == invoice.TranPeriodID) { hist.TranPtdClaimed += invoice.DocBal; hist.TranYtdClaimed += invoice.DocBal; } else { EPHistory tranhist = new EPHistory(); tranhist.EmployeeID = invoice.VendorID; tranhist.FinPeriodID = invoice.TranPeriodID; tranhist = (EPHistory)expenseclaim.Caches[typeof(EPHistory)].Insert(tranhist); tranhist.TranPtdClaimed += invoice.DocBal; tranhist.TranYtdClaimed += invoice.DocBal; } expenseclaim.Views.Caches.Add(typeof(EPHistory)); #endregion expenseclaim.Save.Press(); ts.Complete(); } } if ((bool)epsetup.AutomaticReleaseAP == true) { List <APRegister> doclist = new List <APRegister>(); doclist.Add(docgraph.Document.Current); APDocumentRelease.ReleaseDoc(doclist, false); } }
protected virtual void InsertARTran(ARInvoiceEntry arGraph, EPExpenseClaimDetails row, decimal signOperation, decimal tipQty = 1m, bool isTipTransaction = false) { CurrencyInfo curyInfo = PXSelect <CurrencyInfo> .Search <CurrencyInfo.curyInfoID>(arGraph, row.CuryInfoID); EPSetup epsetup = PXSelectReadonly <EPSetup> .Select(arGraph); ARTran tran = arGraph.Transactions.Insert(); if (isTipTransaction) { IN.InventoryItem tipItem = PXSelect <IN.InventoryItem, Where <IN.InventoryItem.inventoryID, Equal <Required <IN.InventoryItem.inventoryID> > > > .Select(arGraph, epsetup.NonTaxableTipItem); tran.InventoryID = epsetup.NonTaxableTipItem; tran.Qty = tipQty; tran.UOM = tipItem.BaseUnit; tran.TranDesc = tipItem.Descr; SetAmount(arGraph, row.CuryTipAmt, row.TipAmt, tipQty, signOperation, curyInfo, tran); tran = arGraph.Transactions.Update(tran); if (epsetup.UseReceiptAccountForTips == true) { tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; } else { Location companyloc = (Location)PXSelectJoin <Location, InnerJoin <BAccountR, On <Location.bAccountID, Equal <BAccountR.bAccountID>, And <Location.locationID, Equal <BAccountR.defLocationID> > >, InnerJoin <GL.Branch, On <BAccountR.bAccountID, Equal <GL.Branch.bAccountID> > > >, Where <GL.Branch.branchID, Equal <Current <ARTran.branchID> > > > .Select(arGraph); Contract contract = PXSelect <Contract, Where <Contract.contractID, Equal <Required <Contract.contractID> > > > .Select(this, row.ContractID); PMTask task = PXSelect <PMTask, Where <PMTask.projectID, Equal <Required <PMTask.projectID> >, And <PMTask.taskID, Equal <Required <PMTask.taskID> > > > > .Select(arGraph, row.ContractID, row.TaskID); EPEmployee employee = (EPEmployee)PXSelect <EPEmployee> .Search <EPEmployee.bAccountID>(this, row != null?row.EmployeeID : null); Location customerLocation = (Location)PXSelectorAttribute.Select <EPExpenseClaimDetails.customerLocationID>(arGraph.Caches[typeof(EPExpenseClaimDetails)], row); int?employee_SubID = (int?)arGraph.Caches[typeof(EPEmployee)].GetValue <EPEmployee.salesSubID>(employee); int?item_SubID = (int?)arGraph.Caches[typeof(IN.InventoryItem)].GetValue <IN.InventoryItem.salesSubID>(tipItem); int?company_SubID = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(companyloc); int?project_SubID = (int?)arGraph.Caches[typeof(Contract)].GetValue <Contract.defaultSubID>(contract); int?task_SubID = (int?)arGraph.Caches[typeof(PMTask)].GetValue <PMTask.defaultSubID>(task); int?location_SubID = (int?)arGraph.Caches[typeof(Location)].GetValue <Location.cSalesSubID>(customerLocation); object value = SubAccountMaskAttribute.MakeSub <EPSetup.salesSubMask>(arGraph, epsetup.SalesSubMask, new object[] { employee_SubID, item_SubID, company_SubID, project_SubID, task_SubID, location_SubID }, new Type[] { typeof(EPEmployee.salesSubID), typeof(IN.InventoryItem.salesSubID), typeof(Location.cSalesSubID), typeof(Contract.defaultSubID), typeof(PMTask.defaultSubID), typeof(Location.cSalesSubID) }); arGraph.Caches[typeof(ARTran)].RaiseFieldUpdating <ARTran.subID>(tran, ref value); tran.SubID = (int?)value; } } else { tran.InventoryID = row.InventoryID; tran.Qty = row.Qty * signOperation; tran.UOM = row.UOM; tran = arGraph.Transactions.Update(tran); tran.AccountID = row.SalesAccountID; tran.SubID = row.SalesSubID; tran.TranDesc = row.TranDesc; //For gross taxes we can't put tranAmt. So we should use taxable amount EPTaxTran firstLevelTaxTran = null; foreach (EPTaxTran taxRow in PXSelect <EPTaxTran, Where <EPTaxTran.claimDetailID, Equal <Required <EPTaxTran.claimDetailID> >, And <EPTaxTran.isTipTax, Equal <False> > > > .Select(this, row.ClaimDetailID)) { if (firstLevelTaxTran == null || Math.Abs(firstLevelTaxTran.CuryTaxableAmt ?? 0m) > Math.Abs(taxRow.CuryTaxableAmt ?? 0m)) { firstLevelTaxTran = taxRow; } } decimal?curyAmt = firstLevelTaxTran?.CuryTaxableAmt ?? row.CuryTaxableAmt; decimal?amt = firstLevelTaxTran?.TaxableAmt ?? row.TaxableAmt; SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran); tran = arGraph.Transactions.Update(tran); if (tran.CuryTaxableAmt != 0 && tran.CuryTaxableAmt != curyAmt) // indicates that we have gross/ iclusive taxes. In this case recalculation is required { curyAmt = row.CuryTaxableAmt; amt = row.TaxableAmt; SetAmount(arGraph, curyAmt, amt, row.Qty, signOperation, curyInfo, tran); } } tran.Date = row.ExpenseDate; tran.ManualPrice = true; tran = arGraph.Transactions.Update(tran); PXNoteAttribute.CopyNoteAndFiles(Caches[typeof(EPExpenseClaimDetails)], row, arGraph.Transactions.Cache, tran, Setup.Current.GetCopyNoteSettings <PXModule.ar>()); }
public virtual void CreateInvoice(PXGraph graphProcess, List <DocLineExt> docLines, List <DocLineExt> docLinesGrouped, short invtMult, DateTime?invoiceDate, string invoiceFinPeriodID, OnDocumentHeaderInsertedDelegate onDocumentHeaderInserted, OnTransactionInsertedDelegate onTransactionInserted, PXQuickProcess.ActionFlow quickProcessFlow) { if (docLines.Count == 0) { return; } FSServiceOrder fsServiceOrderRow = docLines[0].fsServiceOrder; FSSrvOrdType fsSrvOrdTypeRow = docLines[0].fsSrvOrdType; FSPostDoc fsPostDocRow = docLines[0].fsPostDoc; FSAppointment fsAppointmentRow = docLines[0].fsAppointment; PMRegister pmRegisterRow = new PMRegister(); pmRegisterRow.Module = BatchModule.PM; pmRegisterRow.Date = invoiceDate; pmRegisterRow.Description = fsAppointmentRow != null ? fsAppointmentRow.DocDesc : fsServiceOrderRow.DocDesc; pmRegisterRow.Status = PMRegister.status.Balanced; pmRegisterRow.OrigDocType = fsAppointmentRow != null ? PMOrigDocType.Appointment : PMOrigDocType.ServiceOrder; pmRegisterRow.OrigNoteID = fsAppointmentRow != null ? fsAppointmentRow.NoteID : fsServiceOrderRow.NoteID; pmRegisterRow = PXCache <PMRegister> .CreateCopy(Base.Document.Insert(pmRegisterRow)); IDocLine docLine = null; PMTask pmTaskRow = null; PMTran pmTranRow = null; foreach (DocLineExt docLineExt in docLinesGrouped) { docLine = docLineExt.docLine; fsPostDocRow = docLineExt.fsPostDoc; fsServiceOrderRow = docLineExt.fsServiceOrder; fsSrvOrdTypeRow = docLineExt.fsSrvOrdType; fsAppointmentRow = docLineExt.fsAppointment; pmTranRow = new PMTran(); pmTranRow.Date = invoiceDate; pmTranRow.BranchID = docLine.BranchID; pmTranRow = PXCache <PMTran> .CreateCopy(Base.Transactions.Insert(pmTranRow)); pmTaskRow = docLineExt.pmTask; if (pmTaskRow != null && pmTaskRow.Status == ProjectTaskStatus.Completed) { throw new PXException(TX.Error.POSTING_PMTASK_ALREADY_COMPLETED, fsServiceOrderRow.RefNbr, docLine.LineRef, pmTaskRow.TaskCD); } if (docLine.ProjectID != null) { pmTranRow.ProjectID = docLine.ProjectID; } if (docLine.ProjectID != null && docLine.ProjectTaskID != null) { pmTranRow.TaskID = docLine.ProjectTaskID; } pmTranRow.TranCuryID = fsAppointmentRow != null ? fsAppointmentRow.CuryID : fsServiceOrderRow.CuryID; pmTranRow.UOM = docLine.UOM; pmTranRow.BAccountID = fsServiceOrderRow.BillCustomerID; pmTranRow.Billable = true; pmTranRow.InventoryID = docLine.InventoryID; pmTranRow.CostCodeID = docLine.CostCodeID; pmTranRow.LocationID = fsServiceOrderRow.BillLocationID; pmTranRow.Qty = docLine.GetQty(FieldType.BillableField); pmTranRow.FinPeriodID = invoiceFinPeriodID; pmTranRow.TranCuryUnitRate = docLine.CuryUnitPrice * invtMult; pmTranRow.TranCuryAmount = docLine.GetTranAmt(FieldType.BillableField) * invtMult; pmTranRow.AccountGroupID = fsSrvOrdTypeRow.AccountGroupID; pmTranRow.Description = docLine.TranDesc; fsPostDocRow.DocLineRef = pmTranRow = Base.Transactions.Update(pmTranRow); } }