Ejemplo n.º 1
0
        public ActionResult Calculate([Bind(Include = "TravelReportId,ApplicationUserId,TravelReportName,Destination,Purpose,DepartureDate,DepartureTime,ReturnDate,ReturnTime,DepartureHoursExtra,ReturnHoursExtra,FullDay,HalfDay,Night,BreakfastReduction,LunchReduction,DinnerReduction,StatusTypeId,Comment")] TravelReport travelReport, string button)
        {
            if (ModelState.IsValid)
            {
                if (button == "Summera")
                {
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Calculate", new { id = travelReport.TravelReportId }));
                }
                if (button == "Lägg till utgifter")
                {
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Create", "Expenses", new { tId = travelReport.TravelReportId }));
                }
                if (button == "Skicka in")
                {
                    travelReport.StatusTypeId    = db.StatusTypes.Where(stt => stt.StatusName == "Inskickad").FirstOrDefault().StatusTypeId;
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(RedirectToAction("Calculate", new { id = travelReport.TravelReportId }));
            }
            ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
            ViewBag.StatusTypeId      = new SelectList(db.StatusTypes, "StatusTypeId", "StatusName", travelReport.StatusTypeId);
            return(View(travelReport));
        }
Ejemplo n.º 2
0
        // GET: TravelReports/Edit1/5
        // Possibility to change date/time for travel
        public ActionResult Edit1(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }

            if (User.IsInRole("Assistant"))
            {
                var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();
                if (travelReport.ApplicationUserId != ActiveUser.Id)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }

            ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
            ViewBag.StatusName        = db.StatusTypes.Find(travelReport.StatusTypeId).StatusName;
            ViewBag.PatientId         = new SelectList(db.PatientUsers.Where(p => p.StaffUserId == travelReport.ApplicationUserId).Include(g => g.Patient).Where(g => g.PatientId == g.Patient.PatientId).Select(g => g.Patient), "PatientId", "PatientName", travelReport.PatientId);
            return(View(travelReport));
        }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            TravelReport travelReport = db.TravelReports.Find(id);

            db.TravelReports.Remove(travelReport);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
        // GET: TravelReports/Calc/5
        //
        // The view Calc will present the calculated sum of allowance and expenses
        //
        public ActionResult Calc(int?id, string selectedUserId)
        {
            var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();

            ViewBag.ActiveUser     = ActiveUser.Id;
            ViewBag.SelectedUserId = selectedUserId;

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            if (User.IsInRole("Assistant"))
            {
                if (travelReport.ApplicationUserId != ActiveUser.Id)
                {
                    return(HttpNotFound());
                }
            }

            var legalAmount = db.LegalAmounts.Where(l => l.ValidDate <= travelReport.DepartureDate).OrderByDescending(l => l.ValidDate).FirstOrDefault();

            ViewBag.LegalAmount = legalAmount;

            var sumOfAll = SumOfAllowance(travelReport, legalAmount);

            ViewBag.Summa = sumOfAll;

            var     expensesThisTravel = db.Expenses.Where(e => e.TravelReportId == travelReport.TravelReportId);
            int     noOfExpenses       = expensesThisTravel.Count();
            decimal sumOfExpenses      = 0;

            foreach (var e1 in expensesThisTravel)
            {
                sumOfExpenses = sumOfExpenses + (decimal)e1.ExpenseAmount;
            }

            ViewBag.NoOfExpenses  = noOfExpenses;
            ViewBag.SumOfExpenses = sumOfExpenses;

            ViewBag.SummaPlus = sumOfAll + sumOfExpenses;

            ViewBag.TravelReportId = travelReport.TravelReportId;

            ViewBag.Traktamente = (travelReport.Night != 0);

            ViewBag.Comment = travelReport.Comment;

            travelReport.Comment = "";

            return(View(travelReport));
        }
