public void addSalFactD(SalFactD sfd) {
   Map params = new Hashtable();
   params.put("branch.id", sfd.getBranchId());
   params.put("fact.no", sfd.getHdNo());
   params.put("no", sfd.getNo());
   params.put("item.id", sfd.getItemId());
   params.put("depart.id", sfd.getFact().getDepartId());
   params.put("person.id", sfd.getPersonId());
   params.put("amount", sfd.getAmount());
   params.put("date", sfd.getFact().getDate());
   params.put("person.workerId", sfd.getPerson().getWorkerId());
   addSalFactD(params);
 }
  public List<SalFactD> getSelectedSalFactDs(Map qo) {
    StringBuilder sb = new StringBuilder();
    sb.append("select s, p.depart from SalFactD s")
        .append(" left outer join fetch s.id.fact")
        .append(" left outer join fetch s.id.fact.depart")
        .append(" left outer join fetch s.id.fact.issuer")
        .append(" left outer join fetch s.id.item")
        .append(" left outer join fetch s.person")
        .append(", PsnOnline p")
        .append(" where 1=1")
        .append(" and s.id.fact.id.branch.id = p.branch.id")
        .append(" and s.person.id = p.person.id")
        .append(" and p.onDate <= s.id.fact.issueDate")
        .append(" and p.downDate >= s.id.fact.issueDate");
    if (qo != null) {
      if (qo.containsKey("branch.id")) sb.append(" and s.id.fact.id.branch.id = :bid");
      if (qo.containsKey("date_from") && qo.get("date_from") != null)
        sb.append(" and s.id.fact.issueDate >= :from");
      if (qo.containsKey("date_to") && qo.get("date_to") != null)
        sb.append(" and s.id.fact.issueDate <= :end");
      if (qo.containsKey("items.id")) sb.append(" and s.id.item.id in (:items)");
    }
    sb.append(
        " order by s.id.fact.depart.id, p.depart.id, s.person.workerId, s.id.fact.id.no, s.id.item.id");
    Query q = getSession().createQuery(sb.toString());
    if (qo != null) {
      if (qo.containsKey("branch.id")) q.setParameter("bid", qo.get("branch.id"));
      if (qo.containsKey("date_from") && qo.get("date_from") != null)
        q.setParameter("from", ObjectUtil.toCalendar(qo.get("date_from")));
      if (qo.containsKey("date_to") && qo.get("date_to") != null)
        q.setParameter("end", ObjectUtil.toCalendar(qo.get("date_to")));
      if (qo.containsKey("items.id")) {
        List<SalItem> list = (List<SalItem>) qo.get("items.id");
        List<Integer> items = new ArrayList<Integer>();
        for (SalItem item : list) {
          if (items.indexOf(item.getId()) == -1) items.add(item.getId());
        }
        q.setParameterList("items", items);
      }
    }

    List l = q.list();
    List<SalFactD> ret = new ArrayList<SalFactD>();
    for (int i = 0; i < l.size(); i++) {
      Object[] obj = (Object[]) l.get(i);
      SalFactD sal = (SalFactD) obj[0];
      sal.getPerson().setDepart((Department) obj[1]);
      ret.add(sal);
    }
    return ret;
  }