package nc.ui.arap.actions;

import java.awt.event.ActionEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.Icon;
import javax.swing.JFileChooser;
import javax.swing.KeyStroke;

import nc.jdbc.framework.processor.BeanProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.ui.pub.bill.BillModel;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import nc.bs.framework.common.NCLocator;
import nc.itf.uap.IUAPQueryBS;
import nc.pub.templet.converter.util.helper.ExceptionUtils;
import nc.sfbase.client.ClientToolKit;
import nc.ui.arap.view.ArapBillCardForm;
import nc.ui.pub.bill.BillCardPanel;
import nc.ui.pub.report.ReportBaseClass;
import nc.ui.pubapp.uif2app.actions.BodyAddLineAction;
import nc.vo.arap.payable.PayableBillItemVO;

/**
 * 导入
 * @author YY
 *
 */
public class ImportBodyAction extends BodyAddLineAction{
	private IUAPQueryBS iuap = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
	private final static long serialVersionUID = 3494691988067685023L;
	private ArapBillCardForm editorModel;
	private JFileChooser m_chooser = null;
	private ReportBaseClass tp;
	private Icon icon = ClientToolKit.loadImageIcon("\\themeroot\\blue\\themeres\\ui\\toolbaricons\\template.png");
	private int rowCount = 0;
	public ArapBillCardForm getEditorModel() {
		return editorModel;
	}

