package com.dxhy.core.util;

/**
 * 通过发票代码获取发票类型
 *
 * @author user
 */
@SuppressWarnings("AlibabaUndefineMagicConstant")
public class GetInvoiceType {
    private static final String[] FPDM_LIST = {"144031539110", "131001570151", "133011501118", "111001571071"};

    public static String getFplx(String fpdm) {
        // 识别不成功默认普票
        String fplx = "04";
        if (fpdm.trim().length() == 12) {
            String fplxflag = fpdm.substring(7, 8);
            for (String s : FPDM_LIST) {
                if (fpdm.equals(s)) {
                    fplx = "10";
                    break;
                }
            }
            if ("0".equals(fpdm.substring(0, 1)) && "11".equals(fpdm.substring(10, 12))) {
                fplx = "10";
            }
            if ("0".equals(fpdm.substring(0, 1)) && "12".equals(fpdm.substring(10, 12))) {
                fplx = "14";
            }
            boolean flag = "0".equals(fpdm.substring(0, 1))
                && ("06".equals(fpdm.substring(10, 12)) || "07".equals(fpdm.substring(10, 12)));
            if (flag) {
                // 判断是否为卷式发票 第1位为0且第11-12位为06或07
                fplx = "11";
            }
            if ("2".equals(fplxflag) && !"0".equals(fpdm.substring(0, 1))) {
                fplx = "03";
            }
            boolean flag1 = "0".equals(fpdm.substring(0, 1))
                && ("04".equals(fpdm.substring(10, 12)) || "05".equals(fpdm.substring(10, 12)));
            if (flag1) {
                fplx = "04";
            }
        } else if (fpdm.trim().length() == 10) {
            String fplxflag = fpdm.substring(7, 8);
            switch (fplxflag) {
                case "1":
                case "5":
                    fplx = "01";
                    break;
                case "6":
                case "3":
                    fplx = "04";
                    break;
                case "7":
                case "2":
                    fplx = "02";
                    break;
                default:
                    break;
            }
        }
        return fplx;
    }
}
