public virtual IEnumerable AddSSUser(PXAdapter adapter)
        {
            PMProject pmProjectRow = this.Base.Project.Current;

            ProjectEntry     projectEntryGraph = PXGraph.CreateInstance <ProjectEntry>();
            SmartsheetClient smartsheetClient  = CheckTokenSheetSS(projectEntryGraph, pmProjectRow);

            PXLongOperation.StartOperation(this.Base, delegate()
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    CreateEmployeesAcuUserSS(projectEntryGraph, smartsheetClient);
                    ts.Complete();
                }
                PXLongOperation.SetCustomInfo(this.Base);
            });
            return(adapter.Get());
        }
Esempio n. 2
0
        private bool SetButtonColor(bool x, int index, Button xButton)
        {
            bool result = true;


            //System.Threading.Thread.Sleep(2000);

            s = projectUse.ActiveProject;
            if (currentButton != null)
            {
                previousButton           = currentButton;
                previousButton.BackColor = Color.LightGreen;
            }
            currentButton           = xButton;
            currentButton.BackColor = Color.Red;
            Thread.Sleep(2000);
            return(result);
        }
Esempio n. 3
0
        private void Connect(bool x, int index, Button xButton)
        {
            if (x)
            {
                //Connect to Powermill instance
                projectUse = new PMAutomation(comList[index]);

                //Change the color of the button in use to red
                //And change the color of all other buttons to green
                SetButtonColor(x, index, xButton);

                //create project instance from instance
                session = projectUse.ActiveProject;

                int i = 0;
                //Add the name of the file to the text box
                setProjectLabel(x, index, xButton, i);
            }
        }
Esempio n. 4
0
        protected virtual IEnumerable SynGanttSmartsheetProject(PXAdapter adapter)
        {
            PMProject pmProjectRow = this.Base.Project.Current;

            this.Base.Actions.PressSave();
            PXLongOperation.StartOperation(this.Base,
                                           delegate()
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    ProjectEntry projectEntryGraph = PXGraph.CreateInstance <ProjectEntry>();
                    ProjectEntryExt graphExtended  = projectEntryGraph.GetExtension <ProjectEntryExt>();
                    graphExtended.CreateUpdateGanttProject(projectEntryGraph, pmProjectRow);

                    ts.Complete();
                }
            });

            return(adapter.Get());
        }
Esempio n. 5
0
        protected virtual void EPExpenseClaimDetails_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            EPExpenseClaimDetails row = e.Row as EPExpenseClaimDetails;

            if (row != null && row.CustomerID != null)
            {
                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 != project.CustomerID)
                    {
                        cache.RaiseExceptionHandling <EPExpenseClaimDetails.customerID>(e.Row, null,
                                                                                        new PXSetPropertyException(Messages.CustomerDoesNotMatchProject,
                                                                                                                   PXErrorLevel.Warning));
                    }
                }
                cache.SetDefaultExt <EPExpenseClaimDetails.customerLocationID>(e.Row);
            }
        }
        /// <summary>
        /// Unlinks the Acumatica project from a Smartsheet reference
        /// </summary>
        /// <param name="projectEntryGraph"></param>
        public void UnlinkSmartsheetProject(ProjectEntry projectEntryGraph)
        {
            PMProject pmProjectRow = projectEntryGraph.Project.Current;

            if (pmProjectRow != null)
            {
                PMProjectSSExt pmProjectExtRow = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

                pmProjectExtRow.UsrSmartsheetContractID = null;
                foreach (PMTask pmTaskRow in projectEntryGraph.Tasks.Select())
                {
                    PMTaskSSExt pmTaskRowExt = PXCache <PMTask> .GetExtension <PMTaskSSExt>(pmTaskRow);

                    pmTaskRowExt.UsrSmartsheetTaskID = null;
                    projectEntryGraph.Tasks.Cache.Update(pmTaskRow);
                }

                projectEntryGraph.Project.Cache.Update(pmProjectRow);
                projectEntryGraph.Persist();
            }
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        protected virtual void PMTimeActivity_ProjectID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            PMTimeActivity row = (PMTimeActivity)e.Row;

            if (row == null)
            {
                return;
            }

            if (e.NewValue != null && e.NewValue is int)
            {
                PMProject proj = PXSelect <PMProject> .Search <PMProject.contractID>(sender.Graph, e.NewValue);

                if (proj != null)
                {
                    if (proj.IsCompleted == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsCompleted);
                        ex.ErrorValue = proj.ContractCD;
                        throw ex;
                    }
                    if (proj.IsCancelled == true)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsCanceled);
                        ex.ErrorValue = proj.ContractCD;;
                        throw ex;
                    }
                    if (proj.Status == CT.Contract.status.Expired)
                    {
                        var ex = new PXSetPropertyException(PM.Messages.ProjectIsSuspended);
                        ex.ErrorValue = proj.ContractCD;;
                        throw ex;
                    }
                }
            }
        }
