Beispiel #1
0
  public static int delete(JUser user, Connection con, String[] sk_ids) throws Exception {
    int delRows = 0; // 删除的行数

    if (sk_ids == null) return delRows;
    PreparedStatement pstmt = null, pstmt1 = null, pstmt2 = null;
    ResultSet rs = null;
    String sql = null;

    // 下个月的 两个工作日内 可以修改
    java.util.Date two_workDate = CommonOptions.getConfirmerCanMoidyDate();

    sql = "delete from shinyway.emp_fl_sales where sk_id=? ";
    pstmt = con.prepareStatement(sql);

    sql = "delete from t_flschool_money where sk_id=? and sk_status !=1";
    pstmt1 = con.prepareStatement(sql);

    sql = "select count(*) from t_flschool_money where stu_id=?";
    pstmt2 = con.prepareStatement(sql);

    Connection con_igo = com.gemway.igo.JDatabase.getJDatabase().getConnection();
    String szOperateCompanyCodes = user.getOperateCompanyCodeClause(con_igo, "money", "fl_confirm");
    con_igo.close();

    for (int i = 0; i < sk_ids.length; i++) {
      boolean canDel = false;
      FLSchoolMoney moneyObj = FLSchoolMoney.getFLSchoolMoney(con, sk_ids[i]);

      java.util.Date oldSkDate = JUtil.str2SQLDate(moneyObj.getSk_date()); // 修改前的收款日期

      if ((moneyObj.getSk_status() == 0 || moneyObj.getSk_status() == 2)
          && JUtil.daysAfter(oldSkDate, two_workDate) <= 0) {
        // 审核状态的数据不能删除
        if (user.HasFunc("fl_confirm", "money")
            && szOperateCompanyCodes.indexOf(moneyObj.getCompany_code()) != -1) {
          canDel = true; // 有审核权限的人只能删除一个工作日之内的数据
        } else if (moneyObj.getCreater().equals(user.getUserId())) {
          canDel = true; // 无审核权限的人只能删除自己录入的一个工作日之内的数据
        }
      }
      if (canDel) {
        int updateCount = 0;

        pstmt.setString(1, sk_ids[i]);
        pstmt.executeUpdate();

        pstmt1.setString(1, sk_ids[i]);
        updateCount = pstmt1.executeUpdate();
        if (updateCount > 1) throw new Exception("删除记录超过一条");
        delRows++;

        String stu_id = moneyObj.getStu_id();

        pstmt2.setString(1, stu_id);
        rs = pstmt2.executeQuery();
        rs.next();
        int count = rs.getInt(1);
        rs.close();

        FLSchoolStu.setStatData(con, stu_id);

        if (count == 0) FLSchoolStu.delete(con, stu_id);
        rs.close();
      }
    }
    pstmt.close();
    pstmt1.close();
    pstmt2.close();

    return delRows;
  }
