public AddEditVarianceCodeViewModel(IssueFinancial financial,CommonUtils.VarianceCode varianceCode, List<IssueFinancialVarianceCode> issueFinancialVarianceCodes)
        {
            IssueFinancialVarianceCodes = issueFinancialVarianceCodes;
            mFinancial = financial;
            mVarianceCode = varianceCode;

            OkButtonCommand = new DelegateCommand<object>(OkButtonHandler, CanExecuteOkButtonHandler);
            CancelButtonCommand = new DelegateCommand<object>(CanelButtonHandler, CanExecuteOkButtonHandler);
        }
 public IssueFinancialTableViewModel(IssueFinancial financial, List<IssueFinancialVarianceCode> issueFinancialVarianceCodes,
     IssueFinancialControl view, bool userCanModify, IssueSetting issueSetting)
 {
     mView = view;
     mFinancial = financial;
     mUserCanModify = userCanModify;
     IssueFinancialVarianceCodes = issueFinancialVarianceCodes;
     mIssueSetting = issueSetting;
     ActualVsBaselineVarianceCommand = new DelegateCommand<object>(ActualvsBaselineButtonHandler, CanExecuteOkButtonHandler);
     ActualVsForecastVarianceCommand = new DelegateCommand<object>(ActualvsForecastButtonHandler, CanExecuteOkButtonHandler);
     OpenPurchaseOrderCommand = new DelegateCommand<object>(OpenPurchaseOrderCommandHandler, CanExecuteOpenPurchaseOrderCommandHandler);
 }
        public AddEditVarianceCodeDialog(IssueFinancial financial, CommonUtils.VarianceCode varianceCode,List<IssueFinancialVarianceCode> issueFinancialVarianceCodes)
        {
            InitializeComponent();

            CompositionInitializer.SatisfyImports(this);

            Title = "Variance";

            if (varianceCode == CommonUtils.VarianceCode.ActualVsBaseline) Title = String.Format("Reason For Actual vs Baseline Variance ({0:MMM yy})", financial.Date);
            if (varianceCode == CommonUtils.VarianceCode.ActualVsForecast) Title = String.Format("Reason For Actual vs Forecast Variance ({0:MMM yy})", financial.Date);

            var viewModel = new AddEditVarianceCodeViewModel(financial, varianceCode,issueFinancialVarianceCodes);
            viewModel.View = this;
            DataContext = viewModel;
        }
        public void Run()
        {
            using (var cee = new CmsEntities())
            {
                //cee.Configuration.AutoDetectChangesEnabled = false;
                cee.Configuration.ValidateOnSaveEnabled = false;
                var orSystemReference = cee.SystemReferenceTypes.FirstOrDefault(x => x.Code.ToUpper() == "OR");

                foreach (var sapInternalOrderImporterObject in mSapInternalOrderImporterObject)
                {
                    mLog.Verbose(" ");
                    mLog.Verbose("Processing Sap Internal Order '{0}' for IssueId {1} and its children ({2}).",
                        sapInternalOrderImporterObject.InternalOrderNumber, sapInternalOrderImporterObject.IssueId, sapInternalOrderImporterObject.Children.Count);

                    var issueFinancials = cee.IssueFinancials.Where(x => x.IssueId == sapInternalOrderImporterObject.IssueId).ToList();

                    var groupByDates = sapInternalOrderImporterObject.Children.Select(x => new DateTime(x.Year, x.Month, 1)).Distinct();

                    foreach (var groupByDate in groupByDates)
                    {
                        var actualMonthSum = sapInternalOrderImporterObject.Children.Where(x => x.Year == groupByDate.Year && x.Month == groupByDate.Month).Sum(x => x.Actuals);

                        var issueFinancial = issueFinancials.FirstOrDefault(x => x.Date.Year == groupByDate.Year && x.Date.Month == groupByDate.Month);

                        if (issueFinancial == null)
                        {
                            issueFinancial = new IssueFinancial
                            {
                                IssueId = sapInternalOrderImporterObject.IssueId,
                                Date = groupByDate,
                                LastModifiedDate = DateTime.Now,
                                LastModifiedUserId = 1,
                                LastImportedById = 1,
                                LastImportedDate = DateTime.Now,
                            };
                            cee.IssueFinancials.Add(issueFinancial);
                        }

                        issueFinancial.Actual = actualMonthSum ?? 0;
                        issueFinancial.ActualsOpex = issueFinancial.Actual;

                        issueFinancial.LastImportedById = 1;
                        issueFinancial.LastImportedDate = DateTime.Now;

                        if (issueFinancial.Id == 0)
                        {
                            mLog.Verbose("Inserted new IssueFinancial IssueId = '{0}' Date ='{1}' Actual = '{2}'",
                                issueFinancial.IssueId, issueFinancial.Date, issueFinancial.Actual);
                        }
                        else
                        {
                            mLog.Verbose("Updated IssueFinancial Id = '{0}', IssueId = '{1}' Date ='{2}' Actual = '{3}'",
                                issueFinancial.Id,issueFinancial.IssueId, issueFinancial.Date, issueFinancial.Actual);
                        }
                    }

                    var actualsSum = sapInternalOrderImporterObject.Children.Sum(x => x.Actuals);

                    var existingSystemReference = cee.SystemReferences.FirstOrDefault(x => x.IssueId == sapInternalOrderImporterObject.IssueId &&
                        x.SystemReferenceTypeId == orSystemReference.Id);

                    existingSystemReference.ActualValue = actualsSum;
                    existingSystemReference.FundingType = "OPEX";

                    mLog.Verbose("Updated ActualValue = {0} for IssueId '{1}' SystemReference.Number '{2}' SystemReferenceType '{3}'",
                                actualsSum, sapInternalOrderImporterObject.IssueId, sapInternalOrderImporterObject.InternalOrderNumber, orSystemReference.Id);
                }

                //https://jira.issgroup.com.au/browse/BODCMS-1574
                //Set ALL IssueFinancial.Accruals to 0 when importing CJI3
                //condition - only set to 0 where Month is less than (<) Current Month
                //var now = DateTime.Now;
                //foreach (var issueFinancial in cee.IssueFinancials.Where(x => x.Date.Year < now.Year || (x.Date.Year == now.Year && x.Date.Month < now.Month)))
                //{
                //    issueFinancial.Accrual = 0;
                //}

                cee.SaveChanges();
            }
        }
        private void AddButtonHandler(object parameter)
        {
            if (CanExecuteAddButtonHandler(parameter))
            {
                if (AreAllValid())
                {
                    MonthPicker monthPicker = new MonthPicker(mIssueFinancials.Select(x => x.Date).Distinct().ToList());

                    monthPicker.Closed += (s1, e1) =>
                    {
                        if (monthPicker.DialogResult.HasValue && monthPicker.DialogResult.Value)
                        {
                            IsBusy = true;
                            foreach (var date in monthPicker.Dates)
                            {
                                var issueFinancial = new IssueFinancial {IssueId = mIssue.Id, Date = date.Date, LastModifiedDate = DateTime.Now, LastModifiedUserId = CMS.User.Id};

                                var newIssueFinancialTableViewModel = new IssueFinancialTableViewModel(issueFinancial, IssueFinancialVarianceCodes, mView,
                                    CanUserModifyFinancialData(), mIssueSetting);
                                newIssueFinancialTableViewModel.KpiBaselineReadOnly = mKpiBaselineEnabled;

                                mIssueFinancials.Add(newIssueFinancialTableViewModel);
                                mIssue.IssueFinancials.Add(issueFinancial);
                            }
                            mTimer.Start();
                        }
                    };
                    monthPicker.Show();
                }
            }
        }