Ejemplo n.º 5
0
        // GET: Expenses
        public ActionResult Index(int tId)
        {
            var activeUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();

            ViewBag.ActualTravelReportId = tId;
            var          expenses           = db.Expenses.Include(e => e.ExpenseType).Include(e => e.TravelReport).Where(e => e.TravelReportId == tId);
            TravelReport activeTravelReport = db.TravelReports.Find(tId);

            ViewBag.ActiveTravelReport = activeTravelReport;
            return(View(expenses.ToList()));
        }
Ejemplo n.º 6
0
 public ActionResult Edit1([Bind(Include = "TravelReportId,ApplicationUserId,TravelReportName,Destination,Purpose,DepartureDate,DepartureTime,ReturnDate,ReturnTime,DepartureHoursExtra,ReturnHoursExtra,FullDay,HalfDay,Night,BreakfastReduction,LunchReduction,DinnerReduction,StatusTypeId,Comment")] TravelReport travelReport)
 {
     if (ModelState.IsValid)
     {
         db.Entry(travelReport).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Edit2", new { id = travelReport.TravelReportId }));
     }
     ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
     ViewBag.StatusTypeId      = new SelectList(db.StatusTypes, "StatusTypeId", "StatusName", travelReport.StatusTypeId);
     return(View(travelReport));
 }
Ejemplo n.º 7
0
        // GET: Expenses/Create
        public ActionResult Create(int tId)
        {
            string faultMessage = null;

            TravelReport activeTravelReport = db.TravelReports.Find(tId);;

            ViewBag.ExpenseTypeId        = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName");
            ViewBag.ActualTravelReportId = tId;
            ViewBag.ActiveTravelReport   = activeTravelReport;
            ViewBag.ErrorMsg             = faultMessage;
            return(View());
        }
Ejemplo n.º 8
0
 public ActionResult Edit1([Bind(Include = "TravelReportId,ApplicationUserId,PatientId,TravelReportName,Destination,Purpose,DepartureDate,DepartureTime,ReturnDate,ReturnTime,DepartureHoursExtra,ReturnHoursExtra,FullDay,HalfDay,Night,BreakfastDeduction,LunchOrDinnerDeduction,LunchAndDinnerDeduction,AllMealsDeduction,StatusTypeId,Comment")] TravelReport travelReport)
 {
     if (ModelState.IsValid)
     {
         db.Entry(travelReport).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Edit2", new { id = travelReport.TravelReportId }));
     }
     ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
     ViewBag.StatusName        = db.StatusTypes.Find(travelReport.StatusTypeId).StatusName;
     ViewBag.PatientId         = new SelectList(db.PatientUsers.Where(p => p.StaffUserId == travelReport.ApplicationUserId).Include(g => g.Patient).Where(g => g.PatientId == g.Patient.PatientId).Select(g => g.Patient), "PatientId", "PatientName", travelReport.PatientId);
     return(View(travelReport));
 }
Ejemplo n.º 9
0
        public decimal SumOfAllowance(TravelReport travelReport)
        {
            var legalAmount  = db.LegalAmounts.FirstOrDefault();
            int allowanceSum = 0;

            allowanceSum = allowanceSum + (int)travelReport.Night * (int)legalAmount.NightAmount;
            allowanceSum = allowanceSum + (int)travelReport.FullDay * (int)legalAmount.FullDayAmount;
            allowanceSum = allowanceSum + (int)travelReport.HalfDay * (int)legalAmount.HalfDayAmount;
            allowanceSum = allowanceSum - (int)travelReport.BreakfastReduction * (int)legalAmount.BreakfastReductionAmount;
            allowanceSum = allowanceSum - (int)travelReport.LunchReduction * (int)legalAmount.LunchReductionAmount;
            allowanceSum = allowanceSum - (int)travelReport.DinnerReduction * (int)legalAmount.DinnerReductionAmount;
            return((decimal)allowanceSum);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Saves the current comment from the tavelreport together with timing information into the Notes db table
        /// Will be used later as history of the status changes for the travel report
        /// </summary>
        /// <param name="travelReport"></param>
        public void SaveNote(TravelReport travelReport)
        {
            var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();

            Note note = new Note();

            note.ApplicationUserId = ActiveUser.FullName;
            note.NoteTime          = DateTime.Now;
            note.NoteStatus        = db.StatusTypes.Where(stt => stt.StatusTypeId == travelReport.StatusTypeId).FirstOrDefault().StatusName;
            note.NoteInfo          = travelReport.Comment;
            note.TravelReportId    = travelReport.TravelReportId;
            db.Notes.Add(note);
            db.SaveChanges();
        }
Ejemplo n.º 11
0
        // GET: TravelReports/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            return(View(travelReport));
        }
