NC销售订单

Posted 廿二又

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NC销售订单相关的知识,希望对你有一定的参考价值。

package nc.ui.so.m30.billui.action;

import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.RemoteException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import nc.desktop.ui.Workbench;
import nc.desktop.ui.WorkbenchEnvironment;
import nc.itf.pubapp.pub.exception.IResumeException;
import nc.pubitf.credit.accountcheck.IAccountCheckMessageService;
import nc.pubitf.credit.creditcheck.ICreditCheckMessageService;
import nc.ui.iufo.dao.DAOAction_Client;
import nc.ui.pub.beans.MessageDialog;
import nc.ui.pubapp.pub.common.context.PFlowContext;
import nc.ui.pubapp.pub.locator.NCUILocator;
import nc.ui.pubapp.uif2app.AppUiState;
import nc.ui.pubapp.uif2app.model.BillManageModel;
import nc.ui.so.m30.billui.view.SaleOrderBillForm;
import nc.ui.so.pub.keyvalue.CardKeyValue;
import nc.ui.trade.business.HYPubBO_Client;
import nc.uif.pub.exception.UifException;
import nc.vo.bd.defdoc.DefdocVO;
import nc.vo.bd.material.MaterialVO;
import nc.vo.bd.material.measdoc.MeasdocVO;
import nc.vo.bd.stordoc.StordocVO;
import nc.vo.credit.exception.OverPeriodDayCheckException;
import nc.vo.credit.exception.OverPeriodInnerDayCheckException;
import nc.vo.credit.exception.OverPeriodMoneyCheckException;
import nc.vo.org.FactoryVO;
import nc.vo.org.SalesOrgVO;
import nc.vo.org.StockOrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.billtype.BilltypeVO;
import nc.vo.pub.lang.UFDouble;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.vo.pubapp.pflow.PfUserObject;
import nc.vo.pubapp.res.NCModule;
import nc.vo.scmpub.res.BusinessCheck;
import nc.vo.so.m30.entity.SaleOrderVO;
import nc.vo.so.m4331.entity.DeliveryBVO;
import nc.vo.so.m4331.entity.DeliveryHVO;
import nc.vo.so.pub.enumeration.BillStatus;
//审批
public class SaleOrderMESApproveAction extends nc.ui.pubapp.uif2app.actions.pflow.ApproveScriptAction

	
	protected boolean isActionEnable()
	  
	    Object[] seldatas = model.getSelectedOperaDatas();
	    
	    if ((model.getAppUiState() == AppUiState.NOT_EDIT) && (null != seldatas) && (seldatas.length > 1))
	    
	      
		return true;
	    
	    Object selectedData = model.getSelectedData();
	    Integer status = null;
	    if ((null != selectedData) && ((selectedData instanceof SaleOrderVO))) 
	      SaleOrderVO selorder = (SaleOrderVO)selectedData;
	      status = selorder.getParentVO().getFstatusflag();
	    
	    boolean isEnable = (model.getAppUiState() == AppUiState.NOT_EDIT) && (selectedData != null) && ((BillStatus.FREE.equalsValue(status)) || (BillStatus.AUDITING.equalsValue(status)));
	    
	
	
		
	
	
	    return isEnable;
	  

	/**
	 * 指定类型的字符串转换成日期
	 * @param str
	 * @param format
	 * @return
	 */
	private static Date str2Date(String str, String format) 
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		Date date = null;
		try 
			date = sdf.parse(str);
			return date;
		 catch (java.text.ParseException e) 
			e.printStackTrace();
		
		return null;
	
	
	
	/**
	 * 指定日期转换为指定类型的字符串
	 * @param date
	 * @param format
	 * @return
	 */

