浏览代码

材料请购单接口生成请购单接口类

zthwr 1 年之前
父节点
当前提交
9824ef77d7

+ 43 - 5
xc/cg/src/private/u8c/impl/DemandAddImpl.java

@@ -1,6 +1,8 @@
 package u8c.impl;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
@@ -15,18 +17,24 @@ import com.microsoft.sqlserver.jdbc.StringUtils;
 import nc.bs.dao.BaseDAO;
 import nc.bs.framework.adaptor.IHttpServletAdaptor;
 import nc.bs.framework.common.NCLocator;
+import nc.bs.pub.billcodemanage.BillcodeGenerater;
 import nc.itf.uap.IUAPQueryBS;
 import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.vo.jcom.lang.StringUtil;
 import nc.vo.pub.BusinessException;
+import nc.vo.pub.CircularlyAccessibleValueObject;
 import nc.vo.pub.lang.UFDate;
 import nc.vo.pub.lang.UFDouble;
 import nc.vo.trade.pub.IBillStatus;
 import u8c.bs.servlet.service.BaseServlet;
 import u8c.bs.servlet.service.GetBaseDAOUtil;
+import u8c.itf.po.IDemandPurchaseRequisition;
 import u8c.log.NcLog;
 import u8c.vo.DemandBVO;
 import u8c.vo.DemandVO;
 
+import nc.bs.framework.common.NCLocator;
+
 public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 	private  IUAPQueryBS iuap = NCLocator.getInstance().lookup(IUAPQueryBS.class);
 	BaseDAO dao = new BaseDAO();
@@ -72,6 +80,10 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 				JSONObject bodyObject = JSONObject.parseObject(Object.toString());
 				String pk_corp = bodyObject.getString("pk_corp");//计划组织
 				String vbillcode = bodyObject.getString("vbillcode");//单据号
+				String prjcodehead=bodyObject.getString("prjcode");
+				if(StringUtil.isEmpty(vbillcode)) {//如果单据号为空则自动生成
+					vbillcode=new BillcodeGenerater().getBillCode("A2A3",pk_corp, null, null);
+				}
 				String pk_demandOld = getVbillcode(vbillcode);
 				if(!StringUtils.isEmpty(pk_demandOld)) {
 					errMessage.add(formatRSJsonData("失败","单据号"+ vbillcode +"已存在",""));
@@ -95,6 +107,9 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 				}
 				String workmanid = GetBaseDAOUtil.getPsndocid(bodyObject.getString("workmanid"));//业务员
 				String plandeptid = GetBaseDAOUtil.getDeptdocid(bodyObject.getString("plandeptid"));//计划部门
+				String xmjbpk=GetBaseDAOUtil.getprojectid(prjcodehead);//项目基本档案主键
+				String xmglpk=SqlexecuteQuery("pk_jobmngfil","bd_jobmngfil","pk_jobbasfil",xmjbpk);//项目管理档案主键
+				
 				String vnote = bodyObject.getString("vnote");//备注
 				DemandVO headvo = new DemandVO();
 				//表头赋值
@@ -108,6 +123,7 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 				headvo.setVnote(vnote);//备注
 				headvo.setVdef30(bodyObject.getString("vdef30"));//业务类型
 				headvo.setBillstatus(IBillStatus.FREE);
