@isTest
public with sharing class otherButtonRepairControllerTest {

    @isTest
    static void tesMethod1(){
        // otherButtonRepairController otherButtonRepairController = new otherButtonRepairController();


        // List<Repair__c> repair = [SELECT Id FROM Repair__c  LIMIT 2];
        /* Account hp = new Account();
        hp.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP'].id;
        hp.Name = 'test hp';
        hp.Is_Active__c = '有効';
        hp.Attribute_Type__c = '卫生部';
        hp.Speciality_Type__c = '综合医院';
        hp.Grade__c = '一级';
        hp.OCM_Category__c = 'SLTV';
        hp.Is_Medical__c = '医疗机构';
        hp.Town__c = '东京';
        insert hp;

        Account[] strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hp.Id AND recordType.DeveloperName = 'Department_Class_OTH'];
        Account dpt = new Account();
        dpt.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_OTH'].id;
        dpt.Name = 'test dpt';
        dpt.AgentCode_Ext__c = '112231';
        dpt.ParentId = strategicDep[0].Id;
        dpt.Department_Class__c = strategicDep[0].Id;
        dpt.Hospital__c = hp.Id;
        insert dpt;
        Product2 pro2 = new Product2(Name='name02',IsActive=true,Family='GI',
                Fixture_Model_No__c='n02',Serial_Lot_No__c='Lot tracing',
                ProductCode_Ext__c='pc02',Manual_Entry__c=false);
        insert pro2;
        Asset asset = new Asset(Asset_Owner__c = 'Olympus');
        asset.RecordTypeId = System.Label.Asset_RecordType;
        asset.SerialNumber = 'ass022';
        asset.Name = 'ass022';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = strategicDep[0].Id;
        asset.Hospital__c = hp.Id;
        asset.Product2Id = pro2.Id;
        asset.Quantity = 10;
        asset.Status = '有库存';
        asset.Manage_type__c = '数量管理';
        asset.Loaner_accsessary__c = true;
        asset.Product_category__c = 'GI';
        asset.Delete_Flag__c = false;
        asset.Freeze_sign__c = false;
        asset.Out_of_wh__c = 3;
        asset.Frozen_Quantity__c = 2;
        asset.Salesdepartment__c = '1.华北营业本部';
        asset.Internal_asset_location__c = '北京 备品中心';
        asset.Product_category__c = 'GI';
        asset.Equipment_Type__c = '产品试用';
        asset.SalesProvince__c = '北京';
        asset.WH_location__c = '货架号2';
        asset.AssetManageConfirm__c = true;
        // insert asset;
        insert new Asset[] { asset };
         */
        String rectHp = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        String rectSct = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_GI').getRecordTypeId();
        String rectDpt = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId();

        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];

        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner;
        User hpOwner2 = new User(Test_staff__c = true, LastName = 'hp2', FirstName = 'owner', Alias = 'hp2', Work_Location__c = '重庆', CommunityNickname = 'hpOwner2', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner2@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        insert hpOwner2;
        StaticParameter.MaintenanceContractHpDeptUpdTrigger = true;
        FixtureUtil.SkipTrigger = true;
        // 病院作成
        Account hp = new Account(RecordTypeId = rectHp, Name = 'hp', OwnerId = hpOwner.Id);
        hp.FSE_GI_Main_Leader__c = hpOwner.Id;
        hp.FSE_SP_Main_Leader__c = hpOwner2.Id;
        insert hp;

        Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GI'];
        
        // 診療科を作る
        Account dpt = new Account(RecordTypeId = rectDpt);
        dpt.Name         = '*';
        dpt.Department_Name__c  = 'TestDepart';
        dpt.ParentId            = dc.Id;
        dpt.Department_Class__c = dc.Id;
        dpt.Hospital__c         = hp.Id;
        insert dpt;
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        asset.AccountId = dpt.Id;
        asset.Department_Class__c = dc.Id;
        asset.Hospital__c = hp.Id;
        asset.SerialNumber = 'testserial';
        insert asset;

        Repair__c repair = new Repair__c();
        repair.Account__c = dpt.Id;
        repair.Department_Class__c = dc.Id;
        repair.Hospital__c = hp.Id;
        repair.Delivered_Product__c = asset.Id;
        repair.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays(0);  // 维修合同判断日がサービス契約の中間辺りの日付
        repair.FSE_Work_Location__c = '上海';
        insert repair;
        otherButtonRepairController.init(repair.Id);
        //Final universal code编辑
        String typeId = 'ASACDecision';
        otherButtonRepairController.selectPAEDecisionRecord(repair.Id,typeId);
        otherButtonRepairController.selectPAEDecisionRecord('',typeId);

        otherButtonRepairController.queryForRds(repair.Id);
        //修理报价预估
        otherButtonRepairController.selectAssetID(repair.Id);
        //申请修理
        List<Profile> profile = [SELECT id,name FROM Profile limit 1];
        otherButtonRepairController.initSelectProfile(profile[0].Id);

        List<User> user = [SELECT Id,name FROM User  limit 1];
        otherButtonRepairController.initUserName(user[0].Id);

        // List<Asset> assets = [SELECT Id, Status FROM Asset limit 1];
        otherButtonRepairController.queryForEquipments(asset.Id);

        // List<Account> accounts = [select Id,Is_Validity__c from Account where Is_Validity__c = false limit 1];
        otherButtonRepairController.queryForFindInvalidLicense(hp.Id);

        // List<Repair__c> repair1 = [SELECT Id FROM Repair__c  LIMIT 1];

        List<User> user1 = [SELECT Id,name FROM User  limit 1];
        List<User> users = otherButtonRepairController.queryForReocrds(user1[0].Id);

        // List<Repair__c> repair2 = [SELECT Id,URFLimitSerial__c, FROM Repair__c  LIMIT 1];
        ProductURF__c purf = new ProductURF__c(UFR_MaxRepairCount__c = 2,URFLimitSerial__c = 'URF-P',Maintenance_Price_Year_URF__c = 1200,Maintenance_Price_Year_URF_3__c=110000);
        insert purf;
        // List<ProductURF__c> urfs = [SELECT Id,URFLimitSerial__c FROM ProductURF__c LIMIT 1]; 
        otherButtonRepairController.queryForUrfSeriesInfo(purf.URFLimitSerial__c);

        // List<Repair__c> repair = [SELECT Id,Maintenance_Contract__c FROM Repair__c  LIMIT 1];
        List<String> statusList = new List<String>();
        statusList.add('00.申请完毕');
        statusList.add('01.分公司受理完毕');
        statusList.add('02.RC受理完毕');
        statusList.add('03.报价检查结束');
        statusList.add('04.报价跟进中');
        otherButtonRepairController.queryForRepairCount(repair.Maintenance_Contract__c,statusList,purf.URFLimitSerial__c);
        otherButtonRepairController.CeilingContractRepair(repair.Maintenance_Contract__c);

        Maintenance_Contract__c contract1 = new Maintenance_Contract__c();
        contract1.Name = 'tect contract1';
        contract1.Hospital__c = hp.Id;
        // contract1.Department_Class__c = strategicDep[0].Id;
        contract1.Department__c = dpt.Id;
        contract1.Payment_Plan_Sum_First__c = 1;
        contract1.Status__c = '契約';
        contract1.Maintenance_Contract_No__c = '11123';
         contract1.recordtypeId = 
             Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId();
        contract1.Not_Upper_limit_reason__c = ' 1';
        contract1.Contract_Start_Date__c = Date.today().addDays( -10);   
        contract1.Contract_End_Date__c = Date.today().addDays( 5);       
        contract1.SalesOfficeCode_selection__c = '北京RC';
        insert contract1;

        Maintenance_Contract_Asset__c middleTable = new Maintenance_Contract_Asset__c();
        middleTable.Asset__c = asset.Id;
        middleTable.Maintenance_Contract__c = contract1.id;
        insert middleTable;

        // List<Maintenance_Contract_Asset__c> assets1 = [SELECT Id,Maintenance_Contract__c,URF_Series_F__c,Series_MaxRepairCount_F__c,Series_RepairCount_F__c,Asset__c FROM Maintenance_Contract_Asset__c limit 1];
        otherButtonRepairController.queryForUrfAsset(middleTable.Maintenance_Contract__c,middleTable.Asset__c);

        // List<Account> accounts1 = [SELECT id, FirstParagraph__c,name from Account limit 1]; 
        otherButtonRepairController.queryForrecords3(hp.Id);

        // List<Repair__c> repair = [SELECT Id,DOJ_Status__c,SAP_condition__c FROM Repair__c limit 1 ];
        // otherButtonRepairController.updateForRepair1(repair.Id);
        Boolean DWSign = true;
        String statusc = '1.受理完毕';
        otherButtonRepairController.updateRepair2(repair.Id,users[0],DWSign,statusc,repair.DOJ_Status__c,repair.SAP_condition__c,false);

        otherButtonRepairController.selectRecords(repair.Id);
        otherButtonRepairController.updateRepair(repair.Id,'无需报告');
        // otherButtonRepairController.updateRepair('','无需报告');
        otherButtonRepairController.updateYanshoudan(repair.Id);
        List<String> a = new List<String>();
        List<String> c = new List<String>();
        BatchIF_Log__c iflog = new BatchIF_Log__c();
        iflog.Type__c = 'sendToETQ';
        iflog.ErrorLog__c = '';
        iflog.Log__c = 'NFM401WebService start--';
        a.add(repair.Id);
        c.add('a0J10000008VbEmEAK');
        otherButtonRepairController.sendToETQ('',iflog,a,'R2');
        otherButtonRepairController.sendToETQ('',iflog,c,'R2');
        otherButtonRepairController.initList();
        //删除
        otherButtonRepairController.selectCustomDeleteById(repair.Id);
        otherButtonRepairController.deleteRepair(repair.Id);
    }
}