Search in sources :

Example 1 with GlobalHourReport

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;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) GlobalHourReport(com.autentia.tnt.businessobject.GlobalHourReport) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Activity(com.autentia.tnt.businessobject.Activity) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Example 2 with GlobalHourReport

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();
    }
}
Also used : User(com.autentia.tnt.businessobject.User) GlobalHourReport(com.autentia.tnt.businessobject.GlobalHourReport) GlobalHoursReportBean(com.autentia.tnt.bean.activity.GlobalHoursReportBean) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) PrintWriter(java.io.PrintWriter)

Example 3 with GlobalHourReport

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;
}
Also used : User(com.autentia.tnt.businessobject.User) GlobalHourReport(com.autentia.tnt.businessobject.GlobalHourReport) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 4 with GlobalHourReport

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;
}
Also used : GlobalHourReport(com.autentia.tnt.businessobject.GlobalHourReport) User(com.autentia.tnt.businessobject.User) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Aggregations

GlobalHourReport (com.autentia.tnt.businessobject.GlobalHourReport)4 User (com.autentia.tnt.businessobject.User)3 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 GlobalHoursReportBean (com.autentia.tnt.bean.activity.GlobalHoursReportBean)1 Activity (com.autentia.tnt.businessobject.Activity)1 Project (com.autentia.tnt.businessobject.Project)1 SortCriteria (com.autentia.tnt.dao.SortCriteria)1 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)1 PrintWriter (java.io.PrintWriter)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1