Exemple #1
0
        public void Row_VismaID510_SaveInColoumnR()
        {
            //Arrange
            DateTime testDateTime = new DateTime(2019, DateTime.Now.Month, DateTime.Now.Day);
            string   expected     = (testDateTime.Year - 1).ToString();

            TimesheetEntry tse = new TimesheetEntry
            {
                EmployeeID = 12,
                Date       = testDateTime,
                ProjectID  = "23"
            };

            VismaEntry ve = new VismaEntry
            {
                VismaID    = 510,
                Comment    = "test",
                Value      = 2,
                RateValue  = 203,
                LinkedRate = new Rate {
                    Type = "Kørsel"
                }                                         //Type of arbejde
            };

            Row testRow = new Row(tse, ve, false);

            PrivateObject testRowObj = new PrivateObject(testRow);

            //Act
            testRowObj.Invoke("AssignValue", ve);
            string actual = (string)testRowObj.GetField("R");

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #2
0
        public void AssignRate_RateTypeOfNotKørsel_NoSaveInColumnJ()
        {
            //Arrange
            double testRateValue = 42000;
            string expected      = "";

            TimesheetEntry tse = new TimesheetEntry
            {
                EmployeeID = 12,
                Date       = DateTime.Now,
                ProjectID  = "23"
            };

            VismaEntry ve = new VismaEntry
            {
                VismaID    = 34,
                Comment    = "test",
                Value      = 2,
                RateValue  = testRateValue,
                LinkedRate = new Rate {
                    Type = "Arbejde"
                }                                          //Type of arbejde
            };

            Row testRow = new Row(tse, ve, false);

            PrivateObject testRowObj = new PrivateObject(testRow);

            //Act
            testRowObj.Invoke("AssignValue", ve);
            string actual = (string)testRowObj.GetField("J");

            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void AssignValue_RateWithSaveAsMoney_SaveAsMoneyInColumnK()
        {
            //Arrange
            double testValue = 2;
            string expected  = "2";

            TimesheetEntry tse = new TimesheetEntry
            {
                EmployeeID = 12,
                Date       = DateTime.Now,
                ProjectID  = "23"
            };

            VismaEntry ve = new VismaEntry
            {
                VismaID    = 34,
                Comment    = "test",
                Value      = testValue,
                LinkedRate = new Rate {
                    Type = "Arbejde", SaveAsMoney = true
                }                                                              //Type of arbejde
            };

            Row testRow = new Row(tse, ve, false);

            PrivateObject testRowObj = new PrivateObject(testRow);

            //Act
            testRowObj.Invoke("AssignValue", ve);
            string actual = (string)testRowObj.GetField("K");

            //Assert

            Assert.AreEqual(expected, actual);
        }
        private static void ApplyDailyRate(TimesheetEntry entry, Rate rate)
        {
            VismaEntry vismaEntry = new VismaEntry
            {
                VismaID          = rate.VismaID,
                RateID           = rate.Id,
                RateValue        = rate.RateValue,
                TimesheetEntryID = entry.Id,
                LinkedRate       = rate,
                Value            = 1
            };

            entry.vismaEntries.Add(vismaEntry);
        }
        private static void ApplyDriveRate(TimesheetEntry entry, Rate rate)
        {
            VismaEntry vismaEntry = new VismaEntry
            {
                VismaID          = rate.VismaID,
                RateID           = rate.Id,
                RateValue        = entry.DriveRate,
                TimesheetEntryID = entry.Id,
                Value            = entry.KrTextBox / entry.DriveRate,
                LinkedRate       = rate,
                Comment          = "Km. " + entry.SelectedRouteComboBoxItem
            };

            entry.vismaEntries.Add(vismaEntry);
        }
Exemple #6
0
        public VismaEntryViewModel(VismaEntry entry, TimesheetEntryConfirmationViewModel timesheetEntry, TimesheetConfirmationViewModel TsConfirmationViewModel)
        {
            TimesheetConfirmationViewModel = TsConfirmationViewModel;
            Entry          = entry;
            TimesheetEntry = timesheetEntry;

            // Saves all the rates' names to a list and then adds them as items in the combobox.
            rateNames = TimesheetEntry.Tsentry.timesheet.rates.Select(rate => rate.Name).ToList();
            foreach (string name in rateNames)
            {
                RateNamesCombobox.Add(new ComboBoxItem()
                {
                    Content = name
                });
            }
            // Then it finds the rate which was added to then select the correct rate to show.
            string raten = TimesheetEntry.Tsentry.timesheet.rates
                           .Where(rate => rate.Id == Entry.RateID)
                           .Select(rate => rate.Name).FirstOrDefault();

            SelectedRate = RateNamesCombobox.Where(name => (string)name.Content == raten).FirstOrDefault();
        }
Exemple #7
0
        public void Row_ProjectIsNull_FormatWithoutAProject()
        {
            int day   = 12;
            int month = 8;
            int year  = 2019;

            DateTime exampleDateTime = new DateTime(year, month, day);

            //Arrange
            TimesheetEntry tse = new TimesheetEntry
            {
                EmployeeID = 12,
                Date       = exampleDateTime,
                ProjectID  = null
            };

            VismaEntry ve = new VismaEntry
            {
                VismaID    = 34,
                Comment    = "test",
                Value      = 2,
                RateValue  = 20,
                LinkedRate = new Rate {
                    Type = "Arbejde"
                }
            };

            Row testRow = new Row(tse, ve, true);

            string expected = $"1242;1;{CommonValuesRepository.ColumnCSick};{tse.EmployeeID};{day}0{8}{2019};{day}0{8}{2019};{ve.VismaID};{ve.Comment};{ve.Value};;;;;;;;;;;;;;;;;;;;";

            //Act
            string actual = testRow.GetLine();


            //Assert
            Assert.AreEqual(expected, actual);
        }
        private static void ApplyHourlyRate(TimesheetEntry entry, Rate rate)
        {
            //First a vismaEntry is created with values from the TimesheetEntry and the Rate.
            VismaEntry vismaEntry = new VismaEntry
            {
                VismaID          = rate.VismaID,
                RateID           = rate.Id,
                RateValue        = rate.RateValue,
                TimesheetEntryID = entry.Id,
                LinkedRate       = rate
            };

            // Then it finds the amount of time within the hourly rate by first checking which is larger, the start time of the rate or the entry.
            DateTime startTime = entry.StartTime > rate.StartTime ? entry.StartTime : rate.StartTime;

            // Then it checks which is smaller, the end time of the entry or the rate.
            DateTime endTime = entry.EndTime < rate.EndTime ? entry.EndTime : rate.EndTime;

            // Finally it calculates the timespan.
            TimeSpan interval = endTime - startTime;

            // Only the nearest quarter value is needed for precision.
            vismaEntry.Value = RoundToNearestQuarter(interval.TotalHours);

            //Breaktime is subtracted from normal work hours.
            if (rate.Name == "Normal")
            {
                vismaEntry.Value -= entry.BreakTime;
            }

            // Finally for a failsafe a check for the value of the new vismaEntry is done, to check if any hours were in fact in the timespan. Before adding it to the timesheetEntry.
            if (vismaEntry.Value > 0)
            {
                entry.vismaEntries.Add(vismaEntry);
            }
        }
Exemple #9
0
        public EmployeeProfileViewModel(Employee emp)
        {
            SelectedEmployee = emp;

            // Instantiate the new route and set the foreignkey value to the,
            // currently selected employee.
            NewRoute            = new Route();
            NewRoute.EmployeeID = SelectedEmployee.Id;

            // Get all the workplaces from the database and store them.
            Task.Run(async() =>
            {
                var workplaces = await GetWorkplacesAsync();
                Workplaces     = new BindableCollection <Workplace>(workplaces);
            });

            // Find the active collective agreement from the database,
            // and pull the rate containing the rate for routes determined by the state.
            using (var ctx = new DatabaseDir.Database())
            {
                var routeRate = ctx.CollectiveAgreements.Include(r => r.Rates).FirstOrDefault(x => x.IsActive).Rates.FirstOrDefault(k => k.Type.Equals("Kørsel"));
                if (routeRate != null)
                {
                    NewRoute.RateValue = StateRouteRate = routeRate.RateValue;
                }
            }

            Task.Run(async() =>
            {
                _sixtyDayHolders = await GetSixtyDayDataAsync();
                NotifyOfPropertyChange(() => SixtyDayCollection);
            });

            // 1: Get all TimesheetEntries and the projectID
            // 2: Query for all VismaEntries linked to the TimesheetEntries
            // 3: Format all the data into a new bindablecollection to display on the table
            using (var ctx = new DatabaseDir.Database())
            {
                List <TimesheetEntry> entries = ctx.TimesheetEntries.Include(k => k.vismaEntries.Select(p => p.LinkedRate)).Where(x => x.EmployeeID == SelectedEmployee.Id).ToList();

                foreach (TimesheetEntry ts in entries)
                {
                    VismaEntry visma = ts.vismaEntries.FirstOrDefault(x => x.LinkedRate.Name == "Normal");
                    if (visma != null)
                    {
                        ProjectFormat pf = _allProjects.FirstOrDefault(k => k.ProjectID == ts.ProjectID);
                        if (pf == null)
                        {
                            pf = new ProjectFormat(ts.ProjectID);
                        }

                        pf.Hours += visma.Value;

                        if (!_allProjects.Contains(pf))
                        {
                            _allProjects.Add(pf);
                        }
                    }
                }

                ProjectCollection = new BindableCollection <ProjectFormat>(_allProjects);
            }

            // Calculate the current week, deduct one from it and afterwards get the current year.
            // Set the boxes for timesheets searching to automatically use these when the page starts.
            DateTime currentDate = DateTime.Now;

            SelectedWeek = DateHelper.GetWeekNumber(currentDate) - 1;
            SelectedYear = currentDate.Year;
            // Then do a search for entries.
            BtnSearchForEntries();

            using (var ctx = new DatabaseDir.Database())
            {
                // Get all timesheets for this year including the vismaentries.
                List <TimesheetEntry> allEntries = ctx.TimesheetEntries.Include(k => k.vismaEntries.Select(p => p.LinkedRate)).
                                                   Where(x => x.EmployeeID == SelectedEmployee.Id && x.Date.Year == DateTime.Now.Year).ToList();
                OverviewRow totalRow = new OverviewRow("SALDO");

                // Loop through all the rows in the datagrid.
                for (int i = 0; i < 27; i++)
                {
                    // Find the name of the row.
                    string rowName = "";
                    if (i > 0)
                    {
                        string prefix = ((i * 2) < 10) ? "0" : "";
                        rowName = $"{prefix}{i * 2}-{prefix}{(i * 2) + 1}";
                    }
                    else
                    {
                        rowName = "52/53-01";
                    }
                    OverviewRow row         = new OverviewRow(rowName);
                    OverviewRow previousRow = null;
                    if (i > 0)
                    {
                        previousRow = _overviewCollection[i - 1];
                    }

                    // Get the timesheet entries belonging to this row.
                    List <TimesheetEntry> tempEntries = allEntries.Where(x => DateHelper.GetWeekNumber(x.Date) == i * 2 ||
                                                                         DateHelper.GetWeekNumber(x.Date) == (i * 2) + 1).ToList();

                    // Column "Afspadsering IND"
                    row.ColumnValues[0]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "Afspadsering (ind)").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[0] += row.ColumnValues[0];
                    // Column "Afspadsering UD"
                    row.ColumnValues[1]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "Afspadsering (ud)").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[1] += row.ColumnValues[1];
                    // Column "Afspadsering SALDO" // Row 0 needs to get the value from the previous year
                    row.ColumnValues[2]       = (previousRow == null ? 0 : (previousRow.ColumnValues[2] + row.ColumnValues[0] - row.ColumnValues[1]));
                    totalRow.ColumnValues[2] += row.ColumnValues[2];
                    // Column "Feriefri UD"
                    row.ColumnValues[3]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Type == "Feriefri").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[3] += row.ColumnValues[3];
                    // Column "Feriefri SALDO"
                    row.ColumnValues[4]      = (previousRow == null ? 37 - row.ColumnValues[3] : previousRow.ColumnValues[4] - row.ColumnValues[3]);
                    totalRow.ColumnValues[4] = row.ColumnValues[4];
                    // Column "Ferie UD"
                    row.ColumnValues[5]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Type == "Ferie").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[5] += row.ColumnValues[5];
                    // Ferie SALDO // Row 0 needs to get value from the previous year
                    row.ColumnValues[6]       = (previousRow == null ? 0 : previousRow.ColumnValues[6] - row.ColumnValues[5]);
                    totalRow.ColumnValues[6] += row.ColumnValues[6];
                    // Column "Sygdom"
                    row.ColumnValues[7]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "Sygdom").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[7] += row.ColumnValues[7];
                    // Column "Timer"
                    row.ColumnValues[8]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "Normal").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[8] += row.ColumnValues[8];
                    // Column "Tillæg 1. og 2. time"
                    row.ColumnValues[9]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "1. + 2.timers overarbejde").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[9] += row.ColumnValues[9];
                    // Column "Tillæg 3. og 4. time"
                    row.ColumnValues[10]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Name == "3 + 4. times overarbejde").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[10] += row.ColumnValues[10];
                    // Column "Diæt"
                    row.ColumnValues[11]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Type == "Diæt").ToList().Sum(k => k.Value));
                    totalRow.ColumnValues[11] += row.ColumnValues[11];
                    // Column "Skattefri 1 KM"
                    row.ColumnValues[12]       = (float)tempEntries.Sum(x => x.vismaEntries.Where(p => p.LinkedRate.Type == "Kørsel").ToList().Sum(k => (k.Value / k.RateValue)));
                    totalRow.ColumnValues[12] += row.ColumnValues[12];

                    _overviewCollection.Add(row);
                }
                _overviewCollection.Add(totalRow);
                if (totalRow.ColumnValues[12] > CommonValuesRepository.TwentyThousindThreshold)
                {
                    new Notification(Notification.NotificationType.Warning, $"20 tusind kilometer reglen er overskredet for {SelectedEmployee.Fullname}.", 60);
                }
            }

            NotifyOfPropertyChange(() => OverviewCollection);

            // Prepare data for the statistics box
            PrepareStatisticsBox();
        }