Esempio n. 6
0
        private void SaveIssueFinancials(Issue issue, Issue originalIssue, CmsEntities cee)
        {
            log.Verbose("SaveIssueFinancials()");
            //Delete SaveIssueFinancials
            cee.DeleteWhere<IssueFinancial>(cee, x => x.IssueId == issue.Id);

            cee.Configuration.AutoDetectChangesEnabled = false;

            //Save SaveIssueFinancials
            foreach (IssueFinancial issueFinancial in issue.IssueFinancials.ToList())
            {
                var newFinancial = new IssueFinancial
                {
                    IssueId = issue.Id,
                    Date = issueFinancial.Date,
                    Budget = issueFinancial.Budget,
                    Baseline = issueFinancial.Baseline,
                    Forecast = issueFinancial.Forecast,
                    Actual = issueFinancial.Actual,
                    Accrual = issueFinancial.Accrual,
                    ActualVsBaselineVarianceCodeId = issueFinancial.ActualVsBaselineVarianceCodeId,
                    ActualVsForecastVarianceCodeId = issueFinancial.ActualVsForecastVarianceCodeId,
                    ActualVsBaselineNote = issueFinancial.ActualVsBaselineNote,
                    ActualVsForecastNote = issueFinancial.ActualVsForecastNote,
                    LastModifiedDate = issueFinancial.LastModifiedDate,
                    LastModifiedUserId = issueFinancial.LastModifiedUserId,
                    ForecastLastModifiedDate = issueFinancial.ForecastLastModifiedDate,
                    ForecastLastModifiedUserId = issueFinancial.ForecastLastModifiedUserId,
                    ActualsOpex = issueFinancial.ActualsOpex,
                    ActualsCapex = issueFinancial.ActualsCapex,
                    ForecastV1 = issueFinancial.ForecastV1,
                    ForecastV2 = issueFinancial.ForecastV2,
                    ForecastV3 = issueFinancial.ForecastV3

                };
                originalIssue.IssueFinancials.Add(newFinancial);
            }
            cee.Configuration.AutoDetectChangesEnabled = true;
        }