Esempio n. 9
0
        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));
                    }
                }
            }
        }
        private void InsertRecipientsFromTemplate(PMProject project, int?templateId)
        {
            var projectRecipients = CreateProjectRecipients(project, templateId);

            LienWaiverRecipients.Cache.InsertAll(projectRecipients);
        }
        /// <summary>
        /// Verifies the connection Token and the existence of the Sheet
        /// </summary>
        /// <param name="projectEntryGraph">Project's Graph</param>
        /// <param name="pmProjectRow">Current PMProject row</param>
        /// <param name="refreshedToken">Existing token</param>
        /// <param name="isMassProcess">Indicates if it's used in a processing page</param>
        /// <returns></returns>
        public SmartsheetClient CheckTokenSheetSS(ProjectEntry projectEntryGraph, PMProject pmProjectRow, string refreshedToken = "", bool isMassProcess = false)
        {
            //Primary Data View is set
            projectEntryGraph.Project.Current = pmProjectRow;

            SmartsheetHelper smartSheetHelperObject = new SmartsheetHelper();

            string sheetName = pmProjectRow.ContractCD.Trim() + " - " + pmProjectRow.Description.Trim();

            sheetName = smartSheetHelperObject.Left(sheetName, SmartsheetConstants.SSConstants.SS_PROJECT_NAME_LENGTH);

            PMSetup      setupRecord  = projectEntryGraph.Setup.Select();
            PMSetupSSExt pmSetupSSExt = PXCache <PMSetup> .GetExtension <PMSetupSSExt>(setupRecord);

            PMProjectSSExt pmProjectSSExt = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

            Users userRecord = PXSelect <
                Users,
                Where <Users.pKID, Equal <Required <AccessInfo.userID> > > >
                               .Select(projectEntryGraph, projectEntryGraph.Accessinfo.UserID);

            UsersSSExt userRecordSSExt = PXCache <Users> .GetExtension <UsersSSExt>(userRecord);

            smartSheetHelperObject.SetupValidation(userRecordSSExt, pmSetupSSExt);
            smartSheetHelperObject.ProjectValidation(projectEntryGraph);

            Token token = new Token();

            token.AccessToken = (String.IsNullOrEmpty(refreshedToken)) ? userRecordSSExt.UsrSmartsheetToken : refreshedToken;

            try
            {
                SmartsheetClient smartsheetClient = new SmartsheetBuilder()
                                                    .SetAccessToken(token.AccessToken)
                                                    .SetDateTimeFixOptOut(true)
                                                    .Build();

                long?sheetSelected;
                Dictionary <string, long> currentColumnMap = new Dictionary <string, long>();

                if (pmProjectSSExt != null &&
                    pmProjectSSExt.UsrSmartsheetContractID != null)        //Acumatica Project is already linked to SS
                {
                    sheetSelected = pmProjectSSExt.UsrSmartsheetContractID;

                    Sheet ssProjectSheet = smartsheetClient.SheetResources.GetSheet((long)sheetSelected, null, null, null, null, null, null, null);
                }

                return(smartsheetClient);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains(SmartsheetConstants.SSConstants.EXPIRED_TOKEN_MESSAGE))
                {
                    MyProfileMaint    profileMaintGraph = PXGraph.CreateInstance <MyProfileMaint>();
                    MyProfileMaintExt graphExtended     = profileMaintGraph.GetExtension <MyProfileMaintExt>();
                    string            updatedToken      = graphExtended.RefreshSmartsheetToken();
                    CheckTokenSheetSS(projectEntryGraph, pmProjectRow, updatedToken);
                }

                if (ex.Message.Contains(SmartsheetConstants.SSConstants.NOTFOUND_PROJECT_MESSAGE))
                {
                    if (isMassProcess)
                    {
                        SmartsheetClient smartsheetClient = new SmartsheetBuilder()
                                                            .SetAccessToken(token.AccessToken)
                                                            .SetDateTimeFixOptOut(true)
                                                            .Build();
                        UnlinkSmartsheetProject(projectEntryGraph);
                        CreateUpdateGanttProject(projectEntryGraph, pmProjectRow, smartsheetClient, true);
                    }
                    else
                    {
                        UnlinkSmartsheetProject(projectEntryGraph);
                        throw new PXException(SmartsheetConstants.Messages.UNLINK_PROJECT);
                    }
                }
                else
                {
                    throw new PXException(ex.Message);
                }

                return(null);
            }
        }
        /// <summary>
        /// Creates or updates the Smartsheet project with information from Acumatica.
        /// New Tasks created in Smartsheet will be updated back in Acumatica
        /// </summary>
        /// <param name="projectEntryGraph">Project Entry graph</param>
        /// <param name="pmProjectRow">PMProject record</param>
        /// <param name="smartsheetClient">Smartsheet's SDK Client</param>
        /// <param name="isMassProcess">Indicates if it's used in a processing page</param>
        public void CreateUpdateGanttProject(ProjectEntry projectEntryGraph, PMProject pmProjectRow, SmartsheetClient smartsheetClient, bool isMassProcess = false)
        {
            //Primary Data View is set
            projectEntryGraph.Project.Current = pmProjectRow;
            PMProjectSSExt pmProjectSSExt = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

            PMSetup      setupRecord  = projectEntryGraph.Setup.Select();
            PMSetupSSExt pmSetupSSExt = PXCache <PMSetup> .GetExtension <PMSetupSSExt>(setupRecord);

            SmartsheetHelper smartSheetHelperObject = new SmartsheetHelper();

            if (String.IsNullOrEmpty(pmProjectSSExt.UsrTemplateSS))
            {
                throw new PXException(SmartsheetConstants.Messages.DEFAULT_TEMPLATE);
            }

            string sheetName = pmProjectRow.ContractCD.Trim() + " - " + pmProjectRow.Description.Trim();

            sheetName = smartSheetHelperObject.Left(sheetName, SmartsheetConstants.SSConstants.SS_PROJECT_NAME_LENGTH);

            try
            {
                long?sheetSelected;
                Dictionary <string, long> currentColumnMap = new Dictionary <string, long>();

                //////////////////
                //Information from Acumatica is updated in Smartsheet
                //////////////////

                PXResultset <PMSSMapping> templateMappingSet = PXSelect <
                    PMSSMapping,
                    Where <PMSSMapping.templateSS, Equal <Required <PMSSMapping.templateSS> > > >
                                                               .Select(projectEntryGraph, pmProjectSSExt.UsrTemplateSS);

                if (pmProjectSSExt != null &&
                    pmProjectSSExt.UsrSmartsheetContractID != null)        //Acumatica Project is already linked to SS
                {
                    sheetSelected = pmProjectSSExt.UsrSmartsheetContractID;

                    Sheet ssProjectSheet = smartsheetClient.SheetResources.GetSheet((long)sheetSelected, null, null, null, null, null, null, null);

                    //Columns ID Mapping
                    currentColumnMap = new Dictionary <string, long>();
                    foreach (Column currentColumn in ssProjectSheet.Columns)
                    {
                        currentColumnMap.Add(currentColumn.Title, (long)currentColumn.Id);
                    }

                    smartSheetHelperObject.UpdateSSProject(smartsheetClient, currentColumnMap, projectEntryGraph, sheetSelected, smartSheetHelperObject, templateMappingSet);
                }
                else //Acumatica Project has not been linked to Smartsheet
                {
                    //Sheet is created from a the template selected in the Project
                    Sheet sheet = new Sheet.CreateSheetFromTemplateBuilder(sheetName, Convert.ToInt64(pmProjectSSExt.UsrTemplateSS)).Build();
                    sheet = smartsheetClient.SheetResources.CreateSheet(sheet);

                    Sheet newlyCreatedSheet = smartsheetClient.SheetResources.GetSheet((long)sheet.Id, null, null, null, null, null, null, null);

                    currentColumnMap = new Dictionary <string, long>();
                    foreach (Column currentColumn in newlyCreatedSheet.Columns)
                    {
                        currentColumnMap.Add(currentColumn.Title, (long)currentColumn.Id);
                    }

                    //Acumatica Tasks are added as Smartsheet rows
                    List <Row>  newSSRows = smartSheetHelperObject.InsertAcumaticaTasksInSS(projectEntryGraph, currentColumnMap, null, true, templateMappingSet);
                    IList <Row> ssRows    = smartsheetClient.SheetResources.RowResources.AddRows((long)sheet.Id, newSSRows);

                    int ssTaskIDPosition = 0;
                    if (ssRows.Count > 0 && ssRows[0].Cells != null)
                    {
                        PMSSMapping mappingSS = templateMappingSet.Where(t => ((PMSSMapping)t).NameAcu.Trim().ToUpper() == SmartsheetConstants.ColumnMapping.TASKS_CD.Trim().ToUpper()).FirstOrDefault();

                        ssTaskIDPosition = smartSheetHelperObject.GetSSTaskPosition(ssRows[0].Cells, currentColumnMap[mappingSS.NameSS]);
                    }

                    // Add SubTasks
                    smartSheetHelperObject.InsertAcumaticaSubTasks(projectEntryGraph, smartsheetClient, sheet, ssRows, smartSheetHelperObject, currentColumnMap, ssTaskIDPosition, templateMappingSet);

                    foreach (Row currentRow in ssRows)
                    {
                        foreach (PMTask rowTask in projectEntryGraph.Tasks.Select())
                        {
                            if (currentRow.Cells[ssTaskIDPosition].Value != null &&
                                rowTask.TaskCD != null &&
                                string.Equals(currentRow.Cells[ssTaskIDPosition].Value.ToString().Trim(), rowTask.TaskCD.Trim(), StringComparison.OrdinalIgnoreCase))
                            {
                                PMTaskSSExt pmTaskSSExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(rowTask);

                                pmTaskSSExtRow.UsrSmartsheetTaskID = currentRow.Id;
                                projectEntryGraph.Tasks.Update(rowTask);
                                break;
                            }
                        }
                    }

                    sheetSelected = (long)sheet.Id;

                    PMProjectSSExt pmProjectSSExtRow = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

                    pmProjectSSExtRow.UsrSmartsheetContractID = sheetSelected;
                    projectEntryGraph.Project.Update(pmProjectRow);
                }


                //////////////////
                //Information from Smartsheet is updated in Acumatica
                //////////////////
                Sheet updatedSheet = smartsheetClient.SheetResources.GetSheet((long)sheetSelected, null, null, null, null, null, null, null);

                int columnPosition = 0;
                Dictionary <string, int> columnPositionMap = new Dictionary <string, int>();
                foreach (Column currentColumn in updatedSheet.Columns)
                {
                    columnPositionMap.Add(currentColumn.Title, columnPosition);
                    columnPosition += 1;
                }

                smartSheetHelperObject.UpdateAcumaticaTasks(projectEntryGraph, pmProjectRow, pmSetupSSExt, updatedSheet, columnPositionMap, templateMappingSet);

                projectEntryGraph.Actions.PressSave();

                if (isMassProcess)
                {
                    PXProcessing.SetInfo(String.Format(SmartsheetConstants.Messages.SUCCESSFULLY_SYNCED, pmProjectRow.ContractCD));
                }
            }
            catch (Exception e)
            {
                throw new PXException(e.Message);
            }
        }
        protected virtual void INLocation_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            var row = (INLocation)e.Row;

            if (row == null)
            {
                return;
            }

            if ((e.Operation & PXDBOperation.Command) != PXDBOperation.Delete && row.ProjectID != null && row.TaskID == null && row.Active == true)
            {
                INLocation anotherWildcardLocation =
                    PXSelect <INLocation,
                              Where <INLocation.locationID, NotEqual <Required <INLocation.locationID> >,
                                     And <INLocation.projectID, Equal <Required <INLocation.projectID> >,
                                          And <INLocation.taskID, IsNull,
                                               And <INLocation.active, Equal <True> > > > > >
                    .Select(this, row.LocationID, row.ProjectID);

                if (anotherWildcardLocation != null)
                {
                    PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID);

                    INSite warehouse = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(this, anotherWildcardLocation.SiteID);

                    if (sender.RaiseExceptionHandling <INLocation.projectID>(e.Row, project.ContractCD, new PXSetPropertyException(Messages.ProjectWildcardLocationIsUsedIn, PXErrorLevel.Error, warehouse.SiteCD, anotherWildcardLocation.LocationCD)))
                    {
                        throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.projectID>(), row.ProjectID, Messages.ProjectWildcardLocationIsUsedIn, warehouse.SiteCD, anotherWildcardLocation.LocationCD);
                    }
                }
            }
            if ((e.Operation & PXDBOperation.Command) == PXDBOperation.Delete)
            {
                INItemSite itemSite =
                    PXSelect <INItemSite,
                              Where <INItemSite.siteID, Equal <Current <INSite.siteID> >,
                                     And <Where <
                                              INItemSite.dfltReceiptLocationID, Equal <Required <INItemSite.dfltReceiptLocationID> >,
                                              Or <INItemSite.dfltShipLocationID, Equal <Required <INItemSite.dfltShipLocationID> > > > > > >
                    .Select(this, row.LocationID, row.LocationID);

                if (itemSite != null)
                {
                    InventoryItem initem = PXSelect <InventoryItem, Where <InventoryItem.inventoryID, Equal <Required <InventoryItem.inventoryID> > > > .Select(this, itemSite.InventoryID) ?? new InventoryItem();

                    if (sender.RaiseExceptionHandling <INLocation.locationID>(e.Row, row.LocationCD, new PXSetPropertyException(Messages.LocationInUseInItemWarehouseDetails, PXErrorLevel.Error, row.LocationCD.TrimEnd(), initem.InventoryCD.TrimEnd())))
                    {
                        throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.locationID>(), row.LocationID, Messages.LocationInUseInItemWarehouseDetails, row.LocationCD.TrimEnd(), initem.InventoryCD.TrimEnd());
                    }
                }

                INPIClassLocation piLocation =
                    PXSelectJoin <INPIClassLocation,
                                  InnerJoin <INPIClass, On <INPIClass.pIClassID, Equal <INPIClassLocation.pIClassID> > >,
                                  Where <INPIClass.siteID, Equal <Current <INSite.siteID> >,
                                         And <INPIClassLocation.locationID, Equal <Required <INPIClassLocation.locationID> > > > >
                    .Select(this, row.LocationID);

                if (piLocation != null)
                {
                    if (sender.RaiseExceptionHandling <INLocation.locationID>(e.Row, row.LocationCD, new PXSetPropertyException(Messages.LocationInUseInPIType, PXErrorLevel.Error, row.LocationCD.TrimEnd(), piLocation.PIClassID.TrimEnd())))
                    {
                        throw new PXRowPersistingException(PXDataUtils.FieldName <INLocation.locationID>(), row.LocationID, Messages.LocationInUseInPIType, row.LocationCD.TrimEnd(), piLocation.PIClassID.TrimEnd());
                    }
                }
            }
        }
