| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -12,12 +12,14 @@ import java.math.BigDecimal;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.ArrayList;
 | 
					 | 
					 | 
					 | 
					import java.util.ArrayList;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.Calendar;
 | 
					 | 
					 | 
					 | 
					import java.util.Calendar;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.Collections;
 | 
					 | 
					 | 
					 | 
					import java.util.Collections;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.Date;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.List;
 | 
					 | 
					 | 
					 | 
					import java.util.List;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import java.util.concurrent.TimeUnit;
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.hibernate.LazyInitializationException;
 | 
					 | 
					 | 
					 | 
					import org.hibernate.LazyInitializationException;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.hibernate.Query;
 | 
					 | 
					 | 
					 | 
					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.beans.factory.annotation.Autowired;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.springframework.security.access.prepost.PreAuthorize;
 | 
					 | 
					 | 
					 | 
					import org.springframework.security.access.prepost.PreAuthorize;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import org.springframework.transaction.annotation.Transactional;
 | 
					 | 
					 | 
					 | 
					import org.springframework.transaction.annotation.Transactional;
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -33,7 +35,9 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							TripBill bill = new TripBill();
 | 
					 | 
					 | 
					 | 
							TripBill bill = new TripBill();
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
							
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							bill.setRequirement(requirement);
 | 
					 | 
					 | 
					 | 
							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++) {
 | 
					 | 
					 | 
					 | 
							for (int i = 0 ; i < daysCount ; i++) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								TripBillItem item = new TripBillItem();
 | 
					 | 
					 | 
					 | 
								TripBillItem item = new TripBillItem();
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -91,49 +95,35 @@ public class TripBillServiceImpl extends AbstractOwnedService<TripBill> implemen
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						}
 | 
					 | 
					 | 
					 | 
						}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						
 | 
					 | 
					 | 
					 | 
						
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
						private void calculateItem(TripBillItem item) {
 | 
					 | 
					 | 
					 | 
						private void calculateItem(TripBillItem item) {
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Calendar cal = Calendar.getInstance();
 | 
					 | 
					 | 
					 | 
							LocalTime timeTo;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Date to = item.getToArrival();
 | 
					 | 
					 | 
					 | 
							LocalTime timeBack;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
							boolean allDay = false;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (to == null) {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								to = new Date();
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.setTime(to);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.set(Calendar.HOUR_OF_DAY, 0);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.set(Calendar.MINUTE, 0);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							} else {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.setTime(to);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							}
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.DAY_OF_MONTH, 1);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.MONTH, 1);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.YEAR, 2000);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							to.setTime(cal.getTimeInMillis());
 | 
					 | 
					 | 
					 | 
							if (item.getToArrival() == null) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
								timeTo = (new LocalTime()).withHourOfDay(0).withMinuteOfHour(0);
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Date back = item.getBackDeparture();
 | 
					 | 
					 | 
					 | 
							} else {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									
 | 
					 | 
					 | 
					 | 
								timeTo = new LocalTime(item.getToArrival());
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (back == null) {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								back = new Date(to.getTime());
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							}
 | 
					 | 
					 | 
					 | 
							}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
									
 | 
					 | 
					 | 
					 | 
									
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.setTime(back);
 | 
					 | 
					 | 
					 | 
							if (item.getBackDeparture() == null) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
								timeBack = (new LocalTime()).withHourOfDay(23).withMinuteOfHour(59);
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (back.equals(to)) {
 | 
					 | 
					 | 
					 | 
								allDay = true;
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.set(Calendar.HOUR_OF_DAY, 23);
 | 
					 | 
					 | 
					 | 
							} else {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								cal.set(Calendar.MINUTE, 59);
 | 
					 | 
					 | 
					 | 
								timeBack = new LocalTime(item.getBackDeparture());
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							}
 | 
					 | 
					 | 
					 | 
							}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
							
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.DAY_OF_MONTH, 1);
 | 
					 | 
					 | 
					 | 
							if (timeTo.isAfter(timeBack)) {
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.MONTH, 1);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							cal.set(Calendar.YEAR, 2000);
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							back.setTime(cal.getTimeInMillis());
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							if (to.getTime() > back.getTime()) {
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								item.setTotal(BigDecimal.ZERO);
 | 
					 | 
					 | 
					 | 
								item.setTotal(BigDecimal.ZERO);
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
								return; 
 | 
					 | 
					 | 
					 | 
								return; 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							}
 | 
					 | 
					 | 
					 | 
							}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							
 | 
					 | 
					 | 
					 | 
							
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							SettingsData settings = globalSettings.getSettings();
 | 
					 | 
					 | 
					 | 
							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;
 | 
					 | 
					 | 
					 | 
							int refundHour = 0;
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							List<Integer> refundHours = new ArrayList<Integer>(settings.getRefunds().keySet());
 | 
					 | 
					 | 
					 | 
							List<Integer> refundHours = new ArrayList<Integer>(settings.getRefunds().keySet());
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
							Collections.sort(refundHours);
 | 
					 | 
					 | 
					 | 
							Collections.sort(refundHours);
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |