@isTest
private class NewQuoteEntryControllerTest {

    @isTest 
    static void test_init1() {
        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true,
            CurrencyIsoCode = 'CNY'
        );
        insert pricebook;

        system.debug('---pricebook---'+ pricebook);

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);

        //Product2 product2 = new Product2();
        //product2.Name = 'product2';
        //product2.ProductCode = 'product2';
        //product2.Product_ECCode__c = 'product2';
        //product2.IsActive = true;
        //product2.ProductStatus__c = '1';
        //product2.NMPAStatus_one__c = 'Z1';
        //product2.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        //product2.MaterialStatus_one_End__c = Date.today().addDays(22);

        //Product2 product3 = new Product2();
        //product3.Name = 'product3';
        //product3.ProductCode = 'product3';
        //product3.Product_ECCode__c = 'product3';
        //product3.IsActive = true;
        //product3.ProductStatus__c = '1';
        //product3.NMPAStatus_one__c = 'Z1';
        //product3.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        //product3.MaterialStatus_one_End__c = Date.today().addDays(22);

        //insert new Product2[] {product1, product2, product3};
        insert new Product2[] {product1};

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        //PricebookEntry standardPrice2 = new PricebookEntry(
        //    Pricebook2Id = pricebookId,
        //    Product2Id = product2.Id,
        //    UnitPrice = 0,
        //    IsActive = true,
        //    CurrencyIsoCode = 'CNY'
        //);

        //PricebookEntry standardPrice3 = new PricebookEntry(
        //    Pricebook2Id = pricebookId,
        //    Product2Id = product3.Id,
        //    UnitPrice = 0,
        //    IsActive = true,
        //    CurrencyIsoCode = 'CNY'
        //);

        //insert new PricebookEntry[] {standardPrice1, standardPrice2, standardPrice3};
        insert new PricebookEntry[] {standardPrice1};

        system.debug('standardPrice1--->' + standardPrice1);
        PricebookEntry entry1 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'

        );
        system.debug('--entry1-' + entry1.Pricebook2Id);
        //PricebookEntry entry2 = new PricebookEntry(
        //    Pricebook2Id = pricebook.Id,
        //    Product2Id = product2.Id,
        //    UnitPrice = 0,
        //    IsActive = true,
        //    UseStandardPrice = false,
        //    CurrencyIsoCode = 'CNY'
        //);
        //system.debug('--entry2-' + entry2.Pricebook2Id);
        //PricebookEntry entry3 = new PricebookEntry(
        //    Pricebook2Id = pricebook.Id,
        //    Product2Id = product3.Id,
        //    UnitPrice = 0,
        //    IsActive = true,
        //    UseStandardPrice = false,
        //    CurrencyIsoCode = 'CNY'
        //);
        //system.debug('--entry3-' + entry3.Pricebook2Id);
        //insert new PricebookEntry[] {entry1, entry2, entry3};
        insert new PricebookEntry[] {entry1};


        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id
        );
        insert user;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;
        system.debug('opp------>' + opp.Pricebook2Id);
        OpportunityLineItem oli1 = new OpportunityLineItem(
            OpportunityId = opp.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 30
        );
        //system.debug('--oli1-' + oli1.PricebookEntryId);
        //OpportunityLineItem oli2 = new OpportunityLineItem(
        //    OpportunityId = opp.Id,
        //    PricebookEntryId = entry2.Id,
        //    Quantity = 2,
        //    UnitPrice = 30
        //);
        //system.debug('--oli2-' + oli2.PricebookEntryId);
        //OpportunityLineItem oli3 = new OpportunityLineItem(
        //    OpportunityId = opp.Id,
        //    PricebookEntryId = entry3.Id,
        //    Quantity = 3,
        //    UnitPrice = 30
        //);
        //system.debug('--oli3-' + oli3.PricebookEntryId);
        //insert new OpportunityLineItem[] {oli1, oli2, oli3};
        //insert new OpportunityLineItem[] {oli1};


        PageReference page = new PageReference('/apex/NewQuoteService?oppid=' + opp.Id + '&openType=service');
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();

        controller.init();

        controller.quo.Name = '报价1';
        controller.quo.PaymentTerms__c = 'ZTT1';
        controller.quo.Shipment_Term__c = 'CIP';
        controller.quo.Shipment_Term2__c = 'BEIJING';
        controller.quo.DeliveryLeadTime__c = 90;
        controller.quo.Warranty__c = 1;
        controller.quo.ExpirationDate = Date.today();
        controller.quo.Custom_Price_Total_Text__c = 1000;
        controller.quo.Total_Price_Text__c = 922;

