public without sharing class searchContractController {
	public List<Account> at {get;set;}
	private String accountid = null;
	public String searchName {get;set;}               // 検索文字列
	private String ctype;
	Date todayDate = Date.today();

    private Boolean OSHFLG;//lt 20230517 安徽两票制 add

	public searchContractController() {
		ctype = ApexPages.currentPage().getParameters().get('Ctype');
		todayDate = Date.today();

	}
	public void init(){
        //lt 20230517 安徽两票制 add ,OSHFLG__c
		User useracc = [SELECT accountid,OSHFLG__c FROM user WHERE id = :UserInfo.getUserId() ];
        OSHFLG = Useracc.OSHFLG__c; //lt 20230517 安徽两票制 add

        accountid = Useracc.accountid;
        at = [SELECT id,Name,State_Master__c,State_Master__r.Name,Sales_Section__c,
        			Contract_Decide_Start_Date__c,Contract_Decide_End_Date__c
                    // ,OSH_Dealer__c //20230323 lt DB202303088261 两票制 add
                FROM Account
                WHERE ParentId = :accountid
                AND Contact_Type__c like :ctype 
        		AND Contract_Decide_Start_Date__c <= :Date.Today()
                AND Contract_Decide_End_Date__c >= :Date.Today()
                AND Secondary_contract__c = false
                AND OSH_Dealer__c =: OSHFLG  //lt 20230517 安徽两票制 add
                ];
                // System.debug('lt123---1---'+at);

	}
	public PageReference serContact(){
		at = Database.query(this.makeSoql(searchName,todayDate));
        // System.debug('lt123---2---'+at);
		return null;
	}

	private String makeSoql(String CateName,Date timetest){
		
        String soql = 'SELECT id,Name,State_Master__c,State_Master__r.Name,Sales_Section__c,';
        soql += ' Contract_Decide_Start_Date__c,Contract_Decide_End_Date__c,OSH_Dealer__c FROM Account';  //20230323 lt DB202303088261 两票制 add ,OSH_Dealer__c
        soql += ' where ParentId = \'' + this.accountid + '\'' ;
        soql += ' AND OSH_Dealer__c = ' + this.OSHFLG + '' ; //lt 20230517 安徽两票制 add
        soql += ' AND Secondary_contract__c = false' ;
        soql += ' AND Contact_Type__c like \'%' + String.escapeSingleQuotes(ctype.replaceAll('%', '\\%')) + '%\''; 
        soql += ' AND Contract_Decide_Start_Date__c <=' + String.valueOf(timetest).substring(0, 10);
        soql += ' AND Contract_Decide_End_Date__c >= ' + String.valueOf(timetest).substring(0, 10);
        if(!String.isBlank(CateName)){
            soql += ' AND Name like \'%' + String.escapeSingleQuotes(CateName.replaceAll('%', '\\%')) + '%\'';
        }
        // System.debug('lt123---3---'+soql);
        return soql;
        
    }
}