+				headvo.setProjectid(xmglpk);
 				String pk_demand = dao.insertVO(headvo);
 				//表体赋值
 				if(bodyObject.getJSONArray("po")!=null) {
@@ -124,8 +140,16 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 						String cmaterialname = GetBaseDAOUtil.getinvname(cmaterialcode);//存货名称
 						String spec = GetBaseDAOUtil.getinvspec(cmaterialcode);//规格
 						String model = GetBaseDAOUtil.getinvtype(cmaterialcode);//型号
-						String width = GetBaseDAOUtil.getwidth(cmaterialcode);//宽度
-						String height = GetBaseDAOUtil.getheight(cmaterialcode);//高度
+						String width = injsobj.getString("width");//宽度
+						String height = injsobj.getString("height");//高度
+//						String castunitid = GetBaseDAOUtil.getMeasidByName(injsobj.getString("castunitid"));//辅助计量单位
+						String castunitid = injsobj.getString("castunitid");//辅助计量单位
+						String num = injsobj.getString("num");//数量
+						String nastnum = injsobj.getString("nastnum");//辅数量
+						String vdef13="";//换算率
+						if( (!StringUtils.isEmpty(num)) && (!StringUtils.isEmpty(nastnum)) ) {//判断数量与辅数量不为空计算换算率
+							vdef13=new UFDouble(num).div(new UFDouble(nastnum)).toString();
+						}
 						String unitid = GetBaseDAOUtil.getmeasname(cmaterialcode);//计量单位
 						String vdef1 = injsobj.getString("vdef1");//楼号楼层
 						String vdef2 = injsobj.getString("vdef2");//樘数(数量) 
@@ -139,6 +163,7 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 						String vdef10 = injsobj.getString("vdef10");//备注
 						String vdef11 = injsobj.getString("vdef11");//系列
 						String vdef12 = injsobj.getString("vdef12");//玻璃编号
+						
 						DemandBVO bodyvo = new DemandBVO();
 						bodyvo.setPrjcode(prjcode);;
 						bodyvo.setPrjname(prjname);
@@ -151,8 +176,10 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 						bodyvo.setModel(model);
 						bodyvo.setWidth(width);
 						bodyvo.setHeight(height);
+						bodyvo.setCastunitid(castunitid);
+						bodyvo.setNastnum(nastnum);
 						bodyvo.setUnitid(unitid);
-						bodyvo.setNum(new UFDouble(injsobj.getString("num")));//数量
+						bodyvo.setNum(new UFDouble(num));//数量
 						bodyvo.setPk_demand(pk_demand);
 						bodyvo.setVdef1(vdef1);
 						bodyvo.setVdef2(vdef2);
@@ -166,7 +193,19 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 						bodyvo.setVdef10(vdef10);
 						bodyvo.setVdef11(vdef11);
 						bodyvo.setVdef12(vdef12);
+						bodyvo.setVdef13(vdef13);
+						bodyvo.setColor(injsobj.getString("color"));
+						bodyvo.setSizing(injsobj.getString("sizing"));
+						bodyvo.setAlloy(injsobj.getString("alloy"));
+					//	bodyvo.setStandard("国标");
 						dao.insertVO(bodyvo);
+						//生成请购单
+//						IDemandPurchaseRequisition lookup = NCLocator.getInstance().lookup(IDemandPurchaseRequisition.class);
+						List<DemandBVO> demandBVOs = new ArrayList();
+						demandBVOs.add(bodyvo);
+//						lookup.addPraybillVO(headvo,demandBVOs);
+						DemandPurchaseRequisitionImpl dao = new DemandPurchaseRequisitionImpl();
+						dao.addPraybillVO(headvo,demandBVOs);
 					}
 				}
 				result.add(formatRSJsonData("成功","",vbillcode));
@@ -243,7 +282,6 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
 		
 		JSONArray oprepObjectBs = json.getJSONArray("result");
 		
-		String vbillcode = "vbillcode";//单据号
 		String pk_corp = "pk_corp";//组织
 		String billmaker = "billmaker";//制单人
 		String dbilldate = "dbilldate";//单据日期