Ejemplo n.º 12
0
        // GET: TravelReports/Details/5
        public ActionResult Details(int?id, string selectedUserId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ViewBag.SelectedUserId = selectedUserId;
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            if (User.IsInRole("Assistant"))
            {
                //Check that user doesn't manipulate URL string
                var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();
                if (travelReport.ApplicationUserId != ActiveUser.Id)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }
            // Allowances are due when staying away over night (0.00 to 6.00)
            ViewBag.Traktamente = (travelReport.Night != 0);
            // get legalAmount for the travel date
            var legalAmount = db.LegalAmounts.Where(l => l.ValidDate <= travelReport.DepartureDate).OrderByDescending(l => l.ValidDate).FirstOrDefault();

            ViewBag.LegalAmount = legalAmount;

            var sumOfAll = SumOfAllowance(travelReport, legalAmount);

            ViewBag.Summa = sumOfAll;

            var     expensesThisTravel = db.Expenses.Where(e => e.TravelReportId == travelReport.TravelReportId);
            int     noOfExpenses       = expensesThisTravel.Count();
            decimal sumOfExpenses      = 0;

            foreach (var e1 in expensesThisTravel)
            {
                sumOfExpenses = sumOfExpenses + (decimal)e1.ExpenseAmount;
            }

            ViewBag.NoOfExpenses  = noOfExpenses;
            ViewBag.SumOfExpenses = sumOfExpenses;
            ViewBag.SummaPlus     = sumOfAll + sumOfExpenses;

            return(View(travelReport));
        }
Ejemplo n.º 13
0
        // GET: TravelReports/Edit1/5
        public ActionResult Edit1(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
            ViewBag.StatusTypeId      = new SelectList(db.StatusTypes, "StatusTypeId", "StatusName", travelReport.StatusTypeId);
            return(View(travelReport));
        }
