Exemplo n.º 1
0
  public static Map<String, Object> convertToMap(ExpBrwModel model, Boolean showDelBtn) {
    if (model == null) {
      return null;
    }

    Map<String, Object> map = new HashMap<String, Object>();

    map.put(ExpBrwConstant.JFN_ID, model.getId());

    map.put(ExpBrwConstant.JFN_REQ_BY, model.getReqBy());

    map.put(ExpBrwConstant.JFN_OBJECTIVE_TYPE, model.getObjectiveType());
    map.put(ExpBrwConstant.JFN_OBJECTIVE, model.getObjective());
    map.put(ExpBrwConstant.JFN_REASON, model.getReason());
    map.put(ExpBrwConstant.JFN_AV_REMARK, model.getAvRemark());
    map.put(ExpBrwConstant.JFN_NOTE, model.getNote());

    map.put(ExpBrwConstant.JFN_BUDGET_CC, model.getBudgetCc());

    map.put(ExpBrwConstant.JFN_FUND_ID, model.getFundId());

    map.put(ExpBrwConstant.JFN_COST_CONTROL_ID, model.getCostControlId());
    map.put(ExpBrwConstant.JFN_COST_CONTROL_TYPE_ID, model.getCostControlTypeId());

    map.put(ExpBrwConstant.JFN_DATE_BACK, model.getDateBack());

    map.put(ExpBrwConstant.JFN_BANK_TYPE, model.getBankType());
    map.put(ExpBrwConstant.JFN_BANK, model.getBank());

    map.put(ExpBrwConstant.JFN_TOTAL, model.getTotal());
    map.put(ExpBrwConstant.JFN_WORKFLOW_INS_ID, model.getWorkflowInsId());
    map.put(ExpBrwConstant.JFN_DOC_REF, model.getDocRef());
    map.put(ExpBrwConstant.JFN_FOLDER_REF, model.getFolderRef());
    map.put(ExpBrwConstant.JFN_WAITING_LEVEL, String.valueOf(model.getWaitingLevel()));
    map.put(ExpBrwConstant.JFN_STATUS, model.getStatus());
    map.put(ExpBrwConstant.JFN_WF_STATUS, model.getWfStatus());
    map.put(ExpBrwConstant.JFN_OVER_DUE, model.getOverDue());
    map.put(
        ExpBrwConstant.JFN_CREATED_TIME_SHOW,
        CommonDateTimeUtil.convertToGridDateTime(model.getCreatedTime()));
    map.put(ExpBrwConstant.JFN_CREATED_TIME, model.getCreatedTime());
    map.put(ExpBrwConstant.JFN_CREATED_BY, model.getCreatedBy());
    map.put(
        ExpBrwConstant.JFN_UPDATED_TIME,
        CommonDateTimeUtil.convertToGridDate(model.getUpdatedTime()));
    map.put(ExpBrwConstant.JFN_UPDATED_BY, model.getUpdatedBy());
    map.put(ExpBrwConstant.JFN_ACTION, getAction(model, showDelBtn));

    return map;
  }
