public void save() { try { boolean settleTypeFlag = false; Jhpay jhpay = null; Ckjhcheck m = getModel(Ckjhcheck.class, "ckjhcheck"); Jbsupplier supplier = getModel(Jbsupplier.class, "supplier"); Jbstore store = getModel(Jbstore.class, "store"); m.set("SupplierCode", supplier.getStr("supplierCode")); m.set("StoreCode", store.getStr("StoreCode")); Double amount = Double.parseDouble(getPara("amount")); m.set("CKAmount", amount); if (getPara("typeFlg") != null && getParaToInt("typeFlg") == 1) { m.set("SettleTypeFlag", getParaToInt("typeFlg")); settleTypeFlag = true; } if (m.getLong("id") != null) { m.update(); } else { m.save(); } // 当面付模式 if (settleTypeFlag) { jhpay = Jhpay.dao.findFirst("select * from jhpay where BillOrderNo = ?", m.getStr("OrderDate")); if (jhpay == null) { // 生成付款单信息 jhpay = new Jhpay(); synchronized (lock) { String ordCdNw = BsUtil.getMaxOrdNo("OrderCode", "CF", "jhpay"); jhpay.set("OrderCode", ordCdNw); } jhpay.set( "OrderDate", DateUtil.string2Date( DateUtil.date2String(new Date(), DateUtil.FORMAT_DATE), DateUtil.FORMAT_DATE)); jhpay.set("SupplierCode", m.get("SupplierCode")); jhpay.set("DeptCode", m.get("DeptCode")); jhpay.set("EmpCode", m.get("EmpCode")); jhpay.set("PayType", BsUtil.DIR_PAY); jhpay.set("BankNo", supplier.get("BankNo")); jhpay.set("Amount", amount); jhpay.set("BillOrderNo", m.get("OrderCode")); Record man = getCurrentUser(); jhpay.set("checkman", man.getStr("usr_name")); jhpay.set("CheckDate", new Date()); jhpay.set("CheckFlag", 1); jhpay.save(); Jhpaydetail jhpaydetail = new Jhpaydetail(); jhpaydetail.set("OrderCode", m.get("OrderCode")); jhpaydetail.set("PayOrderNo", jhpay.get("OrderCode")); jhpaydetail.set("CollateType", "采购入库单"); jhpaydetail.set("NowCollated", amount); jhpaydetail.set("Adjust", 0); jhpaydetail.set("Amount", amount); } } String orderCode = m.get("OrderCode"); // 保存明细 int size = 0; // 通过【新建商品明细】按钮新追加记录 String[] index = getParaValues("lineId"); size = Db.queryLong( "select count(*) from ckjhcheckdetail where orderCode = '" + orderCode + "'") .intValue(); if (!(index == null || index.length == 0)) { size = size + index.length; } // 不足10条,补足10条显示并保存 if (size < 10) { size = 10; } for (int i = 0; i < size; i++) { Ckjhcheckdetail md = getModel(Ckjhcheckdetail.class, "ckjhcheckDetail" + i); Jbgoods goods = getModel(Jbgoods.class, "goods" + i); if (goods.getStr("GoodsCode") != null) { md.set("GoodsCode", goods.get("GoodsCode")); Ckjhcheckdetail tmp = Ckjhcheckdetail.dao.findById(md.getLong("id")); if (tmp != null) { md.set("price", goods.get("BRefPrice")); md.update(); } else { md.set("ordercode", orderCode); md.set("price", goods.get("BRefPrice")); md.save(); } } } toDwzJson(200, "保存成功!", navTabId, "closeCurrent"); } catch (Exception e) { log.error("保存仓库分类异常", e); toDwzJson(300, "保存异常!"); } }
public void add() { Ckjhcheck ckjhcheck = new Ckjhcheck(); Jbsupplier jbsupplier = new Jbsupplier(); Jbstore jbstore = new Jbstore(); // 采购入库单号 String ordCdNw = null; // 不是采购订单导入 Long id = getParaToLong(0, 0L); List<Object> param = new ArrayList<Object>(); StringBuffer whee = new StringBuffer(); whee.append(" and a.OrderCode = ?"); if (id != 0) { // 修改 ckjhcheck = Ckjhcheck.dao.findById(id); jbsupplier = Jbsupplier.dao.findFirst( "select * from jbsupplier where supplierCode = ?", ckjhcheck.getStr("SupplierCode")); jbstore = Jbstore.dao.findFirst( "select * from jbstore where StoreCode = ?", ckjhcheck.getStr("StoreCode")); param.add(ckjhcheck.get("orderCode")); } else { synchronized (lock) { ordCdNw = BsUtil.getMaxOrdNo("OrderCode", "PK", "ckjhcheck"); } ckjhcheck.set("OrderCode", ordCdNw); param.add(ordCdNw); // 赋值当前时间 Date dt = new Date(); SimpleDateFormat ckDate = new SimpleDateFormat("yyyy-MM-dd"); ckjhcheck.set("orderdate", ckDate.format(dt)); // 赋值制单人 Record m = getCurrentUser(); ckjhcheck.set("operator", m.getStr("usr_name")); } String sql = "select a.id,b.GoodsCode 商品编号,b.GoodsName 商品名称,b.Model 商品规格,b.BaseUnit 基本单位,b.BRefPrice 原价,a.Discount 折扣, a.Quantity 数量,"; sql += " a.TaxRate 税率,a.TaxAmount 税额,a.Amount 金额"; String sqlSelect = " from ckjhcheckdetail a"; sqlSelect += " left join jbgoods b on a.GoodsCode = b.GoodsCode where 1=1 "; Page<Record> redLst = Db.paginate( getParaToInt("pageNum", 1), getParaToInt("numPerPage", 20), sql, sqlSelect + whee.toString(), param.toArray()); int size = redLst.getList().size(); // 不足10条,补足10条显示 if (size < 10) { for (int i = 0; i < 10 - size; i++) { redLst.getList().add(new Record()); } } setAttr("page", redLst); setAttr( "collist", new String[] {"商品编号", "商品名称", "商品规格", "单位", "原价", "折扣%", "数量", "订单金额", "税率%", "税额", "金额"}); setAttr("ckjhcheck", ckjhcheck); setAttr("store", jbstore); setAttr("supplier", jbsupplier); setAttr(InOutTypeNoSelectTarget.targetName, new InOutTypeNoSelectTarget()); setAttr(PartmentSelectTarget.targetName, new PartmentSelectTarget()); setAttr(EmployeeSelectTarget.targetName, new EmployeeSelectTarget()); render("add.html"); }