Ejemplo n.º 14
0
 // Calculates the sum of all allowances for current travel report
 //
 // Returns the sum if allowanse is according to tax rules, that is away for at least one night
 // Otherwise returns 0
 /// <summary>
 /// Calculates the sum of all allowances for current travel report
 /// </summary>
 /// <param name="travelReport"></param>
 /// <param name="legalAmount"></param>
 /// <returns>Returns the sum if allowanse is according to tax rules, that is if the traveller is away for at least one night
 /// Otherwise returns 0</returns>
 public decimal SumOfAllowance(TravelReport travelReport, LegalAmount legalAmount)
 {
     if (travelReport.Night != 0)
     {
         int allowanceSum = 0;
         allowanceSum = allowanceSum + (int)travelReport.Night * (int)legalAmount.NightAmount;
         allowanceSum = allowanceSum + (int)travelReport.FullDay * (int)legalAmount.FullDayAmount;
         allowanceSum = allowanceSum + (int)travelReport.HalfDay * (int)legalAmount.HalfDayAmount;
         allowanceSum = allowanceSum - (int)travelReport.BreakfastDeduction * (int)legalAmount.BreakfastAmount;
         allowanceSum = allowanceSum - (int)travelReport.LunchOrDinnerDeduction * (int)legalAmount.LunchOrDinnerAmount;
         allowanceSum = allowanceSum - (int)travelReport.LunchAndDinnerDeduction * (int)legalAmount.LunchAndDinnerAmount;
         allowanceSum = allowanceSum - (int)travelReport.AllMealsDeduction * (int)legalAmount.AllMealsAmount;
         return((decimal)allowanceSum);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 15
0
        // GET: TravelReports/Calc/5
        //
        // The view Calculate will present the calculated sum of allowance for expenses
        //
        public ActionResult Calc(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            //var legalAmount = db.LegalAmounts.FirstOrDefault();
            var legalAmount = db.LegalAmounts.Where(l => l.ValidDate <= travelReport.DepartureDate).OrderByDescending(l => l.ValidDate).FirstOrDefault();

            ViewBag.LegalAmount = legalAmount;

            var sumOfAll = SumOfAllowance(travelReport);

            ViewBag.Summa = sumOfAll;

            var     expensesThisTravel = db.Expenses.Where(e => e.TravelReportId == travelReport.TravelReportId);
            int     noOfExpenses       = expensesThisTravel.Count();
            decimal sumOfExpenses      = 0;

            foreach (var e1 in expensesThisTravel)
            {
                sumOfExpenses = sumOfExpenses + (decimal)e1.ExpenseAmount;
            }

            ViewBag.NoOfExpenses  = noOfExpenses;
            ViewBag.SumOfExpenses = sumOfExpenses;

            ViewBag.SummaPlus = sumOfAll + sumOfExpenses;

            ViewBag.TravelReportId = travelReport.TravelReportId;

            ViewBag.Traktamente = (travelReport.Night != 0);


            return(View(travelReport));
        }
Ejemplo n.º 16
0
        // GET: Expenses/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Expense      expense            = db.Expenses.Find(id);
            TravelReport activeTravelReport = db.TravelReports.Find(expense.TravelReportId);

            if (expense == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ExpenseTypeId        = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName", expense.ExpenseTypeId);
            ViewBag.ActualTravelReportId = expense.TravelReportId;
            ViewBag.ActualExpenseTypeId  = expense.ExpenseTypeId;
            ViewBag.ActiveTravelReport   = activeTravelReport;
            var actualExpenseTypeName = db.ExpenseTypes.Where(e => e.ExpenseTypeId == expense.ExpenseTypeId).FirstOrDefault();

            ViewBag.ExpenseTypeName = actualExpenseTypeName.ExpenseTypeName;
            return(View(expense));
        }
Ejemplo n.º 17
0
        // GET: TravelReports/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TravelReport travelReport = db.TravelReports.Find(id);

            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            if (User.IsInRole("Assistant"))
            {
                var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();
                if (travelReport.ApplicationUserId != ActiveUser.Id)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.Forbidden));
                }
            }

            return(View(travelReport));
        }
