public IActionResult TransferReportsToPayroll()
 {
     _logger.LogDebug($"{GetType().Name}, Get(), TransferReportsToPayroll initialized");
     if (!CurrentUser.IsAdmin)
     {
         _logger.LogError($"{GetType().Name}, Get(), {CurrentUser} is not admin, file generation aborted, Status code:403 Forbidden");
         return(StatusCode(StatusCodes.Status403Forbidden));
     }
     try
     {
         _transferToPayrollService.TransferReportsToPayroll();
         _logger.LogDebug($"{GetType().Name}, Get(), Transfer to payroll finished");
         return(Ok(true));
     }
     catch (Exception e)
     {
         _logger.LogError(e, $"{GetType().Name}, Get(), Error when transfering reports to payroll, Status Code: 500 Internal Server Error");
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
        /// <summary>
        /// Generated and transfers the files to the payroll system.
        /// Sends notification about the event to the admins
        /// </summary>
        private void AttemptGenerateFile()
        {
            try
            {
                _transferToPayrollService.TransferReportsToPayroll();

                // Send mail to admins
                var mailSubject = "Filen fra OS2 Indberetning er genereret";
                var mailText    = "Filen fra OS2 Indberetning med godkendte indberetning er genereret.";
                _mailService.SendMailToAdmins(mailSubject, mailText);
            }
            catch (Exception e)
            {
                var mailSubject = "Generering af filen fra OS2 Indberetning fejlede";
                var mailText    = "Generering af filen fra OS2 Indberetning med godkendte indberetninger fejlede. Filen er ikke blevet genereret.";
                _mailService.SendMailToAdmins(mailSubject, mailText);

                //TODO: Handle issues when trying to send payroll
                Console.WriteLine("Kunne ikke send files til payroll");
                _logger.LogForAdmin("Fejl ved generering af IND01 fil til KMD med godkendte indberetninger. Filen er ikke genereret, og indberetninger dermed ikke overført.");
                _logger.Error($"{GetType().Name}, AttemptGenerateFiles(), Could not generet file for KMD", e);
            }
        }
        public void TestTransferReportsToPayrollWithSD()
        {
            // Arrange
            var shouldProcessAndChangeStatus = _reportRepoMock.Insert(new DriveReport
            {
                Status     = ReportStatus.Accepted,
                Distance   = 50,
                Employment = new Employment()
                {
                    Id           = 0,
                    EmploymentId = "123"
                },
                ApprovedBy = new Person()
                {
                    Id        = 321,
                    CprNumber = "9090909090"
                },
                TFCode             = "0000",
                DriveDateTimestamp = 0,
                LicensePlate       = "aa 12 123",
                Purpose            = "shouldProcessAndChangeStatus",
                Person             = new Person()
                {
                    CprNumber = "1234123400"
                }
            });

            var shouldNotProcessBecausePending = _reportRepoMock.Insert(new DriveReport
            {
                Status     = ReportStatus.Pending,
                Distance   = 50,
                Employment = new Employment()
                {
                    Id = 0
                },
                TFCode             = "0000",
                DriveDateTimestamp = 0,
                LicensePlate       = "aa 12 123",
                Person             = new Person()
                {
                    CprNumber = "1234123400"
                }
            });

            var shouldNotProcessBecauseRejected = _reportRepoMock.Insert(new DriveReport
            {
                Status     = ReportStatus.Rejected,
                Distance   = 50,
                Employment = new Employment()
                {
                    Id = 0
                },
                TFCode             = "0000",
                DriveDateTimestamp = 0,
                LicensePlate       = "aa 12 123",
                Person             = new Person()
                {
                    CprNumber = "1234123400"
                }
            });

            var shouldChangeStatus = _reportRepoMock.Insert(new DriveReport
            {
                Status     = ReportStatus.Accepted,
                Distance   = 0,
                Employment = new Employment()
                {
                    Id = 0
                },
                TFCode             = "0000",
                DriveDateTimestamp = 0,
                LicensePlate       = "aa 12 123",
                Person             = new Person()
                {
                    CprNumber = "1234123400"
                }
            });

            // Act
            _transferToPayRollService.TransferReportsToPayroll();

            // Assert
            Assert.AreEqual(ReportStatus.Invoiced, shouldProcessAndChangeStatus.Status);
            Assert.AreEqual(ReportStatus.Pending, shouldNotProcessBecausePending.Status);
            Assert.AreEqual(ReportStatus.Rejected, shouldNotProcessBecauseRejected.Status);
            Assert.AreEqual(ReportStatus.Invoiced, shouldChangeStatus.Status);
            _sdClientMock.ReceivedWithAnyArgs(1).SendRequest(new Core.ApplicationServices.SdKoersel.AnsaettelseKoerselOpretInputType());
        }