@isTest
private class ConsumApplyWebServiceTest {
    // // 造出已批准的数据
    // @testSetup static void setupTestData(){
    //     ConsumTestDataFactory factory = new ConsumTestDataFactory();
    //     factory.setupTestData();
    //     factory.selectDetails();
    //     factory.approve();
    // }
    // 造出已出库申请
    static testMethod void testReceiveAll() {
    	try{
			Oly_TriggerHandler.bypass('ConsumApplyTrigger');
	        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
	        Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
	        ConsumTestDataFactory factory = new ConsumTestDataFactory();
	        factory.setupTestData();
	        factory.selectDetails();
	        factory.approve();
	        factory.defaultAssign();
	        factory.shippmentRequest();
	        factory.shipment();

	        Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1];
	        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = null;
	        caesdList = [SELECT Received_Confirm__c
	                          , Loaner_received_time__c
	                       FROM Consum_Apply_Equipment_Set_Detail__c];
	        System.assertEquals(null, caesdList[0].Received_Confirm__c);
	        System.assertEquals(null, caesdList[0].Loaner_received_time__c);
	        Test.startTest();
	        ConsumApplyWebService.all_received_fse(ca.Id);
	        ConsumApplyWebService.approvalCheck(ca.Id);
	        ConsumApplyWebService.setShipment_request(ca.Id);
	        ConsumApplyWebService.test();
	        ConsumApplyWebService.all_received_fse(null);
	        Test.stopTest();
	        // caesdList = [SELECT Received_Confirm__c
	        //                   , Loaner_received_time__c
	        //                FROM Consum_Apply_Equipment_Set_Detail__c];
	        // System.assertEquals('OK', caesdList[0].Received_Confirm__c);
	        // System.assertNotEquals(null, caesdList[0].Loaner_received_time__c);
    	}catch(Exception e){

    	}
        
    }
    
    static testMethod void testReceive2() {
        Oly_TriggerHandler.bypass('ConsumApplyTrigger');
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
		Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
       factory.setupTestData();
       factory.selectDetails();
       factory.approve();
       factory.defaultAssign();
       factory.shippmentRequest();

        // Consum_Apply__c ca = [SELECT Id FROM Consum_Apply__c LIMIT 1];
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id,Consum_Apply_Equipment_Set__c 
                                                        FROM Consum_Apply_Equipment_Set_Detail__c];
        // System.assertEquals(null, caesdList[0].Received_Confirm__c);
        // System.assertEquals(null, caesdList[0].Loaner_received_time__c);
        Test.startTest();
        ConsumApplyWebService.setShipment_requests('',caesdList[0].Consum_Apply_Equipment_Set__c);
        Test.stopTest();
        // caesdList = [SELECT Received_Confirm__c
        //                   , Loaner_received_time__c
        //                FROM Consum_Apply_Equipment_Set_Detail__c];
        // System.assertEquals('OK', caesdList[0].Received_Confirm__c);
        // System.assertNotEquals(null, caesdList[0].Loaner_received_time__c);
    }
    static testMethod void testMethod01() {
        FixtureDeliverySlip__c slip = new FixtureDeliverySlip__c();
        slip.Name = '运输单号1';
        slip.DeliveryType__c = '发货';
        slip.Distributor_method__c = '陆运';
        slip.DeliveryCompany__c = 'Fedex';
        slip.Wh_Staff__c = Userinfo.getUserId();
        slip.Shippment_loaner_time__c = Date.today();
        slip.Combine_Pack__c = '123';
        insert slip;

        OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = System.Today();
        oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
        insert oc;
      // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
     
     
        Consum_Apply__c ca = new Consum_Apply__c();
        ca.DataMigration_Flag__c = true;
        insert ca;

        Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c();
        caes.Consum_Apply__c = ca.Id;
        caes.Consum_Start_Date__c = Date.today().addDays(20);
        caes.DataMigration_Flag__c = true;
        insert caes;

        Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c();
        caesd.DataMigration_Flag__c = true;
        caesd.Consum_Apply__c = ca.Id;
        caesd.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd.Trial_User__c = '我';
        caesd.Follower_User__c = UserInfo.getUserId();
        caesd.Cancel_Select__c=false;
        caesd.Shipment_request__c=false;
        caesd.Consum_Apply__c = ca.Id;
        caesd.DeliverySlip__c=slip.id;
        // caesd.Shipment_request__c=false;
        // caesd.Cancel_Select__c = false;
        // ca
        insert caesd; // 草案中
        update caes;
        update ca;

        ConsumApplyWebService.approvalCheck(ca.Id);
        try{
			ConsumApplyWebService.getwkDate('','');
        }catch(Exception e){}
        
        try{
            ConsumApplyWebService.getwkDate('2023/10/10','1');
        }catch(Exception e){}
        try{
            ConsumApplyWebService.getwkDate('2023/10/10','-1');
        }catch(Exception e){}
        try {
            ConsumApplyWebService.postponeCheck(String.valueOf(oc.Date__c),-1);
        }catch(Exception e){}
        ConsumApplyWebService.AssignBtn(ca.Id);
        //ConsumApplyWebService.postponeCheck(String.valueOf(oc.Date__c),-1);
        ConsumApplyWebService c=new ConsumApplyWebService();
        c.getDateMap(Date.valueOf(oc.Date__c),Date.valueOf(oc.Date__c),1);
        ConsumApplyWebService.ConsumApplyCancel(ca.Id,true);
        ConsumApplyWebService.ConsumApplyCancel(ca.Id,false);
        ConsumApplyWebService.setShipment_requests(ca.Id,caes.id);
        ConsumApplyWebService.all_received_fse(ca.Id);
    }

    static testMethod void testMethod02() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = '販売店',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
    }
    static testMethod void testMethod03() {
        Consum_Apply__c ca = new Consum_Apply__c();
        ca.DataMigration_Flag__c = true;
        insert ca;
        Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c();
        caes.Consum_Apply__c = ca.Id;
        caes.Consum_Start_Date__c = Date.today().addDays(20);
        caes.DataMigration_Flag__c = true;

        insert caes;


        FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c();
        fds.Name = 'TEST';
        fds.Distributor_method__c = '空运';
        fds.DeliveryCompany__c = '顺丰';
        fds.Wh_Staff__c = Userinfo.getUserId();
        fds.DeliveryType__c = '回寄';
        insert fds;





        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;

        // 病院を作る
        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.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        Account account1 =new Account();
        account1.Name = 'test1医院';
        account1.RecordTypeId = '01210000000QemG';
        insert account1;
        Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.RecordTypeId = System.Label.Asset_RecordType;
        assetC1.SerialNumber = 'assetC1';
        assetC1.Name = 'assetC1';
        assetC1.AccountId = account1.Id;
        assetC1.Quantity = 1;
        assetC1.Status = '有库存';
        assetC1.Manage_type__c = '个体管理';
        assetC1.Internal_asset_location__c = '北京 备品中心';
        assetC1.Loaner_accsessary__c = true;
        assetC1.Delete_Flag__c = false;
        assetC1.Freeze_sign__c = false;
        Date n=System.today();
        assetC1.Consumable_Guaranteen_end__c=n;
        insert assetC1;

        Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c();
        caesd.DataMigration_Flag__c = true;
        caesd.Consum_Apply__c = ca.Id;
        caesd.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd.Trial_User__c = '我';
        caesd.Follower_User__c = UserInfo.getUserId();
        caesd.Return_DeliverySlip__c =  fds.Id;
        caesd.Received_Confirm__c = 'OK';
        caesd.Asset_Center_Confirm__c = 'OK';
        caesd.Dao_Huo_OK_Jia__c = 1;
        caesd.Dao_Huo_NG_Jia__c = 0;
        caesd.Hui_Ji_Jia__c = 0;
        caesd.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd.Shang_Jia_Jia__c=null;
        caesd.Fixture_Model_No_text__c ='dd';
        caesd.Asset__c=assetC1.Id;
        insert caesd; // 草案中

        Consum_Apply_Equipment_Set_Detail__c caesd2 = new Consum_Apply_Equipment_Set_Detail__c();
        caesd2.DataMigration_Flag__c = true;
        caesd2.Consum_Apply__c = ca.Id;
        caesd2.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd2.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd2.Trial_User__c = '我';
        caesd2.Follower_User__c = UserInfo.getUserId();
        caesd2.Return_DeliverySlip__c = fds.Id;
        caesd2.Received_Confirm__c = 'OK';
        caesd2.Asset_Center_Confirm__c = 'OK';
        caesd2.Dao_Huo_OK_Jia__c = 1;
        caesd2.Dao_Huo_NG_Jia__c = 0;
        caesd2.Hui_Ji_Jia__c = 0;
        caesd2.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd2.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd2.Shang_Jia_Jia__c=null;
        caesd2.Asset__c=assetC1.Id;
        insert caesd2; // 草案中
        ConsumApplyWebService.all_received_fse(ca.Id);
    }
    static testMethod void testMethod04() {
        ControllerUtil.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass('ContactTrigger');
        Oly_TriggerHandler.bypass('ContactTriggerHandler');
        Oly_TriggerHandler.bypass('PIHelper');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetDetailTrigger');
        Oly_TriggerHandler.bypass('ConsumApplyEquipmentSetDetailHandler');
        Consum_Apply__c ca = new Consum_Apply__c();
        ca.DataMigration_Flag__c = true;
        ca.Status__c='申请中';
        insert ca;
        Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c();
        caes.Consum_Apply__c = ca.Id;
        caes.Consum_Start_Date__c = Date.today().addDays(20);
        caes.DataMigration_Flag__c = true;

        insert caes;


        FixtureDeliverySlip__c fds = new FixtureDeliverySlip__c();
        fds.Name = 'TEST';
        fds.Distributor_method__c = '空运';
        fds.DeliveryCompany__c = '顺丰';
        fds.Wh_Staff__c = Userinfo.getUserId();
        fds.DeliveryType__c = '回寄';
        insert fds;





        Address_Level__c al = new Address_Level__c();
        al.Name = '東京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '東京';
        al2.Name = '渋谷区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;

        // 病院を作る
        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.State_Master__c = al.id;
        hospital.City_Master__c = al2.id;
        hospital.Town__c = '东京';
        insert hospital;

        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        Contact contact2 = new Contact();
        contact2.AccountId = dep.Id;
        contact2.FirstName = '責任者';
        contact2.LastName = 'test1经销商';
        insert contact2;

        // 产品
        Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',
                Fixture_Model_No__c='n01',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc01',Manual_Entry__c=false);
        insert pro1;
        // 耗材类保有设备
        Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        assetC1.RecordTypeId = System.Label.Asset_RecordType;
        assetC1.SerialNumber = 'ass01';
        assetC1.Name = 'ass01';
        assetC1.AccountId = dep.Id;
        assetC1.Department_Class__c = strategicDep[0].Id;
        assetC1.Hospital__c = hospital.Id;
        assetC1.Product2Id = pro1.Id;
        assetC1.Quantity = 10;
        assetC1.Consumed_Count__c = 1;
        assetC1.Status = '有库存';
        assetC1.Manage_type__c = '数量管理';
        assetC1.Loaner_accsessary__c = true;
        assetC1.Product_category__c = 'GI';
        assetC1.Delete_Flag__c = false;
        assetC1.Freeze_sign__c = false;
        // assetC1.Out_of_wh__c = 0;
        assetC1.Asset_loaner_category__c = '耗材';
        assetC1.AssetMark__c = '耗材';
        assetC1.Frozen_Quantity__c = 2;
        assetC1.Salesdepartment__c = '0.备品中心';
        assetC1.Internal_asset_location__c = '上海 备品中心';
        assetC1.Product_category__c = 'GI';
        assetC1.Equipment_Type__c = '产品试用';
        assetC1.SalesProvince__c = '上海';
        assetC1.WH_location__c = '货架号1';
        assetC1.AssetManageConfirm__c = true;
        // assetC1.Rental_Count__c=0;
        insert assetC1;
        // Asset assetC1 = new Asset(Asset_Owner__c = 'Olympus');
        // assetC1.RecordTypeId = System.Label.Asset_RecordType;
        // assetC1.SerialNumber = 'assetC1';
        // assetC1.Name = 'assetC1';
        // assetC1.AccountId = account1.Id;
        // assetC1.Quantity = 1;
        // assetC1.Status = '有库存';
        // assetC1.Manage_type__c = '个体管理';
        // assetC1.Internal_asset_location__c = '北京 备品中心';
        // assetC1.Loaner_accsessary__c = true;
        // assetC1.Delete_Flag__c = false;
        // assetC1.Freeze_sign__c = false;
        // Date n=System.today();
        // assetC1.Consumable_Guaranteen_end__c=n;
        // insert assetC1;

        Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c();
        caesd.DataMigration_Flag__c = true;
        caesd.Consum_Apply__c = ca.Id;
        caesd.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd.Trial_User__c = '我';
        caesd.Follower_User__c = UserInfo.getUserId();
        caesd.Return_DeliverySlip__c =  fds.Id;
        caesd.Received_Confirm__c = 'OK';
        caesd.Asset_Center_Confirm__c = 'OK';
        caesd.Dao_Huo_OK_Jia__c = 0;
        caesd.Dao_Huo_NG_Jia__c = 0;
        caesd.Hui_Ji_Jia__c = 0;
        caesd.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd.Shang_Jia_Jia__c=null;
        caesd.Fixture_Model_No_text__c ='dd';
        caesd.Asset__c=assetC1.Id;
        insert caesd;
        caesd.Select_Time__c=System.now();
        // update caesd; // 草案中

        FixtureDeliverySlip__c slip = new FixtureDeliverySlip__c();
        slip.Name = '运输单号';
        slip.DeliveryType__c = '发货';
        slip.Distributor_method__c = '陆运';
        slip.DeliveryCompany__c = 'Fedex';
        slip.Wh_Staff__c = Userinfo.getUserId();
        slip.Combine_Pack__c = '123';
        insert slip;

        caesd.Shippment_loaner_time__c = System.Now();
        caesd.DeliverySlip__c = slip.Id;
        //update caesd; // 已出库

        caesd.Received_Confirm__c = 'OK';
        // update caesd; // 申请者已收货

        Consum_Apply_Equipment_Set_Detail__c caesd2 = new Consum_Apply_Equipment_Set_Detail__c();
        caesd2.DataMigration_Flag__c = true;
        caesd2.Consum_Apply__c = ca.Id;
        caesd2.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd2.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd2.Trial_User__c = '我';
        caesd2.Follower_User__c = UserInfo.getUserId();
        caesd2.Return_DeliverySlip__c = fds.Id;
        caesd2.Received_Confirm__c = 'OK';
        caesd2.Asset_Center_Confirm__c = 'OK';
        caesd2.Dao_Huo_OK_Jia__c = 1;
        caesd2.Dao_Huo_NG_Jia__c = 0;
        caesd2.Hui_Ji_Jia__c = 0;
        caesd2.Yi_Zhi_Bao_Fei_Jia__c=null;
        caesd2.Yi_Zhi_Guo_Qi_Jia__c=null;
        caesd2.Shang_Jia_Jia__c=null;
        caesd2.Asset__c=assetC1.Id;
        // caesd2.Select_Time__c=System.now();
        insert caesd2; // 草案中
        ConsumApplyWebService.all_received_fse(ca.Id);
        ConsumApplyWebService.approvalCheck(ca.Id);
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.defaultAssign();
        try{
            ConsumApplyWebService.getWD_now(Date.today());
        }catch(Exception e){

        }
        try{
            ConsumApplyWebService.getWD_addday(Date.today(),1);
        }catch(Exception e){
            
        }
        try{
            ConsumApplyWebService.getWD_addday(Date.today(),-1);
        }catch(Exception e){
            
        }
        try{
            ConsumApplyWebService.setRaesShipment_request(caes.Id);
        }catch(Exception e){
            
        }
        try{
            ConsumApplyWebService.setShipment_request(ca.Id);
        }catch(Exception e){
            
        }
    }        
        


    // static testMethod void testMethod13() {
    //     List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
    //     if (rectCo.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
    //     if (rectSct.size() == 0) {
    //         return;
    //     }
    //     List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
    //     if (rectDpt.size() == 0) {
    //         return;
    //     }
    //      List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
    //     if (rectAs.size() == 0) {
    //         return;
    //     }

     
    //     // insert hospital
    //     Account company1 = new Account();
    //     company1.RecordTypeId = rectCo[0].Id;
    //     company1.Name = '病院テスト1';
    //     company1.OCM_man_province_txt__c = '江西';
    //     List<Account> hps = new Account[]{company1};
    //     insert hps;
          
    //     List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
    //     Account depart1 = new Account();
    //     depart1.RecordTypeId = rectDpt[0].Id;
    //     depart1.Name         = '*';
    //     depart1.Department_Name__c  = '診療科1';
    //     depart1.ParentId            = dc1s[0].Id;
    //     depart1.Department_Class__c = dc1s[0].Id;
    //     depart1.Hospital__c         = company1.Id;
    //     depart1.OCM_man_province_txt__c = '江西';
        
    //     insert new Account[] {depart1};

    //     List<Product2> prdList = new List<Product2>();
    //     Product2 prd1 = new Product2();
    //     prd1.ProductCode_Ext__c     = 'HistoryPrd1';
    //     prd1.ProductCode            = 'HistoryPrd1';
    //     prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
    //     prd1.Name                   = 'HistoryPrd1';
    //     prd1.Manual_Entry__c        = false;
    //     prd1.Extend_new_product_gurantee__c = true;
    //     prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
    //     prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
    //     prdList.add(prd1);
    //     insert prdList;
    
    //     Asset ast = new Asset();

    //     ast.RecordTypeId = rectAs[0].Id;
    //     ast.SerialNumber = 'abcdefg';
    //     ast.Name = '测试资产1';
    //     ast.AccountId              = depart1.Id;
    //     ast.Department_Class__c    = dc1s[0].Id;
    //     ast.Hospital__c            = company1.Id;
    //     ast.Product2Id             = prd1.Id;
    //     ast.Guarantee_period_for_products__c = Date.today();
    //     ast.InstallDate                      = Date.today();
    //     ast.Manage_type__c = '个体管理';
    //     ast.FirstApproveDate_old__c = Date.today().addDays(-30);

    //     Oly_TriggerHandler.bypass('AssetHandler');

    //     insert ast;
        
    //     Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
    //     String RecordTypeID = ast1.RecordTypeID__c;
           
    //     System.assertEquals(RecordTypeID , ast.RecordTypeId);

    //     RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
     
    //     Opportunity opp4 = new Opportunity(
    //            Name='testOpp1',
    //            StageName='引合',
    //            CloseDate=Date.today(),
    //            AccountId=depart1.Id,
    //            Sales_Root__c = '販売店',
    //            Competitor__c ='A',
    //            Click_Close_Date__c = null,
    //            RecordType = rectOpp,
    //            Opportunity_No__c = 'SP'
    //     );
    //     insert opp4;
    //     opp4.Opportunity_No__c='SP';
    //     update opp4;
    //     //注残
    //     Statu_Achievements__c Sac4 = new Statu_Achievements__c(
    //         name = 'zhucan_one',
    //         Opportunity__c = opp4.id,
    //         DeliveryDate__c = Date.today(),
    //         ContractNO__c = 'ContractNO1',
    //         ContractAmount__c = 1000
    //     );
    //     insert Sac4;
    //     ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac4.Id);
    // }
    static testMethod void testMethod14() {
        Oly_TriggerHandler.bypass('ConsumApplyTrigger');
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
		Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        factory.approve();
        factory.defaultAssign();
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id, Consum_Apply__c,Consum_Apply_Equipment_Set__c 
              FROM Consum_Apply_Equipment_Set_Detail__c];
        ConsumApplyWebService.setRaesShipment_request(caesdList[0].Consum_Apply_Equipment_Set__c);
    }
    static testMethod void testMethod15() {
    	try{
    	    Oly_TriggerHandler.bypass('ConsumApplyTrigger');
	        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
			Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
	        ConsumTestDataFactory factory = new ConsumTestDataFactory();
	        factory.setupTestData();
	        factory.selectDetails();
	        factory.approve();
	        factory.defaultAssign();
	        factory.shippmentRequest();
	        // factory.shipment();
	        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id, Consum_Apply__c,Consum_Apply_Equipment_Set__c 
	              FROM Consum_Apply_Equipment_Set_Detail__c];
	        ConsumApplyWebService.setRaesShipment_request(caesdList[0].Consum_Apply_Equipment_Set__c);	
    	}catch(Exception e){

    	}

    }
    static testMethod void testMethod05() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = '販売店',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'GI'
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
    }
    static testMethod void test_RentalApplyCheckForSAoneEle() {
        ControllerUtil.EscapeNFM001Trigger = true; // OLY_OCM-643 追加ControllerUtil.EscapeNFM001Trigger
        System.runAs(new User(Id = Userinfo.getUserId())) {
            StaticParameter.EscapeNFM001AgencyContractTrigger = true;
            StaticParameter.EscapeNFM001Trigger = true;
            Oly_TriggerHandler.bypass(AssetHandler.Class.getName());
            // Implement test code
            //Profile prof = [select Id from Profile where Name ='系统管理员'];
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            // 产品
            Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false);
            Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false);
            Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',Asset_Model_No__c='n03',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc03',Manual_Entry__c=false);
            insert new Product2[] {pro1, pro2, pro3};
            RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
            // 戦略科室を得る
            Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
            dep.Name = 'test dep';
            dep.AgentCode_Ext__c = '9999998';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;

            // 资产
            Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
            asset1.RecordTypeId = System.Label.Asset_RecordType;
            asset1.SerialNumber = 'ass01';
            asset1.Name = 'ass01';
            asset1.AccountId = dep.Id;
            asset1.Department_Class__c = strategicDep[0].Id;
            asset1.Hospital__c = hospital.Id;
            asset1.Product2Id = pro1.Id;
            asset1.Manage_type__c = '个体管理';

            Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
            asset2.RecordTypeId = System.Label.Asset_RecordType;
            asset2.SerialNumber = 'ass02';
            asset2.Loaner_accsessary__c = true;
            asset2.Name = 'ass02';
            asset2.AccountId = dep.Id;
            asset2.Department_Class__c = strategicDep[0].Id;
            asset2.Hospital__c = hospital.Id;
            asset2.Product2Id = pro2.Id;

            Asset asset3 = new Asset(Asset_Owner__c = 'Olympus');
            asset3.RecordTypeId = System.Label.Asset_RecordType;
            asset3.SerialNumber = 'ass03';
            asset3.Loaner_accsessary__c = true;
            asset3.Name = 'ass03';
            asset3.AccountId = dep.Id;
            asset3.Department_Class__c = strategicDep[0].Id;
            asset3.Hospital__c = hospital.Id;
            asset3.Product2Id = pro3.Id;
            insert new Asset[] {asset1, asset2,asset3};

            Oly_TriggerHandler.clearAllBypasses();
            System.Test.startTest();
            Opportunity opp1 = new Opportunity(
                Name='testOpp1',
                StageName='引合',
                CloseDate=Date.today(),
                Close_Forecasted_Date__c=Date.today().addDays(-2),
                AccountId=dep.Id,
                Sales_Root__c = '販売店',
                Competitor__c ='A',
                Click_Close_Date__c = null,
                RecordType = rectOpp,
                Opportunity_No__c = 'GI'
            );
            Opportunity opp2 = new Opportunity(
                Name='testOpp1',
                StageName='引合',
                CloseDate=Date.today(),
                Close_Forecasted_Date__c=Date.today().addDays(-2),
                AccountId=dep.Id,
                Sales_Root__c = '販売店',
                Competitor__c ='A',
                Click_Close_Date__c = null,
                RecordType = rectOpp,
                Opportunity_No__c = 'SP'
            );
            insert new Opportunity[] {opp2, opp1};
            opp2.Opportunity_No__c = 'SP';
            opp1.Opportunity_No__c = 'GI';
            update new Opportunity[] {opp2, opp1};
            //注残
            Statu_Achievements__c Sac = new Statu_Achievements__c(
                name = 'zhucan_one',
                Opportunity__c = opp1.id,
                SoLatestDeliveryDate__c = Date.today(),
                FirstApproveDate__c = Date.today(),
                OverviewStatus__c = '注残',
                ContractAmount__c = 0
            );
            Statu_Achievements__c Sac2 = new Statu_Achievements__c(
                name = 'zhucan_one',
                Opportunity__c = opp2.id,
                SoLatestDeliveryDate__c = Date.today(),
                FirstApproveDate__c = Date.today(),
                OverviewStatus__c = '注残',
                ContractAmount__c = 0
            );
            insert new Statu_Achievements__c[]{Sac, Sac2};

            List<Statu_Achievements__c> ss = [Select Id,Status_2_Formula__c, Status_1__c, Opp_Number__c From Statu_Achievements__c];
            System.assertEquals('13 待发货', ss[0].Status_2_Formula__c);
            System.assertEquals('注残', ss[0].Status_1__c);
            System.assertEquals('13 待发货', ss[1].Status_2_Formula__c);
            System.assertEquals('注残', ss[1].Status_1__c);

            ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
            ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac2.Id);
            // ConsumApplyWebService.ConsumApplyCheckForSAoneEle(ss[1].Id);
            System.Test.stopTest();
        }
    }
    static testMethod void test_RentalApplyCheckForSAoneEle2() {
        ControllerUtil.EscapeNFM001Trigger = true; // OLY_OCM-643 追加ControllerUtil.EscapeNFM001Trigger
        System.runAs(new User(Id = Userinfo.getUserId())) {
            StaticParameter.EscapeNFM001AgencyContractTrigger = true;
            StaticParameter.EscapeNFM001Trigger = true;
            Oly_TriggerHandler.bypass(AssetHandler.Class.getName());
            // Implement test code
            //Profile prof = [select Id from Profile where Name ='系统管理员'];
            // 病院を作る
            Account hospital = new Account();
            hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
            hospital.Name = 'test hospital';
            insert hospital;
            // 产品
            Product2 pro1 = new Product2(Name='name01',IsActive=true,Family='GI',Asset_Model_No__c='n01',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc01',Manual_Entry__c=false);
            Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',Asset_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',ProductCode_Ext__c='pc02',Manual_Entry__c=false);
            Product2 pro3 = new Product2(Name='name03',IsActive=true,Family='GI',Asset_Model_No__c='n03',Serial_Lot_No__c='S/N tracing',ProductCode_Ext__c='pc03',Manual_Entry__c=false);
            insert new Product2[] {pro1, pro2, pro3};
            RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
            // 戦略科室を得る
            Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
            Account dep = new Account();
            dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
            dep.Name = 'test dep';
            dep.AgentCode_Ext__c = '9999998';
            dep.ParentId = strategicDep[0].Id;
            dep.Department_Class__c = strategicDep[0].Id;
            dep.Hospital__c = hospital.Id;
            insert dep;

            // 资产
            Asset asset1 = new Asset(Asset_Owner__c = 'Olympus');
            asset1.RecordTypeId = System.Label.Asset_RecordType;
            asset1.SerialNumber = 'ass01';
            asset1.Name = 'ass01';
            asset1.AccountId = dep.Id;
            asset1.Department_Class__c = strategicDep[0].Id;
            asset1.Hospital__c = hospital.Id;
            asset1.Product2Id = pro1.Id;
            asset1.Manage_type__c = '个体管理';

            Asset asset2 = new Asset(Asset_Owner__c = 'Olympus');
            asset2.RecordTypeId = System.Label.Asset_RecordType;
            asset2.SerialNumber = 'ass02';
            asset2.Loaner_accsessary__c = true;
            asset2.Name = 'ass02';
            asset2.AccountId = dep.Id;
            asset2.Department_Class__c = strategicDep[0].Id;
            asset2.Hospital__c = hospital.Id;
            asset2.Product2Id = pro2.Id;

            Asset asset3 = new Asset(Asset_Owner__c = 'Olympus');
            asset3.RecordTypeId = System.Label.Asset_RecordType;
            asset3.SerialNumber = 'ass03';
            asset3.Loaner_accsessary__c = true;
            asset3.Name = 'ass03';
            asset3.AccountId = dep.Id;
            asset3.Department_Class__c = strategicDep[0].Id;
            asset3.Hospital__c = hospital.Id;
            asset3.Product2Id = pro3.Id;
            insert new Asset[] {asset1, asset2,asset3};

            Oly_TriggerHandler.clearAllBypasses();
            System.Test.startTest();
            Opportunity opp1 = new Opportunity(
                Name='testOpp1',
                StageName='引合',
                CloseDate=Date.today(),
                Close_Forecasted_Date__c=Date.today().addDays(-2),
                AccountId=dep.Id,
                Sales_Root__c = 'OCM直接販売',
                Competitor__c ='A',
                Click_Close_Date__c = null,
                RecordType = rectOpp,
                Opportunity_No__c = 'GI'
            );
            Opportunity opp2 = new Opportunity(
                Name='testOpp1',
                StageName='引合',
                CloseDate=Date.today(),
                Close_Forecasted_Date__c=Date.today().addDays(-2),
                AccountId=dep.Id,
                Sales_Root__c = 'OCM直接販売',
                Competitor__c ='A',
                Click_Close_Date__c = null,
                RecordType = rectOpp,
                Opportunity_No__c = 'SP'
            );
            insert new Opportunity[] {opp2, opp1};
            opp2.Opportunity_No__c = 'SP';
            opp1.Opportunity_No__c = 'GI';
            update new Opportunity[] {opp2, opp1};
            //注残
            Statu_Achievements__c Sac = new Statu_Achievements__c(
                name = 'zhucan_one',
                Opportunity__c = opp1.id,
                SoLatestDeliveryDate__c = Date.today(),
                FirstApproveDate__c = Date.today(),
                OverviewStatus__c = '注残',
                ContractAmount__c = 0
            );
            Statu_Achievements__c Sac2 = new Statu_Achievements__c(
                name = 'zhucan_one',
                Opportunity__c = opp2.id,
                SoLatestDeliveryDate__c = Date.today(),
                FirstApproveDate__c = Date.today(),
                OverviewStatus__c = '注残',
                ContractAmount__c = 0
            );
            insert new Statu_Achievements__c[]{Sac, Sac2};

            List<Statu_Achievements__c> ss = [Select Id,Status_2_Formula__c, Status_1__c, Opp_Number__c From Statu_Achievements__c];
            System.assertEquals('13 待发货', ss[0].Status_2_Formula__c);
            System.assertEquals('注残', ss[0].Status_1__c);
            System.assertEquals('13 待发货', ss[1].Status_2_Formula__c);
            System.assertEquals('注残', ss[1].Status_1__c);

            ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
            ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac2.Id);
            // ConsumApplyWebService.ConsumApplyCheckForSAoneEle(ss[1].Id);
            System.Test.stopTest();
        }
    }
    static testMethod void testMethod06() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = '販売店',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'SP'
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
    }
    static testMethod void testMethod07() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = 'OCM直接販売',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'GI'
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
    }
    static testMethod void testMethod08() {
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = 'OCM直接販売',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'SP'
        );
        insert opp;

        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
        ConsumApplyWebService.test();
    }
    static testMethod void testMethod09() {
        FixtureDeliverySlip__c slip = new FixtureDeliverySlip__c();
        slip.Name = '运输单号1';
        slip.DeliveryType__c = '发货';
        slip.Distributor_method__c = '陆运';
        slip.DeliveryCompany__c = 'Fedex';
        slip.Wh_Staff__c = Userinfo.getUserId();
        slip.Shippment_loaner_time__c = Date.today();
        slip.Combine_Pack__c = '123';
        insert slip;

        OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = Date.valueOf('2023-10-18');
        oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
        // oc.IsWorkDay__c=1;
        insert oc;
      // 病院を作る
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hospital.Name = 'test hospital';
        insert hospital;
        // 戦略科室を得る
        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
            // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dep.Name = 'test dep';
        dep.AgentCode_Ext__c = '9999998';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;
     
     
        Consum_Apply__c ca = new Consum_Apply__c();
        ca.DataMigration_Flag__c = true;
        insert ca;

        Consum_Apply_Equipment_Set__c caes = new Consum_Apply_Equipment_Set__c();
        caes.Consum_Apply__c = ca.Id;
        caes.Consum_Start_Date__c = Date.today().addDays(20);
        caes.DataMigration_Flag__c = true;
        insert caes;

        Consum_Apply_Equipment_Set_Detail__c caesd = new Consum_Apply_Equipment_Set_Detail__c();
        caesd.DataMigration_Flag__c = true;
        caesd.Consum_Apply__c = ca.Id;
        caesd.Consum_Apply_Equipment_Set__c = caes.Id;
        caesd.Consum_Start_Date__c = caes.Consum_Start_Date__c;
        caesd.Trial_User__c = '我';
        caesd.Follower_User__c = UserInfo.getUserId();
        caesd.Cancel_Select__c=false;
        caesd.Shipment_request__c=false;
        caesd.Consum_Apply__c = ca.Id;
        caesd.DeliverySlip__c=slip.id;
        // caesd.Shipment_request__c=false;
        // caesd.Cancel_Select__c = false;
        // ca
        insert caesd; // 草案中
        update caes;
        update ca;

        ConsumApplyWebService.approvalCheck(ca.Id);
        ConsumApplyWebService.getwkDate('','');
        try{
            ConsumApplyWebService.getwkDate('2023/10/10','1');
        }catch(Exception e){}
        try{
            ConsumApplyWebService.getwkDate('2023/10/10','-1');
        }catch(Exception e){}
        try {
            ConsumApplyWebService.postponeCheck(String.valueOf(oc.Date__c),-1);
        }catch(Exception e){}
        ConsumApplyWebService.AssignBtn(ca.Id);
        //ConsumApplyWebService.postponeCheck(String.valueOf(oc.Date__c),-1);
        ConsumApplyWebService c=new ConsumApplyWebService();
        c.getDateMap(Date.valueOf(oc.Date__c),Date.valueOf(oc.Date__c),1);





        ConsumApplyWebService.ConsumApplyCancel(ca.Id,true);




        ConsumApplyWebService.ConsumApplyCancel(ca.Id,false);
        ConsumApplyWebService.setShipment_requests(ca.Id,caes.id);
        ConsumApplyWebService.all_received_fse(ca.Id);
    }





























    static testMethod void testMethod10() {
    	try{
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        Opportunity opp = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = 'OCM直接販売',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'SP'
        );
        insert opp;
        opp.Opportunity_No__c='GI';
        update opp;
        //注残
        Statu_Achievements__c Sac = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );

        insert Sac;
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac.Id);
        }catch(Exception e){

        }
    }
    static testMethod void testMethod11() {
    	try{
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];
        

        Opportunity opp2 = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = 'OCM直接販売',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'SP'
        );
        insert opp2;
        opp2.Opportunity_No__c='SP';
        update opp2;
        //注残
        Statu_Achievements__c Sac2 = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp2.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac2;

        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac2.Id);
        }catch(Exception e){
        	
        }
    }
    static testMethod void testMethod12() {
    	try{
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        if (rectDpt.size() == 0) {
            return;
        }
         List<RecordType> rectAs = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Asset' and Name = '备品'];
        if (rectAs.size() == 0) {
            return;
        }

     
        // insert hospital
        Account company1 = new Account();
        company1.RecordTypeId = rectCo[0].Id;
        company1.Name = '病院テスト1';
        company1.OCM_man_province_txt__c = '江西';
        List<Account> hps = new Account[]{company1};
        insert hps;
          
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        depart1.OCM_man_province_txt__c = '江西';
        
        insert new Account[] {depart1};

        List<Product2> prdList = new List<Product2>();
        Product2 prd1 = new Product2();
        prd1.ProductCode_Ext__c     = 'HistoryPrd1';
        prd1.ProductCode            = 'HistoryPrd1';
        prd1.Repair_Product_Code__c = 'HistoryPrd1_RP';
        prd1.Name                   = 'HistoryPrd1';
        prd1.Manual_Entry__c        = false;
        prd1.Extend_new_product_gurantee__c = true;
        prd1.Extend_Gurantee_Start__c = Date.today().addDays(-60);
        prd1.Extend_Gurantee_End__c = Date.today().addDays(60);
        prdList.add(prd1);
        insert prdList;
    
        Asset ast = new Asset();

        ast.RecordTypeId = rectAs[0].Id;
        ast.SerialNumber = 'abcdefg';
        ast.Name = '测试资产1';
        ast.AccountId              = depart1.Id;
        ast.Department_Class__c    = dc1s[0].Id;
        ast.Hospital__c            = company1.Id;
        ast.Product2Id             = prd1.Id;
        ast.Guarantee_period_for_products__c = Date.today();
        ast.InstallDate                      = Date.today();
        ast.Manage_type__c = '个体管理';
        ast.FirstApproveDate_old__c = Date.today().addDays(-30);

        Oly_TriggerHandler.bypass('AssetHandler');

        insert ast;
        
        Asset ast1 = [select RecordTypeID__c from Asset where Id =: ast.Id];
        
        String RecordTypeID = ast1.RecordTypeID__c;
           
        System.assertEquals(RecordTypeID , ast.RecordTypeId);

        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity' ];


        Opportunity opp3 = new Opportunity(
               Name='testOpp1',
               StageName='引合',
               CloseDate=Date.today(),
               AccountId=depart1.Id,
               Sales_Root__c = '販売店',
               Competitor__c ='A',
               Click_Close_Date__c = null,
               RecordType = rectOpp,
               Opportunity_No__c = 'SP'
        );
        insert opp3;
        opp3.Opportunity_No__c='GI';
        update opp3;
        //注残
        Statu_Achievements__c Sac3 = new Statu_Achievements__c(
            name = 'zhucan_one',
            Opportunity__c = opp3.id,
            DeliveryDate__c = Date.today(),
            ContractNO__c = 'ContractNO1',
            ContractAmount__c = 1000
        );
        insert Sac3;
        
        ConsumApplyWebService.ConsumApplyCheckForSAoneEle(Sac3.Id);
        }catch(Exception e){
        	
        }
    }








    static testMethod void testMethod16() {
        Oly_TriggerHandler.bypass('ConsumApplyTrigger');
        Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
		Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
        ConsumTestDataFactory factory = new ConsumTestDataFactory();
        factory.setupTestData();
        factory.selectDetails();
        // factory.approve();
        // factory.defaultAssign();
        List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id, Consum_Apply__c,Consum_Apply_Equipment_Set__c 
              FROM Consum_Apply_Equipment_Set_Detail__c];
        ConsumApplyWebService.setRaesShipment_request(caesdList[0].Consum_Apply_Equipment_Set__c);
        ConsumApplyWebService.all_received_fse(caesdList[0].Consum_Apply__c);
        ConsumApplyWebService.approvalCheck('d');
        ConsumApplyWebService.getWD_addday(Date.valueOf('4000-12-31'),1);

        OlympusCalendar__c oc = new OlympusCalendar__c();
        oc.Date__c = System.Today();
        // oc.IsWorkDay__c=1;
        oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
        insert oc;
        try{
        	ConsumApplyWebService.getWD_addday(oc.Date__c,1);
        }catch(Exception e){

        }
        try{
        	ConsumApplyWebService.getWD_addday(oc.Date__c,-1);
        }catch(Exception e){

        }
        
        ConsumApplyWebService c=new ConsumApplyWebService();
        c.getDateMap(Date.valueOf(oc.Date__c),Date.valueOf(oc.Date__c),0);
    }
    private static User getUser1() {
        String timenow = Datetime.now().format('yyyyMMddHHmmss');
        User user1 = new User(Test_staff__c = true, LastName = 'TestMao1', FirstName = 'TestMaoF1',
                              Alias = 'hp1', Email = 'Test1@sunbridge.com',
                              Username = 'Test1' + timenow + '@sunbridge.com', IsActive = true, 
                              EmailEncodingKey = 'ISO-2022-JP',TimeZoneSidKey = 'Asia/Tokyo', 
                              LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja',
                              ProfileId = System.Label.ProfileId_SystemAdmin,
                              Dept__c = '医疗华北营业本部', Job_Category__c = '销售服务', JingliEquipmentManager__c=UserInfo.getUserId(),
                              SalesManager__c=UserInfo.getUserId(),JingliApprovalManager__c=Userinfo.getUserId(),
                              Province__c = '北京');

        //List<Profile> p = [Select Id From Profile Where Name = '2S6_销售本部窗口&营业助理'];
        //System.assertEquals(p.size(), 1);
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user1;
        }
        return user1;
    }
    static testMethod void testMethod17() {
        User user1 = getUser1();
        System.runAs(user1) {
            Oly_TriggerHandler.bypass('ConsumApplyTrigger');
            Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
		Oly_TriggerHandler.bypass('AssetHandlerCheckQueuable');
            ConsumTestDataFactory factory = new ConsumTestDataFactory();
            factory.setupTestData();
            factory.selectDetails();
            Consum_Apply__c ca = [select id,Status__c from Consum_Apply__c limit1];
            ca.Status__c='申请中';
            update ca;
            // ca.Status__c='申请中';
            // update ca;
            // factory.approve();
            // factory.defaultAssign();
            // List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id, Consum_Apply__c,Consum_Apply_Equipment_Set__c 
            //       FROM Consum_Apply_Equipment_Set_Detail__c];
            // ConsumApplyWebService.setRaesShipment_request(caesdList[0].Consum_Apply_Equipment_Set__c);
            // ConsumApplyWebService.all_received_fse(caesdList[0].Consum_Apply__c);
            // ConsumApplyWebService.approvalCheck('d');
            // ConsumApplyWebService.getWD_addday(Date.valueOf('4000-12-31'),1);

            // OlympusCalendar__c oc = new OlympusCalendar__c();
            // oc.Date__c = System.Today();
            // // oc.IsWorkDay__c=1;
            // oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
            // insert oc;
            // ConsumApplyWebService.getWD_addday(oc.Date__c,1);
            // ConsumApplyWebService.getWD_addday(oc.Date__c,-1);
            // ConsumApplyWebService c=new ConsumApplyWebService();
            // c.getDateMap(Date.valueOf(oc.Date__c),Date.valueOf(oc.Date__c),0);
            ConsumApplyWebService.ConsumApplyCancel(ca.Id,true);
        }
    }
    static testMethod void testMethod18() {
        User user1 = getUser1();
        System.runAs(user1) {
            Oly_TriggerHandler.bypass('ConsumApplyTrigger');
            Oly_TriggerHandler.bypass('ConsumApplyTriggerHandler');
            ConsumTestDataFactory factory = new ConsumTestDataFactory();
            factory.setupTestData();
            factory.selectDetails();
            Consum_Apply__c ca = [select id,Status__c from Consum_Apply__c limit1];
            ca.Status__c='申请中';
            update ca;
            // ca.Status__c='申请中';
            // update ca;
            // factory.approve();
            // factory.defaultAssign();
            // List<Consum_Apply_Equipment_Set_Detail__c> caesdList = [SELECT Id, Consum_Apply__c,Consum_Apply_Equipment_Set__c 
            //       FROM Consum_Apply_Equipment_Set_Detail__c];
            // ConsumApplyWebService.setRaesShipment_request(caesdList[0].Consum_Apply_Equipment_Set__c);
            // ConsumApplyWebService.all_received_fse(caesdList[0].Consum_Apply__c);
            // ConsumApplyWebService.approvalCheck('d');
            // ConsumApplyWebService.getWD_addday(Date.valueOf('4000-12-31'),1);

            // OlympusCalendar__c oc = new OlympusCalendar__c();
            // oc.Date__c = System.Today();
            // // oc.IsWorkDay__c=1;
            // oc.Before_1_WorkDay__c = oc.Date__c.addDays(-1);
            // insert oc;
            // ConsumApplyWebService.getWD_addday(oc.Date__c,1);
            // ConsumApplyWebService.getWD_addday(oc.Date__c,-1);
            // ConsumApplyWebService c=new ConsumApplyWebService();
            // c.getDateMap(Date.valueOf(oc.Date__c),Date.valueOf(oc.Date__c),0);
            ConsumApplyWebService.ConsumApplyCancel(ca.Id,true);
            ConsumApplyWebService.ConsumApplyCancel(ca.Id,true);
        }
    }
}