Beispiel #1
0
  private void search(HttpServletRequest request) throws Exception {
    logger.info("----->PaymentEditAction into Search");
    // Get payment entity
    BudgetActionHelper actionHelper =
        AppContextUtil.getAppContext().getBean("budgetActionHelper", BudgetActionHelper.class);
    PaymentHelper paymentHelper =
        AppContextUtil.getAppContext().getBean("paymentHelper", PaymentHelper.class);
    BudgetHelper budgetHelper =
        AppContextUtil.getAppContext().getBean("budgetHelper", BudgetHelper.class);

    int xID = ParamUtil.getInt(request, "xID");
    //		String borrowFromOther = AppConsts.NO;
    Budget budget = null;
    double borrowAmt = 0.0;
    int borrowDeptId = 0;
    int borrowBudgetId = 0;

    // 1.Get the payment
    logger.info("----->PaymentEditAction into Search  1.Get the payment	");
    Payment payment = paymentHelper.getPayment(xID, true);

    // 2.Get the budget and budget action
    logger.info("----->PaymentEditAction into Search Ready to Get the actionList ");
    List<BudgetAction> actionList =
        actionHelper.getActionByActionTypeAndPaymentID(MessageConsts.BUDGET_TYPE_BORROW_OUT, xID);
    logger.info(
        "----->PaymentEditAction into Search  2.Get the budget and budget action  actionList size"
            + actionList.size());
    if (actionList != null && actionList.size() > 0) {
      logger.info("----->PaymentEditAction into Search  borrow From Other");
      BudgetAction borrowOutAction = actionList.get(0);
      if (borrowOutAction != null) {
        // Set the borrowFromOther == Yes
        //				borrowFromOther = AppConsts.YES;

        // Get the borrow amt
        borrowAmt = borrowOutAction.getxACTION_AMT();

        // Get the borrow dept by budget
        borrowBudgetId = borrowOutAction.getxBUDGET_xID();
        if (borrowBudgetId > 0) {
          budget = budgetHelper.getBudget(borrowBudgetId, false);
          if (budget != null) {
            borrowDeptId = budget.getxDEPT_xID();
          }
        }
      }
    }
    request.setAttribute("xID", xID);
    request.setAttribute("entity", payment);
    //		request.setAttribute("borrowFromOther", borrowFromOther);
    request.setAttribute("borrowAmt", borrowAmt);
    request.setAttribute("borrowDeptId", borrowDeptId);
    logger.info("----->PaymentEditAction ready Go out Search");
  }
Beispiel #2
0
  private User setEntity(HttpServletRequest request) throws Exception {
    User user = (User) ParamUtil.getSessionAttr(request, "LOGIN_USER");
    if (user == null) throw new Exception(MessageConsts.MSG_COMMON_SESSION_TIMEOUT);
    String userId = user.getxLOGIN_ID();
    User entity = new User();

    DeptHelper deptHelper = AppContextUtil.getAppContext().getBean("deptHelper", DeptHelper.class);
    String deptId = ParamUtil.getString(request, "deptId");
    Dept dept = deptHelper.getByXID(Integer.valueOf(deptId), true);
    // ParamUtil.setSessionAttr(request, "dept", dept);
    String createUserLoginId = ParamUtil.getString(request, "createUserLoginId");
    String createUserDisplayName = ParamUtil.getString(request, "createUserDisplayName");
    String createUserPWD = ParamUtil.getString(request, "createUserPWD");
    String sourcexID = ParamUtil.getString(request, "xID");

    if (!StringUtil.isEmpty(sourcexID)) {
      entity.setxID(Integer.valueOf(sourcexID));
      entity.setxUPDATE_ID(userId);
    } else {
      entity.setxCREATER_ID(userId);
    }

    entity.setxDEPT_xID(Integer.valueOf(deptId));
    entity.setxPRIVILEGE_xID(dept.getPrivilege().getxID());
    entity.setxPRIVILEGE_xNAME(dept.getPrivilege().getxPRIVILEGE_NAME());
    entity.setxLOGIN_ID(createUserLoginId);
    entity.setxDISPLAY_NAME(createUserDisplayName);
    entity.setxPWD(createUserPWD);

    return entity;
  }