Ejemplo n.º 18
0
        public ActionResult DeleteConfirmed(int id)
        {
            //check for expenses
            var checkForExpense = db.Expenses.Where(e => e.TravelReportId == id).FirstOrDefault();

            if (checkForExpense != null)
            {
                DeleteExpenses(id);
            }
            //check for notes
            var checkForNote = db.Notes.Where(e => e.TravelReportId == id).FirstOrDefault();

            if (checkForNote != null)
            {
                DeleteNotes(id);
            }

            TravelReport travelReport = db.TravelReports.Find(id);

            db.TravelReports.Remove(travelReport);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        public static TravelReportVM MapToView(this TravelReport model)
        {
            if (model == null)
            {
                return(null);
            }

            IQueryable <Expense> expenses = model.Expenses.AsQueryable();

            return(new TravelReportVM
            {
                Id = model.Id,
                EmployeeId = model.EmployeeId,
                Employee = model.Employee.MapToView(),
                CountryAllowanceId = model.CountryAllowanceId,
                //Country = model.Country.MapToView(),
                City = model.City,
                Departure = model.Departure,
                Return = model.Return,
                NumberOfMeals = model.NumberOfMeals,
                NumberOfHours = model.NumberOfHours,
                NumberOfAllowances = model.NumberOfAllowances,
                VehicleType = model.VehicleType,
                VehicleId = model.VehicleId,
                StartMileage = model.StartMileage,
                EndMileage = model.EndMileage,
                //Vehicle = model.Vehicle,
                CompanyVehicle = model.CompanyVehicle.MapToView(),
                ReasonForTravel = model.ReasonForTravel,
                Deposit = model.Deposit,
                DepositAmount = model.DepositAmount,
                ExpenseSum = model.ExpenseSum,
                Status = model.Status,
                Expenses = expenses.MapToViews()
            });
        }
Ejemplo n.º 20
0
        public ActionResult Calc([Bind(Include = "TravelReportId,ApplicationUserId,PatientId,TravelReportName,Destination,Purpose,DepartureDate,DepartureTime,ReturnDate,ReturnTime,DepartureHoursExtra,ReturnHoursExtra,FullDay,HalfDay,Night,BreakfastDeduction,LunchOrDinnerDeduction,LunchAndDinnerDeduction,AllMealsDeduction,StatusTypeId,Comment")] TravelReport travelReport, string button, string selectedUserId)
        {
            if (ModelState.IsValid)
            {
                var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();

                if (button == "Ändra traktamente")
                {
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Edit2", new { id = travelReport.TravelReportId }));
                }
                if (button == "Ny resekostnad")
                {
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Create", "Expenses", new { tId = travelReport.TravelReportId }));
                }
                if (button == "Skicka in")
                {
                    travelReport.StatusTypeId = db.StatusTypes.Where(stt => stt.StatusName == "Inskickad").FirstOrDefault().StatusTypeId;

                    SaveNote(travelReport);

                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { selectedUserId = selectedUserId }));
                }
                if (button == "Godkänd")
                {
                    travelReport.StatusTypeId = db.StatusTypes.Where(stt => stt.StatusName == "Godkänd").FirstOrDefault().StatusTypeId;

                    SaveNote(travelReport);

                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { selectedUserId = selectedUserId }));
                }
                if (button == "Ej godkänd")
                {
                    travelReport.StatusTypeId = db.StatusTypes.Where(stt => stt.StatusName == "Ej godkänd").FirstOrDefault().StatusTypeId;

                    SaveNote(travelReport);

                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { selectedUserId = selectedUserId }));
                }
                if (button == "Verifierad")
                {
                    travelReport.StatusTypeId = db.StatusTypes.Where(stt => stt.StatusName == "Verifierad").FirstOrDefault().StatusTypeId;

                    SaveNote(travelReport);

                    travelReport.Comment = Last2Notes(travelReport.TravelReportId);

                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    DeleteNotes(travelReport.TravelReportId);

                    return(RedirectToAction("Index", new { selectedUserId = selectedUserId }));
                }
                if (button == "Till listan")
                {
                    return(RedirectToAction("Index", new { selectedUserId = selectedUserId }));
                }
                if (button == "Ändra")
                {
                    db.Entry(travelReport).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Edit1", new { id = travelReport.TravelReportId }));
                }
                return(RedirectToAction("Calc", new { id = travelReport.TravelReportId }));
            }
            ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
            ViewBag.StatusTypeId      = new SelectList(db.StatusTypes, "StatusTypeId", "StatusName", travelReport.StatusTypeId);
            return(View(travelReport));
        }