Esempio n. 14
0
        private bool IsItemLevel(PMProject project)
        {
            var result = project.CostBudgetLevel == BudgetLevels.Item || project.CostBudgetLevel == BudgetLevels.Detail;

            return(result);
        }
Esempio n. 15
0
        /// <summary>
        /// Creates or updates the Smartsheet project with information from Acumatica.
        /// New Tasks created in Smartsheet will be updated back in Acumatica
        /// </summary>
        /// <param name="projectEntryGraph">Project Entry graph</param>
        /// <param name="pmProjectRow">PMProject record</param>
        /// <param name="isMassProcess">Indicates if it's used in a processing page</param>
        public void CreateUpdateGanttProject(ProjectEntry projectEntryGraph, PMProject pmProjectRow, string refreshedToken = "", bool isMassProcess = false)
        {
            //Primary Data View is set
            projectEntryGraph.Project.Current = pmProjectRow;

            SmartsheetHelper smartSheetHelperObject = new SmartsheetHelper();

            string sheetName = pmProjectRow.ContractCD.Trim() + " - " + pmProjectRow.Description.Trim();

            sheetName = smartSheetHelperObject.Left(sheetName, SmartsheetConstants.SSConstants.SS_PROJECT_NAME_LENGTH);

            PMSetup      setupRecord  = projectEntryGraph.Setup.Select();
            PMSetupSSExt pmSetupSSExt = PXCache <PMSetup> .GetExtension <PMSetupSSExt>(setupRecord);

            PMProjectSSExt pmProjectSSExt = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

            Users userRecord = PXSelect <Users, Where <Users.pKID, Equal <Current <AccessInfo.userID> > > > .Select(projectEntryGraph);

            UsersSSExt userRecordSSExt = PXCache <Users> .GetExtension <UsersSSExt>(userRecord);

            smartSheetHelperObject.SetupValidation(userRecordSSExt, pmSetupSSExt);
            smartSheetHelperObject.ProjectValidation(projectEntryGraph);

            try
            {
                Token token = new Token();

                token.AccessToken = (String.IsNullOrEmpty(refreshedToken)) ? userRecordSSExt.UsrSmartsheetToken : refreshedToken;

                SmartsheetClient smartsheetClient = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build();

                long?sheetSelected;
                Dictionary <string, long> currentColumnMap = new Dictionary <string, long>();

                //////////////////
                //Information from Acumatica is updated in Smartsheet
                //////////////////
                if (pmProjectSSExt != null &&
                    pmProjectSSExt.UsrSmartsheetContractID != null)        //Acumatica Project is already linked to SS
                {
                    sheetSelected = pmProjectSSExt.UsrSmartsheetContractID;

                    Sheet ssProjectSheet = smartsheetClient.SheetResources.GetSheet((long)sheetSelected, null, null, null, null, null, null, null);

                    //Columns ID Mapping
                    currentColumnMap = new Dictionary <string, long>();
                    foreach (Column currentColumn in ssProjectSheet.Columns)
                    {
                        currentColumnMap.Add(currentColumn.Title, (long)currentColumn.Id);
                    }

                    smartSheetHelperObject.UpdateSSProject(smartsheetClient, currentColumnMap, projectEntryGraph, sheetSelected, smartSheetHelperObject);
                }
                else //Acumatica Project has not been linked to Smartsheet
                {
                    //Sheet is created from a Gantt Template available in SmartSheet
                    Sheet sheet = new Sheet.CreateSheetFromTemplateBuilder(sheetName, SmartsheetConstants.SSConstants.BASIC_SS_PROJECT_WITH_GANTT).Build();
                    sheet = smartsheetClient.SheetResources.CreateSheet(sheet);

                    Sheet newlyCreatedSheet = smartsheetClient.SheetResources.GetSheet((long)sheet.Id, null, null, null, null, null, null, null);

                    currentColumnMap = new Dictionary <string, long>();
                    foreach (Column currentColumn in newlyCreatedSheet.Columns)
                    {
                        currentColumnMap.Add(currentColumn.Title, (long)currentColumn.Id);
                    }

                    smartSheetHelperObject.AdjustGanttSheet(smartsheetClient, sheet, currentColumnMap);

                    //Acumatica Tasks are added as Smartsheet rows
                    List <Row>  newSSRows = smartSheetHelperObject.InsertAcumaticaTasksInSS(projectEntryGraph, currentColumnMap, null, true);
                    IList <Row> ssRows    = smartsheetClient.SheetResources.RowResources.AddRows((long)sheet.Id, newSSRows);

                    int ssTaskIDPosition = 0;
                    if (ssRows.Count > 0 && ssRows[0].Cells != null)
                    {
                        ssTaskIDPosition = smartSheetHelperObject.GetSSTaskPosition(ssRows[0].Cells, currentColumnMap[SmartsheetConstants.GanttTemplateMapping.TASK_NAME]);
                    }

                    smartSheetHelperObject.InsertAcumaticaSubTasks(projectEntryGraph, smartsheetClient, sheet, ssRows, smartSheetHelperObject, currentColumnMap, ssTaskIDPosition);

                    foreach (Row currentRow in ssRows)
                    {
                        foreach (PMTask rowTask in projectEntryGraph.Tasks.Select())
                        {
                            if (currentRow.Cells[ssTaskIDPosition].Value != null &&
                                rowTask.TaskCD != null &&
                                string.Equals(currentRow.Cells[ssTaskIDPosition].Value.ToString().Trim(), rowTask.TaskCD.Trim(), StringComparison.OrdinalIgnoreCase))
                            {
                                PMTaskSSExt pmTaskSSExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(rowTask);

                                pmTaskSSExtRow.UsrSmartsheetTaskID = currentRow.Id;
                                projectEntryGraph.Tasks.Update(rowTask);
                                break;
                            }
                        }
                    }

                    sheetSelected = (long)sheet.Id;

                    PMProjectSSExt pmProjectSSExtRow = PXCache <PMProject> .GetExtension <PMProjectSSExt>(pmProjectRow);

                    pmProjectSSExtRow.UsrSmartsheetContractID = sheetSelected;
                    projectEntryGraph.Project.Update(pmProjectRow);
                }


                //////////////////
                //Information from Smartsheet is updated in Acumatica
                //////////////////
                Sheet updatedSheet = smartsheetClient.SheetResources.GetSheet((long)sheetSelected, null, null, null, null, null, null, null);

                int columnPosition = 0;
                Dictionary <string, int> columnPositionMap = new Dictionary <string, int>();
                foreach (Column currentColumn in updatedSheet.Columns)
                {
                    columnPositionMap.Add(currentColumn.Title, columnPosition);
                    columnPosition += 1;
                }

                smartSheetHelperObject.UpdateAcumaticaTasks(projectEntryGraph, pmProjectRow, pmSetupSSExt, updatedSheet, columnPositionMap);

                projectEntryGraph.Actions.PressSave();

                if (isMassProcess)
                {
                    PXProcessing.SetInfo(String.Format(SmartsheetConstants.Messages.SUCCESSFULLY_SYNCED, pmProjectRow.ContractCD));
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains(SmartsheetConstants.SSConstants.EXPIRED_TOKEN_MESSAGE))
                {
                    MyProfileMaint    profileMaintGraph = PXGraph.CreateInstance <MyProfileMaint>();
                    MyProfileMaintExt graphExtended     = profileMaintGraph.GetExtension <MyProfileMaintExt>();
                    string            updatedToken      = graphExtended.RefreshSmartsheetToken();
                    CreateUpdateGanttProject(projectEntryGraph, pmProjectRow, updatedToken, isMassProcess = false);
                }
                else
                {
                    throw new PXException(e.Message);
                }
            }
        }
