private String getFromDate(ReportForm reportForm, ActionMessages errors) { String fromDate = null; if (reportForm.getListType().compareToIgnoreCase("R") == 0 || reportForm.getListType().compareToIgnoreCase("S") == 0) { // Get From Date try { fromDate = FormatDate.convertToDateYYYYMMDD(reportForm.getFromDate()); } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate")); formErrors.add("fromDate"); } } else if (reportForm.getListType().compareToIgnoreCase("weekly") == 0) { try { fromDate = FormatDate.convertToDateMMDDYYYY(FormatDate.getCurrentDateFormatedMMDDYYYY()); fromDate = FormatDate.addToDateMMDDYYYY(fromDate, -8, 0); fromDate = FormatDate.convertUnformattedMDYtoYMD(fromDate); } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate")); formErrors.add("toDate"); } } else if (reportForm.getListType().compareToIgnoreCase("monthly") == 0) { try { fromDate = FormatDate.convertToDateMMDDYYYY(FormatDate.getCurrentDateFormatedMMDDYYYY()); fromDate = FormatDate.addToDateMMDDYYYY(fromDate, 0, -1); fromDate = FormatDate.convertUnformattedMDYtoYMD(fromDate); } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.fromdate")); formErrors.add("toDate"); } } return fromDate; }
public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { ActionErrors errors = new ActionErrors(); HttpSession session = request.getSession(); DbUserSession sessionUser = SessionHelpers.getUserSession(request); DatabaseTransaction t = null; DbSpeedData[] dbSpeedData = null; DbLocation[] dbLocation = null; LocaleDTO userlocale = null; MiscCashReceiptsForm miscCashReceipts = new MiscCashReceiptsForm(); java.util.ArrayList locationList = new java.util.ArrayList(); java.util.ArrayList glDescriptionList = new java.util.ArrayList(); java.util.ArrayList cashAcctList = new java.util.ArrayList(); java.util.ArrayList payMethodList = new java.util.ArrayList(); java.util.ArrayList pleaseSelect = new java.util.ArrayList(); if (sessionUser == null) { errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.login.invalid")); } // Database Access Logic try { t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser); // Set the list of receipt types in session. SessionHelpers.setReceiptTypesInSession(request); // Populate the locationList collection dbLocation = FdmsDb.getInstance().getLocationsForRegion(t, sessionUser.getRegion()); // AppLog.trace("DbLocation list length = " +dbLocation.length); for (int i = 0; i < dbLocation.length; i++) { String listValue = String.valueOf(dbLocation[i].getId()); String listLabel = dbLocation[i].getName(); locationList.add(new OptionsList(listValue, listLabel)); } // Populate the glDescriptionList collection dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "REVTYPE"); // AppLog.trace("DbSpeedData for REVTYPE list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2); String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1); glDescriptionList.add(new OptionsList(listValue, listLabel)); } // Populate the cashAcctList collection dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "CASHTYPE"); // AppLog.trace("DbSpeedData for CASHTYPE list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2); String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1); cashAcctList.add(new OptionsList(listValue, listLabel)); } // Populate the payMethodList", payMethodList) userlocale = FdmsDb.getInstance().getLocale(sessionUser.getDbLookup(), sessionUser.getRegion()); dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "PAYMETHOD"); // AppLog.trace("DbSpeedData for PAYMETHOD list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { if (dbSpeedData[i].getData() != null && dbSpeedData[i].getData().length() > 1) { String listValue = dbSpeedData[i].getData().substring(0, 2); String listLabel = dbSpeedData[i].getData(); payMethodList.add(new OptionsList(listValue, listLabel)); } } // Form Defaults miscCashReceipts.setSubmitButton(""); miscCashReceipts.setAmountOfTran("0"); miscCashReceipts.setDateOfTran(FormatDate.getCurrentDateFormatedMMDDYYYY()); miscCashReceipts.setFormId("None"); miscCashReceipts.setReceiptNumber(String.valueOf(userlocale.getNextReceiptNo())); pleaseSelect.add(new OptionsList("", "--Select--")); // AppLog.trace("Finished setting miscCashReceipts form bean"); } catch (PersistenceException pe) { logger.error("Persistence Exception in ShowMiscCashReceipts.doPerform. " + pe); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("error.PersistenceException", pe.getCause())); } catch (Exception pe) { logger.error("Exception in ShowMiscCashReceipts.doPerform. ", pe); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("error.GeneralException", pe.getMessage())); } finally { if (t != null) t.closeConnection(); } // Set Form Bean Into Scope session.setAttribute("miscCashReceipts", miscCashReceipts); session.setAttribute("locationList", locationList); session.setAttribute("glDescriptionList", glDescriptionList); session.setAttribute("cashAcctList", cashAcctList); session.setAttribute("payMethodList", payMethodList); session.setAttribute("pleaseSelect", pleaseSelect); // AppLog.trace("Setting miscCashReceipts form bean and collection arrays into session scope."); ActionForward actionForward = mapping.findForward("miscCashReceipts"); if (!errors.isEmpty()) { // AppLog.info("ShowMiscCahsReceipts invoking forward mapping getInput()."); saveErrors(request, errors); actionForward = new ActionForward(mapping.getInput()); } return actionForward; }
/** Insert the method's description here. Creation date: (11/22/2002 9:31:43 AM) */ public void setNewForm( HttpServletRequest request, DbUserSession sessionUser, HttpSession session, fdms.ui.struts.form.MiscCashReceiptsForm form, ActionErrors errors) { DatabaseTransaction t = null; DbSpeedData[] dbSpeedData = null; DbLocation[] dbLocation = null; LocaleDTO userlocale = null; ArrayList locationList = new ArrayList(); ArrayList glDescriptionList = new ArrayList(); ArrayList cashAcctList = new ArrayList(); ArrayList payMethodList = new ArrayList(); ArrayList pleaseSelect = new ArrayList(); // Database Access Logic try { t = (DatabaseTransaction) DatabaseTransaction.getTransaction(sessionUser); // Set the list of receipt types in session. SessionHelpers.setReceiptTypesInSession(request); // Populate the locationList collection dbLocation = FdmsDb.getInstance().getLocationsForRegion(t, sessionUser.getRegion()); // AppLog.trace("DbLocation list length = " +dbLocation.length); for (int i = 0; i < dbLocation.length; i++) { String listValue = String.valueOf(dbLocation[i].getId()); String listLabel = dbLocation[i].getName(); locationList.add(new OptionsList(listValue, listLabel)); } // Populate the glDescriptionList collection dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "REVTYPE"); // AppLog.trace("DbSpeedData for REVTYPE list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2); String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1); glDescriptionList.add(new OptionsList(listValue, listLabel)); } // Populate the cashAcctList collection dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "CASHTYPE"); // AppLog.trace("DbSpeedData for CASHTYPE list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { String listValue = CsvTable.getField(dbSpeedData[i].getData(), 2); String listLabel = CsvTable.getField(dbSpeedData[i].getData(), 1); cashAcctList.add(new OptionsList(listValue, listLabel)); } // Populate the payMethodList", payMethodList) userlocale = FdmsDb.getInstance().getLocale(sessionUser.getDbLookup(), sessionUser.getRegion()); dbSpeedData = FdmsDb.getInstance() .getSpeedData(sessionUser.getDbLookup(), sessionUser.getRegion(), "PAYMETHOD"); // AppLog.trace("DbSpeedData for PAYMETHOD list length = " +dbSpeedData.length); for (int i = 0; i < dbSpeedData.length; i++) { String listValue = dbSpeedData[i].getData().substring(0, 2); String listLabel = dbSpeedData[i].getData(); payMethodList.add(new OptionsList(listValue, listLabel)); } // Form Defaults form.setSubmitButton(""); form.setAmountOfTran("0"); form.setDateOfTran(FormatDate.getCurrentDateFormatedMMDDYYYY()); form.setFormId("None"); form.setReceiptNumber(String.valueOf(userlocale.getNextReceiptNo())); pleaseSelect.add(new OptionsList("", "--Select--")); // AppLog.trace("Finished setting miscCashReceipts form bean"); } catch (PersistenceException pe) { logger.error("Persistence Exception in ProcessMiscCashReceipts.setNewForm. " + pe); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("error.PersistenceException", pe.getCause())); } catch (Exception pe) { logger.error("Exception in ProcessMiscCashReceipts.setNewForm. ", pe); errors.add( ActionErrors.GLOBAL_ERROR, new ActionError("error.GeneralException", pe.getMessage())); } finally { if (t != null) { try { t.closeConnection(); } catch (Exception e) { logger.error("Error in closeConnection() : ", e); } } } // Set Form Bean Into Scope session.setAttribute("locationList", locationList); session.setAttribute("glDescriptionList", glDescriptionList); session.setAttribute("cashAcctList", cashAcctList); session.setAttribute("payMethodList", payMethodList); session.setAttribute("pleaseSelect", pleaseSelect); // AppLog.trace("Setting miscCashReceipts collection arrays into session scope."); }
/** * Method execute * * @param mapping * @param form * @param request * @param response * @return ActionForward */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException { HttpSession session = request.getSession(); DbUserSession user = (DbUserSession) session.getAttribute(SessionValueKeys.DB_USER); ReportForm reportForm = (ReportForm) form; ActionMessages errors = new ActionMessages(); // ArrayList <CheckListBean> checkURL = new ArrayList <CheckListBean>(); // session.setAttribute("checkURL", checkURL); String requestType = reportForm.getRequestType(); if (requestType == null) { requestType = ""; } String pageName = ""; reportForm.setReportURL(pageName); setReport(reportForm, user, session, errors, request); if (reportForm.getListType() == null) { reportForm.setListType(request.getParameter("all")); } else { reportForm.setListType(reportForm.getListType()); } if (requestType.compareToIgnoreCase("changeLocale") == 0) { changeLocale(reportForm, user, session, errors, request); // changeCategory(reportForm, user, session, errors, request); return (mapping.findForward("localeChange")); } else if (requestType.compareToIgnoreCase("changeLocation") == 0) { // changeCategory(reportForm, user, session, errors, request); return (mapping.findForward("localeChange")); } else if (requestType.compareToIgnoreCase("changeCategory") == 0) { // changeCategory(reportForm, user, session, errors, request); return (mapping.findForward("localeChange")); } else { // ArrayList <OptionsList> reports = new ArrayList<OptionsList>(); // reports.add( new OptionsList( "0" ,"--Select--")); // request.setAttribute("reports",reports); } if (requestType.compareToIgnoreCase("print") == 0) { // Timer smsTimer = new Timer("SMSThread", true); // CompanyManagerBean cmBean = new CompanyManagerBean(); // CompanyDTO company = cmBean.getCompany(user.getCompanyID()); // smsTimer.schedule(new SMSGenerator(company,1), 0l); ReportSchedulingDTO reportScheduling = new ReportSchedulingDTO(); setReportScheduling(reportForm, reportScheduling, errors, user); reportScheduling.setReportType(ReportSchedulingDTO.REPORT_TYPE_REALTIME); reportScheduling.setStatus("Q"); ReportSchedulingDAO reportScheDAo = new ReportSchedulingDAO(user); try { reportScheDAo.addReportScheduling(reportScheduling); } catch (Exception e) { } String crystalFlag = UtilSingleton.getInstance() .getProperty(user.getConfigID(), "CrystalServer.useReportingService"); if (crystalFlag != null && "true".equals(crystalFlag)) { CompanyManagerBean cmBean = new CompanyManagerBean(); CompanyDTO company = cmBean.getCompany(user.getCompanyID()); runNow(reportScheduling, company); } reportForm.setFromDate(FormatDate.getCurrentDateFormatedMMDDYYYY()); reportForm.setToDate(FormatDate.getCurrentDateFormatedMMDDYYYY()); reportForm.setUserLocaleId("0"); reportForm.setUserLocationId("0"); reportForm.setCategory("0"); } else if (requestType.compareToIgnoreCase("schedule") == 0) { ReportSchedulingDTO reportScheduling = new ReportSchedulingDTO(); setReportScheduling(reportForm, reportScheduling, errors, user); int repeatNumber = 0; try { repeatNumber = FormatNumber.parseInteger(reportForm.getRepeatNumber()); } catch (Exception e) { // } String fromDate = getFromDate(reportForm, errors); java.util.Date fDate = FormatDate.convertToDateYYMMDD(fromDate); String toDate = getToDate(reportForm, errors); java.util.Date tDate = FormatDate.convertToDateYYMMDD(toDate); Date rDate = new Date(); try { rDate = FormatDate.convertToDate(reportForm.getRunDate()); } catch (Exception e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.date.rundate")); formErrors.add("runDate"); } ReportSchedulingDAO reportScheDAo = new ReportSchedulingDAO(user); if (repeatNumber > 0) { // do more than 1 time. boolean scheduleNow = true; Timer timer = new Timer(true); for (int i = 0; i < repeatNumber; i++) { try { // ReportSchedulingDTO aSchedule = new ReportSchedulingDTO(); // copyObj(reportScheduling,aSchedule); reportScheDAo.addReportScheduling(reportScheduling); if (scheduleNow) { Calendar date = Calendar.getInstance(); date.setTime((java.util.Date) reportScheduling.getRunDate()); // date.add(Calendar.MINUTE, 5); // set runtime. (CDT) date.set(Calendar.HOUR_OF_DAY, reportScheduling.getRunTimeHH()); // 0-23 date.set(Calendar.MINUTE, reportScheduling.getRunTimeMM()); if (date.getTimeInMillis() <= System.currentTimeMillis()) { CompanyManagerBean cmBean = new CompanyManagerBean(); CompanyDTO company = cmBean.getCompany(user.getCompanyID()); runNow(reportScheduling, company); } else { scheduleNow = false; } } // setSchedule(timer, aSchedule, user); ReportSchedulingDTO aSchedule = new ReportSchedulingDTO(); copyObj(reportScheduling, aSchedule); reportScheduling = aSchedule; } catch (Exception e) { } String strFDate = FormatDate.convertDateToMMDDYYYY(fDate); String strTDate = FormatDate.convertDateToMMDDYYYY(tDate); String strRDate = FormatDate.convertDateToMMDDYYYY(rDate); int field = -1; if (reportForm.getRepeatType().compareToIgnoreCase("D") == 0) { field = 1; } else if (reportForm.getRepeatType().compareToIgnoreCase("W") == 0) { field = 7; } else if (reportForm.getRepeatType().compareToIgnoreCase("M") == 0) { field = 0; } if (field > -1) { strRDate = FormatDate.addToDateMMDDYYYY(strRDate, field, (field == 0 ? 1 : 0)); strFDate = FormatDate.addToDateMMDDYYYY(strFDate, field, (field == 0 ? 1 : 0)); strTDate = FormatDate.addToDateMMDDYYYY(strTDate, field, (field == 0 ? 1 : 0)); rDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strRDate); fDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strFDate); tDate = FormatDate.convertMMDDYYYYToDateYYMMDD(strTDate); reportScheduling.setRunDate(new java.sql.Date(rDate.getTime())); reportScheduling.setFromDate(new java.sql.Date(fDate.getTime())); reportScheduling.setToDate(new java.sql.Date(tDate.getTime())); } } } else { // do only one time try { reportScheDAo.addReportScheduling(reportScheduling); Calendar date = Calendar.getInstance(); date.setTime((java.util.Date) reportScheduling.getRunDate()); // date.add(Calendar.MINUTE, 5); // set runtime. (CDT) date.set(Calendar.HOUR_OF_DAY, reportScheduling.getRunTimeHH()); // 0-23 date.set(Calendar.MINUTE, reportScheduling.getRunTimeMM()); if (date.getTimeInMillis() <= System.currentTimeMillis()) { CompanyManagerBean cmBean = new CompanyManagerBean(); CompanyDTO company = cmBean.getCompany(user.getCompanyID()); runNow(reportScheduling, company); } // setSchedule( null, reportScheduling, user); } catch (Exception e) { } } } // we comment it out because we don't want it to do the pupup but let the user look at the // printed report list. // reportForm.setReportURL(pageName); return (mapping.findForward("localeChange")); }