use of com.autentia.tnt.businessobject.GlobalHourReport in project TNTConcept by autentia.
the class GlobalHoursReportBean method getAll.
public List<GlobalHourReport> getAll() {
// Retrieve activities for every User during that period of time
ActivitySearch search = new ActivitySearch();
Calendar init = Calendar.getInstance();
init.setTime(startDate);
Calendar last = Calendar.getInstance();
last.setTime(endDate);
init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));
last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));
search.setStartStartDate(init.getTime());
search.setEndStartDate(last.getTime());
List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>();
if (billable)
search.setBillable(true);
// Search activities during indicated dates
List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));
for (Activity act : activities) {
Project proj = act.getRole().getProject();
GlobalHourReport unit = new GlobalHourReport();
unit.setProject(proj);
// an entry in the list represents a project
if (!listGlobal.contains(unit))
listGlobal.add(unit);
// Retrieve the stored unit and save hours
GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit));
float horas = act.getDuration() / 60.0f;
storedUnit.setUserHours(act.getUser(), horas);
storedUnit.setIterator(usuarios.iterator());
}
return listGlobal;
}
use of com.autentia.tnt.businessobject.GlobalHourReport in project TNTConcept by autentia.
the class GlobalHoursReportCSVServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String pStartDate = req.getParameter("startDate");
String pEndDate = req.getParameter("endDate");
String pBillable = req.getParameter("billable");
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
StringBuilder csvReport = new StringBuilder();
GlobalHoursReportBean ghReportBean = (GlobalHoursReportBean) req.getSession().getAttribute("globalHoursReportBean");
PrintWriter writer = resp.getWriter();
try {
Date startDate = sdf.parse(pStartDate);
Date endDate = sdf.parse(pEndDate);
boolean billable = Boolean.valueOf(pBillable);
ghReportBean.setEndDate(endDate);
ghReportBean.setStartDate(startDate);
ghReportBean.setBillable(billable);
List<User> users = ghReportBean.getUsers();
List<GlobalHourReport> globalHourReports = ghReportBean.getAll();
csvReport.append(getCSVHeader(users));
csvReport.append(getCSVBody(globalHourReports));
csvReport.append(getCSVFooter(users, globalHourReports));
resp.setContentType("text/csv");
resp.setContentLength(csvReport.length());
writer.append(csvReport.toString());
} catch (ParseException e) {
Log.error("Error en el parseo ", e);
} finally {
writer.close();
}
}
use of com.autentia.tnt.businessobject.GlobalHourReport in project TNTConcept by autentia.
the class GlobalHoursReportCSVServlet method getCSVFooter.
private StringBuilder getCSVFooter(List<User> users, List<GlobalHourReport> globalHourReports) {
StringBuilder sbFooter = new StringBuilder();
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator(',');
DecimalFormat formatter = new DecimalFormat("#0.00", symbols);
sbFooter.append("\"\"").append(CSV_SEPARATOR).append("\"TOTAL\"");
double totalHours = 0;
double totalCost = 0;
for (User user : users) {
double userTotalHours = 0;
for (GlobalHourReport report : globalHourReports) {
userTotalHours += report.getUserHours(user);
}
sbFooter.append(CSV_SEPARATOR).append("\"").append(formatter.format(userTotalHours)).append("\"").append(CSV_SEPARATOR).append("\"").append(formatter.format(userTotalHours * user.getSalaryPerHour())).append("\"");
totalHours += userTotalHours;
totalCost += userTotalHours * user.getSalaryPerHour();
}
sbFooter.append(CSV_SEPARATOR).append("\"").append(formatter.format(totalHours)).append("\"").append(CSV_SEPARATOR).append("\"").append(formatter.format(totalCost)).append("\"").append("\r\n");
return sbFooter;
}
use of com.autentia.tnt.businessobject.GlobalHourReport in project TNTConcept by autentia.
the class GlobalHoursReportCSVServlet method getCSVBody.
private StringBuilder getCSVBody(List<GlobalHourReport> globalHourReports) {
StringBuilder sbBody = new StringBuilder();
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator(',');
DecimalFormat formatter = new DecimalFormat("#0.00", symbols);
for (GlobalHourReport report : globalHourReports) {
String organization = report.getProject().getClient().getName();
String project = report.getProject().getName();
java.util.Iterator<User> users = report.getIterator();
double totalHours = 0;
double totalCost = 0;
sbBody.append("\"").append(organization).append("\"").append(CSV_SEPARATOR).append("\"").append(project).append("\"");
while (users.hasNext()) {
User user = users.next();
double userProjectCost = report.getUserHours(user) * user.getSalaryPerHour();
totalHours += report.getUserHours(user);
totalCost += userProjectCost;
sbBody.append(CSV_SEPARATOR).append("\"").append(formatter.format(report.getUserHours(user))).append("\"").append(CSV_SEPARATOR).append("\"").append(formatter.format(userProjectCost)).append("\"");
}
sbBody.append(CSV_SEPARATOR).append("\"").append(formatter.format(totalHours)).append("\"").append(CSV_SEPARATOR).append("\"").append(formatter.format(totalCost)).append("\"").append("\r\n");
}
return sbBody;
}
Aggregations