Ejemplo n.º 21
0
        // GET: TravelReports/Edit2/5
        public ActionResult Edit2(int?id)
        {
            var          ActiveUser   = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();
            TravelReport travelReport = db.TravelReports.Find(id);

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (travelReport == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.ApplicationUserId = new SelectList(db.Users, "Id", "FullName", travelReport.ApplicationUserId);
            ViewBag.ApplicationUserId1 = ActiveUser.Id;
            ViewBag.StatusTypeId       = new SelectList(db.StatusTypes, "StatusTypeId", "StatusName", travelReport.StatusTypeId);
            //travelReport.TravelReportName = travelYear + "-" + TravelReportNumber.ToString().PadLeft(3, '0');

            TimeSpan differense = travelReport.ReturnDate - travelReport.DepartureDate;

            travelReport.Night = differense.Days;
            if (travelReport.Night == 0)
            {
                travelReport.HalfDay = 0;
                travelReport.FullDay = 0;
                ViewBag.Traktamente  = false;
            }
            else
            {
                travelReport.HalfDay = 0;
                travelReport.FullDay = travelReport.Night + 1;
                ViewBag.Traktamente  = true;


                if (travelReport.DepartureTime.Hours >= 12)
                {
                    travelReport.HalfDay++;
                    travelReport.FullDay--;
                }

                if (travelReport.ReturnTime.Hours <= 18)
                {
                    travelReport.HalfDay++;
                    travelReport.FullDay--;
                }

                if (travelReport.ReturnTime.Hours <= 5)
                {
                    travelReport.Night--;
                    if (travelReport.Night < 0)
                    {
                        travelReport.Night = 0;
                    }
                }
            }
            ViewBag.TravelReportId    = travelReport.TravelReportId;
            ViewBag.TravelReportName1 = travelReport.TravelReportName;


            return(View(travelReport));
        }
Ejemplo n.º 22
0
        public ActionResult Create([Bind(Include = "TravelReportId,ApplicationUserId,TravelReportName,Destination,Purpose,DepartureDate,DepartureTime,ReturnDate,ReturnTime,DepartureHoursExtra,ReturnHoursExtra,FullDay,HalfDay,Night,BreakfastReduction,LunchReduction,DinnerReduction,StatusTypeId,Comment")] TravelReport travelReport)
        {
            var ActiveUser = db.Users.Where(u => u.UserName == User.Identity.Name.ToString()).ToList().FirstOrDefault();

            string travelYear            = travelReport.DepartureDate.Year.ToString();
            var    TravelReportsSameYear = db.TravelReports.Where(t => t.ApplicationUserId == ActiveUser.Id && t.TravelReportName.Substring(0, 4) == travelYear).OrderByDescending(a => a.TravelReportName);
            int    TravelReportNumber;

            if (TravelReportsSameYear.Count() == 0)
            {
                TravelReportNumber = 1;
            }
            else
            {
                TravelReportNumber = Int32.Parse(TravelReportsSameYear.FirstOrDefault().TravelReportName.Substring(5, 3));
                TravelReportNumber = TravelReportNumber + 1;
            }
            //travelReport.TravelReportName = "Testarnamn";
            travelReport.TravelReportName = travelYear + "-" + TravelReportNumber.ToString().PadLeft(3, '0');

            TimeSpan differense = travelReport.ReturnDate - travelReport.DepartureDate;

            travelReport.Night = differense.Days;
            if (travelReport.Night == 0)
            {
                travelReport.HalfDay = 0;
                travelReport.FullDay = 0;
                ViewBag.Traktamente  = false;
            }
            else
            {
                travelReport.HalfDay = 0;
                travelReport.FullDay = travelReport.Night + 1;
                ViewBag.Traktamente  = true;


                if (travelReport.DepartureTime.Hours >= 12)
                {
                    travelReport.HalfDay++;
                    travelReport.FullDay--;
                }

                if (travelReport.ReturnTime.Hours <= 18)
                {
                    travelReport.HalfDay++;
                    travelReport.FullDay--;
                }

                if (travelReport.ReturnTime.Hours <= 5)
                {
                    travelReport.Night--;
                    if (travelReport.Night < 0)
                    {
                        travelReport.Night = 0;
                    }
                }
            }

            if (ModelState.IsValid)
            {
                db.TravelReports.Add(travelReport);
                db.SaveChanges();
                return(RedirectToAction("Edit2", new { id = travelReport.TravelReportId }));
            }

            ViewBag.StatusName         = db.StatusTypes.FirstOrDefault().StatusName;
            ViewBag.StatusTypeId1      = db.StatusTypes.Where(stt => stt.StatusName == "Ny").FirstOrDefault().StatusTypeId;
            ViewBag.ApplicationUserId1 = ActiveUser.Id;

            return(View(travelReport));
        }
Ejemplo n.º 23
0
        public ActionResult Create([Bind(Include = "ExpenseId,ExpenseTypeId,ExpenseDescription,ExpenseDate,ExpenseAmountInfo,ExpenseAmount,ExpenseMilage,TravelReportId")] Expense expense)
        {
            string faultMessage = null;

            TravelReport activeTravelReport = db.TravelReports.Find(expense.TravelReportId);;

            ViewBag.ExpenseTypeId        = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName");
            ViewBag.ActualTravelReportId = expense.TravelReportId;
            ViewBag.ActiveTravelReport   = activeTravelReport;


            if (expense.ExpenseTypeId == 4) // 4 = Driving own car.
            {
                if (expense.ExpenseMilage > 0)
                {
                    // Calulate: ExpenseAmount = ExpenseMilage * Milage from LegalAmount for valid year.
                    //ViewBag.ActualTravelReportId = expense.TravelReportId;
                    //var activeLegalMilage = db.LegalAmounts.Where(l => l.ValidDate <= expense.ExpenseDate);
                    var      activeLegalMilage       = db.LegalAmounts.Where(l => l.ValidDate <= expense.ExpenseDate).OrderBy(l => l.ValidDate).FirstOrDefault();
                    DateTime actualValidDate         = DateTime.Parse("2013-01-01");
                    float    actualLegalMilageAmount = 0;
                    expense.ExpenseAmount   = 0;
                    actualLegalMilageAmount = activeLegalMilage.MilageAmount;
                    expense.ExpenseAmount   = (decimal)((actualLegalMilageAmount) * (expense.ExpenseMilage) / 100);
                }
                else if ((expense.ExpenseMilage == 0) || (expense.ExpenseMilage == null))
                {
                    // There is no amount in ExpenseMilage. Error message in Tempdata.
                    expense.ExpenseAmount     = 0;
                    expense.ExpenseAmountInfo = null;
                    expense.ExpenseMilage     = 0;
                    faultMessage          = "Resa med bil, ange antal kilometer";
                    ViewBag.ErrorMsg      = faultMessage;
                    ViewBag.ExpenseTypeId = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName", expense.ExpenseTypeId);
                    return(View(expense));
                }
            }

            if (expense.ExpenseTypeId != 4)
            {
                if ((expense.ExpenseAmountInfo == null))
                {
                    expense.ExpenseMilage = 0;
                    expense.ExpenseAmount = 0;
                    faultMessage          = "Ange kostnad för utgiften";
                    ViewBag.ErrorMsg      = faultMessage;
                    ViewBag.ExpenseTypeId = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName", expense.ExpenseTypeId);
                    return(View(expense));
                }
                else if (expense.ExpenseAmountInfo != null)
                {
                    expense.ExpenseMilage = 0;

                    expense.ExpenseAmount = AmountCheck(expense.ExpenseAmountInfo);
                }
            }

            if (ModelState.IsValid)
            {
                db.Expenses.Add(expense);
                db.SaveChanges();
                return(RedirectToAction("Index", new { tId = expense.TravelReportId }));
            }
            ViewBag.ExpenseTypeId = new SelectList(db.ExpenseTypes, "ExpenseTypeId", "ExpenseTypeName", expense.ExpenseTypeId);
            return(View(expense));
        }