Exemplo n.º 2
0
  public static JSONObject convertToJSONObject(ExpBrwModel model, Boolean showDelBtn)
      throws Exception {
    if (model == null) {
      return null;
    }

    JSONObject jsObj = new JSONObject();

    jsObj.put(ExpBrwConstant.JFN_ID, model.getId());

    jsObj.put(ExpBrwConstant.JFN_REQ_BY, model.getReqBy());

    jsObj.put(ExpBrwConstant.JFN_OBJECTIVE_TYPE, model.getObjectiveType());
    jsObj.put(ExpBrwConstant.JFN_OBJECTIVE_TYPE_NAME, model.getObjectiveTypeName());
    jsObj.put(ExpBrwConstant.JFN_OBJECTIVE, model.getObjective());
    jsObj.put(ExpBrwConstant.JFN_AV_REMARK, model.getAvRemark());
    jsObj.put(ExpBrwConstant.JFN_REASON, model.getReason());
    jsObj.put(ExpBrwConstant.JFN_NOTE, model.getNote());

    jsObj.put(ExpBrwConstant.JFN_BUDGET_CC, model.getBudgetCc());
    jsObj.put(ExpBrwConstant.JFN_BUDGET_CC_NAME, model.getBudgetCcName());
    jsObj.put(ExpBrwConstant.JFN_BUDGET_CC_TYPE, model.getBudgetCcType());
    jsObj.put(ExpBrwConstant.JFN_BUDGET_CC_TYPE_NAME, model.getBudgetCcTypeName());

    jsObj.put(ExpBrwConstant.JFN_FUND_ID, model.getFundId());
    jsObj.put(ExpBrwConstant.JFN_FUND_NAME, model.getFundName());

    jsObj.put(ExpBrwConstant.JFN_COST_CONTROL_ID, model.getCostControlId());
    jsObj.put(ExpBrwConstant.JFN_COST_CONTROL_TYPE_ID, model.getCostControlTypeId());
    jsObj.put(ExpBrwConstant.JFN_COST_CONTROL_NAME, model.getCostControlName());
    jsObj.put(ExpBrwConstant.JFN_COST_CONTROL_TYPE_NAME, model.getCostControlTypeName());

    jsObj.put(
        ExpBrwConstant.JFN_DATE_BACK,
        CommonDateTimeUtil.convertToSenchaFieldDateTime(model.getDateBack()));

    jsObj.put(ExpBrwConstant.JFN_BANK_TYPE, model.getBankType());
    jsObj.put(ExpBrwConstant.JFN_BANK, model.getBank());

    jsObj.put(ExpBrwConstant.JFN_TOTAL, model.getTotal());
    jsObj.put(ExpBrwConstant.JFN_WORKFLOW_INS_ID, model.getWorkflowInsId());
    jsObj.put(ExpBrwConstant.JFN_DOC_REF, model.getDocRef());
    jsObj.put(ExpBrwConstant.JFN_FOLDER_REF, model.getFolderRef());
    jsObj.put(ExpBrwConstant.JFN_WAITING_LEVEL, String.valueOf(model.getWaitingLevel()));
    jsObj.put(ExpBrwConstant.JFN_STATUS, model.getStatus());
    jsObj.put(ExpBrwConstant.JFN_WF_STATUS, model.getWfStatus());
    jsObj.put(ExpBrwConstant.JFN_OVER_DUE, model.getOverDue());
    jsObj.put(
        ExpBrwConstant.JFN_CREATED_TIME_SHOW,
        CommonDateTimeUtil.convertToGridDateTime(model.getCreatedTime()));
    jsObj.put(
        ExpBrwConstant.JFN_CREATED_TIME,
        CommonDateTimeUtil.convertToSenchaFieldDateTime(model.getCreatedTime()));
    jsObj.put(ExpBrwConstant.JFN_CREATED_BY, model.getCreatedBy());
    jsObj.put(
        ExpBrwConstant.JFN_UPDATED_TIME,
        CommonDateTimeUtil.convertToGridDate(model.getUpdatedTime()));
    jsObj.put(ExpBrwConstant.JFN_UPDATED_BY, model.getUpdatedBy());
    jsObj.put(ExpBrwConstant.JFN_ACTION, getAction(model, showDelBtn));

    jsObj.put(
        ExpBrwConstant.JFN_REQUESTED_TIME_SHOW,
        CommonDateTimeUtil.convertToGridDateTime(model.getRequestedTime()));

    return jsObj;
  }
