mirror of
https://github.com/hargata/lubelog.git
synced 2025-12-11 04:37:03 -06:00
add depreciation calculation
This commit is contained in:
parent
a92d422972
commit
c2a7f39025
@ -1336,19 +1336,36 @@ namespace CarCareTracker.Controllers
|
|||||||
if (!string.IsNullOrWhiteSpace(vehicleHistory.VehicleData.PurchaseDate))
|
if (!string.IsNullOrWhiteSpace(vehicleHistory.VehicleData.PurchaseDate))
|
||||||
{
|
{
|
||||||
var endDate = vehicleHistory.VehicleData.SoldDate;
|
var endDate = vehicleHistory.VehicleData.SoldDate;
|
||||||
|
int daysOwned = 0;
|
||||||
if (string.IsNullOrWhiteSpace(endDate))
|
if (string.IsNullOrWhiteSpace(endDate))
|
||||||
{
|
{
|
||||||
endDate = DateTime.Now.ToShortDateString();
|
endDate = DateTime.Now.ToShortDateString();
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
vehicleHistory.DaysOwned = (DateTime.Parse(endDate) - DateTime.Parse(vehicleHistory.VehicleData.PurchaseDate)).Days.ToString("N0");
|
daysOwned = (DateTime.Parse(endDate) - DateTime.Parse(vehicleHistory.VehicleData.PurchaseDate)).Days;
|
||||||
|
vehicleHistory.DaysOwned = daysOwned.ToString("N0");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex.Message);
|
_logger.LogError(ex.Message);
|
||||||
vehicleHistory.DaysOwned = string.Empty;
|
vehicleHistory.DaysOwned = string.Empty;
|
||||||
}
|
}
|
||||||
|
//calculate depreciation
|
||||||
|
var totalDepreciation = vehicleHistory.VehicleData.PurchasePrice - vehicleHistory.VehicleData.SoldPrice;
|
||||||
|
//we only calculate depreciation if a sold price is provided.
|
||||||
|
if (totalDepreciation != default && vehicleHistory.VehicleData.SoldPrice != default)
|
||||||
|
{
|
||||||
|
vehicleHistory.TotalDepreciation = totalDepreciation;
|
||||||
|
if (daysOwned != default)
|
||||||
|
{
|
||||||
|
vehicleHistory.DepreciationPerDay = Math.Abs(totalDepreciation / daysOwned);
|
||||||
|
}
|
||||||
|
if (distanceTraveled != default)
|
||||||
|
{
|
||||||
|
vehicleHistory.DepreciationPerMile = Math.Abs(totalDepreciation / distanceTraveled);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
List<GenericReportModel> reportData = new List<GenericReportModel>();
|
List<GenericReportModel> reportData = new List<GenericReportModel>();
|
||||||
var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId);
|
var serviceRecords = _serviceRecordDataAccess.GetServiceRecordsByVehicleId(vehicleId);
|
||||||
|
|||||||
@ -13,5 +13,8 @@
|
|||||||
public decimal TotalCostPerMile { get; set; }
|
public decimal TotalCostPerMile { get; set; }
|
||||||
public decimal TotalGasCostPerMile { get; set; }
|
public decimal TotalGasCostPerMile { get; set; }
|
||||||
public string DistanceUnit { get; set; }
|
public string DistanceUnit { get; set; }
|
||||||
|
public decimal TotalDepreciation { get; set; }
|
||||||
|
public decimal DepreciationPerDay { get; set; }
|
||||||
|
public decimal DepreciationPerMile { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,30 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr />
|
<hr />
|
||||||
|
@if (Model.TotalDepreciation != default)
|
||||||
|
{
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-3">
|
||||||
|
@(Model.TotalDepreciation > 0 ? translator.Translate(userLanguage, "Depreciation") : translator.Translate(userLanguage, "Appreciation"))
|
||||||
|
</div>
|
||||||
|
<div class="col-3">
|
||||||
|
<span><i class="bi @(Model.TotalDepreciation > 0 ? "bi-graph-down-arrow" : "bi-graph-up-arrow") me-2"></i>@Math.Abs(Model.TotalDepreciation).ToString("C")</span>
|
||||||
|
</div>
|
||||||
|
@if (Model.DepreciationPerDay != default)
|
||||||
|
{
|
||||||
|
<div class="col-3">
|
||||||
|
<span><i class="bi bi-calendar-event me-2"></i>@($"{Model.DepreciationPerDay.ToString("C")}/{translator.Translate(userLanguage, "day")}")</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if (Model.DepreciationPerMile != default)
|
||||||
|
{
|
||||||
|
<div class="col-3">
|
||||||
|
<span><i class="bi bi-speedometer me-2"></i>@($"{Model.DepreciationPerMile.ToString("C")}/{Model.DistanceUnit}")</span>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user