/**
 * @(#)file    BizNumber.java
 * @(#)author  chj
 * @(#)version 1.0
 * @(#)date    2014-06-24
 * @(#)since   JDK 1.6
 *
 * Copyright (c)  www.udapsoft.co.kr, Inc.
 */
package com.udapsoft.waf.common.ui;

/**
 * 구매신청번호, 견적의뢰 번호, 발주번호, 품의번호, 계약번호에 '-' 붙이는 Utility
 * @author 
 */
public class BizNumber {


	private static final int NUM_SEQ  = 4 ;

	private static final int PR_SIZE1 = 10 ;
	
	private static final int RFQ_SIZE1 = 3 ;
	private static final int RFQ_SIZE2 = 4 ;
	
	private static final int PO_SIZE1 = 2 ;
	private static final int PO_SIZE2 = 4 ;
	
	private static final int CON_SIZE1 = 4 ;

    private static final int SUBR_SIZE1 = 4 ;
    private static final int SUBR_SIZE2 = 4 ;
    
	private static final int SUBO_SIZE1 = 4 ;
	private static final int SUBO_SIZE2 = 4 ;
    

	private static int prLen ;
	private static int rfqLen ;
	private static int poLen ;
	private static int conLen ;
    private static int subrLen ;
	private static int suboLen ;

    public BizNumber() {
    	prLen = PR_SIZE1 + NUM_SEQ ;
    	rfqLen = RFQ_SIZE1 + RFQ_SIZE2 +NUM_SEQ ;    			
    	poLen = PO_SIZE1 + PO_SIZE2 +NUM_SEQ ;    			
    	conLen = CON_SIZE1 + NUM_SEQ ;    			
        subrLen = SUBR_SIZE1 + SUBR_SIZE2 + NUM_SEQ;
		suboLen = SUBO_SIZE1 + SUBO_SIZE2 + NUM_SEQ;         
    }

    /** 구매신청번호에 '-' 붙이기
	 * @param number
	 * @return
	 */
	public static String formatPrNumber(String number){
    	if(number == null || number.equals("") || number.length() < prLen) {
    		return "";
    	}
    	StringBuffer sb = new StringBuffer(number);
    	sb.insert(PR_SIZE1, "-");
    	return sb.toString();
    }

    /** 견적의뢰번호에 '-' 붙이기
     * @param number
     * @return
     */
    public static String formatRfqNumber(String number){
    	if(number == null || number.equals("") || number.length() < rfqLen) {
    		return "";
    	}
    	StringBuffer sb = new StringBuffer(number);
    	sb.insert(RFQ_SIZE1, "-").insert(RFQ_SIZE1+RFQ_SIZE2+1, "-");
    	return sb.toString();
    }

    /** 발주, 품의번호에 '-' 붙이기
     * @param number
     * @return
     */
    public static String formatPoNumber(String number){

    	if(number == null || number.equals("") || number.length() < poLen) {
    		return "";
    	}

    	StringBuffer sb = new StringBuffer(number);
    	sb.insert(PO_SIZE1, "-").insert(PO_SIZE1+PO_SIZE2+1,"-");
    	return sb.toString();
    }

    /** 계약번호에 '-' 붙이기
     * @param number
     * @return
     */
    public static String formatConNumber(String number){

    	if(number == null || number.equals("") || number.length() < conLen) {
    		return "";
    	}

    	StringBuffer sb = new StringBuffer(number);
    	sb.insert(CON_SIZE1, "-");
    	return sb.toString();
    }

    /**
     * 외주 선정요청번호 '-' 붙이기
	 * @param number
	 * @return
	 */
	public static String formatSrNumber(String number) {

        return formatPrNumber(number);
    }

    /** 외주 견적의뢰번호에 '-' 붙이기
     * @param number
     * @return
     */
    public static String formatSubrNumber(String number){
        if(number == null || number.equals("") || number.length() < subrLen) {
            return "";
        }
        StringBuffer sb = new StringBuffer(number);
        sb.insert(SUBR_SIZE1, "-").insert(SUBR_SIZE1 + SUBR_SIZE2 + 1, "-");
        return sb.toString();
    }

	/** 외주 발주번호에 '-' 붙이기
	 * @param number
	 * @return
	 */
	public static String formatSuboNumber(String number){
		if(number == null || number.equals("") || number.length() < suboLen) {
			return "";
		}
		StringBuffer sb = new StringBuffer(number);
		sb.insert(SUBO_SIZE1, "-").insert(SUBO_SIZE1 + SUBO_SIZE2 + 1, "-");
		return sb.toString();
	}
}
