@isTest
private class OppStrategyProductBatchTest {
	static final String RC_BYOUIN = '病院';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static testMethod void testMethod1() {
    	StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
		// Implement test code
		RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;

		RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        sellerA.Ban_On_Use_Date__c = Date.today().addDays(20);
        insert sellerA;

        Product2 product = new Product2( Name='テスト商品');
    	product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
		insert product;
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
		entry.UnitPrice = 0;
		entry.IsActive = true;
		entry.UseStandardPrice = false;
		entry.CurrencyIsoCode = 'CNY';
		insert entry;

        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType= 'Account' and Name=:RC_KEIYAKU limit 1];
        Account contractA = new Account(Name = '*');
        contractA.RecordTypeId = recKeiyaku.id;
        contractA.Agent_Ref__c = sellerA.id;
        contractA.ParentId = sellerA.id;
        contractA.Contract_Decide_Start_Date__c = Date.today().addDays(-1);
        contractA.Contract_Decide_End_Date__c = Date.today().addDays(20);
        //contractA.Contract_Quote_Decide_Flag_checkbox__c = true;
        contractA.ET_SP_Dealer__c = true;

        insert contractA;
        System.Test.startTest();
        Opportunity opp = new Opportunity( Name='aiueo', StageName='contact', CloseDate=Date.today().addDays(60));
        opp.Trade__c = '内貿';
        //opp.CurrencyIsoCode = CurrencyIso;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.owner_not_automatically_update__c = true;
        //opp.Pricebook2Id = pricebook.id;
        opp.Purchase_Type__c = '一般引合';
        opp.Promise_Class__c = '内貿';
        opp.Fund_Basis__c = '政府資金';
        opp.AccountId = contractA.id;
        opp.Hospital__c = contractA.id;
        opp.Agency1__c = sellerA.id;
        opp.Wholesale_Price__c = 9000;
        opp.Opportunity_stage__c = '还没申请预算';
        opp.Close_Forecasted_Date__c = Date.today().addDays(50);
        opp.Special_Opp_lanhai__c = false;
        opp.Competitor__c = 'A';
        opp.If_Authorizing__c = false;
        opp.Contract_Authorize__c = false;
        opp.Special_Opp_lanhai__c = true;
        opp.Estimation_Id__c = 'a1';
        insert opp;
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '111';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        opp.If_Authorizing__c = true;
        //opp.Competitor__c = 'A';
        opp.Contract_Authorize__c = true;
        update opp;
        Id execBTId = Database.executeBatch(new OppStrategyProductBatch(),1);
        Id execBTIdh = Database.executeBatch(new OppStrategyProductBatch(true),1);
        System.Test.StopTest();
    }
}