	public void setEditorModel(ArapBillCardForm arapBillCardForm) {
		this.editorModel = arapBillCardForm;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public ImportBodyAction(){
		setCode("importbodyaction");
		setBtnName("导入");
		setName("导入");
		putValue("AcceleratorKey", KeyStroke.getKeyStroke(82, 8));
		setShowNameInToolbar(true);
		setIsShow(true);
		putValue("ShortDescription", "导入");
		putValue("SmallIcon", icon);

	}
	/**
	 * 获得文件选择器
	 *
	 * @author conn
	 * @return
	 * @return JFileChooser
	 * @date 2019-9-10
	 */
	public JFileChooser getChooser() {
		if (m_chooser == null) {
			m_chooser = new JFileChooser();
			m_chooser.setDialogType(JFileChooser.SAVE_DIALOG);
		}
		return m_chooser;
	}


	@Override
	public void doAction(ActionEvent e) throws Exception {		
		try {
			importData(this);
		} catch (Exception e2) {
			if(rowCount != 0) {
				int rowCounts = this.editorModel.getBillCardPanel().getRowCount();
				//循环删行
				for(int j = rowCounts;j>rowCount;j--){
					System.out.println(j);
					this.editorModel.getBillCardPanel().getBillModel().delLine(new int[] {j-1});
				}	
			}
			if("Cannot get a text value from a numeric cell".equals(e2.getMessage())) {
				throw new Exception("除了数量和金额，所有内容必须为文本格式！请检查Excle！");
			}else {
				throw e2;
			}			
		}
	}

	/**
	 * Excel数据导入
	 *
	 * @author conn
	 * @throws Exception
	 * @return void
	 * @date 2019-9-11
	 * @param importBodyAction
	 */
	public  void importData(ImportBodyAction importBodyAction) throws Exception {
		BillCardPanel cp = importBodyAction.editorModel.getBillCardPanel();
		//只有应付单（非项目） 应付单（项目）可以使用
		String type = sqlexecuteQuery("billtypename", "bd_billtype", "pk_billtypeid", cp.getHeadItem("pk_tradetypeid").getValueObject().toString(),null,0);
		//应付单号
		String billno = cp.getHeadItem("billno").getValueObject().toString();
		if(!"应付单（非项目）".equals(type) && !"应付单（项目）".equals(type) && !"预付核销单（非项目）".equals(type) && !"预付核销单（项目）".equals(type)) {
			return;
		}
		importHendBeforCheck(cp,type);
		String filePath = null;
		FileInputStream fis = null;
		HSSFWorkbook hw = null;

		// 新建一个文件选择器并打开
		JFileChooser jfile = new JFileChooser();
		jfile.setDialogType(JFileChooser.SAVE_DIALOG);
		if (jfile.showSaveDialog(tp) == JFileChooser.CANCEL_OPTION) {
		    return;
		}
		// 获取选择的文件名
		filePath = jfile.getSelectedFile().toString();
		try {
		    fis = new FileInputStream(filePath);
		} catch (FileNotFoundException e) {
		    ExceptionUtils.wrapException(new Exception(e.getMessage()));
		    e.printStackTrace();
		}
		try {
		    hw = new HSSFWorkbook(fis); // 使用HSSFWorkbook
		} catch (IOException e) {
		    e.printStackTrace();
		    ExceptionUtils.wrapException(new Exception(e.getMessage()));
		} finally {
		    try {
		        fis.close();
		    } catch (IOException e) {
		        e.printStackTrace();
		        ExceptionUtils.wrapException(new Exception(e.getMessage()));
		    }
		}

		// 表格从0开始
		HSSFSheet sheet = hw.getSheetAt(0);

		// 获取行数
		int rowNum = sheet.getLastRowNum() + 1;

		rowCount = cp.getRowCount();

		//判断必填项
		importBodyBeforCheck(sheet,type, rowNum);
		for (int i = 2; i < rowNum; i++) {
			
			int count = cp.getRowCount();
			cp.addLine();
			//非项目导出模板
			if("应付单（非项目）".equals(type)) {
				//发票号
				String vbillcode = sheet.getRow(i).getCell(4).getStringCellValue();
				PayableBillItemVO PayableBillItemVO = queryBillItem(billno,vbillcode);
				String pk_org = PayableBillItemVO.getPk_org();
				//摘要
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(0).getStringCellValue(),"999"),count, "def25");
				//费用归属
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(1).getStringCellValue(),"05"),count, "def30");
				//预算编号
				cp.setBodyValueAt(sheet.getRow(i).getCell(2).getStringCellValue(), count, "def1");
				//预算名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_inoutbusiclass", "bd_inoutbusiclass", "name", sheet.getRow(i).getCell(3).getStringCellValue(),null,2), count,"pk_subjcode");
				//发票号
				cp.setBodyValueAt(vbillcode, count, "def12");
				Object quantity_bal = sheet.getRow(i).getCell(5).getCellType() == 1 ? sheet.getRow(i).getCell(5).getStringCellValue() : sheet.getRow(i).getCell(5).getNumericCellValue();
				//数量余额
				cp.setBodyValueAt(quantity_bal,count, "quantity_bal");
				//贷方数量
				cp.setBodyValueAt(quantity_bal,count, "quantity_cr");
				//结算方式
				cp.setBodyValueAt(sqlexecuteQuery("pk_balatype", "bd_balatype", "name", sheet.getRow(i).getCell(6).getStringCellValue(), null,2),count, "pk_balatype");
				//税码
				cp.setBodyValueAt(sqlexecuteQuery("pk_taxcode", "bd_taxcode", "description", sheet.getRow(i).getCell(7).getStringCellValue(), null,2),count, "taxcodeid");	
				//税率
				cp.setBodyValueAt(sheet.getRow(i).getCell(8).getStringCellValue(),count, "taxrate");
 				Object price = null;
				if(dateUnit(sheet,i,9) != null) {
					price = sheet.getRow(i).getCell(9).getCellType() == 1 ? sheet.getRow(i).getCell(9).getStringCellValue() : sheet.getRow(i).getCell(9).getNumericCellValue();
				}
				//单价
				cp.setBodyValueAt(price,count, "price");
				//本币单价
				cp.setBodyValueAt(price,count, "local_price");
				Object caltaxmny = sheet.getRow(i).getCell(10).getCellType() == 1 ? sheet.getRow(i).getCell(10).getStringCellValue() : sheet.getRow(i).getCell(10).getNumericCellValue();
				//计税金额
				cp.setBodyValueAt(caltaxmny,count, "caltaxmny");
				//贷方原币无税金额
				cp.setBodyValueAt(caltaxmny,count, "notax_cr");
				//组织本币无税金额
				cp.setBodyValueAt(caltaxmny,count, "local_notax_cr");
				//税额
				cp.setBodyValueAt(sheet.getRow(i).getCell(11).getCellType() == 1 ? sheet.getRow(i).getCell(11).getStringCellValue() : sheet.getRow(i).getCell(11).getNumericCellValue(),count, "local_tax_cr");
				//原币余额
				Object money_bal = sheet.getRow(i).getCell(12).getCellType() == 1 ? sheet.getRow(i).getCell(12).getStringCellValue() : sheet.getRow(i).getCell(12).getNumericCellValue();
				cp.setBodyValueAt(money_bal,count, "money_bal");
				//组织本币余额
				cp.setBodyValueAt(money_bal,count, "local_money_bal");
				//贷方原币金额
				cp.setBodyValueAt(money_bal,count, "money_cr");
				//组织本币金额
				cp.setBodyValueAt(money_bal,count, "local_money_cr");
				//预占用原币余额
				cp.setBodyValueAt(money_bal,count, "occupationmny");
				//民航发展基金
				cp.setBodyValueAt(dateUnit(sheet,i,13), count, "def29");
				//汇款附言
				cp.setBodyValueAt(dateUnit(sheet,i,14),count, "def21");
				//客户
				cp.setBodyValueAt(dateUnit(sheet,i,15) == null ? null : sqlexecuteQueryDoc(sheet.getRow(i).getCell(15).getStringCellValue(), "CUST"),count, "def13");
				//客户层级
				cp.setBodyValueAt(dateUnit(sheet,i,16),count, "def22");
				//原发票日期
				cp.setBodyValueAt(dateUnit(sheet,i,17),count, "def17");
				//备注
				cp.setBodyValueAt(dateUnit(sheet,i,18),count, "def2");
				//人员
				cp.setBodyValueAt(dateUnit(sheet,i,19),count, "def40");
				//成本归属部门
				cp.setBodyValueAt(sqlexecuteQuery("pk_dept", "org_dept", "name", sheet.getRow(i).getCell(20).getStringCellValue(), pk_org,2),count, "def23");
				String pk_material = sqlexecuteQuery("pk_material", "bd_material", "name", sheet.getRow(i).getCell(21).getStringCellValue(), null, 2);
				//物料
				cp.setBodyValueAt(pk_material,count, "material");
				//原始物料
				cp.setBodyValueAt(pk_material,count, "material_src");
				//含税单价
				cp.setBodyValueAt(PayableBillItemVO.getTaxprice(),count, "taxprice");
				//本币含税单价
				cp.setBodyValueAt(PayableBillItemVO.getLocal_taxprice(),count, "local_taxprice");
				//资产合同号
				cp.setBodyValueAt(PayableBillItemVO.getAssetpactno(),count, "assetpactno");
				//  资金计划项目
				cp.setBodyValueAt(PayableBillItemVO.getBankrollprojet(),count, "bankrollprojet");
				//  单据大类
				cp.setBodyValueAt(PayableBillItemVO.getBillclass(),count, "billclass");
				//  单据日期
				cp.setBodyValueAt(PayableBillItemVO.getBilldate(),count, "billdate");
				//  单据号
				cp.setBodyValueAt(PayableBillItemVO.getBillno(),count, "billno");
				//  起算日期
				cp.setBodyValueAt(PayableBillItemVO.getBusidate(),count, "busidate");
				//  购销类型
				cp.setBodyValueAt(PayableBillItemVO.getBuysellflag(),count, "buysellflag");
				//  现金流量项目
				cp.setBodyValueAt(PayableBillItemVO.getCashitem(),count, "cashitem");
				//  CBS
				cp.setBodyValueAt(PayableBillItemVO.getCbs(),count, "cbs");
				//  责任核算要素
				cp.setBodyValueAt(PayableBillItemVO.getCheckelement(),count, "checkelement");
				//  票据类型
				cp.setBodyValueAt(PayableBillItemVO.getChecktype(),count, "checktype");
				//  摘要c
				cp.setBodyValueAt(PayableBillItemVO.getComment(),count, "comment");
				//  内部交易结算号
				cp.setBodyValueAt(PayableBillItemVO.getConfernum(),count, "confernum");
				//  合同号
				cp.setBodyValueAt(PayableBillItemVO.getContractno(),count, "contractno");
				//  单据协同状态
				cp.setBodyValueAt(PayableBillItemVO.getCoordflag(),count, "coordflag");
				//  成本中心
				cp.setBodyValueAt(PayableBillItemVO.getCostcenter(),count, "costcenter");
				//  方向
				cp.setBodyValueAt(PayableBillItemVO.getDirection(),count, "direction");
				//  设备编码
				cp.setBodyValueAt(PayableBillItemVO.getEquipmentcode(),count, "equipmentcode");
				//  固定资产卡片号
				cp.setBodyValueAt(PayableBillItemVO.getFacard(),count, "facard");
				//  散户
				cp.setBodyValueAt(PayableBillItemVO.getFreecust(),count, "freecust");
				//  全局本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGlobalbalance(),count, "globalbalance");
				//  全局本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalcrebit(),count, "globalcrebit");
				//  全局本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalnotax_cre(),count, "globalnotax_cre");
				//  全局本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGlobalrate(),count, "globalrate");
				//  集团本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGroupbalance(),count, "groupbalance");
				//  集团本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupcrebit(),count, "groupcrebit");
				//  集团本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupnotax_cre(),count, "groupnotax_cre");
				//  集团本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGrouprate(),count, "grouprate");
				//  调拨订单号
				cp.setBodyValueAt(PayableBillItemVO.getInnerorderno(),count, "innerorderno");
				//  发票号
				cp.setBodyValueAt(PayableBillItemVO.getInvoiceno(),count, "invoiceno");
				//  不可抵扣税额
				cp.setBodyValueAt(PayableBillItemVO.getNosubtax(),count, "nosubtax");
				//  不可抵扣税率
				cp.setBodyValueAt(PayableBillItemVO.getNosubtaxrate(),count, "nosubtaxrate");
				//  往来对象
				cp.setBodyValueAt(PayableBillItemVO.getObjtype(),count, "objtype");
				//  是否逆向征税
				cp.setBodyValueAt(PayableBillItemVO.getOpptaxflag(),count, "opptaxflag");
				//  订单供应商
				cp.setBodyValueAt(PayableBillItemVO.getOrdercubasdoc(),count, "ordercubasdoc");
				//  出库单号
				cp.setBodyValueAt(PayableBillItemVO.getOutstoreno(),count, "outstoreno");
				//  挂起标志
				cp.setBodyValueAt(PayableBillItemVO.getPausetransact(),count, "pausetransact");
				//  付款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getPayaccount(),count, "payaccount");
				//  单据类型编码
				cp.setBodyValueAt(PayableBillItemVO.getPk_billtype(),count, "pk_billtype");
				//  币种
				cp.setBodyValueAt(PayableBillItemVO.getPk_currtype(),count, "pk_currtype");
				//  部门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid(),count, "pk_deptid");
				//  部 门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid_v(),count, "pk_deptid_v");
				//  废弃财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg(),count, "pk_fiorg");
				//  废弃财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg_v(),count, "pk_fiorg_v");
				//  所属集团
				cp.setBodyValueAt(PayableBillItemVO.getPk_group(),count, "pk_group");
				//  应付财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_org(),count, "pk_org");
				//  应付财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_org_v(),count, "pk_org_v");
				//  供应商应付单标识
				cp.setBodyValueAt(PayableBillItemVO.getPk_payablebill(),count, "pk_payablebill");
				//  付款协议
				cp.setBodyValueAt(PayableBillItemVO.getPk_payterm(),count, "pk_payterm");
				//  利润中心
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg(),count, "pk_pcorgz");
				//  利润中心版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg_v(),count, "pk_pcorg_v");
				//  业务员
				cp.setBodyValueAt(PayableBillItemVO.getPk_psndoc(),count, "pk_psndoc");
				//  事项审批单
				cp.setBodyValueAt(PayableBillItemVO.getPk_ssitem(),count, "pk_ssitem");
				//  应付类型code
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetype(),count, "pk_tradetype");
				//  应付类型
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetypeid(),count, "pk_tradetypeid");
				//  报价单位含税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostprice(),count, "postprice");
				//  报价单位无税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostpricenotax(),count, "postpricenotax");
				//  报价单位数量
				cp.setBodyValueAt(PayableBillItemVO.getPostquantity(),count, "postquantity");
				//  报价计量单位
				cp.setBodyValueAt(PayableBillItemVO.getPostunit(),count, "postunit");
				//  产品线
				cp.setBodyValueAt(PayableBillItemVO.getProductline(),count, "productline");
				//  项目
				cp.setBodyValueAt(PayableBillItemVO.getProject(),count, "project");
				//  项目任务
				cp.setBodyValueAt(PayableBillItemVO.getProject_task(),count, "project_task");
				//  业务部门
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid(),count, "pu_deptid");
				//  业务部门版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid_v(),count, "pu_deptid_v");
				//  业务组织
				cp.setBodyValueAt(PayableBillItemVO.getPu_org(),count, "pu_org");
				//  业务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_org_v(),count, "pu_org_v");
				//  业务人员
				cp.setBodyValueAt(PayableBillItemVO.getPu_psndoc(),count, "pu_psndoc");
				//  订单号
				cp.setBodyValueAt(PayableBillItemVO.getPurchaseorder(),count, "purchaseorder");
				//  组织本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getRate(),count, "rate");
				//  收款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getRecaccount(),count, "recaccount");
				//  单据分录号
				cp.setBodyValueAt(i-1,count, "rowno");
				//  行类型
				cp.setBodyValueAt(PayableBillItemVO.getRowtype(),count, "rowtype");
				//  摘要
				cp.setBodyValueAt(PayableBillItemVO.getScomment(),count, "scomment");
				//  发货国
				cp.setBodyValueAt(PayableBillItemVO.getSendcountryid(),count, "sendcountryid");
				//  结算财务组织
				cp.setBodyValueAt(PayableBillItemVO.getSett_org(),count, "sett_org");
				//  结算财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getSett_org_v(),count, "sett_org_v");
				//  付款币种
				cp.setBodyValueAt(PayableBillItemVO.getSettlecurr(),count, "settlecurr");
				//  付款金额
				cp.setBodyValueAt(PayableBillItemVO.getSettlemoney(),count, "settlemoney");
				//  源头单据主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billid(),count, "src_billid");
				//  源头单据类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billtype(),count, "src_billtype");
				//  源头单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_itemid(),count, "src_itemid");
				//  源头交易类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_tradetype(),count, "src_tradetype");
				//  科目
				cp.setBodyValueAt(PayableBillItemVO.getSubjcode(),count, "subjcode");
				//  供应商
				cp.setBodyValueAt(PayableBillItemVO.getSupplier(),count, "supplier");
				//  税号
				cp.setBodyValueAt(PayableBillItemVO.getTaxnum(),count, "taxnum");
				//  扣税类别
				cp.setBodyValueAt(PayableBillItemVO.getTaxtype(),count, "taxtype");
				//  上层单据主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_billid(),count, "top_billid");
				//  上层单据类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_billtype(),count, "top_billtype");
				//  加交换时间
				cp.setBodyValueAt(PayableBillItemVO.getTop_changets(),count, "top_changets");
				//  上层单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_itemid(),count, "top_itemid");
				//  上层交易类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_tradetype(),count, "top_tradetype");
				//  VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVatcode(),count, "vatcode");
				//  供应商VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVendorvatcode(),count, "vendorvatcode");
				//自定义1-60
				cp.setBodyValueAt(PayableBillItemVO.getDef3(),count,"def3");
				cp.setBodyValueAt(PayableBillItemVO.getDef4(),count,"def4");
				cp.setBodyValueAt(PayableBillItemVO.getDef5(),count,"def5");
				cp.setBodyValueAt(PayableBillItemVO.getDef6(),count,"def6");
				cp.setBodyValueAt(PayableBillItemVO.getDef7(),count,"def7");
				cp.setBodyValueAt(PayableBillItemVO.getDef8(),count,"def8");
				cp.setBodyValueAt(PayableBillItemVO.getDef9(),count,"def9");
				cp.setBodyValueAt(PayableBillItemVO.getDef10(),count,"def10");
				cp.setBodyValueAt(PayableBillItemVO.getDef11(),count,"def11");
				cp.setBodyValueAt(PayableBillItemVO.getDef14(),count,"def14");
				cp.setBodyValueAt(PayableBillItemVO.getDef15(),count,"def15");
				cp.setBodyValueAt(PayableBillItemVO.getDef16(),count,"def16");
				cp.setBodyValueAt(PayableBillItemVO.getDef18(),count,"def18");
				cp.setBodyValueAt(PayableBillItemVO.getDef19(),count,"def19");
				cp.setBodyValueAt(PayableBillItemVO.getDef20(),count,"def20");
				cp.setBodyValueAt(PayableBillItemVO.getDef24(),count,"def24");
				cp.setBodyValueAt(PayableBillItemVO.getDef26(),count,"def26");
				cp.setBodyValueAt(PayableBillItemVO.getDef27(),count,"def27");
				cp.setBodyValueAt(PayableBillItemVO.getDef28(),count,"def28");
				cp.setBodyValueAt(PayableBillItemVO.getDef31(),count,"def31");
				cp.setBodyValueAt(PayableBillItemVO.getDef32(),count,"def32");
				cp.setBodyValueAt(PayableBillItemVO.getDef33(),count,"def33");
				cp.setBodyValueAt(PayableBillItemVO.getDef34(),count,"def34");
				cp.setBodyValueAt(PayableBillItemVO.getDef35(),count,"def35");
				cp.setBodyValueAt(PayableBillItemVO.getDef36(),count,"def36");
				cp.setBodyValueAt(PayableBillItemVO.getDef37(),count,"def37");
				cp.setBodyValueAt(PayableBillItemVO.getDef38(),count,"def38");
				cp.setBodyValueAt(PayableBillItemVO.getDef39(),count,"def39");
				cp.setBodyValueAt(PayableBillItemVO.getDef41(),count,"def41");
				cp.setBodyValueAt(PayableBillItemVO.getDef42(),count,"def42");
				cp.setBodyValueAt(PayableBillItemVO.getDef43(),count,"def43");
				cp.setBodyValueAt(PayableBillItemVO.getDef44(),count,"def44");
				cp.setBodyValueAt(PayableBillItemVO.getDef45(),count,"def45");
				cp.setBodyValueAt(PayableBillItemVO.getDef46(),count,"def46");
				cp.setBodyValueAt(PayableBillItemVO.getDef47(),count,"def47");
				cp.setBodyValueAt(PayableBillItemVO.getDef48(),count,"def48");
				cp.setBodyValueAt(PayableBillItemVO.getDef49(),count,"def49");
				cp.setBodyValueAt(PayableBillItemVO.getDef50(),count,"def50");
				cp.setBodyValueAt(PayableBillItemVO.getDef51(),count,"def51");
				cp.setBodyValueAt(PayableBillItemVO.getDef52(),count,"def52");
				cp.setBodyValueAt(PayableBillItemVO.getDef53(),count,"def53");
				cp.setBodyValueAt(PayableBillItemVO.getDef54(),count,"def54");
				cp.setBodyValueAt(PayableBillItemVO.getDef55(),count,"def55");
				cp.setBodyValueAt(PayableBillItemVO.getDef56(),count,"def56");
				cp.setBodyValueAt(PayableBillItemVO.getDef57(),count,"def57");
				cp.setBodyValueAt(PayableBillItemVO.getDef58(),count,"def58");
				cp.setBodyValueAt(PayableBillItemVO.getDef59(),count,"def59");
				cp.setBodyValueAt(PayableBillItemVO.getDef60(),count,"def60");

			}else if("应付单（项目）".equals(type)){
				//发票号
				String vbillcode = sheet.getRow(i).getCell(6).getStringCellValue();
				PayableBillItemVO PayableBillItemVO = queryBillItem(billno,vbillcode);
				String pk_org = PayableBillItemVO.getPk_org();
				//摘要
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(0).getStringCellValue(),"999"),count, "def25");
				//费用归属
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(1).getStringCellValue(),"05"),count, "def30");
				//项目编号
				cp.setBodyValueAt(sheet.getRow(i).getCell(2).getStringCellValue(), count, "def18");
				//项目名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_project", "bd_project", "project_name", sheet.getRow(i).getCell(3).getStringCellValue(),null,2), count, "project");
				//专业
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(4).getStringCellValue(), "HR016"), count, "def6");
				//费用事项
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(5).getStringCellValue(), "88"), count, "def7");
				//发票号
				cp.setBodyValueAt(sheet.getRow(i).getCell(6).getStringCellValue(), count, "def12");
				Object quantity_bal = sheet.getRow(i).getCell(7).getCellType() == 1 ? sheet.getRow(i).getCell(7).getStringCellValue() : sheet.getRow(i).getCell(7).getNumericCellValue();
				//数量余额
				cp.setBodyValueAt(quantity_bal,count, "quantity_bal");
				//贷方数量
				cp.setBodyValueAt(quantity_bal,count, "quantity_cr");
				//税码
				cp.setBodyValueAt(sqlexecuteQuery("pk_taxcode", "bd_taxcode", "description", sheet.getRow(i).getCell(8).getStringCellValue(), null,2),count, "taxcodeid");	
				//税率
				cp.setBodyValueAt(sheet.getRow(i).getCell(9).getStringCellValue(),count, "taxrate");
				//结算方式
				cp.setBodyValueAt(sqlexecuteQuery("pk_balatype", "bd_balatype", "name", sheet.getRow(i).getCell(10).getStringCellValue(), null,2),count, "pk_balatype");
				Object price = null;
				if(dateUnit(sheet,i,11) != null) {
					price = sheet.getRow(i).getCell(11).getCellType() == 1 ? sheet.getRow(i).getCell(11).getStringCellValue() : sheet.getRow(i).getCell(11).getNumericCellValue();
				}
				//单价
				cp.setBodyValueAt(price,count, "price");
				//本币单价
				cp.setBodyValueAt(price,count, "local_price");
				Object caltaxmny = sheet.getRow(i).getCell(12).getCellType() == 1 ? sheet.getRow(i).getCell(12).getStringCellValue() : sheet.getRow(i).getCell(12).getNumericCellValue();
				//计税金额
				cp.setBodyValueAt(caltaxmny,count, "caltaxmny");
				//贷方原币无税金额
				cp.setBodyValueAt(caltaxmny,count, "notax_cr");
				//组织本币无税金额
				cp.setBodyValueAt(caltaxmny,count, "local_notax_cr");
				//税额
				cp.setBodyValueAt(sheet.getRow(i).getCell(13).getCellType() == 1 ? sheet.getRow(i).getCell(13).getStringCellValue() : sheet.getRow(i).getCell(13).getNumericCellValue() ,count, "local_tax_cr");
				//民航发展基金
				cp.setBodyValueAt(dateUnit(sheet, i, 14),count, "def29");
				Object money_bal = sheet.getRow(i).getCell(15).getCellType() == 1 ? sheet.getRow(i).getCell(15).getStringCellValue() : sheet.getRow(i).getCell(15).getNumericCellValue();
				//原币余额
				cp.setBodyValueAt(money_bal,count, "money_bal");
				//组织本币余额
				cp.setBodyValueAt(money_bal,count, "local_money_bal");
				//贷方原币金额
				cp.setBodyValueAt(money_bal,count, "money_cr");
				//组织本币金额
				cp.setBodyValueAt(money_bal,count, "local_money_cr");
				//预占用原币余额
				cp.setBodyValueAt(money_bal,count, "occupationmny");
				//汇款附言
				cp.setBodyValueAt(dateUnit(sheet, i, 16),count, "def21");
				//成本归属部门
				cp.setBodyValueAt(sqlexecuteQuery("pk_dept", "org_dept", "name", sheet.getRow(i).getCell(17).getStringCellValue(), pk_org,2),count, "def22");
				//票据号/保理申请编号
				cp.setBodyValueAt(dateUnit(sheet, i, 18), count, "def5");
				//备注
				cp.setBodyValueAt(dateUnit(sheet, i, 19), count, "def2");
				//预算名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_inoutbusiclass", "bd_inoutbusiclass", "name", sheet.getRow(i).getCell(20).getStringCellValue(), null,2),count, "pk_subjcode");
				String pk_material = sqlexecuteQuery("pk_material", "bd_material", "name", sheet.getRow(i).getCell(21).getStringCellValue(), null, 2);
				//物料
				cp.setBodyValueAt(pk_material,count, "material");
				//原始物料
				cp.setBodyValueAt(pk_material,count, "material_src");
				//含税单价
				cp.setBodyValueAt(PayableBillItemVO.getTaxprice(),count, "taxprice");
				//本币含税单价
				cp.setBodyValueAt(PayableBillItemVO.getLocal_taxprice(),count, "local_taxprice");
				//资产合同号
				cp.setBodyValueAt(PayableBillItemVO.getAssetpactno(),count, "assetpactno");
				//  资金计划项目
				cp.setBodyValueAt(PayableBillItemVO.getBankrollprojet(),count, "bankrollprojet");
				//  单据大类
				cp.setBodyValueAt(PayableBillItemVO.getBillclass(),count, "billclass");
				//  单据日期
				cp.setBodyValueAt(PayableBillItemVO.getBilldate(),count, "billdate");
				//  单据号
				cp.setBodyValueAt(PayableBillItemVO.getBillno(),count, "billno");
				//  起算日期
				cp.setBodyValueAt(PayableBillItemVO.getBusidate(),count, "busidate");
				//  购销类型
				cp.setBodyValueAt(PayableBillItemVO.getBuysellflag(),count, "buysellflag");
				//  现金流量项目
				cp.setBodyValueAt(PayableBillItemVO.getCashitem(),count, "cashitem");
				//  CBS
				cp.setBodyValueAt(PayableBillItemVO.getCbs(),count, "cbs");
				//  责任核算要素
				cp.setBodyValueAt(PayableBillItemVO.getCheckelement(),count, "checkelement");
				//  票据类型
				cp.setBodyValueAt(PayableBillItemVO.getChecktype(),count, "checktype");
				//  摘要c
				cp.setBodyValueAt(PayableBillItemVO.getComment(),count, "comment");
				//  内部交易结算号
				cp.setBodyValueAt(PayableBillItemVO.getConfernum(),count, "confernum");
				//  合同号
				cp.setBodyValueAt(PayableBillItemVO.getContractno(),count, "contractno");
				//  单据协同状态
				cp.setBodyValueAt(PayableBillItemVO.getCoordflag(),count, "coordflag");
				//  成本中心
				cp.setBodyValueAt(PayableBillItemVO.getCostcenter(),count, "costcenter");
				//  方向
				cp.setBodyValueAt(PayableBillItemVO.getDirection(),count, "direction");
				//  设备编码
				cp.setBodyValueAt(PayableBillItemVO.getEquipmentcode(),count, "equipmentcode");
				//  固定资产卡片号
				cp.setBodyValueAt(PayableBillItemVO.getFacard(),count, "facard");
				//  散户
				cp.setBodyValueAt(PayableBillItemVO.getFreecust(),count, "freecust");
				//  全局本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGlobalbalance(),count, "globalbalance");
				//  全局本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalcrebit(),count, "globalcrebit");
				//  全局本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalnotax_cre(),count, "globalnotax_cre");
				//  全局本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGlobalrate(),count, "globalrate");
				//  集团本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGroupbalance(),count, "groupbalance");
				//  集团本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupcrebit(),count, "groupcrebit");
				//  集团本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupnotax_cre(),count, "groupnotax_cre");
				//  集团本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGrouprate(),count, "grouprate");
				//  调拨订单号
				cp.setBodyValueAt(PayableBillItemVO.getInnerorderno(),count, "innerorderno");
				//  发票号
				cp.setBodyValueAt(PayableBillItemVO.getInvoiceno(),count, "invoiceno");
				//  不可抵扣税额
				cp.setBodyValueAt(PayableBillItemVO.getNosubtax(),count, "nosubtax");
				//  不可抵扣税率
				cp.setBodyValueAt(PayableBillItemVO.getNosubtaxrate(),count, "nosubtaxrate");
				//  往来对象
				cp.setBodyValueAt(PayableBillItemVO.getObjtype(),count, "objtype");
				//  是否逆向征税
				cp.setBodyValueAt(PayableBillItemVO.getOpptaxflag(),count, "opptaxflag");
				//  订单供应商
				cp.setBodyValueAt(PayableBillItemVO.getOrdercubasdoc(),count, "ordercubasdoc");
				//  出库单号
				cp.setBodyValueAt(PayableBillItemVO.getOutstoreno(),count, "outstoreno");
				//  挂起标志
				cp.setBodyValueAt(PayableBillItemVO.getPausetransact(),count, "pausetransact");
				//  付款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getPayaccount(),count, "payaccount");
				//  单据类型编码
				cp.setBodyValueAt(PayableBillItemVO.getPk_billtype(),count, "pk_billtype");
				//  币种
				cp.setBodyValueAt(PayableBillItemVO.getPk_currtype(),count, "pk_currtype");
				//  部门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid(),count, "pk_deptid");
				//  部 门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid_v(),count, "pk_deptid_v");
				//  废弃财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg(),count, "pk_fiorg");
				//  废弃财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg_v(),count, "pk_fiorg_v");
				//  所属集团
				cp.setBodyValueAt(PayableBillItemVO.getPk_group(),count, "pk_group");
				//  应付财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_org(),count, "pk_org");
				//  应付财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_org_v(),count, "pk_org_v");
				//  供应商应付单标识
				cp.setBodyValueAt(PayableBillItemVO.getPk_payablebill(),count, "pk_payablebill");
				//  付款协议
				cp.setBodyValueAt(PayableBillItemVO.getPk_payterm(),count, "pk_payterm");
				//  利润中心
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg(),count, "pk_pcorgz");
				//  利润中心版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg_v(),count, "pk_pcorg_v");
				//  业务员
				cp.setBodyValueAt(PayableBillItemVO.getPk_psndoc(),count, "pk_psndoc");
				//  事项审批单
				cp.setBodyValueAt(PayableBillItemVO.getPk_ssitem(),count, "pk_ssitem");
				//  应付类型code
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetype(),count, "pk_tradetype");
				//  应付类型
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetypeid(),count, "pk_tradetypeid");
				//  报价单位含税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostprice(),count, "postprice");
				//  报价单位无税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostpricenotax(),count, "postpricenotax");
				//  报价单位数量
				cp.setBodyValueAt(PayableBillItemVO.getPostquantity(),count, "postquantity");
				//  报价计量单位
				cp.setBodyValueAt(PayableBillItemVO.getPostunit(),count, "postunit");
				//  产品线
				cp.setBodyValueAt(PayableBillItemVO.getProductline(),count, "productline");
				//  项目任务
				cp.setBodyValueAt(PayableBillItemVO.getProject_task(),count, "project_task");
				//  业务部门
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid(),count, "pu_deptid");
				//  业务部门版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid_v(),count, "pu_deptid_v");
				//  业务组织
				cp.setBodyValueAt(PayableBillItemVO.getPu_org(),count, "pu_org");
				//  业务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_org_v(),count, "pu_org_v");
				//  业务人员
				cp.setBodyValueAt(PayableBillItemVO.getPu_psndoc(),count, "pu_psndoc");
				//  订单号
				cp.setBodyValueAt(PayableBillItemVO.getPurchaseorder(),count, "purchaseorder");
				//  组织本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getRate(),count, "rate");
				//  收款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getRecaccount(),count, "recaccount");
				//  单据分录号
				cp.setBodyValueAt(i-1,count, "rowno");
				//  行类型
				cp.setBodyValueAt(PayableBillItemVO.getRowtype(),count, "rowtype");
				//  摘要
				cp.setBodyValueAt(PayableBillItemVO.getScomment(),count, "scomment");
				//  发货国
				cp.setBodyValueAt(PayableBillItemVO.getSendcountryid(),count, "sendcountryid");
				//  结算财务组织
				cp.setBodyValueAt(PayableBillItemVO.getSett_org(),count, "sett_org");
				//  结算财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getSett_org_v(),count, "sett_org_v");
				//  付款币种
				cp.setBodyValueAt(PayableBillItemVO.getSettlecurr(),count, "settlecurr");
				//  付款金额
				cp.setBodyValueAt(PayableBillItemVO.getSettlemoney(),count, "settlemoney");
				//  源头单据主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billid(),count, "src_billid");
				//  源头单据类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billtype(),count, "src_billtype");
				//  源头单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_itemid(),count, "src_itemid");
				//  源头交易类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_tradetype(),count, "src_tradetype");
				//  科目
				cp.setBodyValueAt(PayableBillItemVO.getSubjcode(),count, "subjcode");
				//  供应商
				cp.setBodyValueAt(PayableBillItemVO.getSupplier(),count, "supplier");
				//  税号
				cp.setBodyValueAt(PayableBillItemVO.getTaxnum(),count, "taxnum");
				//  扣税类别
				cp.setBodyValueAt(PayableBillItemVO.getTaxtype(),count, "taxtype");
				//  上层单据主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_billid(),count, "top_billid");
				//  上层单据类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_billtype(),count, "top_billtype");
				//  加交换时间
				cp.setBodyValueAt(PayableBillItemVO.getTop_changets(),count, "top_changets");
				//  上层单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_itemid(),count, "top_itemid");
				//  上层交易类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_tradetype(),count, "top_tradetype");
				//  VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVatcode(),count, "vatcode");
				//  供应商VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVendorvatcode(),count, "vendorvatcode");
				//自定义1-60
				cp.setBodyValueAt(PayableBillItemVO.getDef1(),count,"def1");
				cp.setBodyValueAt(PayableBillItemVO.getDef3(),count,"def3");
				cp.setBodyValueAt(PayableBillItemVO.getDef4(),count,"def4");
				cp.setBodyValueAt(PayableBillItemVO.getDef8(),count,"def8");
				cp.setBodyValueAt(PayableBillItemVO.getDef9(),count,"def9");
				cp.setBodyValueAt(PayableBillItemVO.getDef10(),count,"def10");
				cp.setBodyValueAt(PayableBillItemVO.getDef11(),count,"def11");
				cp.setBodyValueAt(PayableBillItemVO.getDef13(),count,"def13");
				cp.setBodyValueAt(PayableBillItemVO.getDef14(),count,"def14");
				cp.setBodyValueAt(PayableBillItemVO.getDef15(),count,"def15");
				cp.setBodyValueAt(PayableBillItemVO.getDef16(),count,"def16");
				cp.setBodyValueAt(PayableBillItemVO.getDef17(),count,"def17");
				cp.setBodyValueAt(PayableBillItemVO.getDef19(),count,"def19");
				cp.setBodyValueAt(PayableBillItemVO.getDef20(),count,"def20");
				cp.setBodyValueAt(PayableBillItemVO.getDef22(),count,"def23");
				cp.setBodyValueAt(PayableBillItemVO.getDef24(),count,"def24");
				cp.setBodyValueAt(PayableBillItemVO.getDef26(),count,"def26");
				cp.setBodyValueAt(PayableBillItemVO.getDef27(),count,"def27");
				cp.setBodyValueAt(PayableBillItemVO.getDef28(),count,"def28");
				cp.setBodyValueAt(PayableBillItemVO.getDef31(),count,"def31");
				cp.setBodyValueAt(PayableBillItemVO.getDef32(),count,"def32");
				cp.setBodyValueAt(PayableBillItemVO.getDef33(),count,"def33");
				cp.setBodyValueAt(PayableBillItemVO.getDef34(),count,"def34");
				cp.setBodyValueAt(PayableBillItemVO.getDef35(),count,"def35");
				cp.setBodyValueAt(PayableBillItemVO.getDef36(),count,"def36");
				cp.setBodyValueAt(PayableBillItemVO.getDef37(),count,"def37");
				cp.setBodyValueAt(PayableBillItemVO.getDef38(),count,"def38");
				cp.setBodyValueAt(PayableBillItemVO.getDef39(),count,"def39");
				cp.setBodyValueAt(PayableBillItemVO.getDef40(),count,"def40");
				cp.setBodyValueAt(PayableBillItemVO.getDef41(),count,"def41");
				cp.setBodyValueAt(PayableBillItemVO.getDef42(),count,"def42");
				cp.setBodyValueAt(PayableBillItemVO.getDef43(),count,"def43");
				cp.setBodyValueAt(PayableBillItemVO.getDef44(),count,"def44");
				cp.setBodyValueAt(PayableBillItemVO.getDef45(),count,"def45");
				cp.setBodyValueAt(PayableBillItemVO.getDef46(),count,"def46");
				cp.setBodyValueAt(PayableBillItemVO.getDef47(),count,"def47");
				cp.setBodyValueAt(PayableBillItemVO.getDef48(),count,"def48");
				cp.setBodyValueAt(PayableBillItemVO.getDef49(),count,"def49");
				cp.setBodyValueAt(PayableBillItemVO.getDef50(),count,"def50");
				cp.setBodyValueAt(PayableBillItemVO.getDef51(),count,"def51");
				cp.setBodyValueAt(PayableBillItemVO.getDef52(),count,"def52");
				cp.setBodyValueAt(PayableBillItemVO.getDef53(),count,"def53");
				cp.setBodyValueAt(PayableBillItemVO.getDef54(),count,"def54");
				cp.setBodyValueAt(PayableBillItemVO.getDef55(),count,"def55");
				cp.setBodyValueAt(PayableBillItemVO.getDef56(),count,"def56");
				cp.setBodyValueAt(PayableBillItemVO.getDef57(),count,"def57");
				cp.setBodyValueAt(PayableBillItemVO.getDef58(),count,"def58");
				cp.setBodyValueAt(PayableBillItemVO.getDef59(),count,"def59");
				cp.setBodyValueAt(PayableBillItemVO.getDef60(),count,"def60");
			}else if("预付核销单（非项目）".equals(type)){
				//发票号
				String vbillcode = sheet.getRow(i).getCell(4).getStringCellValue();
				PayableBillItemVO PayableBillItemVO = queryBillItem(billno,vbillcode);
				String pk_org = PayableBillItemVO.getPk_org();
				//摘要
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(0).getStringCellValue(),"999"),count, "def25");
				//费用归属
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(1).getStringCellValue(),"05"),count, "def30");
				//预算编号
				cp.setBodyValueAt(sheet.getRow(i).getCell(2).getStringCellValue(), count, "def1");
				//预算名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_inoutbusiclass", "bd_inoutbusiclass", "name", sheet.getRow(i).getCell(3).getStringCellValue(),null,2), count,"pk_subjcode");
				//发票号
				cp.setBodyValueAt(vbillcode, count, "def12");
				String pk_material = sqlexecuteQuery("pk_material", "bd_material", "name", sheet.getRow(i).getCell(5).getStringCellValue(), null, 2);
				//物料
				cp.setBodyValueAt(pk_material,count, "material");
				//原始物料
				cp.setBodyValueAt(pk_material,count, "material_src");
				//税码
				cp.setBodyValueAt(sqlexecuteQuery("pk_taxcode", "bd_taxcode", "description", sheet.getRow(i).getCell(6).getStringCellValue(), null,2),count, "taxcodeid");	
				//税率
				cp.setBodyValueAt(sheet.getRow(i).getCell(7).getStringCellValue(),count, "taxrate");
 				Object price = null;
				if(dateUnit(sheet,i,8) != null) {
					price = sheet.getRow(i).getCell(8).getCellType() == 1 ? sheet.getRow(i).getCell(8).getStringCellValue() : sheet.getRow(i).getCell(8).getNumericCellValue();
				}
				//单价
				cp.setBodyValueAt(price,count, "price");
				//本币单价
				cp.setBodyValueAt(price,count, "local_price");
				Object caltaxmny = sheet.getRow(i).getCell(9).getCellType() == 1 ? sheet.getRow(i).getCell(9).getStringCellValue() : sheet.getRow(i).getCell(9).getNumericCellValue();
				//计税金额
				cp.setBodyValueAt(caltaxmny,count, "caltaxmny");
				//贷方原币无税金额
				cp.setBodyValueAt(caltaxmny,count, "notax_cr");
				//组织本币无税金额
				cp.setBodyValueAt(caltaxmny,count, "local_notax_cr");
				//税额
				cp.setBodyValueAt(sheet.getRow(i).getCell(10).getCellType() == 1 ? sheet.getRow(i).getCell(10).getStringCellValue() : sheet.getRow(i).getCell(10).getNumericCellValue(),count, "local_tax_cr");
				//原币余额
				Object money_bal = sheet.getRow(i).getCell(11).getCellType() == 1 ? sheet.getRow(i).getCell(11).getStringCellValue() : sheet.getRow(i).getCell(11).getNumericCellValue();
				cp.setBodyValueAt(money_bal,count, "money_bal");
				//组织本币余额
				cp.setBodyValueAt(money_bal,count, "local_money_bal");
				//贷方原币金额
				cp.setBodyValueAt(money_bal,count, "money_cr");
				//组织本币金额
				cp.setBodyValueAt(money_bal,count, "local_money_cr");
				//预占用原币余额
				cp.setBodyValueAt(money_bal,count, "occupationmny");
				//扣税类别
				cp.setBodyValueAt("应税内含".equals(sheet.getRow(i).getCell(12).getStringCellValue()) ? 0 : 1,count, "taxtype");
				//成本归属部门
				cp.setBodyValueAt(sqlexecuteQuery("pk_dept", "org_dept", "name", sheet.getRow(i).getCell(13).getStringCellValue(), pk_org,2),count, "def23");
				//往来对象
				Object objtype = dateUnit(sheet,i,14);
				cp.setBodyValueAt("供应商".equals(objtype) ? 1 : "部门".equals(objtype) ? 2 : 3,count, "objtype");
				//备注
				cp.setBodyValueAt(dateUnit(sheet,i,15),count, "def2");
				//对方单位名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_supplier", "bd_supplier", "name", sheet.getRow(i).getCell(16).getStringCellValue(), null, 2),count,"supplier");
				//部门
				cp.setBodyValueAt(sqlexecuteQuery("pk_dept", "org_dept", "name", sheet.getRow(i).getCell(17).getStringCellValue(), pk_org, 2),count, "pk_deptid");
				//部 门
				cp.setBodyValueAt(sqlexecuteQuery("pk_vid", "org_dept_v", "name", sheet.getRow(i).getCell(17).getStringCellValue(), pk_org, 2),count, "pk_deptid_v");
				//含税单价
				cp.setBodyValueAt(PayableBillItemVO.getTaxprice(),count, "taxprice");
				//本币含税单价
				cp.setBodyValueAt(PayableBillItemVO.getLocal_taxprice(),count, "local_taxprice");
				//数量余额
				cp.setBodyValueAt(PayableBillItemVO.getQuantity_bal(),count, "quantity_bal");
				//贷方数量
				cp.setBodyValueAt(PayableBillItemVO.getQuantity_cr(),count, "quantity_cr");
				//结算方式
				cp.setBodyValueAt(PayableBillItemVO.getPk_balatype(),count, "pk_balatype");
				//资产合同号
				cp.setBodyValueAt(PayableBillItemVO.getAssetpactno(),count, "assetpactno");
				//  资金计划项目
				cp.setBodyValueAt(PayableBillItemVO.getBankrollprojet(),count, "bankrollprojet");
				//  单据大类
				cp.setBodyValueAt(PayableBillItemVO.getBillclass(),count, "billclass");
				//  单据日期
				cp.setBodyValueAt(PayableBillItemVO.getBilldate(),count, "billdate");
				//  单据号
				cp.setBodyValueAt(PayableBillItemVO.getBillno(),count, "billno");
				//  起算日期
				cp.setBodyValueAt(PayableBillItemVO.getBusidate(),count, "busidate");
				//  购销类型
				cp.setBodyValueAt(PayableBillItemVO.getBuysellflag(),count, "buysellflag");
				//  现金流量项目
				cp.setBodyValueAt(PayableBillItemVO.getCashitem(),count, "cashitem");
				//  CBS
				cp.setBodyValueAt(PayableBillItemVO.getCbs(),count, "cbs");
				//  责任核算要素
				cp.setBodyValueAt(PayableBillItemVO.getCheckelement(),count, "checkelement");
				//  票据类型
				cp.setBodyValueAt(PayableBillItemVO.getChecktype(),count, "checktype");
				//  摘要c
				cp.setBodyValueAt(PayableBillItemVO.getComment(),count, "comment");
				//  内部交易结算号
				cp.setBodyValueAt(PayableBillItemVO.getConfernum(),count, "confernum");
				//  合同号
				cp.setBodyValueAt(PayableBillItemVO.getContractno(),count, "contractno");
				//  单据协同状态
				cp.setBodyValueAt(PayableBillItemVO.getCoordflag(),count, "coordflag");
				//  成本中心
				cp.setBodyValueAt(PayableBillItemVO.getCostcenter(),count, "costcenter");
				//  方向
				cp.setBodyValueAt(PayableBillItemVO.getDirection(),count, "direction");
				//  设备编码
				cp.setBodyValueAt(PayableBillItemVO.getEquipmentcode(),count, "equipmentcode");
				//  固定资产卡片号
				cp.setBodyValueAt(PayableBillItemVO.getFacard(),count, "facard");
				//  散户
				cp.setBodyValueAt(PayableBillItemVO.getFreecust(),count, "freecust");
				//  全局本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGlobalbalance(),count, "globalbalance");
				//  全局本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalcrebit(),count, "globalcrebit");
				//  全局本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalnotax_cre(),count, "globalnotax_cre");
				//  全局本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGlobalrate(),count, "globalrate");
				//  集团本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGroupbalance(),count, "groupbalance");
				//  集团本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupcrebit(),count, "groupcrebit");
				//  集团本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupnotax_cre(),count, "groupnotax_cre");
				//  集团本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGrouprate(),count, "grouprate");
				//  调拨订单号
				cp.setBodyValueAt(PayableBillItemVO.getInnerorderno(),count, "innerorderno");
				//  发票号
				cp.setBodyValueAt(PayableBillItemVO.getInvoiceno(),count, "invoiceno");
				//  不可抵扣税额
				cp.setBodyValueAt(PayableBillItemVO.getNosubtax(),count, "nosubtax");
				//  不可抵扣税率
				cp.setBodyValueAt(PayableBillItemVO.getNosubtaxrate(),count, "nosubtaxrate");
				//  是否逆向征税
				cp.setBodyValueAt(PayableBillItemVO.getOpptaxflag(),count, "opptaxflag");
				//  订单供应商
				cp.setBodyValueAt(PayableBillItemVO.getOrdercubasdoc(),count, "ordercubasdoc");
				//  出库单号
				cp.setBodyValueAt(PayableBillItemVO.getOutstoreno(),count, "outstoreno");
				//  挂起标志
				cp.setBodyValueAt(PayableBillItemVO.getPausetransact(),count, "pausetransact");
				//  付款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getPayaccount(),count, "payaccount");
				//  单据类型编码
				cp.setBodyValueAt(PayableBillItemVO.getPk_billtype(),count, "pk_billtype");
				//  币种
				cp.setBodyValueAt(PayableBillItemVO.getPk_currtype(),count, "pk_currtype");
				//  废弃财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg(),count, "pk_fiorg");
				//  废弃财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg_v(),count, "pk_fiorg_v");
				//  所属集团
				cp.setBodyValueAt(PayableBillItemVO.getPk_group(),count, "pk_group");
				//  应付财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_org(),count, "pk_org");
				//  应付财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_org_v(),count, "pk_org_v");
				//  供应商应付单标识
				cp.setBodyValueAt(PayableBillItemVO.getPk_payablebill(),count, "pk_payablebill");
				//  付款协议
				cp.setBodyValueAt(PayableBillItemVO.getPk_payterm(),count, "pk_payterm");
				//  利润中心
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg(),count, "pk_pcorgz");
				//  利润中心版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg_v(),count, "pk_pcorg_v");
				//  业务员
				cp.setBodyValueAt(PayableBillItemVO.getPk_psndoc(),count, "pk_psndoc");
				//  事项审批单
				cp.setBodyValueAt(PayableBillItemVO.getPk_ssitem(),count, "pk_ssitem");
				//  应付类型code
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetype(),count, "pk_tradetype");
				//  应付类型
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetypeid(),count, "pk_tradetypeid");
				//  报价单位含税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostprice(),count, "postprice");
				//  报价单位无税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostpricenotax(),count, "postpricenotax");
				//  报价单位数量
				cp.setBodyValueAt(PayableBillItemVO.getPostquantity(),count, "postquantity");
				//  报价计量单位
				cp.setBodyValueAt(PayableBillItemVO.getPostunit(),count, "postunit");
				//  产品线
				cp.setBodyValueAt(PayableBillItemVO.getProductline(),count, "productline");
				//  项目
				cp.setBodyValueAt(PayableBillItemVO.getProject(),count, "project");
				//  项目任务
				cp.setBodyValueAt(PayableBillItemVO.getProject_task(),count, "project_task");
				//  业务部门
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid(),count, "pu_deptid");
				//  业务部门版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid_v(),count, "pu_deptid_v");
				//  业务组织
				cp.setBodyValueAt(PayableBillItemVO.getPu_org(),count, "pu_org");
				//  业务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_org_v(),count, "pu_org_v");
				//  业务人员
				cp.setBodyValueAt(PayableBillItemVO.getPu_psndoc(),count, "pu_psndoc");
				//  订单号
				cp.setBodyValueAt(PayableBillItemVO.getPurchaseorder(),count, "purchaseorder");
				//  组织本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getRate(),count, "rate");
				//  收款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getRecaccount(),count, "recaccount");
				//  单据分录号
				cp.setBodyValueAt(i-1,count, "rowno");
				//  行类型
				cp.setBodyValueAt(PayableBillItemVO.getRowtype(),count, "rowtype");
				//  摘要
				cp.setBodyValueAt(PayableBillItemVO.getScomment(),count, "scomment");
				//  发货国
				cp.setBodyValueAt(PayableBillItemVO.getSendcountryid(),count, "sendcountryid");
				//  结算财务组织
				cp.setBodyValueAt(PayableBillItemVO.getSett_org(),count, "sett_org");
				//  结算财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getSett_org_v(),count, "sett_org_v");
				//  付款币种
				cp.setBodyValueAt(PayableBillItemVO.getSettlecurr(),count, "settlecurr");
				//  付款金额
				cp.setBodyValueAt(PayableBillItemVO.getSettlemoney(),count, "settlemoney");
				//  源头单据主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billid(),count, "src_billid");
				//  源头单据类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billtype(),count, "src_billtype");
				//  源头单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_itemid(),count, "src_itemid");
				//  源头交易类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_tradetype(),count, "src_tradetype");
				//  科目
				cp.setBodyValueAt(PayableBillItemVO.getSubjcode(),count, "subjcode");
				//  税号
				cp.setBodyValueAt(PayableBillItemVO.getTaxnum(),count, "taxnum");
				//  上层单据主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_billid(),count, "top_billid");
				//  上层单据类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_billtype(),count, "top_billtype");
				//  加交换时间
				cp.setBodyValueAt(PayableBillItemVO.getTop_changets(),count, "top_changets");
				//  上层单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_itemid(),count, "top_itemid");
				//  上层交易类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_tradetype(),count, "top_tradetype");
				//  VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVatcode(),count, "vatcode");
				//  供应商VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVendorvatcode(),count, "vendorvatcode");
				//自定义1-60
				cp.setBodyValueAt(PayableBillItemVO.getDef3(),count,"def3");
				cp.setBodyValueAt(PayableBillItemVO.getDef4(),count,"def4");
				cp.setBodyValueAt(PayableBillItemVO.getDef5(),count,"def5");
				cp.setBodyValueAt(PayableBillItemVO.getDef6(),count,"def6");
				cp.setBodyValueAt(PayableBillItemVO.getDef7(),count,"def7");
				cp.setBodyValueAt(PayableBillItemVO.getDef8(),count,"def8");
				cp.setBodyValueAt(PayableBillItemVO.getDef9(),count,"def9");
				cp.setBodyValueAt(PayableBillItemVO.getDef10(),count,"def10");
				cp.setBodyValueAt(PayableBillItemVO.getDef11(),count,"def11");
				cp.setBodyValueAt(PayableBillItemVO.getDef13(),count,"def13");
				cp.setBodyValueAt(PayableBillItemVO.getDef14(),count,"def14");
				cp.setBodyValueAt(PayableBillItemVO.getDef15(),count,"def15");
				cp.setBodyValueAt(PayableBillItemVO.getDef16(),count,"def16");
				cp.setBodyValueAt(PayableBillItemVO.getDef17(),count,"def17");
				cp.setBodyValueAt(PayableBillItemVO.getDef18(),count,"def18");
				cp.setBodyValueAt(PayableBillItemVO.getDef19(),count,"def19");
				cp.setBodyValueAt(PayableBillItemVO.getDef20(),count,"def20");
				cp.setBodyValueAt(PayableBillItemVO.getDef21(),count,"def21");
				cp.setBodyValueAt(PayableBillItemVO.getDef22(),count,"def22");
				cp.setBodyValueAt(PayableBillItemVO.getDef24(),count,"def24");
				cp.setBodyValueAt(PayableBillItemVO.getDef26(),count,"def26");
				cp.setBodyValueAt(PayableBillItemVO.getDef27(),count,"def27");
				cp.setBodyValueAt(PayableBillItemVO.getDef28(),count,"def28");
				cp.setBodyValueAt(PayableBillItemVO.getDef29(), count,"def29");
				cp.setBodyValueAt(PayableBillItemVO.getDef31(),count,"def31");
				cp.setBodyValueAt(PayableBillItemVO.getDef32(),count,"def32");
				cp.setBodyValueAt(PayableBillItemVO.getDef33(),count,"def33");
				cp.setBodyValueAt(PayableBillItemVO.getDef34(),count,"def34");
				cp.setBodyValueAt(PayableBillItemVO.getDef35(),count,"def35");
				cp.setBodyValueAt(PayableBillItemVO.getDef36(),count,"def36");
				cp.setBodyValueAt(PayableBillItemVO.getDef37(),count,"def37");
				cp.setBodyValueAt(PayableBillItemVO.getDef38(),count,"def38");
				cp.setBodyValueAt(PayableBillItemVO.getDef39(),count,"def39");
				cp.setBodyValueAt(PayableBillItemVO.getDef40(),count,"def40");
				cp.setBodyValueAt(PayableBillItemVO.getDef41(),count,"def41");
				cp.setBodyValueAt(PayableBillItemVO.getDef42(),count,"def42");
				cp.setBodyValueAt(PayableBillItemVO.getDef43(),count,"def43");
				cp.setBodyValueAt(PayableBillItemVO.getDef44(),count,"def44");
				cp.setBodyValueAt(PayableBillItemVO.getDef45(),count,"def45");
				cp.setBodyValueAt(PayableBillItemVO.getDef46(),count,"def46");
				cp.setBodyValueAt(PayableBillItemVO.getDef47(),count,"def47");
				cp.setBodyValueAt(PayableBillItemVO.getDef48(),count,"def48");
				cp.setBodyValueAt(PayableBillItemVO.getDef49(),count,"def49");
				cp.setBodyValueAt(PayableBillItemVO.getDef50(),count,"def50");
				cp.setBodyValueAt(PayableBillItemVO.getDef51(),count,"def51");
				cp.setBodyValueAt(PayableBillItemVO.getDef52(),count,"def52");
				cp.setBodyValueAt(PayableBillItemVO.getDef53(),count,"def53");
				cp.setBodyValueAt(PayableBillItemVO.getDef54(),count,"def54");
				cp.setBodyValueAt(PayableBillItemVO.getDef55(),count,"def55");
				cp.setBodyValueAt(PayableBillItemVO.getDef56(),count,"def56");
				cp.setBodyValueAt(PayableBillItemVO.getDef57(),count,"def57");
				cp.setBodyValueAt(PayableBillItemVO.getDef58(),count,"def58");
				cp.setBodyValueAt(PayableBillItemVO.getDef59(),count,"def59");
				cp.setBodyValueAt(PayableBillItemVO.getDef60(),count,"def60");
			}else {
				//发票号
				String vbillcode = sheet.getRow(i).getCell(6).getStringCellValue();
				PayableBillItemVO PayableBillItemVO = queryBillItem(billno,vbillcode);
				String pk_org = PayableBillItemVO.getPk_org();
				//摘要
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(0).getStringCellValue(),"999"),count, "def25");
				//费用归属
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(1).getStringCellValue(),"05"),count, "def30");
				//项目编号
				cp.setBodyValueAt(sheet.getRow(i).getCell(2).getStringCellValue(), count, "def18");
				//项目名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_project", "bd_project", "project_name", sheet.getRow(i).getCell(3).getStringCellValue(),null,2), count, "project");
				//专业
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(4).getStringCellValue(), "HR016"), count, "def6");
				//费用事项
				cp.setBodyValueAt(sqlexecuteQueryDoc(sheet.getRow(i).getCell(5).getStringCellValue(), "88"), count, "def7");
				//发票号
				cp.setBodyValueAt(vbillcode, count, "def12");
				String pk_material = sqlexecuteQuery("pk_material", "bd_material", "name", sheet.getRow(i).getCell(7).getStringCellValue(), null, 2);
				//物料
				cp.setBodyValueAt(pk_material,count, "material");
				//原始物料
				cp.setBodyValueAt(pk_material,count, "material_src");
				//税码
				cp.setBodyValueAt(sqlexecuteQuery("pk_taxcode", "bd_taxcode", "description", sheet.getRow(i).getCell(8).getStringCellValue(), null,2),count, "taxcodeid");	
				//税率
				cp.setBodyValueAt(sheet.getRow(i).getCell(9).getStringCellValue(),count, "taxrate");
				Object price = null;
				if(dateUnit(sheet,i,10) != null) {
					price = sheet.getRow(i).getCell(10).getCellType() == 1 ? sheet.getRow(i).getCell(10).getStringCellValue() : sheet.getRow(i).getCell(10).getNumericCellValue();
				}
				//单价
				cp.setBodyValueAt(price,count, "price");
				//本币单价
				cp.setBodyValueAt(price,count, "local_price");
				Object caltaxmny = sheet.getRow(i).getCell(11).getCellType() == 1 ? sheet.getRow(i).getCell(11).getStringCellValue() : sheet.getRow(i).getCell(11).getNumericCellValue();
				//计税金额
				cp.setBodyValueAt(caltaxmny,count, "caltaxmny");
				//贷方原币无税金额
				cp.setBodyValueAt(caltaxmny,count, "notax_cr");
				//组织本币无税金额
				cp.setBodyValueAt(caltaxmny,count, "local_notax_cr");
				//税额
				cp.setBodyValueAt(sheet.getRow(i).getCell(12).getCellType() == 1 ? sheet.getRow(i).getCell(12).getStringCellValue() : sheet.getRow(i).getCell(12).getNumericCellValue() ,count, "local_tax_cr");
				Object money_bal = sheet.getRow(i).getCell(13).getCellType() == 1 ? sheet.getRow(i).getCell(13).getStringCellValue() : sheet.getRow(i).getCell(13).getNumericCellValue();
				//原币余额
				cp.setBodyValueAt(money_bal,count, "money_bal");
				//组织本币余额
				cp.setBodyValueAt(money_bal,count, "local_money_bal");
				//贷方原币金额
				cp.setBodyValueAt(money_bal,count, "money_cr");
				//组织本币金额
				cp.setBodyValueAt(money_bal,count, "local_money_cr");
				//预占用原币余额
				cp.setBodyValueAt(money_bal,count, "occupationmny");
				//成本归属部门
				cp.setBodyValueAt(sqlexecuteQuery("pk_dept", "org_dept", "name", sheet.getRow(i).getCell(14).getStringCellValue(), pk_org,2),count, "def22");
				//扣税类别
				cp.setBodyValueAt("应税内含".equals(sheet.getRow(i).getCell(15).getStringCellValue()) ? 0 : 1,count, "taxtype");
				//往来对象
				Object objtype = dateUnit(sheet,i,16);
				cp.setBodyValueAt("供应商".equals(objtype) ? 1 : "部门".equals(objtype) ? 2 : 3,count, "objtype");
				//对方单位名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_supplier", "bd_supplier", "name", sheet.getRow(i).getCell(17).getStringCellValue(), null, 2),count,"supplier");
				//备注
				cp.setBodyValueAt(dateUnit(sheet, i, 18), count, "def2");
				//预算名称
				cp.setBodyValueAt(sqlexecuteQuery("pk_inoutbusiclass", "bd_inoutbusiclass", "name", sheet.getRow(i).getCell(19).getStringCellValue(), null,2),count, "pk_subjcode");
				//含税单价
				cp.setBodyValueAt(PayableBillItemVO.getTaxprice(),count, "taxprice");
				//本币含税单价
				cp.setBodyValueAt(PayableBillItemVO.getLocal_taxprice(),count, "local_taxprice");
				//数量余额
				cp.setBodyValueAt(PayableBillItemVO.getQuantity_bal(),count, "quantity_bal");
				//贷方数量
				cp.setBodyValueAt(PayableBillItemVO.getQuantity_cr(),count, "quantity_cr");				
				//结算方式
				cp.setBodyValueAt(PayableBillItemVO.getPk_balatype(),count, "pk_balatype");
				//资产合同号
				cp.setBodyValueAt(PayableBillItemVO.getAssetpactno(),count, "assetpactno");
				//  资金计划项目
				cp.setBodyValueAt(PayableBillItemVO.getBankrollprojet(),count, "bankrollprojet");
				//  单据大类
				cp.setBodyValueAt(PayableBillItemVO.getBillclass(),count, "billclass");
				//  单据日期
				cp.setBodyValueAt(PayableBillItemVO.getBilldate(),count, "billdate");
				//  单据号
				cp.setBodyValueAt(PayableBillItemVO.getBillno(),count, "billno");
				//  起算日期
				cp.setBodyValueAt(PayableBillItemVO.getBusidate(),count, "busidate");
				//  购销类型
				cp.setBodyValueAt(PayableBillItemVO.getBuysellflag(),count, "buysellflag");
				//  现金流量项目
				cp.setBodyValueAt(PayableBillItemVO.getCashitem(),count, "cashitem");
				//  CBS
				cp.setBodyValueAt(PayableBillItemVO.getCbs(),count, "cbs");
				//  责任核算要素
				cp.setBodyValueAt(PayableBillItemVO.getCheckelement(),count, "checkelement");
				//  票据类型
				cp.setBodyValueAt(PayableBillItemVO.getChecktype(),count, "checktype");
				//  摘要c
				cp.setBodyValueAt(PayableBillItemVO.getComment(),count, "comment");
				//  内部交易结算号
				cp.setBodyValueAt(PayableBillItemVO.getConfernum(),count, "confernum");
				//  合同号
				cp.setBodyValueAt(PayableBillItemVO.getContractno(),count, "contractno");
				//  单据协同状态
				cp.setBodyValueAt(PayableBillItemVO.getCoordflag(),count, "coordflag");
				//  成本中心
				cp.setBodyValueAt(PayableBillItemVO.getCostcenter(),count, "costcenter");
				//  方向
				cp.setBodyValueAt(PayableBillItemVO.getDirection(),count, "direction");
				//  设备编码
				cp.setBodyValueAt(PayableBillItemVO.getEquipmentcode(),count, "equipmentcode");
				//  固定资产卡片号
				cp.setBodyValueAt(PayableBillItemVO.getFacard(),count, "facard");
				//  散户
				cp.setBodyValueAt(PayableBillItemVO.getFreecust(),count, "freecust");
				//  全局本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGlobalbalance(),count, "globalbalance");
				//  全局本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalcrebit(),count, "globalcrebit");
				//  全局本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGlobalnotax_cre(),count, "globalnotax_cre");
				//  全局本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGlobalrate(),count, "globalrate");
				//  集团本币余额
				cp.setBodyValueAt(PayableBillItemVO.getGroupbalance(),count, "groupbalance");
				//  集团本币金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupcrebit(),count, "groupcrebit");
				//  集团本币无税金额(贷方)
				cp.setBodyValueAt(PayableBillItemVO.getGroupnotax_cre(),count, "groupnotax_cre");
				//  集团本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getGrouprate(),count, "grouprate");
				//  调拨订单号
				cp.setBodyValueAt(PayableBillItemVO.getInnerorderno(),count, "innerorderno");
				//  发票号
				cp.setBodyValueAt(PayableBillItemVO.getInvoiceno(),count, "invoiceno");
				//  不可抵扣税额
				cp.setBodyValueAt(PayableBillItemVO.getNosubtax(),count, "nosubtax");
				//  不可抵扣税率
				cp.setBodyValueAt(PayableBillItemVO.getNosubtaxrate(),count, "nosubtaxrate");
				//  是否逆向征税
				cp.setBodyValueAt(PayableBillItemVO.getOpptaxflag(),count, "opptaxflag");
				//  订单供应商
				cp.setBodyValueAt(PayableBillItemVO.getOrdercubasdoc(),count, "ordercubasdoc");
				//  出库单号
				cp.setBodyValueAt(PayableBillItemVO.getOutstoreno(),count, "outstoreno");
				//  挂起标志
				cp.setBodyValueAt(PayableBillItemVO.getPausetransact(),count, "pausetransact");
				//  付款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getPayaccount(),count, "payaccount");
				//  单据类型编码
				cp.setBodyValueAt(PayableBillItemVO.getPk_billtype(),count, "pk_billtype");
				//  币种
				cp.setBodyValueAt(PayableBillItemVO.getPk_currtype(),count, "pk_currtype");
				//  部门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid(),count, "pk_deptid");
				//  部 门
				cp.setBodyValueAt(PayableBillItemVO.getPk_deptid_v(),count, "pk_deptid_v");
				//  废弃财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg(),count, "pk_fiorg");
				//  废弃财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_fiorg_v(),count, "pk_fiorg_v");
				//  所属集团
				cp.setBodyValueAt(PayableBillItemVO.getPk_group(),count, "pk_group");
				//  应付财务组织
				cp.setBodyValueAt(PayableBillItemVO.getPk_org(),count, "pk_org");
				//  应付财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_org_v(),count, "pk_org_v");
				//  供应商应付单标识
				cp.setBodyValueAt(PayableBillItemVO.getPk_payablebill(),count, "pk_payablebill");
				//  付款协议
				cp.setBodyValueAt(PayableBillItemVO.getPk_payterm(),count, "pk_payterm");
				//  利润中心
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg(),count, "pk_pcorgz");
				//  利润中心版本
				cp.setBodyValueAt(PayableBillItemVO.getPk_pcorg_v(),count, "pk_pcorg_v");
				//  业务员
				cp.setBodyValueAt(PayableBillItemVO.getPk_psndoc(),count, "pk_psndoc");
				//  事项审批单
				cp.setBodyValueAt(PayableBillItemVO.getPk_ssitem(),count, "pk_ssitem");
				//  应付类型code
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetype(),count, "pk_tradetype");
				//  应付类型
				cp.setBodyValueAt(PayableBillItemVO.getPk_tradetypeid(),count, "pk_tradetypeid");
				//  报价单位含税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostprice(),count, "postprice");
				//  报价单位无税单价
				cp.setBodyValueAt(PayableBillItemVO.getPostpricenotax(),count, "postpricenotax");
				//  报价单位数量
				cp.setBodyValueAt(PayableBillItemVO.getPostquantity(),count, "postquantity");
				//  报价计量单位
				cp.setBodyValueAt(PayableBillItemVO.getPostunit(),count, "postunit");
				//  产品线
				cp.setBodyValueAt(PayableBillItemVO.getProductline(),count, "productline");
				//  项目任务
				cp.setBodyValueAt(PayableBillItemVO.getProject_task(),count, "project_task");
				//  业务部门
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid(),count, "pu_deptid");
				//  业务部门版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_deptid_v(),count, "pu_deptid_v");
				//  业务组织
				cp.setBodyValueAt(PayableBillItemVO.getPu_org(),count, "pu_org");
				//  业务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getPu_org_v(),count, "pu_org_v");
				//  业务人员
				cp.setBodyValueAt(PayableBillItemVO.getPu_psndoc(),count, "pu_psndoc");
				//  订单号
				cp.setBodyValueAt(PayableBillItemVO.getPurchaseorder(),count, "purchaseorder");
				//  组织本币汇率
				cp.setBodyValueAt(PayableBillItemVO.getRate(),count, "rate");
				//  收款银行账户
				cp.setBodyValueAt(PayableBillItemVO.getRecaccount(),count, "recaccount");
				//  单据分录号
				cp.setBodyValueAt(i-1,count, "rowno");
				//  行类型
				cp.setBodyValueAt(PayableBillItemVO.getRowtype(),count, "rowtype");
				//  摘要
				cp.setBodyValueAt(PayableBillItemVO.getScomment(),count, "scomment");
				//  发货国
				cp.setBodyValueAt(PayableBillItemVO.getSendcountryid(),count, "sendcountryid");
				//  结算财务组织
				cp.setBodyValueAt(PayableBillItemVO.getSett_org(),count, "sett_org");
				//  结算财务组织版本
				cp.setBodyValueAt(PayableBillItemVO.getSett_org_v(),count, "sett_org_v");
				//  付款币种
				cp.setBodyValueAt(PayableBillItemVO.getSettlecurr(),count, "settlecurr");
				//  付款金额
				cp.setBodyValueAt(PayableBillItemVO.getSettlemoney(),count, "settlemoney");
				//  源头单据主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billid(),count, "src_billid");
				//  源头单据类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_billtype(),count, "src_billtype");
				//  源头单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getSrc_itemid(),count, "src_itemid");
				//  源头交易类型
				cp.setBodyValueAt(PayableBillItemVO.getSrc_tradetype(),count, "src_tradetype");
				//  科目
				cp.setBodyValueAt(PayableBillItemVO.getSubjcode(),count, "subjcode");
				//  税号
				cp.setBodyValueAt(PayableBillItemVO.getTaxnum(),count, "taxnum");
				//  上层单据主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_billid(),count, "top_billid");
				//  上层单据类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_billtype(),count, "top_billtype");
				//  加交换时间
				cp.setBodyValueAt(PayableBillItemVO.getTop_changets(),count, "top_changets");
				//  上层单据行主键
				cp.setBodyValueAt(PayableBillItemVO.getTop_itemid(),count, "top_itemid");
				//  上层交易类型
				cp.setBodyValueAt(PayableBillItemVO.getTop_tradetype(),count, "top_tradetype");
				//  VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVatcode(),count, "vatcode");
				//  供应商VAT注册码
				cp.setBodyValueAt(PayableBillItemVO.getVendorvatcode(),count, "vendorvatcode");
				//自定义1-60
				cp.setBodyValueAt(PayableBillItemVO.getDef1(),count,"def1");
				cp.setBodyValueAt(PayableBillItemVO.getDef3(),count,"def3");
				cp.setBodyValueAt(PayableBillItemVO.getDef4(),count,"def4");
				cp.setBodyValueAt(PayableBillItemVO.getDef5(), count,"def5");
				cp.setBodyValueAt(PayableBillItemVO.getDef8(),count,"def8");
				cp.setBodyValueAt(PayableBillItemVO.getDef9(),count,"def9");
				cp.setBodyValueAt(PayableBillItemVO.getDef10(),count,"def10");
				cp.setBodyValueAt(PayableBillItemVO.getDef11(),count,"def11");
				cp.setBodyValueAt(PayableBillItemVO.getDef13(),count,"def13");
				cp.setBodyValueAt(PayableBillItemVO.getDef14(),count,"def14");
				cp.setBodyValueAt(PayableBillItemVO.getDef15(),count,"def15");
				cp.setBodyValueAt(PayableBillItemVO.getDef16(),count,"def16");
				cp.setBodyValueAt(PayableBillItemVO.getDef17(),count,"def17");
				cp.setBodyValueAt(PayableBillItemVO.getDef19(),count,"def19");
				cp.setBodyValueAt(PayableBillItemVO.getDef20(),count,"def20");
				cp.setBodyValueAt(PayableBillItemVO.getDef21(),count,"def21");
				cp.setBodyValueAt(PayableBillItemVO.getDef22(),count,"def23");
				cp.setBodyValueAt(PayableBillItemVO.getDef24(),count,"def24");
				cp.setBodyValueAt(PayableBillItemVO.getDef26(),count,"def26");
				cp.setBodyValueAt(PayableBillItemVO.getDef27(),count,"def27");
				cp.setBodyValueAt(PayableBillItemVO.getDef28(),count,"def28");
				cp.setBodyValueAt(PayableBillItemVO.getDef29(),count,"def29");
				cp.setBodyValueAt(PayableBillItemVO.getDef31(),count,"def31");
				cp.setBodyValueAt(PayableBillItemVO.getDef32(),count,"def32");
				cp.setBodyValueAt(PayableBillItemVO.getDef33(),count,"def33");
				cp.setBodyValueAt(PayableBillItemVO.getDef34(),count,"def34");
				cp.setBodyValueAt(PayableBillItemVO.getDef35(),count,"def35");
				cp.setBodyValueAt(PayableBillItemVO.getDef36(),count,"def36");
				cp.setBodyValueAt(PayableBillItemVO.getDef37(),count,"def37");
				cp.setBodyValueAt(PayableBillItemVO.getDef38(),count,"def38");
				cp.setBodyValueAt(PayableBillItemVO.getDef39(),count,"def39");
				cp.setBodyValueAt(PayableBillItemVO.getDef40(),count,"def40");
				cp.setBodyValueAt(PayableBillItemVO.getDef41(),count,"def41");
				cp.setBodyValueAt(PayableBillItemVO.getDef42(),count,"def42");
				cp.setBodyValueAt(PayableBillItemVO.getDef43(),count,"def43");
				cp.setBodyValueAt(PayableBillItemVO.getDef44(),count,"def44");
				cp.setBodyValueAt(PayableBillItemVO.getDef45(),count,"def45");
				cp.setBodyValueAt(PayableBillItemVO.getDef46(),count,"def46");
				cp.setBodyValueAt(PayableBillItemVO.getDef47(),count,"def47");
				cp.setBodyValueAt(PayableBillItemVO.getDef48(),count,"def48");
				cp.setBodyValueAt(PayableBillItemVO.getDef49(),count,"def49");
				cp.setBodyValueAt(PayableBillItemVO.getDef50(),count,"def50");
				cp.setBodyValueAt(PayableBillItemVO.getDef51(),count,"def51");
				cp.setBodyValueAt(PayableBillItemVO.getDef52(),count,"def52");
				cp.setBodyValueAt(PayableBillItemVO.getDef53(),count,"def53");
				cp.setBodyValueAt(PayableBillItemVO.getDef54(),count,"def54");
				cp.setBodyValueAt(PayableBillItemVO.getDef55(),count,"def55");
				cp.setBodyValueAt(PayableBillItemVO.getDef56(),count,"def56");
				cp.setBodyValueAt(PayableBillItemVO.getDef57(),count,"def57");
				cp.setBodyValueAt(PayableBillItemVO.getDef58(),count,"def58");
				cp.setBodyValueAt(PayableBillItemVO.getDef59(),count,"def59");
				cp.setBodyValueAt(PayableBillItemVO.getDef60(),count,"def60");
			}
		}
		//循环删行
		for(int j = 0;j<rowCount;j++){
			cp.getBillModel().delLine(new int[] {0});
		}
		//将pk转换成显示的编码	
		BillModel tableModel = importBodyAction.editorModel.getBillCardPanel().getBodyPanel().getTableModel();
		tableModel.loadLoadRelationItemValue();
		/*
		 * 表体def1是个参照，pk_subjcode写了个编辑公式把code赋值给了def1,我只能说很6,将编码导入def1后调用上面两句代码
		会导致def1值为空，因为导入的code匹配不到对应name,只能再次调用编辑公式赋值
		 */

		//获取导入后的表体行数量循环调用编辑公式
		int rowCounts = cp.getRowCount();
		for (int x = 0; x < rowCounts; x++) {
			importBodyAction.editorModel.getBillCardPanel().getBillModel().execEditFormulasByKey(x, "pk_subjcode");
		}
	}
	
	/*
	 *	判断表头必填项
	 */
	private  void importHendBeforCheck(BillCardPanel cp,String type) throws Exception {
		if("应付单（非项目）".equals(type)) {
			Object 	def3 = cp.getHeadItem("def3").getValueObject();
			if(def3 == null){
				throw new Exception("请先填写表头建议付款日期！");
			}
			Object 	def5 = cp.getHeadItem("def5").getValueObject();
			if(def5 == null){
				throw new Exception("请先填写表头费用承担部门！");
			}
			Object 	def20 = cp.getHeadItem("def20").getValueObject();
			if(def20 == null){
				throw new Exception("请先填写表头预算所在部门！");
			}
			Object supplier = cp.getHeadItem("supplier").getValueObject();
			if(supplier == null){
				throw new Exception("请先填写表头对方单位名称！");
			}
			Object recaccount = cp.getHeadItem("recaccount").getValueObject();
			if(recaccount == null){
				throw new Exception("请先填写表头对方银行账户！");
			}
		}else if("应付单（项目）".equals(type)){
			Object 	def3 = cp.getHeadItem("def3").getValueObject();
			if(def3 == null){
				throw new Exception("请先填写表头建议付款日期！");
			}
			Object 	def5 = cp.getHeadItem("def5").getValueObject();
			if(def5 == null){
				throw new Exception("请先填写表头费用承担部门！");
			}
		}else if("预付核销单（非项目）".equals(type)){
			Object 	def5 = cp.getHeadItem("def5").getValueObject();
			if(def5 == null){
				throw new Exception("请先填写表头费用承担部门！");
			}
			Object 	def20 = cp.getHeadItem("def20").getValueObject();
			if(def20 == null){
				throw new Exception("请先填写表头预算所在部门！");
			}
		}else {
			Object 	def5 = cp.getHeadItem("def5").getValueObject();
			if(def5 == null){
				throw new Exception("请先填写表头费用承担部门！");
			}
		}
	}
	
	
	
	/*
	 * 判断表体必填项
	 */
	private void importBodyBeforCheck(HSSFSheet sheet, String type, int rowNum) throws Exception {
		for (int i = 2; i < rowNum; i++) {
			int[] index = null;
			if("应付单（非项目）".equals(type)) {
				//需要校验的Excle下标
				index = new int[]{0,1,2,3,4,5,6,7,8,10,11,12,20,21};
			}else if("应付单（项目）".equals(type)){
				//需要校验的Excle下标
				index = new int[]{0,1,2,3,4,5,6,7,8,9,10,12,13,15,17,20,21};
			}else if("预付核销单（非项目）".equals(type)){
				//需要校验的Excle下标
				index = new int[]{0,1,2,3,4,5,6,7,9,10,11,12,13,14,16,17,18};
			}else {
				//需要校验的Excle下标
				index = new int[]{0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,19,20};
			}
			for (int j = 0; j < index.length; j++) {
				if(sheet.getRow(i).getCell(index[j])!= null) {
					if(sheet.getRow(i).getCell(index[j]).getCellType() == 3) {
						throw new Exception("带*标题为必填项，请确认后进行导入！请检查Excle！");
					}else {
						Object value = sheet.getRow(i).getCell(index[j]).getCellType() == 1 ? sheet.getRow(i).getCell(index[j]).getStringCellValue() : sheet.getRow(i).getCell(index[j]).getNumericCellValue();
						if(value == null || "".equals(value)) {
							throw new Exception("带*标题为必填项，请确认后进行导入！请检查Excle！");
						}
					}
					
				}else {
					throw new Exception("带*标题为必填项，请确认后进行导入！请检查Excle！");
				}
			}
		}
	}
	
	/*
	 * 不必填数据处理
	 */
	private Object dateUnit(HSSFSheet sheet, int i, int j) {
		if(sheet.getRow(i).getCell(j) == null) {
			return null;
		}else {
			//等于3表示空字符
			if(sheet.getRow(i).getCell(j).getCellType() == 3) {
				return null;
			}else {
				return sheet.getRow(i).getCell(j).getCellType() == 1 ? sheet.getRow(i).getCell(j).getStringCellValue() : sheet.getRow(i).getCell(j).getNumericCellValue();
			}	
		}
	}
	
	
	/*
	 * 数据库查询
	 */
	private String sqlexecuteQuery(String out,String table,String key,String value,String pk_org,int enablestate) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append("select "+out+" from "+table+" where "+key+" = '"+value+"' and nvl(dr,0) = 0");
		if(pk_org != null) {
			sql.append(" and pk_org = '"+pk_org+"'");
		}
		if(enablestate == 2) {
			sql.append(" and enablestate = 2");
		}
		
		Object object;
		object = iuap.executeQuery(sql.toString(), new ColumnProcessor());
		if (object == null) {
			throw new Exception("数据翻译失败，待翻译值:"+value);
		}
		return object.toString();
	}
	/*
	 * 数据库查询自定义档案
	 */
	private String sqlexecuteQueryDoc(String name,String code) throws Exception {
		String sql = "select  pk_defdoc from bd_defdoc where name = '"+name+"' and pk_defdoclist = (select pk_defdoclist from bd_defdoclist where code ='"+code+"') ";
		
		Object object;
			object = iuap.executeQuery(sql, new ColumnProcessor());
			if (object == null) {
				throw new Exception("数据翻译失败，待翻译值:"+name);
			}
			return object.toString();
	}
	
	/*
	 * 根据采购发票发票号插查询对应行号
	 */
	private  PayableBillItemVO queryBillItem(String billno,String vbillcode) throws Exception {
		String sql = "select * from ap_payableitem where def12 = '"+vbillcode+"' and pk_payablebill = (select pk_payablebill from ap_payablebill where billno = '"+billno+"'and nvl( dr, 0 ) = 0) and nvl( dr, 0 ) = 0";
		PayableBillItemVO payableBillItemVO = (PayableBillItemVO) iuap.executeQuery(sql, new BeanProcessor(PayableBillItemVO.class));
		if(payableBillItemVO == null){
			throw new Exception("请检查发票号是否正确！");
		}
		return payableBillItemVO;

	}
}