Esempio n. 16
0
        private object CalculateAndExpandValue(bool drilldown, RMDataSource ds, RMDataSourceGL dsGL, RMDataSourcePM dsPM, ARmDataSet dataSet, List <PMAccountGroup> accountGroups, List <PMProject> projects, List <PMTask> tasks, List <InventoryItem> items, List <object[]> splitret)
        {
            decimal totalAmount = 0;
            object  locker      = new object();
            Dictionary <PMHistoryKeyTuple, PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> > drilldownData = null;

            if (drilldown)
            {
                drilldownData = new Dictionary <PMHistoryKeyTuple, PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> >();
            }

            Parallel.For(0, accountGroups.Count, accountGroup =>
            {
                PMAccountGroup currentAccountGroup = accountGroups[accountGroup];
                if (!_historySegments.Contains(new PMHistoryKeyTuple(0, String.Empty, currentAccountGroup.GroupID.Value, 0)))
                {
                    return;
                }

                Parallel.For(0, projects.Count, project =>
                {
                    PMProject currentProject = projects[project];
                    if (!_historySegments.Contains(new PMHistoryKeyTuple(currentProject.ContractID.Value, String.Empty, currentAccountGroup.GroupID.Value, 0)))
                    {
                        return;
                    }

                    Parallel.For(0, tasks.Count, task =>
                    {
                        PMTask currentTask = tasks[task];
                        if (!_historySegments.Contains(new PMHistoryKeyTuple(currentProject.ContractID.Value, currentTask.TaskCD, currentAccountGroup.GroupID.Value, 0)))
                        {
                            return;
                        }
                        if (ds.Expand != ExpandType.ProjectTask && currentTask.ProjectID != currentProject.ContractID)
                        {
                            return;
                        }

                        Parallel.For(0, items.Count, item =>
                        {
                            InventoryItem currentItem = items[item];
                            List <PMHistory> periods  = GetPeriodsToCalculate(currentProject, currentTask, currentAccountGroup, currentItem, ds, dsGL);
                            if (periods == null)
                            {
                                return;
                            }

                            foreach (var hist in periods)
                            {
                                decimal amount = GetAmountFromPMHistory(ds, hist);
                                lock (locker)
                                {
                                    totalAmount += amount;
                                }

                                if (drilldown)
                                {
                                    var key = new PMHistoryKeyTuple(currentProject.ContractID.Value, currentTask.TaskCD, currentAccountGroup.GroupID.Value, currentItem.InventoryID.Value);
                                    PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem> drilldownRow = null;

                                    lock (drilldownData)
                                    {
                                        if (!drilldownData.TryGetValue(key, out drilldownRow))
                                        {
                                            drilldownRow = new PXResult <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem>(new PMHistory(), currentProject, currentTask, currentAccountGroup, currentItem);
                                            drilldownData.Add(key, drilldownRow);
                                        }
                                    }

                                    lock (drilldownRow)
                                    {
                                        AggregatePMHistoryForDrilldown(drilldownRow, hist);
                                    }
                                }

                                if (ds.Expand == ExpandType.AccountGroup)
                                {
                                    lock (currentAccountGroup)
                                    {
                                        splitret[accountGroup][2] = (decimal)splitret[accountGroup][2] + amount;
                                        if (splitret[accountGroup][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartAccountGroup] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndAccountGroup] = currentAccountGroup.GroupCD;
                                            splitret[accountGroup][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.Project)
                                {
                                    lock (currentProject)
                                    {
                                        splitret[project][2] = (decimal)splitret[project][2] + amount;
                                        if (splitret[project][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartProject] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndProject] = currentProject.ContractCD;
                                            splitret[project][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.ProjectTask)
                                {
                                    lock (currentItem)
                                    {
                                        splitret[task][2] = (decimal)splitret[task][2] + amount;
                                        if (splitret[task][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartProjectTask] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndProjectTask] = currentTask.TaskCD;
                                            splitret[task][3] = dataSetCopy;
                                        }
                                    }
                                }
                                else if (ds.Expand == ExpandType.Inventory)
                                {
                                    lock (currentItem)
                                    {
                                        splitret[item][2] = (decimal)splitret[item][2] + amount;
                                        if (splitret[item][3] == null)
                                        {
                                            var dataSetCopy = new ARmDataSet(dataSet);
                                            dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.StartInventory] = dataSetCopy[PX.Objects.CS.RMReportReaderPM.Keys.EndInventory] = currentItem.InventoryCD;
                                            splitret[item][3] = dataSetCopy;
                                        }
                                    }
                                }
                            }
                        });
                    });
                });
            });

            if (drilldown)
            {
                var resultset = new PXResultset <PMHistory, PMProject, PMTask, PMAccountGroup, InventoryItem>();
                foreach (var r in
                         from row in drilldownData.Values
                         let projectCD = ((PMProject)row[typeof(PMProject)]).With(_ => _.ContractCD)
                                         let taskCD = ((PMTask)row[typeof(Sub)]).With(_ => _.TaskCD)
                                                      let accGroupCD = ((PMAccountGroup)row[typeof(PMAccountGroup)]).With(_ => _.GroupCD)
                                                                       let inventoryCD = ((InventoryItem)row[typeof(InventoryItem)]).With(_ => _.InventoryCD)
                                                                                         orderby projectCD, taskCD, accGroupCD, inventoryCD
                         select row)
                {
                    resultset.Add(r);
                }
                return(resultset);
            }
            else if (ds.Expand != ExpandType.Nothing)
            {
                return(splitret);
            }
            else
            {
                return(totalAmount);
            }
        }
Esempio n. 17
0
 private void FillProjectInfo(ComplianceDocument complianceDocument, PMProject project)
 {
     complianceDocument.ProjectID    = project.ContractID;
     complianceDocument.CustomerID   = project.CustomerID;
     complianceDocument.CustomerName = GetCustomerName(complianceDocument.CustomerID);
 }
Esempio n. 18
0
        protected virtual void INLocation_ProjectID_FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
        {
            ///TODO: Redo this using Plans and Status tables once we have them in version 7.0

            INLocation row = e.Row as INLocation;

            if (row == null)
            {
                return;
            }

            PO.POReceiptLine unreleasedPO = PXSelect <PO.POReceiptLine,
                                                      Where <PO.POReceiptLine.projectID, Equal <Required <PO.POReceiptLine.projectID> >,
                                                             And <PO.POReceiptLine.released, Equal <False>,
                                                                  And <PO.POReceiptLine.locationID, Equal <Required <INLocation.locationID> > > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.LocationID);

            if (unreleasedPO != null)
            {
                PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID ?? e.NewValue);

                if (project != null)
                {
                    e.NewValue = project.ContractCD;
                }

                throw new PXSetPropertyException(Messages.ProjectUsedInPO);
            }

            SO.SOShipLine unreleasedSO = PXSelect <SO.SOShipLine,
                                                   Where <SO.SOShipLine.projectID, Equal <Required <SO.SOShipLine.projectID> >,
                                                          And <SO.SOShipLine.released, Equal <False>,
                                                               And <SO.SOShipLine.locationID, Equal <Required <INLocation.locationID> > > > > > .SelectWindowed(this, 0, 1, row.ProjectID, row.LocationID);

            if (unreleasedSO != null)
            {
                PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID ?? e.NewValue);

                if (project != null)
                {
                    e.NewValue = project.ContractCD;
                }

                throw new PXSetPropertyException(Messages.ProjectUsedInSO);
            }

            INLocationStatus locationStatus = PXSelect <INLocationStatus, Where <INLocationStatus.siteID, Equal <Required <INLocationStatus.siteID> >,
                                                                                 And <INLocationStatus.locationID, Equal <Required <INLocationStatus.locationID> >,
                                                                                      And <INLocationStatus.qtyOnHand, NotEqual <decimal0> > > > > .SelectWindowed(this, 0, 1, row.SiteID, row.LocationID);

            if (locationStatus != null)
            {
                PMProject project = PXSelect <PMProject, Where <PMProject.contractID, Equal <Required <PMProject.contractID> > > > .Select(this, row.ProjectID ?? e.NewValue);

                if (project != null)
                {
                    e.NewValue = project.ContractCD;
                }

                throw new PXSetPropertyException(Messages.ProjectUsedInIN);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Creates/Updates Acumatica Tasks with the Smartsheet modifications
        /// </summary>
        /// <param name="projectEntryGraph"></param>
        /// <param name="pmProjectRow"></param>
        /// <param name="pmSetupSSExt"></param>
        /// <param name="updatedSheet"></param>
        /// <param name="columnPositionMap"></param>
        public void UpdateAcumaticaTasks(ProjectEntry projectEntryGraph,
                                         PMProject pmProjectRow,
                                         PMSetupSSExt pmSetupSSExt,
                                         Sheet updatedSheet,
                                         Dictionary <string, int> columnPositionMap,
                                         PXResultset <PMSSMapping> templateMappingSet)
        {
            bool recordedInAcumatica   = false;
            int  primaryColumnPosition = 0;

            PMTask pmTaskNewEntry = new PMTask();

            foreach (Column updatedColumn in updatedSheet.Columns)
            {
                if (updatedColumn != null &&
                    updatedColumn.Primary != null &&
                    updatedColumn.Primary == true)
                {
                    foreach (Row updatedSSRow in updatedSheet.Rows)
                    {
                        if (updatedSSRow != null &&
                            updatedSSRow.ParentId != null)     //Subtasks are not synced back to Acumatica
                        {
                            continue;
                        }

                        PMTask      currentTaskRow = null;
                        PMTaskSSExt pmTaskSSExtRow = null;

                        foreach (PMTask taskRow in projectEntryGraph.Tasks.Select())
                        {
                            recordedInAcumatica = false;
                            pmTaskSSExtRow      = PXCache <PMTask> .GetExtension <PMTaskSSExt>(taskRow);

                            if (pmTaskSSExtRow != null &&
                                pmTaskSSExtRow.UsrSmartsheetTaskID == updatedSSRow.Id)
                            {
                                recordedInAcumatica = true;
                                currentTaskRow      = taskRow;
                                break;
                            }
                        }

                        if (recordedInAcumatica == false) //New Row in Smartsheet not yet added to Acumatica
                        {
                            //Fields retrieved: Task, Description, Start Date, End Date, % Complete,
                            if (updatedSSRow.Cells[primaryColumnPosition].Value != null)
                            {
                                pmTaskNewEntry           = new PMTask();
                                pmTaskNewEntry.ProjectID = pmProjectRow.ContractID;
                                pmTaskNewEntry.TaskCD    = updatedSSRow.Cells[primaryColumnPosition].Value.ToString();

                                PMTask taskCDValidation = (PMTask)projectEntryGraph.Tasks.Select()
                                                          .Where(t => ((PMTask)t).TaskCD.Trim().ToUpper() == updatedSSRow.Cells[primaryColumnPosition].Value.ToString().Trim().ToUpper()).FirstOrDefault();

                                if (taskCDValidation == null)
                                {
                                    projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.rateTableID>(pmTaskNewEntry, pmSetupSSExt.UsrDefaultRateTableID);
                                    projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.status>(pmTaskNewEntry, SmartsheetConstants.SSConstants.ACTIVE);
                                    pmTaskNewEntry.Description = SmartsheetConstants.Messages.DEFAULT_TASK_DESCRIPTION;

                                    string durationVar = "";
                                    foreach (PMSSMapping row in templateMappingSet)
                                    {
                                        if (!String.IsNullOrEmpty(row.NameAcu))
                                        {
                                            SettingForSheets(row, columnPositionMap, updatedSSRow, pmTaskNewEntry, projectEntryGraph, durationVar);
                                        }
                                    }

                                    PMTaskSSExt pmTaskExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(pmTaskNewEntry);

                                    pmTaskExtRow.UsrSmartsheetTaskID = updatedSSRow.Id;
                                    //Insert() has to be invoked at the end as the order in which the values are assigned to the object depend on the iteration
                                    pmTaskNewEntry = projectEntryGraph.Tasks.Insert(pmTaskNewEntry);
                                }
                            }
                        }
                        else //Previously existing row in SS
                        {
                            pmTaskNewEntry = new PMTask();
                            //Fields updated: Description, Start Date, End Date, % complete.
                            if (updatedSSRow.Cells[primaryColumnPosition].Value != null)
                            {
                                if (currentTaskRow != null)
                                {
                                    // Find the Task to update it
                                    PMSSMapping mappingSS = templateMappingSet.Where(t => ((PMSSMapping)t).NameAcu.Trim().ToUpper() == SmartsheetConstants.ColumnMapping.TASKS_CD.Trim().ToUpper()).FirstOrDefault();

                                    pmTaskNewEntry = (PMTask)projectEntryGraph.Tasks.Select()
                                                     .Where(t => ((PMTask)t).TaskCD.Trim().ToUpper() == updatedSSRow.Cells[columnPositionMap[mappingSS.NameSS]].Value.ToString().Trim().ToUpper()).FirstOrDefault();
                                    string durationVar = "";

                                    foreach (PMSSMapping row in templateMappingSet)
                                    {
                                        if (!String.IsNullOrEmpty(row.NameAcu))
                                        {
                                            SettingForSheets(row, columnPositionMap, updatedSSRow, pmTaskNewEntry, projectEntryGraph, durationVar);
                                        }
                                    }
                                    currentTaskRow = projectEntryGraph.Tasks.Update(currentTaskRow);
                                }
                            }
                        }
                    }
                    break;
                }
                else
                {
                    primaryColumnPosition += 1;
                }
            }

            return;
        }
        /// <summary>
        /// Creates/Updates Acumatica Tasks with the Smartsheet modifications
        /// </summary>
        /// <param name="projectEntryGraph"></param>
        /// <param name="pmProjectRow"></param>
        /// <param name="pmSetupSSExt"></param>
        /// <param name="updatedSheet"></param>
        /// <param name="columnPositionMap"></param>
        public void UpdateAcumaticaTasks(ProjectEntry projectEntryGraph,
                                         PMProject pmProjectRow,
                                         PMSetupSSExt pmSetupSSExt,
                                         Sheet updatedSheet,
                                         Dictionary <string, int> columnPositionMap)
        {
            bool recordedInAcumatica   = false;
            int  primaryColumnPosition = 0;

            foreach (Column updatedColumn in updatedSheet.Columns)
            {
                if (updatedColumn != null &&
                    updatedColumn.Primary != null &&
                    updatedColumn.Primary == true)
                {
                    foreach (Row updatedSSRow in updatedSheet.Rows)
                    {
                        if (updatedSSRow != null &&
                            updatedSSRow.ParentId != null)     //Subtasks are not synced back to Acumatica
                        {
                            continue;
                        }

                        PMTask      currentTaskRow = null;
                        PMTaskSSExt pmTaskSSExtRow = null;

                        foreach (PMTask taskRow in projectEntryGraph.Tasks.Select())
                        {
                            recordedInAcumatica = false;
                            pmTaskSSExtRow      = PXCache <PMTask> .GetExtension <PMTaskSSExt>(taskRow);

                            if (pmTaskSSExtRow != null &&
                                pmTaskSSExtRow.UsrSmartsheetTaskID == updatedSSRow.Id)
                            {
                                recordedInAcumatica = true;
                                currentTaskRow      = taskRow;
                                break;
                            }
                        }

                        if (recordedInAcumatica == false) //New Row in Smartsheet not yet added to Acumatica
                        {
                            //Fields retrieved: Task, Description, Start Date, End Date, % Complete,
                            if (updatedSSRow.Cells[primaryColumnPosition].Value != null)
                            {
                                PMTask pmTaskNewEntry = new PMTask();
                                pmTaskNewEntry.ProjectID = pmProjectRow.ContractID;
                                pmTaskNewEntry.TaskCD    = updatedSSRow.Cells[primaryColumnPosition].Value.ToString();

                                PMTask taskCDValidation = (PMTask)projectEntryGraph.Tasks.Select()
                                                          .Where(t => ((PMTask)t).TaskCD.Trim().ToUpper() == updatedSSRow.Cells[primaryColumnPosition].Value.ToString().Trim().ToUpper()).FirstOrDefault();

                                if (taskCDValidation == null)
                                {
                                    pmTaskNewEntry = projectEntryGraph.Tasks.Insert(pmTaskNewEntry);

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]].Value != null)
                                    {
                                        projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.description>(pmTaskNewEntry, updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]].Value.ToString());
                                    }
                                    else
                                    {
                                        projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.description>(pmTaskNewEntry, SmartsheetConstants.Messages.DEFAULT_TASK_DESCRIPTION);
                                    }

                                    projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.rateTableID>(pmTaskNewEntry, pmSetupSSExt.UsrDefaultRateTableID);
                                    projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.status>(pmTaskNewEntry, SmartsheetConstants.SSConstants.ACTIVE);

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value != null)
                                    {
                                        if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value is DateTime)
                                        {
                                            DateTime startDate = (DateTime)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value;
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.startDate>(pmTaskNewEntry, startDate);
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.plannedStartDate>(pmTaskNewEntry, startDate);
                                        }
                                    }

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value != null)
                                    {
                                        if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value is DateTime)
                                        {
                                            DateTime endDate = (DateTime)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value;
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.endDate>(pmTaskNewEntry, endDate);
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.plannedEndDate>(pmTaskNewEntry, endDate);
                                        }
                                    }

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]].Value != null &&
                                        pmTaskNewEntry.Status == SmartsheetConstants.SSConstants.ACTIVE)
                                    {
                                        projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.completedPercent>(pmTaskNewEntry, (decimal)((double)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]].Value * 100));
                                    }

                                    PMTaskSSExt pmTaskExtRow = PXCache <PMTask> .GetExtension <PMTaskSSExt>(pmTaskNewEntry);

                                    pmTaskExtRow.UsrSmartsheetTaskID = updatedSSRow.Id;

                                    pmTaskNewEntry = projectEntryGraph.Tasks.Update(pmTaskNewEntry);
                                }
                            }
                        }
                        else //Previously existing row in SS
                        {
                            //Fields updated: Description, Start Date, End Date, % complete.
                            if (updatedSSRow.Cells[primaryColumnPosition].Value != null)
                            {
                                if (currentTaskRow != null)
                                {
                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]].Value != null)
                                    {
                                        projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.description>(currentTaskRow, updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.DESCRIPTION]].Value.ToString());
                                    }

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value != null)
                                    {
                                        if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value is DateTime)
                                        {
                                            DateTime startDate = (DateTime)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.START_DATE]].Value;
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.startDate>(currentTaskRow, startDate);
                                        }
                                    }

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value != null)
                                    {
                                        if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value is DateTime)
                                        {
                                            DateTime endDate = (DateTime)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.END_DATE]].Value;
                                            projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.endDate>(currentTaskRow, endDate);
                                        }
                                    }

                                    if (updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]] != null &&
                                        updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]].Value != null &&
                                        currentTaskRow.Status == SmartsheetConstants.SSConstants.ACTIVE)
                                    {
                                        projectEntryGraph.Tasks.Cache.SetValueExt <PMTask.completedPercent>(currentTaskRow, (decimal)((double)updatedSSRow.Cells[columnPositionMap[SmartsheetConstants.ColumnMapping.PCT_COMPLETE]].Value * 100));
                                    }

                                    currentTaskRow = projectEntryGraph.Tasks.Update(currentTaskRow);
                                }
                            }
                        }
                    }
                    break;
                }
                else
                {
                    primaryColumnPosition += 1;
                }
            }

            return;
        }
Esempio n. 21
0
        private PXResult <LienWaiverRecipient, PMProject> MaintainLienWaiverRecipientsLinks(PMProject project)
        {
            var linkedRecipient = GetLinkedLienWaiverRecipient(project);

            if (linkedRecipient == null)
            {
                var lienWaiverRecipient = CreateLienWaiverRecipient(project);
                return(new PXResult <LienWaiverRecipient, PMProject>(lienWaiverRecipient, project));
            }
            if (linkedRecipient.Selected == null)
            {
                linkedRecipient.Selected = true;
            }
            return(new PXResult <LienWaiverRecipient, PMProject>(linkedRecipient, project));
        }
Esempio n. 22
0
        private bool IsNonProjectAccountGroupsAllowed(PMProject project)
        {
            var projectExt = PXCache <Contract> .GetExtension <ContractExt>(project);

            return(projectExt.AllowNonProjectAccountGroups == true);
        }