调接口生成付款单

package com.kingdee.eas.guiliumuye.duckbreeding.app;

 

import java.math.BigDecimal;
import java.util.Date;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.log4j.Logger;

 
import com.kingdee.bos.*;
import com.kingdee.bos.metadata.bot.BOTMappingFactory;
import com.kingdee.bos.metadata.bot.BOTMappingInfo;
import com.kingdee.bos.metadata.bot.BOTRelationCollection;
import com.kingdee.bos.metadata.bot.BOTRelationFactory;
import com.kingdee.bos.metadata.bot.BOTRelationInfo;
import com.kingdee.bos.metadata.bot.DefineSysEnum;
import com.kingdee.bos.metadata.bot.IBOTMapping;
import com.kingdee.bos.dao.IObjectCollection;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.eas.base.btp.BTPManagerFactory;
import com.kingdee.eas.base.btp.BTPTransformResult;
import com.kingdee.eas.base.btp.IBTPManager;
import com.kingdee.eas.basedata.assistant.CurrencyFactory;
import com.kingdee.eas.basedata.assistant.PaymentTypeFactory;
import com.kingdee.eas.basedata.master.account.AccountViewFactory;
import com.kingdee.eas.basedata.master.auxacct.AsstActTypeFactory;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.fi.cas.PaymentBillEntryCollection;
import com.kingdee.eas.fi.cas.PaymentBillEntryInfo;
import com.kingdee.eas.fi.cas.PaymentBillFactory;
import com.kingdee.eas.fi.cas.PaymentBillInfo;
import com.kingdee.eas.fi.cas.PaymentBillTypeFactory;
import com.kingdee.eas.fi.cas.SourceTypeEnum;
import com.kingdee.eas.fm.common.FMException;
import com.kingdee.eas.framework.CoreBillBaseCollection;
import com.kingdee.eas.framework.CoreBillBaseInfo;
import com.kingdee.eas.guiliumuye.duckbreeding.CalculateStatementFactory;
import com.kingdee.eas.guiliumuye.duckbreeding.CalculateStatementInfo;
import com.kingdee.eas.util.GlUtils;
import com.kingdee.eas.util.SysUtil;


