public static int newLeaveRequest(JSONObject jsonObj) {
    	JSONArray detailList = new JSONArray();
    	float ttlDays = 0;
    	int caseId = -1;
    	ArrayList<String> subSqls = new ArrayList<String>();

		try {
    	    String eid = jsonObj.getString("EmployeeId");
    	    String leavaTypeId = jsonObj.getString("LeavaTypeId");
    	    String issuedDate = jsonObj.getString("IssuedDate");
    	    detailList = jsonObj.getJSONArray("LeaveDetail");
    	    // calculate total days
    	    for (int i=0; i<detailList.length(); i++) {
    	    	JSONObject detailItem = detailList.getJSONObject(i);
    	    	String strStartDate = detailItem.getString("StartDay");
    	    	String strStopDate = detailItem.getString("StopDay");
    	    	String halfDay = detailItem.getString("HalfDayOrNot");
    	    	String amPm = detailItem.getString("AmOrPm");
    	    	logger.info("check duplicate:"+eid+","+strStartDate+","+strStopDate);
    	    	
    	    	String chkSql = "SELECT * from view_case where (StatusID = 2 or StatusID = 3) and StartDay = '" + strStartDate + "' and '" + strStopDate + "' and AmOrPm ";
    	    	if ("NULL".equals(amPm)) {
    	    		chkSql += " is " + amPm;
    	    	} else {
    	    		chkSql += " = " + amPm;
    	    	}
    	    	chkSql += " and HalfDayOrNot = " + halfDay;
    	    	ResultSet rs = EleaveDB.getQueryRs(chkSql);
    	    	if (rs.next()){
    	    		logger.info("Duplicate case:"+rs.getString("CaseId"));
    	    		return caseId;
    	    	}
    	    	/*
    	    	if (!chkDupReq(eid,strStartDate,strStopDate,amPm,halfDay)) {
    	    		logger.info("Duplicate case:"+strStartDate+","+strStopDate);
    	    		return -1;
    	    	}*/
    	    	String subSql = "INSERT INTO `leave_case_detail` VALUES (?,'"
 	    		       + strStartDate + "','" + strStopDate + "'," + halfDay + "," + amPm + ");";
    	    	subSqls.add(subSql);
    	    }
    	    if (!chkLeftDays(eid,ttlDays)) {
    	    	logger.info("Days left not enough:"+eid+","+ttlDays);
	    		return -1;
    	    }
    	    String mainSql = "INSERT INTO `leave_case` (EmployeeId,LeavaTypeId,IssuedDate,StatusID,LeaveDays) VALUES ("
    	    		       + eid + "," + leavaTypeId + ",'" + issuedDate + "',1," + ttlDays + ");";
    	    if (EleaveDB.execSql(mainSql)>0) {
    	    	String querySql = "SELECT LAST_INSERT_ID()";
    	    	ResultSet rs = EleaveDB.getQueryRs(querySql);
    	    	if (rs.next()){
    	    		caseId = rs.getInt(1);
    	    		System.out.print("caseId:"+caseId);
    	    	    // insert leave_case_detail
    	    	    for (int i=0; i<subSqls.size(); i++) {
    	    	    	String subSql = subSqls.get(i);
    	    	    	String cid = ""+caseId;
    	    	    	subSql = subSql.replace("?", cid);
    	    	    	if (EleaveDB.execSql(subSql)<=0) {
        	    			EleaveDB.transRollback();
        	    		}
    	    	    }
    	    	    EleaveDB.transCommit();
    	    	}
    	    } else {
    	    	EleaveDB.transRollback();
    	    }
    	    
    	    
    	} catch (Exception e){
			e.printStackTrace();
		}
    	return caseId;
    }