Skip to content

Commit

Permalink
additional logic taking into account vehicle sold date.
Browse files Browse the repository at this point in the history
  • Loading branch information
hargata committed Jan 24, 2025
1 parent 4c60bb2 commit ebf6388
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Controllers/Vehicle/ReportController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,17 @@ public IActionResult GetCostTableForVehicle(int vehicleId, int year = 0)
var totalDays = 0;
if (year != default)
{
if (year == DateTime.Now.Year)
if (year == DateTime.Now.Year) //current year selected, do math based on how many days have elapsed.
{
totalDays = DateTime.Now.DayOfYear;
if (!string.IsNullOrWhiteSpace(vehicleData.SoldDate)) //if vehicle is sold in current year, cap the number of days to sold date.
{
var endDate = DateTime.Parse(vehicleData.SoldDate);
if (endDate.Year == DateTime.Now.Year)
{
totalDays = endDate.DayOfYear;
}
}
} else
{
totalDays = DateTime.IsLeapYear(year) ? 366 : 365;
Expand Down

0 comments on commit ebf6388

Please sign in to comment.