package com.tax.file.utils.invoice;

import java.text.SimpleDateFormat;

import com.tax.file.model.FinInvoice;
import com.tax.file.model.FinInvoiceDetail;
import com.tax.file.utils.invoice.ElectricInvoiceCellRead.SingletonHolder;
import com.yxcheng.token.utils.StringUtil;
/** 
 * 普票单元格读取具体实现类
 * 
 * */ 
public class GeneralInvoiceCellRead extends AbstractInvoiceCellRead {
	
	
    private GeneralInvoiceCellRead(){
		
	}
	
	public static class SingletonHolder{
		private static GeneralInvoiceCellRead instance = new GeneralInvoiceCellRead();
	}
	
	public static  GeneralInvoiceCellRead getInstance(){
		return SingletonHolder.instance;
	}

	 /** 
     * 根据单元格序号和单元格的值设置发票主模型的值
     * @param invoice 发票模型
     * @param cellNum 单元格序号
     * @param cellValue 单元格值
     * @throws Exception  
     */   
	@Override
	public void readCellInvoice(FinInvoice invoice, int cellNum, String cellValue) throws Exception{
		
		 switch(cellNum){
     	case 1:
     		invoice.setInvkind(cellValue);
     		break;
     	case 2:
     		invoice.setInvnum(cellValue);
     		break;
     	case 3:
     		if(StringUtil.isNotEmpty(cellValue)){
     			invoice.setInvdate(new SimpleDateFormat("yyyy-MM-dd").parse(cellValue));
     		}
     		break;
     	case 4:
     		//invoice.setInvStatus(getInvStatus(cellValue));
     		break;
     	case 5:
     		invoice.setSelltaxno(cellValue);
     		break;
     	case 6:
     		invoice.setSellname(cellValue);
     		break;
     	case 7:
     		invoice.setBuytaxno(cellValue);
     		break;
     	case 8:
     		invoice.setBuyname(cellValue);
     		break;
     	case 9:
     		invoice.setInvcost(getDoubleValue(cellValue));
     		break;
     	case 10:
     		invoice.setInvvat(getDoubleValue(cellValue));
     		break;
     	case 11:
     		invoice.setInvsum(getDoubleValue(cellValue));
     		break;
     	case 12:
     		invoice.setJym(cellValue);
     		break;
     	case 13:
     		invoice.setSelladdress(cellValue);
     		break;
     	case 14:
     		invoice.setSellaccount(cellValue);
     		break;
     	case 15:
     		invoice.setBuyaddress(cellValue);
     		break;
     	case 16:
     		invoice.setBuyaccount(cellValue);
     		break;
     	case 17:
     		//invoice.setInvpwd(cellValue);
     		break;
     	case 18:
     		//invoice.setInvremark(cellValue);
     		break;
     	case 19:
     		//invoice.setBillingName(cellValue);
     		break;
     	case 20:
     		//invoice.setPayeeName(cellValue);
     		break;
     	case 21:
     		//invoice.setReviewerName(cellValue);
     		break;
     }

	}
	
	/** 
     * 根据单元格序号和单元格的值设置发票明细模型的值
     * @param invoice 发票模型
     * @param invoiceDetail 单元格序号
     * @param cellValue 单元格值
     * @throws Exception  
     */  
	@Override
	public void readCellDetail(FinInvoiceDetail invoiceDetail, int cellNum, String cellValue,boolean flag) throws Exception {
		
		if(flag){
			switch(cellNum){
			case 0:
				//invoiceDetail.setLineNo(Integer.parseInt(cellValue));
				break;
	     	case 1:
	     		invoiceDetail.setInvKind(cellValue);
	     		break;
	     	case 2:
	     		invoiceDetail.setInvNum(cellValue);
	     		break;
	     	case 4:
	     		invoiceDetail.setTaxClassCode(cellValue != null?cellValue.trim():null);
	     		break;
	     	case 5:
	     		invoiceDetail.setGname(cellValue);
	     		break;
	     	case 6:
	     		invoiceDetail.setGtype(cellValue);
	     		break;
	     	case 7:
	     		invoiceDetail.setGpiece(cellValue);
	     		break;
	     	case 8:
	     		invoiceDetail.setGnum(cellValue);
	     		break;
	     	case 9:
	     		invoiceDetail.setPrice(cellValue);
	     		break;
	     	case 10:
	     		invoiceDetail.setInvCost(getDoubleValue(cellValue));
	     		break;
	     	case 11:
	     		invoiceDetail.setInvRate(getDoubleValue(cellValue));
	     		break;
	     	case 12:
	     		invoiceDetail.setInvVat(getDoubleValue(cellValue));
	     		break;
	     }
		}else{
			switch(cellNum){
			case 0:
				//invoiceDetail.setLineNo(Integer.parseInt(cellValue));
				break;
	     	case 1:
	     		invoiceDetail.setInvKind(cellValue);
	     		break;
	     	case 2:
	     		invoiceDetail.setInvNum(cellValue);
	     		break;
	     	case 3:
	     		invoiceDetail.setTaxClassCode(cellValue != null?cellValue.trim():null);
	     		break;
	     	case 4:
	     		invoiceDetail.setGname(cellValue);
	     		break;
	     	case 5:
	     		invoiceDetail.setGtype(cellValue);
	     		break;
	     	case 6:
	     		invoiceDetail.setGpiece(cellValue);
	     		break;
	     	case 7:
	     		invoiceDetail.setGnum(cellValue);
	     		break;
	     	case 8:
	     		invoiceDetail.setPrice(cellValue);
	     		break;
	     	case 9:
	     		invoiceDetail.setInvCost(getDoubleValue(cellValue));
	     		break;
	     	case 10:
	     		invoiceDetail.setInvRate(getDoubleValue(cellValue));
	     		break;
	     	case 11:
	     		invoiceDetail.setInvVat(getDoubleValue(cellValue));
	     		break;
	     }
		}
	
	}


}
