-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoice.cs
81 lines (67 loc) · 2.32 KB
/
Invoice.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Vehicle_Rental_System
{
internal class Invoice
{
public Vehicle Vehicle { get; set; }
public Invoice(Vehicle vehicle)
{
Vehicle = vehicle;
}
// checks if the vehicle is returned earlier to show additional messages
public bool IsEarlyReturned()
{
return Vehicle.ReturnDate < Vehicle.EndDate;
}
public decimal GetTotalPrice()
{
return Math.Round(GetTotalRentalCosts() + GetElapsedDaysInsurance(), 2);
}
public decimal GetDailyInsuranceDiscount()
{
return Math.Round(Vehicle.DailyInsuranceCost() - Vehicle.AdjustDailyInsuranceCost(), 2);
}
public decimal GetEarlyReturnInsuranceDiscount()
{
return Math.Round(RemainingDays() * Vehicle.AdjustDailyInsuranceCost(), 2);
}
public decimal RemainingDays()
{
return (Vehicle.EndDate - Vehicle.ReturnDate).Days;
}
public decimal EarlyReturnDiscountForRent()
{
return (RemainingDays() * Vehicle.GetDailyRentalCost()) / 2;
}
decimal GetTotalRentCost()
{
return Vehicle.GetDailyRentalCost() * Vehicle.ReservationPeriod();
}
public decimal GetElapsedDaysInsurance()
{
// insurance is full price for elapsed days and NOT paid for the remaining days
return Vehicle.AdjustDailyInsuranceCost() * Vehicle.ActualRentalPeriod();
}
public decimal GetTotalRentalCosts()
{
// full cost for the elapsed days and half for the rest, if returned ahead of time
if (Vehicle.ActualRentalPeriod() < Vehicle.ReservationPeriod())
{
// find how many days are left until the end date and apply discount
EarlyReturnDiscountForRent();
return GetTotalRentCost() - EarlyReturnDiscountForRent();
}
// calc full cost for the elapsed days
return GetTotalRentCost();
}
public void PrintInvoice()
{
InvoicePrinter printer = new ();
InvoicePrinter.DisplayInvoice(this);
}
}
}