forked from johnrogers104/PointOfSaleSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRental1.java
63 lines (55 loc) · 1.86 KB
/
Rental1.java
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ProcessSale;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
*
* @author tjb317
*/
public class Rental1 {
// Class variables
String type;
PersistentStorage storage;
Sale finalSale;
// Constructor
public Rental1(Sale finalSale, String type) {
this.type = type;
this.finalSale = finalSale;
storage = PersistentStorage.getInstance();
}
// Upload the rental to the database
public boolean finalizeRental() {
// Variables used
DateFormat formatter = new SimpleDateFormat("ddMMyyyy");
Date dt = finalSale.time;
String date = formatter.format(dt);
Calendar c = Calendar.getInstance();
c.setTime(dt);
c.add(Calendar.DATE, 30);
dt = c.getTime();
String returnDate = formatter.format(dt);
// Check to make sure rental is connected to credit card
if (type.equalsIgnoreCase("cash")) {
System.out.println("We do not accept cash for Rentals, please use a credit card");
return false;
} else {
try {
Integer.parseInt(type);
for (SalesLineItem item: finalSale.cart) {
String id = Integer.toString( (int)(Math.random() * 1000 + 1) );
storage.makePayment(id, "Rent", item.getPrice(), item.quantity, "Card", date, returnDate, type);
}
} catch (NumberFormatException e) {
System.out.println("Error: not a credit card number");
return false;
}
}
return true;
}
}