Beispiel #3
0
  @Override
  public String execute() {
    HttpServletRequest request = ServletActionContext.getRequest();
    User entity;
    UserHelper userHelper = AppContextUtil.getAppContext().getBean("userHelper", UserHelper.class);
    try {
      String createUserLoginId = ParamUtil.getString(request, "createUserLoginId");
      if (userHelper.getUserByUserId(createUserLoginId) != null) {
        request.setAttribute(
            AppConsts.MSG_ERROR, MessageHelper.getMessage(MessageConsts.USER_EXIST));
        return ERROR;
      }

      entity = setEntity(request);

      userHelper.saveEntity(entity);
    } catch (Exception e) {
      if (MessageConsts.MSG_COMMON_SESSION_TIMEOUT.equals(e.getMessage())) {
        request.setAttribute(AppConsts.MSG_ERROR, MessageHelper.getMessage(e.getMessage()));
      } else {
        request.setAttribute(
            AppConsts.MSG_ERROR, MessageHelper.getMessage(MessageConsts.MSG_PAYMENT_ERROR));
      }
      return ERROR;
    }
    request.setAttribute("xID", String.valueOf(entity.getxID()));

    request.setAttribute(
        AppConsts.MSG_SUCCESS, MessageHelper.getMessage(MessageConsts.MSG_COMMON_SUBMIT_SUC));
    entity = userHelper.getUserByXId(entity.getxID());
    // request.setAttribute("entity", entity);
    return SUCCESS;
  }
 public List<CompanyPrincipal> getCompanyPrincipalByCompanyID(
     String companyPrincipalText, int companyId) {
   CompanyPrincipalDao companyPrincipalDao =
       AppContextUtil.getAppContext().getBean("companyPrincipalDao", CompanyPrincipalDao.class);
   Map<String, Object> param = new HashMap<String, Object>();
   if (!StringUtil.isEmpty(companyPrincipalText)) {
     param.put("xNAME_TEXT", companyPrincipalText);
   }
   if (companyId > 0) {
     param.put("xCOMPANY_xID", companyId);
   }
   return companyPrincipalDao.select(param);
 }
Beispiel #5
0
  private Payment setEntity(HttpServletRequest request) throws Exception {
    User user = (User) ParamUtil.getSessionAttr(request, "LOGIN_USER");
    if (user == null) throw new Exception(MessageConsts.MSG_COMMON_SESSION_TIMEOUT);
    String userId = user.getxLOGIN_ID();
    Payment entity = new Payment();
    int companyPrincipleId = ParamUtil.getInt(request, "companyPrincipleId");
    int projectId = ParamUtil.getInt(request, "projectId");
    int companyId = -1;

    CompanyPrincipalHelper companyPrincipalHelper =
        AppContextUtil.getAppContext()
            .getBean("companyPrincipalHelper", CompanyPrincipalHelper.class);
    CompanyPrincipal companyPrincipal =
        companyPrincipalHelper.getCompanyPrincipal(companyPrincipleId);
    if (companyPrincipal != null) {
      companyId = companyPrincipal.getxCOMPANY_xID();
    }

    double payAmt = ParamUtil.getDouble(request, "payAmt");
    Date payDate = ParamUtil.getDate(request, "payDate");
    String sourcexID = ParamUtil.getString(request, "xID");
    /*		String paymentWhat = URLDecoder.decode(ParamUtil.getString(request, "paymentWhat"), "utf-8");
    String remark = URLDecoder.decode(ParamUtil.getString(request, "remark"), "utf-8");*/

    String paymentWhat = ParamUtil.getString(request, "paymentWhat");
    String remark = ParamUtil.getString(request, "remark");

    if (!StringUtil.isEmpty(sourcexID)) {
      entity.setxID(Integer.valueOf(sourcexID));
      entity.setxUPDATE_ID(userId);
    } else {
      entity.setxCREATER_ID(userId);
    }
    entity.setxPAY_AMT(payAmt);
    entity.setxPAY_DATE(payDate);
    entity.setxPAY_REASON(paymentWhat);
    entity.setxREMARK(remark);
    entity.setxCOMPANY_PRINCIPAL_xID(companyPrincipleId);
    entity.setxPROJECT_xID(projectId);
    entity.setxCOMPANY_xID(companyId);

    return entity;
  }
 public int update(CompanyPrincipal entity) {
   CompanyPrincipalDao companyPrincipalDao =
       AppContextUtil.getAppContext().getBean("companyPrincipalDao", CompanyPrincipalDao.class);
   return companyPrincipalDao.update(entity);
 }
 public CompanyPrincipal getCompanyPrincipal(int xID) {
   CompanyPrincipalDao companyPrincipalDao =
       AppContextUtil.getAppContext().getBean("companyPrincipalDao", CompanyPrincipalDao.class);
   return companyPrincipalDao.selectById(xID);
 }
