@isTest
private class NewQuoteIraiControllerTest {
    
    //新建报价委托，填入单品一个，set品一个，保存
    static testMethod void test01() {
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;
        //CHAN-BHNBX6 2019/11/26 START
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        //CHAN-BHNBX6 2019/11/26 END
        
        Product2 product1 = new Product2();
        product1.Name = '00107:高频电极，按钮形，4Fr.，软性';
        product1.SFDA_Status__c = '有効';
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '00107';
        product1.ProductCode = '00107';
        product1.SFDA_Approbated_Status__c = '有效';
        product1.Product_Status__c = '正常销售';
        product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_1__c=2150;
        product1.Intra_Trade_List_RMB_2__c=2150;
        product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.SFDA_Expiration_Date__c= Date.today();
        product1.LastbuyProductFLG__c = true;
        //CHAN-BHNBX6 2019/11/25 START
        // product1.Intra_Trade_Service_RMB__c = 2150;
        // product1.Entend_gurantee_period_all__c=1;
        //CHAN-BHNBX6 2019/11/25 END
        
        Product2 product2 = new Product2();
        product2.Name = '00103:软管接头';
        product2.SFDA_Status__c = '有効';
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '00103';
        product2.ProductCode = '00103';
        product2.SFDA_Approbated_Status__c = '有效';
        product2.Product_Status__c = '正常销售';
        product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_1__c=170;
        product2.Intra_Trade_List_RMB_2__c=170;
        product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c=10;
        product2.Intra_Trade_Cost_RMB_2__c=10;
        product2.SFDA_Expiration_Date__c= Date.today();
        // CHAN-BHNBX6 2019/11/25 START
        //product2.Intra_Trade_Service_RMB__c =170;
        //product2.Entend_gurantee_period_all__c=2;
        // CHAN-BHNBX6 2019/11/25 END
        
        Product2 product3 = new Product2();
        product3.Name = '00102.1:旋阀，免维护';
        product3.SFDA_Status__c = '有効';
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '00102.1';
        product3.ProductCode = '00102.1';
        product3.SFDA_Approbated_Status__c = '有效';
        product3.Product_Status__c = '正常销售';
        product3.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product3.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product3.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product3.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product3.Intra_Trade_List_RMB_1__c=920;
        product3.Intra_Trade_List_RMB_2__c=920;
        product3.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product3.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product3.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product3.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product3.Intra_Trade_Cost_RMB_1__c=10;
        product3.Intra_Trade_Cost_RMB_2__c=10;
        product3.SFDA_Expiration_Date__c= Date.today();
        // CHAN-BHNBX6 2019/11/25 START
        //product3.Intra_Trade_Service_RMB__c =920;
        //product3.Entend_gurantee_period_all__c=3;
        // CHAN-BHNBX6 2019/11/25 END
        
        insert new Product2[] {product1,product2,product3};
        
        Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
        
        insert new PricebookEntry[] {entry1,entry2,entry3};
        
        Product_Set__c pset1 = new Product_Set__c();
        pset1.Name = 'set1';
        pset1.CurrencyIsoCode = 'CNY';
        pset1.Product_Set_CD__c = 'test-set1';
        insert pset1;
        
        Product_Set_Detail__c psetd1 = new Product_Set_Detail__c();
        psetd1.CurrencyIsoCode = 'CNY';
        psetd1.Quantity__c = 10;
        psetd1.Product_Set__c = pset1.Id;
        psetd1.Product__c = product2.Id;
        insert psetd1;
        
        Product_Set_Detail__c psetd2 = new Product_Set_Detail__c();
        psetd2.CurrencyIsoCode = 'CNY';
        psetd2.Quantity__c = 10;
        psetd2.Product_Set__c = pset1.Id;
        psetd2.Product__c = product3.Id;
        insert psetd2;
        //CHAN-BHNBX6 2019/11/26 START
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount1.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product1.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = product2.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        //产品-产品注册证关系
        Product_Register_Link__c prlc3 = new Product_Register_Link__c(
                                                Product2__c = product3.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc3;
        product2 pro = [select id,SFDA_Status_New__c from product2 where id = :Product1.Id];
        //System.assertEquals('有効', pro.SFDA_Status_New__c);
        //CHAN-BHNBX6 2019/11/26 END
        PageReference page = new PageReference('/apex/NewQuoteIrai');
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        //初始化
        controller.init();
        
//         System.assertEquals(null, controller.quo.IraiSubject__c);
// //        System.assertEquals('CNY', controller.quo.CurrencyIsoCode);
//         System.assertEquals(null, controller.quo.IraiUser__c);
//         System.assertEquals(null, controller.activities[0].Asset_Model);
        
        controller.quo.IraiSubject__c = 'テスト01';
        controller.quo.IraiName__c = 'テスト02';
        controller.quo.IraiComment__c = 'テスト03';
        controller.quo.QuoteProportion__c = 10;
        controller.quo.IraiUser__c = user.Id;
        
        controller.activities[0].lineNo = 0;
        controller.activities[0].Asset_Model = '00107';
        controller.activities[0].pageObject.SFDA_Status__c = '有効';
        controller.activities[0].pageObject.Name__c = '00107:高频电极，按钮形，4Fr.，软性';
        controller.activities[0].pageObject.Product2__c = product1.Id;
        controller.activities[0].pageObject.Quantity__c = 1;
        controller.activities[0].ListPrice_Page = 2150;
        // controller.activities[0].pageObject.SFDA_Approbated_Status__c = '有效';
        // controller.activities[0].pageObject.Product_Status__c = '正常销售';
        // CHAN-BHNBX6 2019/11/25 START
        controller.activities[0].pageObject.GuaranteePeriod__c = 1;
        controller.activities[0].NoDiscount_Page = 2150;
        // CHAN-BHNBX6 2019/11/25 END


        
        controller.setProduct_text = pset1.Id;
        controller.setProductEntry();
        
        //System.assertEquals('00103', controller.activities[1].Asset_Model);
       // System.assertEquals(10, controller.activities[1].pageObject.Quantity__c);
        //System.assertEquals(170, controller.activities[1].ListPrice_Page);

        // CHAN-BHNBX6 2019/11/25 START
        //System.assertEquals(0, controller.activities[1].pageObject.GuaranteePeriod__c);
        //System.assertEquals(0, controller.activities[1].NoDiscount_Page);
        // CHAN-BHNBX6 2019/11/25 END
        //System.assertEquals('00102.1', controller.activities[2].Asset_Model);
        //System.assertEquals(10, controller.activities[2].pageObject.Quantity__c);
        //System.assertEquals(920, controller.activities[2].ListPrice_Page);
        // CHAN-BHNBX6 2019/11/25 START
        //System.assertEquals(0, controller.activities[2].pageObject.GuaranteePeriod__c);
        //System.assertEquals(0, controller.activities[2].NoDiscount_Page);
        // CHAN-BHNBX6 2019/11/25 END
        controller.Save();
        
        QuoteIrai__c[] irais = [select Id, Name,Note__c, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        // CHAN-BHNBX6 2019/11/25 START
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        // CHAN-BHNBX6 2019/11/25 END
        //System.assertEquals('テスト01', irais[0].IraiSubject__c);
        //System.assertEquals(user.Id, irais[0].IraiUser__c);
        //System.assertEquals('CNY', irais[0].CurrencyIsoCode);
        
        //System.assertEquals('00107', items[0].Asset_Model_No__c);
        // System.assertEquals('有効', items[0].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items[0].Name__c);
        // System.assertEquals(1, items[0].Quantity__c);
        // System.assertEquals(2150, items[0].ListPrice__c);
        // System.assertEquals('00107', items[0].ProductCode__c);
        // System.assertEquals(product1.Id, items[0].Product2__c);
        // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(1, items[0].GuaranteePeriod__c);
        // System.assertEquals(2150, items[0].ServicePrice__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00103', items[1].Asset_Model_No__c);
        // System.assertEquals('有効', items[1].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items[1].Name__c);
        // System.assertEquals(10, items[1].Quantity__c);
        // System.assertEquals(170, items[1].ListPrice__c);
        // System.assertEquals('00103', items[1].ProductCode__c);
        // System.assertEquals(product2.Id, items[1].Product2__c);
        // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(2, items[1].GuaranteePeriod__c);
        // System.assertEquals(170, items[1].ServicePrice__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00102.1', items[2].Asset_Model_No__c);
        // System.assertEquals('有効', items[2].SFDA_Status__c);
        // System.assertEquals('00102.1:旋阀，免维护', items[2].Name__c);
        // System.assertEquals(10, items[2].Quantity__c);
        // System.assertEquals(920, items[2].ListPrice__c);
        // System.assertEquals('00102.1', items[2].ProductCode__c);
        // System.assertEquals(product3.Id, items[2].Product2__c);
        // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(3, items[2].GuaranteePeriod__c);
        // System.assertEquals(920, items[2].ServicePrice__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.quoteIrai();
        
        QuoteIrai__c[] irais2 = [select Id,Note__c, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        //System.assertEquals('_サンブリッジ う', irais2[0].LastIraiUser__c);
        
        Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                        from Task where QuoteIraiId__c = :irais[0].Id];
                        
        // System.assertEquals('报价委托：テスト01， テスト02， テスト03， 10.00%', tasks[0].Subject);
        // System.assertEquals(user.Id, tasks[0].OwnerId);
        // System.assertEquals(irais[0].Id, tasks[0].QuoteIraiId__c);
        
        controller.activities[0].pageObject.Quantity__c = 1;
        controller.Save();
        QuoteIrai__c[] irais3 = [select Id,Note__c, Name, IraiUser__c, LastIraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト01'];
        //System.assertEquals(null, irais3[0].LastIraiUser__c);
    }
    
    //既存报价委托，有一条既存明细，修改既存明细的数量，添加set品一个，保存
    static testMethod void test02() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        Product2 product1 = new Product2();
        product1.Name = '00107:高频电极，按钮形，4Fr.，软性';
        product1.SFDA_Status__c = '有効';
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '00107';
        product1.ProductCode = '00107';
        product1.SFDA_Approbated_Status__c = '有效';
        product1.Product_Status__c = '正常销售';
        product1.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1);
        product1.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1);
        product1.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1);
        product1.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1);
        product1.Foreign_Trade_List_US_1__c=2150;
        product1.Foreign_Trade_List_US_2__c=2150;
        product1.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1);
        product1.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1);
        product1.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1);
        product1.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1);
        product1.Foreign_Trade_Cost_US_1__c=10;
        product1.Foreign_Trade_Cost_US_2__c=10;
        // product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
        
        Product2 product2 = new Product2();
        product2.Name = '00103:软管接头';
        product2.SFDA_Status__c = '有効';
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '00103';
        product2.ProductCode = '00103';
        product2.SFDA_Approbated_Status__c = '有效';
        product2.Product_Status__c = '正常销售';
        product2.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1);
        product2.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1);
        product2.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1);
        product2.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1);
        product2.Foreign_Trade_List_US_1__c=170;
        product2.Foreign_Trade_List_US_2__c=170;
        product2.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1);
        product2.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1);
        product2.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1);
        product2.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1);
        product2.Foreign_Trade_Cost_US_1__c=10;
        product2.Foreign_Trade_Cost_US_2__c=10;
        // CHAN-BHNBX6 2019/11/25 START
        //product2.Entend_gurantee_period_all__c=2;
        // CHAN-BHNBX6 2019/11/25 END
        Product2 product3 = new Product2();
        product3.Name = '00102.1:旋阀，免维护';
        product3.SFDA_Status__c = '有効';
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '00102.1';
        product3.ProductCode = '00102.1';
        product3.SFDA_Approbated_Status__c = '有效';
        product3.Product_Status__c = '正常销售';
        product3.Foreign_Trade_List_US_Date1__c=Date.today().addDays(-1);
        product3.Foreign_Trade_List_US_Date2__c=Date.today().addDays(-1);
        product3.Foreign_Trade_List_US_End_Date1__c=Date.today().addDays(1);
        product3.Foreign_Trade_List_US_End_Date2__c=Date.today().addDays(1);
        product3.Foreign_Trade_List_US_1__c=920;
        product3.Foreign_Trade_List_US_2__c=920;
        product3.Foreign_Trade_Cost_US_Date1__c=Date.today().addDays(-1);
        product3.Foreign_Trade_Cost_US_Date2__c=Date.today().addDays(-1);
        product3.Foreign_Trade_Cost_US_End_Date1__c=Date.today().addDays(1);
        product3.Foreign_Trade_Cost_US_End_Date2__c=Date.today().addDays(1);
        product3.Foreign_Trade_Cost_US_1__c=10;
        product3.Foreign_Trade_Cost_US_2__c=10;
        // CHAN-BHNBX6 2019/11/25 START
        //product3.Entend_gurantee_period_all__c=3;
        // CHAN-BHNBX6 2019/11/25 END
        
        insert new Product2[] {product1,product2,product3};
        
        Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'USD';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'USD';
        
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'USD';
        
        insert new PricebookEntry[] {entry1,entry2,entry3};
        
        QuoteIrai__c irai = new QuoteIrai__c();
        irai.IraiSubject__c = '委托01';
        irai.IraiUser__c = null;
        irai.CurrencyIsoCode = 'USD';
        insert irai;
        
        QuoteIraiLineItem__c item1 = new QuoteIraiLineItem__c();
        item1.SFDA_Status__c = '有効';
        item1.Name__c = '00107:高频电极，按钮形，4Fr.，软性';
        item1.Quantity__c = 1;
        item1.ListPrice__c = 2150;
        item1.Product2__c = product1.Id;
        item1.QuoteIrai__c = irai.Id;
        item1.ServicePrice__c = 2150;
        item1.GuaranteePeriod__c =1;
        insert item1;
        
        Product_Set__c pset1 = new Product_Set__c();
        pset1.Name = 'set1';
        pset1.CurrencyIsoCode = 'USD';
        pset1.Product_Set_CD__c = 'test-set1';
        insert pset1;
        
        Product_Set_Detail__c psetd1 = new Product_Set_Detail__c();
        psetd1.CurrencyIsoCode = 'USD';
        psetd1.Quantity__c = 10;
        psetd1.Product_Set__c = pset1.Id;
        psetd1.Product__c = product2.Id;
        insert psetd1;
        
        Product_Set_Detail__c psetd2 = new Product_Set_Detail__c();
        psetd2.CurrencyIsoCode = 'USD';
        psetd2.Quantity__c = 10;
        psetd2.Product_Set__c = pset1.Id;
        psetd2.Product__c = product3.Id;
        insert psetd2;
        
        //CHAN-BHNBX6 2019/11/26 START
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = Date.today().addMonths(6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount1.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product1.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = product2.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        //产品-产品注册证关系
        Product_Register_Link__c prlc3 = new Product_Register_Link__c(
                                                Product2__c = product3.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc3;
        product2 pro = [select id,SFDA_Status_New__c from product2 where id = :Product1.Id];
        //System.assertEquals('有効', pro.SFDA_Status_New__c);
        //CHAN-BHNBX6 2019/11/26 END
        PageReference page = new PageReference('/apex/NewQuoteIrai?id=' + irai.Id);
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        //初始化
        controller.init();
        
        // System.assertEquals('委托01', controller.quo.IraiSubject__c);
        // System.assertEquals('USD', controller.quo.CurrencyIsoCode);
        // System.assertEquals(null, controller.quo.IraiUser__c);
        
        // System.assertEquals(0, controller.activities[0].lineNo);
        // System.assertEquals('00107', controller.activities[0].Asset_Model);
        // System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', controller.activities[0].pageObject.Name__c);
        // System.assertEquals(1, controller.activities[0].pageObject.Quantity__c);
        // System.assertEquals(2150, controller.activities[0].ListPrice_Page);
        // System.assertEquals(product1.Id, controller.activities[0].pageObject.Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(2150, controller.activities[0].NoDiscount_Page);
        // System.assertEquals(1 ,controller.activities[0].pageObject.GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.quo.IraiSubject__c = 'テスト02';
        controller.activities[0].pageObject.Quantity__c = 2;
        
        controller.setProduct_text = pset1.Id;
        controller.setProductEntry();
        
        // System.assertEquals('00103', controller.activities[1].Asset_Model);
        // System.assertEquals(10, controller.activities[1].pageObject.Quantity__c);
        // System.assertEquals(170, controller.activities[1].ListPrice_Page);
        //  // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[1].NoDiscount_Page);
        // System.assertEquals(0, controller.activities[1].pageObject.GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        // System.assertEquals('00102.1', controller.activities[2].Asset_Model);
        // System.assertEquals(10, controller.activities[2].pageObject.Quantity__c);
        // System.assertEquals(920, controller.activities[2].ListPrice_Page);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[2].NoDiscount_Page);
        // System.assertEquals(0 ,controller.activities[2].pageObject.GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.OppReflection();
        
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト02'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト02', irais[0].IraiSubject__c);
        // System.assertEquals(null, irais[0].IraiUser__c);
        // System.assertEquals('USD', irais[0].CurrencyIsoCode);
        
        // System.assertEquals('00107', items[0].Asset_Model_No__c);
        // System.assertEquals('有効', items[0].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items[0].Name__c);
        // System.assertEquals(2, items[0].Quantity__c);
        // System.assertEquals(2150, items[0].ListPrice__c);
        // System.assertEquals('00107', items[0].ProductCode__c);
        // System.assertEquals(product1.Id, items[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[0].pageObject.GuaranteePeriod__c);
        // System.assertEquals(2150, controller.activities[0].NoDiscount_Page);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00103', items[1].Asset_Model_No__c);
        // System.assertEquals('有効', items[1].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items[1].Name__c);
        // System.assertEquals(10, items[1].Quantity__c);
        // System.assertEquals(170, items[1].ListPrice__c);
        // System.assertEquals('00103', items[1].ProductCode__c);
        // System.assertEquals(product2.Id, items[1].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[1].pageObject.GuaranteePeriod__c);
        // System.assertEquals(0, controller.activities[1].NoDiscount_Page);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00102.1', items[2].Asset_Model_No__c);
        // System.assertEquals('有効', items[2].SFDA_Status__c);
        // System.assertEquals('00102.1:旋阀，免维护', items[2].Name__c);
        // System.assertEquals(10, items[2].Quantity__c);
        // System.assertEquals(920, items[2].ListPrice__c);
        // System.assertEquals('00102.1', items[2].ProductCode__c);
        // System.assertEquals(product3.Id, items[2].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[2].pageObject.GuaranteePeriod__c);
        // System.assertEquals(0, controller.activities[2].NoDiscount_Page);
        // // CHAN-BHNBX6 2019/11/25 END
    }
    
    //委托按钮测试
    static testMethod void test03() {
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;

        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }

        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        
        Product2 product1 = new Product2();
        product1.Name = '00107:高频电极，按钮形，4Fr.，软性';
        product1.SFDA_Status__c = '有効';
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '00107';
        product1.ProductCode = '00107';
        product1.SFDA_Approbated_Status__c = '有效';
        product1.Product_Status__c = '正常销售';
        product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_1__c=2150;
        product1.Intra_Trade_List_RMB_2__c=2150;
        product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        // product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
        
        insert product1;
        
        Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        insert entry1;
        
        QuoteIrai__c irai = new QuoteIrai__c();
        irai.IraiSubject__c = '委托01';
        irai.IraiName__c = 'テスト01';
        irai.IraiComment__c = 'テスト02';
        irai.QuoteProportion__c = 5;
        irai.IraiUser__c = null;
        irai.CurrencyIsoCode = 'CNY';
        insert irai;
        
        //CHAN-BHNBX6 2019/11/26 START
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount1.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product1.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        
        product2 pro = [select id,SFDA_Status_New__c from product2 where id = :Product1.Id];
        //System.assertEquals('有効', pro.SFDA_Status_New__c);
        //CHAN-BHNBX6 2019/11/26 END
        PageReference page = new PageReference('/apex/NewQuoteIrai?id=' + irai.Id);
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        //初始化
        controller.init();
        
        // System.assertEquals('委托01', controller.quo.IraiSubject__c);
        // System.assertEquals('CNY', controller.quo.CurrencyIsoCode);
        // System.assertEquals(null, controller.quo.IraiUser__c);
        // System.assertEquals(null, controller.activities[0].Asset_Model);
        
        controller.quo.IraiSubject__c = '委托02';
        controller.quo.IraiName__c = 'テスト02';
        controller.quo.IraiComment__c = 'テスト03';
        controller.quo.QuoteProportion__c = 10;
        
        //没有选择委托人
        controller.quoteIrai();
        
        // System.assertEquals(true, controller.errorflg);
        // System.assertEquals('请选择委托人员。', controller.errorMessage);
        
        controller.quo.IraiUser__c = user.Id;
        
        //没有明细
        controller.quoteIrai();
        // System.assertEquals(true, controller.errorflg);
        // System.assertEquals('没有要委托的产品。', controller.errorMessage);
        
        controller.activities[0].lineNo = 0;
        controller.activities[0].Asset_Model = '00107';
        controller.activities[0].pageObject.SFDA_Status__c = '有効';
        controller.activities[0].pageObject.Name__c = '00107:高频电极，按钮形，4Fr.，软性';
        controller.activities[0].pageObject.Product2__c = product1.Id;
        controller.activities[0].pageObject.Quantity__c = 1;
        controller.activities[0].ListPrice_Page = 2150;
        // CHAN-BHNBX6 2019/11/25 START
        controller.activities[0].pageObject.GuaranteePeriod__c = 1;
        controller.activities[0].NoDiscount_Page = 2150;
        // CHAN-BHNBX6 2019/11/25 END
        
        //报价委托和task保存
        controller.quoteIrai();
        
        // System.assertEquals(true, controller.errorflg);
        // System.assertEquals('邮件发送完成。', controller.errorMessage);
        // System.assertEquals('你选择了不可报价的产品。产品已经更新为最新状态，请再次确认。', controller.errorMessage);

        
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托02'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('委托02', irais[0].IraiSubject__c);
        // System.assertEquals(user.Id, irais[0].IraiUser__c);
        
        // System.assertEquals('00107', items[0].Asset_Model_No__c);
        // System.assertEquals('有効', items[0].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items[0].Name__c);
        // System.assertEquals(1, items[0].Quantity__c);
        // System.assertEquals(2150, items[0].ListPrice__c);
        // System.assertEquals('00107', items[0].ProductCode__c);
        // System.assertEquals(product1.Id, items[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(2150, items[0].ServicePrice__c);
        // System.assertEquals(0 ,items[0].GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                        from Task where QuoteIraiId__c = :irais[0].Id];
                        
        // System.assertEquals('报价委托：委托02， テスト02， テスト03， 10.00%', tasks[0].Subject);
        // System.assertEquals(user.Id, tasks[0].OwnerId);
        // System.assertEquals(irais[0].Id, tasks[0].QuoteIraiId__c);
        
        controller.activities[0].pageObject.Quantity__c = 2;
        
        //Description更新
        controller.quoteIrai();
        
        QuoteIraiLineItem__c[] items2 = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('00107', items2[0].Asset_Model_No__c);
        // System.assertEquals('有効', items2[0].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items2[0].Name__c);
        // System.assertEquals(2, items2[0].Quantity__c);
        // System.assertEquals(2150, items2[0].ListPrice__c);
        // System.assertEquals('00107', items2[0].ProductCode__c);
        // System.assertEquals(product1.Id, items2[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(2150, items2[0].ServicePrice__c);
        // System.assertEquals(0 ,items2[0].GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        Task[] tasks2 = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                        from Task where QuoteIraiId__c = :irais[0].Id];
        
        //System.assertEquals(1, tasks2.size());
    }
    
    //再报价
    static testMethod void test04() {
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }

        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        
        Product2 product1 = new Product2();
        product1.Name = '00107:高频电极，按钮形，4Fr.，软性';
        product1.SFDA_Status__c = '有効';
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '00107';
        product1.ProductCode = '00107';
        product1.SFDA_Approbated_Status__c = '有效';
        product1.Product_Status__c = '正常销售';
        product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_1__c=2150;
        product1.Intra_Trade_List_RMB_2__c=2150;
        product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
        
        Product2 product2 = new Product2();
        product2.Name = '00103:软管接头';
        product2.SFDA_Status__c = '有効';
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '00103';
        product2.ProductCode = '00103';
        product2.SFDA_Approbated_Status__c = '有效';
        product2.Product_Status__c = '正常销售';
        product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_1__c=170;
        product2.Intra_Trade_List_RMB_2__c=170;
        product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c=10;
        product2.Intra_Trade_Cost_RMB_2__c=10;
        // CHAN-BHNBX6 2019/11/25 START
        //product2.Entend_gurantee_period_all__c=2;
        // CHAN-BHNBX6 2019/11/25 END
        
        insert new Product2[] {product1,product2};
        
        Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        
        insert new PricebookEntry[] {entry1,entry2};
        
        QuoteIrai__c irai = new QuoteIrai__c();
        irai.IraiSubject__c = '委托01';
        irai.IraiUser__c = null;
        irai.CurrencyIsoCode = 'CNY';
        irai.IraiUser__c = user.Id;
        insert irai;
        
        QuoteIraiLineItem__c item1 = new QuoteIraiLineItem__c();
        item1.SFDA_Status__c = '有効';
        item1.Name__c = '00107:高频电极，按钮形，4Fr.，软性';
        item1.Quantity__c = 1;
        item1.ListPrice__c = 2150;
        item1.ServicePrice__c = 12580;
        item1.Product2__c = product1.Id;
        item1.QuoteIrai__c = irai.Id;
        insert item1;
        
        QuoteIraiLineItem__c item2 = new QuoteIraiLineItem__c();
        item2.SFDA_Status__c = '有効';
        item2.Name__c = '00103:软管接头';
        item2.Quantity__c = 10;
        item2.ListPrice__c = 170;
        item2.ServicePrice__c = 12580;
        item2.Product2__c = product2.Id;
        item2.QuoteIrai__c = irai.Id;
        insert item2;
        
        //CHAN-BHNBX6 2019/11/26 START
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount1.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = date.newinstance(2018, 07, 22),
                                                ValidTo__c = date.newinstance(2028, 07, 22),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product1.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = product2.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        product2 pro = [select id,SFDA_Status_New__c from product2 where id = :Product1.Id];
        //System.assertEquals('有効', pro.SFDA_Status_New__c);
        //CHAN-BHNBX6 2019/11/26 END
        PageReference page = new PageReference('/apex/NewQuoteIrai?copyid=' + irai.Id);
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        //初始化
        controller.init();
        
       //  System.assertEquals('', controller.quo.IraiSubject__c);
       // // System.assertEquals('CNY', controller.quo.CurrencyIsoCode);
       //  System.assertEquals(null, controller.quo.IraiUser__c);
        
       //  System.assertEquals(0, controller.activities[0].lineNo);
       //  System.assertEquals('00107', controller.activities[0].Asset_Model);
       //  System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c);
       //  System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', controller.activities[0].pageObject.Name__c);
       //  System.assertEquals(1, controller.activities[0].pageObject.Quantity__c);
       //  System.assertEquals(2150, controller.activities[0].ListPrice_Page);
       //  System.assertEquals(product1.Id, controller.activities[0].pageObject.Product2__c);
       //  // CHAN-BHNBX6 2019/11/25 START
       //  System.assertEquals(12580, controller.activities[0].NoDiscount_Page);
       //  // System.assertEquals(0 ,controller.activities[0].pageObject.GuaranteePeriod__c);
       //  // CHAN-BHNBX6 2019/11/25 END
        
       //  System.assertEquals(1, controller.activities[1].lineNo);
       //  System.assertEquals('00103', controller.activities[1].Asset_Model);
       //  System.assertEquals('有効', controller.activities[1].pageObject.SFDA_Status__c);
       //  System.assertEquals('00103:软管接头', controller.activities[1].pageObject.Name__c);
       //  System.assertEquals(10, controller.activities[1].pageObject.Quantity__c);
       //  System.assertEquals(170, controller.activities[1].ListPrice_Page);
       //  System.assertEquals(product2.Id, controller.activities[1].pageObject.Product2__c);
       //  // CHAN-BHNBX6 2019/11/25 START
       //  System.assertEquals(12580, controller.activities[1].NoDiscount_Page);
       //  // System.assertEquals(0 ,controller.activities[1].pageObject.GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.quo.IraiSubject__c = '委托99';
        controller.quo.IraiName__c = 'テスト99';
        controller.quo.IraiComment__c = 'テスト99';
        controller.quo.QuoteProportion__c = 99;
        
        controller.quo.IraiUser__c = user.Id;
        
        controller.quoteIrai();
        
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c order where IraiSubject__c = '委托99'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('委托99', irais[0].IraiSubject__c);
        // System.assertEquals(user.Id, irais[0].IraiUser__c);
        
        // System.assertEquals('00107', items[0].Asset_Model_No__c);
        // System.assertEquals('有効', items[0].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items[0].Name__c);
        // System.assertEquals(1, items[0].Quantity__c);
        // System.assertEquals(2150, items[0].ListPrice__c);
        // System.assertEquals('00107', items[0].ProductCode__c);
        // System.assertEquals(product1.Id, items[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(12580, items[0].ServicePrice__c);
        // // System.assertEquals(0,items[0].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00103', items[1].Asset_Model_No__c);
        // System.assertEquals('有効', items[1].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items[1].Name__c);
        // System.assertEquals(10, items[1].Quantity__c);
        // System.assertEquals(170, items[1].ListPrice__c);
        // System.assertEquals('00103', items[1].ProductCode__c);
        // System.assertEquals(product2.Id, items[1].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(12580, items[1].ServicePrice__c);
        // // System.assertEquals(0,items[1].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                        from Task where QuoteIraiId__c = :irais[0].Id];
                        
        // System.assertEquals('报价委托：委托99， テスト99， テスト99， 99.00%', tasks[0].Subject);
        // System.assertEquals(user.Id, tasks[0].OwnerId);
        // System.assertEquals(irais[0].Id, tasks[0].QuoteIraiId__c);
        controller.Save();
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'test';
        opp1.StageName = '引合';
        opp1.CloseDate = Date.today().adddays(1);
        insert opp1;
        
        QuoteLineItem[] qlis = [select id,QuoteId,PricebookEntry.Product2Id from QuoteLineItem where PricebookEntry.Product2Id != :null limit 1];
        String str = '';
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        LastbuyProduct__c lst = new LastbuyProduct__c();
        lst.InquiryCode__c= opp1.Id;
        lst.ProductName__c = Product1.Id;
        lst.LastbuyQuantity__c = 3;
        lst.effectiveFLG__c = true;
        insert lst;
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();
        LastbuyProduct__c lst2 = new LastbuyProduct__c();
        lst2.InquiryCode__c= opp1.Id;
        lst2.ProductName__c = Product2.Id;
        lst2.LastbuyQuantity__c = 3;
        lst2.effectiveFLG__c = true;
        insert lst2;
        PageReference page3 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page3);
        NewQuoteIraiController controller3 = new NewQuoteIraiController();
        controller3.init();
                
    }

    //新建报价委托，excel导入明细一条，保存；再excel导入明细三条，委托
    static testMethod void test05() {
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympustest03@sunbridge.com';
        user.Username = 'olympustest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__c = '上海市';
        user.Use_Start_Date__c = Date.today().addMonths(-6);
        insert user;

        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }

        //经销商、联系人、用户信息
        Account myAccount1 = new Account(name='Testaccount001',
                                        Dealer_discount__c =20,
                                        Ban_On_Use_Date__c = Date.today().addDays(1),
                                        Business_Paper_Expiration_Date__c = Date.today().addDays(1),
                                        Tax_Practice_Expiration_Date__c = Date.today().addDays(1),
                                        Medical_Equipment_Expiration_Date__c = Date.today().addDays(1),
                                        RecordTypeId = rectCo[0].Id);
        insert myAccount1;
        
        Product2 product1 = new Product2();
        product1.Name = '00107:高频电极，按钮形，4Fr.，软性';
        product1.SFDA_Status__c = '有効';
        product1.Manual_Entry__c = false;
        product1.Asset_Model_No__c = '00107';
        product1.ProductCode = '00107';
        product1.SFDA_Approbated_Status__c = '有效';
        product1.Product_Status__c = '正常销售';
        product1.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_List_RMB_1__c=2150;
        product1.Intra_Trade_List_RMB_2__c=2150;
        product1.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product1.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product1.Intra_Trade_Cost_RMB_1__c=10;
        product1.Intra_Trade_Cost_RMB_2__c=10;
        product1.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product1.Entend_gurantee_period_all__c=1;
        // CHAN-BHNBX6 2019/11/25 END
        
        Product2 product2 = new Product2();
        product2.Name = '00103:软管接头';
        product2.SFDA_Status__c = '有効';
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '00103';
        product2.ProductCode = '00103';
        product2.SFDA_Approbated_Status__c = '有效';
        product2.Product_Status__c = '正常销售';
        product2.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_List_RMB_1__c=170;
        product2.Intra_Trade_List_RMB_2__c=170;
        product2.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product2.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c=10;
        product2.Intra_Trade_Cost_RMB_2__c=10;
        product2.LastbuyProductFLG__c = true;
        // CHAN-BHNBX6 2019/11/25 START
        //product2.Entend_gurantee_period_all__c=2;
        // CHAN-BHNBX6 2019/11/25 END
        
        Product2 product3 = new Product2();
        product3.Name = '00102.1:旋阀，免维护';
        product3.SFDA_Status__c = '有効';
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '00102.1';
        product3.ProductCode = '00102.1';
        product3.SFDA_Approbated_Status__c = '有效';
        product3.Product_Status__c = '正常销售';
        product3.Intra_Trade_List_RMB_Date1__c=Date.today().addDays(-1);
        product3.Intra_Trade_List_RMB_Date2__c=Date.today().addDays(-1);
        product3.Intra_Trade_List_RMB_End_Date1__c=Date.today().addDays(1);
        product3.Intra_Trade_List_RMB_End_Date2__c=Date.today().addDays(1);
        product3.Intra_Trade_List_RMB_1__c=920;
        product3.Intra_Trade_List_RMB_2__c=920;
        product3.Intra_Trade_Cost_RMB_Date1__c=Date.today().addDays(-1);
        product3.Intra_Trade_Cost_RMB_Date2__c=Date.today().addDays(-1);
        product3.Intra_Trade_Cost_RMB_End_Date1__c=Date.today().addDays(1);
        product3.Intra_Trade_Cost_RMB_End_Date2__c=Date.today().addDays(1);
        product3.Intra_Trade_Cost_RMB_1__c=10;
        product3.Intra_Trade_Cost_RMB_2__c=10;
        // CHAN-BHNBX6 2019/11/25 START
       // product3.Entend_gurantee_period_all__c=3;
        // CHAN-BHNBX6 2019/11/25 END
        
        insert new Product2[] {product1,product2,product3};
        
        Pricebook2 pricebook = ControllerUtil.getStandardPricebook();
        
        PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id);
        entry1.UnitPrice = 0;
        entry1.IsActive = true;
        entry1.UseStandardPrice = false;
        entry1.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id);
        entry2.UnitPrice = 0;
        entry2.IsActive = true;
        entry2.UseStandardPrice = false;
        entry2.CurrencyIsoCode = 'CNY';
        
        PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id);
        entry3.UnitPrice = 0;
        entry3.IsActive = true;
        entry3.UseStandardPrice = false;
        entry3.CurrencyIsoCode = 'CNY';
        
        insert new PricebookEntry[] {entry1,entry2,entry3};
        
        //CHAN-BHNBX6 2019/11/26 START
        /* 注册证相关信息 */
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = Date.today().addMonths(6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = myAccount1.Id
                                                );
        insert linc;
        //System.assertEquals('123',linc.ScopeKey__c);
        //产品注册证
        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
                                                MedPrdClass__c = '3',
                                                ValidFrom__c = Date.today().addMonths(-6),
                                                ValidTo__c = Date.today().addMonths(6),
                                                RegisterNoClass_Old__c = '6815',
                                                RegisterNoClass_New__c = '6815',
                                                RegisterNoStatus__c = '有效'
                                                );
        insert prc;
        //新旧关系对照表
        Product_Register_contrast__c prcc = new Product_Register_contrast__c(
                                                Name = 'Test20181204',
                                                Register_new__c = '314',
                                                Register_old__c = '36815'
                                                );
        insert prcc;
        //产品-产品注册证关系  prod01
        Product_Register_Link__c  prlc = new Product_Register_Link__c(
                                                Product2__c = product1.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = product2.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        //产品-产品注册证关系
        Product_Register_Link__c prlc3 = new Product_Register_Link__c(
                                                Product2__c = product3.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc3;
        product2 pro = [select id,SFDA_Status_New__c from product2 where id = :Product1.Id];
        //System.assertEquals('有効', pro.SFDA_Status_New__c);
        //CHAN-BHNBX6 2019/11/26 END
        PageReference page = new PageReference('/apex/NewQuoteIrai');
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        //初始化
        controller.init();
        
        // System.assertEquals(null, controller.quo.IraiSubject__c);
        // //System.assertEquals('CNY', controller.quo.CurrencyIsoCode);
        // System.assertEquals(null, controller.quo.IraiUser__c);
        // System.assertEquals(null, controller.activities[0].Asset_Model);
        
        controller.quo.IraiSubject__c = 'テスト05';
        
        controller.excel_text = '00103\t10';
        controller.excelImport();
        
        //System.assertEquals('00103', controller.activities[0].Asset_Model);
        // System.assertEquals('停止', controller.activities[0].pageObject.SFDA_Status__c);
       // System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c);
        // System.assertEquals('00103:软管接头', controller.activities[0].pageObject.Name__c);
        // System.assertEquals(10, controller.activities[0].pageObject.Quantity__c);
        // System.assertEquals(product2.Id, controller.activities[0].pageObject.Product2__c);
        // System.assertEquals(0, controller.activities[0].pageObject.GuaranteePeriod__c);
        // System.assertEquals(0, controller.activities[0].NoDiscount_Page);
        
        controller.Save();
        
        QuoteIrai__c[] irais = [select Id,Note__c, Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIraiLineItem__c[] items = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト05', irais[0].IraiSubject__c);
        // System.assertEquals(null, irais[0].IraiUser__c);
        // System.assertEquals('CNY', irais[0].CurrencyIsoCode);
        
        // System.assertEquals('00103', items[0].Asset_Model_No__c);
        // System.assertEquals('有効', items[0].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items[0].Name__c);
        // System.assertEquals(10, items[0].Quantity__c);
        // System.assertEquals('00103', items[0].ProductCode__c);
        // System.assertEquals(product2.Id, items[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, items[0].ServicePrice__c);
        // System.assertEquals(0, items[0].GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.quo.IraiUser__c = user.Id;
        controller.excel_text = '00103\t10\n00102.1\t10\n00107\t2';
        controller.excelImport();
        
        // System.assertEquals('00103', controller.activities[0].Asset_Model);
        // System.assertEquals('有効', controller.activities[0].pageObject.SFDA_Status__c);
        // System.assertEquals('00103:软管接头', controller.activities[0].pageObject.Name__c);
        // System.assertEquals(10, controller.activities[0].pageObject.Quantity__c);
        // System.assertEquals(product2.Id, controller.activities[0].pageObject.Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[0].NoDiscount_Page);
        // System.assertEquals(0,controller.activities[0].pageObject.GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00103', controller.activities[1].Asset_Model);
        // System.assertEquals('有効', controller.activities[1].pageObject.SFDA_Status__c);
        // System.assertEquals('00103:软管接头', controller.activities[1].pageObject.Name__c);
        // System.assertEquals(10, controller.activities[1].pageObject.Quantity__c);
        // System.assertEquals(product2.Id, controller.activities[1].pageObject.Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[1].NoDiscount_Page);
        // System.assertEquals(0, controller.activities[1].pageObject.GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00102.1', controller.activities[2].Asset_Model);
        // System.assertEquals('有効', controller.activities[2].pageObject.SFDA_Status__c);
        // System.assertEquals('00102.1:旋阀，免维护', controller.activities[2].pageObject.Name__c);
        // System.assertEquals(10, controller.activities[2].pageObject.Quantity__c);
        // System.assertEquals(product3.Id, controller.activities[2].pageObject.Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[2].NoDiscount_Page);
        // // System.assertEquals(1 ,controller.activities[2].pageObject.GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00107', controller.activities[3].Asset_Model);
        // System.assertEquals('有効', controller.activities[3].pageObject.SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', controller.activities[3].pageObject.Name__c);
        // System.assertEquals(2, controller.activities[3].pageObject.Quantity__c);
        // System.assertEquals(product1.Id, controller.activities[3].pageObject.Product2__c);
        //  // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, controller.activities[3].NoDiscount_Page);
        // System.assertEquals(0, controller.activities[3].pageObject.GuaranteePeriod__c);
        // CHAN-BHNBX6 2019/11/25 END
        
        controller.quoteIrai();

        QuoteIrai__c[] irais2 = [select Id, Note__c,Name, IraiUser__c, IraiSubject__c, CurrencyIsoCode from QuoteIrai__c where IraiSubject__c = 'テスト05'];
        QuoteIraiLineItem__c[] items2 = [select Id, Asset_Model_No__c, SFDA_Status__c, Name__c,Quantity__c, ListPrice__c, ProductCode__c,Product2__c,ServicePrice__c,GuaranteePeriod__c from QuoteIraiLineItem__c where QuoteIrai__c = :irais2[0].Id order by Item_Order__c];
        
        // System.assertEquals('テスト05', irais2[0].IraiSubject__c);
        // System.assertEquals(user.Id, irais2[0].IraiUser__c);
        // System.assertEquals('CNY', irais2[0].CurrencyIsoCode);
        
        // System.assertEquals('00103', items2[0].Asset_Model_No__c);
        // System.assertEquals('有効', items2[0].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items2[0].Name__c);
        // System.assertEquals(10, items2[0].Quantity__c);
        // System.assertEquals('00103', items2[0].ProductCode__c);
        // System.assertEquals(product2.Id, items2[0].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, items2[0].ServicePrice__c);
        // System.assertEquals(0 ,items2[0].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END

        // System.assertEquals('00103', items2[1].Asset_Model_No__c);
        // System.assertEquals('有効', items2[1].SFDA_Status__c);
        // System.assertEquals('00103:软管接头', items2[1].Name__c);
        // System.assertEquals(10, items2[1].Quantity__c);
        // System.assertEquals('00103', items2[1].ProductCode__c);
        // System.assertEquals(product2.Id, items2[1].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, items2[1].ServicePrice__c);
        // System.assertEquals(0 ,items2[1].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00102.1', items2[2].Asset_Model_No__c);
        // System.assertEquals('有効', items2[2].SFDA_Status__c);
        // System.assertEquals('00102.1:旋阀，免维护', items2[2].Name__c);
        // System.assertEquals(10, items2[2].Quantity__c);
        // System.assertEquals('00102.1', items2[2].ProductCode__c);
        // System.assertEquals(product3.Id, items2[2].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, items2[2].ServicePrice__c);
        // // System.assertEquals(0 ,items2[2].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        // System.assertEquals('00107', items2[3].Asset_Model_No__c);
        // System.assertEquals('有効', items2[3].SFDA_Status__c);
        // System.assertEquals('00107:高频电极，按钮形，4Fr.，软性', items2[3].Name__c);
        // System.assertEquals(2, items2[3].Quantity__c);
        // System.assertEquals('00107', items2[3].ProductCode__c);
        // System.assertEquals(product1.Id, items2[3].Product2__c);
        // // CHAN-BHNBX6 2019/11/25 START
        // System.assertEquals(0, items2[3].ServicePrice__c);
        // // System.assertEquals(1 ,items2[3].GuaranteePeriod__c);
        // // CHAN-BHNBX6 2019/11/25 END
        
        Task[] tasks = [select Id,Subject,OwnerId,Description,ActivityDate,QuoteIraiId__c
                        from Task where QuoteIraiId__c = :irais2[0].Id];
                        
        // System.assertEquals('报价委托：テスト05', tasks[0].Subject);
        // System.assertEquals(user.Id, tasks[0].OwnerId);
        // System.assertEquals(irais2[0].Id, tasks[0].QuoteIraiId__c);
        
        // 商品状态刷新
        Product2 p2 = [select Id, SFDA_Status__c,Name from Product2 where Id = :product2.Id];
        p2.SFDA_Status__c = '停止';
        p2.Name = '00103:软管接头123';
        update p2;
        
        controller.Save();
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'test';
        opp1.StageName = '引合';
        opp1.CloseDate = Date.today().adddays(1);
        insert opp1;
        
        QuoteLineItem[] qlis = [select id,QuoteId,PricebookEntry.Product2Id from QuoteLineItem where PricebookEntry.Product2Id != :null limit 1];
        String str = '';
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        LastbuyProduct__c lst = new LastbuyProduct__c();
        lst.InquiryCode__c= opp1.Id;
        lst.ProductName__c = Product1.Id;
        lst.LastbuyQuantity__c = 3;
        lst.effectiveFLG__c = true;
        insert lst;
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();
        LastbuyProduct__c lst2 = new LastbuyProduct__c();
        lst2.InquiryCode__c= opp1.Id;
        lst2.ProductName__c = Product2.Id;
        lst2.LastbuyQuantity__c = 3;
        lst2.effectiveFLG__c = true;
        insert lst2;
        PageReference page3 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page3);
        NewQuoteIraiController controller3 = new NewQuoteIraiController();
        controller3.init();
        // System.assertEquals(true, controller.errorflg);
        // System.assertEquals('停止', controller.activities[0].pageObject.SFDA_Status__c);
        // System.assertEquals('00103:软管接头123', controller.activities[0].pageObject.Name__c);
    }
    
    //其他单体函数
    static testMethod void test06() {
        QuoteIrai__c irai = new QuoteIrai__c();
        irai.IraiSubject__c = '委托01';
        irai.IraiUser__c = null;
        irai.CurrencyIsoCode = 'CNY';
        insert irai;
        
        PageReference page = new PageReference('/apex/NewQuoteIrai?id=' + irai.Id);
        System.Test.setCurrentPage(page);
        
        NewQuoteIraiController controller = new NewQuoteIraiController();
        controller.init();
        controller.checkIraiUser();
        controller.Back();
        
        // 从潜在客户新建
        Lead lead1 = new Lead();
        lead1.LastName = 'test';
        lead1.Company = 'test';
        insert lead1;
        
        PageReference page1 = new PageReference('/apex/NewQuoteIrai?leadid=' + lead1.Id);
        System.Test.setCurrentPage(page1);
        NewQuoteIraiController controller1 = new NewQuoteIraiController();
        controller1.init();
        
        // 从业务机会新建
        Opportunity opp1 = new Opportunity();
        opp1.Name = 'test';
        opp1.StageName = '引合';
        opp1.CloseDate = Date.today().adddays(1);
        insert opp1;
        
        QuoteLineItem[] qlis = [select id,QuoteId,PricebookEntry.Product2Id from QuoteLineItem where PricebookEntry.Product2Id != :null limit 1];
        String str = '';
        if (qlis.size() > 0) {
            str = qlis[0].QuoteId;
        }
        // LastbuyProduct__c lst = new LastbuyProduct__c();
        // lst.InquiryCode__c= opp1.Id;
        // lst.ProductName__c = Product1.Id;
        // lst.LastbuyQuantity__c = 3;
        system.debug('opp1.Id+++'+opp1.Id);
        PageReference page2 = new PageReference('/apex/NewQuoteIrai?oppid=' + opp1.Id + '&oppquoid=' + str);
        System.Test.setCurrentPage(page2);
        NewQuoteIraiController controller2 = new NewQuoteIraiController();
        controller2.init();

        // 经销商询价新建
        Agency_Opportunity__c agenOpp = new Agency_Opportunity__c();
        agenOpp.Name = 'test';
        agenOpp.Department_Cateogy__c = 'GI';
        insert agenOpp;
        PageReference page3 = new PageReference('/apex/NewQuoteIrai?agencyoppid=' + agenOpp.Id);
        System.Test.setCurrentPage(page3);
        NewQuoteIraiController controller3 = new NewQuoteIraiController();
        controller3.init();
    }
}