| Summary: | Incorrect commission in monthly summary in the admin panel | ||
|---|---|---|---|
| Product: | CS3343 Salon Booking System | Reporter: | shukhyiu2-c |
| Component: | admin.monthly_summary.Read | Assignee: | kwanng9 <kwanng9-c> |
| Status: | RESOLVED FIXED | ||
| Severity: | enhancement | CC: | chtsang246-c, shukhyiu2-c |
| Priority: | --- | ||
| Version: | 2.0 | ||
| Hardware: | PC | ||
| OS: | Mac OS | ||
|
Description
shukhyiu2-c
2023-11-05 12:38:52 HKT
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;
}
}
|