Esempio n. 7
0
        private void InsertUpdateData(IList<Cji3DataAdapter> importData)
        {
            if (importData.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, NoDataFoundForWorkSheetMessage());
                return;
            }
            var currentDate = DateTime.Now;

            var existingFinancials = (from x in Cee.IssueFinancials select x).ToList();

            //get unique Project Definitions
            var projectDefinitions = (from x in importData select x.ProjectDefinition).Distinct().ToList();

            //RaiseMessage(CommonUtils.MessageType.Warning, string.Format("!!!!! This version of a importer plugin will NOT set Accruals to 0 when importing CJI3 !!!!!"));

            //import all financial data
            foreach (var projectDefinition in projectDefinitions)
            {
                IssueFinancial existingFinancial = null;
                IssueFinancial newIssueFinancial = null;

                var issue = GetIssue(projectDefinition);

                if (issue != null)
                {

                    string definition = projectDefinition;
                    var uniqueDates = importData.Where(x => x.ProjectDefinition == definition).OrderBy(x=> x.Date).Select(x => x.Date).Distinct();

                    foreach (var uniqueDate in uniqueDates)
                    {
                        decimal currencySum = importData.Where(x => x.ProjectDefinition == projectDefinition && x.Date == uniqueDate).Select(x => x.ValueInObjectCurrency).Sum();

                        existingFinancial = existingFinancials.Find(x => x.IssueId == issue.Id && x.Date == uniqueDate);

                        if (existingFinancial != null)
                        {
                           //Update
                            existingFinancial.Actual = currencySum;
                            existingFinancial.LastModifiedDate = currentDate;
                            existingFinancial.LastModifiedUserId = MetaData.UserId;
                            existingFinancial.LastImportedDate = currentDate;
                            existingFinancial.LastImportedById = MetaData.UserId;
                        }
                        else
                        {
                            //Insert
                            newIssueFinancial = new IssueFinancial
                            {
                                IssueId = issue.Id,
                                Date = uniqueDate,
                                Budget = 0,
                                Baseline = 0,
                                Forecast = 0,
                                Actual = currencySum,
                                Accrual = 0,
                                LastModifiedDate = currentDate,
                                LastModifiedUserId = MetaData.UserId,
                                LastImportedDate = currentDate,
                                LastImportedById = MetaData.UserId
                            };
                            Cee.IssueFinancials.Add(newIssueFinancial);
                        }
                        if (newIssueFinancial != null)
                        {
                            mInsertedResults.Add(newIssueFinancial);
                        }
                        if (existingFinancial != null)
                        {
                            mUpdatedResults.Add(existingFinancial);
                        }
                    }
                }
                else
                {
                    RaiseMessage(CommonUtils.MessageType.Warning, string.Format("Could not determine Issue from Project Definition '{0}'.", projectDefinition));
                }
            }

            //https://jira.issgroup.com.au/browse/BODCMS-1574
            //Set ALL IssueFinancial.Accruals to 0 when importing CJI3
            //condition - only set to 0 where Month is less than (<) Current Month
            var now = DateTime.Now;
            foreach (var issueFinancial in Cee.IssueFinancials.Where(x => x.Date.Year < now.Year || (x.Date.Year == now.Year && x.Date.Month < now.Month)) )
            {
                issueFinancial.Accrual = 0;
            }

            if (mInsertedResults.Count == 0 && mUpdatedResults.Count == 0)
            {
                RaiseMessage(CommonUtils.MessageType.Warning, string.Format("No Financials were added from worksheet {0}.", WorkSheetName));
            }
            else
            {
                //SAVE
                Cee.SaveChanges();

                foreach (var result in mInsertedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added,
                        string.Format("Added into IssueFinancial Table: Issue Id '{0}', Date = '{1}', Actual = '{2}'",
                        result.IssueId, result.Date, result.Actual));
                }

                foreach (var eresult in mUpdatedResults)
                {
                    RaiseMessage(CommonUtils.MessageType.Added,
                        string.Format("Updated IssueFinancial Table: Issue Id '{0}', Date = '{1}', Actual = '{2}'",
                        eresult.IssueId, eresult.Date, eresult.Actual));
                }
            }
        }
