1 package projectmanagement.presentation.worksheets; 2 3 import projectmanagement.presentation.*; 4 import projectmanagement.spec.timewage.*; 5 import projectmanagement.spec.employee.*; 6 import projectmanagement.spec.project.*; 7 import com.lutris.appserver.server.httpPresentation.*; 8 import org.enhydra.xml.xmlc.XMLObject; 9 10 import org.w3c.dom.*; 11 import org.w3c.dom.html.*; 12 13 import java.util.Calendar ; 14 import java.util.GregorianCalendar ; 15 import java.sql.Date ; 16 import java.sql.Time ; 17 import java.lang.*; 18 19 25 public class AdministeringSearch extends BasePO { 26 27 private static String EMPLOYEE = "employee"; 28 private static String PROJECT = "project"; 29 private static String FROMYEAR = "fromYear"; 30 private static String FROMMONTH = "fromMonth"; 31 private static String FROMDAY = "fromDay"; 32 private static String TOYEAR = "toYear"; 33 private static String TOMONTH = "toMonth"; 34 private static String TODAY = "toDay"; 35 36 private static String IS_PERSONAL = "isPersonal"; 37 38 41 protected int getRequiredAuthLevel() { 42 String isPersonal=""; 43 try { 44 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 45 } catch (Exception ex) {} 46 47 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 48 return 1; 49 } else { 50 return 2; 51 } 52 } 53 54 57 public XMLObject handleDefault() 58 throws HttpPresentationException,ClientPageRedirectException { 59 60 AdministeringHTML page = new AdministeringHTML(); 61 String employee=null; 62 String project=null; 63 boolean multiple = false; 64 java.util.ArrayList employeeIDs=new java.util.ArrayList ();; 66 int index=0; 67 String employeeID=EMPLOYEE+String.valueOf("0"); 68 69 while ( this.getComms().request.getParameter(employeeID) != null ) { 70 employeeIDs.add( this.getComms().request.getParameter(employeeID) ); 71 index++; 72 employeeID = EMPLOYEE+String.valueOf(index); 73 } 74 75 try{ 77 if( employeeIDs.size() == 1 || employeeIDs.get(0).toString().equals("") ) { 78 employee = employeeIDs.get(0).toString(); 79 if (employee!=null && employee.length()==0) { 80 employee=null; 81 } 82 } else { 83 multiple = true; 84 } 85 }catch(IndexOutOfBoundsException e){} 86 java.util.ArrayList projectIDs=new java.util.ArrayList (); 87 index=0; 88 String projectID=PROJECT+String.valueOf("0"); 89 while ( this.getComms().request.getParameter(projectID) != null ) { 90 91 projectIDs.add( this.getComms().request.getParameter(projectID) ); 92 index++; 93 projectID = PROJECT+String.valueOf(index); 94 95 } 96 if( projectIDs.size() == 1 || projectIDs.get(0).toString().equals("")) { 98 project = projectIDs.get(0).toString(); 99 if (project!=null && project.length()==0) { 100 project=null; 101 } 102 } else { 103 multiple = true; 104 } 105 106 107 String fromYear = this.getComms().request.getParameter(FROMYEAR); 108 if (fromYear!=null && fromYear.length()==0) { 109 fromYear=null; 110 } 111 String fromMonth = this.getComms().request.getParameter(FROMMONTH); 112 if (fromMonth!=null && fromMonth.length()==0) { 113 fromMonth=null; 114 } 115 String fromDay = this.getComms().request.getParameter(FROMDAY); 116 if (fromDay!=null && fromDay.length()==0) { 117 fromDay=null; 118 } 119 120 String toYear = this.getComms().request.getParameter(TOYEAR); 121 if ( toYear != null && toYear.length()==0) { 122 toYear=null; 123 } 124 String toMonth = this.getComms().request.getParameter(TOMONTH); 125 if (toMonth!=null && toMonth.length()==0) { 126 toMonth=null; 127 } 128 String toDay = this.getComms().request.getParameter(TODAY); 129 if (toDay!=null && toDay.length()==0) { 130 toDay=null; 131 } 132 boolean checkDates = true; 133 String params = ""; 134 if ( !checkDate( fromYear , fromMonth , fromDay ) ) { 135 params += "?checkFromDate=false"; 136 checkDates = false; 137 } 138 if ( !checkDate( toYear , toMonth , toDay ) ) { 139 if ( !checkDates ) { 140 params += "&checkToDate=false"; 141 } else { 142 params += "?checkToDate=false"; 143 } 144 checkDates = false; 145 } 146 if ( !checkDates ) { 147 throw new ClientPageRedirectException("Search.po"+params); 148 } 149 150 HTMLFormElement form = page.getElementForm(); 151 form.setAttribute("target","_self"); 152 153 154 HTMLTableElement table = page.getElementTblWorkSheets(); 156 try { 157 WorkSheet[] workSheets=null; 158 WorkSheetManager workSheetManager = WorkSheetManagerFactory. 159 getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl"); 160 161 162 Calendar c1=Calendar.getInstance(); 163 Calendar c2=Calendar.getInstance(); 164 165 if( fromYear!=null && fromMonth!=null && fromDay!=null && toYear!=null && toMonth!=null && toDay!=null ) { 166 167 c1.set( Integer.parseInt(fromYear),Integer.parseInt(fromMonth)-1,Integer.parseInt(fromDay) ); 168 c2.set( Integer.parseInt(toYear),Integer.parseInt(toMonth)-1,Integer.parseInt(toDay) ); 169 170 if ( !multiple ) { 171 workSheets=workSheetManager. 172 getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2( 173 employee,project,new Date (c1.getTimeInMillis()),new Date (c2.getTimeInMillis())); 174 } else { 175 workSheets=workSheetManager. 176 getAllWorksheetsForEmployeeArrayAndProjectArrayBetweenDates( 177 employeeIDs,projectIDs,new Date (c1.getTimeInMillis()),new Date (c2.getTimeInMillis())); 178 } 179 } 180 double sumOfHours=0; 181 double sumOfMoney=0; 182 if (workSheets!=null) { 183 HoursAndMoney ham=new HoursAndMoney(); 184 for (int i=0; i<workSheets.length; i++) { 185 HTMLTableRowElement htmlRE=createNewRow(page,workSheets[i],ham); 187 table.appendChild(htmlRE); 189 } 190 sumOfHours=ham.getHours(); 191 sumOfMoney=ham.getMoney(); 192 sumOfMoney=(double)(Math.round(sumOfMoney*100))/100; 193 sumOfHours=(double)(Math.round(sumOfHours*100))/100; 194 } 195 page.setTextTxtSumOfHours(String.valueOf(sumOfHours)); 196 page.setTextTxtSumOfMoney(String.valueOf(sumOfMoney)); 197 198 202 203 } catch(NullPointerException ex) { 204 return page; 205 } catch(Exception ex) { 206 this.writeDebugMsg("Error populating list of work sheets: " + ex); 207 throw new ProjectManagementPresentationException("Error getting list of work sheets: ", ex); 208 } 209 210 table.removeChild(page.getElementTemplateRow()); 212 213 String errorMsg = this.getSessionData().getAndClearUserMessage(); 214 219 220 String isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 221 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 222 HTMLInputElement ip=page.getElementIsPersonal(); 223 ip.setValue("true"); 224 } 225 return page; 227 } 228 231 private boolean checkDate(String year, String month, String day) { 232 GregorianCalendar cal=new GregorianCalendar (); 233 boolean retVal=true; 234 cal.setLenient(false); 235 cal.set( Integer.parseInt(year),Integer.parseInt(month)-1,1 ); 236 if ( cal.getActualMaximum(Calendar.DAY_OF_MONTH) < Integer.parseInt(day) ) { 237 retVal = false; 238 } else if( cal.isLeapYear( Integer.parseInt(year) ) && Integer.parseInt(month) == 1 && Integer.parseInt(day) == 29 ) { 239 retVal = true; 240 } else { 241 retVal = true; 242 } 243 return retVal; 244 } 245 246 249 private HTMLTableRowElement createNewRow(AdministeringHTML administeringHTML, 250 WorkSheet workSheet,HoursAndMoney ham) { 251 252 String workSheetID=""; 253 254 try { 255 workSheetID=workSheet.getHandle(); 256 PayRate pr=workSheet.getPayRate(); 257 Employee emp=pr.getEmployee(); 258 Project prj=pr.getProject(); 259 Time timeStarted=workSheet.getTimeStarted(); 260 Time timeFinished=workSheet.getTimeFinished(); 261 administeringHTML.setTextTxtEmployee(emp.getFirstName()+" "+ 262 emp.getLastName()); 263 administeringHTML.setTextTxtProject(prj.getName()); 264 Calendar cal=new GregorianCalendar (); 265 cal.setTime(workSheet.getWorkingDate()); 266 String wd=String.valueOf(cal.get(Calendar.YEAR))+"-"+ 267 String.valueOf(cal.get(Calendar.MONTH)+1)+"-"+ 268 String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); 269 administeringHTML.setTextTxtWorkingDate(wd); 270 cal.setTime(timeStarted); 271 String tst=String.valueOf(cal.get(Calendar.HOUR))+":"+ 272 String.valueOf(cal.get(Calendar.MINUTE)); 273 administeringHTML.setTextTxtTimeStarted(tst); 274 cal.setTime(timeFinished); 275 String tfn=String.valueOf(cal.get(Calendar.HOUR))+":"+ 276 String.valueOf(cal.get(Calendar.MINUTE)); 277 administeringHTML.setTextTxtTimeFinished(tfn); 278 double mny=(double)(Math.round( 279 ham.calculate(calculateTimeDifferenceInHours(timeStarted,timeFinished), 280 prj.getMoneyPerHour(),pr.getRate())*100))/100; 281 administeringHTML.setTextTxtMoney(String.valueOf(mny)); 282 } catch (Exception ex) {} 283 284 HTMLImageElement detailsImg=administeringHTML.getElementImgDetails(); 286 detailsImg.setName(workSheetID); 287 288 HTMLImageElement modifyImg=administeringHTML.getElementImgModify(); 290 modifyImg.setName(workSheetID); 291 292 HTMLImageElement deleteImg=administeringHTML.getElementImgDelete(); 294 deleteImg.setName(workSheetID); 295 296 HTMLTableRowElement row=(HTMLTableRowElement)administeringHTML. 297 getElementTemplateRow().cloneNode(true); 298 299 return row; 300 } 301 302 private double calculateTimeDifferenceInHours (Time timeStarted, 303 Time timeFinished) { 304 long ts=timeStarted.getTime(); 305 long tf=timeFinished.getTime(); 306 long diffInMilliseconds=tf-ts; 307 double diffInHours=diffInMilliseconds/3600000.0; 308 return diffInHours; 309 } 310 311 class HoursAndMoney { 312 private double hours=0; 313 private double money=0; 314 315 public double calculate (double hrs,double moneyPerHour,double payRate) { 316 hours+=hrs; 317 double dm=hrs*moneyPerHour*payRate; 318 money+=dm; 319 return dm; 320 } 321 322 public double getHours () { 323 return hours; 324 } 325 326 public double getMoney () { 327 return money; 328 } 329 } 330 331 } 332 333 | Popular Tags |