@isTest
private class OrderSplitRatioControllerTest {
   static testMethod void myTest1() {
   		List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        String AppSta = '';
        String BsAgm = '';
        String new_profileId = '';
        Account buyer = new Account(
            Name = '*',
            FacilityName__c = 'buyer',
            PostCode__c = '123456',
            RecordTypeId = rectDealer[0].Id,
            ProductSegment__c = 'BS'
        );
        insert buyer;

        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCodeD__c='000000',
            PostCode__c='000000'
        );
        insert accIE; 
        
        PriceBook2 pricebook =new PriceBook2(
            Name = 'BS'
        );
        insert pricebook;
        
        Contact contact = new Contact(
            LastName = 'contact',
            AccountId = accIE.Id
        );
        insert contact;

        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct'
        );
        insert opp;

        OpportunityContactRole ocr = new OpportunityContactRole(
            OpportunityId = opp.Id,
            ContactId = contact.Id,
            Role = 'End user',
            IsPrimary = true
        );
        insert ocr;

        Order odr = new Order(
            Name = '',
            CurrencyIsoCode = 'CNY',
            Status = 'Draft',
            CrossCooperativeDealerText__c = 'hehe',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Submit',
            OpportunityId = opp.Id,
            EffectiveDate = Date.today(),
            Pricebook2Id = pricebook.Id,
            EndUser__c = contact.Id,
            BS_AsistGenManger_BS__c = '00528000000YSeOAAW'
        );
        insert odr;
        
         //画面迁移--留言画面
        PageReference page = new PageReference('/apex/OrderSplitRatioPopUp?raid=' + odr.Id );
        System.Test.setCurrentPage(page);
        
        OrderSplitRatioController controller = new OrderSplitRatioController();
        

        //取得订单
        Order odr1 = [select Id, Name, Dealer__c,SplitRatio__c,CrossCooperativeDealerText__c,SplitRatioFormule__c,BS_AsistGenManger_BS__c,ApproveStatus__c from Order where Id = :odr.Id];

        //初始化
        controller.init1();
        
        //发送按钮
        controller.ra1.SplitRatio__c = '5 : 5';

        //保存后
        controller.saveBtn();
    }

    static testMethod void myTest2() {
    	List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
        String AppSta = '';
        String BsAgm = '';
        String new_profileId = '';
        Account buyer = new Account(
            Name = '*',
            FacilityName__c = 'buyer',
            PostCode__c = '123456',
            RecordTypeId = rectDealer[0].Id,
            ProductSegment__c = 'BS'
        );
        insert buyer;

        Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCodeD__c='000000',
            PostCode__c='000000'
        );
        insert accIE;

        PriceBook2 pricebook =new PriceBook2(
            Name = 'BS'
        );
        insert pricebook;

        Contact contact = new Contact(
            LastName = 'contact',
            AccountId = accIE.Id
        );
        insert contact;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct'
        );
        insert opp;

        OpportunityContactRole ocr = new OpportunityContactRole(
            OpportunityId = opp.Id,
            ContactId = contact.Id,
            Role = 'End user',
            IsPrimary = true
        );
        insert ocr;

        Order odr = new Order(
            Name = '',
            CurrencyIsoCode = 'CNY',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Submit',
            OpportunityId = opp.Id,
            CrossCooperativeDealerText__c = 'hehe',
            EffectiveDate = Date.today(),
            Pricebook2Id = pricebook.Id,
            EndUser__c = contact.Id,
            BS_AsistGenManger_BS__c = '00528000000YSeOAAW'
        );
        insert odr;
        
        //画面迁移--留言画面
        PageReference page = new PageReference('/apex/OrderSplitRatioPopUp?raid=' + odr.Id );
        System.Test.setCurrentPage(page);
        OrderSplitRatioController controller = new OrderSplitRatioController();
        
        //取得订单
        Order odr1 = [select Id, Name, Dealer__c,SplitRatio__c,CrossCooperativeDealerText__c,SplitRatioFormule__c,BS_AsistGenManger_BS__c,ApproveStatus__c from Order where Id = :odr.Id];

        //初始化
        controller.init1();
        //System.assertEquals('', controller.ra1.OCN_Internal_Notes__c);
        
        //发送按钮
        controller.ra1.SplitRatio__c = '5 : 5';

        //保存后
        controller.saveBtn();
    }
     static testMethod void myTest3() {
     	List<RecordType> rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer'];
         List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS'];
         String AppSta = '';
         String BsAgm = '';
         Account accIE = new Account(
            Name = '*',
            RecordTypeId = rectIE[0].Id,
            OwnerId = UserInfo.getUserId(),
            DivisionName__c='Customer BS',
            FacilityName__c='abc',
            PostCodeD__c='000000',
            PostCode__c='000000'
        );
        insert accIE;

        PriceBook2 pricebook =new PriceBook2(
            Name = 'BS'
        );
        insert pricebook;

        Contact contact = new Contact(
            LastName = 'contact',
            AccountId = accIE.Id
        );
        insert contact;
         
        List<RecordType> rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity'];
        // 有预定下单日
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = accIE.Id,
            //Dealer__c = '呵呵',
            RecordTypeId = rectOpp[0].Id,
            OwnerId = UserInfo.getUserId(),
            StageName = 'Phase3',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'BS',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            SalesChannel__c = 'direct'
        );
        insert opp;

        OpportunityContactRole ocr = new OpportunityContactRole(
            OpportunityId = opp.Id,
            ContactId = contact.Id,
            Role = 'End user',
            IsPrimary = true
        );
        insert ocr;

        Order odr = new Order(
            Name = '',
            CurrencyIsoCode = 'CNY',
            Status = 'Draft',
            AccountId = accIE.Id,
            ApproveStatus__c = 'Submit',
            OpportunityId = opp.Id,
            CrossCooperativeDealerText__c = 'hehe',
            EffectiveDate = Date.today(),
            Pricebook2Id = pricebook.Id,
            EndUser__c = contact.Id,
            BS_AsistGenManger_BS__c = '00528000000YSeOAAW'
        );
        insert odr;
        
        //画面迁移--留言画面
        PageReference page = new PageReference('/apex/OrderSplitRatioPopUp?raid=' + odr.Id );
        System.Test.setCurrentPage(page);
        OrderSplitRatioController controller = new OrderSplitRatioController();
        
        //取得订单
        Order odr1 = [select Id, Name, Dealer__c,SplitRatio__c,CrossCooperativeDealerText__c,SplitRatioFormule__c,BS_AsistGenManger_BS__c,ApproveStatus__c from Order where Id = :odr.Id];

        //初始化
        controller.init();
        //System.assertEquals('', controller.ra1.OCN_Internal_Notes__c);
        
        //发送按钮
        controller.ra1 = odr1;
        controller.ra1.SplitRatio__c = '';

        //保存后
        controller.saveBtn();
    }
}