Exemplo n.º 3
0
  public String createAV(ExpBrwModel model) throws Exception {
    log.info("interface : createAV");

    Boolean success = false;
    String msgs = null;
    Map<String, Object> map = new HashMap<String, Object>();

    try {
      Map<String, Object> cfg =
          getConnectionConfig(CommonConstant.EXT_ADMIN_USER, CommonConstant.EXT_ADMIN_PASSWORD);
      XmlRpcClient client = getXmlRpcClient(cfg);

      List<Map<String, Object>> list = expBrwService.listForInf(model.getId());
      Map<String, Object> data = list.size() > 0 ? list.get(0) : null;

      List args = getInitArgs(cfg);
      args.add("hr.expense.expense"); // Remote Object
      args.add("generate_hr_expense"); // method

      List a = new ArrayList();

      /*
       * Header
       */
      map.put("is_employee_advance", "True");
      map.put("number", data.get("av_id"));
      map.put("employee_code", data.get("req_by"));
      map.put("preparer_code", data.get("created_by"));
      map.put("date", CommonDateTimeUtil.convertToOdooFieldDate(CommonDateTimeUtil.now()));
      //	        map.put("write_date",CommonDateTimeUtil.convertToOdooFieldDateTime((Timestamp)
      // data.get("updated_time")));
      map.put("advance_type", data.get("objective_type"));
      map.put(
          "date_back",
          CommonDateTimeUtil.convertToOdooFieldDate(
              data.get("date_back") != null
                  ? (Timestamp) data.get("date_back")
                  : CommonDateTimeUtil.now()));
      map.put("name", data.get("objective"));
      map.put("apweb_ref_url", NodeUtil.trimNodeRef((String) data.get("doc_ref")));
      map.put("receive_method", receiveMethodForInf((String) data.get("bank_type")));
      map.put("employee_bank_id.id", data.get("bank") != null ? data.get("bank") : "");
      map.put("reason_bypass_procure", data.get("reason") != null ? data.get("reason") : "");
      map.put("note", data.get("note") != null ? data.get("note") : "");
      map.put("remark", data.get("av_remark") != null ? data.get("av_remark") : "");

      for (String key : map.keySet()) {
        log.info(" - " + key + ":" + map.get(key));
      }

      /*
       * Line Item
       */
      list = expBrwService.listDtlForInf(model.getId());

      List orderLine = new ArrayList();

      String bgType = (String) data.get("budget_cc_type");
      String bg = ((Integer) data.get("budget_cc")).toString();
      String sid = bgType.equals(MainBudgetSrcConstant.TYPE_UNIT) ? bg : "";
      String pid = bgType.equals(MainBudgetSrcConstant.TYPE_PROJECT) ? bg : "";
      String aid = bgType.equals(MainBudgetSrcConstant.TYPE_ASSET) ? bg : "";
      String cid = bgType.equals(MainBudgetSrcConstant.TYPE_CONSTRUCTION) ? bg : "";

      String ccid =
          data.get("cost_control_id") != null ? data.get("cost_control_id").toString() : "";

      String fundid = data.get("fund_id") != null ? data.get("fund_id").toString() : "";

      for (Map<String, Object> dtl : list) {
        Map<String, Object> line = new HashMap<String, Object>();
        line.put("section_id.id", sid);
        line.put("project_id.id", pid);
        line.put("invest_asset_id.id", aid);
        line.put("invest_construction_phase_id.id", cid);
        line.put("fund_id.id", fundid);
        line.put("is_advance_product_line", "True");
        line.put("activity_group_id.id", String.valueOf(dtl.get("act_grp_id")));
        line.put("activity_id.id", String.valueOf(dtl.get("act_id")));
        line.put("name", dtl.get("activity"));
        line.put("unit_amount", String.valueOf(dtl.get("amount")));
        line.put("cost_control_id.id", ccid);
        orderLine.add(line);

        for (String key : line.keySet()) {
          log.info(" -- " + key + ":" + line.get(key));
        }
      }

      map.put("line_ids", orderLine);

      /*
       * Employee
       */
      List<Map<String, Object>> empList =
          expBrwService.listAttendeeByMasterIdAndType(
              model.getId(), ExpBrwAttendeeConstant.T_EMPLOYEE, null);
      log.info("empList.size()=" + empList.size());

      List employees = new ArrayList();

      int seq = 1;

      for (Map<String, Object> emp : empList) {

        Map<String, Object> employee = new HashMap<String, Object>();
        employee.put("sequence", String.valueOf(seq++));
        employee.put("employee_code", emp.get("code"));
        employees.add(employee);

        for (String key : employee.keySet()) {
          log.info(" ---- " + key + ":" + employee.get(key));
        }
      }

      map.put("attendee_employee_ids", employees);

      /*
       * Non employee
       */
      List<Map<String, Object>> nonempList =
          expBrwService.listAttendeeByMasterIdAndType(
              model.getId(), ExpBrwAttendeeConstant.T_OTHER, null);
      log.info("nonempList.size()=" + nonempList.size());

      List nonemployees = new ArrayList();

      seq = 1;

      for (Map<String, Object> nonemp : nonempList) {

        Map<String, Object> nonemployee = new HashMap<String, Object>();
        nonemployee.put("sequence", String.valueOf(seq++));
        nonemployee.put(
            "attendee_name",
            nonemp.get("title") + " " + nonemp.get("fname") + " " + nonemp.get("lname"));
        nonemployee.put("position", nonemp.get("position") != null ? nonemp.get("position") : "");
        nonemployee.put(
            "organization", nonemp.get("unit_type") != null ? nonemp.get("unit_type") : "");
        nonemployees.add(nonemployee);

        for (String key : nonemployee.keySet()) {
          log.info(" ----- " + key + ":" + nonemployee.get(key));
        }
      }

      map.put("attendee_external_ids", nonemployees);

      /*
       * Attachment
       */
      List<FileModel> fileList = expBrwService.listFile(model.getId(), false);
      log.info("fileList.size()=" + fileList.size());

      List attachment = new ArrayList();

      for (FileModel file : fileList) {
        // detail :
        // http://localhost:18080/share/page/document-details?nodeRef=workspace://SpacesStore/5190b027-00c6-4322-98c3-1be01314bdd9
        // download format url :
        // http://localhost:18080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/<url>/<name>?a=true
        // example url :
        // http://localhost:18080/share/proxy/alfresco/api/node/content/workspace/SpacesStore/260cdb8d-5a9c-43af-9c8e-178c75f1fe38/PR16000050.pdf?a=true

        Map<String, Object> att = new HashMap<String, Object>();
        att.put("name", file.getName());
        att.put("description", file.getDesc() != null ? file.getDesc() : "");
        att.put("url", NodeUtil.trimNodeRef(file.getNodeRef().toString()));
        attachment.add(att);

        for (String key : att.keySet()) {
          log.info(" ------ " + key + ":" + att.get(key));
        }
      }

      map.put("attachment_ids", attachment);

      /*
       * Final
       */
      a.add(map);

      args.add(a);

      log.info("args=" + args);

      /*
       * Call
       */
      Object res = client.invoke("execute_kw", args);

      /*
       * Result
       */
      log.info("res=" + res);

      XmlRpcStruct strc = (XmlRpcStruct) res;

      for (Object k : strc.keySet()) {
        Object v = strc.get(k);

        log.info(" - " + k + " : " + v + ":" + v.getClass().getName());
      }

      success = (Boolean) strc.get("is_success");
      msgs = strc.get("messages") != null ? strc.get("messages").toString() : "";

    } catch (Exception ex) {
      return ex.toString() + ":" + map.toString();
    }

    return success ? "OK" : msgs + ":" + map.toString();
  }