Description: Overview: The commission is calculated incorrectly in the admin panel. Steps to Reproduce: 1. login as admin 2. select "Check Monthly Summary" 3. select a year and month with existing records in the drop-down list (e.g. Year: 2023 Month: 10 (Retrieved 2023-11-05 from the database)) Actual Results: The system shows the following result: Hairdresser ID: 3 Name: Peter Number of Booking: 2 Grand Total: 700 Commission: 0 The screenshot of actual result is also attached for references (admin_monthly_summary.png). Expected Results: The commission for hairdresser_id 3 should be 350 (Grand Total : 700, Commission Rate: 50% (Retrieved 2023-11-05 from the database)). The system should show the following result: Hairdresser ID: 3 Name: Peter Number of Booking: 2 Grand Total: 700 Commission: 350 Build Date & Hardware: Build 2023-11-05 on Mac OS 13.1
Already fixed. The issue was caused by the wrong if-clause for checking currentSum in read method in the Read.java file in admin.monthly_summary package. The original code was as follows: if (currentSum > Integer.parseInt(commissionRuleFrom[i]) && currentSum < Integer.parseInt(commissionRuleFrom[i])) It is logically wrong because the currentSum cannot be greater than or less than commissionRuleFrom[i] at the same time. Other variable should be used to represent the upper bound of the range. The code was revised as follows: public String[][] read(DBConnectionInterface conn, String sql_in) { ArrayList<String[]> arrayList = new ArrayList<>(); String[][] tableData_temp; try { Class.forName("com.mysql.cj.jdbc.Driver"); ResultSet rs = conn.query(sql_in); while (rs.next()) { String[] currRecord = new String[showField.length+1]; String currRaw = ""; for (int i=0 ; i<showField.length ; i++) { currRecord[i] = rs.getString(showField[i]); if (i == 0) currRaw += rs.getString(showField[i]); else currRaw += ", " + rs.getString(showField[i]); } // calculate commission int currentSum = Integer.parseInt(rs.getString("SUM(booking_grandtotal)")); int currCommission = 0; for(int i=0 ; i<commissionRuleFrom.length ; i++) { if (currentSum > Integer.parseInt(commissionRuleFrom[i]) && currentSum < Integer.parseInt(commissionRuleTo[i])) { currCommission = (int)(currentSum * ((Double.parseDouble(commissionRuleRate[i]))/100)); } } currRecord[showField.length] = String.valueOf(currCommission); tableDataRaw.add(currRaw); arrayList.add(currRecord); } rs.close(); tableData_temp = new String[arrayList.size()][showField.length]; for(int i=0 ; i<arrayList.size() ; i++) { tableData_temp[i] = arrayList.get(i); } return tableData_temp; } catch (Exception e) { e.printStackTrace(); tableData_temp = new String[0][0]; return tableData_temp; } }