期初合同销售订单认领直接生成高级版收款单
This commit is contained in:
		
							parent
							
								
									a27d073012
								
							
						
					
					
						commit
						934312e370
					
				|  | @ -7,8 +7,12 @@ import javax.ws.rs.Path; | |||
| import javax.ws.rs.Produces; | ||||
| import nc.bs.framework.common.NCLocator; | ||||
| import nc.bs.trade.business.HYSuperDMO; | ||||
| import nc.itf.bd.defdoc.IDefdocService; | ||||
| import nc.itf.pmpub.project.pub.IProjectServiceForPu; | ||||
| import nc.vo.arap.basebill.BaseAggVO; | ||||
| import nc.vo.pmpub.project.ProjectHeadVO; | ||||
| import nc.vo.pub.BusinessException; | ||||
| import nc.vo.pub.lang.UFDateTime; | ||||
| import nccloud.api.rest.utils.NCCRestUtils; | ||||
| import nccloud.api.rest.utils.ResultMessageUtil; | ||||
| import nccloud.pubitf.arap.openapi.IGatheringbillOpenService; | ||||
|  | @ -32,6 +36,7 @@ import java.util.Base64; | |||
| import java.util.HashMap; | ||||
| import java.util.List; | ||||
| import java.util.TreeMap; | ||||
| import java.util.stream.Collectors; | ||||
| import java.util.zip.GZIPInputStream; | ||||
| import javax.crypto.Mac; | ||||
| import javax.crypto.spec.SecretKeySpec; | ||||
|  | @ -788,4 +793,309 @@ public class GatheringbillRestResource extends ArapBaseRestResource { | |||
| 		return value.toString().trim(); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 	/** | ||||
| 	 * 期初合同销售订单认领直接生成高级版收款单 | ||||
| 	 * | ||||
| 	 * @param str | ||||
| 	 * @return | ||||
| 	 */ | ||||
| 
 | ||||
| 	@POST | ||||
| 	@Path("/bipinsert1") | ||||
| 	@Consumes({ "application/json" }) | ||||
| 	@Produces({ "application/json" }) | ||||
| 	public JSONString bipInsertPaybill1(JSONString str) throws BusinessException { | ||||
| 		InvocationInfoProxy.getInstance().setGroupId("0001A110000000000677"); | ||||
| 		NCCRestUtils.initInvocationInfo(); | ||||
| 		String json = str.toJSONString(); | ||||
| 		Map<String, Object> billMap = (Map) fromJson(json, Map.class); | ||||
| 		billMap.put("recaccount", billMap.get("ar_recaccount")); | ||||
| 		GatheringBillVO headvo = (GatheringBillVO) fromJsonToVO(billMap, GatheringBillVO.class); | ||||
| 		headvo.setDef28(headvo.getBilldate().toStdString());// 交易日期 | ||||
| 		// 汇率为空时,默认为1 | ||||
| 		if (headvo.getRate() == null) { | ||||
| 			headvo.setRate(UFDouble.ONE_DBL); | ||||
| 		} | ||||
| 		// 结算方式名称 | ||||
| 		Object balatypeName = ""; | ||||
| 		// 金额 | ||||
| 		UFDouble money = new UFDouble(0); | ||||
| 		// 税率 | ||||
| 		UFDouble ntaxrate = new UFDouble(0); | ||||
| 		// 税码 | ||||
| 		String ctaxcode = ""; | ||||
| 		BaseDAO dao = new BaseDAO(); | ||||
| 		// 销售订单号 从表体拿 | ||||
| //		String csaleorderid = ""; | ||||
| 
 | ||||
| 		// 客户 从表体拿 | ||||
| 		String customer = ""; | ||||
| 		List<Map<String, Object>> itemMaps = (List) billMap.get("items"); | ||||
| 		List<GatheringBillItemVO> itemvos = new ArrayList<GatheringBillItemVO>(); | ||||
| 		if (itemMaps != null && itemMaps.size() > 0) { | ||||
| 			for (Map<String, Object> item : itemMaps) { | ||||
| 				GatheringBillItemVO itemvo = (GatheringBillItemVO) fromJsonToVO(item, GatheringBillItemVO.class); | ||||
| 				customer = itemvo.getCustomer(); | ||||
| 			} | ||||
| 		} | ||||
| 		try { | ||||
| 			HYPubBO hybo = new HYPubBO(); | ||||
| 			headvo.setIsinit(new UFBoolean(false)); | ||||
| 			// 默认 收款类型 默认合同收款单 | ||||
| 			Object pk_billtypecode = hybo.findColValue("bd_billtype", "PK_BILLTYPECODE", "billtypename = '合同收款单' "); | ||||
| 			headvo.setPk_tradetype(pk_billtypecode.toString()); | ||||
| 			// 业务流程 默认【收款结算】 | ||||
| 			Object pk_busitype = hybo.findColValue("bd_busitype", "busicode", "businame = '收款结算' "); | ||||
| 			headvo.setPk_busitype(pk_busitype.toString()); | ||||
| 			// 往来对象0-客户 2-部门 3-业务员 默认客户 | ||||
| 			headvo.setObjtype(0); | ||||
| 			headvo.setCustomer(customer); | ||||
| 
 | ||||
| 			// pk_currtype 币种编码 默认人民币 | ||||
| 			if (headvo.getPk_currtype() == null || headvo.getPk_currtype().isEmpty()) { | ||||
| 				headvo.setPk_currtype("CNY"); | ||||
| 			} | ||||
| 
 | ||||
| 			// accessorynum 附件张数 默认2 | ||||
| 			headvo.setAccessorynum(2); | ||||
| 			// 制单人 默认BIP | ||||
| 			headvo.setBillmaker("BIP"); | ||||
| 			// 结算方式名称 | ||||
| 			String balatypeCode = headvo.getPk_balatype(); | ||||
| 			if (!StringUtils.isEmpty(balatypeCode)) { | ||||
| 				Object pk_balatype = hybo.findColValue("bd_balatype", "pk_balatype", " code = '" + balatypeCode + "' "); | ||||
| //			          headvo.setPk_balatype(pk_balatype.toString()); | ||||
| 				if (pk_balatype != null) { | ||||
| 					balatypeName = hybo.findColValue("bd_balatype", "name", " code = '" + balatypeCode + "' "); | ||||
| 				} | ||||
| 
 | ||||
| 			} | ||||
| 
 | ||||
| 			// 银行收款账号 | ||||
| 			// 原币金额 | ||||
| 			// 单据状态 | ||||
| 			headvo.setBillstatus(-1); | ||||
| 			// 单据来源系统编码 | ||||
| 			headvo.setSrc_syscode(17); | ||||
| 			// 合同金额 | ||||
| 			// 结算组织 | ||||
| 			headvo.setSett_org(headvo.getPk_org()); | ||||
| 		} catch (Exception e) { | ||||
| 			return ResultMessageUtil.exceptionToJSON(e); | ||||
| 		} | ||||
| 		//根据BIP传的值进行创建自定义档案 def2	合同销售订单号 | ||||
| 		//def6	合同编号 | ||||
| 		//def3	标前项目号 | ||||
| 		if (itemMaps.size() > 0) { | ||||
| 			NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(headvo.getPk_org(), createDefVO(itemMaps.stream() | ||||
| 					.map(map -> (String) map.get("def6")) | ||||
| 					.collect(Collectors.toList()), "zdy-001", headvo.getPk_org().toString())); | ||||
| 		} | ||||
| 		if (itemMaps.size() > 0) { | ||||
| 			NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(headvo.getPk_org(), createDefVO(itemMaps.stream() | ||||
| 					.map(map -> (String) map.get("def2")) | ||||
| 					.collect(Collectors.toList()), "BIP-ddh", headvo.getPk_org().toString())); | ||||
| 		} | ||||
| 		if (itemMaps.size() > 0) { | ||||
| 			NCLocator.getInstance().lookup(IDefdocService.class).insertDefdocs(headvo.getPk_org(), createDefVO(itemMaps.stream() | ||||
| 					.map(map -> (String) map.get("def3")) | ||||
| 					.collect(Collectors.toList()), "zdy-023", headvo.getPk_org().toString())); | ||||
| 
 | ||||
| 			createProjectHeadVO(itemMaps,   headvo.getPk_org().toString()); | ||||
| 		} | ||||
| 
 | ||||
| 		if (itemMaps != null && itemMaps.size() > 0) { | ||||
| 			for (Map<String, Object> item : itemMaps) { | ||||
| 				GatheringBillItemVO itemvo = (GatheringBillItemVO) fromJsonToVO(item, GatheringBillItemVO.class); | ||||
| 
 | ||||
| 				try { | ||||
| 					HYPubBO hybo = new HYPubBO(); | ||||
| 					itemvo.setRecaccount(headvo.getRecaccount()); | ||||
| 					// pk_balatype 结算方式 表头带出 | ||||
| 					itemvo.setPk_balatype(headvo.getPk_balatype()); | ||||
| 					// 票据类型 checktype 结算方式:银行承兑汇票-电子、银行承兑汇票-纸质=银行承兑汇票;商业承兑汇票-电子、商业承兑汇票-纸质=商业承兑汇票 | ||||
| 					String checktypeName = ""; | ||||
| 					if ("银行承兑汇票-电子".equals(balatypeName)) { | ||||
| 						checktypeName = "电子银行承兑汇票"; | ||||
| 					} else if ("商业承兑汇票-电子".equals(balatypeName)) { | ||||
| 						checktypeName = "电子商业承兑汇票"; | ||||
| 					} else if ("商业承兑汇票-纸质".equals(balatypeName)) { | ||||
| 						checktypeName = "商业承兑汇票"; | ||||
| 					} else if ("银行承兑汇票-纸质".equals(balatypeName)) { | ||||
| 						checktypeName = "银行承兑汇票"; | ||||
| 					} | ||||
| 
 | ||||
| 					if (checktypeName != "") { | ||||
| 						Object checktypeCode = hybo.findColValue("bd_notetype", "code", | ||||
| 								" name = '" + checktypeName + "' "); | ||||
| 						itemvo.setChecktype(checktypeCode.toString()); | ||||
| 					} | ||||
| 
 | ||||
| 					// objtype 往来对象0-客户 2-部门 3-业务员 表头带出 | ||||
| 					itemvo.setObjtype(headvo.getObjtype()); | ||||
| 					// supplier 客户编码 表头带出 | ||||
| //					itemvo.setCustomer(headvo.getCustomer()); | ||||
| 					// pk_dept 部门编码 表头带出 | ||||
| 					itemvo.setPk_deptid(headvo.getPk_deptid()); | ||||
| 					// pk_psndoc 业务员编码 表头带出 | ||||
| 					itemvo.setPk_psndoc(headvo.getPk_psndoc()); | ||||
| 					// pk_currtype 币种编码 表头带出 | ||||
| 					itemvo.setPk_currtype(headvo.getPk_currtype()); | ||||
| 					// prepay 收款性质 默认应收款 0 | ||||
| 					itemvo.setPrepay(0); | ||||
| 					// | ||||
| 					UFDouble money_cr = itemvo.getMoney_cr(); | ||||
| 					UFDouble local_tax_cr = money_cr.multiply(ntaxrate).div(100); | ||||
| 					itemvo.setLocal_tax_cr(local_tax_cr); | ||||
| 					// | ||||
| 					UFDouble notax_cr = money_cr.sub(local_tax_cr); | ||||
| 					itemvo.setNotax_cr(notax_cr); | ||||
| 					// zhangxinah增加组织本币无税金额(贷方) | ||||
| 					itemvo.setLocal_notax_cr(notax_cr); | ||||
| 					// 汇率为空时,默认为1 | ||||
| 					if (headvo.getRate() == null) { | ||||
| 						itemvo.setRate(UFDouble.ONE_DBL); | ||||
| 					} else { | ||||
| 						itemvo.setRate(headvo.getRate()); | ||||
| 					} | ||||
| 					// | ||||
| 					itemvo.setTaxcodeid(ctaxcode); | ||||
| 					// | ||||
| 					itemvo.setTaxrate(ntaxrate); | ||||
| 					// 收支项目 | ||||
| 					itemvo.setPk_subjcode("201"); | ||||
| 					money = money.add(itemvo.getMoney_cr()); | ||||
| 					itemvo.setLocal_money_cr( | ||||
| 							itemvo.getMoney_cr().multiply(itemvo.getRate()).setScale(2, UFDouble.ROUND_HALF_UP)); | ||||
| 					Object def2 = itemvo.getDef2(); | ||||
| 					if (def2 != null) | ||||
| 						itemvo.setDef2(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def2 + "' ") + ""); | ||||
| 					Object def3 = itemvo.getDef3(); | ||||
| 					if (def3 != null) | ||||
| 						itemvo.setDef3(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def3 + "' ") + ""); | ||||
| 					Object def6 = itemvo.getDef6(); | ||||
| 					if (def6 != null) | ||||
| 						itemvo.setDef6(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def6 + "' ") + ""); | ||||
| //					Object def36 = itemvo.getDef36(); | ||||
| //					if (def36 != null) | ||||
| //						itemvo.setDef36(hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + def36 + "' ") + ""); | ||||
|                     //新增自定义档案 | ||||
| 
 | ||||
| 					HYSuperDMO dmo = new HYSuperDMO(); | ||||
| //					SaleOrderHVO[] hvo = (SaleOrderHVO[]) dmo.queryByWhereClause(SaleOrderHVO.class, | ||||
| //							"vbillcode='" + def2 + "' and dr=0"); | ||||
| //					if (hvo == null || hvo.length == 0) { | ||||
| //						throw new BusinessException("该销售订单在ERP中被删除,订单号:" + def2); | ||||
| //					} | ||||
| //					SaleOrderBVO[] bvos = (SaleOrderBVO[]) dmo.queryByWhereClause(SaleOrderBVO.class, | ||||
| //							"csaleorderid='" + hvo[0].getPrimaryKey() + "'"); | ||||
| //					if (bvos != null) { | ||||
| //						itemvo.setSrc_billid(bvos[0].getCsaleorderid()); | ||||
| //						itemvo.setSrc_itemid(bvos[0].getCsaleorderbid()); | ||||
| //						itemvo.setSrc_billtype("30"); | ||||
| //						itemvo.setSrc_tradetype(hvo[0].getVtrantypecode()); | ||||
| //						itemvo.setTop_billid(bvos[0].getCsaleorderid()); | ||||
| //						itemvo.setTop_itemid(bvos[0].getCsaleorderbid()); | ||||
| //						itemvo.setTop_billtype("30"); | ||||
| //					} | ||||
| 
 | ||||
| 				} catch (Exception e) { | ||||
| 					return ResultMessageUtil.exceptionToJSON(e); | ||||
| 				} | ||||
| 
 | ||||
| 				itemvos.add(itemvo); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		headvo.setMoney(money); | ||||
| 		headvo.setGloballocal(money); | ||||
| 		// headvo.setRate(new UFDouble(1)); | ||||
| 		headvo.setLocal_money(money.multiply(headvo.getRate()).setScale(2, UFDouble.ROUND_HALF_UP)); | ||||
| 		AggGatheringBillVO bill = new AggGatheringBillVO(); | ||||
| 		bill.setParentVO(headvo); | ||||
| 		bill.setChildrenVO((CircularlyAccessibleValueObject[]) itemvos.toArray(new GatheringBillItemVO[0])); | ||||
| 		try { | ||||
| 			Map<String, String> returnMap = ((IGatheringbillOpenService) NCLocator.getInstance() | ||||
| 					.lookup(IGatheringbillOpenService.class)).saveBill(bill); | ||||
| 			JSONString resultJson = ResultMessageUtil.toJSON(returnMap); | ||||
| 			// 保存后动作 | ||||
| 			JSONObject js_result = JSON.parseObject(resultJson.toJSONString()); | ||||
| 			if (js_result.containsKey("success")) { | ||||
| 				if (js_result.getString("success").equals("true")) { | ||||
| 					if (js_result.containsKey("data")) { | ||||
| 						JSONObject js_data = js_result.getJSONObject("data"); | ||||
| 						String pk_gatherid = js_data.getString("pk_bill"); | ||||
| 						String pk_org = js_data.getString("pk_org"); | ||||
| 						GatheringBillItemVO[] billItemVOs = (GatheringBillItemVO[]) bill.getChildrenVO(); | ||||
| 						for (GatheringBillItemVO gatheringBillItemVO : billItemVOs) { | ||||
| //							afterChangeMny(gatheringBillItemVO.getSrc_billid(), pk_org, billItemVOs[0].getDef6(), | ||||
| //									pk_gatherid); | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 			} | ||||
| 			return resultJson; | ||||
| 		} catch (BusinessException e) { | ||||
| 			return ResultMessageUtil.exceptionToJSON(e); | ||||
| 		} | ||||
| 	} | ||||
| 	private DefdocVO[] createDefVO(List<String> newhth, String defdoclistcode, String pk_org) throws BusinessException { | ||||
| 		String sql = " select pk_defdoclist from bd_defdoclist  where code='" + defdoclistcode + "' "; | ||||
| 
 | ||||
| 		BaseDAO dao = new BaseDAO(); | ||||
| 		String o = (String) dao.executeQuery(sql, new ColumnProcessor()); | ||||
| 		HYPubBO hybo = new HYPubBO(); | ||||
| 
 | ||||
| 		ArrayList<DefdocVO> arrvo = new ArrayList<DefdocVO>(); | ||||
| 		for (int i = 0; i < newhth.size(); i++) { | ||||
| 
 | ||||
| 			Object pk_defdoc = hybo.findColValue("bd_defdoc", "pk_defdoc", " code = '" + newhth.get(i) + "' "); | ||||
| 			if (pk_defdoc != null) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			DefdocVO vo = new DefdocVO(); | ||||
| 			vo.setEnablestate(2); | ||||
| 			vo.setPk_defdoclist(o); | ||||
| 			vo.setPk_org(pk_org); | ||||
| 			vo.setCode(newhth.get(i)); | ||||
| 			vo.setName(newhth.get(i)); | ||||
| 			vo.setDataoriginflag(0); | ||||
| 			vo.setDr(0); | ||||
| 			vo.setPk_group(InvocationInfoProxy.getInstance().getGroupId()); | ||||
| 			vo.setCreator(InvocationInfoProxy.getInstance().getUserId()); | ||||
| 			vo.setCreationtime(new UFDateTime()); | ||||
| 
 | ||||
| 			arrvo.add(vo); | ||||
| 		} | ||||
| 
 | ||||
| 		return arrvo.toArray(new DefdocVO[arrvo.size()]); | ||||
| 
 | ||||
| 	} | ||||
| 	private ProjectHeadVO[] createProjectHeadVO(List<Map<String, Object>> newhth,String pk_org) throws BusinessException { | ||||
| 		HYPubBO hybo = new HYPubBO(); | ||||
| 		ArrayList<ProjectHeadVO> arrvo = new ArrayList<ProjectHeadVO>(); | ||||
| 		for (int i = 0; i < newhth.size(); i++) { | ||||
| 			Object pk_project = hybo.findColValue("bd_project", "pk_project", " PROJECT_CODE = '" + (String) newhth.get(i).get("def6") + "' "); | ||||
| 			if (pk_project != null) { | ||||
| 				continue; | ||||
| 			} | ||||
| 			ProjectHeadVO vo = new ProjectHeadVO(); | ||||
| 			vo.setEnablestate(2); | ||||
| 			vo.setPk_org(pk_org); | ||||
| 			vo.setProject_code((String) newhth.get(i).get("def6")); | ||||
| 			vo.setProject_name((String) newhth.get(i).get("def6")+(String) newhth.get(i).get("def36")); | ||||
| 			vo.setPk_eps(hybo.findColValue("pm_eps", "pk_eps", " eps_code = '"+01+"' ") + ""); | ||||
| 			vo.setDr(0); | ||||
| 			vo.setPk_group(InvocationInfoProxy.getInstance().getGroupId()); | ||||
| 			vo.setCreator(InvocationInfoProxy.getInstance().getUserId()); | ||||
| 			vo.setCreationtime(new UFDateTime()); | ||||
| 			NCLocator.getInstance().lookup(IProjectServiceForPu.class).insertProject(vo); | ||||
| 
 | ||||
| 		} | ||||
| 
 | ||||
| 		return arrvo.toArray(new ProjectHeadVO[arrvo.size()]); | ||||
| 
 | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue