@isTest
private class NFM202triggerTest {
	static final String RC_BYOUIN = '病院';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    
	@isTest static void test_method_one() {
        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;
        String CRON_EXP = '0 0 0 3 9 ? 2032';
        // system.schedule('AgencyIntelligenceExpireTest', CRON_EXP, new AgencyIntelligenceExpireSchedule());
        System.Test.StopTest();
	}
	
	//@isTest static void test_method_two() {
	//	Opportunity opp = new Opportunity(
 //           Opportunity_No__c = '1234567',
 //           Name='Opp',
 //           StageName='引合',
 //           CloseDate=Date.today(),
 //           CurrencyIsoCode = 'CNY'
 //       );
 //       insert opp;
 //       //opp.old_Oppo_No__c = '123456789';
 //       //opp.SeparateBillMark__c = '1';
 //       Opportunity opp1 = new Opportunity(
 //           Name='Opp',
 //           StageName='引合',
 //           CloseDate=Date.today(),
 //           CurrencyIsoCode = 'CNY',
 //           old_Oppo_No__c = '1234567',
 //           SeparateBillMark__c = '1'
 //       );
 //       insert opp1;
	//}
    
	@isTest static void test_method_two() {
        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;
        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;

         //見積データ作成
         Quote quote = new Quote( Name = 'テスト見積');
         quote.OpportunityId = opp.Id;
        //  quote.Pricebook2Id = entry.id;
         quote.Quote_No__c = 'quoteNo';
 
         quote.Unit_Price__c = true;
         quote.Offer_Amount__c = true;
         quote.TOTAL__c = true;
         quote.Discount__c = true;
         quote.Pricing__c = true;
         quote.Preferential_Trading_Price__c = true;
         quote.Contract__c = true;
         quote.Quote_Comment__c = 'true';
         insert quote;

        opp.If_Authorizing__c = true;
        //opp.Competitor__c = 'A';
        opp.Contract_Authorize__c = true;
        opp.Estimation_Id__c = quote.id;
        update opp;
        PromotionHead__c ph = new PromotionHead__c();
        ph.SpoId__c = 'SPOXX';
        ph.name = 'SPOXX';
        //写死促销方案id
        // ph.recordTypeId = '01210000000aLmw';
        insert ph;

        PromotionSales__c ps =new PromotionSales__c();
        ps.PromotionHead__c = ph.id;
        ps.Category__c = '促销政策';
        ps.name ='xxx';

        insert ps;


        PromotionSalesProducts__c psp = new PromotionSalesProducts__c();
        psp.QuantityId__c = quote.id;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp.Asset_Model_No__c = 'N/A';
        psp.Quantity__c = 2;
        psp.AgencyUnitPrice__c =12.0;
        psp.UseCount__c =2;

        insert psp;

        PromotionSalesProducts__c psp3 = new PromotionSalesProducts__c();
        psp3.QuantityId__c = quote.id;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp3.Asset_Model_No__c = 'A321：啊乌拉乌拉乌拉哇哇';
        psp3.Quantity__c = 2;
        psp3.AgencyUnitPrice__c =12.0;
        psp3.UseCount__c =2;

        insert psp3;

        NFM202Controller.testI();
    }
	
}