package nc.wy.baseapp.utils;

import java.util.ArrayList;
import java.util.List;

import nc.bs.dao.BaseDAO;
import nc.bs.dao.DAOException;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.vo.baseapp.image.ImageInvoiceHVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;

public class CheckBillUtils {
	
	public static BaseDAO dao = null;
	
	public static void checkBill(String billid, ImageInvoiceHVO imageInvoiceHVO) throws BusinessException {
		if(InsertErminvoice.isBXZB(billid)) {
			InsertErminvoice.insertVO(billid, imageInvoiceHVO);
		}
		//验证是否应付发票 2021-05-20 ll
		else if(InsertErminvoice.ispayablebill(billid)) {
			InsertErminvoice.payablebillInsertVO(billid, imageInvoiceHVO);
		}
	}
	
	/**
	 * 判断影像文件可否上传发票夹
	 * @param ticketCode
	 * @return
	 * @throws BusinessException
	 */
	public static boolean isInvoice(String ticketCode) throws BusinessException{
		String sql = new StringBuilder("select b.code")
				.append(" from bd_defdoclist a")
				.append(" left join bd_defdoc b")
				.append(" on a.pk_defdoclist = b.pk_defdoclist")
				.append(" where a.code = 'WY887'")
				.append(" and b.enablestate = 2").toString();
		List<String> result = new ArrayList<>();
		try {
			result = (List<String>) getDao().executeQuery(sql, new ColumnListProcessor());
		} catch (DAOException e) {
			throw new DAOException("查询发票夹接收范围失败,请联系用友顾问!");
		}
		if(result.contains(ticketCode)) {
			return true;
		}
		return false;
	}
	
	private static BaseDAO getDao() {
		if(null == dao) {
			dao = new BaseDAO();
		}
		return dao;
	}
}
