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.sql.Date ; 15 import java.sql.Time ; 16 import java.lang.*; 17 import java.util.*; 18 19 25 public class Administering extends BasePO { 26 27 private static String EMPLOYEE = "employee"; 28 private static String PROJECT = "project"; 29 private static String YEAR = "year"; 30 private static String MONTH = "month"; 31 32 private static String IS_PERSONAL = "isPersonal"; 33 34 37 protected int getRequiredAuthLevel() { 38 String isPersonal=""; 39 try { 40 isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 41 } catch (Exception ex) {} 42 43 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 44 return 1; 45 } else { 46 return 2; 47 } 48 } 49 50 53 public XMLObject handleDefault() 54 throws HttpPresentationException { 55 56 AdministeringHTML page = new AdministeringHTML(); 57 58 String employee = this.getComms().request.getParameter(EMPLOYEE); 59 if (employee!=null && employee.length()==0) { 60 employee=null; 61 } 62 String project = this.getComms().request.getParameter(PROJECT); 63 if (project!=null && project.length()==0) { 64 project=null; 65 } 66 String year = this.getComms().request.getParameter(YEAR); 67 if (year!=null && year.length()==0) { 68 year=null; 69 } 70 String month = this.getComms().request.getParameter(MONTH); 71 if (month!=null && month.length()==0) { 72 month=null; 73 } 74 75 HTMLTableElement table = page.getElementTblWorkSheets(); 77 78 try { 79 WorkSheet[] workSheets=null; 80 81 WorkSheetManager workSheetManager = WorkSheetManagerFactory. 82 getWorkSheetManager("projectmanagement.business.timewage.WorkSheetManagerImpl"); 83 84 if (year==null) { 85 86 workSheets=workSheetManager.getAllWorkSheetsForEmployeeProjectPair(employee,project); 87 } else { 88 Calendar c1=Calendar.getInstance(); 89 Calendar c2=Calendar.getInstance(); 90 if (month==null) { 91 c1.set(Integer.parseInt(year),1,1); 92 c2.set(Integer.parseInt(year),12,31); 93 } else { 94 c1.set(Integer.parseInt(year),Integer.parseInt(month)-1,1); 95 c2.set( Integer.parseInt(year),Integer.parseInt(month)-1,c1.getActualMaximum(Calendar.DAY_OF_MONTH) ); 96 } 97 workSheets=workSheetManager.getAllWorkSheetsForEmployeeProjectPairFromDate1ToDate2( 98 employee,project,new Date (c1.getTimeInMillis()),new Date (c2.getTimeInMillis())); 99 } 100 101 102 double sumOfHours=0; 103 double sumOfMoney=0; 104 if (workSheets!=null) { 105 HoursAndMoney ham=new HoursAndMoney(); 106 for (int i=0; i<workSheets.length; i++) { 107 HTMLTableRowElement htmlRE=createNewRow(page,workSheets[i],ham); 109 table.appendChild(htmlRE); 111 } 112 sumOfHours=ham.getHours(); 113 sumOfMoney=ham.getMoney(); 114 sumOfMoney=(double)(Math.round(sumOfMoney*100))/100; 115 sumOfHours=(double)(Math.round(sumOfHours*100))/100; 116 } 117 page.setTextTxtSumOfHours(String.valueOf(sumOfHours)); 118 page.setTextTxtSumOfMoney(String.valueOf(sumOfMoney)); 119 page.getElementBackElement().getParentNode().removeChild( page.getElementBackElement() ); 121 122 table.removeChild(page.getElementTemplateRow()); 124 125 String errorMsg = this.getSessionData().getAndClearUserMessage(); 126 131 132 String isPersonal=this.getComms().request.getParameter(IS_PERSONAL); 133 if (isPersonal!=null && isPersonal.equalsIgnoreCase("true")) { 134 HTMLInputElement ip=page.getElementIsPersonal(); 135 ip.setValue("true"); 136 } 137 } catch(NullPointerException ex) { 138 } catch(Exception ex) { 139 this.writeDebugMsg("Error populating list of work sheets: " + ex); 140 throw new ProjectManagementPresentationException("Error getting list of work sheets: ", ex); 141 } 142 143 144 145 return page; 147 } 148 149 152 private HTMLTableRowElement createNewRow(AdministeringHTML administeringHTML, 153 WorkSheet workSheet,HoursAndMoney ham) { 154 155 String workSheetID=""; 156 157 try { 158 workSheetID=workSheet.getHandle(); 159 PayRate pr=workSheet.getPayRate(); 160 Employee emp=pr.getEmployee(); 161 Project prj=pr.getProject(); 162 Time timeStarted=workSheet.getTimeStarted(); 163 Time timeFinished=workSheet.getTimeFinished(); 164 administeringHTML.setTextTxtEmployee(emp.getFirstName()+" "+ 165 emp.getLastName()); 166 administeringHTML.setTextTxtProject(prj.getName()); 167 Calendar cal=new GregorianCalendar(); 168 cal.setTime(workSheet.getWorkingDate()); 169 String wd=String.valueOf(cal.get(Calendar.YEAR))+"-"+ 170 String.valueOf(cal.get(Calendar.MONTH)+1)+"-"+ 171 String.valueOf(cal.get(Calendar.DAY_OF_MONTH)); 172 administeringHTML.setTextTxtWorkingDate(wd); 173 cal.setTime(timeStarted); 174 String tst=String.valueOf(cal.get(Calendar.HOUR_OF_DAY))+":"+ 175 String.valueOf(cal.get(Calendar.MINUTE)); 176 administeringHTML.setTextTxtTimeStarted(tst); 177 cal.setTime(timeFinished); 178 String tfn=String.valueOf(cal.get(Calendar.HOUR_OF_DAY))+":"+ 179 String.valueOf(cal.get(Calendar.MINUTE)); 180 administeringHTML.setTextTxtTimeFinished(tfn); 181 double mny=(double)(Math.round( 182 ham.calculate(calculateTimeDifferenceInHours(timeStarted,timeFinished), 183 prj.getMoneyPerHour(),pr.getRate())*100))/100; 184 administeringHTML.setTextTxtMoney(String.valueOf(mny)); 185 } catch (Exception ex) {} 186 187 HTMLImageElement detailsImg=administeringHTML.getElementImgDetails(); 189 detailsImg.setName(workSheetID); 190 191 HTMLImageElement modifyImg=administeringHTML.getElementImgModify(); 193 modifyImg.setName(workSheetID); 194 195 HTMLImageElement deleteImg=administeringHTML.getElementImgDelete(); 197 deleteImg.setName(workSheetID); 198 199 HTMLTableRowElement row=(HTMLTableRowElement)administeringHTML. 200 getElementTemplateRow().cloneNode(true); 201 202 return row; 203 } 204 205 private double calculateTimeDifferenceInHours (Time timeStarted, 206 Time timeFinished) { 207 long ts=timeStarted.getTime(); 208 long tf=timeFinished.getTime(); 209 long diffInMilliseconds=tf-ts; 210 double diffInHours=diffInMilliseconds/3600000.0; 211 return diffInHours; 212 } 213 214 class HoursAndMoney { 215 private double hours=0; 216 private double money=0; 217 218 public double calculate (double hrs,double moneyPerHour,double payRate) { 219 hours+=hrs; 220 double dm=hrs*moneyPerHour*payRate; 221 money+=dm; 222 return dm; 223 } 224 225 public double getHours () { 226 return hours; 227 } 228 229 public double getMoney () { 230 return money; 231 } 232 } 233 234 } 235 236 | Popular Tags |