/*
 *
 * Copyright (c) 2001-2018 泛微软件.
 * 泛微协同商务系统,版权所有.
 *
 */
package weaver.fna.invoice.utils;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import org.apache.commons.lang.StringEscapeUtils;

import com.engine.fna.util.FnaInvoiceUploadUtil;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import weaver.conn.RecordSet;
import weaver.docs.docs.DocExtUtil;
import weaver.file.FileUpload;
import weaver.fna.general.FnaLogSqlUtil;
import weaver.fna.invoice.Constants;
import weaver.fna.invoice.common.FnaAbstractInterface;
import weaver.fna.invoice.common.FnaInvoiceCommon;
import weaver.fna.maintenance.BudgetfeeTypeComInfo;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.resource.ResourceComInfo;
import weaver.systeminfo.SystemEnv;

/**
 * @author zhangwj
 * @Jan 23, 2019
 */
public class MultiInvoiceUtil {

	/**错误的返回编码*/
	private static final String ERROR_RESULT_CODE = "1";
	/**发票不存在*/
	private static final String INVOICE_NOT_EXISTS = "0";
	/**增值税普通*/
	private static final String VAT_ORDINARY_TYPE = "1";
	/**增值税专用*/
	private static final String VAT_SPECIAL_TYPE = "2";
	/**通用机打发票*/
	private static final String GENERALMACHINE_TYPE = "3";
	/**定额发票*/
	private static final String QUOTA_TYPE = "5";
	/**出租发票*/
	private static final String TAXI_TYPE = "7";
	/**动车高铁票*/
	private static final String TRAIN_TYPE = "8";
	/**过路费发票*/
	private static final String TOLLS_TYPE = "9";
	/**客运汽车票*/
	private static final String PASSENGERTICKET_TYPE = "10";
	/**二手车销售统一发票*/
	private static final String USEDCARSALES_TYPE = "11";
	/**机动车销售统一发票*/
	private static final String MOTORVEHICLESALES_TYPE = "12";
	/**航空运输电子客票行程单*/
	private static final String AIRTRANSPORTTICKET_TYPE = "14";
	/**国际小票*/
	private static final String INTERNATIONAL_RECEIPTS = "13";
	/**增值税电子普通发票*/
	private static final String VAT_Electronic_Type = "15";
	/**增值税普通发票（卷票）*/
	private static final String VAT_ORDINARY_Volume_TYPE = "16";
	/**可报销其他发票*/
	private static final String OTHERS_TYPE = "17";
	/**完税证明*/
	private static final String TAX_CERTIFICATE_TYPE = "18";
	/**区块链*/
	private static final String BLOCKCHAIN_TYPE = "19";
	/**增值税电子普通发票(通行费)*/
	private static final String VAT_Electronic_Tolls_Type = "20";
	/**增值税电子专用发票*/
	private static final String VAT_Electronic_SPECIAL_Type = "21";
	/**全电票（电子专票）*/
	private static final String VAT_ELEC_TYPE = "32";
	/**全电票（普通发票）*/
	private static final String VAT_GENE_TYPE = "33";

	/**待定*/
	private static final int AUTHENTICITY_UNDETERMINED = 0;
	/**真*/
	private static final int AUTHENTICITY_TRUE = 1;
	/**伪*/
	private static final int AUTHENTICITY_FALSE = 2;
	/**df*/
	private static DecimalFormat df = new DecimalFormat("##########################0.00");
	/**科目缓存*/
	private static BudgetfeeTypeComInfo btc = new BudgetfeeTypeComInfo();
	private static FnaLogSqlUtil fnaLogSqlUtil = new FnaLogSqlUtil();
	/**
	 * 发票识别
	 * @param apiJson
	 * @param user
	 * @param imageBytes
	 * @return
	 * @throws Exception
	 */
	public static JSONObject handler(JSONObject apiJson, User user,byte[] imageBytes,int imagefileid,String ipAdress) throws Exception {
		String entryTime = Util.date(2);//录入时间
		BaseBean bb = new BaseBean();
		int status = apiJson.getInt("status");
		if (status == Constants.ERROR_CODE) {
			throw new Exception(apiJson.getString("errMsg"));
		}
		JSONObject postjson = JSONObject.fromObject(apiJson.get("returnInfo"));
		bb.writeLog("postjson:", postjson);
		String result = postjson.getString("result");
		if (!ERROR_RESULT_CODE.equals(result)) {
			FnaInvoiceCommon.saveFailLog(user.getUID(), 0, postjson.getString("message"));
			throw new Exception(postjson.getString("message"));
		}
		JSONArray identify_results_array = postjson.getJSONObject("response").getJSONObject("data")
				.getJSONArray("identify_results");
		if (identify_results_array.size() == 0) {
			FnaInvoiceCommon.saveFailLog(user.getUID(), 0, SystemEnv.getHtmlLabelName(509482, user.getLanguage()));//识别结果为空!
			throw new Exception(SystemEnv.getHtmlLabelName(509482, user.getLanguage()));//识别结果为空!
		}
		JSONObject rtnJson = new JSONObject();
		JSONArray invoiceArray = new JSONArray();
		int userid = user.getUID();
		RecordSet rs = new RecordSet();
		int identifyArraySize = identify_results_array.size();
		bb.writeLog("identifyArraySize:" + identifyArraySize);
		int imageID = 0;	
		String suffix = "";
		if(imagefileid>0){
			suffix = FnaInvoiceUploadUtil.getFileSuffix(String.valueOf(imagefileid));
		}
		if(identifyArraySize == 1 || "pdf".equalsIgnoreCase(suffix) || "ofd".equalsIgnoreCase(suffix)){
			if(imagefileid>0){
				imageID = imagefileid;
			}else{
				imageID = FnaInvoiceCommon.saveImage(imageBytes,user);
			}
			
		}

		FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
		StringBuffer existsInvoiceSb = new StringBuffer();
		boolean existsInterface = InvoiceUtil.ifExistsInterface(user);
		for (int i = 0; i < identifyArraySize; i++) {
			JSONObject infoJson = new JSONObject();
			bb.writeLog("解析发票开始:" + i + "################################################");
			JSONObject identify_results = identify_results_array.getJSONObject(i);
			bb.writeLog("identify_results:" + identify_results);
			String type = identify_results.getString("type");
			String orientation = identify_results.getString("orientation");
			if(identifyArraySize > 1 && !"pdf".equalsIgnoreCase(suffix) && !"ofd".equalsIgnoreCase(suffix)){
				String region = identify_results.getString("region");
				String[] regions = region.replace("[", "").replace("]", "").split(",");
				int x = 0;
				int y = 0;
				int w = 0;
				int h = 0;
				if(regions.length == 4){
					x = Util.getIntValue(regions[0]);
					y = Util.getIntValue(regions[1]);
					w = Util.getIntValue(regions[2]);
					h = Util.getIntValue(regions[3]);
					if(x==0){
						x++;
					}
					if(y==0){
						y++;
					}
					String cutImageBase64 = ImageUtil.cutImg(x,y,w-x,h-y,imageBytes,orientation);
					imageID = ImageUtil.saveImage(cutImageBase64,user);
					if(!"".equals(cutImageBase64)){
						infoJson.put("newImage", cutImageBase64);
					}
				}
			}



			JSONObject details = identify_results.getJSONObject("details");
			//通过title和block_chain 区分可报销其他发票和区域链发票
			if("10100".equals(type) || "10101".equals(type) || "10102".equals(type) || "10103".equals(type)){
				String block_chain = getString(details,"block_chain");
				String transit_mark = getString(details,"transit_mark");//通行费标识
				String electronic_mark = getString(details,"electronic_mark");//电子专票标识
				if("1".equals(block_chain)){
					type="19";
				}
				if("1".equals(transit_mark)){
					type="20";
				}
				if("10100".equals(type) && "1".equals(electronic_mark)){
					type="21";
				}
			}


			if(details.containsKey("title")){
				String title = details.getString("title");
				if(!"".equals(title)) {
					if ("10100".equals(type) || "10101".equals(type) || "10102".equals(type) || "10103".equals(type)) {
						if (!title.contains("增值税")) {
							//type = "10900";
						}
					} else if ("10104".equals(type)) {
						if (!title.contains("机动车")) {
							type = "10900";
						}
					}
				}
			}

			 if( "102015".equals(type)||"102021".equals(type)) {
				type = "10900";
				details.put("number", getString(details, "bill_number"));
				details.put("code", getString(details, "bill_code"));
			}

			bb.writeLog(Constants.INVOICETYPE.get(type));
			infoJson.put("invoiceType", type);
			infoJson.put("invoiceTitle", Constants.INVOICETYPE.get(type));

			boolean insertLog=false;
			int invoiceId=0;
			if ("10100".equals(type) || "21".equals(type)) {// 增值税专用发票
				String number = details.getString("number");
				String code = details.getString("code");

				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				
				String invoiceType="";
				if("10100".equals(type)){
					invoiceType = VAT_SPECIAL_TYPE;
				}else if("21".equals(type)){
					invoiceType = VAT_Electronic_SPECIAL_Type;
				}

				if(!"".equals(number)&&!"".equals(code)){
					if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
						String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
								.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
						existsInvoiceSb.append(msg);
						existsInvoiceSb.append("\n");
					}
				}

				double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
				boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
				if(existsInterface && needCheck){
					infoJson.put("invoiceInfo", details);
					infoJson.put("exists", false);
					infoJson.put("imageID", imageID);
					//保存发票
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
				}else{
					infoJson.put("invoiceInfo", details);
					infoJson.put("description", Constants.INVOICETYPE.get(type));
					infoJson.put("exists", true);
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
					infoJson.put("number", number);
					infoJson.put("invoiceId", invoiceId);
				}
			} else if ("10107".equals(type)) {// 新型专票（电票）//32专用33普通
				String number = details.getString("number");
				//String code = details.getString("code");
				String code=number;
				String invoiceType="";
				if("10107".equals(type)){
					invoiceType = VAT_ELEC_TYPE;
				}
				if(!"".equals(number)&&number.length()>16){
					if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
						String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
								.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
						existsInvoiceSb.append(msg);
						existsInvoiceSb.append("\n");
					}
				}
				double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
				boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
				if(existsInterface && needCheck){
					infoJson.put("invoiceInfo", details);
					infoJson.put("exists", false);
					infoJson.put("imageID", imageID);
					//保存发票
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
				}else{
					infoJson.put("invoiceInfo", details);
					infoJson.put("description", Constants.INVOICETYPE.get(type));
					infoJson.put("exists", true);
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
					infoJson.put("number", number);
					infoJson.put("invoiceId", invoiceId);
				}
			}else if ("10108".equals(type)) {// 新型专票（电票）//32专用33普通
				String number = details.getString("number");
				//String code = details.getString("code");
				String code=number;
				String invoiceType=VAT_GENE_TYPE;

				if(!"".equals(number)&&number.length()>16){
					if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
						String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
								.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
						existsInvoiceSb.append(msg);
						existsInvoiceSb.append("\n");
					}
				}
				double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
				boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
				if(existsInterface && needCheck){
					infoJson.put("invoiceInfo", details);
					infoJson.put("exists", false);
					infoJson.put("imageID", imageID);
					//保存发票
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
				}else{
					infoJson.put("invoiceInfo", details);
					infoJson.put("description", Constants.INVOICETYPE.get(type));
					infoJson.put("exists", true);
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
					infoJson.put("number", number);
					infoJson.put("invoiceId", invoiceId);
				}
			} else if ("10101".equals(type) || "10102".equals(type) || "10103".equals(type) || "20".equals(type)) {// 增值税普通发票
				String number = details.getString("number");
				String code = details.getString("code");


				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}


				if(!"".equals(number)&&!"".equals(code)){
					if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
						String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
								.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
						existsInvoiceSb.append(msg);
						existsInvoiceSb.append("\n");
					}
				}
				String invoiceType="";
				if("10101".equals(type)){
					invoiceType = VAT_ORDINARY_TYPE;
				}else if("10102".equals(type)){
					invoiceType = VAT_Electronic_Type;
				}else if("10103".equals(type)){
					invoiceType = VAT_ORDINARY_Volume_TYPE;
				}else if("20".equals(type)){
					invoiceType = VAT_Electronic_Tolls_Type;
				}

				double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
				boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
				if(existsInterface && needCheck){
					infoJson.put("invoiceInfo", details);
					infoJson.put("exists", false);
					infoJson.put("imageID", imageID);
					//保存发票
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
				}else{
					infoJson.put("invoiceInfo", details);
					infoJson.put("description", Constants.INVOICETYPE.get(type));
					infoJson.put("exists", true);
					invoiceId = InvoiceUtil.saveVATInvoice(details,user,invoiceType,imageID,existsInterface,needCheck,ipAdress);
					infoJson.put("number", number);
					infoJson.put("invoiceId", invoiceId);
				}
			} else if ("10104".equals(type)) {// 机动车销售统一发票
				String number = details.getString("number");
				String code = details.getString("code");

				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}


				if(!"".equals(number)&&!"".equals(code)){
					if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
						String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
								.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
						existsInvoiceSb.append(msg);
						existsInvoiceSb.append("\n");
					}
				}

				double totalAmount =Util.getDoubleValue(getString(details, "total"),0.00);
				boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);
				if(existsInterface && needCheck){
					infoJson.put("invoiceInfo", details);
					infoJson.put("exists", false);
					infoJson.put("imageID", imageID);
				}else {
					infoJson.put("invoiceInfo", details);
					infoJson.put("description", Constants.INVOICETYPE.get(type));
					infoJson.put("exists", true);
					bb.writeLog("机动车销售统一发票", details);

					String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

					String seller = getString(details, "seller");
					String buyer = getString(details, "buyer");
					String total = getString(details, "total");
					String machine_code = getString(details, "machine_code");// 机打代码
					String machine_number = getString(details, "machine_number");// 机打号码
					String pretax_amount = getString(details, "pretax_amount");// 税前金额
					String seller_tax_id = getString(details, "seller_tax_id");// 销售方纳税人识别号
					String buyer_id = getString(details, "buyer_id");// 买方单位代码/个人身份证号
					String tax_authorities = getString(details, "tax_authorities");// 主管税务机关
					String tax_authorities_code = getString(details, "tax_authorities_code");// 主管税务机关代码
					String car_code = getString(details, "car_code");// 买方单位代码/个人身份证号
					String car_engine_code = getString(details, "car_engine_code");// 发动机号码
					String car_model = getString(details, "car_model");// 厂牌型号
					String certificate_number = getString(details, "certificate_number");// 合格证号
                    String tax= getString(details, "tax");
					String taxRate = getString(details, "tax_rate").replace("%","");


					invoiceId = Integer.parseInt(MultiInvoiceUtil.getInvoiceData(number, code)[3]);
					if (invoiceId == 0) {
						String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,salesTaxNo,purchaserTaxNo,taxIncludedPrice,priceWithoutTax,tax,taxRate,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, date, code, number, MOTORVEHICLESALES_TYPE, seller, buyer,seller_tax_id,buyer_id,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(pretax_amount, 0.00)),df.format(Util.getDoubleValue(tax, 0.00)),df.format(Util.getDoubleValue(taxRate, 0.00)), userid, "1","2",
								FnaInvoiceCommon.INIT_STATUS, imageID, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime);
						// 获取发票id
						invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
						String insertMotor_Vehicle = "insert into motor_VehicleInvoice(mainid,machine_code,machine_number,pretax_amount,seller_tax_id,buyer_id,tax_authorities,tax_authorities_code,car_code,"
								+ "car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertMotor_Vehicle, invoiceId, machine_code, machine_number, pretax_amount,
								seller_tax_id, buyer_id, tax_authorities, tax_authorities_code, car_code, car_engine_code,
								car_model, certificate_number);
						//插入明细
						InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pretax_amount, 0.00)), df.format(Util.getDoubleValue(taxRate,0.00)),df.format(Util.getDoubleValue(tax,0.00)),1,df.format(Util.getDoubleValue(pretax_amount, 0.00)),df.format(Util.getDoubleValue(pretax_amount, 0.00)),"","");

						insertLog=true;
					}
					infoJson.put("number", number);
					infoJson.put("invoiceId", invoiceId);
					addShowInfo(infoJson, number, code);
				}
			} else if ("10105".equals(type)) {// 二手车销售统一发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("二手车销售统一发票", details);
				String number = Util.null2String(getString(details, "number"));
				String code = getString(details, "code");
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String total = getString(details, "total");
				String seller = getString(details, "seller");
				String buyer = getString(details, "buyer");
				String seller_id = getString(details, "seller_id");// 卖方单位代码/个人身份证号
				String buyer_id = getString(details, "buyer_id");// 买方单位代码/个人身份证号
				String company_name = getString(details, "company_name");// 二手车市场
				String company_tax_id = getString(details, "company_tax_id");// 二手车市场纳税人识别号
				String license_plate = getString(details, "license_plate");// 车牌号
				String registration_number = getString(details, "registration_number");// 登记证号
				String car_code = getString(details, "car_code");// 二手车市场
				String car_model = getString(details, "car_model");// 厂牌型号
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, code, number, USEDCARSALES_TYPE, seller, buyer, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					// 插入二手车销售统一发票明细表
					String insertSecond_car = "insert into second_carInvoice(mainid,seller_id,buyer_id,company_name,company_tax_id"
							+ ",license_plate,registration_number,car_code,car_model) values(?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertSecond_car, invoiceId, seller_id, buyer_id, company_name, company_tax_id,
							license_plate, registration_number, car_code, car_model);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			} else if ("10200".equals(type)) {// 定额发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("定额发票", details);
				String number = Util.null2String(getString(details, "number"));
				String code = getString(details, "code");
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String total = getString(details, "total");
				if ("".equals(total)) {
					total = "0.00";
				}
				String billingDate = "";
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);

				//ocr增加字段
				String kind =getString(details, "kind");
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, billingDate, code, number, QUOTA_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			} else if ("10400".equals(type)) {// 机打发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("机打发票", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String number = Util.null2String(getString(details, "number"));
				String code = getString(details, "code");
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String seller = getString(details, "seller");
				String buyer = getString(details, "buyer");
				String total = getString(details, "total");
				String check_code = getString(details, "check_code");
				if ("".equals(total)) {
					total = "0.00";
				}
				String time = getString(details, "time");// 时间
				String category = getString(details, "category");// 种类，oil//
				String seller_tax_id = getString(details, "seller_tax_id");// 销售方纳税人识别号
				String buyer_tax_id = getString(details, "buyer_tax_id");// 购买方纳税人识别号


				String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
				String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
				String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
				String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");

				//ocr增加字段
				String kind =getString(details, "kind");//发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,taxIncludedPrice,userid_new,checkcode,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,category,salesTaxNo,purchaserTaxNo,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, code, number, GENERALMACHINE_TYPE, seller, buyer, df.format(Util.getDoubleValue(total,0.00)), userid, check_code,
							"1","2", FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,category,seller_tax_id,buyer_tax_id,kind);
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					// 插入机打发票明细表
					String insertMachine = "insert into machineInvoice(mainid,time,category,seller_tax_id,buyer_tax_id) values(?,?,?,?,?)";
					rs.executeUpdate(insertMachine, invoiceId, time, category, seller_tax_id, buyer_tax_id);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			} else if ("10500".equals(type)) {// 出租车发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("出租车发票", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String code = getString(details, "code");
				String number = Util.null2String(getString(details, "number"));
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}

				String fare = getString(details, "fare");//原始金额
				String total = getString(details, "total");
				if (!"".equals(fare)) {
					total = fare;
				}
				if ("".equals(total)) {
					total = "0.00";
				}

				String time_geton = getString(details, "time_geton");// 上车时间
				String time_getoff = getString(details, "time_getoff");// 下车时间
				String mileage = getString(details, "mileage");// 里程
				//ocr增加字段
				String place =  getString(details, "place");// 发票所在地
				String kind =  getString(details, "kind");// 发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, code, number, TAXI_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					// 插入出租车发票明细表
					String insertTaxi = "insert into taxiInvoice(mainid,time_geton,time_getoff,mileage,place) values(?,?,?,?,?)";
					rs.executeUpdate(insertTaxi, invoiceId, time_geton, time_getoff, mileage,place);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			} else if ("10503".equals(type)) {// 火车票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("火车票", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String number = Util.null2String(getString(details, "serial_number"));
				if("".equals(number)){
					number = randomInvoiceNumber();
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String total = getString(details, "total");
				if ("".equals(total)) {
					total = "0.00";
				}
				//铁路旅客运输进项税额=票面金额÷（1+9%）×9%
				String taxRate="9";
				String tax = df.format(Util.getDoubleValue(total,0.00) / (1+0.09) * 0.09);
				String time = getString(details, "time");// 时间
				String name = getString(details, "name");// 乘车人姓名
				//未取得注明旅客身份信息
				if("".equals(name)){
					tax = "0.00";
					taxRate = "0";
				}
				String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
				String station_geton = getString(details, "station_geton");// 上车车站
				String station_getoff = getString(details, "station_getoff");// 下车车站
				String train_number = getString(details, "train_number");// 车次
				String seat = getString(details, "seat");// 座位类型
                //ocr增加字段
				String kind =  getString(details, "kind");// 发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,number)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceNumber,invoiceCode,invoiceType,taxIncludedPrice,pricewithouttax,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind,taxRate,tax) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, number, number, TRAIN_TYPE, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind,taxRate,tax);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
					// 插入火车发票明细表
					String insertTrain = "insert into trainInvoice(mainid,time,name,station_geton,station_getoff,train_number,seat) values(?,?,?,?,?,?,?)";
					rs.executeUpdate(insertTrain, invoiceId, time, name, station_geton, station_getoff, train_number,
							seat);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,number);
			} else if ("10505".equals(type)) {// 客运汽车
				infoJson.put("invoiceInfo", details);
				bb.writeLog("客运汽车", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String code = getString(details, "code");
				String number = Util.null2String(getString(details, "number"));
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String total = getString(details, "total");
				String time = getString(details, "time");// 时间
				String station_geton = getString(details, "station_geton");// 上车车站
				String station_getoff = getString(details, "station_getoff");// 下车车站
				String name = getString(details, "name");// 乘车人姓名
				if ("".equals(total)) {
					total = "0.00";
				}
				//公路、水路等其他旅客运输进项税额=票面金额÷（1+3%）×3%
				String taxRate="3";
				String tax = df.format(Util.getDoubleValue(total,0.00) / (1+0.03) * 0.03);
				//未取得注明旅客身份信息
				if("".equals(name)){
					tax = "0.00";
					taxRate="0";
				}
				String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
				//ocr增加字段
				String kind =  getString(details, "kind");// 发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,pricewithouttax,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind,tax,taxRate) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, code, number, PASSENGERTICKET_TYPE, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind,tax,taxRate);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					// 插入客运汽车发票明细表
					String insertCar = "insert into carInvoice(mainid,time,station_geton,station_getoff,name) values(?,?,?,?,?)";
					rs.executeUpdate(insertCar, invoiceId, time, station_geton, station_getoff, name);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			} else if ("10506".equals(type)) {// 航空运输电子客票行程单
				infoJson.put("invoiceInfo", details);
				bb.writeLog("航空运输电子客票行程单", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String number = Util.null2String(getString(details, "number"));
				if("".equals(number)){
					number = randomInvoiceNumber();
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, number, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String total = getString(details, "total");
				String user_name = getString(details, "user_name");// 乘机人姓名
				String user_id = getString(details, "user_id");// 身份证号
				String agentcode = getString(details, "agentcode");// 销售单位代号
				String issue_by = getString(details, "issue_by");// 填开单位
				if ("".equals(total)) {
					total = "0.00";
				}
				String fare = getString(details, "fare");// 票价
				String fuel_surcharge = getString(details, "fuel_surcharge");// 燃油附加费
				//航空旅客运输进项税额=（票价+燃油附加费）÷（1+9%）×9%
				String taxRate="9";
				String tax = df.format((Util.getDoubleValue(fare,0.00)+Util.getDoubleValue(fuel_surcharge,0.00)) / (1+0.09) * 0.09);
				//未取得注明旅客身份信息
				if("".equals(user_name)){
					tax = "0.00";
					taxRate="0";
				}
				String pricewithouttax = df.format(Util.getDoubleValue(total)-Util.getDoubleValue(tax));
				String caac_development_fund = getString(details, "caac_development_fund");// 民航发展基金
				String insurance = getString(details, "insurance");// 保险费
				String check_code = getString(details, "check_code");// 验证码
				//ocr增加字段
				String kind =  getString(details, "kind");// 发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,number)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceNumber,invoiceCode,invoiceType,tax,taxRate,taxIncludedPrice,pricewithouttax,userid_new,checkcode,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, number,number, AIRTRANSPORTTICKET_TYPE, tax, taxRate, df.format(Util.getDoubleValue(total,0.00)),pricewithouttax, userid, check_code, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,number)[3]);
					// 插入飞机发票明细表
					String insertAir = "insert into airInvoice(mainid,user_name,user_id,agentcode,issue_by,fare,fuel_surcharge,caac_development_fund,insurance) values(?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertAir, invoiceId, user_name, user_id, agentcode, issue_by, fare,
							fuel_surcharge, caac_development_fund, insurance);
					JSONArray flights = details.getJSONArray("flights");
					for (int j = 0; j < flights.size(); j++) {
						JSONObject flightsjson = flights.getJSONObject(j);
						String from = getString(flightsjson, "from");// 出发站
						String to = getString(flightsjson, "to");// 到达站
						String flight_number = getString(flightsjson, "flight_number");// 航班号
						String flight_date = getString(flightsjson, "date").replace("年", "-").replace("月", "-")
								.replace("日", "");// 乘机日期

						String time = getString(flightsjson, "time");// 乘机时间
						String seat = getString(flightsjson, "seat");// 座位等级
						String carrier = getString(flightsjson, "carrier");// 承运人
						String insertAirDtl = "insert into airDtlInvoice(mainid,from_city,to_city,flight_number,airdate,airtime,seat,carrier) values(?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertAirDtl, invoiceId, from, to, flight_number, flight_date, time, seat,carrier);
					}

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,number);
			} else if ("10507".equals(type)) {// 过路费发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("过路费发票", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String code = getString(details, "code");
				String number = Util.null2String(getString(details, "number"));
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				String total = getString(details, "total");
				String time = getString(details, "time");// 时间
				String entrance = getString(details, "entrance");// 入口
				String exit = getString(details, "exit");// 出口
				if ("".equals(total)) {
					total = "0.00";
				}
				//ocr增加字段
				String kind =  getString(details, "kind");// 发票消费类型
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				infoJson.put("number", number);
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = "insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,taxIncludedPrice,userid_new,authenticity,checkStatus,status,imageID,invoiceSource_new,entryTime,kind) values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, date, code, number, TOLLS_TYPE, df.format(Util.getDoubleValue(total,0.00)), userid, "1","2",
							FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime,kind );
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					// 插入过路费发票明细表
					String insertToll = "insert into tollInvoice(mainid,time,entrance,export) values(?,?,?,?)";
					rs.executeUpdate(insertToll, invoiceId, time, entrance, exit);

					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					insertLog=true;
				}
				addShowInfo(infoJson, number,code);
			}else if("20100".equals(type)){//国际小票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("国际小票", details);
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String store_name = getString(details, "store_name");//店名
				String time = getString(details, "time");//时间
				String subtotal = getString(details, "subtotal");//税前金额
				if("".equals(subtotal)){
					subtotal = "0.00";
				}
				String tax = getString(details, "tax");//税费
				if("".equals(tax)){
					subtotal = "0.00";
				}
				String discount = getString(details, "discount");//折扣
				String tips = getString(details, "tips");//小费
				String total = getString(details, "total");//总金额
				if("".equals(total)){
					total = "0.00";
				}
				String currency_code = getString(details, "currency_code");//币种
				String xftype = getString(details, "type");//消费类型
				String number = randomInvoiceNumber();
				String code = number;
				String insertInvoice = " insert into fnaInvoiceLedger(billingDate,invoiceCode,invoiceNumber,invoiceType,"+ 
									   " taxIncludedPrice,userid_new,authenticity,checkStatus,status,priceWithoutTax,tax,entryTime,invoiceSource_new,imageID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
				rs.executeUpdate(insertInvoice, date,code, number, 13,total,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,subtotal,tax,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID);
				//获取发票id
				invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
				//插入小票发票明细表
				String insertToll = "insert into smallInvoice(mainid,storename,time,discount,tips,currency_code,type) values(?,?,?,?,?,?,?)";
				rs.executeUpdate(insertToll, invoiceId,store_name,time,discount,tips,currency_code,xftype);

				//插入明细
				InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
				insertLog=true;
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				addShowInfo(infoJson, number,code);
			}else if("10900".equals(type)){//可报销的其他发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("可报销其他发票", details);
				String code = Util.null2String(getString(details, "code"));
				String number = Util.null2String(getString(details, "number"));
				String kind = Util.null2String(getString(details, "kind"));
				String total = Util.null2String(getString(details, "total"));
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

                //如果都为空，默认识别失败
                if("".equals(code) && "".equals(number) && "".equals(total) && "".equals(date)){
					FnaInvoiceCommon.saveFailLog(user.getUID(), 0, "识别失败");
					if(identifyArraySize==1){
						throw new Exception("识别失败");
					}else{
						continue;
					}
				}


				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				if ("".equals(total)) {
					total = "0.00";
				}


				String seller = MultiInvoiceUtil.getString(details, "seller");
				String seller_tax_id = MultiInvoiceUtil.getString(details, "seller_tax_id");
				String buyer = MultiInvoiceUtil.getString(details, "buyer");
				String buyer_tax_id = MultiInvoiceUtil.getString(details, "buyer_tax_id");
				String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
				String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
				String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
				String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");

				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = " insert into fnaInvoiceLedger(invoiceCode,invoiceNumber,invoiceType,billingDate,"+
							" taxIncludedPrice,kind,userid_new,authenticity,checkStatus,status,entryTime,invoiceSource_new,imageID," +
							" seller,salesTaxNo,purchaser,purchaserTaxNo) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, code, number,OTHERS_TYPE,date,total,kind,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID,seller,seller_tax_id,buyer,buyer_tax_id);

					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
					insertLog=true;
				}
				infoJson.put("number", number);
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				addShowInfo(infoJson, number,code);
			}else if("10902".equals(type)){//完税证明
				infoJson.put("invoiceInfo", details);
				bb.writeLog("完税证明", details);
				String code = Util.null2String(getString(details, "code"));
				String number = Util.null2String(getString(details, "number"));
				String total = Util.null2String(getString(details, "total"));
				String date = getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");

				String buyer = Util.null2String(getString(details, "buyer"));
				String buyer_tax_id = Util.null2String(getString(details, "buyer_tax_id"));

				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}
				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}
				if ("".equals(total)) {
					total = "0.00";
				}
				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					String insertInvoice = " insert into fnaInvoiceLedger(invoiceCode,invoiceNumber,invoiceType,billingDate,"+
							" taxIncludedPrice,purchaser,purchaserTaxNo,userid_new,authenticity,checkStatus,status,entryTime,invoiceSource_new,imageID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, code, number,TAX_CERTIFICATE_TYPE ,date,total,buyer,buyer_tax_id,userid,"1","2",FnaInvoiceCommon.INIT_STATUS,entryTime,FnaInvoiceCommon.INVOICESOURCE_OCR,imageID);

					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number,code)[3]);
					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId,Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(total, 0.00)),"0.00","0.00",1,df.format(Util.getDoubleValue(total, 0.00)),df.format(Util.getDoubleValue(total, 0.00)),"","");
					insertLog=true;
				}
				infoJson.put("number", number);
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				addShowInfo(infoJson, number,code);

			}else if("19".equals(type)){//区块链发票
				infoJson.put("invoiceInfo", details);
				bb.writeLog("区块链发票", details);
				String number = getString(details, "number");
				String code =getString(details, "code");
				String date =getString(details, "date").replace("年", "-").replace("月", "-").replace("日", "");
				String pretax_amount = getString(details, "pretax_amount");

				if("".equals(pretax_amount)){
					pretax_amount = "0.00";
				}
				if("".equals(number)&&"".equals(code)){
					number = randomInvoiceNumber();
					code = number;
				}else if(!"".equals(number)&&"".equals(code)){
					code = number;
				}else if("".equals(number)&&!"".equals(code)){
					number = code;
				}

				if(fnaInvoiceCommon.ifExistAuthenticity(number, code, rs)){
					String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", number)
							.replace("${invoiceType}", Constants.INVOICETYPE.get(type));
					existsInvoiceSb.append(msg);
					existsInvoiceSb.append("\n");
				}

				String check_code = getString(details, "check_code");
				String total = getString(details, "total");
				if("".equals(total)){
					total = "0.00";
				}
				String tax = getString(details, "tax");
				if("".equals(tax)){
					tax = "0.00";
				}
				DecimalFormat dfTaxRate = new DecimalFormat("###0");
				double taxRate =0;
				if(!"0.00".equals(tax) && !"0.00".equals(pretax_amount)){
					taxRate = (Util.getDoubleValue(tax)/Util.getDoubleValue(pretax_amount))*100;
				}

				String seller = getString(details, "seller");
				String seller_tax_id = getString(details, "seller_tax_id");
				String buyer = getString(details, "buyer");
				String buyer_tax_id = getString(details, "buyer_tax_id");
				String category = getString(details, "category");//种类
				String kind = getString(details, "kind");//发票消费类型

				String seller_addr_tel = MultiInvoiceUtil.getString(details, "seller_addr_tel");
				String seller_bank_account = MultiInvoiceUtil.getString(details, "seller_bank_account");
				String buyer_addr_tel = MultiInvoiceUtil.getString(details, "buyer_addr_tel");
				String buyer_bank_account = MultiInvoiceUtil.getString(details, "buyer_bank_account");

				if (INVOICE_NOT_EXISTS.equals(getInvoiceData(number,code)[3])) {
					rs.executeUpdate("insert into FnaInvoiceLedger(invoiceCode,invoiceNumber,billingDate,priceWithoutTax,tax,taxRate,"
									+ " checkcode,taxIncludedPrice,seller,salesTaxNo,purchaser,purchaserTaxNo,userid_new,status,authenticity,checkStatus," +
									" invoiceType,imageID,invoiceSource_new,entryTime,category,kind) " +
									"values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
							code, number, date, pretax_amount, tax, dfTaxRate.format(taxRate),
							check_code, total, seller, seller_tax_id, buyer, buyer_tax_id, userid, FnaInvoiceCommon.INIT_STATUS, "1", "2",
							BLOCKCHAIN_TYPE, imageID, FnaInvoiceCommon.INVOICESOURCE_OCR, entryTime, category, kind);
					// 获取发票id
					invoiceId = Integer.parseInt(getInvoiceData(number, code)[3]);
					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(invoiceId, Constants.INVOICESERVICEYYPE.get(type), df.format(Util.getDoubleValue(pretax_amount, 0.00)), dfTaxRate.format(taxRate),tax, 1, df.format(Util.getDoubleValue(pretax_amount, 0.00)), df.format(Util.getDoubleValue(pretax_amount, 0.00)), "", "");
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0, invoiceId, "","", seller_addr_tel, buyer_addr_tel, seller_bank_account, buyer_bank_account);
					insertLog=true;
				}
				infoJson.put("number", number);
				infoJson.put("description", Constants.INVOICETYPE.get(type));
				addShowInfo(infoJson, number,code);
			}else {
				FnaInvoiceCommon.saveFailLog(user.getUID(), 0, "识别失败");
				if(identifyArraySize==1){
					throw new Exception("识别失败");
				}else{
					continue;
				}
			}
			invoiceArray.add(infoJson);

			//插入日志
            if(insertLog) {

				//生成发票文档
				ImageDocUtil.updateImageDocId(String.valueOf(invoiceId));

				Map<String, String> labelIdMap = new HashMap<String, String>();
				Map<String, String> beforeMap = new HashMap<String, String>();
				Map<String, String> afterMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceId), labelIdMap);
				fnaLogSqlUtil.invoiceLedgerAddlog(user, ipAdress, "0", String.valueOf(invoiceId), "0",
						beforeMap, afterMap, labelIdMap);
			}





			bb.writeLog("解析发票结束:"+i+"################################################");
		}
		new BaseBean().writeLog("invoiceArray:"+invoiceArray.toString());
		rtnJson.put("flag", true);
		rtnJson.put("ifExistsInterface", InvoiceUtil.ifExistsInterface(user));
		rtnJson.put("data", invoiceArray);
		rtnJson.put("existsInvoiceSb", existsInvoiceSb.toString());

		return rtnJson;
	}


	/**
	 * 格式化金额
	 * @param amount
	 * @return
	 */
	public static String formatAmount(String amount){
		if(Util.getDoubleValue(amount,0.00)==0){
			amount="";
		}else{
			amount = df.format(Util.getDoubleValue(amount,0.00));
		}
		return amount;
	}
	/**
	 * 获取发票信息
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject invoiceShow(FileUpload fu,User user) throws Exception{
		String invoiceId = Util.null2String(fu.getParameter("invoiceId"));
		String uuid = Util.null2String(fu.getParameter("uuid"));
		RecordSet rs = new RecordSet();
		RecordSet rs2 = new RecordSet();
		checkInvoiceBelongs(user,invoiceId);
		rs.executeQuery("select * from fnainvoiceledger where id = ?", invoiceId);
		JSONObject infoJson = new JSONObject();
		if(rs.next()){
			String type = Util.null2String(rs.getString("invoiceType"));
			int authenticity = Util.getIntValue(rs.getString("authenticity"));
			double totalAmount= Util.getDoubleValue(rs.getString("taxIncludedPrice"),0.00);
			boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);

			infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003283,weaver.general.ThreadVarLanguage.getLang())+"", Constants.INVOICETYPE.get(type));
			infoJson.put("type", type);
			if(VAT_ORDINARY_TYPE.equals(type) || VAT_SPECIAL_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type) || VAT_Electronic_Tolls_Type.equals(type)
					|| VAT_Electronic_SPECIAL_Type.equals(type)||VAT_ELEC_TYPE.equals(type)||VAT_GENE_TYPE.equals(type)){//增值税发票
				if(authenticity == AUTHENTICITY_TRUE){
					String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
					String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
					String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
					String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));


					String seller = Util.null2String(rs.getString("seller"));
					String purchaser = Util.null2String(rs.getString("purchaser"));
					String billingDate = Util.null2String(rs.getString("billingDate"));
					String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
					String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", invoiceCode);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", invoiceNumber);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", formatAmount(taxIncludedPrice));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(priceWithoutTax,0.00)));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", billingDate);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", seller);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", purchaser);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003291,weaver.general.ThreadVarLanguage.getLang())+"", salesTaxNo);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003292,weaver.general.ThreadVarLanguage.getLang())+"", purchaserTaxNo);

					if(!InvoiceUtil.ifExistsInterface(user)){
						String checkCode = Util.null2String(rs.getString("checkCode"));
						String category = Util.null2String(rs.getString("category"));//种类
						String kind = Util.null2String(rs.getString("kind"));//发票消费类型
						if(VAT_ORDINARY_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type) || VAT_Electronic_Tolls_Type.equals(type)){//如果是增值税普通发票
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003293,weaver.general.ThreadVarLanguage.getLang())+"", checkCode);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003294,weaver.general.ThreadVarLanguage.getLang())+"", category);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", kind);
						}else{//增值税专用发票
							String tax = Util.null2String(rs.getString("tax"));
							String taxRate = Util.null2String(rs.getString("taxRate"));
							String company_seal = Util.null2String(rs.getString("company_seal"));//是否有公司印章
							String form_type = Util.null2String(rs.getString("form_type"));//发票是第几联
							String form_name = Util.null2String(rs.getString("form_name"));//发票联次
							String ciphertext = Util.null2String(rs.getString("ciphertext"));//密码区

							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003296,weaver.general.ThreadVarLanguage.getLang())+"", tax);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003297,weaver.general.ThreadVarLanguage.getLang())+"", taxRate);
							infoJson.put("是否有公司印章(有/没有)：", "0".equals(company_seal)?"没有":"有");
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003298,weaver.general.ThreadVarLanguage.getLang())+"", form_type);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003299,weaver.general.ThreadVarLanguage.getLang())+"", form_name);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003300,weaver.general.ThreadVarLanguage.getLang())+"", ciphertext);
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", kind);
						}

					}
					infoJson.put("authenticity", AUTHENTICITY_TRUE);
				}else{
					if(authenticity == AUTHENTICITY_UNDETERMINED || authenticity == AUTHENTICITY_FALSE ){
						if(InvoiceUtil.ifExistsInterface(user) && needCheck){
							String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
							String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
							String billingDate = Util.null2String(rs.getString("billingDate"));
							String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
							String checkcode = Util.null2String(rs.getString("checkcode"));
							infoJson.put("invoiceCode", invoiceCode);
							infoJson.put("invoiceNumber", invoiceNumber);
							infoJson.put("billingDate", billingDate);
							infoJson.put("priceWithoutTax", df.format(Util.getDoubleValue(priceWithoutTax,0.00)));
							infoJson.put("checkcode", checkcode);
							infoJson.put("authenticity", AUTHENTICITY_FALSE);
							infoJson.put("exists", true);
						}else{
							String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
							String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
							String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
							String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));


							String seller = Util.null2String(rs.getString("seller"));
							String purchaser = Util.null2String(rs.getString("purchaser"));
							String billingDate = Util.null2String(rs.getString("billingDate"));
							String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
							String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-invoiceCode","text",invoiceCode));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-invoiceNumber","text",invoiceNumber));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-priceWithoutTax","text",df.format(Util.getDoubleValue(priceWithoutTax,0.00))));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-billingDate","date",billingDate));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-seller","text",seller));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-purchaser","text",purchaser));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003291,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-zzs-salesTaxNo","text",salesTaxNo));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003292,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-zzs-purchaserTaxNo","text",purchaserTaxNo));

							//ocr新增字段
							String checkCode = Util.null2String(rs.getString("checkCode"));
							String category = Util.null2String(rs.getString("category"));//种类
							String kind = Util.null2String(rs.getString("kind"));//发票消费类型
							if(VAT_ORDINARY_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type) || VAT_Electronic_Tolls_Type.equals(type)){//如果是增值税普通发票
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003293,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-checkCode","text",checkCode));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003294,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-category","category",category));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-kind","kind",kind));
							}else{//增值税专用发票
								String tax = Util.null2String(rs.getString("tax"));
								String taxRate = Util.null2String(rs.getString("taxRate"));
								String company_seal = Util.null2String(rs.getString("company_seal"));//是否有公司印章
								String form_type = Util.null2String(rs.getString("form_type"));//发票是第几联
								String form_name = Util.null2String(rs.getString("form_name"));//发票联次
								String ciphertext = Util.null2String(rs.getString("ciphertext"));//密码区
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003296,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-tax","text",df.format(Util.getDoubleValue(tax,0.00))));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003297,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-taxRate","text",taxRate));
								infoJson.put("是否有公司印章(有/没有)：",getInput(uuid+"-zzs-company_seal","text","0".equals(company_seal)?"没有":"有"));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003298,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-form_type","text",form_type));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003299,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-form_name","text",form_name));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003300,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-ciphertext","text",ciphertext));
								infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-kind","text",kind));
							}
							infoJson.put("authenticity", AUTHENTICITY_UNDETERMINED);
							infoJson.put("exists", false);
						}
					}
				}
			}else if(MOTORVEHICLESALES_TYPE.equals(type)){//机动车销售统一发票
				if(authenticity == AUTHENTICITY_TRUE){
					String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
					String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
					String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
					String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
					String seller = Util.null2String(rs.getString("seller"));
					String purchaser = Util.null2String(rs.getString("purchaser"));
					String billingDate = Util.null2String(rs.getString("billingDate"));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", invoiceCode);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", invoiceNumber);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", formatAmount(taxIncludedPrice));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(priceWithoutTax,0.00)));
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", billingDate);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", seller);
					infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", purchaser);
					infoJson.put("authenticity", AUTHENTICITY_TRUE);
				}else{
					if(authenticity == AUTHENTICITY_UNDETERMINED || authenticity == AUTHENTICITY_FALSE ){
						if(InvoiceUtil.ifExistsInterface(user) && needCheck){
							String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
							String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
							String billingDate = Util.null2String(rs.getString("billingDate"));
							String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
							String checkcode = Util.null2String(rs.getString("checkcode"));
							infoJson.put("invoiceCode", invoiceCode);
							infoJson.put("invoiceNumber", invoiceNumber);
							infoJson.put("billingDate", billingDate);
							infoJson.put("priceWithoutTax", df.format(Util.getDoubleValue(priceWithoutTax,0.00)));
							infoJson.put("checkcode", checkcode);
							infoJson.put("authenticity", AUTHENTICITY_FALSE);
							infoJson.put("exists", true);
						}else{
							String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
							String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
							String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
							String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
							String seller = Util.null2String(rs.getString("seller"));
							String purchaser = Util.null2String(rs.getString("purchaser"));
							String billingDate = Util.null2String(rs.getString("billingDate"));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-invoiceCode","text",invoiceCode));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-invoiceNumber","text",invoiceNumber));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-priceWithoutTax","text",df.format(Util.getDoubleValue(priceWithoutTax,0.00))));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-billingDate","date",billingDate));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-seller","text",seller));
							infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-zzs-purchaser","text",purchaser));
							infoJson.put("authenticity", AUTHENTICITY_UNDETERMINED);
							infoJson.put("exists", false);
						}
					}
				}
			}else if(USEDCARSALES_TYPE.equals(type)){//二手车销售统一发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String seller_id="";//卖方单位代码/个人身份证号
				String buyer_id="";//买方单位代码/个人身份证号
				String company_name="";//二手车市场
				String company_tax_id="";//二手车市场纳税人识别号
				String license_plate="";//车牌号
				String registration_number="";//登记证号
				String car_code="";//车架号/车辆识别代码
				String car_model="";//厂牌型号
				rs2.executeQuery("select * from second_carInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					seller_id = Util.null2String(rs2.getString("seller_id"));
					buyer_id = Util.null2String(rs2.getString("buyer_id"));
					company_name = Util.null2String(rs2.getString("company_name"));
					company_tax_id = Util.null2String(rs2.getString("company_tax_id"));
					license_plate = Util.null2String(rs2.getString("license_plate"));
					registration_number = Util.null2String(rs2.getString("registration_number"));
					car_code = Util.null2String(rs2.getString("car_code"));
					car_model = Util.null2String(rs2.getString("car_model"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003301,weaver.general.ThreadVarLanguage.getLang())+"/"+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003302,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-seller_id","text",seller_id));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003303,weaver.general.ThreadVarLanguage.getLang())+"/"+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003302,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-buyer_id","text",buyer_id));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003304,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-company_name","text",company_name));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003305,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-company_tax_id","text",company_tax_id));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003306,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-license_plate","text",license_plate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003307,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-registration_number","text",registration_number));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003308,weaver.general.ThreadVarLanguage.getLang())+"/"+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003309,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-car_code","text",car_code));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003310,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-esc-car_model","text",car_model));
			}else if(QUOTA_TYPE.equals(type)){//定额发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-de-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-de-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-de-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				//ocr新增字段
				String kind = Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-de-kind","text",kind));
			}else if(GENERALMACHINE_TYPE.equals(type)){//机打发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String seller = Util.null2String(rs.getString("seller"));
				String purchaser = Util.null2String(rs.getString("purchaser"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				String checkCode = Util.null2String(rs.getString("checkCode"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-seller","text",seller));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-purchaser","text",purchaser));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003293,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-checkCode","text",checkCode));
				String time="";//时间
				String category="";//种类，oil 表示是加油票
				String salesTaxNo=Util.null2String(rs.getString("salesTaxNo"));// 销售方纳税人识别号
				String purchaserTaxNo=Util.null2String(rs.getString("purchaserTaxNo"));//购买方纳税人识别号
				rs2.executeQuery("select * from machineInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					time = Util.null2String(rs2.getString("time"));
					category = Util.null2String(rs2.getString("category"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003311,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-time","text",time));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003294,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-category","text",category));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003291,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-salesTaxNo","text",salesTaxNo));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003292,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-jdfp-purchaserTaxNo","text",purchaserTaxNo));
				//ocr新增字段
				String kind = Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-jdfp-kind","text",kind));


				String sellerAddress="";
				String purchaserAddress="";
				String salesBank="";
				String purchaserBank="";
				rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
				if(rs2.next()){
					sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
					purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
					salesBank = Util.null2String(rs2.getString("salesBank"));
					purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
				}
				infoJson.put(SystemEnv.getHtmlLabelName(529910,user.getLanguage()),getInput(uuid+"-jdfp-sellerAddress","text",sellerAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529911,user.getLanguage()),getInput(uuid+"-jdfp-purchaserAddress","text",purchaserAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529912,user.getLanguage()),getInput(uuid+"-jdfp-salesBank","text",salesBank));
				infoJson.put(SystemEnv.getHtmlLabelName(529913,user.getLanguage()),getInput(uuid+"-jdfp-purchaserBank","text",purchaserBank));

			}else if(TAXI_TYPE.equals(type)){//出租车发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String time_geton="";//上车时间
				String time_getoff="";//下车时间
				String mileage="";//里程
				String place="";//发票所在地
				rs2.executeQuery("select * from taxiInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					time_geton = Util.null2String(rs2.getString("time_geton"));
					time_getoff = Util.null2String(rs2.getString("time_getoff"));
					mileage = Util.null2String(rs2.getString("mileage"));
					place = Util.null2String(rs2.getString("place"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003312,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-time_geton","text",time_geton));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003313,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-time_getoff","text",time_getoff));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003314,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-mileage","text",mileage));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003315,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-czc-place","text",place));
				//ocr新增字段
				String kind = Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-czc-kind","text",kind));
			}else if(TRAIN_TYPE.equals(type)){//火车票
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String time="";//时间
				String name="";//乘车人姓名
				String station_geton="";//上车车站
				String station_getoff="";//下车车站
				String train_number="";//车次
				String seat="";//座位类型
				rs2.executeQuery("select * from trainInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					time = Util.null2String(rs2.getString("time"));
					name = Util.null2String(rs2.getString("name"));
					station_geton = Util.null2String(rs2.getString("station_geton"));
					station_getoff = Util.null2String(rs2.getString("station_getoff"));
					train_number = Util.null2String(rs2.getString("train_number"));
					seat = Util.null2String(rs2.getString("seat"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003311,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-time","text",time));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003316,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-name","text",name));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003317,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-station_geton","text",station_geton));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003318,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-station_getoff","text",station_getoff));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003319,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-train_number","text",train_number));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003320,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hcp-seat","text",seat));
				//ocr新增字段
				String kind = Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-hcp-kind","text",kind));
			}else if(PASSENGERTICKET_TYPE.equals(type)){//客运汽车
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String time="";//时间
				String station_geton="";//上车车站
				String station_getoff="";//下车车站
				String name="";//乘车人姓名
				rs2.executeQuery("select * from carInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					time = Util.null2String(rs2.getString("time"));
					name = Util.null2String(rs2.getString("name"));
					station_geton = Util.null2String(rs2.getString("station_geton"));
					station_getoff = Util.null2String(rs2.getString("station_getoff"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003311,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-time","text",time));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003321,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-station_geton","text",station_geton));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003322,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-station_getoff","text",station_getoff));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003316,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-kyqc-name","text",name));
				//ocr新增字段
				String kind = Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-kyqc-kind","text",kind));
			}else if(AIRTRANSPORTTICKET_TYPE.equals(type)){//航空运输电子客票行程单
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
//				infoJson.put("发票代码：", getInput(uuid+"-hk-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003323,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String user_name="";// 乘机人姓名
				String user_id="";//身份证号
				String agentcode="";//销售单位代号
				String issue_by="";//填开单位
				String fare="";//票价
				String fuel_surcharge="";//燃油附加费
				String caac_development_fund="";//民航发展基金
				String insurance="";//保险费
				rs2.executeQuery("select * from airInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					user_name = Util.null2String(rs2.getString("user_name"));
					user_id = Util.null2String(rs2.getString("user_id"));
					agentcode = Util.null2String(rs2.getString("agentcode"));
					issue_by = Util.null2String(rs2.getString("issue_by"));
					fare = Util.null2String(rs2.getString("fare"));
					fuel_surcharge = Util.null2String(rs2.getString("fuel_surcharge"));
					caac_development_fund = Util.null2String(rs2.getString("caac_development_fund"));
					insurance = Util.null2String(rs2.getString("insurance"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003324,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-user_name","text",user_name));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003325,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-user_id","text",user_id));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003326,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-agentcode","text",agentcode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003327,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-issue_by","text",issue_by));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003328,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-fare","text",fare));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003329,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-fuel_surcharge","text",fuel_surcharge));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003330,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-caac_development_fund","text",caac_development_fund));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003331,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-insurance","text",insurance));

				//ocr添加字段
				String check_code = Util.null2String(rs.getString("checkCode"));
				String tax = Util.null2String(rs.getString("tax"));
				String kind=  Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003293,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-check_code","text",check_code));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003296,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-tax","text",df.format(Util.getDoubleValue(tax,0.00))));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-hk-kind","text",kind));
			}else if(TOLLS_TYPE.equals(type)){//过路费发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				String time="";//时间
				String entrance="";//入口
				String exit="";//出口
				rs2.executeQuery("select * from tollInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					time = Util.null2String(rs2.getString("time"));
					entrance = Util.null2String(rs2.getString("entrance"));
					exit = Util.null2String(rs2.getString("export"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003311,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-time","text",time));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003332,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-entrance","text",entrance));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003333,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-exit","text",exit));
				//ocr添加字段
				String kind=  Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-glf-kind","text",kind));
			}else if(INTERNATIONAL_RECEIPTS.equals(type)){//国际小票
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
				String tax = Util.null2String(rs.getString("tax"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003334,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003335,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-priceWithoutTax","text",df.format(Util.getDoubleValue(priceWithoutTax,0.00))));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003336,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-tax","text",tax));
				String storename = "";
				String time = "";
				String discount = "";
				String tips = "";
				String currency_code = "";
				String xftype = "";
				rs2.executeQuery("select * from smallInvoice where mainid = ?",invoiceId);
				if(rs2.next()){
					storename = Util.null2String(rs2.getString("storename"));
					time = Util.null2String(rs2.getString("time"));
					discount = Util.null2String(rs2.getString("discount"));
					tips = Util.null2String(rs2.getString("tips"));
					currency_code = Util.null2String(rs2.getString("currency_code"));
					xftype = Util.null2String(rs2.getString("type"));
				}
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003337,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-storename","text",storename));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003311,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-time","text",time));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003338,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-discount","text",discount));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003339,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-tips","text",tips));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003340,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-currency_code","text",currency_code));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003341,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-xp-xftype","text",xftype));
			}else if(OTHERS_TYPE.equals(type)){//可报销的其他发票
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				String kind =  Util.null2String(rs.getString("kind"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qt-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qt-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qt-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qt-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qt-kind","text",kind));

				String seller = Util.null2String(rs.getString("seller"));
				String purchaser = Util.null2String(rs.getString("purchaser"));
				String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
				String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
				String sellerAddress="";
				String purchaserAddress="";
				String salesBank="";
				String purchaserBank="";
				rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
				if(rs2.next()){
					sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
					purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
					salesBank = Util.null2String(rs2.getString("salesBank"));
					purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
				}

				infoJson.put(SystemEnv.getHtmlLabelName(10003289,user.getLanguage()), getInput(uuid+"-qt-seller","text",seller));
				infoJson.put(SystemEnv.getHtmlLabelName(10003290,user.getLanguage()), getInput(uuid+"-qt-purchaser","text",purchaser));
				infoJson.put(SystemEnv.getHtmlLabelName(10003291,user.getLanguage()),getInput(uuid+"-qt-salesTaxNo","text",salesTaxNo));
				infoJson.put(SystemEnv.getHtmlLabelName(10003292,user.getLanguage()),getInput(uuid+"-qt-purchaserTaxNo","text",purchaserTaxNo));
				infoJson.put(SystemEnv.getHtmlLabelName(529910,user.getLanguage()),getInput(uuid+"-qt-sellerAddress","text",sellerAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529911,user.getLanguage()),getInput(uuid+"-qt-purchaserAddress","text",purchaserAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529912,user.getLanguage()),getInput(uuid+"-qt-salesBank","text",salesBank));
				infoJson.put(SystemEnv.getHtmlLabelName(529913,user.getLanguage()),getInput(uuid+"-qt-purchaserBank","text",purchaserBank));

			}else if(TAX_CERTIFICATE_TYPE.equals(type)){//完税证明
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				String purchaser = Util.null2String(rs.getString("purchaser"));
				String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-purchaser","text",purchaser));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003292,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-wszm-purchaserTaxNo","text",purchaserTaxNo));


			}else if(BLOCKCHAIN_TYPE.equals(type)) {//区块链
				String invoiceCode = Util.null2String(rs.getString("invoiceCode"));
				String invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
				String billingDate = Util.null2String(rs.getString("billingDate"));
				String priceWithoutTax = Util.null2String(rs.getString("priceWithoutTax"));
				String taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
				String checkCode = Util.null2String(rs.getString("checkCode"));
				String seller = Util.null2String(rs.getString("seller"));
				String purchaser = Util.null2String(rs.getString("purchaser"));
				String salesTaxNo = Util.null2String(rs.getString("salesTaxNo"));
				String purchaserTaxNo = Util.null2String(rs.getString("purchaserTaxNo"));
				String kind = Util.null2String(rs.getString("kind"));
				String category = Util.null2String(rs.getString("category"));

				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-invoiceCode","text",invoiceCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-invoiceNumber","text",invoiceNumber));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-billingDate","date",billingDate));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-taxIncludedPrice","text",formatAmount(taxIncludedPrice)));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-priceWithoutTax","text",df.format(Util.getDoubleValue(priceWithoutTax,0.00))));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003293,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-checkCode","text",checkCode));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-seller","text",seller));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-purchaser","text",purchaser));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003291,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-qkl-salesTaxNo","text",salesTaxNo));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003292,weaver.general.ThreadVarLanguage.getLang())+"",getInput(uuid+"-qkl-purchaserTaxNo","text",purchaserTaxNo));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003295,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-kind","text",kind));
				infoJson.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003294,weaver.general.ThreadVarLanguage.getLang())+"", getInput(uuid+"-qkl-category","text",category));


				String sellerAddress="";
				String purchaserAddress="";
				String salesBank="";
				String purchaserBank="";
				rs2.executeQuery("select * from FnaInvoiceLedgerDtl where mainid = ?",invoiceId);
				if(rs2.next()){
					sellerAddress = Util.null2String(rs2.getString("sellerAddress"));
					purchaserAddress = Util.null2String(rs2.getString("purchaserAddress"));
					salesBank = Util.null2String(rs2.getString("salesBank"));
					purchaserBank = Util.null2String(rs2.getString("purchaserBank"));
				}
				infoJson.put(SystemEnv.getHtmlLabelName(529910,user.getLanguage()),getInput(uuid+"-qkl-sellerAddress","text",sellerAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529911,user.getLanguage()),getInput(uuid+"-qkl-purchaserAddress","text",purchaserAddress));
				infoJson.put(SystemEnv.getHtmlLabelName(529912,user.getLanguage()),getInput(uuid+"-qkl-salesBank","text",salesBank));
				infoJson.put(SystemEnv.getHtmlLabelName(529913,user.getLanguage()),getInput(uuid+"-qkl-purchaserBank","text",purchaserBank));
			}
		}
		infoJson.put("flag", true);
		return infoJson;
	}

	/**
	 * 单个发票验票
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject authenticityCheck(FileUpload fu,User user,String ipAdress) throws Exception{
		boolean existsInterface = InvoiceUtil.ifExistsInterface(user);
		FnaInvoiceCommon fnaInvoiceCommon = new FnaInvoiceCommon();
		if(!existsInterface){
			throw new Exception(SystemEnv.getHtmlLabelName(384842,user.getLanguage()));
		}
		String result = Util.null2String(fu.getParameter("result"));
		//判断此张发票是否已经存在
		RecordSet rs = new RecordSet();
		String invoiceid = Util.null2String(fu.getParameter("invoiceid"));
		String invoiceCode = result.split(",")[2];//发票代码
		String invoiceNo = result.split(",")[3];//发票号码
		rs.executeQuery("select invoiceType from FnaInvoiceLedger where invoiceCode = ? and invoiceNumber = ? and id <> ?", invoiceCode,invoiceNo,invoiceid);
		if(rs.next()){
			int invoiceType = Util.getIntValue(rs.getString("invoiceType"));
			String msg = SystemEnv.getHtmlLabelName(509483, user.getLanguage()).replace("${invoiceNumber}", invoiceNo)
					.replace("${invoiceType}", Constants.INVOICETYPE.get(invoiceType));
			throw new Exception(msg);
		}
		
		FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
		JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
		int checkstatus = resultObj.getInt("status");
		JSONObject json = new JSONObject();
		if(checkstatus == 0){//失败
			json.put("flag", false);
			if(resultObj.containsKey("errMsg")){
				json.put("msg", resultObj.getString("errMsg"));
			}else{
				json.put("msg", SystemEnv.getHtmlLabelName(509478, user.getLanguage()));//查验失败!
			}

			//插入日志1
			Map<String, String> labelIdMap = new HashMap<String, String>();
			Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);
			rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,3,invoiceid);
			//插入日志2
			Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);
			fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",String.valueOf(invoiceid),"1",
					beforeMap,afterMap,labelIdMap);
		}else{
			//首先判断当前发票的发票类型
			rs.executeQuery("select invoiceType from FnaInvoiceLedger where id=?",invoiceid);
			String invoiceType ="";
			if(rs.next()){
				invoiceType=Util.null2String(rs.getString("invoiceType"));
			}
            if(VAT_SPECIAL_TYPE.equals(invoiceType) || VAT_ORDINARY_TYPE.equals(invoiceType) || VAT_Electronic_Type.equals(invoiceType) || VAT_ORDINARY_Volume_TYPE.equals(invoiceType) || VAT_Electronic_Tolls_Type.equals(invoiceType)
            		 || VAT_Electronic_SPECIAL_Type.equals(invoiceType)||VAT_ELEC_TYPE.equals(invoiceType)||VAT_GENE_TYPE.equals(invoiceType)){//增值税发票
				String purchaser = resultObj.getString("_purchaser");
				String _purchaserTaxNo = resultObj.getString("_purchaserTaxNo");
				String seller = resultObj.getString("_seller");
				String _salesTaxNo = resultObj.getString("_salesTaxNo");//销售方纳税人识别号
				String taxRate = Util.getDoubleValue(resultObj.getString("_taxRate"),0.00)+"";
				String tax = resultObj.getString("_tax");
				String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
				String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
				String _billingDate1 = resultObj.getString("_billingDate");
				String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
				String _invoiceNumber = resultObj.getString("_invoiceNumber");
				String _billingDate = resultObj.getString("_billingDate");
				//String _invoicecode = resultObj.getString("_invoicecode");
				String _checkCode = resultObj.getString("_checkCode");

				String checkCodeSix = "";
				String _invoicecode="";
				if(VAT_ELEC_TYPE.equals(invoiceType)||VAT_GENE_TYPE.equals(invoiceType)){
					_invoicecode=_invoiceNumber;
				}else {
					_invoicecode = resultObj.getString("_invoicecode");
				}
				if(_checkCode.length()>6){
					checkCodeSix = _checkCode.substring(_checkCode.length()-6);
				}
				String remark = resultObj.getString("_remark");
				String sellerAddress = resultObj.getString("_sellerAddress");
				String purchaserAddress = resultObj.getString("_purchaserAddress");
				String salesBank = resultObj.getString("_salesBank");
				String purchaserBank = resultObj.getString("_purchaserBank");
				
				if(!fnaInvoiceCommon.ifExistAuthenticity2(_invoiceNumber, _invoicecode, new RecordSet())){
					//判断纳税人识别号是否维护
					boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
					if(!protectInvoiceTaxpayerNumber){
						json.put("flag", false);
						json.put("msg", SystemEnv.getHtmlLabelName(390260,user.getLanguage()));
						return json;
					}

					//插入日志1
					Map<String, String> labelIdMap = new HashMap<String, String>();
					Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);

					rs.executeUpdate("update fnaInvoiceLedger set checkCode=?,tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
									"salesTaxNo=?,purchaserTaxNo=?,invoiceNumber=?,invoiceCode=? where id=?"
							,_checkCode,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,
							_salesTaxNo,_purchaserTaxNo,_invoiceNumber,_invoicecode,invoiceid);
					invoiceid = getInvoiceData(_invoiceNumber,_invoicecode)[3];
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceid),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);
					JSONArray detaildata = resultObj.getJSONArray("detaildata");
					InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceid);

					//插入日志2
					Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);
					fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",String.valueOf(invoiceid),"1",
							beforeMap,afterMap,labelIdMap);
				}

				json.put("flag", true);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", _invoicecode);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", _invoiceNumber);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(_taxIncludedPrice)));
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(_priceWithoutTax)));
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", _billingDate);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", seller);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", purchaser);
				json.put("id", invoiceid);
				json.put("date", _billingDate);
				json.put("number", _invoiceNumber);
				json.put("amt", df.format(Util.getDoubleValue(_taxIncludedPrice)));
			}else if(MOTORVEHICLESALES_TYPE.equals(invoiceType)){//机动车销售统一发票
				//获取发票信息
                String taxIncludedPriceTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxIncludedPrice"),0.00));
                String priceWithoutTaxTrue = df.format(Util.getDoubleValue(resultObj.getString("_priceWithoutTax"),0.00));
                String taxTrue = df.format(Util.getDoubleValue(resultObj.getString("_tax"),0.00));
                String taxRateTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxRate"),0.00));
				String invoiceNumberTrue = resultObj.getString("_invoiceNumber");
				String invoicecodeTrue = resultObj.getString("_invoicecode");
				String purchaserTrue = resultObj.getString("_purchaser");
				String sellerTrue = resultObj.getString("_seller");
				String purchaserTaxNoTrue = resultObj.getString("_purchaserTaxNo");
				String salesTaxNoTrue = resultObj.getString("_salesTaxNo");
				String billingDateTrue = resultObj.getString("_billingDate");

				String remark = resultObj.getString("_remark");
				String sellerAddress = resultObj.getString("_sellerAddress");
				String purchaserAddress = resultObj.getString("_purchaserAddress");
				String salesBank = resultObj.getString("_salesBank");
				String purchaserBank = resultObj.getString("_purchaserBank");

				//机动车销售统一发票明细信息
				String machine_code = resultObj.getString("_machine_code");
				String machine_number = resultObj.getString("_machine_number");
				String tax_authorities = resultObj.getString("_tax_authorities");
				String tax_authorities_code = resultObj.getString("_tax_authorities_code");
				String car_code = resultObj.getString("_car_code");
				String car_engine_code = resultObj.getString("_car_engine_code");
				String car_model = resultObj.getString("_car_model");
				String certificate_number = resultObj.getString("_certificate_number");
				
				if(!fnaInvoiceCommon.ifExistAuthenticity2(invoiceNumberTrue, invoicecodeTrue, new RecordSet())){

					//插入日志1
					Map<String, String> labelIdMap = new HashMap<String, String>();
					Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);

					rs.executeUpdate("update fnaInvoiceLedger set billingDate=?,invoiceCode=?,invoiceNumber=?,invoiceType=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?," +
							"priceWithoutTax=?,tax=?,taxRate=?,taxIncludedPrice=?,authenticity=?,checkStatus=? where id=?"
							,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,invoiceType,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
					priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,invoiceid);
					rs.executeQuery("select 1 from motor_VehicleInvoice where mainid=?",invoiceid);
					if(rs.next()){
						rs.executeUpdate("update motor_VehicleInvoice set machine_code=?,machine_number=?,tax_authorities=?,tax_authorities_code=?,car_code=?,car_engine_code=?,car_model=?,certificate_number=? where mainid=?",
								machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number,invoiceid);

					}else{
						rs.executeUpdate("insert into motor_VehicleInvoice (mainid,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?)",
								invoiceid,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

					}

					//保存FnaInvoiceLedgerDtl表信息
					InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceid,0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);
					//插入明细
					InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");

					//插入日志2
					Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(String.valueOf(invoiceid),labelIdMap);
					fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",String.valueOf(invoiceid),"1",
							beforeMap,afterMap,labelIdMap);
				}

				
				json.put("flag", true);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003284,weaver.general.ThreadVarLanguage.getLang())+"", invoicecodeTrue);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003285,weaver.general.ThreadVarLanguage.getLang())+"", invoiceNumberTrue);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003286,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(taxIncludedPriceTrue)));
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003287,weaver.general.ThreadVarLanguage.getLang())+"", df.format(Util.getDoubleValue(priceWithoutTaxTrue)));
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003288,weaver.general.ThreadVarLanguage.getLang())+"", billingDateTrue);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003289,weaver.general.ThreadVarLanguage.getLang())+"", sellerTrue);
				json.put(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10003290,weaver.general.ThreadVarLanguage.getLang())+"", purchaserTrue);
				json.put("id", invoiceid);
				json.put("date", billingDateTrue);
				json.put("number", invoiceNumberTrue);
				json.put("amt", df.format(Util.getDoubleValue(taxIncludedPriceTrue)));
			}


		}
		return json;
	}

	/**
	 * 发票验票
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject invoiceCheck(FileUpload fu,User user,String ipAdress) throws Exception{
		String entryTime = Util.date(2);//录入时间
		JSONObject jsonObject = new JSONObject();
		BaseBean bb = new BaseBean();
		String invoiceType = fu.getParameter("invoiceType");
		String invoiceNumber = Util.null2String(fu.getParameter("number"));
		String invoiceCode = Util.null2String(fu.getParameter("code"));
		String billingDate = Util.null2String(fu.getParameter("date")).replace("年", "-").replace("月", "-").replace("日", "");
		String billingDate_bak = billingDate;
		String priceWithoutTax = df.format(Util.getDoubleValue(fu.getParameter("pretax_amount"),0.00));
		String taxIncludedPrice = df.format(Util.getDoubleValue(fu.getParameter("total"),0.00));
		int imageID = Util.getIntValue(fu.getParameter("imageID"),0);
		String[] invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
		if(!"".equals(invoiceNumber) && ifExistAuthenticity2(invoiceNumber,invoiceCode)){
			jsonObject.put("flag", true);
			jsonObject.put("status", 0);
			jsonObject.put("invoiceId", invoiceData[3]);
			jsonObject.put("taxIncludedPrice", invoiceData[1]);
			jsonObject.put("number", invoiceNumber);
			jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
			return jsonObject;
		}
		RecordSet rs = new RecordSet();
		if("10100".equals(invoiceType) || "21".equals(invoiceType)){//增值税专用发票
			if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(priceWithoutTax)) {
				if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
					if("".equals(priceWithoutTax)){
						priceWithoutTax = "0.00";
					}
					if("".equals(taxIncludedPrice)){
						taxIncludedPrice = "0.00";
					}
					
					String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
										   " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,VAT_SPECIAL_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
							0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,0,
									user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

					invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
					//生成发票文档
					ImageDocUtil.updateImageDocId(invoiceData[3]);
					//插入日志
					Map<String, String> labelIdMap = new HashMap<String, String>();
					Map<String, String> beforeMap = new HashMap<String, String>();
					Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
					fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
							beforeMap,afterMap,labelIdMap);
				}

				jsonObject.put("invoiceId", invoiceData[3]);
				jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
				jsonObject.put("flag", true);
				jsonObject.put("status", 1);
				return jsonObject;
			}else{
				String result = "01,01," + invoiceCode + "," + invoiceNumber
						+ "," + priceWithoutTax
						+ "," + billingDate.replaceAll("-", "")
						+ ",,1111,";
				bb.writeLog("invoiceCheck-result:", result);
				FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
				JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result, null);
				int checkstatus = resultObj.getInt("status");
				if (checkstatus == 0) {//验票失败
					int invType = InvoiceUtil.recoginizeInvoiceType(invoiceCode);
					if(invType==1){
						invoiceType = "2";
					}else if(invType==21){
						invoiceType = "21";
					}
					
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
					   " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,invoiceType,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
								0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,3,
								user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						//生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{
						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,3,invoiceData[3]);
						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}

					jsonObject.put("flag", true);
					jsonObject.put("status", 2);
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
					jsonObject.put("number", invoiceNumber);
					jsonObject.put("invoiceId", invoiceData[3]);
					return jsonObject;
				}else{//更新发票记录

					String purchaser = resultObj.getString("_purchaser");
					String _purchaserTaxNo = resultObj.getString("_purchaserTaxNo");
					String seller = resultObj.getString("_seller");
					String _salesTaxNo = resultObj.getString("_salesTaxNo");//销售方纳税人识别号
					String taxRate = Util.getDoubleValue(resultObj.getString("_taxRate"),0.00)+"";
					String tax = Util.getDoubleValue(resultObj.getString("_tax"),0.00)+"";
					String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
					String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
					String _billingDate1 = resultObj.getString("_billingDate");
					String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");
					String _invoiceType = resultObj.getString("_invoiceType");
					

					JSONArray detaildata = resultObj.getJSONArray("detaildata");
					//判断纳税人识别号是否维护
					boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
					if(!protectInvoiceTaxpayerNumber){
						if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
							String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
									+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,_invoiceType,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
									_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,3,user.getUID(),imageID,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
							invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


							//保存FnaInvoiceLedgerDtl表信息
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

							//生成发票文档
							ImageDocUtil.updateImageDocId(invoiceData[3]);
							//插入日志
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = new HashMap<String, String>();
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);

						}else{
							//插入日志1
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
									"salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
									,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,AUTHENTICITY_UNDETERMINED,3,taxRate,_priceWithoutTax,_invoiceServiceYype,
									_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);

							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
							//保存FnaInvoiceLedgerDtl表信息
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);
							//插入日志2
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);

						}
						jsonObject.put("flag", true);
						jsonObject.put("status", 2);
						jsonObject.put("seller", seller);
						jsonObject.put("invoiceId", invoiceData[3]);
						jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
						jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(_taxIncludedPrice)));
						jsonObject.put("number", invoiceNumber);
						return jsonObject;
					}
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
								+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,_invoiceType,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
								_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_TRUE,1,user.getUID(),imageID,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

						//生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{

						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
										"salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
								,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,
								_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
						rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);

						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}
					jsonObject.put("flag", true);
					jsonObject.put("status", 0);
					jsonObject.put("seller", seller);
					jsonObject.put("invoiceId", invoiceData[3]);
					jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(_taxIncludedPrice)));
					jsonObject.put("number", invoiceNumber);
					return jsonObject;
				}
			}
		}else if("10107".equals(invoiceType)||"10108".equals(invoiceType)){//增值税专用发票(全电票)
			String VAT_ELEC_GENE_TYPE="";
			if("10107".equals(invoiceType)){
				VAT_ELEC_GENE_TYPE=VAT_ELEC_TYPE;
			}else{
				VAT_ELEC_GENE_TYPE=VAT_GENE_TYPE;
			}
			String checkCode = Util.null2String(fu.getParameter("check_code"));
			if(checkCode.length() != 20){
				checkCode = "";
			}
			String checkCodeSix = "";
			if(checkCode.length()>6){
				checkCodeSix = checkCode.substring(checkCode.length()-6);
			}
			if ("".equals(invoiceNumber)  || "".equals(billingDate) || "".equals(priceWithoutTax)) {
				if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
					if("".equals(priceWithoutTax)){
						priceWithoutTax = "0.00";
					}
					if("".equals(taxIncludedPrice)){
						taxIncludedPrice = "0.00";
					}
					if(!"".equals(billingDate_bak) && !checkDate(billingDate)){
						billingDate = getDate();
					}
					invoiceCode=invoiceNumber;
					String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
							" tax,taxIncludedPrice,authenticity,checkStatus,checkcode,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
							0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,0,checkCode,
							user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


					invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
					//插入日志
					Map<String, String> labelIdMap = new HashMap<String, String>();
					Map<String, String> beforeMap = new HashMap<String, String>();
					Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
					fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
							beforeMap,afterMap,labelIdMap);
				}

				jsonObject.put("invoiceId", invoiceData[3]);
				jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
				jsonObject.put("flag", true);
				jsonObject.put("status", 1);
				//生成发票文档
				ImageDocUtil.updateImageDocId(invoiceData[3]);
				return jsonObject;
			}else{
				invoiceCode=invoiceNumber;
				String result = "01,10," + invoiceCode + "," + invoiceNumber
						+ "," + df.format(Util.getDoubleValue(taxIncludedPrice,0.00)) + ","
						+ billingDate.replaceAll("-", "") + ","
						+ "" + ",1111,";
				bb.writeLog("invoiceCheck-result:", result);
				FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
				JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
				int checkstatus = resultObj.getInt("status");if (checkstatus == 0) {//验票失败
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
								" tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,checkCode,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
								0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,3,
								user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,checkCode,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
						//生成发票文档
						jsonObject.put("invoiceId", invoiceData[3]);
						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}
					jsonObject.put("flag", true);
					jsonObject.put("status", 2);
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
					jsonObject.put("number", invoiceNumber);
					jsonObject.put("invoiceId", invoiceData[3]);
					//生成发票文档
					return jsonObject;
				}else{//更新发票记录
					String purchaser = resultObj.getString("_purchaser");
					String _purchaserTaxNo = resultObj.getString("_purchaserTaxNo");
					String seller = resultObj.getString("_seller");
					String _salesTaxNo = resultObj.getString("_salesTaxNo");//销售方纳税人识别号
					String taxRate = Util.getDoubleValue(resultObj.getString("_taxRate"),0.00)+"";
					String tax = resultObj.getString("_tax");
					String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
					String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
					String _billingDate1 = resultObj.getString("_billingDate");
					String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");
					JSONArray detaildata = resultObj.getJSONArray("detaildata");
					invoiceCode=invoiceNumber;
					//判断纳税人识别号是否维护
					boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
					if(!protectInvoiceTaxpayerNumber){
						if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {

							String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
									+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
									_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,3,user.getUID(),imageID,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
							invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
							//保存FnaInvoiceLedgerDtl表信息
							//生成发票文档
							jsonObject.put("invoiceId", invoiceData[3]);
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);



							//插入日志
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = new HashMap<String, String>();
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);

						}else{
							//插入日志1
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
											"checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
									,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,AUTHENTICITY_UNDETERMINED,3,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
									_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);

							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
							//保存FnaInvoiceLedgerDtl表信息
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);



							//插入日志2
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);
						}
						jsonObject.put("flag", true);
						jsonObject.put("status", 2);
						jsonObject.put("seller", seller);
						jsonObject.put("invoiceId", invoiceData[3]);
						jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
						jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice)));
						jsonObject.put("number", invoiceNumber);
						return jsonObject;
					}

					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String selectSql="select  count(*) from fnaInvoiceLedger where invoiceCode=? and invoiceNumber=?";
						rs.executeQuery(selectSql,invoiceCode,invoiceNumber);
						int colCounts = rs.getColCounts();
						if(colCounts>0){
							rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
											"checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
									,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
									_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
							rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
						}else{
							String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
									+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,VAT_ELEC_GENE_TYPE,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
									_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_TRUE,1,user.getUID(),imageID,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

						}
						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
						//生成发票文档
						jsonObject.put("invoiceId", invoiceData[3]);
						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);


						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);


					}else{

						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

						rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
										"checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
								,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
								_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
						rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);


						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}
					jsonObject.put("flag", true);
					jsonObject.put("status", 0);
					jsonObject.put("seller", seller);
					jsonObject.put("invoiceId", invoiceData[3]);
					jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice)));
					jsonObject.put("number", invoiceNumber);
					return jsonObject;
				}
			}
		}else if("10101".equals(invoiceType) || "10102".equals(invoiceType) || "10103".equals(invoiceType) || "20".equals(invoiceType)){
			String invoiceTypeTrue="";
			if("10101".equals(invoiceType)){
				invoiceTypeTrue = VAT_ORDINARY_TYPE;
			}else if("10102".equals(invoiceType)){
				invoiceTypeTrue = VAT_Electronic_Type;
			}else if("10103".equals(invoiceType)){
				invoiceTypeTrue = VAT_ORDINARY_Volume_TYPE;
			}else if("20".equals(invoiceType)){
				invoiceTypeTrue = VAT_Electronic_Tolls_Type;
			}
			String checkCode = Util.null2String(fu.getParameter("check_code"));
			if(checkCode.length() != 20){
				checkCode = "";
			}
			String checkCodeSix = "";
			if(checkCode.length()>6){
				checkCodeSix = checkCode.substring(checkCode.length()-6);
			}
			if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(checkCode)) {
				if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
					if("".equals(priceWithoutTax)){
						priceWithoutTax = "0.00";
					}
					if("".equals(taxIncludedPrice)){
						taxIncludedPrice = "0.00";
					}

					String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
							   " tax,taxIncludedPrice,authenticity,checkStatus,checkcode,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,invoiceTypeTrue,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
							0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,0,checkCode,
							user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

					invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
					//插入日志
					//生成发票文档
					ImageDocUtil.updateImageDocId(invoiceData[3]);
					Map<String, String> labelIdMap = new HashMap<String, String>();
					Map<String, String> beforeMap = new HashMap<String, String>();
					Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
					fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
							beforeMap,afterMap,labelIdMap);
				}

				jsonObject.put("invoiceId", invoiceData[3]);
				jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
				jsonObject.put("number", invoiceNumber);
				jsonObject.put("flag", true);
				jsonObject.put("status", 1);

				return jsonObject;
			}else{
 				String result = "01,10," + invoiceCode + "," + invoiceNumber
						+ "," + priceWithoutTax + ","
						+ billingDate.replaceAll("-", "") + ","
						+ checkCode.replace(checkCode.substring(0,14),"00000000000000") + ",1111,";
				bb.writeLog("invoiceCheck-result:", result);
				FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
				JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
				int checkstatus = resultObj.getInt("status");
				if (checkstatus == 0) {//验票失败
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
							   " tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,checkCode,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,invoiceTypeTrue,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
								0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,3,
									user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,checkCode,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);


						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						//插入日志
						//生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{
						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,3,invoiceData[3]);
						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}

					jsonObject.put("flag", true);
					jsonObject.put("status", 2);
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
					jsonObject.put("number", invoiceNumber);
					jsonObject.put("invoiceId", invoiceData[3]);
					return jsonObject;
				}else{//更新发票记录
					String purchaser = resultObj.getString("_purchaser");
					String _purchaserTaxNo = resultObj.getString("_purchaserTaxNo");
					String seller = resultObj.getString("_seller");
					String _salesTaxNo = resultObj.getString("_salesTaxNo");//销售方纳税人识别号
					String taxRate = Util.getDoubleValue(resultObj.getString("_taxRate"),0.00)+"";
					String tax = Util.getDoubleValue(resultObj.getString("_tax"),0.00)+"";
					String _priceWithoutTax = resultObj.getString("_priceWithoutTax");
					String _invoiceServiceYype = resultObj.getString("_invoiceServiceYype");
					String _billingDate1 = resultObj.getString("_billingDate");
					String _taxIncludedPrice = resultObj.getString("_taxIncludedPrice");
					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");
					JSONArray detaildata = resultObj.getJSONArray("detaildata");
					//判断纳税人识别号是否维护
					boolean protectInvoiceTaxpayerNumber = FnaInvoiceCommon.protectInvoiceTaxpayerNumber(purchaser,_purchaserTaxNo);
					if(!protectInvoiceTaxpayerNumber){
						if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
							String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
									+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
							rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,invoiceTypeTrue,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
									_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,3,user.getUID(),imageID,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
							invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


							//保存FnaInvoiceLedgerDtl表信息
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

							//生成发票文档
							ImageDocUtil.updateImageDocId(invoiceData[3]);
							//插入日志
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = new HashMap<String, String>();
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);

						}else{

							//插入日志1
							Map<String, String> labelIdMap = new HashMap<String, String>();
							Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

							rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=?,checkStatus=?,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
									"checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
									,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,AUTHENTICITY_UNDETERMINED,3,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
									_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);

							InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);
							//保存FnaInvoiceLedgerDtl表信息
							InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);


							//插入日志2
							Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
							fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
									beforeMap,afterMap,labelIdMap);
						}
						jsonObject.put("flag", true);
						jsonObject.put("status", 2);
						jsonObject.put("seller", seller);
						jsonObject.put("invoiceId", invoiceData[3]);
						jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
						jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(_taxIncludedPrice)));
						jsonObject.put("number", invoiceNumber);
						return jsonObject;
					}
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = "insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,salesTaxNo,purchaser,purchaserTaxNo,"
								+ "invoiceServiceYype,priceWithoutTax,taxRate,tax,taxIncludedPrice,authenticity,checkStatus,userid_new,imageID,checkCode,status,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice,_billingDate1,invoiceCode,invoiceNumber,invoiceTypeTrue,seller,_salesTaxNo,purchaser,_purchaserTaxNo,
								_invoiceServiceYype,_priceWithoutTax,taxRate,tax,df.format(Util.getDoubleValue(_taxIncludedPrice,0.00)),AUTHENTICITY_TRUE,1,user.getUID(),imageID,checkCode,FnaInvoiceCommon.INIT_STATUS,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);
						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);


						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);

                        //生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{

						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

						rs.executeUpdate("update fnaInvoiceLedger set tax=?,taxIncludedPrice=?,billingDate=?,purchaser=?,seller=?,authenticity=1,checkStatus=1,taxRate=?,priceWithoutTax=?,invoiceServiceYype=?,"+
										"checkCode=?,salesTaxNo=?,purchaserTaxNo=? where invoiceNumber=? and invoiceCode=? "
								,tax,_taxIncludedPrice,_billingDate1, purchaser,seller,taxRate,_priceWithoutTax,_invoiceServiceYype,checkCode,
								_salesTaxNo,_purchaserTaxNo,invoiceNumber,invoiceCode);
						rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid=?",invoiceData[3]);
						InvoiceUtil.saveVATInvoiceDetail(detaildata,invoiceData[3]);

						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,checkCodeSix,sellerAddress,purchaserAddress,salesBank,purchaserBank);


						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}
					jsonObject.put("flag", true);
					jsonObject.put("status", 0);
					jsonObject.put("seller", seller);
					jsonObject.put("invoiceId", invoiceData[3]);
					jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(_taxIncludedPrice)));
					jsonObject.put("number", invoiceNumber);
					return jsonObject;
				}
			}
		} else if("10104".equals(invoiceType)){//机动车销售统一发票
			if ("".equals(invoiceNumber) || "".equals(invoiceCode) || "".equals(billingDate) || "".equals(priceWithoutTax)) {
				if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
					if("".equals(priceWithoutTax)){
						priceWithoutTax = "0.00";
					}
					if("".equals(taxIncludedPrice)){
						taxIncludedPrice = "0.00";
					}

					String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
							" tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
					rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,MOTORVEHICLESALES_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
							0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_UNDETERMINED,0,
							user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

					invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
                    //生成发票文档
					ImageDocUtil.updateImageDocId(invoiceData[3]);
                    //插入日志
                    Map<String, String> labelIdMap = new HashMap<String, String>();
                    Map<String, String> beforeMap = new HashMap<String, String>();
                    Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
                    fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
                            beforeMap,afterMap,labelIdMap);
				}

				jsonObject.put("invoiceId", invoiceData[3]);
				jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
				jsonObject.put("flag", true);
				jsonObject.put("status", 1);
				return jsonObject;
			}else{
				String result = "01,01," + invoiceCode + "," + invoiceNumber
						+ "," + priceWithoutTax
						+ "," + billingDate.replaceAll("-", "")
						+ ",,1111,";
				bb.writeLog("invoiceCheck-result:", result);
				FnaAbstractInterface fnaAbstractInterface = new FnaInvoiceCommon().getInterface(user);
				JSONObject resultObj = fnaAbstractInterface.scanQRCodeCheck("0", result,null);
				int checkstatus = resultObj.getInt("status");
				if (checkstatus == 0) {//验票失败
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String insertInvoice = " insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,invoiceServiceYype,priceWithoutTax,taxRate,"+
								" tax,taxIncludedPrice,authenticity,checkStatus,userid_new,status,imageID,invoiceSource_new,entryTime) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(insertInvoice, billingDate,invoiceCode,invoiceNumber,MOTORVEHICLESALES_TYPE,Constants.INVOICETYPE.get(invoiceType),priceWithoutTax,
								0.00,0.00,df.format(Util.getDoubleValue(taxIncludedPrice,0.00)),AUTHENTICITY_FALSE,3,
								user.getUID(),FnaInvoiceCommon.INIT_STATUS,imageID,FnaInvoiceCommon.INVOICESOURCE_OCR,entryTime);

						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						//生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
                        //插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{
						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						rs.executeUpdate("update fnaInvoiceLedger set authenticity=?,checkStatus=? where id=?",AUTHENTICITY_FALSE,3,invoiceData[3]);
						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}

					jsonObject.put("flag", true);
					jsonObject.put("status", 2);
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
					jsonObject.put("number", invoiceNumber);
					jsonObject.put("invoiceId", invoiceData[3]);
					return jsonObject;
				}else{//更新发票记录
					//获取发票信息
                    String taxIncludedPriceTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxIncludedPrice"),0.00));
                    String priceWithoutTaxTrue = df.format(Util.getDoubleValue(resultObj.getString("_priceWithoutTax"),0.00));
                    String taxTrue = df.format(Util.getDoubleValue(resultObj.getString("_tax"),0.00));
                    String taxRateTrue = df.format(Util.getDoubleValue(resultObj.getString("_taxRate"),0.00));
					String invoiceNumberTrue = resultObj.getString("_invoiceNumber");
					String invoicecodeTrue = resultObj.getString("_invoicecode");
					String purchaserTrue = resultObj.getString("_purchaser");
					String sellerTrue = resultObj.getString("_seller");
					String purchaserTaxNoTrue = resultObj.getString("_purchaserTaxNo");
					String salesTaxNoTrue = resultObj.getString("_salesTaxNo");
					String billingDateTrue = resultObj.getString("_billingDate");

					String remark = resultObj.getString("_remark");
					String sellerAddress = resultObj.getString("_sellerAddress");
					String purchaserAddress = resultObj.getString("_purchaserAddress");
					String salesBank = resultObj.getString("_salesBank");
					String purchaserBank = resultObj.getString("_purchaserBank");

					//机动车销售统一发票明细信息
					String machine_code = resultObj.getString("_machine_code");
					String machine_number = resultObj.getString("_machine_number");
					String tax_authorities = resultObj.getString("_tax_authorities");
					String tax_authorities_code = resultObj.getString("_tax_authorities_code");
					String car_code = resultObj.getString("_car_code");
					String car_engine_code = resultObj.getString("_car_engine_code");
					String car_model = resultObj.getString("_car_model");
					String certificate_number = resultObj.getString("_certificate_number");
					if (INVOICE_NOT_EXISTS.equals(invoiceData[3])) {
						String sql="insert into fnaInvoiceLedger (billingDate,invoiceCode,invoiceNumber,invoiceType,seller,purchaser,salesTaxNo,purchaserTaxNo,"+
								"invoiceServiceYype,priceWithoutTax,tax,taxRate,taxIncludedPrice,authenticity,checkStatus,"+
								"userid_new,invoiceSource_new,status,entryTime,imageID)"+
								"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
						rs.executeUpdate(sql,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,MOTORVEHICLESALES_TYPE,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
								"",priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,
								user.getUID(), FnaInvoiceCommon.INVOICESOURCE_OCR,0,entryTime,imageID);
						invoiceData = getInvoiceData(invoiceNumber,invoiceCode);
						rs.executeUpdate("insert into motor_VehicleInvoice (mainid,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?)",
								invoiceData[3],machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(0,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

						//插入明细
						InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceData[3],0),Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");

                        //生成发票文档
						ImageDocUtil.updateImageDocId(invoiceData[3]);
						//插入日志
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = new HashMap<String, String>();
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"0",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}else{

						//插入日志1
						Map<String, String> labelIdMap = new HashMap<String, String>();
						Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);

						rs.executeUpdate("update fnaInvoiceLedger set billingDate=?,invoiceCode=?,invoiceNumber=?,invoiceType=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?," +
										"priceWithoutTax=?,tax=?,taxRate=?,taxIncludedPrice=?,authenticity=?,checkStatus=? where id=?"
								,billingDateTrue,invoicecodeTrue,invoiceNumberTrue,MOTORVEHICLESALES_TYPE,sellerTrue,purchaserTrue,salesTaxNoTrue,purchaserTaxNoTrue,
								priceWithoutTaxTrue,taxTrue,taxRateTrue,taxIncludedPriceTrue,1,1,invoiceData[3]);
						rs.executeQuery("select 1 from motor_VehicleInvoice where mainid=?",invoiceData[3]);
						if(rs.next()){
							rs.executeUpdate("update motor_VehicleInvoice set machine_code=?,machine_number=?,tax_authorities=?,tax_authorities_code=?,car_code=?,car_engine_code=?,car_model=?,certificate_number=? where mainid=?",
									machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number,invoiceData[3]);

						}else{
							rs.executeUpdate("insert into motor_VehicleInvoice (mainid,machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number) values(?,?,?,?,?,?,?,?,?)",
									invoiceData[3],machine_code,machine_number,tax_authorities,tax_authorities_code,car_code,car_engine_code,car_model,certificate_number);

						}

						//保存FnaInvoiceLedgerDtl表信息
						InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1,Util.getIntValue(invoiceData[3],0),remark,"",sellerAddress,purchaserAddress,salesBank,purchaserBank);

						//插入明细
						InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceData[3],0),Constants.INVOICESERVICEYYPE.get(invoiceType),priceWithoutTaxTrue,taxRateTrue,taxTrue,1,priceWithoutTaxTrue,priceWithoutTaxTrue,"","");


						//插入日志2
						Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceData[3],labelIdMap);
						fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceData[3],"1",
								beforeMap,afterMap,labelIdMap);
					}
					jsonObject.put("flag", true);
					jsonObject.put("status", 0);
					jsonObject.put("seller", sellerTrue);
					jsonObject.put("invoiceId", invoiceData[3]);
					jsonObject.put("description", Constants.INVOICETYPE.get(invoiceType));
					jsonObject.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPriceTrue)));
					jsonObject.put("number", invoiceNumber);
					return jsonObject;
				}
			}
		}
		return null;
	}

	/**
	 * 发票删除
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject deleteInvoice(FileUpload fu,User user,String ipAdress) throws Exception{
		String id = Util.null2String(fu.getParameter("id"));
		RecordSet rs = new RecordSet();
		checkInvoiceBelongs(user,id);
		String type = "0";
		rs.executeQuery("select invoiceType,status from fnainvoiceledger where id = ?", id);
		if(rs.next()){
			type = Util.null2String(rs.getString("invoiceType"));
		}
		String msg = FnaInvoiceCommon.canDeleteInvoice(false, user, id);
		if(!"".equals(msg)){
			throw new Exception(msg);
		}

		//插入日志
		Map<String, String> labelIdMap = new HashMap<String, String>();
		Map<String, String> beforeMap =fnaLogSqlUtil.getInvoiceMap(id,labelIdMap);
		Map<String, String> afterMap = new HashMap<String, String>();
		fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"1",id,"0",
				beforeMap,afterMap,labelIdMap);
		
		int imageDocId = 0;
        rs.executeQuery("select * from fnainvoiceledger where id=?",id);
        if(rs.next()){
            imageDocId = Util.getIntValue(rs.getString("imageDocId"),0);
        }
        
        if(imageDocId > 0) {
        	DocExtUtil docExtUtil = new DocExtUtil();
        	docExtUtil.deleteDoc(imageDocId);
        }

		String deleteSql = "";
		String deleteSqlDtl = "";
		if(VAT_ORDINARY_TYPE.equals(type) || VAT_SPECIAL_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type) || VAT_Electronic_Tolls_Type.equals(type) || MOTORVEHICLESALES_TYPE.equals(type)
				 || VAT_Electronic_SPECIAL_Type.equals(type) ){//增值税发票
			deleteSql = "delete from FnaInvoiceLedgerDtl where mainid = ?";
		}else if(MOTORVEHICLESALES_TYPE.equals(type)){//机动车销售统一发票
			deleteSql = "delete from motor_VehicleInvoice where mainid = ?";
		}else if(USEDCARSALES_TYPE.equals(type)){//二手车销售统一发票
			deleteSql = "delete from second_carInvoice where mainid = ?";
		}else if(QUOTA_TYPE.equals(type)){//定额发票
		}else if(GENERALMACHINE_TYPE.equals(type)){//机打发票
			deleteSql = "delete from machineInvoice where mainid = ?";
		}else if(TAXI_TYPE.equals(type)){//出租车发票
			deleteSql = "delete from taxiInvoice where mainid = ?";
		}else if(TRAIN_TYPE.equals(type)){//火车票
			deleteSql = "delete from trainInvoice where mainid = ?";
		}else if(PASSENGERTICKET_TYPE.equals(type)){//客运汽车
			deleteSql = "delete from carInvoice where mainid = ?";
		}else if(AIRTRANSPORTTICKET_TYPE.equals(type)){//航空运输电子客票行程单
			deleteSql = "delete from airInvoice where mainid = ?";
			deleteSqlDtl = "delete from airDtlInvoice where mainid = ?";
		}else if(TOLLS_TYPE.equals(type)){//过路费发票
			deleteSql = "delete from tollInvoice where mainid = ?";
		}
		if(!"".equals(deleteSql)){
			rs.executeUpdate(deleteSql, id);
		}
		if(!"".equals(deleteSqlDtl)){
			rs.executeUpdate(deleteSqlDtl, id);
		}

		rs.executeUpdate("delete from FnaInvoiceLedgerDetail where mainid = ?",id);
		rs.executeUpdate("delete from fnainvoiceLedger where id = ?", id);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("flag", true);
		return jsonObject;
	}

	/**
	 * randomInvoiceNumber
	 * @return
	 */
	public static String randomInvoiceNumber(){
		int[] number = new int[]{0,1,2,3,4,5,6,7,8,9};
		StringBuffer invoicenumber = new StringBuffer();
		for(int i = 0;i<8;i++){
			invoicenumber.append(number[new Random().nextInt(10)]);
		}
		return invoicenumber.toString();
	}

	/**
	 * 判断发票是否属于本人
	 * @param user
	 * @param invoiceId
	 * @throws Exception
	 */
	private static void checkInvoiceBelongs(User user,String invoiceId) throws Exception{
		RecordSet rs = new RecordSet();
		int userid = user.getUID();
		rs.executeQuery("select * from fnainvoiceLedger where id = ? and userid_new = ?", invoiceId,userid);
		if(rs.getCounts()==0){
			throw new Exception(SystemEnv.getHtmlLabelName(509486, user.getLanguage()));//非本人的发票无法操作!
		}
	}

	/**
	 * 判断发票是否属于本人
	 * @param user
	 * @param invoiceId
	 * @return
	 */
	public static boolean checkBooleanInvoiceBelongs(User user,String invoiceId){
		try {
			checkInvoiceBelongs(user,invoiceId);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/**
	 * 发票保存
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject saveInvoice(FileUpload fu,User user,String ipAdress) throws Exception{
		String type = Util.null2String(fu.getParameter("type"));
		String invoiceid = Util.null2String(fu.getParameter("invoiceid"));
		checkInvoiceBelongs(user,invoiceid);

        RecordSet rs = new RecordSet();
        int status = 0;
        rs.executeQuery("select status from fnainvoiceLedger where id = ?", invoiceid);
        if(rs.next()){
        	status = Util.getIntValue(rs.getString("status"));
        }
        if(status!=0) {
        	throw new Exception(SystemEnv.getHtmlLabelName(536451, user.getLanguage()));
        }
		//去重校验控制逻辑
		int workflowlogic = ReimbursementUtil.getWorkflowlogic();
		if(workflowlogic==3) {
			rs.executeQuery("select 1 from FnaInvoiceReimbursement where mainid = ?", invoiceid);
			if(rs.next()) {
	        	throw new Exception(SystemEnv.getHtmlLabelName(536451, user.getLanguage()));
			}
		}
		
		String billingDate = Util.null2String(fu.getParameter("billingDate"));
		String taxIncludedPrice = Util.null2String(fu.getParameter("taxIncludedPrice"));
		taxIncludedPrice = df.format(Util.getDoubleValue(taxIncludedPrice,0.00));
		String invoiceNumber = Util.null2String(fu.getParameter("invoiceNumber"));
		String invoiceCode_check = Util.null2String(fu.getParameter("invoiceCode"));
		if(!INTERNATIONAL_RECEIPTS.equals(type)){
			rs.executeQuery("select 1 from fnainvoiceLedger where invoicenumber = ? and invoiceCode= ? and id <> ?", invoiceNumber,invoiceCode_check,invoiceid);
			if(rs.next()){
				throw new Exception(SystemEnv.getHtmlLabelName(509492, user.getLanguage()));//已存在发票号码相同的发票!
			}
		}

		//插入日志1
		Map<String, String> labelIdMap = new HashMap<String, String>();
		Map<String, String> beforeMap = fnaLogSqlUtil.getInvoiceMap(invoiceid,labelIdMap);
		if(VAT_ORDINARY_TYPE.equals(type) || VAT_SPECIAL_TYPE.equals(type) || VAT_Electronic_Type.equals(type) || VAT_ORDINARY_Volume_TYPE.equals(type)  || VAT_Electronic_Tolls_Type.equals(type)
				|| VAT_Electronic_SPECIAL_Type.equals(type) ){//增值税发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			double priceWithoutTax = Util.getDoubleValue(Util.null2String(fu.getParameter("priceWithoutTax")),0.00);
			String seller = Util.null2String(fu.getParameter("seller"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			//ocr增加字段

			double totalAmount= Util.getDoubleValue(taxIncludedPrice,0.00);
			boolean needCheck = InvoiceUtil.whetherNeedCheck(totalAmount);

			if(InvoiceUtil.ifExistsInterface(user) && needCheck){
				String update = "update FnaInvoiceLedger set billingDate = ?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,priceWithoutTax=?,seller=?,purchaser=? where id = ?";
				rs.executeUpdate(update, billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,df.format(priceWithoutTax),seller,purchaser,invoiceid);

				//插入明细
				InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

			}else{
				String salesTaxNo = Util.null2String(fu.getParameter("salesTaxNo"));
				String purchaserTaxNo = Util.null2String(fu.getParameter("purchaserTaxNo"));
				String checkCode = Util.null2String(fu.getParameter("checkCode"));
				String category = Util.null2String(fu.getParameter("category"));//种类
				String kind = Util.null2String(fu.getParameter("kind"));//发票消费类型
				String tax = Util.null2String(fu.getParameter("tax"));
				String taxRate = Util.null2String(fu.getParameter("taxRate"));
//				String company_seal = Util.null2String(fu.getParameter("company_seal"));//是否有公司印章
				String form_type = Util.null2String(fu.getParameter("form_type"));//发票是第几联
				String form_name = Util.null2String(fu.getParameter("form_name"));//发票联次
				String ciphertext = Util.null2String(fu.getParameter("ciphertext"));//密码区
				String update = " update FnaInvoiceLedger set billingDate = ?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,priceWithoutTax=?," +
						" seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=?,checkCode=?,category=?,kind=?,tax=?,taxRate=?," +
						" form_type=?,form_name=?,ciphertext=? where id = ?";
				rs.executeUpdate(update, billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,priceWithoutTax,
						  seller,purchaser,salesTaxNo,purchaserTaxNo,checkCode,category,kind,tax,taxRate,
						  form_type,form_name,ciphertext,invoiceid);

				//插入明细
				InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(priceWithoutTax),taxRate,tax,1,df.format(priceWithoutTax),df.format(priceWithoutTax),"","");

			}
		}else if(MOTORVEHICLESALES_TYPE.equals(type)){//机动车销售统一发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			double priceWithoutTax = Util.getDoubleValue(Util.null2String(fu.getParameter("priceWithoutTax")),0.00);
			String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00)-priceWithoutTax);
			String taxRate="0.00";
			if(priceWithoutTax!=0.00){
				taxRate = df.format((Util.getDoubleValue(tax,0.00)/priceWithoutTax)*100);
			}
			String seller = Util.null2String(fu.getParameter("seller"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			String update = "update FnaInvoiceLedger set billingDate = ?,taxIncludedPrice=?,invoiceNumber=?,invoiceCode=?,priceWithoutTax=?,tax=?,taxRate=?,seller=?,purchaser=? where id = ?";
			rs.executeUpdate(update, billingDate,taxIncludedPrice,invoiceNumber,invoiceCode,df.format(priceWithoutTax),tax,taxRate,seller,purchaser,invoiceid);
			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(priceWithoutTax),taxRate,tax,1,df.format(priceWithoutTax),df.format(priceWithoutTax),"","");

		}else if(USEDCARSALES_TYPE.equals(type)){//二手车销售统一发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String seller_id=Util.null2String(fu.getParameter("seller_id"));
			String buyer_id=Util.null2String(fu.getParameter("buyer_id"));
			String company_name=Util.null2String(fu.getParameter("company_name"));
			String company_tax_id=Util.null2String(fu.getParameter("company_tax_id"));
			String license_plate=Util.null2String(fu.getParameter("license_plate"));
			String registration_number=Util.null2String(fu.getParameter("registration_number"));
			String car_code=Util.null2String(fu.getParameter("car_code"));
			String car_model=Util.null2String(fu.getParameter("car_model"));

			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=? where id=? "
					, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,invoiceid);

			rs.executeQuery("select 1 from second_carInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update second_carInvoice set seller_id=?,buyer_id=?,company_name=?,"+
								" company_tax_id=?,license_plate=?,registration_number=?,car_code=?,car_model=? where mainid=? ",
						StringEscapeUtils.escapeSql(seller_id),StringEscapeUtils.escapeSql(buyer_id),StringEscapeUtils.escapeSql(company_name),
						company_tax_id,license_plate,registration_number,car_code,car_model,invoiceid);
			}else{
				String insertSecond_car = " insert into second_carInvoice(mainid,seller_id,buyer_id,company_name,"+
						" company_tax_id,license_plate,registration_number,car_code,car_model) values(?,?,?,?,?,?,?,?,?)";
				rs.executeUpdate(insertSecond_car, invoiceid,seller_id,buyer_id,company_name,company_tax_id,license_plate,registration_number,car_code,car_model);
			}
			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

		}else if(QUOTA_TYPE.equals(type)){//定额发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			billingDate = "";
			String kind = Util.null2String(fu.getParameter("kind"));

			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=? where id=? "
					, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,kind,invoiceid);
			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

		}else if(GENERALMACHINE_TYPE.equals(type)){//机打发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String seller = Util.null2String(fu.getParameter("seller"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			String checkCode = Util.null2String(fu.getParameter("checkCode"));
			String time= Util.null2String(fu.getParameter("time"));
			String category=Util.null2String(fu.getParameter("category"));
			String salesTaxNo=Util.null2String(fu.getParameter("salesTaxNo"));
			String purchaserTaxNo=Util.null2String(fu.getParameter("purchaserTaxNo"));
			String kind = Util.null2String(fu.getParameter("kind"));
			String sellerAddress = Util.null2String(fu.getParameter("sellerAddress"));
			String purchaserAddress = Util.null2String(fu.getParameter("purchaserAddress"));
			String salesBank = Util.null2String(fu.getParameter("salesBank"));
			String purchaserBank = Util.null2String(fu.getParameter("purchaserBank"));
			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,seller=?,purchaser=?,checkCode=?,kind=?,category=?,salesTaxNo=?,purchaserTaxNo=? where id=? "
                    , invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,seller, purchaser,checkCode,kind,category,salesTaxNo,purchaserTaxNo,invoiceid);

			rs.executeQuery("select 1 from machineInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update machineInvoice set time=?,category=?,seller_tax_id=?,buyer_tax_id=? where mainid=? ",
						StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(category),StringEscapeUtils.escapeSql(salesTaxNo),
						StringEscapeUtils.escapeSql(purchaserTaxNo),invoiceid);
			}else{
				String insertMachine = "insert into machineInvoice(mainid,time,category,seller_tax_id,buyer_tax_id) values(?,?,?,?,?)";
				rs.executeUpdate(insertMachine, invoiceid,time,category,salesTaxNo,purchaserTaxNo);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
			InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceid,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);

		}else if(TAXI_TYPE.equals(type)){//出租车发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String time_geton=Util.null2String(fu.getParameter("time_geton"));
			String time_getoff=Util.null2String(fu.getParameter("time_getoff"));
			String mileage=Util.null2String(fu.getParameter("mileage"));
			String kind = Util.null2String(fu.getParameter("kind"));
			String place = Util.null2String(fu.getParameter("place"));

			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=? where id=? "
					, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,kind,invoiceid);
			rs.executeQuery("select 1 from taxiInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update taxiInvoice set time_geton=?,time_getoff=?,mileage=?,place=? where mainid=? ",
						StringEscapeUtils.escapeSql(time_geton),StringEscapeUtils.escapeSql(time_getoff),
						StringEscapeUtils.escapeSql(mileage),StringEscapeUtils.escapeSql(place),invoiceid);
			}else{
				String insertTaxi = "insert into taxiInvoice(mainid,time_geton,time_getoff,mileage,place) values(?,?,?,?,?)";
				rs.executeUpdate(insertTaxi, invoiceid, time_geton, time_getoff, mileage,place);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

		}else if(TRAIN_TYPE.equals(type)){//火车票
			String time=Util.null2String(fu.getParameter("time"));
			String name=Util.null2String(fu.getParameter("name"));
			String station_geton=Util.null2String(fu.getParameter("station_geton"));
			String station_getoff=Util.null2String(fu.getParameter("station_getoff"));
			String train_number=Util.null2String(fu.getParameter("train_number"));
			String seat=Util.null2String(fu.getParameter("seat"));
			String kind = Util.null2String(fu.getParameter("kind"));
			//计算进项税额
			String taxRate="9";
			String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00) / (1+0.09) * 0.09);
			if("".equals(name)){
				tax = "0.00";
				taxRate="0";
			}
			String pricewithouttax = df.format(Util.getDoubleValue(taxIncludedPrice)-Util.getDoubleValue(tax));

			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=?,tax=?,taxRate=?,pricewithouttax=? where id=? "
					, invoiceNumber,invoiceNumber,billingDate,taxIncludedPrice,kind,tax,taxRate,pricewithouttax,invoiceid);

			rs.executeQuery("select 1 from trainInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update trainInvoice set time=?,name=?,station_geton=?,station_getoff=?,train_number=?,seat=? where mainid=? ",
						StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(name),
						StringEscapeUtils.escapeSql(station_geton),StringEscapeUtils.escapeSql(station_getoff),
						StringEscapeUtils.escapeSql(train_number),StringEscapeUtils.escapeSql(seat),invoiceid);
			}else{
				String insertTrain = "insert into trainInvoice(mainid,time,name,station_geton,station_getoff,train_number,seat) values(?,?,?,?,?,?,?)";
				rs.executeUpdate(insertTrain, invoiceid, time, name, station_geton, station_getoff, train_number, seat);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

		}else if(PASSENGERTICKET_TYPE.equals(type)){//客运汽车
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String time=Util.null2String(fu.getParameter("time"));
			String station_geton=Util.null2String(fu.getParameter("station_geton"));
			String station_getoff=Util.null2String(fu.getParameter("station_getoff"));
			String name=Util.null2String(fu.getParameter("name"));
			String kind = Util.null2String(fu.getParameter("kind"));
			//计算进项税额
			String taxRate="3";
			String tax = df.format(Util.getDoubleValue(taxIncludedPrice,0.00) / (1+0.03) * 0.03);
			if("".equals(name)){
				tax = "0.00";
				taxRate="0";
			}
			String pricewithouttax = df.format(Util.getDoubleValue(taxIncludedPrice)-Util.getDoubleValue(tax));

			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=?,tax=?,taxRate=?,pricewithouttax=? where id=? "
					, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,kind,tax,taxRate,pricewithouttax,invoiceid);

			rs.executeQuery("select 1 from carInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update carInvoice set time=?,name=?,station_geton=?,station_getoff=? where mainid=? ",
						StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(name),
						StringEscapeUtils.escapeSql(station_geton),StringEscapeUtils.escapeSql(station_getoff),invoiceid);
			}else{
				String insertCar = "insert into carInvoice(mainid,time,station_geton,station_getoff,name) values(?,?,?,?,?)";
				rs.executeUpdate(insertCar, invoiceid,time,station_geton,station_getoff,name);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

		}else if(AIRTRANSPORTTICKET_TYPE.equals(type)){//航空运输电子客票行程单
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String user_name=Util.null2String(fu.getParameter("user_name"));
			String user_id=Util.null2String(fu.getParameter("user_id"));
			String agentcode=Util.null2String(fu.getParameter("agentcode"));
			String issue_by=Util.null2String(fu.getParameter("issue_by"));
			String fare=Util.null2String(fu.getParameter("fare"));
			String fuel_surcharge=Util.null2String(fu.getParameter("fuel_surcharge"));
			String caac_development_fund=Util.null2String(fu.getParameter("caac_development_fund"));
			String insurance=Util.null2String(fu.getParameter("insurance"));
			String check_code=Util.null2String(fu.getParameter("check_code"));
			String kind=Util.null2String(fu.getParameter("kind"));
			//计算进项税额
			String taxRate="9";
			String tax = df.format((Util.getDoubleValue(fare,0.00) + Util.getDoubleValue(fuel_surcharge,0.00)) / (1+0.09) * 0.09);
			if("".equals(user_name)){
				tax = "0.00";
				taxRate="0";
			}
			String pricewithouttax = df.format(Util.getDoubleValue(taxIncludedPrice)-Util.getDoubleValue(tax));
			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,checkCode=?,kind=?,tax=?,taxRate=?,pricewithouttax=? where id=? "
					, invoiceNumber, invoiceNumber, billingDate, taxIncludedPrice,check_code,kind,tax,taxRate,pricewithouttax,invoiceid);
			rs.executeQuery("select 1 from airInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update airInvoice set user_name=?,user_id=?,agentcode=?,issue_by=?,fare=?,fuel_surcharge=?,caac_development_fund=?,insurance=? where mainid=? ",
						StringEscapeUtils.escapeSql(user_name),StringEscapeUtils.escapeSql(user_id),
						StringEscapeUtils.escapeSql(agentcode),StringEscapeUtils.escapeSql(issue_by),fare,fuel_surcharge,caac_development_fund,insurance,invoiceid);
			}else{
				String insertAir = "insert into airInvoice(mainid,user_name,user_id,agentcode,issue_by,fare,fuel_surcharge,caac_development_fund,insurance) values(?,?,?,?,?,?,?,?,?)";
				rs.executeUpdate(insertAir, invoiceid,user_name,user_id,agentcode,issue_by,fare,fuel_surcharge,caac_development_fund,insurance);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),taxRate,tax,1,df.format(Util.getDoubleValue(pricewithouttax, 0.00)),df.format(Util.getDoubleValue(pricewithouttax, 0.00)),"","");

		}else if(TOLLS_TYPE.equals(type)){//过路费发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String time=Util.null2String(fu.getParameter("time"));
			String entrance=Util.null2String(fu.getParameter("entrance"));
			String exit=Util.null2String(fu.getParameter("exit"));
			String kind=Util.null2String(fu.getParameter("kind"));


			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=? where id=? "
					, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,kind,invoiceid);

			rs.executeQuery("select 1 from tollInvoice where mainid = ?", invoiceid);
			if(rs.next()){
				rs.executeUpdate("update tollInvoice set time=?,entrance=?,export=? where mainid=? ",
						StringEscapeUtils.escapeSql(time),StringEscapeUtils.escapeSql(entrance),
						StringEscapeUtils.escapeSql(exit),invoiceid);
			}else{
				String insertToll = "insert into tollInvoice(mainid,time,entrance,export) values(?,?,?,?)";
				rs.executeUpdate(insertToll, invoiceid,time,entrance,exit);
			}

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

		}else if(INTERNATIONAL_RECEIPTS.equals(type)){//国际小票
			double priceWithoutTax = Util.getDoubleValue(Util.null2String(fu.getParameter("priceWithoutTax")),0.00);
			String tax = Util.null2String(fu.getParameter("tax"));
			String storename = Util.null2String(fu.getParameter("storename"));
			String time = Util.null2String(fu.getParameter("time"));
			String discount = Util.null2String(fu.getParameter("discount"));
			String tips = Util.null2String(fu.getParameter("tips"));
			String currency_code = Util.null2String(fu.getParameter("currency_code"));
			String xftype = Util.null2String(fu.getParameter("xftype"));
			rs.executeUpdate("update fnainvoiceledger set billingDate=?,taxIncludedPrice=?,priceWithoutTax=?,tax=? where id = ?", 
					billingDate,taxIncludedPrice,df.format(priceWithoutTax),tax,invoiceid);
			rs.executeUpdate("update smallInvoice set storename=?,time=?,discount=?,tips=?,currency_code=?,type=? where mainid = ?",
					storename,time,discount,tips,currency_code,xftype,invoiceid);

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");

		}else if(OTHERS_TYPE.equals(type)) {//可报销的其他发票
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String kind=Util.null2String(fu.getParameter("kind"));
			String seller = Util.null2String(fu.getParameter("seller"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			String salesTaxNo = Util.null2String(fu.getParameter("salesTaxNo"));
			String purchaserTaxNo = Util.null2String(fu.getParameter("purchaserTaxNo"));

			String sellerAddress = Util.null2String(fu.getParameter("sellerAddress"));
			String purchaserAddress = Util.null2String(fu.getParameter("purchaserAddress"));
			String salesBank = Util.null2String(fu.getParameter("salesBank"));
			String purchaserBank = Util.null2String(fu.getParameter("purchaserBank"));
			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,kind=?,seller=?,purchaser=?,salesTaxNo=?,purchaserTaxNo=? where id=?",
					invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,kind,seller,purchaser,salesTaxNo,purchaserTaxNo,invoiceid);
			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
			InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceid,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
		}else if(TAX_CERTIFICATE_TYPE.equals(type)) {//完税证明
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			String purchaserTaxNo = Util.null2String(fu.getParameter("purchaserTaxNo"));
			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,purchaser=?,purchaserTaxNo=? where id=?",
					invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,purchaser,purchaserTaxNo,invoiceid);

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),taxIncludedPrice,"0.00","0.00",1,taxIncludedPrice,taxIncludedPrice,"","");
		}else if(BLOCKCHAIN_TYPE.equals(type)) {//区块链
			String invoiceCode = Util.null2String(fu.getParameter("invoiceCode"));
			double priceWithoutTax = Util.getDoubleValue(Util.null2String(fu.getParameter("priceWithoutTax")),0.00);
			String checkCode = Util.null2String(fu.getParameter("checkCode"));
			String purchaser = Util.null2String(fu.getParameter("purchaser"));
			String purchaserTaxNo = Util.null2String(fu.getParameter("purchaserTaxNo"));
			String seller = Util.null2String(fu.getParameter("seller"));
			String salesTaxNo = Util.null2String(fu.getParameter("salesTaxNo"));
			String kind = Util.null2String(fu.getParameter("kind"));
			String category = Util.null2String(fu.getParameter("category"));

			String sellerAddress = Util.null2String(fu.getParameter("sellerAddress"));
			String purchaserAddress = Util.null2String(fu.getParameter("purchaserAddress"));
			String salesBank = Util.null2String(fu.getParameter("salesBank"));
			String purchaserBank = Util.null2String(fu.getParameter("purchaserBank"));

			DecimalFormat dfTaxRate = new DecimalFormat("###0");
			double tax=Util.getDoubleValue(taxIncludedPrice,0)-priceWithoutTax;
			double taxRate =0.00;
			if(tax!=0 && priceWithoutTax!=0){
				taxRate = (tax/priceWithoutTax*100);
			}
			rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,priceWithoutTax=?,tax=?,taxRate=?,checkCode=?,purchaser=?,purchaserTaxNo=?," +
							" seller=?,salesTaxNo=?,kind=?,category=? where id=?",
					invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,df.format(priceWithoutTax),df.format(tax),dfTaxRate.format(taxRate),checkCode,purchaser,purchaserTaxNo,
					seller,salesTaxNo,kind,category,invoiceid);

			//插入明细
			InvoiceUtil.insertFnaInvoiceledgerDetail(Util.getIntValue(invoiceid,0),Constants.INVOICESERVICEYYPE.get(type),df.format(priceWithoutTax),dfTaxRate.format(taxRate),df.format(tax),1,df.format(priceWithoutTax),df.format(priceWithoutTax),"","");
			InvoiceUtil.updateInsertFnaInvoiceLedgerDtl(1, Util.getIntValue(invoiceid,0), "", "", sellerAddress, purchaserAddress, salesBank, purchaserBank);
		}

		//插入日志2
		Map<String, String> afterMap =fnaLogSqlUtil.getInvoiceMap(invoiceid,labelIdMap);
		fnaLogSqlUtil.invoiceLedgerAddlog(user,ipAdress,"2",invoiceid,"0",
				beforeMap,afterMap,labelIdMap);

		JSONObject jsonObject = new JSONObject();
		jsonObject.put("flag", true);
		jsonObject.put("billingDate", billingDate);
		jsonObject.put("taxIncludedPrice", taxIncludedPrice);
		jsonObject.put("invoiceNumber", invoiceNumber);
		return jsonObject;
	}

	/**
	 * 生成报销单
	 * @param fu
	 * @param user
	 * @return
	 * @throws Exception
	 */
	public static JSONObject addDetail(FileUpload fu,User user) throws Exception{
		int dindex = Util.getIntValue(fu.getParameter("dindex"),-99);
		int workflowid = Util.getIntValue(fu.getParameter("workflowid"),-1);
		if(dindex == -1 || workflowid == -1){
			throw new Exception(SystemEnv.getHtmlLabelName(509487, user.getLanguage()));//该流程未关联票据流程设置，请在后台【预算】-【发票管理】-【票据流程设置】中设置！
		}
		if(dindex == -2){
			dindex = -1;
		}
		dindex++;
		RecordSet rs = new RecordSet();
		String sql = "select fieldid from fnaInvoiceWfInfoField where workflowid = ? and tabindex = ? and fieldname = ? ";
		rs.executeQuery(sql, workflowid,dindex,"fieldIdInvoice");
		if(rs.getCounts() == 0){
			throw new Exception(SystemEnv.getHtmlLabelName(509488, user.getLanguage()).replace("${table}", 
							dindex==0?SystemEnv.getHtmlLabelName(21778, user.getLanguage()):SystemEnv.getHtmlLabelName(19325, user.getLanguage())+dindex));
			//"该流程关联的票据流程未设置："+(dindex==0?"主表":"明细表"+dindex)+"的发票号码字段对应！"
		}
		sql = "select fieldid,fieldname from fnaInvoiceWfInfoField where workflowid = ? and tabindex = ? ";
		rs.executeQuery(sql, workflowid,dindex);
		int fieldIdInvoice = 0;
		int fieldIdSubject = 0;
		int fieldIdAmount = 0;
		int fieldIdDate = 0;
		int fieldIdDesc = 0;
		while(rs.next()){
			int fieldid = Util.getIntValue(rs.getString("fieldid"));
			String fieldname = Util.null2String(rs.getString("fieldname"));
			if("fieldIdInvoice".equals(fieldname)){
				fieldIdInvoice = fieldid;
			}else if("fieldIdSubject".equals(fieldname)){
				fieldIdSubject = fieldid;
			}else if("fieldIdAmount".equals(fieldname)){
				fieldIdAmount = fieldid;
			}else if("fieldIdDate".equals(fieldname)){
				fieldIdDate = fieldid;
			}else if("fieldIdDesc".equals(fieldname)){
				fieldIdDesc = fieldid;
			}
		}
		String invoiceIds = Util.null2String(fu.getParameter("invoiceIds"));
		StringBuffer msgBuffer = new StringBuffer();
		StringBuffer indexBuffer = new StringBuffer();
		String[] ids = invoiceIds.split(",");
		int idsLen = ids.length;
		ResourceComInfo rci = new ResourceComInfo();
		for(int i = 0;i<idsLen;i++){
			String id = ids[i];
			if(!checkBooleanInvoiceBelongs(user, id) && !InvoiceSharerUtil.checkInvoiceShare(id, user.getUID())){
				rs.executeQuery("select invoiceNumber,userid_new from fnainvoiceledger where id = ?", id);
				String invoiceNumber = "";
				String userid_new = "";
				if(rs.next()){
					invoiceNumber = Util.null2String(rs.getString("invoiceNumber"));
					userid_new = Util.null2String(rs.getString("userid_new"));
				}
				if(msgBuffer.length() > 0){
					msgBuffer.append("\n");
					indexBuffer.append(",");
				}
				indexBuffer.append(i);
				msgBuffer.append(SystemEnv.getHtmlLabelName(509491, user.getLanguage()).replace("${invoiceNumber}", invoiceNumber).
						replace("${lastname}", rci.getLastname(userid_new)));
				//"发票："+invoiceNumber+"的发票归属人为："+rci.getLastname(userid_new)+"，无法添加至流程！"
			}
		}
		JSONObject rtnJson = new JSONObject();
		rtnJson.put("flag", true);
		rtnJson.put("fieldindex", dindex);
		rtnJson.put("fieldIdInvoice", fieldIdInvoice);
		rtnJson.put("fieldIdSubject", fieldIdSubject);
		rtnJson.put("fieldIdAmount", fieldIdAmount);
		rtnJson.put("fieldIdDate", fieldIdDate);
		rtnJson.put("fieldIdDesc", fieldIdDesc);
		rtnJson.put("msgBuffer", msgBuffer.toString());
		rtnJson.put("indexBuffer", indexBuffer.toString());
		rtnJson.put("desc", getInvoiceOtherInfo(ids,user));
		return rtnJson;
	}

	/**
	 * 获取发票其他票面信息
	 * @param invoiceIds
	 * @return
	 */
	public  static JSONArray getInvoiceOtherInfo(String[] invoiceIds,User user){
		int idLen = invoiceIds.length;
		JSONArray jsonArray = new JSONArray();
		String subjectId = getPropertyValue("defaultSubjectId");
		BudgetfeeTypeComInfo btc = new BudgetfeeTypeComInfo();
		String subjectName = btc.getBudgetfeeTypename(subjectId);
		RecordSet rs = new RecordSet();
		int userId = user.getUID();
		for (int i =0;i<idLen;i++) {
			JSONObject json = new JSONObject();
			String id = invoiceIds[i];
			if("".equals(id)){
				continue;
			}
			String invoiceNumber = "";
			String billingDate = "";
			String taxIncludedPrice = "";
			String invoiceServiceYype="";//货物或应税服务类型
			int checkStatus=0;
			rs.executeQuery("select * from FnaInvoiceLedger where id=?", id);
			if (rs.next()) {
				invoiceNumber=Util.null2String(rs.getString("invoiceNumber"));
				billingDate=Util.null2String(rs.getString("billingDate"));
				taxIncludedPrice=Util.null2String(rs.getString("taxIncludedPrice"));
				checkStatus=Util.getIntValue(rs.getString("checkStatus"),0);
			}

			rs.executeQuery("select invoiceServiceYype from FnaInvoiceLedgerDetail where mainid = ? ", id);
			if(rs.next()){
				invoiceServiceYype=Util.null2String(rs.getString("invoiceServiceYype"));
			}
			new BaseBean().writeLog("invoiceServiceYype:"+invoiceServiceYype);
			if(!"".equals(invoiceServiceYype)) {
				rs.executeQuery("select b.id subjectId,b.name subjectName from FnaInvoiceSubject a " +
						"join FnaBudgetfeeType b on a.subjectid=b.id where a.invoiceServiceYype=?", invoiceServiceYype);
				if (rs.next()) {
					subjectId = Util.null2String(rs.getString("subjectId"));
					subjectName = Util.null2String(rs.getString("subjectName"));
				}
			}
			json.put("id", id);
			json.put("invoiceNumber", invoiceNumber);
			json.put("billingDate", billingDate);
			json.put("taxIncludedPrice", df.format(Util.getDoubleValue(taxIncludedPrice,0.00)));
			json.put("subjectId", subjectId);
			json.put("subjectName", subjectName);
			json.put("invoiceServiceYype", invoiceServiceYype);
			//添加至最近选择的科目
			addRecentlySubject(subjectId, userId);
			jsonArray.add(json);
		}
		return jsonArray;
	}


	/**
	 * 添加最新选择的科目
	 * @param subjectId
	 * @param userId
	 */
	private static void addRecentlySubject(String subjectId,int userId){
		RecordSet rs1 = new RecordSet();
		RecordSet rs2 = new RecordSet();
		String sql1 = "delete from FnaBudgetfeeTypeUsed where subjectId = ? and userId = ? ";
		rs1.executeUpdate(sql1, subjectId,userId);
		int idx = 0;
		sql1 = "select * from FnaBudgetfeeTypeUsed where userId = ? order by orderId desc";
		rs1.executeQuery(sql1,userId);
		while(rs1.next()){
			int orderId = rs1.getInt("orderId");
			idx++;
			if(idx >= 20){
				String sql2 = "delete from FnaBudgetfeeTypeUsed where orderId <= ? and userId = ?";
				rs2.executeUpdate(sql2, orderId,userId);
				break;
			}
		}
		int orderId = 0;
		sql1 = "select max(orderId) maxOrderId from FnaBudgetfeeTypeUsed where userId = ?";
		rs1.executeQuery(sql1, userId);
		while(rs1.next()){
			orderId = rs1.getInt("maxOrderId");
		}
		orderId++;
		sql1 = "insert into FnaBudgetfeeTypeUsed (userId, subjectId, orderId) values (?, ?, ?)";
		rs1.executeUpdate(sql1, userId,subjectId,orderId);
		idx = 0;
		sql1 = "select * from FnaBudgetfeeTypeUsed where userId = ? order by orderId asc";
		rs1.executeQuery(sql1,userId);
		while(rs1.next()){
			int _subjectId = rs1.getInt("subjectId");
			String sql2 = "update FnaBudgetfeeTypeUsed set orderId = ? where subjectId = ? and userId = ?";
			rs2.executeUpdate(sql2,idx,_subjectId,userId);
			idx++;
		}
	}

	/**
	 * 获取配置文件信息
	 * @param key
	 * @return
	 */
	private static String getPropertyValue(String key){
		BaseBean bb = new BaseBean();
		String value = Util.null2String(bb.getPropValue(Constants.MULTI_INVOICE_PROP, key)).trim();
		return value;
	}

	/**
	 * 更新发票主表信息
	 * @param invoiceid
	 * @param invoiceCode
	 * @param invoiceNumber
	 * @param billingDate
	 * @param taxIncludedPrice
	 * @param seller
	 * @param purchaser
	 * @param checkCode
	 */
	private static void updateMain(String invoiceid,String invoiceCode,String invoiceNumber,String billingDate,String taxIncludedPrice
			,String seller,String purchaser,String checkCode
	        ,String kind,String category,String seller_tax_id,String buyer_tax_id,String tax){
		RecordSet rs = new RecordSet();
		rs.executeUpdate("update fnainvoiceledger set invoiceCode=?,invoiceNumber=?,billingDate=?,taxIncludedPrice=?,seller=?,purchaser=?,checkCode=? " +
						" ,kind=?,category=?,salesTaxNo=?,purchaserTaxNo=?,tax=? where id=? "
				, invoiceCode,invoiceNumber,billingDate,taxIncludedPrice,seller,purchaser,checkCode,kind,category,seller_tax_id,buyer_tax_id,df.format(Util.getDoubleValue(tax,0.00)),invoiceid);
	}

	/**
	 * 判断此张发票是否为真(有效，已查验)
	 * @param invoiceNumber
	 * @return
	 */
	private static boolean ifExistAuthenticity2(String invoiceNumber,String invoiceCode){
		RecordSet rs = new RecordSet();
		String sql = "select 1 from fnaInvoiceLedger where invoiceNumber = ? and invoiceCode =? and checkStatus = 1";
		rs.executeQuery(sql, invoiceNumber, invoiceCode);
		if(rs.next()){
			return true;
		}
		return false;
	}

	/**
	 * 拼装input
	 * @param id
	 * @param inputtype
	 * @param info
	 * @return
	 */
	private static String getInput(String id,String inputtype,String info){
		String input = "<input id='"+id+"' type='"+inputtype+"' style='height: 30px;margin-top: 10px;' class='form-control text-input' autocomplete='off' value='"+info+"'>";
		return input;
	}

	/**
	 * 添加发票显示信息
	 * @param jsonObject
	 * @param number
	 * @return
	 */
	private static JSONObject addShowInfo(JSONObject jsonObject,String number,String code){
		String[] invoceInfo = getInvoiceData(number,code);
		jsonObject.put("date",invoceInfo[0]);
		jsonObject.put("amt",invoceInfo[1]);
		jsonObject.put("type",invoceInfo[2]);
		String id = invoceInfo[3]+"";
		jsonObject.put("invoiceId",id );
		return jsonObject;
	}

	/**
	 * 获取当前时间
	 * @return
	 */
	private static String getDate(){
		return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
	}

	/**
	 * 获取发票信息
	 * @param id
	 * @return
	 */
	public static String[] getInvoiceData(String invoiceNumber,String invoiceCode){
		RecordSet rs = new RecordSet();
		String[] data = new String[6];
		String sql = "select id,billingDate,taxIncludedPrice,invoiceType,checkCode,invoiceCode from fnaInvoiceLedger where invoiceNumber = ? and invoiceCode = ? ";
		rs.executeQuery(sql, invoiceNumber, invoiceCode);
		String id = "0";
		String billingDate = "";
		String taxIncludedPrice = "";
		String invoiceType = "";
		String checkCode = "";

		if(rs.next()){
			id = Util.null2String(rs.getString("id"));
			billingDate = Util.null2String(rs.getString("billingDate"));
			taxIncludedPrice = Util.null2String(rs.getString("taxIncludedPrice"));
			invoiceType = Util.null2String(rs.getString("invoiceType"));
			checkCode = Util.null2String(rs.getString("checkCode"));

		}
		data[0] = billingDate;
		data[1] = taxIncludedPrice;
		data[2] = invoiceType;
		data[3] = id;
		data[4] = checkCode;
		data[5] = invoiceCode;
		return data;
	}

	/**
	 * 获取json数据
	 * @param json
	 * @param key
	 * @return
	 */
	public static String getString(JSONObject json, String key) {
		if (json.containsKey(key)) {
			return json.getString(key);
		}
		return "";
	}

	/**
	 * 校验日期格式
	 * @param date
	 * @return
	 */
	private static boolean checkDate(String date) {
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			format.setLenient(false);
			format.parse(date);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	/**
	 * @Description: 获取流程中发票自动带出的信息
	 * @param invoiceIds 发票IDs
	 * @return: net.sf.json.JSONObject
	 * @Author: konghang
	 * @Date: 11:40 2020/11/30
	 */
	public static JSONObject getWfAutoBringInfo(String invoiceIds) {
		JSONObject autoBringObj = new JSONObject();
		String invoiceNumberTotal = "";
		String billingDateTotal = "";
		String subjectIdTotal = "";
		String subjectNameTotal = "";
		Double taxIncludedPriceTotal = 0.00;
		String remarkTotal = "";
		Double taxTotal = 0.00;
		String purchaserTotal = "";
		String purchaserTaxNoTotal = "";
		String sellerTotal = "";
		String salesTaxNoTotal = "";
		String invoiceServiceYypeDetailTotal = "";
		Double priceWithoutTaxDetailTotal = 0.00;
		String taxRateDetailTotal = "";
		Double taxDetailTotal = 0.00;

		RecordSet rsOne = new RecordSet();
		RecordSet rsTwo = new RecordSet();
		String[] invoiceIdsSplit = invoiceIds.split(",");
		for (int i = 0; i < invoiceIdsSplit.length; i++) {
			String invoiceId = invoiceIdsSplit[i];

			//获取发票主表信息
			String sqlGetInfo = "select a.invoicenumber,\n" +
					"       a.billingdate,\n" +
					"       a.taxincludedprice,\n" +
					"       b.remark,\n" +
					"       a.tax,\n" +
					"       a.purchaser,\n" +
					"       a.purchasertaxno,\n" +
					"       a.seller,\n" +
					"       a.salestaxno\n" +
					"from fnaInvoiceLedger a\n" +
					"         join FnaInvoiceLedgerDtl b on b.mainId = a.id\n" +
					"where a.id = ?";
			rsOne.executeQuery(sqlGetInfo, invoiceId);
			if (rsOne.next()) {
				invoiceNumberTotal = (String) spliceAutoBringInfo(invoiceNumberTotal, rsOne.getString("invoicenumber"));
				billingDateTotal = (String) spliceAutoBringInfo(billingDateTotal, rsOne.getString("billingdate"));
				taxIncludedPriceTotal = (Double) spliceAutoBringInfo(taxIncludedPriceTotal, rsOne.getString("taxincludedprice"));
				remarkTotal = (String) spliceAutoBringInfo(remarkTotal, rsOne.getString("remark"));
				taxTotal = (Double) spliceAutoBringInfo(taxTotal, rsOne.getString("tax"));
				purchaserTotal = (String) spliceAutoBringInfo(purchaserTotal, rsOne.getString("purchaser"));
				purchaserTaxNoTotal = (String) spliceAutoBringInfo(purchaserTaxNoTotal, rsOne.getString("purchasertaxno"));
				sellerTotal = (String) spliceAutoBringInfo(sellerTotal, rsOne.getString("seller"));
				salesTaxNoTotal = (String) spliceAutoBringInfo(salesTaxNoTotal, rsOne.getString("salestaxno"));
			}

			//获取发票明细信息
			rsOne.executeQuery("select * from FnaInvoiceLedgerDetail where mainid = ? ", invoiceId);
			while (rsOne.next()) {
				String invoiceServiceYype = Util.null2String(rsOne.getString("invoiceServiceYype"));
				if (!"".equals(invoiceServiceYype)) {
					rsTwo.executeQuery("select b.id subjectId,b.name subjectName from FnaInvoiceSubject a " +
							"join FnaBudgetfeeType b on a.subjectid=b.id where a.invoiceServiceYype=?", invoiceServiceYype);
					if (rsTwo.next()) {
						subjectIdTotal = (String) spliceAutoBringInfo(subjectIdTotal, rsTwo.getString("subjectId"));
						subjectNameTotal = (String) spliceAutoBringInfo(subjectNameTotal, rsTwo.getString("subjectName"));
					}
				}

				invoiceServiceYypeDetailTotal = (String) spliceAutoBringInfo(invoiceServiceYypeDetailTotal, rsOne.getString("invoiceserviceyype"));
				priceWithoutTaxDetailTotal = (Double) spliceAutoBringInfo(priceWithoutTaxDetailTotal, rsOne.getString("pricewithouttax"));
				taxRateDetailTotal = (String) spliceAutoBringInfo(taxRateDetailTotal, rsOne.getString("taxrate"));
				taxDetailTotal = (Double) spliceAutoBringInfo(taxDetailTotal, rsOne.getString("tax"));
			}
		}

		autoBringObj.put("invoiceNumberTotal", invoiceNumberTotal);
		autoBringObj.put("billingDateTotal", billingDateTotal);
		autoBringObj.put("subjectIdTotal", subjectIdTotal);
		autoBringObj.put("subjectNameTotal", subjectNameTotal);
		autoBringObj.put("taxIncludedPriceTotal", taxIncludedPriceTotal);
		autoBringObj.put("remarkTotal", remarkTotal);
		autoBringObj.put("taxTotal", taxTotal);
		autoBringObj.put("purchaserTotal", purchaserTotal);
		autoBringObj.put("purchaserTaxNoTotal", purchaserTaxNoTotal);
		autoBringObj.put("sellerTotal", sellerTotal);
		autoBringObj.put("salesTaxNoTotal", salesTaxNoTotal);
		autoBringObj.put("invoiceServiceYypeDetailTotal", invoiceServiceYypeDetailTotal);
		autoBringObj.put("priceWithoutTaxDetailTotal", priceWithoutTaxDetailTotal);
		autoBringObj.put("taxRateDetailTotal", taxRateDetailTotal);
		autoBringObj.put("taxDetailTotal", taxDetailTotal);

		return autoBringObj;
	}

	/**
	 * @Description: 拼接流程自动带出的发票信息
	 * @param currentTotal 当前数据
	 * @param addStr 带添加的数据
	 * @return: java.lang.Object
	 * @Author: konghang
	 * @Date: 11:29 2020/11/30
	 */
	public static Object spliceAutoBringInfo(Object currentTotal, String addStr) {

		if (currentTotal instanceof String) {
			return (currentTotal + "," + Util.null2String(addStr));
		} else if (currentTotal instanceof Double) {
			DecimalFormat decimalFormat = new DecimalFormat("###################################0.00");
			return ((Double) currentTotal + Util.getDoubleValue(decimalFormat.format(Util.getDoubleValue(addStr, 0.00)), 0.00));
		}

		return null;
	}
}
