diff --git a/pom.xml b/pom.xml index 43dde998..215a470a 100644 --- a/pom.xml +++ b/pom.xml @@ -326,6 +326,13 @@ mail 1.4.3 + + + + joda-time + joda-time + 2.4 + diff --git a/src/main/java/info/bukova/isspst/Constants.java b/src/main/java/info/bukova/isspst/Constants.java index 78ec2a99..92e28a19 100644 --- a/src/main/java/info/bukova/isspst/Constants.java +++ b/src/main/java/info/bukova/isspst/Constants.java @@ -95,7 +95,8 @@ public class Constants { public final static ReportMapping REPORTS[] = { new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address")), new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresa", "address", false, true)), - new ReportMapping(MOD_TRIPBILL, new Report("Žádost", "tripRequirement", false, true)) + new ReportMapping(MOD_TRIPBILL, new Report("Žádost", "tripRequirement", false, true)), + new ReportMapping(MOD_TRIPBILL, new Report("Vyúčtování", "tripBill", false, true)) }; public final static String REQTYPE_ORDER = "ORDER"; diff --git a/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java b/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java index 2e9f171d..91c2e662 100644 --- a/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/tripbill/TripBillServiceImpl.java @@ -12,12 +12,14 @@ import java.math.BigDecimal; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; -import java.util.Date; import java.util.List; -import java.util.concurrent.TimeUnit; import org.hibernate.LazyInitializationException; import org.hibernate.Query; +import org.joda.time.DateTime; +import org.joda.time.Days; +import org.joda.time.Hours; +import org.joda.time.LocalTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; @@ -33,7 +35,9 @@ public class TripBillServiceImpl extends AbstractOwnedService implemen TripBill bill = new TripBill(); bill.setRequirement(requirement); - long daysCount = TimeUnit.DAYS.convert(requirement.getEndDate().getTime() - requirement.getTripDate().getTime(), TimeUnit.MILLISECONDS) + 1; + + int daysCount = Days.daysBetween((new DateTime(requirement.getTripDate())).withTimeAtStartOfDay(), + (new DateTime(requirement.getEndDate())).withTimeAtStartOfDay()).getDays() + 1; for (int i = 0 ; i < daysCount ; i++) { TripBillItem item = new TripBillItem(); @@ -91,49 +95,35 @@ public class TripBillServiceImpl extends AbstractOwnedService implemen } private void calculateItem(TripBillItem item) { - Calendar cal = Calendar.getInstance(); - Date to = item.getToArrival(); - - if (to == null) { - to = new Date(); - cal.setTime(to); - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.MINUTE, 0); + LocalTime timeTo; + LocalTime timeBack; + boolean allDay = false; + + if (item.getToArrival() == null) { + timeTo = (new LocalTime()).withHourOfDay(0).withMinuteOfHour(0); } else { - cal.setTime(to); + timeTo = new LocalTime(item.getToArrival()); } - - cal.set(Calendar.DAY_OF_MONTH, 1); - cal.set(Calendar.MONTH, 1); - cal.set(Calendar.YEAR, 2000); - - to.setTime(cal.getTimeInMillis()); - - Date back = item.getBackDeparture(); - if (back == null) { - back = new Date(to.getTime()); - } - - cal.setTime(back); - - if (back.equals(to)) { - cal.set(Calendar.HOUR_OF_DAY, 23); - cal.set(Calendar.MINUTE, 59); + if (item.getBackDeparture() == null) { + timeBack = (new LocalTime()).withHourOfDay(23).withMinuteOfHour(59); + allDay = true; + } else { + timeBack = new LocalTime(item.getBackDeparture()); } - cal.set(Calendar.DAY_OF_MONTH, 1); - cal.set(Calendar.MONTH, 1); - cal.set(Calendar.YEAR, 2000); - back.setTime(cal.getTimeInMillis()); - - if (to.getTime() > back.getTime()) { + if (timeTo.isAfter(timeBack)) { item.setTotal(BigDecimal.ZERO); return; } SettingsData settings = globalSettings.getSettings(); - long hours = TimeUnit.HOURS.convert(back.getTime() - to.getTime(), TimeUnit.MILLISECONDS); + int hours = Hours.hoursBetween(timeTo, timeBack).getHours(); + + if (allDay) { + ++hours; + } + int refundHour = 0; List refundHours = new ArrayList(settings.getRefunds().keySet()); Collections.sort(refundHours); diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jasper b/src/main/webapp/WEB-INF/reports/tripBill.jasper new file mode 100644 index 00000000..b58fe220 Binary files /dev/null and b/src/main/webapp/WEB-INF/reports/tripBill.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripBill.jrxml b/src/main/webapp/WEB-INF/reports/tripBill.jrxml new file mode 100644 index 00000000..70cb63c0 --- /dev/null +++ b/src/main/webapp/WEB-INF/reports/tripBill.jrxml @@ -0,0 +1,359 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jasper b/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jasper new file mode 100644 index 00000000..2683be74 Binary files /dev/null and b/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jrxml b/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jrxml new file mode 100644 index 00000000..e433d924 --- /dev/null +++ b/src/main/webapp/WEB-INF/reports/tripBillFreeMeals.jrxml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/webapp/WEB-INF/reports/tripBillItems.jasper b/src/main/webapp/WEB-INF/reports/tripBillItems.jasper new file mode 100644 index 00000000..a5f52472 Binary files /dev/null and b/src/main/webapp/WEB-INF/reports/tripBillItems.jasper differ diff --git a/src/main/webapp/WEB-INF/reports/tripBillItems.jrxml b/src/main/webapp/WEB-INF/reports/tripBillItems.jrxml new file mode 100644 index 00000000..dd856994 --- /dev/null +++ b/src/main/webapp/WEB-INF/reports/tripBillItems.jrxml @@ -0,0 +1,593 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +