Пример #1
0
    @Override
    protected void createResultTable(Table table, Query.Result result) throws SQLException {
      Table.Row row = table.tr();
      row.th().text(t8("employees.name")).style(CSS.WIDTH, "100%");

      Table.Header h = row.th();
      h.img(new URL("/images/email.png")).setAttr(Image.CLASS, "icon");
      h.text(t8("users.eMail"));
      row.th().text(t8("users.mobilePhone"));
      row.th().text(t8("employees.employmentType"));
      row.th().text(t8("status"));
      row.th().text(t8("pay.slip.latest"));
      row.th();

      while (result.next()) {
        Employee e = Employee.table.loadRec(cx(), result);
        row = table.tr();

        Table.Data d = row.td();
        d.a(e.url(), e.user().fullName());

        row.td().a(new URL("mailto: %s", e.user().eMail()), e.user().eMail());
        row.td().text(e.user().mobilePhone());

        row.td().text(t8(String.format("employmentType.%s", e.employmentType().name())));

        d = row.td();
        if (!e.isActive()) {
          d.text(t8("inactive"));
        } else if (result.getInt(assignmentCountQuery) == 0) {
          d.text(t8("available"));
        } else {
          d.text(t8("busy"));
        }

        d = row.td();
        if (!result.isNull(PaySlip.table.END_DATE)) {
          PaySlip p = PaySlip.table.loadRec(cx(), result);
          PaySlip.table.EMPLOYEE.setValue(p, e);
          d.a(p.url(), cx().formatDate(p.endDate()));
        }

        d = row.td();
        d.style(CSS.TEXT_ALIGN, "center");
        d.a(e.url()).img(new URL("/images/open.png"));
      }
    }
Пример #2
0
    private void loadContacts() throws SQLException {
      Query q =
          Employee.table
              .query()
              .select(Employee.table, Im4ixUser.table)
              .join(Employee.table.USER)
              .where(SQL.eq(Employee.table.IS_CONTACT, true))
              .orderBy(Im4ixUser.table.FIRST_NAME, Im4ixUser.table.LAST_NAME);

      contactField.addOption(cx().t8("all.contacts"), "", null);
      try (Query.Result qr = q.exec(cx())) {
        while (qr.next()) {
          Employee e = Employee.table.loadRec(cx(), qr);
          Employee.table.USER.loadRefRec(e, qr);
          contactField.addOption(e.user().fullName(), e.user().name(), e);
        }
      }
    }
Пример #3
0
 private void loadAssignments(final Date startDate, final Date endDate) throws SQLException {
   try (Query.Result qr =
       Assignment.table
           .query()
           .select(Assignment.table)
           .join(Assignment.table.EMPLOYEE)
           .where(
               Employee.table.USER.eq(cx.currentUser()),
               SQL.gte(Assignment.table.END_DATE, startDate),
               SQL.lte(Assignment.table.START_DATE, endDate),
               SQL.not(SQL.eq(Assignment.table.PAY_RATE, BigDecimal.ZERO)))
           .orderBy(SQL.desc(Assignment.table.START_DATE), SQL.desc(Assignment.table.END_DATE))
           .exec(cx)) {
     while (qr.next()) {
       assignments.add(Assignment.table.loadRec(cx, qr));
     }
   }
 }
Пример #4
0
    private void loadSlips() throws SQLException {
      Query q =
          PaySlip.table
              .query()
              .select(PaySlip.table.START_DATE)
              .join(Employee.table, PaySlip.table.EMPLOYEE.joinCond())
              .join(Im4ixUser.table, Employee.table.USER.joinCond())
              .where(Im4ixUser.table.primaryKey().eq(cx().currentUser()))
              .orderBy(SQL.desc(PaySlip.table.START_DATE));

      Set<Integer> years = new TreeSet<>();

      try (Query.Result qr = q.exec(cx())) {
        while (qr.next()) {
          years.add(qr.getDate(PaySlip.table.START_DATE).getYear() + 1900);
        }
      }

      years.forEach(
          (y) -> {
            String n = y.toString();
            yearField.addOption(n, n, y);
          });
    }
