@istest
public class LexConsumableGoodsInfoTest {
    @IsTest
    static void lexConsumableGoodsInfoTest1(){
        user MyUser_Test;
        Account myAccount1;
        User thisUser = [ select Id from User where Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true);
        insert n;
        System.runAs(thisUser){
			Profile prof1 = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
			List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
			if (rectCo.size() == 0) {
				return;
			}
			StaticParameter.EscapeConsumableOrderDetail2Trigger = true;
			
			RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
			Account olympus = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus');
			insert olympus;
			myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =10,RecordTypeId = rectCo[0].Id,AgentCode_Ext__c = '8888888',Product_Limit_Date__c = 'Test07|3|100,Test08|10|50');
			insert myAccount1;
			Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe',lastname='Plumber',accountid=myAccount1.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 = prof1.Id,TimeZoneSidKey='Asia/Shanghai', UserName='testUser@testorg.com',Work_Location__c = '重庆');
			insert MyUser_Test;

		}
       
		system.runAs(MyUser_Test){
			//产品数据
	        Product2 prod07 = new Product2(Name='Test07',ProductCode='Test07',Asset_Model_No__c = 'Test07',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod08 = new Product2(Name='Test08',ProductCode='Test08',Asset_Model_No__c = 'Test08',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        Product2 prod09 = new Product2(Name='Test09',ProductCode='Test09',Asset_Model_No__c = 'Test09',SFDA_Status__c = '有効',Dealer_special_Object__c = true,Packing_list_manual__c = 1,Manual_Entry__c = false);
	        insert new Product2[] {prod07,prod08,prod09};

			//制作产品
			Product2__c proG = new Product2__c(Name='MH-155:白平衡帽',OT_CODE_Text__c='Test001',Product2__c = prod07.Id);
			insert proG;
			Product2__c proH = new Product2__c(Name='MB-677:BNC电缆',OT_CODE_Text__c='Test002',Product2__c = prod08.Id);
			insert proH;
			Product2__c proF = new Product2__c(Name='TooMAJ-643R:水囊鞘管003',OT_CODE_Text__c='Test003',Product2__c = prod09.Id);
			insert proF;


			//订单
			Consumable_order__c order = new Consumable_order__c();
			order.Name = 'testMing';
			order.Order_status__c = '批准';
			order.RecordTypeid = System.Label.RT_ConOrder_Order;
			order.Dealer_Info__c = myAccount1.id;
			order.Inventory_date__c = Date.today();
        	order.Order_type__c = '订单';
			order.Order_ProType__c = 'ET';
			insert  order;
			//到货
			Consumable_order__c order2 = new Consumable_order__c();
			order2.Name = 'testMing1';
			order2.Order_status__c = '批准';
			order2.RecordTypeid = '01210000000c9dqAAA';
			order2.Dealer_Info__c = myAccount1.id;
        	order2.Order_type__c = '到货';
			order2.Order_ProType__c = 'ET';
			insert  order2;

			List<Consumable_order_details2__c> conList = new List<Consumable_order_details2__c>();
			//制作Consumable_order_details__c-------ProductCount
			// 销售
			Consumable_order_details2__c dataForProductCount7 = new Consumable_order_details2__c();
			dataForProductCount7.Bar_Code__c               = '123456789298k250AAAAA';
			dataForProductCount7.Sterilization_limit__c    = Date.today().addDays(2);
			dataForProductCount7.Arrive_date__c			  = Date.today();
			dataForProductCount7.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount7.Consumable_Product__c     = proH.id;
			dataForProductCount7.Asset_Model_No__c         = proH.Asset_Model_No__c;
			dataForProductCount7.Box_Piece__c              = '盒';
            dataForProductCount7.Used_date__c = Date.today();
            dataForProductCount7.Consumable_order_minor__c = order.id;

			conList.add(dataForProductCount7);
			// 在库 过期 盒
			Consumable_order_details2__c dataForProduct = new Consumable_order_details2__c();
			dataForProduct.Bar_Code__c               = '123456789498k250BBBBB';
			dataForProduct.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProduct.Arrive_date__c			  = Date.today();
			dataForProduct.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProduct.Consumable_Product__c     = proF.id;
			dataForProduct.Asset_Model_No__c         = proF.Asset_Model_No__c;
			dataForProduct.Box_Piece__c              = '盒';
			dataForProduct.Consumable_order_minor__c = order.id;

			conList.add(dataForProduct);
			// 在库 过期 个
			Consumable_order_details2__c dataForProductCount3 = new Consumable_order_details2__c();
			dataForProductCount3.Bar_Code__c               = '123456788398k250CCCCC';
			dataForProductCount3.Sterilization_limit__c    = Date.today().addDays(-2);
			dataForProductCount3.Arrive_date__c			  = Date.today();
			dataForProductCount3.RecordTypeid              = System.Label.RT_ConOrderDetail2_Delivery;
			dataForProductCount3.Consumable_Product__c     = proG.id;
			dataForProductCount3.Asset_Model_No__c         = proG.Asset_Model_No__c;
            dataForProductCount3.Box_Piece__c              = '个';
            dataForProductCount3.RemoveBox_No__c = 1;
            dataForProductCount3.Consumable_order_minor__c = order.id;
			conList.add(dataForProductCount3);
			insert conList;
			
			//过期库存汇总信息 add by Wang Xueqin
			List<Consumable_order_details2__c> conList1 = new List<Consumable_order_details2__c>();
			Consumable_order_details2__c dataForProductCount4 = new Consumable_order_details2__c();
			dataForProductCount4.Bar_Code__c = '1001';
			dataForProductCount4.Arrive_date__c = Date.today();
			dataForProductCount4.Send_Date__c = null;
			dataForProductCount4.Used_date__c = null;
			dataForProductCount4.Return_date__c = null;
			dataForProductCount4.Lose_Flag__c = false;
			dataForProductCount4.Cancellation_Flag__c = false;
			dataForProductCount4.Consumable_Product__c = proG.Id;
			dataForProductCount4.Consumable_Arrived_order__c = order2.id;
			dataForProductCount4.Used_account__c = myAccount1.Id;
			dataForProductCount4.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount4.Box_Piece__c = '盒';
			conList1.add(dataForProductCount4);
			System.debug('conList1==>'+conList1);
			//查询所有过期库存
			Consumable_order_details2__c dataForProductCount5 = new Consumable_order_details2__c();
			dataForProductCount5.Bar_Code__c = '1002';
			dataForProductCount5.Arrive_date__c = Date.today();
			dataForProductCount5.Send_Date__c =  Date.today();
			dataForProductCount5.Used_date__c =  Date.today();
			dataForProductCount5.Return_date__c = null;
			dataForProductCount5.Lose_Flag__c = false;
			dataForProductCount5.Cancellation_Flag__c = false;
			dataForProductCount5.Consumable_Product__c = proG.Id;
			dataForProductCount5.Consumable_Arrived_order__c = order2.id;
			dataForProductCount5.Used_account__c = myAccount1.Id;
			dataForProductCount5.Sterilization_limit__c = Date.today().addDays(-2);
			dataForProductCount5.Box_Piece__c = '盒';
			conList1.add(dataForProductCount5);
			insert conList1; 
            Test.startTest();
            LexConsumableGoodsInfo.initMoreThan7(dataForProductCount7.Id);
            LexConsumableGoodsInfo.initMoreThan7All('all');
            LexConsumableGoodsInfo.initNotArrDet(dataForProductCount7.Id);
            LexConsumableGoodsInfo.initNotArrDetAll('all');
            LexConsumableGoodsInfo.initArrDet(dataForProductCount7.Id);
            LexConsumableGoodsInfo.initArrDetAll('all');
            LexConsumableGoodsInfo.initDeliveryDet(dataForProductCount7.Id);
            LexConsumableGoodsInfo.initDeliveryDetAll('all');
            LexConsumableGoodsInfo.initTotalNum('1', 'all');
            LexConsumableGoodsInfo.initTotalNum(dataForProductCount7.Id, 'all');
            Test.stopTest();
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest2(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            Consumable_order__c Order2 = new Consumable_order__c(
                Name='OCM_01_002',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            insert new Consumable_order__c[] {Order1, Order2};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.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 =  Order2.id;
            createDetail1.Dealer_Custom_Price__c = 999.00;
            createDetail1.Consumable_count__c = 4;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet2 =  new Consumable_order_details2__c(
                Name='OCM_01_001002',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                //Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet4 =  new Consumable_order_details2__c(
                Name='OCM_01_001004',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2, Orderdet3, Orderdet4};

            LexConsumableGoodsInfo.initMoreThan7(Orderdet1.Id);
            LexConsumableGoodsInfo.initMoreThan7All('all');
            LexConsumableGoodsInfo.initNotArrDet(Orderdet1.Id);
            LexConsumableGoodsInfo.initNotArrDetAll('all');
            LexConsumableGoodsInfo.initArrDet(Orderdet1.Id);
            LexConsumableGoodsInfo.initArrDetAll('all');
            LexConsumableGoodsInfo.initDeliveryDet(Orderdet1.Id);
            LexConsumableGoodsInfo.initDeliveryDetAll('all');
            LexConsumableGoodsInfo.initTotalNum('1', 'all');
            LexConsumableGoodsInfo.initTotalNum(Orderdet1.Id, 'all');
 
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest3(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            Consumable_order__c Order2 = new Consumable_order__c(
                Name='OCM_01_002',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            insert new Consumable_order__c[] {Order1, Order2};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.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 =  Order2.id;
            createDetail1.Dealer_Custom_Price__c = 999.00;
            createDetail1.Consumable_count__c = 4;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet2 =  new Consumable_order_details2__c(
                Name='OCM_01_001002',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                //Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet4 =  new Consumable_order_details2__c(
                Name='OCM_01_001004',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2, Orderdet3, Orderdet4};

            LexConsumableGoodsInfo.initMoreThan7(Orderdet2.Id);
            LexConsumableGoodsInfo.initMoreThan7All('');
            LexConsumableGoodsInfo.initNotArrDet(Orderdet2.Id);
            LexConsumableGoodsInfo.initNotArrDetAll('');
            LexConsumableGoodsInfo.initArrDet(Orderdet2.Id);
            LexConsumableGoodsInfo.initArrDetAll('');
            LexConsumableGoodsInfo.initDeliveryDet(Orderdet2.Id);
            LexConsumableGoodsInfo.initDeliveryDetAll('');
            LexConsumableGoodsInfo.initTotalNum(Orderdet2.Id, '');
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest4(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            Consumable_order__c Order2 = new Consumable_order__c(
                Name='OCM_01_002',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            insert new Consumable_order__c[] {Order1, Order2};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.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 =  Order2.id;
            createDetail1.Dealer_Custom_Price__c = 999.00;
            createDetail1.Consumable_count__c = 4;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet2 =  new Consumable_order_details2__c(
                Name='OCM_01_001002',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                //Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet4 =  new Consumable_order_details2__c(
                Name='OCM_01_001004',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2, Orderdet3, Orderdet4};

            LexConsumableGoodsInfo.initMoreThan7(Orderdet3.Id);
            LexConsumableGoodsInfo.initNotArrDet(Orderdet3.Id);
            LexConsumableGoodsInfo.initArrDet(Orderdet3.Id);
            LexConsumableGoodsInfo.initDeliveryDet(Orderdet3.Id);
            LexConsumableGoodsInfo.initTotalNum(Orderdet3.Id, 'all');
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest5(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            Consumable_order__c Order2 = new Consumable_order__c(
                Name='OCM_01_002',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c=myAccount1.Id,
                Order_ProType__c = 'ET');
            insert new Consumable_order__c[] {Order1, Order2};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.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 =  Order2.id;
            createDetail1.Dealer_Custom_Price__c = 999.00;
            createDetail1.Consumable_count__c = 4;
            createDetail1.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail1;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet2 =  new Consumable_order_details2__c(
                Name='OCM_01_001002',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                //Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            Consumable_order_details2__c Orderdet4 =  new Consumable_order_details2__c(
                Name='OCM_01_001004',
                Consumable_order_minor__c = Order2.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro2.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2, Orderdet3, Orderdet4};

            LexConsumableGoodsInfo.initMoreThan7(Orderdet4.Id);
            LexConsumableGoodsInfo.initNotArrDet(Orderdet4.Id);
            LexConsumableGoodsInfo.initArrDet(Orderdet4.Id);
            LexConsumableGoodsInfo.initDeliveryDet(Orderdet4.Id);
            LexConsumableGoodsInfo.initTotalNum(Orderdet4.Id, 'all');
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest6(){
        LexConsumableGoodsInfo.ShowRecords sr = new LexConsumableGoodsInfo.ShowRecords();
        sr.prodModel = 'test';
        sr.recordCount = 1;
        sr.compareTo(new LexConsumableGoodsInfo.ShowRecords());
    }

    @IsTest
    static void lexConsumableGoodsInfoTest7(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京',
                UserPro_Type__c = 'ET');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c = myAccount1.Id,
                Delivery_detail_count__c = 1,
                Order_ProType__c = 'ET',
                showFalseNotshowTrue__c = false);
            insert new Consumable_order__c[] {Order1};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.id;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Asset_Model_No__c = 'Test01',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery,
                Cancellation_Flag__c = false);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Asset_Model_No__c = 'Test01',
                Consumable_order_minor__c = Order1.Id,
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery,
                Cancellation_Flag__c = false);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet3};
            LexConsumableGoodsInfo.initNotArrDet(Order1.Id);
            LexConsumableGoodsInfo.initNotArrDetAll('all');
        }
    }

    @IsTest
    static void lexConsumableGoodsInfoTest8(){
        User myUser_test = new User();
        Account myAccount1;
        Contact core;
        User currentUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
        NoteStay__c n = new NoteStay__c(Name = 'NoteStay',IsStay__c = true); 
        insert n;
        System.runAs(currentUser){
            Profile prof = [select Id from Profile where Name ='901_经销商社区普通权限_2重验证(ET)'];
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '販売店'];
            if (rectCo.size() == 0) {
                return;
            }
            myAccount1 = new Account(name='testaccount001',RecordTypeId = rectCo[0].Id ,AgentCode_Ext__c = '9999900');
            insert myAccount1;
            core = new Contact(email='jplumber@salesforce.com',
            firstname='Joe',
            lastname='Plumber',
            accountid=myAccount1.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',
                Work_Location__c='北京',
                UserPro_Type__c = 'ET');
            insert myUser_test;
        }
        System.runAs(myUser_test){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',Manual_Entry__c = false);
            Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',Manual_Entry__c = false);
            insert new Product2[]{prod01,prod02};
            Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='Test001',Product2__c = prod01.Id);
            Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='Test002',Product2__c = prod02.Id);
            insert new Product2__c[] {pro1, pro2};
            //订单
            Consumable_order__c Order1 = new Consumable_order__c(
                Name='OCM_01_001',
                RecordTypeId = System.Label.RT_ConOrder_Delivery,
                Order_type__c ='订单',
                Dealer_info__c = myAccount1.Id,
                Delivery_detail_count__c = 1,
                Order_ProType__c = 'ET',
                showFalseNotshowTrue__c = false);
            insert new Consumable_order__c[] {Order1};

            //明细1
            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 = 3;
            createDetail.Consumable_order__c =  Order1.id;
            createDetail.RecordTypeid = System.Label.RT_ConOrderDetail1_Order;
            insert createDetail;

            //订单明细
            Consumable_order_details2__c Orderdet1 =  new Consumable_order_details2__c(
                Name='OCM_01_001001',
                Consumable_order_minor__c = Order1.Id,
                Arrive_date__c = Date.today(),
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery,
                Cancellation_Flag__c = false);
            Consumable_order_details2__c Orderdet3 =  new Consumable_order_details2__c(
                Name='OCM_01_001003',
                Consumable_order_minor__c = Order1.Id,
                Consumable_Product__c = pro1.id,
                RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery,
                Cancellation_Flag__c = false);
            insert new Consumable_order_details2__c[] {Orderdet1, Orderdet3};
            LexConsumableGoodsInfo.initNotArrDetAll('all');
        }
    }
}