Beispiel #8
0
  private void handleBudget(HttpServletRequest request, Payment entity) throws Exception {
    BudgetActionHelper budgetActionHelper =
        AppContextUtil.getAppContext().getBean("budgetActionHelper", BudgetActionHelper.class);
    BudgetHelper budgetHelper =
        AppContextUtil.getAppContext().getBean("budgetHelper", BudgetHelper.class);

    // handle budget
    User user = (User) ParamUtil.getSessionAttr(request, "LOGIN_USER");
    if (user == null) throw new Exception(MessageConsts.MSG_COMMON_SESSION_TIMEOUT);
    Budget currentBudget =
        budgetHelper.getBudgetByPaydate(user.getxDEPT_xID(), entity.getxPAY_DATE());

    // if there are no budget,then no paymentAction too
    if (currentBudget == null) {
      return;
    }

    BudgetAction paymenAction = new BudgetAction();
    paymenAction.setxACTION(MessageConsts.BUDGET_TYPE_PAYMENT);
    paymenAction.setxPAYMENT_ID(entity.getxID());
    paymenAction.setxACTION_AMT(entity.getxPAY_AMT());
    paymenAction.setxCREATER_ID(user.getxLOGIN_ID());
    if (currentBudget != null) {
      paymenAction.setxBUDGET_xID(currentBudget.getxID());
      paymenAction.setxSOURCE_AMT(currentBudget.getxBALANCE_AMT());
    }
    budgetActionHelper.insert(paymenAction);

    // handle borrow
    int deptId = ParamUtil.getInt(request, "deptId", 0);
    double borrowAmt = ParamUtil.getDouble(request, "borrowAmtHidden", 0);
    logger.info("PaymentAction-->borrowDeptId:" + deptId);
    logger.info("PaymentAction-->borrowAmt:" + borrowAmt);
    if (deptId > 0 && borrowAmt > 0) {
      Budget borrowBudget = budgetHelper.getBudgetByPaydate(deptId, entity.getxPAY_DATE());
      BudgetAction borrowOutAction = new BudgetAction();
      borrowOutAction.setxBUDGET_xID(borrowBudget.getxID());
      borrowOutAction.setxPAYMENT_ID(entity.getxID());
      borrowOutAction.setxACTION(MessageConsts.BUDGET_TYPE_BORROW_OUT);
      borrowOutAction.setxSOURCE_AMT(borrowBudget.getxBALANCE_AMT());
      borrowOutAction.setxACTION_AMT(borrowAmt);
      borrowOutAction.setxCREATER_ID(user.getxLOGIN_ID());
      budgetActionHelper.insert(borrowOutAction);

      borrowBudget.setxBALANCE_AMT(Calculator.sub(borrowBudget.getxBALANCE_AMT(), borrowAmt));
      budgetHelper.update(borrowBudget);

      BudgetAction borrowInAction = new BudgetAction();
      borrowInAction.setxBUDGET_xID(currentBudget.getxID());
      borrowInAction.setxPAYMENT_ID(entity.getxID());
      borrowInAction.setxACTION(MessageConsts.BUDGET_TYPE_BORROW_IN);
      borrowInAction.setxSOURCE_AMT(currentBudget.getxBALANCE_AMT());
      borrowInAction.setxACTION_AMT(borrowAmt);
      borrowInAction.setxRELATED_BUDGET_ACTION_ID(borrowOutAction.getxID());
      borrowInAction.setxCREATER_ID(user.getxLOGIN_ID());
      budgetActionHelper.insert(borrowInAction);

      borrowOutAction.setxRELATED_BUDGET_ACTION_ID(borrowInAction.getxID());
      budgetActionHelper.update(borrowOutAction);
    }

    double currentBalanceAmt =
        Calculator.add(
            Calculator.sub(currentBudget.getxBALANCE_AMT(), entity.getxPAY_AMT()), borrowAmt);
    currentBudget.setxBALANCE_AMT(currentBalanceAmt);
    budgetHelper.update(currentBudget);
  }