/*        controller.activities[0].pageObject.PricebookEntryId = entry1.Id;
        controller.activities[0].pageObject.Set__c = 'set01';
        controller.activities[0].pageObject.UnitPrice = 11;
        controller.activities[0].pageObject.Quantity = 1
        controller.activities[0].pageObject.Discount = 0;
        controller.activities[0].pageObject.Custom_Price__c = 20;
        controller.activities[0].pageObject.Description = 'test1';*/
        System.Test.StartTest();
        controller.Save();

        //system.assertEquals('',controller.errormessage);

        controller.excelImport();
        controller.testI();
        controller.OppReflection();

        controller.BackBtn();

        controller.Decide();

        controller.UnDecide();
        System.Test.StopTest();
    }

    //@isTest 
    static void test_init2() {
        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);

        Product2 product2 = new Product2();
        product2.Name = 'product2';
        product2.ProductCode = 'product2';
        product2.Product_ECCode__c = 'product2';
        product2.IsActive = true;
        product2.ProductStatus__c = '1';
        product2.NMPAStatus_one__c = 'Z1';
        product2.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product2.MaterialStatus_one_End__c = Date.today().addDays(22);

        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.ProductCode = 'product3';
        product3.Product_ECCode__c = 'product3';
        product3.IsActive = true;
        product3.ProductStatus__c = '1';
        product3.NMPAStatus_one__c = 'Z1';
        product3.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product3.MaterialStatus_one_End__c = Date.today().addDays(22);

        insert new Product2[] {product1, product2, product3};

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 10,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 10,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 10,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        insert new PricebookEntry[] {standardPrice1, standardPrice2, standardPrice3};

        PricebookEntry entry1 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product1.Id,
            UnitPrice = 10,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY',
            CostPrice1__c = 100,
            EffectiveDateFrom1__c = Date.today().addDays(-1),
            EffectiveDateTo1__c = Date.today().addDays(1),
            SalesPrice1__c = 200,
            EffectiveDateFrom1_sales__c = Date.today().addDays(-1),
            EffectiveDateTo1_sales__c = Date.today().addDays(1)
        );

        PricebookEntry entry2 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product2.Id,
            UnitPrice = 10,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY',
            CostPrice1__c = 100,
            EffectiveDateFrom1__c = Date.today().addDays(-1),
            EffectiveDateTo1__c = Date.today().addDays(1),
            SalesPrice1__c = 200,
            EffectiveDateFrom1_sales__c = Date.today().addDays(-1),
            EffectiveDateTo1_sales__c = Date.today().addDays(1)
        );

        PricebookEntry entry3 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product3.Id,
            UnitPrice = 10,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY',
            CostPrice1__c = 100,
            EffectiveDateFrom1__c = Date.today().addDays(-1),
            EffectiveDateTo1__c = Date.today().addDays(1),
            SalesPrice1__c = 200,
            EffectiveDateFrom1_sales__c = Date.today().addDays(-1),
            EffectiveDateTo1_sales__c = Date.today().addDays(1)
        );

        insert new PricebookEntry[] {entry1, entry2, entry3};

        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id,
            ProductSegment__c = 'IE'
        );
        insert user;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            //CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today().addDays(2),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            Trade_Type_D__c = 'Taxation',
            SalesChannel__c = 'direct',
            Sales_Channel_D__c = 'direct',
            Machine_Parts__c = 'Machine',
            Machine_Parts_D__c = 'Machine'
            //,
            //Pricebook2Id = pricebook.Id
        );
        insert opp;

        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname1',
            SetQty1__c = 1,
            SetName2__c = 'setname2',
            SetQty2__c = 2,
            CurrencyIsoCode = 'CNY',
            Custom_Price_Total_Text__c = 1000
        );
        insert quo;
        QuoteLineItem qli1 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry1.Id,
            Quantity = 1,
            UnitPrice = 10,
            Set__c = 'set01'
        );

        QuoteLineItem qli2 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry2.Id,
            Quantity = 2,
            UnitPrice = 10,
            Set__c = 'set01'
        );

        QuoteLineItem qli3 = new QuoteLineItem(
            QuoteId = quo.Id,
            PricebookEntryId = entry3.Id,
            Quantity = 1,
            UnitPrice = 10,
            Set__c = 'set02'
        );

        insert new QuoteLineItem[] {qli1, qli2, qli3};

        opp.SyncedQuoteId = quo.Id;
        upsert opp;

        PageReference page = new PageReference('/apex/NewQuoteService?id=' + quo.Id);
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();

        controller.init();

        controller.Refresh();

        controller.fileName = 'test1';
        controller.csvExport();

        String strblob = '"套装/单品","产品code","产品名称","数量","折扣"\n"单品","product1","product1","2.00","0.00"\n';

        controller.contentFile = Blob.valueOf(strblob);

        controller.csvRead();

        strblob = '套装/单品,产品code,产品名称,数量,折扣\nset01,product1,product1,2,49\nset01,product2,product2,2,49';

        controller.contentFile = Blob.valueOf(strblob);

        controller.csvRead();

        controller.reloadPage();
    }

    @isTest 
    static void test_init3() {
        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.IsActive = true;
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);

        Product2 product2 = new Product2();
        product2.Name = 'product2';
        product2.ProductCode = 'product2';
        product2.Product_ECCode__c = 'product2';
        product2.IsActive = true;
        product2.ProductStatus__c = '1';
        product2.NMPAStatus_one__c = 'Z1';
        product2.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product2.MaterialStatus_one_End__c = Date.today().addDays(22);

        Product2 product3 = new Product2();
        product3.Name = 'product3';
        product3.ProductCode = 'product3';
        product3.Product_ECCode__c = 'product3';
        product3.IsActive = true;
        product3.ProductStatus__c = '1';
        product3.NMPAStatus_one__c = 'Z1';
        product3.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product3.MaterialStatus_one_End__c = Date.today().addDays(22);

        insert new Product2[] {product1, product2, product3};

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry standardPrice2 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product2.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry standardPrice3 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product3.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );

        insert new PricebookEntry[] {standardPrice1, standardPrice2, standardPrice3};

        PricebookEntry entry1 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product1.Id,
            UnitPrice = 1,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry entry2 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product2.Id,
            UnitPrice = 1,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'
        );

        PricebookEntry entry3 = new PricebookEntry(
            Pricebook2Id = pricebook.Id,
            Product2Id = product3.Id,
            UnitPrice = 1,
            IsActive = true,
            UseStandardPrice = false,
            CurrencyIsoCode = 'CNY'
        );

        insert new PricebookEntry[] {entry1, entry2, entry3};

        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id
        );
        insert user;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;

        Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            Pricebook2Id = pricebook.Id,
            SetName1__c = 'setname1',
            SetQty1__c = 1,
            SetName2__c = 'setname2',
            SetQty2__c = 2,
            Custom_Price_Total_Text__c = 1000
        );
        insert quo;

        opp.SyncedQuoteId = quo.Id;
        //update opp;

        PageReference page = new PageReference('/apex/NewQuoteService?copyid=' + quo.Id);
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();

        controller.init();

        PageReference page2 = new PageReference('/apex/NewQuoteService?oppid=' + opp.Id);
        System.Test.setCurrentPage(page2);
        NewQuoteEntryController controller2 = new NewQuoteEntryController();

        controller2.init();
        controller2.setProductEntry();
    }
    //产品配套相关
    @isTest 
    static void test_init4() {
        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.ProductModels__c = true;
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );
        insert standardPrice1;

        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        insert entry1;

        Product_Search__c ps = new Product_Search__c(Product__c = product1.Id);

        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id
        );
        insert user;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;
         Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            SetName1__c = 'IXP-7P2',
            SetQty1__c = 1,
            Is_Decided__c = false
        );
        insert quo;
        List<productSet__c>  insertproductSets = new  List<productSet__c>();
        productSet__c proSet1 = new productSet__c();
        proSet1.Code__c = 'IXP-7P2';
        proSet1.Name = 'IXP-7P2';
        proSet1.IsValid__c = true;
        proSet1.Name = 'IXP-7P2';
        insertproductSets.add(proSet1);
        productSet__c proSet2 = new productSet__c();
        proSet2.Code__c = 'IXP-7P1SC';
        proSet2.Name = 'IXP-7P1SC';
        proSet2.IsValid__c = true;
        proSet2.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet2);
        productSet__c proSet3 = new productSet__c();
        proSet3.Code__c = 'IXSP-T7LED';
        proSet3.Name = 'IXSP-T7LED';
        proSet3.IsValid__c = true;
        proSet3.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet3);
        productSet__c proSet4 = new productSet__c();
        proSet4.Code__c = 'IXSP-T7LED4';
        proSet4.Name = 'IXSP-T7LED4';
        proSet4.IsValid__c = true;
        proSet4.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet4);
        productSet__c proSet5 = new productSet__c();
        proSet5.Code__c = 'IXSP-T7LED4';
        proSet5.Name = 'IXSP-T7LED4';
        proSet5.IsValid__c = true;
        proSet5.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet5);
        productSet__c proSet6 = new productSet__c();
        proSet6.Code__c = 'IXSP-T7LED4';
        proSet6.Name = 'IXSP-T7LED4';
        proSet6.IsValid__c = true;
        proSet6.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet6);
        productSet__c proSet7 = new productSet__c();
        proSet7.Code__c = 'IXSP-T7LED4';
        proSet7.Name = 'IXSP-T7LED4';
        proSet7.IsValid__c = true;
        proSet7.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet7);
        productSet__c proSet8 = new productSet__c();
        proSet8.Code__c = 'IXSP-T7LED4';
        proSet8.Name = 'IXSP-T7LED4';
        proSet8.IsValid__c = true;
        proSet8.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet8);
        productSet__c proSet9 = new productSet__c();
        proSet9.Code__c = 'IXSP-T7LED4';
        proSet9.Name = 'IXSP-T7LED4';
        proSet9.IsValid__c = true;
        proSet9.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet9);
        productSet__c proSet10 = new productSet__c();
        proSet10.Code__c = 'IXSP-T7LED4';
        proSet10.Name = 'IXSP-T7LED4';
        proSet10.IsValid__c = true;
        proSet10.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet10);
        productSet__c proSet11 = new productSet__c();
        proSet11.Code__c = 'IXP-7P2';
        proSet11.Name = 'IXP-7P2';
        proSet11.IsValid__c = true;
        proSet11.Name = 'IXP-7P2';
        insertproductSets.add(proSet11);
        productSet__c proSet12 = new productSet__c();
        proSet12.Code__c = 'IXP-7P1SC';
        proSet12.Name = 'IXP-7P1SC';
        proSet12.IsValid__c = true;
        proSet12.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet12);
        productSet__c proSet13 = new productSet__c();
        proSet13.Code__c = 'IXSP-T7LED';
        proSet13.Name = 'IXSP-T7LED';
        proSet13.IsValid__c = true;
        proSet13.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet13);
        productSet__c proSet14 = new productSet__c();
        proSet14.Code__c = 'IXSP-T7LED4';
        proSet14.Name = 'IXSP-T7LED4';
        proSet14.IsValid__c = true;
        proSet14.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet14);
        productSet__c proSet15 = new productSet__c();
        proSet15.Code__c = 'IXSP-T7LED4';
        proSet15.Name = 'IXSP-T7LED4';
        proSet15.IsValid__c = true;
        proSet15.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet15);
        productSet__c proSet16 = new productSet__c();
        proSet16.Code__c = 'IXSP-T7LED4';
        proSet16.Name = 'IXSP-T7LED4';
        proSet16.IsValid__c = true;
        proSet16.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet16);
        productSet__c proSet17 = new productSet__c();
        proSet17.Code__c = 'IXSP-T7LED4';
        proSet17.Name = 'IXSP-T7LED4';
        proSet17.IsValid__c = true;
        proSet17.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet17);
        productSet__c proSet18 = new productSet__c();
        proSet18.Code__c = 'IXSP-T7LED4';
        proSet18.Name = 'IXSP-T7LED4';
        proSet18.IsValid__c = true;
        proSet18.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet18);
        productSet__c proSet19 = new productSet__c();
        proSet19.Code__c = 'IXSP-T7LED4';
        proSet19.Name = 'IXSP-T7LED4';
        proSet19.IsValid__c = true;
        proSet19.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet19);
        productSet__c proSet20 = new productSet__c();
        proSet20.Code__c = 'IXSP-T7LED4';
        proSet20.Name = 'IXSP-T7LED4';
        proSet20.IsValid__c = true;
        proSet20.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet20);
        productSet__c proSet21 = new productSet__c();
        proSet21.Code__c = 'IXP-7P2';
        proSet21.Name = 'IXP-7P2';
        proSet21.IsValid__c = true;
        proSet21.Name = 'IXP-7P2';
        insertproductSets.add(proSet21);
        productSet__c proSet22 = new productSet__c();
        proSet22.Code__c = 'IXP-7P1SC';
        proSet22.Name = 'IXP-7P1SC';
        proSet22.IsValid__c = true;
        proSet22.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet22);
        productSet__c proSet23 = new productSet__c();
        proSet23.Code__c = 'IXSP-T7LED';
        proSet23.Name = 'IXSP-T7LED';
        proSet23.IsValid__c = true;
        proSet23.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet23);
        productSet__c proSet24 = new productSet__c();
        proSet24.Code__c = 'IXSP-T7LED4';
        proSet24.Name = 'IXSP-T7LED4';
        proSet24.IsValid__c = true;
        proSet24.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet24);
        productSet__c proSet25 = new productSet__c();
        proSet25.Code__c = 'IXSP-T7LED4';
        proSet25.Name = 'IXSP-T7LED4';
        proSet25.IsValid__c = true;
        proSet25.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet25);
        productSet__c proSet26 = new productSet__c();
        proSet26.Code__c = 'IXSP-T7LED4';
        proSet26.Name = 'IXSP-T7LED4';
        proSet26.IsValid__c = true;
        proSet26.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet26);
        productSet__c proSet27 = new productSet__c();
        proSet27.Code__c = 'IXSP-T7LED5';
        proSet27.Name = 'IXSP-T7LED5';
        proSet27.IsValid__c = true;
        proSet27.Name = 'IXSP-T7LED5';
        insertproductSets.add(proSet27);
        productSet__c proSet28 = new productSet__c();
        proSet28.Code__c = 'IXSP-T7LED4';
        proSet28.Name = 'IXSP-T7LED4';
        proSet28.IsValid__c = true;
        proSet28.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet28);
        productSet__c proSet29 = new productSet__c();
        proSet29.Code__c = 'IXSP-T7LED4';
        proSet29.Name = 'IXSP-T7LED4';
        proSet29.IsValid__c = true;
        proSet29.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet29);
        productSet__c proSet30 = new productSet__c();
        proSet30.Code__c = 'IXSP-T7LED4';
        proSet30.Name = 'IXSP-T7LED4';
        proSet30.IsValid__c = true;
        proSet30.Name = 'IXSP-T7LED4';
        insertproductSets.add(proSet30);

        insert insertproductSets;

        productSetItem__c  productSetItem = new productSetItem__c();
        productSetItem.productSet__c = proSet1.Id;
        productSetItem.Count__c = 5;
        productSetItem.product__c = product1.Id;
        insert productSetItem ;
        //List<productSet__c>  insertproductSets = new  List<productSet__c>(){
        //    proSet1,proSet2,proSet3,proSet4,proSet5,proSet6,proSet7,proSet8,proSet9,proSet10,
        //    proSet21,proSet22,proSet23,proSet24,proSet25,proSet26,proSet27,proSet28,proSet29,proSet30,
        //    proSet11,proSet12,proSet13,proSet14,proSet15,proSet16,proSet17,proSet18,proSet19,proSet20
        //};

        //PageReference page = new PageReference('/apex/SearchProduct?oppId=' + opp.Id + '&val=product1');
        PageReference page = new PageReference('/apex/NewQuoteEntry?id=' + quo.Id );
        //PageReference page = new PageReference('/apex/SearchSetProduct?gainQuoteSetNameAndSetQty=IXP-7P2%2C3%3BIXP-7P1SC%2C2');
        //PageReference page = new PageReference('/apex/SearchSetProduct??gainQuoteSetNameAndSetQty=');
        
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();
        
        controller.init();
        controller.Save();
        controller.decideORundecideQuote(quo.Id,true);
        controller.Decide();
        controller.setProduct_text = proSet1.Id+',1,49;'+proSet2.Id +',2,49;'+proSet3.Id+',3,49;'+proSet4.Id+',3,49;'+proSet5.Id+',1,49;'+proSet6.Id +',2,49;'+proSet7.Id+',3,49;'+proSet8.Id+',3,49;'+proSet9.Id+',3,49;'+proSet10.Id+',3,49;';
        controller.setProduct_text += proSet11.Id+',1,49;'+proSet12.Id +',2,49;'+proSet13.Id+',3,49;'+proSet14.Id+',3,49;'+proSet15.Id+',1,49;'+proSet16.Id +',2,49;'+proSet17.Id+',3,49;'+proSet18.Id+',3,49;'+proSet19.Id+',3,49;'+proSet20.Id+',3,49;';
        controller.setProduct_text += proSet21.Id+',1,49;'+proSet22.Id +',2,49;'+proSet23.Id+',3,49;'+proSet24.Id+',3,49;'+proSet25.Id+',1,49;'+proSet26.Id +',2,49;'+proSet27.Id+',3,49;'+proSet28.Id+',3,49;'+proSet29.Id+',3,49;'+proSet30.Id+',3,49;';
        controller.setProductEntry();
    }

    //产品配套相关
    @isTest 
    static void test_init5() {
        Id pricebookId = Test.getStandardPricebookId();

        Pricebook2 pricebook = new Pricebook2(
            Name = 'IE',
            ProductSegment__c = 'IE',
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            MachineParts__c = 'Machine',
            isActive = true
        );
        insert pricebook;

        Product2 product1 = new Product2();
        product1.Name = 'product1';
        product1.ProductCode = 'product1';
        product1.Product_ECCode__c = 'product1';
        product1.ProductModels__c = true;
        product1.ProductStatus__c = '1';
        product1.NMPAStatus_one__c = 'Z1';
        product1.MaterialStatus_one_Start__c = Date.today().addDays(-22);
        product1.MaterialStatus_one_End__c = Date.today().addDays(22);
        insert product1;

        PricebookEntry standardPrice1 = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = product1.Id,
            UnitPrice = 0,
            IsActive = true,
            CurrencyIsoCode = 'CNY'
        );
        insert standardPrice1;

        PricebookEntry entry1 = new PricebookEntry(Pricebook2Id = pricebook.Id, Product2Id = product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        insert entry1;

        Product_Search__c ps = new Product_Search__c(Product__c = product1.Id);

        List<RecordType> rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer IE'];
        Account user = new Account(
            Name = '*',
            FacilityName__c = 'user',
            PostCode__c = '123456',
            RecordTypeId = rectIE[0].Id
        );
        insert user;

        Opportunity opp = new Opportunity(
            Name = 'test opp',
            AccountId = user.Id,
            StageName = 'Prospect Created',
            CurrencyIsoCode = 'CNY',
            ProductSegment__c = 'IE',
            CloseDate = Date.today(),
            NewInquiryDate__c = Date.today().addDays(-2),
            ExpectedOrderDate__c = Date.today().addDays(2),
            TradeType__c = 'Taxation',
            SalesChannel__c = 'direct',
            Machine_Parts__c = 'Machine',
            Pricebook2Id = pricebook.Id
        );
        insert opp;
         Quote quo = new Quote(
            Name = 'quo',
            OpportunityId = opp.Id,
            SetName1__c = 'IXP-7P2',
            SetQty1__c = 1,
            Is_Decided__c = true
        );
        insert quo;
        List<productSet__c>  insertproductSets = new  List<productSet__c>();
        productSet__c proSet1 = new productSet__c();
        proSet1.Code__c = 'IXP-7P2';
        proSet1.Name = 'IXP-7P2';
        proSet1.IsValid__c = true;
        proSet1.Name = 'IXP-7P2';
        insertproductSets.add(proSet1);
        productSet__c proSet2 = new productSet__c();
        proSet2.Code__c = 'IXP-7P1SC';
        proSet2.Name = 'IXP-7P1SC';
        proSet2.IsValid__c = true;
        proSet2.Name = 'IXP-7P1SC';
        insertproductSets.add(proSet2);
        productSet__c proSet3 = new productSet__c();
        proSet3.Code__c = 'IXSP-T7LED';
        proSet3.Name = 'IXSP-T7LED';
        proSet3.IsValid__c = true;
        proSet3.Name = 'IXSP-T7LED';
        insertproductSets.add(proSet3);


        insert insertproductSets;

        productSetItem__c  productSetItem = new productSetItem__c();
        productSetItem.productSet__c = proSet1.Id;
        productSetItem.Count__c = 5;
        productSetItem.product__c = product1.Id;
        insert productSetItem ;
        PageReference page = new PageReference('/apex/NewQuoteEntry?id=' + quo.Id );
        System.Test.setCurrentPage(page);
        NewQuoteEntryController controller = new NewQuoteEntryController();
        Map<String,String> productSetCodeMap = new Map<String,String>();
        productSetCodeMap.put('IXP-7P1SC', '3;49');
        //productSetCodeMap.put('111111111', '3;49');
        controller.init();
        controller.setProduct_text = proSet1.Id+',1,49;'+proSet2.Id +',2,49;';
        controller.setProductEntry();
        controller.acquireProductSetId(productSetCodeMap);
        controller.Save();
        //controller.decideORundecideQuote(quo.Id,true);
        //controller.Decide();
    }

}