@isTest
public class TrackConsumableSaleForecastBatchTest {
    static testMethod void batch1Test() {
        TrackConsumableSalesForecast__c tcsf = new TrackConsumableSalesForecast__c();
        tcsf.HospitalName__c = 'TestHos';
        tcsf.ProductModel__c = 'TestProd';
        tcsf.LastMonthDeliveryNumber__c = 0;
        tcsf.ThisMonthDeliveryNumber__c = 0;
        tcsf.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf.Type__c = 'ET';
        tcsf.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        TrackConsumableSalesForecast__c tcsf1 = new TrackConsumableSalesForecast__c();
        tcsf1.HospitalName__c = 'TestHos2';
        tcsf1.ProductModel__c = 'TestProd2';
        tcsf1.LastMonthDeliveryNumber__c = 1;
        tcsf1.ThisMonthDeliveryNumber__c = 1;
        tcsf1.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf1.Type__c = 'ENG';
        tcsf1.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        // insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
        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_经销商社区普通权限_2重验证(ET)'];
        RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
		Account myAccount2 = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus',ET_owner__c = UserInfo.getUserId());
		Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
		insert new account[]{myAccount1,myAccount2};
		Contact core = new Contact(email='jplumber@salesforce.com',lastname='Plumber',accountid=myAccount1.id);
		insert core;
		User MyUser_Test;
		System.runAs(new User(Id = UserInfo.getUserId())){
		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;
		}
		tcsf.Hospital__c = myAccount2.Id;
		tcsf1.Hospital__c = myAccount2.Id;
		tcsf1.OwnerId = MyUser_Test.id;
        insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
		System.runAs(new User(Id = UserInfo.getUserId())){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
			Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',JANCODE__c = '04953170200312',Dealer_special_Object__c = true,Manual_Entry__c = false);
			insert new Product2[] {prod01,prod02};
			Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='N3047730',Product2__c = prod01.Id);
			Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='N3047731',Product2__c = prod02.Id);
			insert new Product2__c[] {pro1, pro2};
            
            Consumable_order__c Order0 = new Consumable_order__c();
			Order0.Name = 'OCM_01_000';
			Order0.Order_status__c = '批准';
			Order0.Order_type__c = '订单';
			Order0.RecordTypeid = System.Label.RT_ConOrder_Delivery;
			Order0.Order_ProType__c = 'ET';

			Consumable_order__c Order1 = new Consumable_order__c();
			Order1.Name = 'OCM_01_001';
			Order1.Order_status__c = '批准';
			Order1.Order_type__c = '订单';
            Order1.Order_ForHospital__c = myAccount2.id;
			Order1.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order1.Order_ProType__c = 'ET';
            Order1.OutPattern__c = true;
            Order1.SummonsStatus_c__c = '已提交';
            Order1.SummonsForDirction__c = '直接销售给医院';

			Consumable_order__c Order3 = new Consumable_order__c();
			Order3.Name = 'OCM_01_001';
			Order3.Order_status__c = '批准';
			Order3.Order_type__c = '订单';
            // Order3.Order_ForHospital__c = myAccount2.id;
			Order3.Order_ForDealer__c = myAccount1.id;
			Order3.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order3.Order_ProType__c = 'ET';
            Order3.OutPattern__c = true;
            Order3.SummonsStatus_c__c = '已提交';
            Order3.SummonsForDirction__c = '直接销售给医院';

