@isTest
private  class ConsumableControllerTest {
    static Account myAccount2;          //经销商
    static Account contract;            //经销商合同
    static Contact core;                //联系人
    static user myUser_Test;            //经销商合同
    static Product2__c pro1;            //产品检索1
    static Product2__c pro2;            //产品检索2
    static Product2__c pro3;            //产品检索3
    static Product2__c pro4;            //产品检索4
    static Product2__c pro5;            //产品检索5
    static void initHpData() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '契約'];
        if (rectCo1.size() == 0) {
            return;
        }
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
        Product2 prod01 = new Product2(Name='Test01',
                            ProductCode='Test01',
                            Asset_Model_No__c = 'Test01',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'CDS',
                            Category4__c = 'OER',
                            Category5__c = '其它',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test001',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1)
                            );

        Product2 prod02 = new Product2(Name='Test02',
                            ProductCode='Test02',
                            Asset_Model_No__c = 'Test02',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'ENT',
                            Category4__c = 'Celon',
                            Category5__c = 'Celon',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test002',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1)
                            );

        Product2 prod03 = new Product2(Name='Test03',
                            ProductCode='Test03',
                            Asset_Model_No__c = 'Test03',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'US',
                            Category4__c = 'ALOKA',
                            Category5__c = '体外超声',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));

        Product2 prod04 = new Product2(Name='Test04',
            ProductCode='Test04',Asset_Model_No__c = 'Test04',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'OCS',
                            Category4__c = '附属品',
                            Category5__c = 'OCS',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));
        Product2 prod05 = new Product2(Name='Test05',
                            ProductCode='Test05',
                            Asset_Model_No__c = 'Test05',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = '光源',
                            Category4__c = 'CLV',
                            Category5__c = 'S45',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));
        insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
        pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
        pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
        pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
        insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};

        myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
        //正确合同
        contract = new Account(Name ='contractName',ParentId = myAccount2.id,Agent_Ref__c =myAccount2.id, Contract_Department_Class__c = 'ET',ET_SP_Dealer__c = true,Contract_Decide_Start_Date__c=Date.today().addDays(-2),
            Contract_Decide_End_Date__c = Date.today().addDays(2),Dealer_discount__c = 0.8,RecordTypeId = rectCo1[0].Id);
        insert contract;

        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
        insert core;
        myUser_Test = New User(ContactId = core.id,Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com');
        insert myUser_Test;
        /* 注册证相关信息 */
        //医疗器械经营许可证
        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 = myAccount2.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 = prod01.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = prod02.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        //产品检索共享设置
        Product2__Share dcTS1 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro1.id );
        insert dcTS1;
        Product2__Share dcTS2 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro2.id );
        insert dcTS2;
        Product2__Share dcTS3 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro3.id );
        insert dcTS3;
        Product2__Share dcTS4 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro4.id );
        insert dcTS4;
        Product2__Share dcTS5 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro5.id );
        insert dcTS5;

    }
    //add by rentx start 
    static void initHpDataENG() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
        if (rectCo.size() == 0) {
            return;
        }
        Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限'];
        Product2 prod01 = new Product2(Name='Test01',
                            ProductCode='Test01',
                            Asset_Model_No__c = 'Test01',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'CDS',
                            Category4__c = 'OER',
                            Category5__c = '其它',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test001',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1)
                            );

        Product2 prod02 = new Product2(Name='Test02',
                            ProductCode='Test02',
                            Asset_Model_No__c = 'Test02',
                            SFDA_Status__c = '有効',
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'ENT',
                            Category4__c = 'Celon',
                            Category5__c = 'Celon',
                            Dealer_special_Object__c = true,
                            SFDA_Approbation_No__c = 'Test002',
                            Packing_list_manual__c = 1,
                            SFDA_Expiration_Date__c= Date.today(),
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_Date2__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1)
                            );

        Product2 prod03 = new Product2(Name='Test03',
                            ProductCode='Test03',
                            Asset_Model_No__c = 'Test03',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'US',
                            Category4__c = 'ALOKA',
                            Category5__c = '体外超声',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));

        Product2 prod04 = new Product2(Name='Test04',
            ProductCode='Test04',Asset_Model_No__c = 'Test04',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = 'OCS',
                            Category4__c = '附属品',
                            Category5__c = 'OCS',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));
        Product2 prod05 = new Product2(Name='Test05',
                            ProductCode='Test05',
                            Asset_Model_No__c = 'Test05',
                            SFDA_Status__c = '有効',
                            Dealer_special_Object__c = true,
                            Product_Status__c = '正常销售',
                            SFDA_Approbated_Status__c = '有效',
                            Category3__c = '光源',
                            Category4__c = 'CLV',
                            Category5__c = 'S45',
                            Intra_Trade_List_RMB_1__c = 1000,
                            Intra_Trade_List_RMB_Date1__c = Date.today().addDays(-1),
                            Intra_Trade_List_RMB_End_Date1__c = Date.today().addDays(1));
        insert new Product2[] {prod01,prod02,prod03, prod04, prod05};
        pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
        pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
        pro3 = new Product2__c(Name='Pro003',OT_CODE_Text__c='Test003',Product2__c = prod03.Id);
        pro4 = new Product2__c(Name='Pro004',OT_CODE_Text__c='Test004',Product2__c = prod04.Id);
        pro5 = new Product2__c(Name='Pro005',OT_CODE_Text__c='Test005',Product2__c = prod05.Id);
        insert new Product2__c[] {pro1,pro2,pro3,pro4, pro5};

        myAccount2 = new Account(Name='Testaccount002',Dealer_discount__c =20,RecordTypeId = rectCo[0].Id,Product_Limit_Date__c = 'Test01|2|4,Test02|3|5');
        insert myAccount2;
        //正确合同
        contract = new Account(Name ='contractName',ParentId = myAccount2.id,Agent_Ref__c =myAccount2.id, Contract_Department_Class__c = 'ENG',ENG_Dealer__c = true,Contract_Decide_Start_Date__c=Date.today().addDays(-2),
            Contract_Decide_End_Date__c = Date.today().addDays(2),Dealer_discount__c = 0.8);
        insert contract;

        core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount2.id);
        insert core;
        myUser_Test = New User(ContactId = core.id,UserPro_Type__c = 'ENG',Alias = 'newUser',Email='newuser@testorg.com',EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='zh_CN',LocaleSidKey='zh_CN', ProfileId = prof.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com');
        insert myUser_Test;
        /* 注册证相关信息 */
        //医疗器械经营许可证
        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 = myAccount2.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 = prod01.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc;
        //产品-产品注册证关系  prod02
        Product_Register_Link__c  prlc2 = new Product_Register_Link__c(
                                                Product2__c = prod02.Id,
                                                Product_Register__c = prc.Id
                                                ); 
        insert prlc2;
        //产品检索共享设置
        Product2__Share dcTS1 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro1.id );
        insert dcTS1;
        Product2__Share dcTS2 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro2.id );
        insert dcTS2;
        Product2__Share dcTS3 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro3.id );
        insert dcTS3;
        Product2__Share dcTS4 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro4.id );
        insert dcTS4;
        Product2__Share dcTS5 = new Product2__Share(UserOrGroupId=myUser_Test.Id,  AccessLevel='Read', ParentId =pro5.id );
        insert dcTS5;

    }

    static testMethod void testInitAgreement(){
        initHpData();
        system.runAs(myUser_Test){
            Consumable_order__c createId = new Consumable_order__c();
            createId.Name = 'testMing-01';
            createId.Order_status__c = '草案中';
            createId.Deliver_date__c = Date.today();
            createId.Dealer_Info__c = myAccount2.Id;
            createId.RecordTypeid = System.Label.RT_ConOrder_Order;
            createId.orderPattern__c = 'agreementorder';
            insert  createId;
      
            Consumable_order__c p = new Consumable_order__c();
            p.Name = 'test-01';
            p.Dealer_Info__c = myAccount2.Id;
            p.Offers_Price__c = 1;
            p.Order_date__c = Date.today();
            p.Order_Reason__c ='其它';
            insert  p;

            Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
            createDetailc.Name = 'Too00-01';
            createDetailc.Consumable_Product__c = pro1.id;
            createDetailc.Consumable_count__c = 0;
            createDetailc.Consumable_order__c =  createId.id;
            createDetailc.Box_Piece__c = '盒';
            createDetailc.Special_Campaign_Price__c= 1;
            createDetailc.Intra_Trade_List_RMB__c = 1;
            createDetailc.Purchase_Unitprtprice_From__c = '促销';
            createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetailc;

            Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
            createDetail.Name = 'OCM_01_001';
            createDetail.Consumable_Product__c = pro1.id;
            createDetail.Consumable_count__c = 0;
            createDetail.Consumable_order__c =  p.id;
            createDetail.Box_Piece__c = '盒';
            createDetail.Special_Campaign_Price__c= 1;
            createDetail.Intra_Trade_List_RMB__c = 1;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;

            Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
            createDetail1.Name = 'Too0-01';
            createDetail1.Consumable_Product__c = pro2.id;
            createDetail1.Consumable_order__c =  createId.id;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            createDetail1.Box_Piece__c = '盒';
            createDetail1.Special_Campaign_Price__c= 1;
            createDetail1.Consumable_count__c = 10;
            createDetail1.Intra_Trade_List_RMB__c = 1;
            insert createDetail1;

            Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
            Orderdet1.Name = 'OCM_01_001001';
            Orderdet1.Consumable_order_minor__c = createId.Id;
            Orderdet1.Consumable_Arrived_order__c = createId.Id;
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Sterilization_limit__c = Date.today().addDays(1);
            Orderdet1.Bar_Code__c = '11111';
            Orderdet1.Consumable_product__c = pro1.Id;
            Orderdet1.Arrive_date__c = Date.today();
            Orderdet1.Send_Date__c = null;
            Orderdet1.Used_date__c = null;
            Orderdet1.Lose_Flag__c = false;
            Orderdet1.Sterilization_limit__c = Date.today().addDays(1);

            Oly_TriggerHandler.bypass('ConsumableAssetHander');
            insert Orderdet1;

            PageReference page = new PageReference('/apex/Consumable?type=agreementorder');
            // page.setRedirect(true);
            System.Test.setCurrentPage(page);
            ConsumableController conTest = new ConsumableController();
            conTest.init();
            conTest.categoryAllload();
            conTest.categoryload();
            conTest.OffersPrice();
            conTest.SortLimited();
            conTest.save();
            // 为了提升代码覆盖率,无意义
            conTest.dealerPricesee = true;
            conTest.tempidHp = 'notnull';
            conTest.ESetId = '12345';
            conTest.methodType = 'agreementorder';
            conTest.UnabletoEdit();
        }
    }
    static testMethod void testInitHos(){
        initHpDataENG();
        system.runAs(myUser_Test){
            Test.startTest();
                Consumable_order__c createId = new Consumable_order__c();
                createId.Name = 'testMing1';
                createId.Order_status__c = '批准';
                createId.Deliver_date__c = Date.today();
                createId.Dealer_Info__c = myAccount2.Id;
                createId.RecordTypeid = System.Label.RT_ConOrder_Delivery;
                createId.Order_type__c = '订单';
                createId.Order_ProType__c = 'ENG';
                createId.Dealer_Info__c = myAccount2.Id;
                createId.Delivery_detail_count__c = 5;
                createId.orderPattern__c = 'hospitalorder';
                // createId.Name = 'testMing-01';
                // createId.Order_status__c = '草案中';
                // createId.Deliver_date__c = Date.today();
                // createId.Dealer_Info__c = myAccount2.Id;
                // createId.RecordTypeid = System.Label.RT_ConOrder_Order;
                // createId.orderPattern__c = 'hospitalorder';
                insert  createId;
          
                Consumable_order__c p = new Consumable_order__c();
                p.Name = 'test-01';
                p.Dealer_Info__c = myAccount2.Id;
                p.Offers_Price__c = 1;
                p.Order_date__c = Date.today();
                p.Order_Reason__c ='其它';
                p.orderPattern__c = 'hospitalorder';
                insert  p;

                Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
                createDetailc.Name = 'Too00-01';
                createDetailc.Consumable_Product__c = pro1.id;
                createDetailc.Consumable_count__c = 0;
                createDetailc.Consumable_order__c =  createId.id;
                createDetailc.Box_Piece__c = '盒';
                createDetailc.Special_Campaign_Price__c= 1;
                createDetailc.Intra_Trade_List_RMB__c = 1;
                createDetailc.Purchase_Unitprtprice_From__c = '促销';
                createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetailc;

                Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
                createDetail.Name = 'OCM_01_001';
                createDetail.Consumable_Product__c = pro1.id;
                createDetail.Consumable_count__c = 0;
                createDetail.Consumable_order__c =  p.id;
                createDetail.Box_Piece__c = '盒';
                createDetail.Special_Campaign_Price__c= 1;
                createDetail.Intra_Trade_List_RMB__c = 1;
                createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetail;

                Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
                createDetail1.Name = 'Too0-01';
                createDetail1.Consumable_Product__c = pro2.id;
                createDetail1.Consumable_order__c =  createId.id;
                createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                createDetail1.Box_Piece__c = '盒';
                createDetail1.Special_Campaign_Price__c= 1;
                createDetail1.Consumable_count__c = 10;
                createDetail1.Intra_Trade_List_RMB__c = 1;
                insert createDetail1;

                Consumable_order_details2__c createDetail2 = new Consumable_order_details2__c();
                createDetail2 = new Consumable_order_details2__c();
                createDetail2.Consumable_Product__c = pro1.id;
                createDetail2.Asset_Model_No__c     = 'Test01';
                createDetail2.Consumable_order_minor__c =  createId.id;
                createDetail2.Consumable_Arrived_order__c = createId.id;
                createDetail2.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
                createDetail2.Asset_Model_No__c         = pro1.Asset_Model_No__c;
                createDetail2.Bar_Code__c = '123';
                createDetail2.Box_Piece__c ='盒';
                createDetail2.Arrive_date__c            = Date.today();

                Oly_TriggerHandler.bypass('ConsumableAssetHander');
                insert createDetail2;
                

                //创建医院
                Account hospital = new Account();
                hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
                hospital.Name = 'test hospital';
                hospital.Is_Active__c = '有効';
                hospital.Attribute_Type__c = '卫生部';
                hospital.Speciality_Type__c = '综合医院';
                hospital.Grade__c = '一级';
                hospital.OCM_Category__c = 'SLTV';
                hospital.Is_Medical__c = '医疗机构';
                hospital.Town__c = '东京';
                insert hospital;

                //建一条医院特价产品
                hospitalprice__c hc = new hospitalprice__c();
                hc.hospital__c = hospital.Id;
                hc.product__c = pro1.Id;
                hc.aph__c = '12332';
                hc.account__c = myAccount2.Id;
                insert hc;


                System.debug('518:: hc:'+hc.account__c +'  '+hc);
                System.debug('519:: user:'+myUser_Test.AccountId +'  '+myUser_Test);

                PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id+'&type=hospitalorder');
                // page.setRedirect(true);
                System.Test.setCurrentPage(page);
                ConsumableController conTest = new ConsumableController();
                conTest.hospitalId = hospital.Id;
                conTest.hospitalName = hospital.Name;
                conTest.init();
                conTest.OffersPrice();
                conTest.SortLimited();
                conTest.hospitalId = hospital.Id;
                conTest.hospitalName = hospital.Name;
                conTest.searchConsumableorderdetails();
                conTest.save();
                conTest.searchorderdetails();
                page = new PageReference('/apex/Consumable');
                System.Test.setCurrentPage(page);
                conTest.SortLimited();
            Test.stopTest();
        }
    }
    
    static testMethod void testPromotionorder(){
        initHpDataENG();
        Dealer_Product__c dpc = new Dealer_Product__c();
        dpc.Dealer_Contact__c = contract.id;
        dpc.Dealer_Product2__c = pro1.id;
        dpc.Special_Discount__c = 45;
        dpc.Campaign_StartDate__c = Date.today().addDays(-1);
        dpc.Campaign_EndDate__c = Date.today().addDays(1);
        insert dpc;
        
        Dealer_Product__c dpc2 = new Dealer_Product__c();
        dpc2.Dealer_Contact__c = contract.id;
        dpc2.Dealer_Product2__c = pro1.id;
        dpc2.Special_Campaign_Price__c = 4500;
        insert dpc2;
        
        Dealer_Product__c dpc1 = new Dealer_Product__c();
        dpc1.Dealer_Contact__c = contract.id;
        dpc1.Dealer_Product2__c = pro2.id;
        dpc1.Special_Campaign_Price__c = 23456;
        insert dpc1;
        system.runAs(myUser_Test){
            Test.startTest();
                Consumable_order__c createId = new Consumable_order__c();
                createId.Name = 'testMing1';
                createId.Order_status__c = '批准';
                createId.Deliver_date__c = Date.today();
                createId.Dealer_Info__c = myAccount2.Id;
                createId.RecordTypeid = System.Label.RT_ConOrder_Delivery;
                createId.Order_type__c = '订单';
                createId.Order_ProType__c = 'ENG';
                createId.Dealer_Info__c = myAccount2.Id;
                createId.Delivery_detail_count__c = 5;
                createId.orderPattern__c = 'promotionorder';
                insert  createId;
          
                Consumable_order__c p = new Consumable_order__c();
                p.Name = 'test-01';
                p.Dealer_Info__c = myAccount2.Id;
                p.Offers_Price__c = 1;
                p.Order_date__c = Date.today();
                p.Order_Reason__c ='其它';
                p.orderPattern__c = 'promotionorder';
                insert  p;

                Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
                createDetailc.Name = 'Too00-01';
                createDetailc.Consumable_Product__c = pro1.id;
                createDetailc.Consumable_count__c = 0;
                createDetailc.Consumable_order__c =  createId.id;
                createDetailc.Box_Piece__c = '盒';
                createDetailc.Special_Campaign_Price__c= 1;
                createDetailc.Intra_Trade_List_RMB__c = 1;
                createDetailc.Purchase_Unitprtprice_From__c = '促销';
                createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetailc;
            
                Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
                createDetail.Name = 'OCM_01_001';
                createDetail.Consumable_Product__c = pro1.id;
                createDetail.Consumable_count__c = 0;
                createDetail.Consumable_order__c =  p.id;
                createDetail.Box_Piece__c = '盒';
                createDetail.Special_Campaign_Price__c= 1;
                createDetail.Intra_Trade_List_RMB__c = 1;
                createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetail;

                Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
                createDetail1.Name = 'Too0-01';
                createDetail1.Consumable_Product__c = pro2.id;
                createDetail1.Consumable_order__c =  createId.id;
                createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                createDetail1.Box_Piece__c = '盒';
                createDetail1.Special_Campaign_Price__c= 1;
                createDetail1.Consumable_count__c = 10;
                createDetail1.Intra_Trade_List_RMB__c = 1;
                insert createDetail1;

                Consumable_order_details2__c createDetail2 = new Consumable_order_details2__c();
                createDetail2 = new Consumable_order_details2__c();
                createDetail2.Consumable_Product__c = pro1.id;
                createDetail2.Asset_Model_No__c     = 'Test01';
                createDetail2.Consumable_order_minor__c =  createId.id;
                createDetail2.Consumable_Arrived_order__c = createId.id;
                createDetail2.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
                createDetail2.Asset_Model_No__c         = pro1.Asset_Model_No__c;
                createDetail2.Bar_Code__c = '123';
                createDetail2.Box_Piece__c ='盒';
                createDetail2.Arrive_date__c            = Date.today();

                Oly_TriggerHandler.bypass('ConsumableAssetHander');
                insert createDetail2;

                PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id+'&type=promotionorder');
                // page.setRedirect(true);
                System.Test.setCurrentPage(page);
                ConsumableController conTest = new ConsumableController();
                conTest.contractName = 'contractName';
                conTest.init();
                conTest.searchorderdetails();
                conTest.OffersPrice();
                conTest.SortLimited();
                conTest.searchConsumableorderdetails();
                conTest.setEditAble();
                conTest.backOrder();
                conTest.contractName = 'contractName';
                conTest.save();
            Test.stopTest();
        }
    }
    static testMethod void testAgreementorder(){
        initHpDataENG();
        Dealer_Product__c dpc = new Dealer_Product__c();
        dpc.Dealer_Contact__c = contract.id;
        dpc.Dealer_Product2__c = pro1.id;
        dpc.Special_Discount__c = 45;
        dpc.Campaign_StartDate__c = Date.today().addDays(-1);
        dpc.Campaign_EndDate__c = Date.today().addDays(1);
        insert dpc;
        
        Dealer_Product__c dpc2 = new Dealer_Product__c();
        dpc2.Dealer_Contact__c = contract.id;
        dpc2.Dealer_Product2__c = pro1.id;
        dpc2.Special_Campaign_Price__c = 4500;
        insert dpc2;
        
        Dealer_Product__c dpc1 = new Dealer_Product__c();
        dpc1.Dealer_Contact__c = contract.id;
        dpc1.Dealer_Product2__c = pro2.id;
        dpc1.Special_Campaign_Price__c = 23456;
        insert dpc1;
        system.runAs(myUser_Test){
            Test.startTest();
                Consumable_order__c createId = new Consumable_order__c();
                createId.Name = 'testMing1';
                createId.Order_status__c = '批准';
                createId.Deliver_date__c = Date.today();
                createId.Dealer_Info__c = myAccount2.Id;
                createId.RecordTypeid = System.Label.RT_ConOrder_Delivery;
                createId.Order_type__c = '订单';
                createId.Order_ProType__c = 'ENG';
                createId.Dealer_Info__c = myAccount2.Id;
                createId.Delivery_detail_count__c = 5;
                createId.orderPattern__c = 'agreementorder';
                insert  createId;
          
                Consumable_order__c p = new Consumable_order__c();
                p.Name = 'test-01';
                p.Dealer_Info__c = myAccount2.Id;
                p.Offers_Price__c = 1;
                p.Order_date__c = Date.today();
                p.Order_Reason__c ='其它';
                p.orderPattern__c = 'agreementorder';
                insert  p;

                Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
                createDetailc.Name = 'Too00-01';
                createDetailc.Consumable_Product__c = pro1.id;
                createDetailc.Consumable_count__c = 0;
                createDetailc.Consumable_order__c =  createId.id;
                createDetailc.Box_Piece__c = '盒';
                createDetailc.Special_Campaign_Price__c= 1;
                createDetailc.Intra_Trade_List_RMB__c = 1;
                createDetailc.Purchase_Unitprtprice_From__c = '促销';
                createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetailc;
            
                Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
                createDetail.Name = 'OCM_01_001';
                createDetail.Consumable_Product__c = pro1.id;
                createDetail.Consumable_count__c = 0;
                createDetail.Consumable_order__c =  p.id;
                createDetail.Box_Piece__c = '盒';
                createDetail.Special_Campaign_Price__c= 1;
                createDetail.Intra_Trade_List_RMB__c = 1;
                createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                insert createDetail;

                Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
                createDetail1.Name = 'Too0-01';
                createDetail1.Consumable_Product__c = pro2.id;
                createDetail1.Consumable_order__c =  createId.id;
                createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
                createDetail1.Box_Piece__c = '盒';
                createDetail1.Special_Campaign_Price__c= 1;
                createDetail1.Consumable_count__c = 10;
                createDetail1.Intra_Trade_List_RMB__c = 1;
                insert createDetail1;

                Consumable_order_details2__c createDetail2 = new Consumable_order_details2__c();
                createDetail2 = new Consumable_order_details2__c();
                createDetail2.Consumable_Product__c = pro1.id;
                createDetail2.Asset_Model_No__c     = 'Test01';
                createDetail2.Consumable_order_minor__c =  createId.id;
                createDetail2.Consumable_Arrived_order__c = createId.id;
                createDetail2.RecordTypeid = System.Label.RT_ConOrderDetail2_Delivery;
                createDetail2.Asset_Model_No__c         = pro1.Asset_Model_No__c;
                createDetail2.Bar_Code__c = '123';
                createDetail2.Box_Piece__c ='盒';
                createDetail2.Arrive_date__c            = Date.today();

                Oly_TriggerHandler.bypass('ConsumableAssetHander');
                insert createDetail2;

                PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id+'&type=agreementorder');
                // page.setRedirect(true);
                System.Test.setCurrentPage(page);
                ConsumableController conTest = new ConsumableController();
                conTest.contractName = 'contractName';
                conTest.init();
                conTest.OffersPrice();
                conTest.SortLimited();
                conTest.searchConsumableorderdetails();
                conTest.setEditAble();
                conTest.backOrder();
                conTest.contractName = 'contractName';
                conTest.save();
            Test.stopTest();
        }
    }

    //add by rentx end

    //NEW ORDER
    static testMethod void ConsumableTest_NewOrder(){
        initHpData();
        system.runAs(myUser_Test){
            PageReference page = new PageReference('/apex/Consumable?type=agreementorder');
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            ConsumableController conTest = new ConsumableController();
            System.Test.startTest();
            conTest.init();
            conTest.size = 2;
            conTest.SortLimited();
            conTest.searchConsumableorderdetails();
            System.assertEquals(5, conTest.ConsumableorderdetailsCount);
            System.assertEquals(5, conTest.ConsumableorderdetailsviewCount);
            conTest.coc.Order_status__c = '草案中';
            conTest.coc.Deliver_date__c = Date.today();
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 0;
            conTest.save();

            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 10;
            conTest.con.next();
            conTest.refreshPageSize();
            conTest.SortStore();
            conTest.save();

            system.assertEquals(5,conTest.consumableorderdetailsRecordsview.size());
            conTest.contractName = 'contractName2';
            conTest.save();

            conTest.contractName = 'contractName';
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = null;
            conTest.save();
            conTest.consumableorderdetailsRecordsview.sort();
            System.Test.stopTest();
        }
    }

    static testMethod void ConsumableTest_NewOrder1(){
        initHpData();
        system.runAs(myUser_Test){
            PageReference page = new PageReference('/apex/Consumable?type=agreementorder');
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            //page = new Pagereference('/Consumable?ESetid='+createId.id);
            //page.setRedirect(true);
            ConsumableController conTest = new ConsumableController();
            conTest.methodType = 'promotionorder';
            conTest.init();
            
            system.assertEquals(5,conTest.consumableorderdetailsRecordsview.size());
            conTest.contractName = 'contractName';
            conTest.coc.Offers_Price__c = 3800;
            conTest.coc.Order_Reason__c = '123';
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = 200;
            conTest.consumableorderdetailsRecordsview[1].check= true;
            conTest.ConsumableorderdetailsRecordsview[1].esd.Consumable_Count__c = 5;
            //conTest.ConsumableorderdetailsRecordsview[1].esd.Dealer_Custom_Price__c = 300;
            conTest.save();

            conTest.consumableorderdetailsRecordsview.sort();
        }
    }




    static testMethod void ConsumableTestSaveWithEsetid(){
        initHpData();
        system.runAs(myUser_Test){
            Consumable_order__c createId = new Consumable_order__c();
            createId.Name = 'testMing';
            createId.Order_status__c = '草案中';
            createId.Deliver_date__c = Date.today();
            createId.Dealer_Info__c = myAccount2.Id;
            createId.RecordTypeid = System.Label.RT_ConOrder_Order;
            createId.Order_ProType__c = 'ET';
            insert  createId;
            Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
            createDetail.Name = 'Too001';
            createDetail.Consumable_Product__c = pro1.id;
            createDetail.Consumable_count__c = 888.00;
            createDetail.Consumable_order__c =  createId.id;
            createDetail.Box_Piece__c = '盒';
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;
            Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
            createDetail1.Name = 'Too002';
            createDetail1.Consumable_Product__c = pro2.id;
            createDetail1.Consumable_order__c =  createId.id;
            createDetail1.Consumable_count__c = 888.00;
            createDetail1.Box_Piece__c = '盒';
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;
            PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id+'&type=agreementorder');
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            ConsumableController conTest = new ConsumableController();
            conTest.methodType = 'hospitalorder';
            conTest.init();
            system.assertEquals(2,conTest.consumableorderdetailsRecordsview.size());
            conTest.contractName = 'contractName';
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = 200;
            conTest.consumableorderdetailsRecordsview[1].check= true;
            conTest.ConsumableorderdetailsRecordsview[1].esd.Consumable_Count__c = 0;
            //conTest.ConsumableorderdetailsRecordsview[1].esd.Dealer_Custom_Price__c = 300;
            conTest.save();

            conTest.searchConsumableorderdetails();
            conTest.sortKey ='5';
            conTest.SortLimited();
            conTest.SortStore();
            
            PageReference page1 = new PageReference('/apex/Consumable?ESetid='+createId.id + '&KeyWords=statusEdit&type=agreementorder');
            page1.setRedirect(true);
            System.Test.setCurrentPage(page1);
            conTest = new ConsumableController();
            System.Test.startTest();
            conTest.init();
            conTest.searchConsumableorderdetails();
            conTest.consumableorderdetailsRecordsview.sort();
            conTest.SortLimited();
            conTest.SortStore();
            conTest.ordrCopy();
            // conTest.setEditAble();
            conTest.product2s();
            // conTest.backOrder();
            conTest.FilesUpload();
            //conTest.Sorder();
            conTest.printConsumable();
            conTest.consumableorderdetailsRecordsview.sort();
            conTest.returnOrderPage();
            System.Test.stopTest();
            //System.assertEquals(1, conTest.consumableorderdetailsRecordsview[0].size());
        }
    }

    static testMethod void ConsumableTestSaveWithEsetid1(){
    initHpData();
    system.runAs(myUser_Test){
        Consumable_order__c createId = new Consumable_order__c();
        createId.Name = 'testMing';
        createId.Order_status__c = '草案中';
        createId.Deliver_date__c = Date.today();
        createId.Dealer_Info__c = myAccount2.Id;
        createId.RecordTypeid = System.Label.RT_ConOrder_Order;
        createId.Order_ProType__c = 'ET';
        createId.orderPattern__c = 'hospitalorder';
        insert  createId;
        Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
        createDetail.Name = 'Too001';
        createDetail.Consumable_Product__c = pro1.id;
        //createDetail.Dealer_Custom_Price__c = 999.00;
        createDetail.Consumable_count__c = 888.00;
        //createDetail.Sum_of_money__c = 999.99;
        createDetail.Consumable_order__c =  createId.id;
        createDetail.Box_Piece__c = '盒';
        //createDetail.Sterilization_limit__c = Date.today();
        //createDetail.Consumable_principal__c = createId.id;
        createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
        insert createDetail;
        Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
        createDetail1.Name = 'Too002';
        createDetail1.Consumable_Product__c = pro2.id;
        createDetail1.Consumable_order__c =  createId.id;
        //createDetail1.Sterilization_limit__c = Date.today();
        //createDetail1.Dealer_Custom_Price__c = 999.00;
        createDetail1.Consumable_count__c = 888.00;
        createDetail1.Box_Piece__c = '盒';
        //createDetail1.Sum_of_money__c = 999.99;
        //createDetail1.Consumable_principal__c = createId.id;
        createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
        insert createDetail1;
        PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id+'&type=agreementorder');
        page.setRedirect(true);
        System.Test.setCurrentPage(page);
        ConsumableController conTest = new ConsumableController();
        System.Test.startTest();
        conTest.methodType = 'hospitalorder';
        conTest.init();
        system.assertEquals(2,conTest.consumableorderdetailsRecordsview.size());
        conTest.contractName = 'contractName';
        conTest.consumableorderdetailsRecordsview[0].check= true;
        conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
        //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = 200;
        conTest.consumableorderdetailsRecordsview[1].check= true;
        conTest.ConsumableorderdetailsRecordsview[1].esd.Consumable_Count__c = 0;
        //conTest.ConsumableorderdetailsRecordsview[1].esd.Dealer_Custom_Price__c = 300;
        conTest.save();

        conTest.searchConsumableorderdetails();
        conTest.sortKey ='5';
        conTest.SortLimited();
        conTest.SortStore();
        
        PageReference page1 = new PageReference('/apex/Consumable?ESetid='+createId.id + '&KeyWords=statusEdit');
        page1.setRedirect(true);
        System.Test.setCurrentPage(page1);
        conTest = new ConsumableController();
        conTest.methodType = 'hospitalorder';
        conTest.init();
        conTest.searchConsumableorderdetails();
        conTest.consumableorderdetailsRecordsview.sort();
        conTest.SortLimited();
        conTest.SortStore();
        
        conTest.FilesUpload();
        conTest.Sorder();
        conTest.DelConsumable();
        conTest.printConsumable();
        conTest.consumableorderdetailsRecordsview.sort();
        conTest.returnOrderPage();
        System.Test.stopTest();
        //System.assertEquals(1, conTest.consumableorderdetailsRecordsview[0].size());
        }
    }
    static testMethod void neworderWithoutId(){
        initHpData();

        Dealer_Product__c dealer = new Dealer_Product__c();
        //dealer.Name = 'A';
        dealer.Dealer_Contact__c = contract.Id;
        dealer.Campaign_StartDate__c = Date.today();
        dealer.Campaign_EndDate__c =Date.today();
        dealer.Special_Campaign_Price__c = 10;
        dealer.Agent_Ref__c= myAccount2.Id;
        dealer.Special_Discount__c = 0.2;
        dealer.Dealer_Product2__c = pro2.Id;
        Dealer_Product__c dealer1 = new Dealer_Product__c();
        //dealer1.Name = 'B';
        dealer1.Dealer_Contact__c = contract.Id;
        dealer1.Campaign_StartDate__c = Date.today();
        dealer1.Campaign_EndDate__c =Date.today();
        dealer1.Special_Campaign_Price__c = 15;
        dealer1.Agent_Ref__c= myAccount2.Id;
        dealer1.Special_Discount__c = 0.5;
        dealer1.Dealer_Product2__c = pro1.Id;
        Dealer_Product__c dealer2 = new Dealer_Product__c();
        //dealer2.Name = 'C';
        dealer2.Dealer_Contact__c = contract.Id;
        dealer2.Campaign_StartDate__c = Date.today().addDays(-1);
        dealer2.Campaign_EndDate__c =Date.today().addDays(1);
        dealer2.Special_Campaign_Price__c = 13;
        dealer2.Agent_Ref__c= myAccount2.Id;
        dealer2.Special_Discount__c = 0.7;
        dealer2.Dealer_Product2__c = pro2.Id;
        insert new Dealer_Product__c[] {dealer, dealer1,dealer2};

        
        system.runAs(myUser_Test){
            PageReference page = new PageReference('/apex/Consumable?type=agreementorder');
            System.Test.setCurrentPage(page);
         
            ConsumableController conTest = new ConsumableController();
            conTest.methodType = 'promotionorder';
            conTest.size =1;
            System.Test.startTest();
            conTest.init();
            conTest.SortLimited();
            conTest.SortStore();
            conTest.searchConsumableorderdetails();
            System.Test.stopTest();
        }
    }


    static testMethod void  ConsumableSaveTest(){
        initHpData();
        system.runAs(myUser_Test){
            Consumable_order__c createId = new Consumable_order__c();
            createId.Name = 'testMing-0';
            createId.Order_status__c = '草案中';
            createId.Deliver_date__c = Date.today();
            createId.Dealer_Info__c = myAccount2.Id;
            createId.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  createId;
            Consumable_order__c createId2 = new Consumable_order__c();
            createId2.Name = 'testMing';
            createId2.Order_status__c = '批准';
            createId2.Order_date__c = Date.today();
            createId2.Deliver_date__c = Date.today();
            createId2.Dealer_Info__c = myAccount2.Id;
            createId2.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  createId2;
            Consumable_order__c createId1 = new Consumable_order__c();
            createId1.Name = 'testMing';
            createId1.Order_status__c = '已提交';
            createId1.Order_date__c = Date.today();
            createId1.Deliver_date__c = Date.today();
            createId1.Dealer_Info__c = myAccount2.Id;
            createId1.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  createId1;

            Consumable_order__c p = new Consumable_order__c();
            p.Name = 'test-01';
            p.Order_status__c = '草案中';
            p.Dealer_Info__c = myAccount2.Id;
            p.Offers_Price__c = 1;
            p.Order_date__c = Date.today();
            //p.Order_effective_contact__c = contract.Id;
            p.Order_Reason__c ='其它';
            p.RecordTypeid = System.Label.RT_ConOrder_Order;
            p.Overrule_order__c = createId.Id;
            insert  p;

            Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
            createDetailc.Name = 'Too001-0';
            createDetailc.Consumable_Product__c = pro1.id;
            //createDetailc.Dealer_Custom_Price__c = 999.00;
            createDetailc.Consumable_count__c = 1;
            //createDetail.Sum_of_money__c = 999.99;
            createDetailc.Consumable_order__c =  createId.id;
            createDetailc.Box_Piece__c = '盒';
            createDetailc.Special_Campaign_Price__c= 1;
            createDetailc.Intra_Trade_List_RMB__c = 1;
            createDetailc.Purchase_Unitprtprice_From__c = '促销';
            //createDetail.Sterilization_limit__c = Date.today();
            //createDetail.Consumable_principal__c = createId.id;
            createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetailc;
            Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
            createDetail.Name = 'Too0-01';
            createDetail.Consumable_Product__c = pro1.id;
            //createDetail.Dealer_Custom_Price__c = 999.00;
            createDetail.Consumable_count__c = 1;
            //createDetail.Sum_of_money__c = 999.99;
            createDetail.Consumable_order__c =  createId.id;
            createDetail.Box_Piece__c = '盒';
            createDetail.Special_Campaign_Price__c= 1;
            createDetail.Intra_Trade_List_RMB__c = 1;
            //createDetail.Sterilization_limit__c = Date.today();
            //createDetail.Consumable_principal__c = createId.id;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;

            Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
            createDetail1.Name = 'Too0-02';
            createDetail1.Consumable_Product__c = pro2.id;
            createDetail1.Consumable_order__c =  createId2.id;
            //createDetail1.Sterilization_limit__c = Date.today();
            //createDetail1.Dealer_Custom_Price__c = 999.00;
            //createDetail1.Sum_of_money__c = 999.99;
            //createDetail1.Consumable_principal__c = createId.id;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            createDetail1.Box_Piece__c = '盒';
            createDetail1.Special_Campaign_Price__c= 1;
            createDetail1.Consumable_count__c = 0;
            createDetail1.Intra_Trade_List_RMB__c = 1;
            insert createDetail1;

            Consumable_orderdetails__c createDetail2 = new Consumable_orderdetails__c();
            createDetail2.Name = 'Too-0';
            createDetail2.Consumable_Product__c = pro2.id;
            createDetail2.Consumable_order__c =  createId1.id;
            //createDetail1.Sterilization_limit__c = Date.today();
            //createDetail2.Dealer_Custom_Price__c = 999.00;
            //createDetail1.Sum_of_money__c = 999.99;
            //createDetail1.Consumable_principal__c = createId.id;
            createDetail2.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            createDetail2.Box_Piece__c = '盒';
            createDetail2.Special_Campaign_Price__c= 1;
            createDetail2.Consumable_count__c = 0;
            createDetail2.Intra_Trade_List_RMB__c = 1;
            insert createDetail2;

            Consumable_orderdetails__c createDetail3 = new Consumable_orderdetails__c();
            createDetail3.Name = 'Too0-01';
            createDetail3.Consumable_Product__c = pro1.id;
            //createDetail3.Dealer_Custom_Price__c = 999.00;
            createDetail3.Consumable_count__c = 0;
            //createDetail3createDetail3createDetail3.Sum_of_money__c = 999.99;
            createDetail3.Consumable_order__c =  p.id;
            createDetail3.Box_Piece__c = '盒';
            createDetail3.Special_Campaign_Price__c= 1;
            createDetail3.Intra_Trade_List_RMB__c = 1;
            //createDetail.Sterilization_limit__c = Date.today();
            //createDetail.Consumable_principal__c = createId.id;
            createDetail3.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail3;
            PageReference page = new Pagereference('/apex/Consumable?ESetid='+createId.id+'&?type=agreementorder');
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            ConsumableController conTest = new ConsumableController();
            System.Test.startTest();
            conTest.init();
            conTest.bargainPrice =1;
            conTest.size = 3;
            conTest.SortLimited();
            conTest.searchConsumableorderdetails();
            System.assertEquals(5, conTest.ConsumableorderdetailsCount);
            conTest.contractName = 'contractName';
            conTest.coc.Offers_Price__c = 3800;
            conTest.coc.Order_Reason__c = '123';
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = null;
            conTest.save();

            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 0;
            conTest.con.next();
            conTest.refreshPageSize();
            conTest.save();
            conTest.sortKey ='5';
            conTest.SortStore();
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 10;
            conTest.save();
            conTest.consumableorderdetailsRecordsview[0].check= true;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = null;
            conTest.save();
            system.assertEquals(4,conTest.consumableorderdetailsRecordsview.size());
            conTest.consumableorderdetailsRecordsview[0].check= false;
            conTest.consumableorderdetailsRecordsview.sort();
            conTest.save();
            System.Test.stopTest();
        }
    }



    //static testMethod void  ConsumableSearchTest(){
    //    system.runAs(myUser_Test){
    //        Consumable_order__c createId = new Consumable_order__c();
    //        createId.Name = 'testMing-0';
    //        createId.Order_status__c = '草案中';
    //        createId.Deliver_date__c = Date.today();
    //        createId.Dealer_Info__c = myAccount2.Id;
    //        createId.RecordTypeid = System.Label.RT_ConOrder_Order;
    //        insert  createId;
    //        Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
    //        createDetailc.Name = 'Too001-0';
    //        createDetailc.Consumable_Product__c = pro1.id;
    //        createDetailc.Consumable_count__c = 1;
    //        createDetailc.Consumable_order__c =  createId.id;
    //        createDetailc.Box_Piece__c = '盒';
    //        createDetailc.Special_Campaign_Price__c= 1;
    //        createDetailc.Intra_Trade_List_RMB__c = 1;
    //        createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
    //        insert createDetailc;
    //        PageReference page = new PageReference('/apex/Consumable?ESetid='+createId.id);
    //        page.setRedirect(true);
    //        System.Test.setCurrentPage(page);
    //        ConsumableController ScTest = new ConsumableController();
    //        ScTest.init();
    //        System.assertEquals(6, ScTest.ConsumableorderdetailsCount);
    //        ScTest.category3 = 'CDS';
    //        ScTest.categoryAllload();
    //        system.assertEquals(2,ScTest.category4OptionList.size());
    //        ScTest.category4 = 'OER';
    //        ScTest.categoryload();
    //        ScTest.category5 ='其它';
    //        system.assertEquals(2,ScTest.category5OptionList.size());

    //        //ScTest.category3 = 'OCS';
    //        //ScTest.categoryAllload();
    //        //system.assertEquals(2,ScTest.category4OptionList.size());
    //        //ScTest.category4 = '附属品';
    //        //ScTest.categoryload();
    //        //system.assertEquals(2,ScTest.category5OptionList.size());


    //        //ScTest.category3 = 'ENT';
    //        //ScTest.categoryAllload();
    //        //system.assertEquals(2,ScTest.category4OptionList.size());
    //        //ScTest.category4 = 'Celon';
    //        //ScTest.categoryload();
    //        //ScTest.category5 = 'Celon';
    //        //system.assertEquals(2,ScTest.category5OptionList.size());

    //        //ScTest.category3 = 'US';
    //        //ScTest.categoryAllload();
    //        //system.assertEquals(2,ScTest.category4OptionList.size());
    //        //ScTest.category4 = 'ALOKA';
    //        //ScTest.categoryload();
    //        //system.assertEquals(2,ScTest.category5OptionList.size());

    //        //ScTest.category3 = '光源';
    //        //ScTest.categoryAllload();
    //        //system.assertEquals(2,ScTest.category4OptionList.size());
    //        //ScTest.category4 = 'LPL';
    //        //ScTest.categoryload();
    //        system.assertEquals(1,ScTest.category5OptionList.size());
    //        ScTest.searchConsumableorderdetails();
    //        ScTest.SortLimited();
    //        ScTest.category1 = 'Test01';
    //        ScTest.searchConsumableorderdetails();
    //        ScTest.specialCampaign = true;
    //        ScTest.searchConsumableorderdetails();
    //        ScTest.consumableorderdetailsRecordsview.sort();
    //    }
    //}


    static testMethod void  ConsumableTestSave(){
        initHpData();
        system.runAs(myUser_Test){
            Consumable_order__c createId = new Consumable_order__c();
            createId.Name = 'testMing-01';
            createId.Order_status__c = '草案中';
            createId.Deliver_date__c = Date.today();
            createId.Dealer_Info__c = myAccount2.Id;
            createId.RecordTypeid = System.Label.RT_ConOrder_Order;
            insert  createId;
      
            Consumable_order__c p = new Consumable_order__c();
            p.Name = 'test-01';
             p.Dealer_Info__c = myAccount2.Id;
            p.Offers_Price__c = 1;
            p.Order_date__c = Date.today();
            //p.Order_effective_contact__c = contract.Id;
            p.Order_Reason__c ='其它';
            insert  p;
            Consumable_orderdetails__c createDetailc = new Consumable_orderdetails__c();
            createDetailc.Name = 'Too00-01';
            createDetailc.Consumable_Product__c = pro1.id;
            //createDetailc.Dealer_Custom_Price__c = 999.00;
            createDetailc.Consumable_count__c = 0;
            //createDetail.Sum_of_money__c = 999.99;
            createDetailc.Consumable_order__c =  createId.id;
            createDetailc.Box_Piece__c = '盒';
            createDetailc.Special_Campaign_Price__c= 1;
            createDetailc.Intra_Trade_List_RMB__c = 1;
            createDetailc.Purchase_Unitprtprice_From__c = '促销';
            //createDetail.Sterilization_limit__c = Date.today();
            //createDetail.Consumable_principal__c = createId.id;
            createDetailc.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetailc;
            Consumable_orderdetails__c createDetail = new Consumable_orderdetails__c();
            createDetail.Name = 'OCM_01_001';
            createDetail.Consumable_Product__c = pro1.id;
            //createDetail.Dealer_Custom_Price__c = 999.00;
            createDetail.Consumable_count__c = 0;
            //createDetail.Sum_of_money__c = 999.99;
            createDetail.Consumable_order__c =  p.id;
            createDetail.Box_Piece__c = '盒';
            createDetail.Special_Campaign_Price__c= 1;
            createDetail.Intra_Trade_List_RMB__c = 1;
            //createDetail.Sterilization_limit__c = Date.today();
            //createDetail.Consumable_principal__c = createId.id;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;

            Consumable_orderdetails__c createDetail1 = new Consumable_orderdetails__c();
            createDetail1.Name = 'Too0-01';
            createDetail1.Consumable_Product__c = pro2.id;
            createDetail1.Consumable_order__c =  createId.id;
            //createDetail1.Sterilization_limit__c = Date.today();
            //createDetail1.Dealer_Custom_Price__c = 999.00;
            //createDetail1.Sum_of_money__c = 999.99;
            //createDetail1.Consumable_principal__c = createId.id;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            createDetail1.Box_Piece__c = '盒';
            createDetail1.Special_Campaign_Price__c= 1;
            createDetail1.Consumable_count__c = 10;
            createDetail1.Intra_Trade_List_RMB__c = 1;
            insert createDetail1;

            


            Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
            Orderdet1.Name = 'OCM_01_001001';
            Orderdet1.Consumable_order_minor__c = createId.Id;
            Orderdet1.Consumable_Arrived_order__c = createId.Id;
            Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
            Orderdet1.Sterilization_limit__c = Date.today().addDays(1);
            Orderdet1.Bar_Code__c = '11111';
            Orderdet1.Consumable_product__c = pro1.Id;
            Orderdet1.Arrive_date__c = Date.today();
            Orderdet1.Send_Date__c = null;
            Orderdet1.Used_date__c = null;
            Orderdet1.Lose_Flag__c = false;
            Orderdet1.Sterilization_limit__c = Date.today().addDays(1);

            Oly_TriggerHandler.bypass('ConsumableAssetHander');
            insert Orderdet1;
            PageReference page = new PageReference('/apex/Consumable?type=agreementorder');
            page.setRedirect(true);
            System.Test.setCurrentPage(page);
            ConsumableController conTest = new ConsumableController();
            System.Test.startTest();
            conTest.methodType = 'agreementorder';
            conTest.init();
            conTest.bargainPrice =1 ;
            conTest.size = 3;
            conTest.SortLimited();
            conTest.searchConsumableorderdetails();
            System.assertEquals(5, conTest.ConsumableorderdetailsCount);
            conTest.contractName = 'contractName';
            conTest.coc.Offers_Price__c = 3800;
            conTest.coc.Order_Reason__c = '123';
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_Count__c = 12;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = null;
            conTest.save();

            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 0;
            conTest.con.next();
            conTest.refreshPageSize();
            conTest.save();
            conTest.SortStore();
            conTest.consumableorderdetailsRecordsview[0].check= true;
            conTest.ConsumableorderdetailsRecordsview[0].esd.Consumable_count__c = 10;
            conTest.save();
            conTest.consumableorderdetailsRecordsview[0].check= true;
            //conTest.ConsumableorderdetailsRecordsview[0].esd.Dealer_Custom_Price__c = null;
            conTest.save();
            system.assertEquals(5,conTest.consumableorderdetailsRecordsview.size());
            conTest.consumableorderdetailsRecordsview[0].check= false;
            conTest.consumableorderdetailsRecordsview.sort();
            conTest.save();
            System.Test.stopTest();
          
        }
    }
}