private static String date2Str(Date date, String format) 
	SimpleDateFormat sdf = new SimpleDateFormat(format);
	
	if (null == date) 
		return null;
	
	return sdf.format(date);


	
  	@Override
  	public void actionPerformed(ActionEvent e) 
	
		super.actionPerformed(e);
	    Object selectedData = model.getSelectedData();
	    Integer status = null;
	    if ((null != selectedData) && ((selectedData instanceof SaleOrderVO))) 
	      SaleOrderVO selorder = (SaleOrderVO)selectedData;
	      status = selorder.getParentVO().getFstatusflag();
	    
	    boolean isEnable = (model.getAppUiState() == AppUiState.NOT_EDIT) && (selectedData != null) && ((BillStatus.FREE.equalsValue(status)) || (BillStatus.AUDITING.equalsValue(status)));
	
		if (isEnable)
			MessageDialog.showOkCancelDlg(null, "log", "不执行mes接口");
		else
			
			SaleOrderBillForm billform = (SaleOrderBillForm)editor;
		    CardKeyValue keyValue = new CardKeyValue(billform.getBillCardPanel());
		    String hID = keyValue.getHeadStringValue("csaleorderid");//主键
		    String vbillcode = keyValue.getHeadStringValue("vbillcode");//销售发货单-来源单据号
		    
		    StringBuffer sbSql = new StringBuffer("select t.* from jpncdb1.so_delivery_b t where t.csrcid  =  '"+hID+"'");
		    //sbSql.append("");
			//DAOAction_Client.load(DeliveryBVO.class, "jpncdb1", "");
		    try 
		    	//销售发货表体
		    	//MessageDialog.showOkCancelDlg(null, "hID值", hID+"");
				SuperVO[] deliveryBVOs = HYPubBO_Client.queryByCondition(DeliveryBVO.class,  " csrcid = '"+hID+"'");
				//MessageDialog.showOkCancelDlg(null, "deliveryBVOs[0]值", deliveryBVOs[0].toString()+"");
				if(deliveryBVOs.length > 0)
					
					/*for (SuperVO superVO : deliveryBVOs) 
						
					*/
					//select t.cdeliveryid,t.*  from jpncdb1.so_delivery t where t.cdeliveryid =  '1001AZ10000001C3AO9V'
					SuperVO[] deliveryHVOs = HYPubBO_Client.queryByCondition(DeliveryHVO.class, " cdeliveryid =  '"+deliveryBVOs[0].getAttributeValue("cdeliveryid")+"'");
					//销售发货表头
					SuperVO deliveryHVO = deliveryHVOs[0];
					
					//头
					JSONObject hjson = new JSONObject();
					/**销售发货类型*/
					SuperVO trantype = HYPubBO_Client.queryByPrimaryKey(BilltypeVO.class,deliveryHVO.getAttributeValue("ctrantypeid").toString());
					String vtrantypecode=trantype.getAttributeValue("pk_billtypecode").toString();
					String vtrantypename=trantype.getAttributeValue("billtypename").toString();
				    /**发货部门*/
					
					SuperVO salesorg = null;
					if(deliveryHVO.getAttributeValue("csenddeptvid") != null)
						salesorg = HYPubBO_Client.queryByPrimaryKey(SalesOrgVO.class,deliveryHVO.getAttributeValue("csenddeptvid") == null?"": deliveryHVO.getAttributeValue("csenddeptvid").toString());
					
					String csenddeptcode =  "";
					if(salesorg != null)
						csenddeptcode = salesorg.getAttributeValue("name").toString();
					
					
					/**单据日期*/
					String dbilldate = deliveryHVO.getAttributeValue("dbilldate").toString();
				    if(StringUtils.isNotBlank(dbilldate))
				    	dbilldate = date2Str(str2Date(dbilldate, "yyyy-MM-dd"), "yyyy/MM/dd");
				    
				    
					hjson.put("vbillcode", deliveryHVO.getAttributeValue("vbillcode").toString());//销售发货单号
				    hjson.put("ctrantypecode",vtrantypecode);//发货类型
				    //hjson.put("vtrantypename",vtrantypename);//
				    
				    hjson.put("csenddeptcode",csenddeptcode);//发货部门
				    hjson.put("fstatusflag",deliveryHVO.getAttributeValue("fstatusflag").toString());//单据状态
				    hjson.put("dbilldate",dbilldate);//单据日期
				    hjson.put("vnote",deliveryHVO.getAttributeValue("vnote") == null?"": deliveryHVO.getAttributeValue("vnote").toString());//备注 赠品
				    hjson.put("vdef1",deliveryHVO.getAttributeValue("vdef1") == null?"": deliveryHVO.getAttributeValue("vdef1").toString());//自定义项1 
				    
				    //体
				    JSONArray bjsonarr = new JSONArray();
				    for (SuperVO superVO : deliveryBVOs) 
				    	String dsenddate = superVO.getAttributeValue("dsenddate").toString(); //发货日期
				    	if(StringUtils.isNotBlank(dsenddate))
				    		dsenddate = date2Str(str2Date(dsenddate, "yyyy-MM-dd"), "yyyy/MM/dd");
					    
				    	SuperVO material = null;
				    	SuperVO defdoc = null;
				    	SuperVO measdoc = null;
				    	SuperVO factory = null;
				    	SuperVO stockorg = null;
				    	SuperVO stordoc = null;
				    	SuperVO cust = null;
				    	
				    	try 
							material = HYPubBO_Client.queryByPrimaryKey(MaterialVO.class,superVO.getAttributeValue("cmaterialid").toString());//物料
							if(superVO.getAttributeValue("vfree1") != null)
								defdoc = HYPubBO_Client.queryByPrimaryKey(DefdocVO.class, superVO.getAttributeValue("vfree1").toString());//颜色
							
							measdoc = HYPubBO_Client.queryByPrimaryKey(MeasdocVO.class, superVO.getAttributeValue("castunitid").toString());//计量单位
							stockorg = HYPubBO_Client.queryByPrimaryKey(StockOrgVO.class, superVO.getAttributeValue("csendstockorgid").toString());//发货库存组织
							//factory = HYPubBO_Client.queryByPrimaryKey(FactoryVO.class, cfactoryid);//工厂
							//stordoc = HYPubBO_Client.queryByPrimaryKey(StordocVO.class, csendstordocid);//发货仓库
							cust = HYPubBO_Client.queryByPrimaryKey(nc.vo.bd.cust.CustomerVO.class, superVO.getAttributeValue("cordercustid").toString());//客户
							
							
							
						 catch (UifException e1) 
							e1.printStackTrace();
						
				    	String materialcode=material.getAttributeValue("code").toString();
				    	String materialname=material.getAttributeValue("name").toString();
				    	String materialspec=material.getAttributeValue("materialspec") == null ? "":material.getAttributeValue("materialspec").toString();
				    	String materialversion=material.getAttributeValue("version") == null ? "":material.getAttributeValue("version").toString();//物料版本号
				    	
				    	String defdocname = "";//颜色名称
				    	String defdoccode = "";//颜色code
				    	if(defdoc != null)
				    		defdocname = defdoc.getAttributeValue("name").toString();//颜色名称
				    		defdoccode=defdoc.getAttributeValue("code").toString();//颜色code
				    	
				    	
				    	String cunitname=measdoc.getAttributeValue("name").toString();
				    	String cunitcode=measdoc.getAttributeValue("code").toString();
				    	String csendstockorgcode=stockorg.getAttributeValue("code").toString();
				    	String csendstockorgname=stockorg.getAttributeValue("name").toString();
				    	String cordercustcode = cust.getAttributeValue("code").toString();
				    	String cordercustname = cust.getAttributeValue("name").toString();
				    	
				    	
				    	JSONObject bjson = new JSONObject();
				    	bjson.put("vbillcode", deliveryHVO.getAttributeValue("vbillcode").toString());
				    	bjson.put("crowno",  superVO.getAttributeValue("crowno").toString());
				    	bjson.put("materialcode", materialcode);//物料编码
				    	bjson.put("materialspec", materialspec);//规格型号
				    	bjson.put("materialversion", materialversion);//版本
				    	
				    	bjson.put("defdocname", defdocname);//颜色
				    	bjson.put("defdoccode", defdoccode);//颜色code
				    	bjson.put("nastnum", String.valueOf(superVO.getAttributeValue("nastnum").toString()));//数量
				    	bjson.put("castunitcode", cunitcode);//单位编码
				    	bjson.put("castunitname", cunitname);//单位名称
				    	bjson.put("frownote", superVO.getAttributeValue("frownote ") ==null? "":superVO.getAttributeValue("frownote ").toString() );//航备注
				    	bjson.put("csendstockorgcode", csendstockorgname);
				    	//bjson.put("csendstockorgcode", csendstockorgcode);
				    	bjson.put("blargessflag", superVO.getAttributeValue("blargessflag").toString());//曾平
				    	bjson.put("vbdef11", superVO.getAttributeValue("vbdef11").toString());//是否上牌
				    	bjson.put("vbdef12", superVO.getAttributeValue("vbdef12").toString());//是否特价
				    	bjson.put("dsenddate", dsenddate);
				    	bjson.put("vsrccode", superVO.getAttributeValue("vsrccode") == null? "":superVO.getAttributeValue("vsrccode").toString());//来源单据号
				    	bjson.put("vsrcrowno", superVO.getAttributeValue("vsrcrowno") == null? "":superVO.getAttributeValue("vsrcrowno").toString());//来源单据行号 
				    	bjson.put("ntotaloutnum", Integer.parseInt(superVO.getAttributeValue("ntotaloutnum") == null? "0":superVO.getAttributeValue("ntotaloutnum").toString()));//累计出库数量 
				    	bjson.put("cordercustcode", cordercustcode);//客户code
				    	//bjson.put("cordercustcode", cordercustname);//客户code
				    	
				    	bjsonarr.add(bjson);
				    	
					
				    
				    hjson.put("body", bjsonarr);
				    MessageDialog.showOkCancelDlg(null, "MES接口入参JSON", hjson.toString()); 
					
				    
				  //开始调用MES接口
				    String url="http://192.168.1.205/jpmes/api/so/ship/SoShipService";
				    Service service=new Service();
				    Call call = null;
					
					try 
						call = (Call)service.createCall();
					 catch (ServiceException e2) 
						// TODO Auto-generated catch block
						e2.printStackTrace();
					
				
					try 
						call.setTargetEndpointAddress(new java.net.URL(url));
					 catch (MalformedURLException e2) 
						// TODO Auto-generated catch block
						e2.printStackTrace();
					
					
				    call.setOperationName(new QName("http://service.interfaces.mes.pos.com/", "insertOrUpdate"));
				    
				    call.addParameter("arg0", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
				    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
				    String result=null;
				    
					try 
						result=(String)call.invoke(new Object[]hjson.toString());
					 catch (RemoteException e1) 
						// TODO Auto-generated catch block
						e1.printStackTrace();
					
					
				    MessageDialog.showOkCancelDlg(null, "MES接口结果返回", result);
				    StringBuffer sbupdate = new StringBuffer();
				    String sql = "";
				    sql = " update tmp_bt set id =id+1;";
					sbupdate.append(sql);
					DAOAction_Client.execUpdate(sql, "jpncdb1");
					
				else
					//MessageDialog.showOkCancelDlg(null, "提示", "没有发货单!");
				
			    
			 catch (UifException e1) 
				e1.printStackTrace();
			
		    
		
	

  protected boolean isResume(IResumeException resumeInfo)
  
    boolean isCCResume = false;
    

    isCCResume = processCreditCheck(resumeInfo);
    

    boolean isCOPMCResume = false;
    isCOPMCResume = processCreditOverPeriodMoneyCheck(resumeInfo);
    

    boolean isCOPDCResume = false;
    isCOPDCResume = processCreditOverPeriodDayCheck(resumeInfo);
    

    boolean isCOPIDCResume = false;
    isCOPIDCResume = processCreditOverPeriodInnerDayCheck(resumeInfo);
    
    return (isCCResume) && (isCOPMCResume) && (isCOPDCResume) && (isCOPIDCResume);
  
  



  private boolean processCreditOverPeriodMoneyCheck(IResumeException resumeInfo)
  
    boolean isResume = true;
    if (BusinessCheck.CreditOverPeriodMoneyCheck.getCheckCode().equals(resumeInfo.getBusiExceptionType()))
    
      IAccountCheckMessageService service = (IAccountCheckMessageService)NCUILocator.getInstance().lookup(IAccountCheckMessageService.class, NCModule.CREDIT);
      
      try
      
        isResume = service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), ((OverPeriodMoneyCheckException)resumeInfo).getHintMessage());

      
      catch (BusinessException e)
      

        ExceptionUtils.wrappException(e);
      
      

      PfUserObject userObj = getFlowContext().getUserObj();
      if (userObj == null) 
        userObj = new PfUserObject();
      
      userObj.getBusinessCheckMap().put(BusinessCheck.CreditOverPeriodMoneyCheck.getCheckCode(), Boolean.valueOf(!isResume));
      
      getFlowContext().setUserObj(userObj);
    
    return isResume;
  
  







  private boolean processCreditOverPeriodInnerDayCheck(IResumeException resumeInfo)
  
    boolean isResume = true;
    if (BusinessCheck.CreditOverPeriodInnerDayCheck.getCheckCode().equals(resumeInfo.getBusiExceptionType()))
    
      IAccountCheckMessageService service = (IAccountCheckMessageService)NCUILocator.getInstance().lookup(IAccountCheckMessageService.class, NCModule.CREDIT);
      
      try
      
        isResume = service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), ((OverPeriodInnerDayCheckException)resumeInfo).getHintMessage());


      
      catch (BusinessException e)
      

        ExceptionUtils.wrappException(e);
      
      

      PfUserObject userObj = getFlowContext().getUserObj();
      if (userObj == null) 
        userObj = new PfUserObject();
      
      userObj.getBusinessCheckMap().put(BusinessCheck.CreditOverPeriodInnerDayCheck.getCheckCode(), Boolean.valueOf(!isResume));
      

      getFlowContext().setUserObj(userObj);
    
    return isResume;
  
  






  private boolean processCreditOverPeriodDayCheck(IResumeException resumeInfo)
  
    boolean isResume = true;
    if (BusinessCheck.CreditOverPeriodDayCheck.getCheckCode().equals(resumeInfo.getBusiExceptionType()))
    
      IAccountCheckMessageService service = (IAccountCheckMessageService)NCUILocator.getInstance().lookup(IAccountCheckMessageService.class, NCModule.CREDIT);
      
      try
      
        isResume = service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), ((OverPeriodDayCheckException)resumeInfo).getHintMessage());

      
      catch (BusinessException e)
      

        ExceptionUtils.wrappException(e);
      
      

      PfUserObject userObj = getFlowContext().getUserObj();
      if (userObj == null) 
        userObj = new PfUserObject();
      
      userObj.getBusinessCheckMap().put(BusinessCheck.CreditOverPeriodDayCheck.getCheckCode(), Boolean.valueOf(!isResume));
      
      getFlowContext().setUserObj(userObj);
    
    return isResume;
  
  
  private boolean processCreditCheck(IResumeException resumeInfo) 
    boolean isResume = true;
    
    if (BusinessCheck.CreditCheck.getCheckCode().equals(resumeInfo.getBusiExceptionType()))
    
      ICreditCheckMessageService service = (ICreditCheckMessageService)NCUILocator.getInstance().lookup(ICreditCheckMessageService.class, NCModule.CREDIT);
      
      try
      
        isResume = service.showMessage(WorkbenchEnvironment.getInstance().getWorkbench().getParent(), (nc.vo.credit.exception.CreditCheckException)resumeInfo);

      
      catch (BusinessException e)
      
        ExceptionUtils.wrappException(e);
      
      
      PfUserObject userObj = getFlowContext().getUserObj();
      if (userObj == null) 
        userObj = new PfUserObject();
      
      userObj.getBusinessCheckMap().put(BusinessCheck.CreditCheck.getCheckCode(), Boolean.valueOf(!isResume));
      
      getFlowContext().setUserObj(userObj);
    
    return isResume;
  


以上是关于NC销售订单的主要内容,如果未能解决你的问题,请参考以下文章

ABAP如何判断单据是否被锁定

SAP SD如何将销售订单其它ITEM加入到一个已创建好的交货单里

交货单和销售订单增强不能报错误消息导致DUMP问题解决;

sap系统中,一张销售订单做了三张交货单,现要对其中一张交货单做退货,如何配置实现。

参考销售订单创建内向交货单BAPI_OUTB_DELIVERY_CREATE_SLS

如何修改K3单据录入的界面