			insert new List<Consumable_order__c> {Order0, Order1,Order3};

			Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
			Orderdet.Name = 'OCM_01_00101';
			Orderdet.Consumable_order__c = Order0.Id;
			Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
			Orderdet.Consumable_Product__c = pro1.Id;
			Orderdet.Consumable_count__c = 4;
            Orderdet.Shipment_Count__c = 10;
            Orderdet.isOutPattern__c = true;
            Orderdet.Delivery_List_RMB__c = 100;
            Orderdet.Box_Piece__c = '盒';
			insert Orderdet;
			Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
			Orderdet1.Name = 'OCM_01_001001';
			Orderdet1.Consumable_Sale_order__c = Order1.Id;
			Orderdet1.Consumable_Product__c = pro1.Id;
			Orderdet1.Asset_Model_No__c = 'Test01';
			Orderdet1.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
			Orderdet1.Cancellation_Date__c = null;
			Orderdet1.TracingCode__c = 'BXJRF';
			Orderdet1.SerialLotNo__c = '5ZK';
			Orderdet1.Arrive_date__c = Date.today();
			Orderdet1.exchangeOutPattern__c = true;
			Orderdet1.Used_date__c = Date.today();
			Orderdet1.Box_Piece__c = '盒';
			Orderdet1.Sterilization_limit__c= Date.today().addDays(2);
			// insert Orderdet1;
			Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
			Orderdet2.Name = 'OCM_01_001002';
			Orderdet2.Consumable_Shipment_order__c = Order1.Id;
			Orderdet2.Consumable_Product__c = pro1.Id;
			Orderdet2.Asset_Model_No__c = 'Test01';
			Orderdet2.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJA';
			Orderdet2.Cancellation_Date__c = null;
			Orderdet2.TracingCode__c = 'BXJA';
			Orderdet2.SerialLotNo__c = '5ZK';
			Orderdet2.Arrive_date__c = Date.today();
			Orderdet2.exchangeOutPattern__c = true;
			Orderdet2.Used_date__c = Date.today();
			Orderdet2.Box_Piece__c = '盒';
			Orderdet2.Sterilization_limit__c= Date.today().addDays(2);

			Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
			Orderdet3.Name = 'OCM_01_001002';
            Orderdet3.Consumable_Sale_order__c = Order3.Id;
			Orderdet3.Consumable_Product__c = pro1.Id;
			Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJB';
			Orderdet3.Cancellation_Date__c = null;
			Orderdet3.TracingCode__c = 'BXJB';
			Orderdet3.SerialLotNo__c = '5ZK';
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.exchangeOutPattern__c = true;
			Orderdet3.Used_date__c = Date.today();
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.Sterilization_limit__c= Date.today().addDays(2);


			Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
			Orderdet4.Name = 'OCM_01_001002';
            Orderdet4.Consumable_Shipment_order__c = Order3.Id;
			Orderdet4.Consumable_Product__c = pro1.Id;
			Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR';
			Orderdet4.Cancellation_Date__c = null;
			Orderdet4.TracingCode__c = 'BXJR';
			Orderdet4.SerialLotNo__c = '5ZK';
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.exchangeOutPattern__c = true;
			Orderdet4.Used_date__c = Date.today();
            Orderdet4.Box_Piece__c = '盒';
            Orderdet4.Sterilization_limit__c= Date.today().addDays(2);
			// insert Orderdet3;
			// Orderdet3 = [select id,Product_Type__c,Asset_Model_No__c,Inventory_Status__c  FROM Consumable_order_details2__c where id = :Orderdet3.id];
			insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2,Orderdet3,Orderdet4};
            System.Test.startTest();
            Id batjobId = Database.executeBatch(new TrackConsumableSaleForecastBatch1(Date.newInstance(2023, 3, 1),Date.newInstance(2023, 3, 1)), 200);
            batjobId = Database.executeBatch(new TrackConsumableSaleForecastBatch1(Date.newInstance(2022, 3, 1),Date.newInstance(2020, 3, 1),true), 200);
			System.Test.stopTest();
        }
    }
    static testMethod void batch2Test() {
        TrackConsumableSalesForecast__c tcsf = new TrackConsumableSalesForecast__c();
        tcsf.HospitalName__c = 'TestHos';
        tcsf.ProductModel__c = 'TestProd';
        tcsf.LastMonthDeliveryNumber__c = 0;
        tcsf.ThisMonthDeliveryNumber__c = 0;
        tcsf.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf.Type__c = 'ET';
        tcsf.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        TrackConsumableSalesForecast__c tcsf1 = new TrackConsumableSalesForecast__c();
        tcsf1.HospitalName__c = 'TestHos2';
        tcsf1.ProductModel__c = 'TestProd2';
        tcsf1.LastMonthDeliveryNumber__c = 1;
        tcsf1.ThisMonthDeliveryNumber__c = 1;
        tcsf1.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf1.Type__c = 'ENG';
        tcsf1.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        // insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
        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_经销商社区普通权限_2重验证(ET)'];
        RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
		Account myAccount2 = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus',ET_owner__c = UserInfo.getUserId());
		Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
		insert new account[]{myAccount1,myAccount2};
		Contact core = new Contact(email='jplumber@salesforce.com',lastname='Plumber',accountid=myAccount1.id);
		insert core;
		User MyUser_Test;
		System.runAs(new User(Id = UserInfo.getUserId())){
		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;
		}
		tcsf.Hospital__c = myAccount2.Id;
		tcsf1.Hospital__c = myAccount2.Id;
		tcsf1.OwnerId = MyUser_Test.id;
        insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
		System.runAs(new User(Id = UserInfo.getUserId())){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
			Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',JANCODE__c = '04953170200312',Dealer_special_Object__c = true,Manual_Entry__c = false);
			insert new Product2[] {prod01,prod02};
			Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='N3047730',Product2__c = prod01.Id);
			Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='N3047731',Product2__c = prod02.Id);
			insert new Product2__c[] {pro1, pro2};
            
            Consumable_order__c Order0 = new Consumable_order__c();
			Order0.Name = 'OCM_01_000';
			Order0.Order_status__c = '批准';
			Order0.Order_type__c = '订单';
			Order0.RecordTypeid = System.Label.RT_ConOrder_Delivery;
			Order0.Order_ProType__c = 'ET';

			Consumable_order__c Order1 = new Consumable_order__c();
			Order1.Name = 'OCM_01_001';
			Order1.Order_status__c = '批准';
			Order1.Order_type__c = '订单';
            Order1.Order_ForHospital__c = myAccount2.id;
			Order1.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order1.Order_ProType__c = 'ET';
            Order1.OutPattern__c = true;
            Order1.SummonsStatus_c__c = '已提交';
            Order1.SummonsForDirction__c = '直接销售给医院';

			Consumable_order__c Order3 = new Consumable_order__c();
			Order3.Name = 'OCM_01_001';
			Order3.Order_status__c = '批准';
			Order3.Order_type__c = '订单';
            // Order3.Order_ForHospital__c = myAccount2.id;
			Order3.Order_ForDealer__c = myAccount1.id;
			Order3.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order3.Order_ProType__c = 'ET';
            Order3.OutPattern__c = true;
            Order3.SummonsStatus_c__c = '已提交';
            Order3.SummonsForDirction__c = '直接销售给医院';

			insert new List<Consumable_order__c> {Order0, Order1,Order3};

			Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
			Orderdet.Name = 'OCM_01_00101';
			Orderdet.Consumable_order__c = Order0.Id;
			Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
			Orderdet.Consumable_Product__c = pro1.Id;
			Orderdet.Consumable_count__c = 4;
            Orderdet.Shipment_Count__c = 10;
            Orderdet.isOutPattern__c = true;
            Orderdet.Delivery_List_RMB__c = 100;
            Orderdet.Box_Piece__c = '盒';
			insert Orderdet;
			Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
			Orderdet1.Name = 'OCM_01_001001';
			Orderdet1.Consumable_Sale_order__c = Order1.Id;
			Orderdet1.Consumable_Product__c = pro1.Id;
			Orderdet1.Asset_Model_No__c = 'Test01';
			Orderdet1.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
			Orderdet1.Cancellation_Date__c = null;
			Orderdet1.TracingCode__c = 'BXJRF';
			Orderdet1.SerialLotNo__c = '5ZK';
			Orderdet1.Arrive_date__c = Date.today();
			Orderdet1.exchangeOutPattern__c = true;
			Orderdet1.Used_date__c = Date.today();
			Orderdet1.Box_Piece__c = '盒';
			Orderdet1.Sterilization_limit__c= Date.today().addDays(2);
			// insert Orderdet1;
			Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
			Orderdet2.Name = 'OCM_01_001002';
			Orderdet2.Consumable_Shipment_order__c = Order1.Id;
			Orderdet2.Consumable_Product__c = pro1.Id;
			Orderdet2.Asset_Model_No__c = 'Test01';
			Orderdet2.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJA';
			Orderdet2.Cancellation_Date__c = null;
			Orderdet2.TracingCode__c = 'BXJA';
			Orderdet2.SerialLotNo__c = '5ZK';
			Orderdet2.Arrive_date__c = Date.today();
			Orderdet2.exchangeOutPattern__c = true;
			Orderdet2.Used_date__c = Date.today();
			Orderdet2.Box_Piece__c = '盒';
			Orderdet2.Sterilization_limit__c= Date.today().addDays(2);

			Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
			Orderdet3.Name = 'OCM_01_001002';
            Orderdet3.Consumable_Sale_order__c = Order3.Id;
			Orderdet3.Consumable_Product__c = pro1.Id;
			Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJB';
			Orderdet3.Cancellation_Date__c = null;
			Orderdet3.TracingCode__c = 'BXJB';
			Orderdet3.SerialLotNo__c = '5ZK';
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.exchangeOutPattern__c = true;
			Orderdet3.Used_date__c = Date.today();
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.Sterilization_limit__c= Date.today().addDays(2);


			Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
			Orderdet4.Name = 'OCM_01_001002';
            Orderdet4.Consumable_Shipment_order__c = Order3.Id;
			Orderdet4.Consumable_Product__c = pro1.Id;
			Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR';
			Orderdet4.Cancellation_Date__c = null;
			Orderdet4.TracingCode__c = 'BXJR';
			Orderdet4.SerialLotNo__c = '5ZK';
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.exchangeOutPattern__c = true;
			Orderdet4.Used_date__c = Date.today();
            Orderdet4.Box_Piece__c = '盒';
            Orderdet4.Sterilization_limit__c= Date.today().addDays(2);
			// insert Orderdet3;
			// Orderdet3 = [select id,Product_Type__c,Asset_Model_No__c,Inventory_Status__c  FROM Consumable_order_details2__c where id = :Orderdet3.id];
			insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2,Orderdet3,Orderdet4};
            System.Test.startTest();
            Id batjobId = Database.executeBatch(new TrackConsumableSaleForecastBatch1(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 1, 1)), 200);
            Database.executeBatch(new TrackConsumableSaleForecastBatch2(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 1, 1)), 200);
			System.Test.stopTest();
        }
    }
    static testMethod void batch3Test() {
        TrackConsumableSalesForecast__c tcsf = new TrackConsumableSalesForecast__c();
        tcsf.HospitalName__c = 'TestHos';
        tcsf.ProductModel__c = 'TestProd';
        tcsf.LastMonthDeliveryNumber__c = 0;
        tcsf.ThisMonthDeliveryNumber__c = 0;
        tcsf.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf.Type__c = 'ET';
        tcsf.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        TrackConsumableSalesForecast__c tcsf1 = new TrackConsumableSalesForecast__c();
        tcsf1.HospitalName__c = 'TestHos2';
        tcsf1.ProductModel__c = 'TestProd2';
        tcsf1.LastMonthDeliveryNumber__c = 1;
        tcsf1.ThisMonthDeliveryNumber__c = 1;
        tcsf1.LastShipmentDate__c = Date.newInstance(2023, 1, 1);
        tcsf1.Type__c = 'ENG';
        tcsf1.SnapshotMonth__c = Date.newInstance(2023, 2, 1);
        // insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
        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_经销商社区普通权限_2重验证(ET)'];
        RecordType rectCoO = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
		Account myAccount2 = new Account(RecordTypeId = rectCoO.Id, AgentCode_Ext__c = '9999900', Name = 'olympus',ET_owner__c = UserInfo.getUserId());
		Account myAccount1 = new Account(name='Testaccount001',Dealer_discount__c =30,RecordTypeId = rectCo[0].Id);
		insert new account[]{myAccount1,myAccount2};
		Contact core = new Contact(email='jplumber@salesforce.com',lastname='Plumber',accountid=myAccount1.id);
		insert core;
		User MyUser_Test;
		System.runAs(new User(Id = UserInfo.getUserId())){
		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;
		}
		tcsf.Hospital__c = myAccount2.Id;
		tcsf1.Hospital__c = myAccount2.Id;
		tcsf1.OwnerId = MyUser_Test.id;
        insert new List<TrackConsumableSalesForecast__c>{tcsf,tcsf1};
		System.runAs(new User(Id = UserInfo.getUserId())){
            Product2 prod01 = new Product2(Name='Test01',ProductCode='Test01',Asset_Model_No__c = 'Test01',SFDA_Status__c = '有効',JANCODE__c = '04953170200311',Dealer_special_Object__c = true,Manual_Entry__c = false);
			Product2 prod02 = new Product2(Name='Test02',ProductCode='Test02',Asset_Model_No__c = 'Test02',SFDA_Status__c = '有効',JANCODE__c = '04953170200312',Dealer_special_Object__c = true,Manual_Entry__c = false);
			insert new Product2[] {prod01,prod02};
			Product2__c pro1 = new Product2__c(Name='Pro001',OT_CODE_Text__c='N3047730',Product2__c = prod01.Id);
			Product2__c pro2 = new Product2__c(Name='Pro002',OT_CODE_Text__c='N3047731',Product2__c = prod02.Id);
			insert new Product2__c[] {pro1, pro2};
            
            Consumable_order__c Order0 = new Consumable_order__c();
			Order0.Name = 'OCM_01_000';
			Order0.Order_status__c = '批准';
			Order0.Order_type__c = '订单';
			Order0.RecordTypeid = System.Label.RT_ConOrder_Delivery;
			Order0.Order_ProType__c = 'ET';

			Consumable_order__c Order1 = new Consumable_order__c();
			Order1.Name = 'OCM_01_001';
			Order1.Order_status__c = '批准';
			Order1.Order_type__c = '订单';
            Order1.Order_ForHospital__c = myAccount2.id;
			Order1.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order1.Order_ProType__c = 'ET';
            Order1.OutPattern__c = true;
            Order1.SummonsStatus_c__c = '已提交';
            Order1.SummonsForDirction__c = '直接销售给医院';

			Consumable_order__c Order3 = new Consumable_order__c();
			Order3.Name = 'OCM_01_001';
			Order3.Order_status__c = '批准';
			Order3.Order_type__c = '订单';
            // Order3.Order_ForHospital__c = myAccount2.id;
			Order3.Order_ForDealer__c = myAccount1.id;
			Order3.RecordTypeid = System.Label.RT_ConOrder_Arrive;
			Order3.Order_ProType__c = 'ET';
            Order3.OutPattern__c = true;
            Order3.SummonsStatus_c__c = '已提交';
            Order3.SummonsForDirction__c = '直接销售给医院';

			insert new List<Consumable_order__c> {Order0, Order1,Order3};

			Consumable_orderdetails__c Orderdet = new Consumable_orderdetails__c();
			Orderdet.Name = 'OCM_01_00101';
			Orderdet.Consumable_order__c = Order0.Id;
			Orderdet.RecordTypeId = System.Label.RT_ConOrderDetail1_Order;
			Orderdet.Consumable_Product__c = pro1.Id;
			Orderdet.Consumable_count__c = 4;
            Orderdet.Shipment_Count__c = 10;
            Orderdet.isOutPattern__c = true;
            Orderdet.Delivery_List_RMB__c = 100;
            Orderdet.Box_Piece__c = '盒';
			insert Orderdet;
			Consumable_order_details2__c Orderdet1 = new Consumable_order_details2__c();
			Orderdet1.Name = 'OCM_01_001001';
			Orderdet1.Consumable_Sale_order__c = Order1.Id;
			Orderdet1.Consumable_Product__c = pro1.Id;
			Orderdet1.Asset_Model_No__c = 'Test01';
			Orderdet1.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet1.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet1.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJRF';
			Orderdet1.Cancellation_Date__c = null;
			Orderdet1.TracingCode__c = 'BXJRF';
			Orderdet1.SerialLotNo__c = '5ZK';
			Orderdet1.Arrive_date__c = Date.today();
			Orderdet1.exchangeOutPattern__c = true;
			Orderdet1.Used_date__c = Date.today();
			Orderdet1.Box_Piece__c = '盒';
			Orderdet1.Sterilization_limit__c= Date.today().addDays(2);
			// insert Orderdet1;
			Consumable_order_details2__c Orderdet2 = new Consumable_order_details2__c();
			Orderdet2.Name = 'OCM_01_001002';
			Orderdet2.Consumable_Shipment_order__c = Order1.Id;
			Orderdet2.Consumable_Product__c = pro1.Id;
			Orderdet2.Asset_Model_No__c = 'Test01';
			Orderdet2.Send_Date__c = Date.newInstance(2023, 1, 2);
			Orderdet2.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet2.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJA';
			Orderdet2.Cancellation_Date__c = null;
			Orderdet2.TracingCode__c = 'BXJA';
			Orderdet2.SerialLotNo__c = '5ZK';
			Orderdet2.Arrive_date__c = Date.today();
			Orderdet2.exchangeOutPattern__c = true;
			Orderdet2.Used_date__c = Date.today();
			Orderdet2.Box_Piece__c = '盒';
			Orderdet2.Sterilization_limit__c= Date.today().addDays(2);

			Consumable_order_details2__c Orderdet3 = new Consumable_order_details2__c();
			Orderdet3.Name = 'OCM_01_001002';
            Orderdet3.Consumable_Sale_order__c = Order3.Id;
			Orderdet3.Consumable_Product__c = pro1.Id;
			Orderdet3.Asset_Model_No__c = 'Test01';
            Orderdet3.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet3.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet3.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJB';
			Orderdet3.Cancellation_Date__c = null;
			Orderdet3.TracingCode__c = 'BXJB';
			Orderdet3.SerialLotNo__c = '5ZK';
            Orderdet3.Arrive_date__c = Date.today();
            Orderdet3.exchangeOutPattern__c = true;
			Orderdet3.Used_date__c = Date.today();
            Orderdet3.Box_Piece__c = '盒';
            Orderdet3.Sterilization_limit__c= Date.today().addDays(2);


			Consumable_order_details2__c Orderdet4 = new Consumable_order_details2__c();
			Orderdet4.Name = 'OCM_01_001002';
            Orderdet4.Consumable_Shipment_order__c = Order3.Id;
			Orderdet4.Consumable_Product__c = pro1.Id;
			Orderdet4.Asset_Model_No__c = 'Test01';
            Orderdet4.Send_Date__c = Date.newInstance(2023, 2, 2);
			Orderdet4.RecordTypeId = System.Label.RT_ConOrderDetail2_Delivery;
			Orderdet4.Bar_Code__c = '01049531702003111115120017181000105ZK250BXJR';
			Orderdet4.Cancellation_Date__c = null;
			Orderdet4.TracingCode__c = 'BXJR';
			Orderdet4.SerialLotNo__c = '5ZK';
            Orderdet4.Arrive_date__c = Date.today();
            Orderdet4.exchangeOutPattern__c = true;
			Orderdet4.Used_date__c = Date.today();
            Orderdet4.Box_Piece__c = '盒';
            Orderdet4.Sterilization_limit__c= Date.today().addDays(2);
            Orderdet4.Consumable_Sale_order__c=null;
			// insert Orderdet3;
			// Orderdet3 = [select id,Product_Type__c,Asset_Model_No__c,Inventory_Status__c  FROM Consumable_order_details2__c where id = :Orderdet3.id];
			insert new Consumable_order_details2__c[] {Orderdet1, Orderdet2,Orderdet3,Orderdet4};        

            System.Test.startTest();
            Database.executeBatch(new TrackConsumableSaleForecastBatch2C(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 2, 1),true), 200);
			System.Test.stopTest();
        }
    }
    static testMethod void batch4Test() {
            Database.executeBatch(new TrackConsumableSaleForecastBatch1(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 2, 1),true,true), 200);
            Database.executeBatch(new TrackConsumableSaleForecastBatch2(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 2, 1),true), 200);
            Database.executeBatch(new TrackConsumableSaleForecastBatch3(Date.newInstance(2023, 1, 1),Date.newInstance(2023, 2, 1),true,true), 200);
    }
}