public class CashbotpFacadeControllerBean extends AbstractCashbotpFacadeControllerBean
{
    private static Logger logger =
        Logger.getLogger("com.kingdee.eas.guiliumuye.duckbreeding.app.CashbotpFacadeControllerBean");
     
    
      @Override
    protected String _cashtoPay(Context ctx, String id) throws BOSException,
    		EASBizException {
    	// TODO Auto-generated method stub
    	   JSONArray jsonArray = new JSONArray();
    	   JSONObject jsonObj = new JSONObject();
    	 // IBOTMapping botMapping = BOTMappingFactory.getLocalInstance(ctx);
    	//得到源单
    	  CalculateStatementInfo model = CalculateStatementFactory.getLocalInstance(ctx).getCalculateStatementInfo(new ObjectUuidPK(id));
//    	  CoreBillBaseCollection coreBillBaseColl = new CoreBillBaseCollection();
//          coreBillBaseColl.add((CoreBillBaseInfo)model);
          PaymentBillInfo   payinfo=  new  PaymentBillInfo();
    	  try {                
//    		  //目标单据bostype     
//    		    BOTMappingInfo botp = botMapping.getMapping(model, "40284E81", DefineSysEnum.BTP);
//    	            if (botp == null) {
//    	                throw new FMException(FMException.NODESTBILL);
//    	            }
//    	            IBTPManager botpManager = BTPManagerFactory.getLocalInstance(ctx);
//    	            BTPTransformResult btpResult = null;
//    	            btpResult = botpManager.transformForBotp(coreBillBaseColl, "40284E81", new ObjectUuidPK("fEkBffHGTuWWUFwYFpN9GARRIsQ="));
//    	            IObjectCollection destColl = btpResult.getBills(); //目标单据集合
//    	            BOTRelationCollection botRelations = btpResult.getBOTRelationCollection();  
//    	            for (int i = 0; i < destColl.size(); i++) {
//    	                CoreBillBaseInfo destBillInfo = (CoreBillBaseInfo) destColl.getObject(i); //目标单据
//    	               payinfo=(PaymentBillInfo)destBillInfo;
//    	             botpManager.saveRelations(destBillInfo, botRelations);
//    	              
//    	            }
    	
    		 //使用代码转换
    		
    		  payinfo.setCompany(model.getCompany());
    		  payinfo.setBizDate(new Date());
    		  payinfo.setPayBillType(PaymentBillTypeFactory.getLocalInstance(ctx).getPaymentBillTypeInfo(new ObjectUuidPK("NLGLdwEREADgAAHcwKgSRj6TKVs=")));//付款类型
    		 //币别
    		  payinfo.setCurrency(CurrencyFactory.getLocalInstance(ctx).getCurrencyInfo(new ObjectUuidPK("dfd38d11-00fd-1000-e000-1ebdc0a8100dDEB58FDC")));
    		 //付款金额
    		  payinfo.setAmount(model.getCurrentBalance());
    		  payinfo.setLocalAmt(model.getCurrentBalance());
    		  //业务系统
    		  payinfo.setSourceType(SourceTypeEnum.AP);
    		  //汇率
    		  payinfo.setExchangeRate(new  BigDecimal("1")) ;
    		  //往来户类型
    		  payinfo.setPayeeType(AsstActTypeFactory.getLocalInstance(ctx).getAsstActTypeInfo(new ObjectUuidPK("YW3xsAEJEADgAAUWwKgTB0c4VZA=")));
    		  payinfo.setPayeeID(model.getCust().getId().toString());
    		  payinfo.setPayeeName(model.getCust().getName());
    		  payinfo.setPayeeNumber(model.getCust().getNumber());
    		  // 付款方式
    		  payinfo.setPaymentType(PaymentTypeFactory.getLocalInstance(ctx).getPaymentTypeInfo(new ObjectUuidPK("2fa35444-5a23-43fb-99ee-6d4fa5f260da6BCA0AB5")));
    		 //收款人实名
    		  payinfo.setBankAcctName(model.getCust().getName());
    		  //付款科目
    		  payinfo.setPayerAccount(AccountViewFactory.getLocalInstance(ctx).getAccountViewInfo(new ObjectUuidPK("hIri6WhJSVSOFtaPH8lXOZ2pmCY=")));
    		  //合同号
    		  payinfo.setContractNum(model.getContractNo().getNumber());
    		  //收款银行
    		  payinfo.setPayeeAccountBank(model.getPayingbank());
    		  //收款账户
    		  payinfo.setPayeeBank(model.getBankaccount());
    		  PaymentBillEntryInfo paymentBillEntryInfo =new PaymentBillEntryInfo();
    		  //分录付款金额
    		  paymentBillEntryInfo.setLocalAmt( model.getCurrentBalance());
    		  //分录折本位币
    		  paymentBillEntryInfo.setAmount( model.getCurrentBalance());
    		  paymentBillEntryInfo.setContractNum(model.getContractNo().getNumber());
    		  payinfo.getEntries().add(paymentBillEntryInfo);
    		  IObjectPK save = PaymentBillFactory.getLocalInstance(ctx).save(payinfo);
    		 //手动建立 botp
    		 // GlUtils.createBotpRelation(ctx, model.getBOSType(), payinfo.getBOSType(), model.getId().toString(), save.toString(), "user");
    			BOTRelationInfo botRelationInfo = new BOTRelationInfo();
    			botRelationInfo.setSrcEntityID(model.getBOSType().toString());
    			botRelationInfo.setSrcObjectID(model.getId().toString());
    			botRelationInfo.setDestEntityID(payinfo.getBOSType().toString());
    			botRelationInfo.setDestObjectID(save.toString());
    			botRelationInfo.setDate(new Date());
    			botRelationInfo.setType(0);
    			botRelationInfo.setOperatorID("user");
    			 IObjectPK addnew = BOTRelationFactory.getLocalInstance(ctx).addnew(
 						botRelationInfo);
    	  } catch (Exception e) {
    		  jsonObj.put("staus", "失败");
    		  jsonObj.put("info",  e.getMessage().toString());
    		  e.printStackTrace();
    		   SysUtil.abort();
    		  
   }
    	  jsonObj.put("staus", "成功");
    	  jsonObj.put("info", payinfo.toString() );
    	  jsonArray.add(jsonObj);
    	  return jsonArray.toString() ;
}
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值