Esempio n. 8
0
        public void Run()
        {
            using (var cee = new CmsEntities())
            {
                //cee.Configuration.AutoDetectChangesEnabled = false;
                cee.Configuration.ValidateOnSaveEnabled = false;

                var existingSystemReferences = cee.SystemReferences.ToList();

                foreach (var financialActualImporterObject in mFinancialActualImporterObjects)
                {
                    mLog.Verbose(" ");
                    mLog.Verbose("Processing Financial Actuals for IssueId {0} and its children ({1}).",
                        financialActualImporterObject.IssueId, financialActualImporterObject.Children.Count);

                    //Find if the ProjectCode(SystemReference.Number) and Type PRJ-DEF exist in CMS SystemReference table
                    var issueFinancials = cee.IssueFinancials.Where(x => x.IssueId == financialActualImporterObject.IssueId).ToList();

                    var groupByDates = financialActualImporterObject.Children.Select(x => new DateTime(x.Year, x.Month, 1)).Distinct();

                    foreach (var groupByDate in groupByDates)
                    {
                        var actualMonthSum = financialActualImporterObject.Children.Where(x => x.Year == groupByDate.Year && x.Month == groupByDate.Month).Sum(x => x.Actuals);

                        var opexSum = financialActualImporterObject.Children.Where(
                            x => x.Year == groupByDate.Year && x.Month == groupByDate.Month
                                 && existingSystemReferences.Where(
                                     xx => xx.IssueId == financialActualImporterObject.IssueId && xx.FundingType == "OPEX" && x.WbsElement == xx.Number)
                                     .Select(y => y.Number).Contains(x.WbsElement)).Sum(a => a.Actuals);

                        var capexSum = financialActualImporterObject.Children.Where(
                            x => x.Year == groupByDate.Year && x.Month == groupByDate.Month
                                 && existingSystemReferences.Where(
                                     xx => xx.IssueId == financialActualImporterObject.IssueId && xx.FundingType == "CAPEX" && x.WbsElement == xx.Number)
                                     .Select(y => y.Number).Contains(x.WbsElement)).Sum(a => a.Actuals);

                        var issueFinancial = issueFinancials.FirstOrDefault(x => x.Date.Year == groupByDate.Year && x.Date.Month == groupByDate.Month);

                        if (issueFinancial == null)
                        {
                            issueFinancial = new IssueFinancial
                            {
                                IssueId = financialActualImporterObject.IssueId,
                                Date = groupByDate,
                                LastModifiedDate = DateTime.Now,
                                LastModifiedUserId = 1,
                                LastImportedById = 1,
                                LastImportedDate = DateTime.Now,
                                ActualsOpex = opexSum ?? 0,
                                ActualsCapex = capexSum ?? 0

                            };
                            cee.IssueFinancials.Add(issueFinancial);
                        }

                        issueFinancial.Actual = actualMonthSum ?? 0;
                        issueFinancial.ActualsOpex = opexSum ?? 0;
                        issueFinancial.ActualsCapex = capexSum ?? 0;

                        issueFinancial.LastImportedById = 1;
                        issueFinancial.LastImportedDate = DateTime.Now;

                        if (issueFinancial.Id == 0)
                        {
                            mLog.Verbose("Inserted new IssueFinancial IssueId = '{0}' Date ='{1}' Actual = '{2}'",
                                issueFinancial.IssueId, issueFinancial.Date, issueFinancial.Actual);
                        }
                        else
                        {
                            mLog.Verbose("Updated IssueFinancial Id = '{0}', IssueId = '{1}' Date ='{2}' Actual = '{3}'",
                                issueFinancial.Id,issueFinancial.IssueId, issueFinancial.Date, issueFinancial.Actual);
                        }
                    }
                }

                //https://jira.issgroup.com.au/browse/BODCMS-1574
                //Set ALL IssueFinancial.Accruals to 0 when importing CJI3
                //condition - only set to 0 where Month is less than (<) Current Month
                var now = DateTime.Now;
                foreach (var issueFinancial in cee.IssueFinancials.Where(x => x.Date.Year < now.Year || (x.Date.Year == now.Year && x.Date.Month < now.Month)))
                {
                    issueFinancial.Accrual = 0;
                }

                cee.SaveChanges();
            }
        }