Пример #5
0
    private void createCanvas(final DOM container) throws SQLException {
      d = container.div();
      c = d.canvas();
      c.style(CSS.HEIGHT, "30em").style(CSS.MAX_WIDTH, "1160px");
      d.br();

      final int year = yearField.selectedObject();
      final Date startDate = cx.tz().newDate(year, 1, 1);
      final Date endDate = cx.tz().newDate(year, 12, 31);
      loadAssignments(startDate, endDate);

      final List<String> labels = new ArrayList<>();
      final List<BigDecimal> maxPayBuffers = new ArrayList<>();
      final List<BigDecimal> payCosts = new ArrayList<>();
      final List<BigDecimal> payBuffers = new ArrayList<>();
      final List<BigDecimal> vacationDeductions = new ArrayList<>();
      final List<BigDecimal> otherCosts = new ArrayList<>();

      try (Query.Result qr =
          PaySlip.table
              .query()
              .select(
                  PaySlip.table.START_DATE,
                  PaySlip.table.END_DATE,
                  PaySlip.table.GROSS_PAY,
                  PaySlip.table.GENERAL_PAYROLL_TAX,
                  PaySlip.table.OUTGOING_PAY_BUFFER,
                  PaySlip.table.INCOMING_PAY_BUFFER,
                  PaySlip.table.VACATION_DEDUCTION,
                  PaySlip.table.TOTAL_COST)
              .join(Employee.table, PaySlip.table.EMPLOYEE.joinCond())
              .join(Im4ixUser.table, Employee.table.USER.joinCond())
              .where(
                  Im4ixUser.table.primaryKey().eq(cx().currentUser()),
                  SQL.lte(PaySlip.table.START_DATE, endDate),
                  SQL.gte(PaySlip.table.END_DATE, startDate),
                  SQL.eq(PaySlip.table.IS_APPROVED, true))
              .orderBy(PaySlip.table.START_DATE)
              .exec(cx)) {
        while (qr.next()) {
          labels.add(String.format("'%s'", cx.formatDate(qr.getDate(PaySlip.table.START_DATE))));

          BigDecimal maxPay = BigDecimal.ZERO;
          for (Date d = qr.getDate(PaySlip.table.START_DATE);
              d.compareTo(qr.getDate(PaySlip.table.END_DATE)) <= 0;
              d = cx.tz().addDays(d, 1)) {
            final boolean isHoliday = cx.isHoliday(d);
            if (!isHoliday) {
              maxPay = maxPay.add(getMaxPayRate(d).multiply(BigDecimal.valueOf(8)));
            }
          }

          maxPayBuffers.add(maxPay);
          payCosts.add(
              qr.getBigDecimal(PaySlip.table.GROSS_PAY)
                  .add(qr.getBigDecimal(PaySlip.table.GENERAL_PAYROLL_TAX)));
          payBuffers.add(
              qr.getBigDecimal(PaySlip.table.OUTGOING_PAY_BUFFER)
                  .subtract(qr.getBigDecimal(PaySlip.table.INCOMING_PAY_BUFFER)));
          vacationDeductions.add(qr.getBigDecimal(PaySlip.table.VACATION_DEDUCTION));
          otherCosts.add(
              qr.getBigDecimal(PaySlip.table.TOTAL_COST)
                  .subtract(qr.getBigDecimal(PaySlip.table.GROSS_PAY))
                  .subtract(qr.getBigDecimal(PaySlip.table.GENERAL_PAYROLL_TAX))
                  .subtract(qr.getBigDecimal(PaySlip.table.VACATION_DEDUCTION)));
        }
      }

      final StringBuffer labelData = new StringBuffer();
      final StringBuffer maxPayBufferData = new StringBuffer();
      final StringBuffer payCostData = new StringBuffer();
      final StringBuffer payBufferData = new StringBuffer();
      final StringBuffer vacationDeductionData = new StringBuffer();
      final StringBuffer otherCostData = new StringBuffer();

      String sep = "";
      for (int i = 0; i < payCosts.size(); i++) {
        labelData.append(sep).append(labels.get(i));
        maxPayBufferData.append(sep).append(cx().formatDecimalRaw(maxPayBuffers.get(i)));
        payCostData.append(sep).append(cx().formatDecimalRaw(payCosts.get(i)));
        payBufferData.append(sep).append(cx().formatDecimalRaw(payBuffers.get(i)));
        vacationDeductionData.append(sep).append(cx().formatDecimalRaw(vacationDeductions.get(i)));
        otherCostData.append(sep).append(cx().formatDecimalRaw(otherCosts.get(i)));
        sep = ", ";
      }

      JS(String.format("var ctx = Coredom.tags[%d].getContext('2d');", c.id()));
      JS("var data = {");
      JS("labels: [");
      JS(labelData.toString());
      JS("],");
      JS("datasets: [");

      JS("{backgroundColor: 'rgba(151,187,187,1)', ");
      JS("data: [");
      JS(payCostData.toString());
      JS("]},");

      JS("{backgroundColor: 'rgba(151,205,187,1)', ");
      JS("data: [");
      JS(maxPayBufferData.toString());
      JS("]},");

      JS("{backgroundColor: 'rgba(151,187,205,1)', ");
      JS("data: [");
      JS(payBufferData.toString());
      JS("]},");

      JS("{backgroundColor: 'rgba(205,187,151,1)', ");
      JS("data: [");
      JS(vacationDeductionData.toString());
      JS("]},");

      JS("{backgroundColor: 'rgba(205,151,151,1)', ");
      JS("data: [");
      JS(otherCostData.toString());
      JS("]}]};");

      JS("document.Im4ix = {};");
      JS(
          "document.Im4ix.chart = new Chart(ctx, {type: 'bar', data: data, "
              + "options: {legend: {display: false}, scaleStepWidth: 1, scaleStartValue: 0, "
              + "scales: {xAxes:[{gridLines: {display: false}}], "
              + "yAxes:[{gridLines: {display: false}}]}, "
              + "animation: false, responsive: true, showTooltips: false}});");
    }