@@ -252,7 +290,7 @@ public class DemandAddImpl extends BaseServlet implements IHttpServletAdaptor{
  
 		for(int i = 0; i < oprepObjectBs.size(); i++) {
 			JSONObject oprepJsonObjectB = oprepObjectBs.getJSONObject(i);
-			String[] HeadKey = {vbillcode,pk_corp,billmaker,dbilldate};
+			String[] HeadKey = {pk_corp,billmaker,dbilldate};
 			int num = i+1;
 			
 			mags.append("第"+num+"块表头:{");

+ 117 - 0
xc/cg/src/private/u8c/impl/DemandPurchaseRequisitionImpl.java

@@ -0,0 +1,117 @@
+package u8c.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import nc.bs.framework.common.NCLocator;
+import nc.itf.uap.IUAPQueryBS;
+import nc.itf.uap.pf.IplatFormEntry;
+import nc.jdbc.framework.processor.ColumnProcessor;
+import nc.ui.pub.beans.MessageDialog;
+import nc.vo.hr.tools.pub.HRAggVO;
+import nc.vo.pr.pray.PraybillHeaderVO;
+import nc.vo.pr.pray.PraybillItemVO;
+import nc.vo.pr.pray.PraybillVO;
+import nc.vo.pub.BusinessException;
+import nc.vo.pub.CircularlyAccessibleValueObject;
+import nc.vo.pub.lang.UFBoolean;
+import nc.vo.pub.lang.UFDate;
+import u8c.bs.servlet.service.GetBaseDAOUtil;
+import u8c.itf.po.IDemandPurchaseRequisition;
+import u8c.ui.mytest.panel.DemandTestUI;
+import u8c.vo.DemandBVO;
+import u8c.vo.DemandVO;
+
+public class DemandPurchaseRequisitionImpl implements IDemandPurchaseRequisition {
+	
+	private IUAPQueryBS iuap = NCLocator.getInstance().lookup(IUAPQueryBS.class);
+	DemandTestUI frameUI = null;
+	
+	/**
+	 * 根据材料采购单生成请购单
+	 * @param s
+	 * @throws Exception 
+	 */
+	@Override
+	//HRAggVO s
+	public void addPraybillVO(DemandVO demandVO, List<DemandBVO> demandBVOs) throws Exception {
+		
+//		DemandVO DemandBVO
+		
+//		DemandVO demandVO = (DemandVO) s.getParentVO();//
+//		CircularlyAccessibleValueObject[] demandBVOList =  s.getAllChildrenVO();//
+//		List<DemandBVO> demandBVOs = new ArrayList();
+//		for(CircularlyAccessibleValueObject vo : demandBVOList) {
+//			if(vo instanceof DemandBVO) {
+//				demandBVOs.add((DemandBVO)vo);
+//			}
+//		}
+//		if(demandBVOs.size()==0) {
+//			throw new BusinessException("当前材料采购单没有数据,请先添加数据");
+//		}
+		PraybillHeaderVO header = new PraybillHeaderVO();
+		header.setPk_corp(demandVO.getPk_corp());//公司
+		header.setDpraydate(demandVO.getDbilldate());//单据日期-->请购日期
+		header.setIpraysource(5);//请购来源
+		header.setIpraytype(2);//请购类型
+		header.isDirecttransit(new UFBoolean(true));// -->是否直运???
+		header.setIbillstatus(0);//单据状态
+		header.setCpraypsn(demandVO.getWorkmanid());//请购人id-->业务员
+		header.setCdeptid(demandVO.getPlandeptid());//请购部门id-->计划部门
+		header.setVmemo(demandVO.getVnote());//备注-》备注
+		header.setDr(0);
+		header.setCaccountyear(String.valueOf(new UFDate().getYear()));//年份
+		header.setCoperator(demandVO.getBillmaker());//制单人-》制单人
+		PraybillItemVO[] items = new PraybillItemVO[demandBVOs.size()];
+		for (int i = 0; i < demandBVOs.size(); i++) {
+			DemandBVO demandBVO = demandBVOs.get(i);
+			PraybillItemVO praybillItemVO = new PraybillItemVO();
+			praybillItemVO.setPk_corp(demandVO.getPk_corp()); // 公司
+			// 表体赋值
+			praybillItemVO.setRowno((i+1)*10+"");//行号(单据模板里面是crowno,但是对象中只有Rowno)
+			praybillItemVO.setCmangid(getCmangid(demandBVO.getCmaterialcode())); //存货编码-》存货编码
+			praybillItemVO.setNpraynum(demandBVO.getNum()); //主数量-》数量
+			praybillItemVO.setDdemanddate(new UFDate());//-->需求日期 ???
+			String cprojectid = "";//项目id
+			if(demandBVO.getPrjcode().startsWith("1001")) {
+				cprojectid = demandBVO.getPrjcode();
+			}
+			else {
+				cprojectid = GetBaseDAOUtil.getprojectid(demandBVO.getPrjcode());
+			}
+			praybillItemVO.setCprojectid(cprojectid);
+//			praybillItemVO.setCassistunit(demandBVO.getCastunitid());//辅助计量单位
+//			praybillItemVO.setNassistnum(new UFDouble(demandBVO.getNastnum()));//辅计量数量
+//			praybillItemVO.setVproducenum(demandBVO.getVbatchcode());//批次号
+			items[i] = praybillItemVO;
+		}
+		PraybillVO vo = new PraybillVO();
+		vo.setParentVO(header);
+		vo.setChildrenVO(items);
+		PraybillVO[] praybillVOs = new PraybillVO[1];
+		praybillVOs[0] = vo;
+		IplatFormEntry iIplatFormEntry = (IplatFormEntry)NCLocator.getInstance().lookup(IplatFormEntry.class.getName());
+		ArrayList retObj = (ArrayList) iIplatFormEntry.processAction("SAVEBASE", "20", vo.getHeadVO().getDpraydate().toString(), null, vo, null, null);
+		MessageDialog.showHintDlg(frameUI, "成功", "请购单新增成功");
+//		IPrayBillMaintainAPI prayBillMaintainAPI = NCLocator.getInstance().lookup(IPrayBillMaintainAPI.class);
+//		prayBillMaintainAPI.insert(praybillVOs);
+
+	}
+
+	/**
+	 * 根据物料code查询主键
+	 * @param code
+	 * @return
+	 * @throws BusinessException
+	 */
+	public String getCmangid(String code) throws BusinessException {
+		String cmangid = null;
+		String sql = " select pk_invbasdoc from bd_invbasdoc" + " where invcode  ='" + code + "' and dr =0 ";
+		cmangid = (String) iuap.executeQuery(sql, new ColumnProcessor());
+		if (cmangid == null) {
+			throw new BusinessException("U8C物料code不存在:" + code);
+		}
+		return cmangid;
+	}
+
+}