Beispiel #9
0
  private void rollBackPreviousAction(Payment payment) {
    int xID = payment.getxID();

    BudgetActionHelper budgetActionHelper =
        AppContextUtil.getAppContext().getBean("budgetActionHelper", BudgetActionHelper.class);
    List<BudgetAction> budgetActions =
        budgetActionHelper.getActionByActionTypeAndPaymentID(null, xID);

    BudgetHelper budgetHelper =
        AppContextUtil.getAppContext().getBean("budgetHelper", BudgetHelper.class);
    Budget borrowOutBudget = null;
    Budget currentBudget = null;
    Double borrowInAmt = 0.0D;
    if (budgetActions != null && budgetActions.size() > 0) {
      //
      for (int i = 0; i < budgetActions.size(); i++) {
        BudgetAction action = budgetActions.get(i);
        if (MessageConsts.BUDGET_TYPE_BORROW_OUT.equals(action.getxACTION())) {
          double borrowOutAmt = action.getxACTION_AMT();
          borrowInAmt = borrowOutAmt;
        }
      }

      for (int i = 0; i < budgetActions.size(); i++) {
        BudgetAction action = budgetActions.get(i);

        // add the budgetAmt to borrowOut Budget
        if (MessageConsts.BUDGET_TYPE_BORROW_OUT.equals(action.getxACTION())) {
          // Get the borrow out budget
          int borrowOutBudgetId = action.getxBUDGET_xID();
          double borrowOutAmt = action.getxACTION_AMT();

          // Add the borrowOutAmt to the borrow out budget
          borrowOutBudget = budgetHelper.getBudget(borrowOutBudgetId, false);
          if (borrowOutBudget != null) {
            logger.info(
                "BorrowOut Budget Amt: "
                    + String.valueOf(
                        Calculator.add(borrowOutBudget.getxBALANCE_AMT(), borrowOutAmt)));
            borrowOutBudget.setxBALANCE_AMT(
                Calculator.add(borrowOutBudget.getxBALANCE_AMT(), borrowOutAmt));
            budgetHelper.update(borrowOutBudget);
          }
        }

        // add the budgetAmt to current Budget
        if (MessageConsts.BUDGET_TYPE_PAYMENT.equals(action.getxACTION())) {
          // Get the borrow out budget
          int currentBudgetId = action.getxBUDGET_xID();
          double payOutAmt = action.getxACTION_AMT();

          // Add the budgetAmt to the current budget
          currentBudget = budgetHelper.getBudget(currentBudgetId, false);
          if (currentBudget != null) {
            logger.info(
                "currentBudget.getxBALANCE_AMT(): "
                    + String.valueOf(currentBudget.getxBALANCE_AMT()));
            logger.info("payOutAmt: " + String.valueOf(payOutAmt));
            logger.info("borrowInAmt: " + String.valueOf(borrowInAmt));
            logger.info(
                "Current Budget Amt "
                    + Calculator.sub(
                        Calculator.add(currentBudget.getxBALANCE_AMT(), payOutAmt), borrowInAmt));
            currentBudget.setxBALANCE_AMT(
                Calculator.sub(
                    Calculator.add(currentBudget.getxBALANCE_AMT(), payOutAmt), borrowInAmt));
            budgetHelper.update(currentBudget);
          }
        }

        // delete this budget action
        budgetActionHelper.delete(action.getxID());
      }
    }
  }
Beispiel #10
0
  private void edit(HttpServletRequest request) throws Exception {
    BudgetHelper budgetHelper =
        AppContextUtil.getAppContext().getBean("budgetHelper", BudgetHelper.class);
    BudgetActionHelper actionHelper =
        AppContextUtil.getAppContext().getBean("budgetActionHelper", BudgetActionHelper.class);
    PaymentHelper paymentHelper =
        AppContextUtil.getAppContext().getBean("paymentHelper", PaymentHelper.class);
    // Get payment entity
    // -->
    logger.info("----->PaymentEditAction into edit<-----");

    // Get the  entity
    Payment payment = setEntity(request);
    paymentHelper.saveEntity(payment);
    payment = paymentHelper.getPayment(payment.getxID(), true);

    // Roll back old records
    rollBackPreviousAction(payment);

    // HandleBudget
    handleBudget(request, payment);

    // Past the data to the Jsp
    Budget budget = null;
    double borrowAmt = 0.0;
    int borrowDeptId = 0;
    int borrowBudgetId = 0;
    logger.info("----->PaymentEditAction into Search Ready to Get the actionList ");
    List<BudgetAction> actionList =
        actionHelper.getActionByActionTypeAndPaymentID(
            MessageConsts.BUDGET_TYPE_BORROW_OUT, payment.getxID());
    logger.info(
        "----->PaymentEditAction into Search  2.Get the budget and budget action  actionList size"
            + actionList.size());
    if (actionList != null && actionList.size() > 0) {
      logger.info("----->PaymentEditAction into Search  borrow From Other");
      BudgetAction borrowOutAction = actionList.get(0);
      if (borrowOutAction != null) {
        // Get the borrow amt
        borrowAmt = borrowOutAction.getxACTION_AMT();

        // Get the borrow dept by budget
        borrowBudgetId = borrowOutAction.getxBUDGET_xID();
        if (borrowBudgetId > 0) {
          budget = budgetHelper.getBudget(borrowBudgetId, false);
          if (budget != null) {
            borrowDeptId = budget.getxDEPT_xID();
          }
        }
      }
    }

    request.setAttribute("xID", payment.getxID());
    request.setAttribute("entity", payment);
    //		request.setAttribute("borrowFromOther", borrowFromOther);
    request.setAttribute("borrowAmt", borrowAmt);
    request.setAttribute("borrowDeptId", borrowDeptId);
    request.setAttribute("hasSave", AppConsts.YES);

    logger.info("----->PaymentEditAction End of Edit Method <-----");
  }