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); }); }
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}});"); }