Beispiel #2
0
  public void save(Connection con, JUser user) throws Exception {
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String qry = null;
    java.util.Date skDate = JUtil.str2SQLDate(sk_date);
    java.util.Date today = new java.util.Date();
    java.util.Date two_workDate = CommonOptions.getConfirmerCanMoidyDate();

    if (JUtil.daysAfter(skDate, today) < 0) {
      throw new Exception("收款日期不能在今天之后");
    }
    if (JUtil.daysAfter(skDate, two_workDate) > 0) {
      throw new Exception("收款日期不能在" + JUtil.formatDate(two_workDate, "YYYY-MM-DD") + "之前");
    }

    if (this.company_code.length() == 0) throw new Exception("公司代码不能为空");
    if (this.invoice_type.length() == 0) throw new Exception("开票类型不能为空");
    if (this.currency.length() == 0) throw new Exception("币种不能为空");
    SKItem itemObj = SKItem.getSkItem(sk_item);
    if (itemObj.getItem_type() == 1 || itemObj.getItem_type() == 9 || sk_item.equals("fl.yj.htk")) {
      if (branch_id == null || branch_id.length() == 0) throw new Exception("费用归属分校不能为空");
    }

    if (course_con_id == null || course_con_id.length() == 0) {
      qry =
          "select a.emp_id "
              + "  from shinyway.fl_sale_dist a, t_flschool_student b "
              + " where a.cs_stu_id=b.cs_stu_id and b.stu_id=?"
              + " order by a.row_no";
      pstmt = con.prepareStatement(qry);
      pstmt.setString(1, stu_id);
      rs = pstmt.executeQuery();
      if (rs.next()) course_con_id = rs.getString("emp_id");
      rs.close();
      pstmt.close();
    }

    String skPosName = null;
    if (JSkPos.getSkPosById(sk_pos_id) == null) {
      sk_pos_id = null;
    } else {
      skPosName = JSkPos.getSkPosById(sk_pos_id).getPos_name(); // 收款点名称
    }

    if (sk_id.length() > 0) {
      java.util.Date oldSkDate =
          JUtil.str2SQLDate(FLSchoolMoney.getFLSchoolMoney(con, sk_id).getSk_date()); // 修改前的收款日期
      if (JUtil.daysAfter(oldSkDate, two_workDate) > 0) {
        throw new Exception("不能修改一个工作日前的数据");
      }
      qry =
          " update t_flschool_money "
              + "    set company_code=?, branch_id=?, sk_pos_id=?, sk_pos_name=?, "
              + "        sk_date =?, is_sk=?, stu_id=?,   invoice_type=?, sk_money=?, "
              + "        sk_item=?,  currency=?, course_con_id=?, ds_unit_id=?,  "
              + "        sk_memo=?, modified=?, modifier=?, sk_type=?"
              + "  where sk_id=?";
      int colIndex = 1;
      pstmt = con.prepareStatement(qry);

      pstmt.setString(colIndex++, this.company_code);
      pstmt.setString(colIndex++, this.branch_id);
      pstmt.setString(colIndex++, this.sk_pos_id);
      pstmt.setString(colIndex++, skPosName);
      pstmt.setDate(colIndex++, JUtil.str2SQLDate(sk_date));
      pstmt.setInt(colIndex++, this.is_sk);
      pstmt.setString(colIndex++, this.stu_id);
      pstmt.setString(colIndex++, this.invoice_type);
      pstmt.setString(colIndex++, sk_money);
      pstmt.setString(colIndex++, sk_item);
      pstmt.setString(colIndex++, currency);
      pstmt.setString(colIndex++, this.course_con_id);

      if (ds_unit_id.length() == 0) pstmt.setString(colIndex++, null);
      else pstmt.setString(colIndex++, ds_unit_id);
      pstmt.setString(colIndex++, sk_memo);
      pstmt.setTimestamp(colIndex++, new java.sql.Timestamp(System.currentTimeMillis()));
      pstmt.setString(colIndex++, user.getUserId());
      pstmt.setString(colIndex++, this.sk_type);
      pstmt.setString(colIndex++, sk_id);
      pstmt.executeUpdate();
      pstmt.close();
    } else {
      sk_id = com.gemway.util.ID.getIDObject("DEFAULT").create();

      qry =
          " insert into t_flschool_money "
              + "   (sk_id,     company_code,  branch_id, stu_id,    sk_pos_id,    sk_pos_name,  sk_date,      "
              + "    is_sk,     invoice_type,  sk_money,  sk_item,   currency,     course_con_id,  "
              + "    tk_pay_id, df_pay_id, ds_unit_id,    sk_memo,   sk_status,   creater, created, sk_type) "
              + " values(?,?,?,?,?,?,?,   ?,?,?,?,?,?,  ?,?,?,?,0,?,sysdate,?)";

      int colIndex = 1;
      pstmt = con.prepareStatement(qry);
      pstmt.setString(colIndex++, sk_id);
      pstmt.setString(colIndex++, this.company_code);
      pstmt.setString(colIndex++, this.branch_id);
      pstmt.setString(colIndex++, this.stu_id);
      pstmt.setString(colIndex++, this.sk_pos_id);
      pstmt.setString(colIndex++, skPosName);
      pstmt.setDate(colIndex++, JUtil.str2SQLDate(sk_date));

      pstmt.setInt(colIndex++, this.is_sk);
      pstmt.setString(colIndex++, this.invoice_type);
      pstmt.setDouble(colIndex++, Double.parseDouble(sk_money));
      pstmt.setString(colIndex++, sk_item);
      pstmt.setString(colIndex++, currency);
      pstmt.setString(colIndex++, this.course_con_id);

      pstmt.setString(colIndex++, this.tk_pay_id);
      pstmt.setString(colIndex++, this.df_pay_id);
      pstmt.setString(colIndex++, ds_unit_id.length() == 0 ? null : ds_unit_id);
      pstmt.setString(colIndex++, sk_memo);
      pstmt.setString(colIndex++, user.getUserId());
      pstmt.setString(colIndex++, this.sk_type);
      pstmt.executeUpdate();
      pstmt.close();
    }

    com.gemway.igo.fl.kh.SaleDist.distSkSales(con, sk_id);
    FLSchoolStu.setStatData(con, this.stu_id);
  }