@isTest
// calloutのtriggerなので、assertがなにもできないです。
// NFM007.trigger、NFM007Controller、Nfm007Sync のカバー率を確認
private class NFM007TriggerTest {
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static testMethod void testInsertTrue() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;

        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'NFM007TestCompany1';
        upsert company1;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = company1.Id
                                                );
        insert linc;
        // 再取得
        //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
        //List<Account> accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

        // insert 時、SAP_Send_OK__c が true
        Product2 product = new Product2( Name='テスト商品');
        product.SFDA_Status__c = '有効';
        product.Intra_Trade_List_RMB_1__c = 100;
        product.Intra_Trade_List_RMB_Date1__c = date.today();
        product.Intra_Trade_Cost_RMB_1__c = 200;
        product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product.Manual_Entry__c = false;
        product.Asset_Model_No__c = '11111';
        product.ProductCode = 'OTV-SP1H-NA-12E';
        product.MDM_Model_No__c = 'test';
        product.CanNotCancelledGurantee__c=true;
        insert product;

        Product_Register__c prc = new Product_Register__c(Name = '国械注进20162220210',
            MedPrdClass__c = '3',
            ValidFrom__c = date.newinstance(2018, 07, 22),
            ValidTo__c = date.newinstance(2028, 07, 22),
            RegisterNoClass_Old__c = '6815',
            RegisterNoClass_New__c = '6815',
            RegisterNoStatus__c = '有效'
            );
        insert prc;

        Product_Register_Link__c prlc = new Product_Register_Link__c(
            Product2__c = product.Id,
            Product_Register__c = prc.Id
            );
        insert prlc;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;

        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = false;
        opp.Gurantee_Period__c = '2';
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.Sales_Root__c       = '販売店';
        // opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.CloseDate           = date.today().addDays(3);
        opp.Agency1__c = company1.Id;
        opp.Authorized_DB_No__c = 'Test20180522';
        opp.Contract_DB_SalesDept_complite_day__c = date.newinstance(2019, 05, 22);
        opp.NotesApprovedNo__c = 'Test20180622';
        opp.Estimation_Id__c    = '';
        opp.multiYearWarranty__c =true;
        insert opp;
        opp = [select id,CloseDate,Close_Forecasted_Date__c from Opportunity where id = :opp.Id];
        System.assertEquals(null, opp.Close_Forecasted_Date__c);
        System.assertEquals(date.today().addDays(3), opp.CloseDate);
        

        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;

        System.Test.startTest();

        //QuoteLineItem qli = new QuoteLineItem();
        //qli.QuoteId = quo.Id;
        //qli.Id__c = '210';
        //qli.SFDA_Status__c = '有効';
        //qli.Name__c = '211';
        //qli.ListPrice__c = 212;
        //qli.Quantity = 213;
        //qli.UnitPrice__c = 215;
        //qli.UnitPrice = 0;
        //qli.Qty_Unit__c = '216';
        //qli.Cost__c = 217;
        //qli.BSS_Category__c = 'ET';
        //qli.Subtotal__c = 218;
        //qli.PricebookEntryId = entry.Id;
        //insert qli;
        opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        update opp;


        //Product2 product = new Product2( Name='テスト商品');
        //product.SFDA_Status__c = '有効';
        //product.Intra_Trade_List_RMB_1__c = 100;
        //product.Intra_Trade_List_RMB_Date1__c = date.today();
        //product.Intra_Trade_Cost_RMB_1__c = 200;
        //product.Intra_Trade_Cost_RMB_Date1__c = date.today();
        //product.Manual_Entry__c = false;
        //product.Asset_Model_No__c = '11111';
        //product.ProductCode = 'OTV-SP1H-NA-12E';

        //insert product;
        

        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        System.Test.stopTest();
        StaticParameter.EscapeOppandStaTrigger = false;
        //Test.startTest();
        // NFM007より、送信しないこと
        //System.assertEquals('', NFM007Controller.debug_msg);
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c = '2';
        //opp.oldData_flg__c = true;
        update opp;  
        //Test.stopTest();
    }

    static testMethod void testInsertTrue_2() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;

        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'NFM007TestCompany1';
        upsert company1;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = company1.Id
                                                );
        insert linc;
        // 再取得
        //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
        //List<Account> accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

        // insert 時、SAP_Send_OK__c が true
        
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c  = '2';
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.Sales_Root__c       = '販売店';
        // opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.CloseDate           = date.today();
        opp.Agency1__c = company1.Id;
        opp.Authorized_DB_No__c = 'Test20180522';
        opp.Contract_DB_SalesDept_complite_day__c = date.newinstance(2019, 05, 22);
        opp.NotesApprovedNo__c = 'Test20180622';
        opp.Estimation_Id__c    = '';
        opp.multiYearWarranty__c =true;
        insert opp;

        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        System.Test.startTest();
        opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        update opp;

        Product2 product3 = new Product2( Name='テスト商品');
        product3.SFDA_Status__c = '有効';
        product3.Intra_Trade_List_RMB_1__c = 100;
        product3.Intra_Trade_List_RMB_Date1__c = date.today();
        product3.Intra_Trade_Cost_RMB_1__c = 200;
        product3.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '11111';
        product3.MDM_Model_No__c = '123';
        product3.ProductCode = 'OTV-SP1H-NA-12E';
        product3.CanNotCancelledGurantee__c=true;
        insert product3;

        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product3.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        //qli.PricebookEntry.Product2Id = product.ID;
        insert qli;

        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        System.Test.stopTest();
        StaticParameter.EscapeOppandStaTrigger = false;
        //Test.startTest();
        // NFM007より、送信しないこと
        //System.assertEquals('', NFM007Controller.debug_msg);
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c = '2';
        opp.oldData_flg__c = true;
        opp.Estimation_Decision__c = true;
        update opp;  
        //Test.stopTest();
    }

      //static testMethod void testUpdateHospital() {
    //    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
    //    if (rectCo.size() == 0) {
    //        return;
    //    }
    //    List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
    //    if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
    //    if (rectDpt.size() == 0) {
    //        return;
    //    }
    //    String userId = UserInfo.getUserId();
    //    User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, SAP_Send_OFF__c FROM User WHERE Id = :userId];
    //    u1.Quote_Correct__c = true;
    //    u1.Quote_Special_Operation__c = true;
    //    u1.SAP_Send_OFF__c = true;
    //    update u1;

    //    // テストデータ
    //    Account company = new Account();
    //    company.RecordTypeId = rectCo[0].Id;
    //    company.Name         = 'NFM007TestCompany';
    //    upsert company;
    //    Account company1 = new Account();
    //    company1.RecordTypeId = rectCo1[0].Id;
    //    company1.Name         = 'NFM007TestCompany1';
    //    upsert company1;
    //    Account section = new Account();
    //    section.RecordTypeId = rectSct[0].Id;
    //    section.Name         = '*';
    //    section.Department_Class_Label__c = '消化科';
    //    section.ParentId                  = company.Id;
    //    section.Hospital_Department_Class__c = company.Id;
    //    upsert section;
    //    Account depart = new Account();
    //    depart.RecordTypeId = rectDpt[0].Id;
    //    depart.Name         = '*';
    //    depart.Department_Name__c  = 'NFM007TestDepart';
    //    depart.ParentId            = section.Id;
    //    depart.Department_Class__c = section.Id;
    //    depart.Hospital__c         = company.Id;
    //    upsert depart;
    //    //医疗器械经营许可证
    //    License_Information__c linc = new License_Information__c( name='Test20181204',
    //                                            LicenseType__c = '医疗器械经营许可证',
    //                                            BusinessLicense__c = '20180522',
    //                                            ValidFrom__c = date.newinstance(2018, 05, 22),
    //                                            ValidTo__c = date.newinstance(2088, 05, 22),
    //                                            Scope3__c = '6815;6822;6823;6825',
    //                                            LicenseAndAccount__c = company1.Id
    //                                            );
    //    insert linc;
    //    // 再取得
    //    //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
    //    //List<Account> accList = [select Management_Code__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

    //    // insert 時、SAP_Send_OK__c が false、updateする
    //    Opportunity opp = new Opportunity();
    //    opp.AccountId           = depart.Id;
    //    opp.Department_Class__c = section.Id;
    //    opp.Hospital__c         = company.Id;
    //    opp.SAP_Send_OK__c      = false;
    //    opp.Name                = 'GZ-SP-NFM007_2';
    //    opp.Trade__c            = '内貿';
    //    opp.StageName           = '引合';
    //    opp.Sales_Root__c       = 'OCM直接販売';
    //    opp.CloseDate           = date.newinstance(2022, 11, 30);
    //    opp.Agency1__c = company1.Id;
    //    Test.startTest();
    //    insert opp;
    //    System.assertEquals('', NFM007Controller.debug_msg);
    //    // 見積りを追加
    //    opp.Estimation_Decision__c = true;
    //    opp.Whether_FALSE_order__c = true;
    //    opp.Estimation_Id__c    = 'Estimation_Id';
    //    opp.Purchase_Type__c    = '一般引合';
    //    opp.Promise_Class__c    = '内貿';
    //    opp.Fund_Basis__c       = '政府資金';
    //    opp.SAP_Province__c     = '北京市';
    //    //Test.startTest();
    //    update opp;
    //    //opp.Agency1__c = company1.Id;
    //    opp.SAP_Send_OK__c      = true;
    //    update opp;
    //    System.assertEquals('NFM007_callout_insert2', NFM007Controller.debug_msg);
        
    //    NFM007Controller.isRunning = false;
    //    opp.SAP_Send_OK__c      = false;
    //    update opp;
    //    Test.stopTest();
    //    opp.SAP_Send_OK__c      = true;
    //    update opp;
    //    System.assertEquals('NFM007_callout_update', NFM007Controller.debug_msg);
    //}

    //static testMethod void testUpdateAgency() {
    //    ControllerUtil.EscapeNFM001Trigger = true;
    //    StaticParameter.EscapeNFM007Trigger = true;
    //    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
    //    if (rectCo.size() == 0) {
    //        return;
    //    }
    //    List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'AgencyContract'];
    //    if (rectDpt.size() == 0) {
    //        return;
    //    }
    //    String userId = UserInfo.getUserId();
    //    User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, SAP_Send_OFF__c FROM User WHERE Id = :userId];
    //    u1.Quote_Correct__c = true;
    //    u1.Quote_Special_Operation__c = true;
    //    u1.SAP_Send_OFF__c = true;
    //    update u1;

    //    // テストデータ
    //    Account company = new Account();
    //    company.RecordTypeId = rectCo[0].Id;
    //    company.Name         = 'NFM007TestCompany';
    //    upsert company;
    //    Account depart = new Account();
    //    depart.RecordTypeId = rectDpt[0].Id;
    //    depart.Contract_Decide_Start_Date__c = System.today();
    //    depart.Contract_Decide_End_Date__c = System.today();
    //    depart.Name         = '*';
    //    depart.Department_Name__c  = 'NFM007TestDepart';
    //    depart.ParentId            = company.Id;
    //    depart.Agent_Ref__c        = company.Id;
    //    depart.ET_SP_Dealer__c = true;
    //    upsert depart;
    //    //医疗器械经营许可证
    //    License_Information__c linc = new License_Information__c( name='Test20181204',
    //                                            LicenseType__c = '医疗器械经营许可证',
    //                                            BusinessLicense__c = '20180522',
    //                                            ValidFrom__c = date.newinstance(2018, 05, 22),
    //                                            ValidTo__c = date.newinstance(2088, 05, 22),
    //                                            Scope3__c = '6815;6822;6823;6825',
    //                                            LicenseAndAccount__c = company.Id
    //                                            );
    //    insert linc;
    //    // 再取得
    //    List<Id> accountIds = new Id[] {company.Id, depart.Id};
    //    List<Account> accList = [select Management_Code__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

    //    // insert 時、SAP_Send_OK__c が false、updateする
    //    Opportunity opp = new Opportunity();
    //    opp.AccountId           = depart.Id;
    //    opp.Hospital__c         = depart.Id;
    //    opp.SAP_Send_OK__c      = false;
    //    opp.Name                = 'GZ-SP-NFM007_3';
    //    opp.Trade__c            = '内貿';
    //    opp.StageName           = '引合';
    //    opp.Sales_Root__c       = 'OCM直接販売';
    //    opp.CloseDate           = date.newinstance(2022, 11, 30);
    //    opp.ET_SP_Consumption__c = true;
    //    opp.Agency1__c = company.Id;
    //    opp.Contract_DB_SalesDept_complite_day__c = Date.today();
    //    opp.NotesApprovedNo__c = 'note';
    //    insert opp;
    //    Quote q = new Quote(
    //        Name = 'quote',
    //        OpportunityId = opp.Id
    //    );
    //    insert q;
    //    System.assertEquals('', NFM007Controller.debug_msg);
    //    // 見積りを追加
    //    opp.Estimation_Decision__c = true;
    //    opp.Estimation_Id__c    = q.Id;//'Estimation_Id';
    //    opp.Purchase_Type__c    = '一般引合';
    //    opp.Promise_Class__c    = '内貿';
    //    opp.Fund_Basis__c       = '政府資金';
    //    opp.SAP_Province__c     = '北京市';
    //    Test.startTest();
    //    update opp;
    //    opp.SAP_Send_OK__c      = true;

    //    update opp;
    //    //System.assertEquals('NFM007_callout_insert2', NFM007Controller.debug_msg);
    //    Test.stopTest();
    //}

    //static testMethod void resend_test() {
    //    ControllerUtil.EscapeNFM001Trigger = true;
    //    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
    //    if (rectCo.size() == 0) {
    //        return;
    //    }
    //    List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'AgencyContract'];
    //    if (rectDpt.size() == 0) {
    //        return;
    //    }
        
    //    String userId = UserInfo.getUserId();
    //    User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, SAP_Send_OFF__c FROM User WHERE Id = :userId];
    //    u1.Quote_Correct__c = true;
    //    u1.Quote_Special_Operation__c = true;
    //    u1.SAP_Send_OFF__c = true;
    //    update u1;

    //    // テストデータ
    //    Account company = new Account();
    //    company.RecordTypeId = rectCo[0].Id;
    //    company.Name         = 'NFM007TestCompany';
    //    upsert company;

    //    //Account company1 = new Account();
    //    //company1.RecordTypeId = rectCo[0].Id;
    //    //company1.Name         = 'NFM007TestCompany';
    //    //upsert company1;

    //    Account depart = new Account();
    //    depart.RecordTypeId = rectDpt[0].Id;
    //    depart.Contract_Decide_Start_Date__c = System.today();
    //    depart.Contract_Decide_End_Date__c = System.today();
    //    depart.Name         = '*';
    //    depart.Department_Name__c  = 'NFM007TestDepart';
    //    depart.ParentId            = company.Id;
    //    depart.Agent_Ref__c        = company.Id;
    //    depart.ET_SP_Dealer__c = true;
    //    upsert depart;
    //    //医疗器械经营许可证
    //    License_Information__c linc = new License_Information__c( name='Test20181204',
    //                                            LicenseType__c = '医疗器械经营许可证',
    //                                            BusinessLicense__c = '20180522',
    //                                            ValidFrom__c = date.newinstance(2018, 05, 22),
    //                                            ValidTo__c = date.newinstance(2088, 05, 22),
    //                                            Scope3__c = '6815;6822;6823;6825',
    //                                            LicenseAndAccount__c = company.Id
    //                                            );
    //    insert linc;
    //    // 再取得
    //    List<Id> accountIds = new Id[] {company.Id, depart.Id};
    //    List<Account> accList = [select Management_Code__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

    //    // insert 時、SAP_Send_OK__c が false、updateする
    //    Opportunity opp = new Opportunity();
    //    opp.AccountId           = depart.Id;
    //    opp.Hospital__c         = depart.Id;
    //    opp.SAP_Send_OK__c      = false;
    //    opp.Name                = 'GZ-SP-NFM007_3';
    //    opp.Trade__c            = '内貿';
    //    opp.StageName           = '引合';
    //    opp.Sales_Root__c       = 'OCM直接販売';
    //    opp.CloseDate           = date.newinstance(2022, 11, 30);
    //    opp.Agency1__c = company.Id;
    //    opp.Contract_DB_SalesDept_complite_day__c = Date.today();
    //    opp.NotesApprovedNo__c = 'note';
    //    insert opp;
    //    System.assertEquals('', NFM007Controller.debug_msg);
    //    // 見積りを追加
    //    opp.Estimation_Decision__c = true;
    //    opp.Estimation_Id__c    = 'Estimation_Id';
    //    opp.Purchase_Type__c    = '一般引合';
    //    opp.Promise_Class__c    = '内貿';
    //    opp.Fund_Basis__c       = '政府資金';
    //    opp.SAP_Province__c     = '北京市';

    //    Test.startTest();
    //    update opp;

    //    opp.SAP_Send_OK__c      = true;
        
    //    update opp;
    //    Test.stopTest();
    //    System.assertEquals('NFM007_callout_insert2', NFM007Controller.debug_msg);

    //    // retry_cnt__c がクリアされること
    //    List<BatchIF_Log__c> rowbl = [Select Id,
    //                                        Log__c,
    //                                        Log2__c,
    //                                        ErrorLog__c,
    //                                        retry_cnt__c
    //                                        from BatchIF_Log__c
    //                                        where RowDataFlg__c = true
    //                                        and Type__c = 'NFM007'
    //                                        order by CreatedDate desc];
    //    //System.assertEquals(1, rowbl.size());
    //    //System.assertEquals(1, rowbl[0].retry_cnt__c);

    //    //NFM007Controller.execute(rowbl[0],null);
    //    //List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
    //    //        Type__c, Log__c, ErrorLog__c,retry_cnt__c
    //    //        from BatchIF_Log__c
    //    //        where Id = :rowbl[0].id];
    //    //System.assertEquals(2, bl[0].retry_cnt__c);

    //    //NFM007Controller.execute(rowbl[0],null);
    //    //bl = [Select Id, Is_Error__c,
    //    //        Type__c, Log__c, ErrorLog__c,retry_cnt__c
    //    //        from BatchIF_Log__c
    //    //        where Id = :rowbl[0].id];
    //    //System.assertEquals(3, bl[0].retry_cnt__c);

    //    //System.assertEquals(true, bl[0].ErrorLog__c.indexof('错误次数已经超过自动送信设定的最大次数') >= 0, 'Except:错误次数已经超过自动送信设定的最大次数');

    //    // TODO System.assertEquals(0, bl[0].retry_cnt__c);     Mock
    //}
    
    //static testMethod void resend_test_2() {
    //    ControllerUtil.EscapeNFM001Trigger = true;
    //    List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
    //    if (rectCo.size() == 0) {
    //        return;
    //    }
    //    List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'AgencyContract'];
    //    if (rectDpt.size() == 0) {
    //        return;
    //    }
        
    //    String userId = UserInfo.getUserId();
    //    User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, SAP_Send_OFF__c FROM User WHERE Id = :userId];
    //    u1.Quote_Correct__c = true;
    //    u1.Quote_Special_Operation__c = true;
    //    u1.SAP_Send_OFF__c = true;
    //    update u1;

    //    // テストデータ
    //    Account company = new Account();
    //    company.RecordTypeId = rectCo[0].Id;
    //    company.Name         = 'NFM007TestCompany';
    //    upsert company;

    //    //Account company1 = new Account();
    //    //company1.RecordTypeId = rectCo[0].Id;
    //    //company1.Name         = 'NFM007TestCompany';
    //    //upsert company1;

    //    Account depart = new Account();
    //    depart.RecordTypeId = rectDpt[0].Id;
    //    depart.Contract_Decide_Start_Date__c = System.today();
    //    depart.Contract_Decide_End_Date__c = System.today();
    //    depart.Name         = '*';
    //    depart.Department_Name__c  = 'NFM007TestDepart';
    //    depart.ParentId            = company.Id;
    //    depart.Agent_Ref__c        = company.Id;
    //    depart.ET_SP_Dealer__c = true;
    //    upsert depart;
    //    //医疗器械经营许可证
    //    License_Information__c linc = new License_Information__c( name='Test20181204',
    //                                            LicenseType__c = '医疗器械经营许可证',
    //                                            BusinessLicense__c = '20180522',
    //                                            ValidFrom__c = date.newinstance(2018, 05, 22),
    //                                            ValidTo__c = date.newinstance(2088, 05, 22),
    //                                            Scope3__c = '6815;6822;6823;6825',
    //                                            LicenseAndAccount__c = company.Id
    //                                            );
    //    insert linc;
    //    // 再取得
    //    List<Id> accountIds = new Id[] {company.Id, depart.Id};
    //    List<Account> accList = [select Management_Code__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

    //    // insert 時、SAP_Send_OK__c が false、updateする
    //    Opportunity opp = new Opportunity();
    //    opp.AccountId           = depart.Id;
    //    opp.SAP_Send_OK_Date__c = Date.today();
    //    opp.Hospital__c         = depart.Id;
    //    opp.SAP_Send_OK__c      = false;
    //    opp.Name                = 'GZ-SP-NFM007_3';
    //    opp.Trade__c            = '内貿';
    //    opp.StageName           = '引合';
    //    opp.Sales_Root__c       = 'OCM直接販売';
    //    opp.CloseDate           = date.newinstance(2022, 11, 30);
    //    opp.Agency1__c = company.Id;
    //    opp.Contract_DB_SalesDept_complite_day__c = Date.today();
    //    opp.NotesApprovedNo__c = 'note';
    //    insert opp;
    //    System.assertEquals('', NFM007Controller.debug_msg);
    //    // 見積りを追加
    //    opp.Estimation_Decision__c = true;
    //    opp.Estimation_Id__c    = 'Estimation_Id';
    //    opp.Purchase_Type__c    = '一般引合';
    //    opp.Promise_Class__c    = '内貿';
    //    opp.Fund_Basis__c       = '政府資金';
    //    opp.SAP_Province__c     = '北京市';
    //    Test.startTest();
    //    update opp;

    //    opp.SAP_Send_OK__c      = true;
        
    //    update opp;
    //    Test.stopTest();
    //    //System.assertEquals('NFM007_callout_insert2', NFM007Controller.debug_msg);

    //    // retry_cnt__c がクリアされること
    //    List<BatchIF_Log__c> rowbl = [Select Id,
    //                                        Log__c,
    //                                        Log2__c,
    //                                        ErrorLog__c,
    //                                        retry_cnt__c
    //                                        from BatchIF_Log__c
    //                                        where RowDataFlg__c = true
    //                                        and Type__c = 'NFM007'
    //                                        order by CreatedDate desc];
    //    System.assertEquals(1, rowbl.size());
    //    System.assertEquals(1, rowbl[0].retry_cnt__c);

    //    //NFM007Controller.execute(rowbl[0],null);
    //    //List<BatchIF_Log__c> bl = [Select Id, Is_Error__c,
    //    //        Type__c, Log__c, ErrorLog__c,retry_cnt__c
    //    //        from BatchIF_Log__c
    //    //        where Id = :rowbl[0].id];
    //    //System.assertEquals(2, bl[0].retry_cnt__c);

    //    //NFM007Controller.execute(rowbl[0],null);
    //    //bl = [Select Id, Is_Error__c,
    //    //        Type__c, Log__c, ErrorLog__c,retry_cnt__c
    //    //        from BatchIF_Log__c
    //    //        where Id = :rowbl[0].id];
    //    //System.assertEquals(3, bl[0].retry_cnt__c);

    //    //System.assertEquals(true, bl[0].ErrorLog__c.indexof('错误次数已经超过自动送信设定的最大次数') >= 0, 'Except:错误次数已经超过自动送信设定的最大次数');

    //    // TODO System.assertEquals(0, bl[0].retry_cnt__c);     Mock
    //}


    //修改
     //static testMethod void testUpdateHospital1() {
     //   List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
     //   if (rectCo.size() == 0) {
     //       return;
     //   }
     //   List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
     //   if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
     //   if (rectDpt.size() == 0) {
     //       return;
     //   }
     //   String userId = UserInfo.getUserId();
     //   User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, SAP_Send_OFF__c FROM User WHERE Id = :userId];
     //   u1.Quote_Correct__c = true;
     //   u1.Quote_Special_Operation__c = true;
     //   u1.SAP_Send_OFF__c = true;
     //   update u1;

     //   // テストデータ
     //   Account company = new Account();
     //   company.RecordTypeId = rectCo[0].Id;
     //   company.Name         = 'NFM007TestCompany';
     //   upsert company;
     //   Account company1 = new Account();
     //   company1.RecordTypeId = rectCo1[0].Id;
     //   company1.Name         = 'NFM007TestCompany1';
     //   upsert company1;
     //   Account section = new Account();
     //   section.RecordTypeId = rectSct[0].Id;
     //   section.Name         = '*';
     //   section.Department_Class_Label__c = '消化科';
     //   section.ParentId                  = company.Id;
     //   section.Hospital_Department_Class__c = company.Id;
     //   upsert section;
     //   Account depart = new Account();
     //   depart.RecordTypeId = rectDpt[0].Id;
     //   depart.Name         = '*';
     //   depart.Department_Name__c  = 'NFM007TestDepart';
     //   depart.ParentId            = section.Id;
     //   depart.Department_Class__c = section.Id;
     //   depart.Hospital__c         = company.Id;
     //   upsert depart;
     //   //医疗器械经营许可证
     //   License_Information__c linc = new License_Information__c( name='Test20181204',
     //                                           LicenseType__c = '医疗器械经营许可证',
     //                                           BusinessLicense__c = '20180522',
     //                                           ValidFrom__c = date.newinstance(2018, 05, 22),
     //                                           ValidTo__c = date.newinstance(2088, 05, 22),
     //                                           Scope3__c = '6815;6822;6823;6825',
     //                                           LicenseAndAccount__c = company1.Id
     //                                           );
     //   insert linc;
     //   // 再取得
     //   //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
     //   //List<Account> accList = [select Management_Code__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

     //   // insert 時、SAP_Send_OK__c が false、updateする
     //   Opportunity opp = new Opportunity();
     //   opp.AccountId           = depart.Id;
     //   opp.Department_Class__c = section.Id;
     //   opp.Hospital__c         = company.Id;
     //   opp.SAP_Send_OK__c      = false;
     //   opp.Name                = 'GZ-SP-NFM007_2';
     //   opp.Trade__c            = '内貿';
     //   opp.StageName           = '引合';
     //   opp.Sales_Root__c       = 'OCM直接販売';
     //   opp.CloseDate           = date.newinstance(2022, 11, 30);
     //   opp.Agency1__c = company1.Id;
     //   //Test.startTest();
     //   insert opp;
     //   //insert opp;
     //   System.assertEquals('', NFM007Controller.debug_msg);
     //   // 見積りを追加
     //   opp.Estimation_Decision__c = true;
     //   opp.Whether_FALSE_order__c = true;
     //   opp.Estimation_Id__c    = 'Estimation_Id';
     //   opp.Purchase_Type__c    = '一般引合';
     //   opp.Promise_Class__c    = '内貿';
     //   opp.Fund_Basis__c       = '政府資金';
     //   opp.SAP_Province__c     = '北京市';
     //   //Test.startTest();
     //   update opp;
     //   //opp.Agency1__c = company1.Id;
     //   opp.SAP_Send_OK__c      = true;
     //   Test.startTest();
     //   update opp;
     //   //System.assertEquals('NFM007_callout_insert2', NFM007Controller.debug_msg);
        
     //   NFM007Controller.isRunning = false;
     //   opp.SAP_Send_OK__c      = false;
     //   update opp;
     //   Test.stopTest();
     //   opp.SAP_Send_OK__c      = true;
     //   update opp;
     //   System.assertEquals('NFM007_callout_update', NFM007Controller.debug_msg);
     //}
     static testMethod void testInsertTrue_3() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;

        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'NFM007TestCompany1';
        upsert company1;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = company1.Id
                                                );
        insert linc;
        // 再取得
        //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
        //List<Account> accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

        // insert 時、SAP_Send_OK__c が true
        
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c  = '2';
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.Sales_Root__c       = '販売店';
        // opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.CloseDate           = date.today();
        opp.Agency1__c = company1.Id;
        opp.Authorized_DB_No__c = 'Test20180522';
        opp.Contract_DB_SalesDept_complite_day__c = date.newinstance(2019, 05, 22);
        opp.NotesApprovedNo__c = 'Test20180622';
        opp.Estimation_Id__c    = '';
        opp.multiYearWarranty__c =true;
        insert opp;

        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        System.Test.startTest();
        opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        update opp;

        Product2 product3 = new Product2( Name='テスト商品');
        product3.SFDA_Status__c = '有効';
        product3.Intra_Trade_List_RMB_1__c = 100;
        product3.Intra_Trade_List_RMB_Date1__c = date.today();
        product3.Intra_Trade_Cost_RMB_1__c = 200;
        product3.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '11111';
        product3.MDM_Model_No__c = '123';
        product3.ProductCode = 'OTV-SP1H-NA-12E';
        product3.CanNotCancelledGurantee__c=true;
        insert product3;

        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product3.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;

        List<RecordType> rectPH = [select Id from RecordType where IsActive = true and SobjectType = 'PromotionHead__c' and Name = '促销方案'];
        if (rectPH.size() == 0) {
            return;
        }
        

        PromotionHead__c ph = new PromotionHead__c();
        ph.SpoId__c = 'SPOXX';
        ph.name = 'SPOXX';
        //写死促销方案id
        ph.recordTypeId = rectPH[0].Id;
        insert ph;

        PromotionSales__c ps =new PromotionSales__c();
        ps.PromotionHead__c = ph.id;
        ps.Category__c = '促销政策';
        ps.name ='xxx';

        insert ps;


        PromotionSalesProducts__c psp = new PromotionSalesProducts__c();
        psp.QuantityId__c = quo.ID;
        // psp.PromotionSales__r.PromotionHead__r.SpoId__c
        // psp.PromotionSales__r.Category__c
        psp.PromotionSales__c = ps.id;
        psp.Asset_Model_No__c = '';
        psp.Quantity__c = 2;
        psp.AgencyUnitPrice__c =12.0;
        psp.UseCount__c =2;

        insert psp;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.ID;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        //qli.PricebookEntry.Product2Id = product.ID;
        insert qli;
        
        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        System.Test.stopTest();
        StaticParameter.EscapeOppandStaTrigger = false;
        //Test.startTest();
        // NFM007より、送信しないこと
        //System.assertEquals('', NFM007Controller.debug_msg);
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c = '2';
        opp.oldData_flg__c = true;
        opp.Estimation_Decision__c = true;
        // opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        // update opp;
        update opp;  
        //Test.stopTest();
    }
    
    static testMethod void testInsertTrue_4() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;

        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'NFM007TestCompany1';
        upsert company1;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = company1.Id
                                                );
        insert linc;
        // 再取得
        //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
        //List<Account> accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

        // insert 時、SAP_Send_OK__c が true
        
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c  = '2';
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '内貿';
        opp.StageName           = '引合';
        opp.Sales_Root__c       = '販売店';
        // opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.CloseDate           = date.today();
        opp.Authorized_DB_No__c = 'Test20180522';
        opp.Contract_DB_SalesDept_complite_day__c = date.newinstance(2019, 05, 22);
        opp.NotesApprovedNo__c = 'Test20180622';
        opp.Estimation_Id__c    = '';
        opp.multiYearWarranty__c =true;
        insert opp;

        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        System.Test.startTest();
        opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        update opp;
        opp.DecideQuoteDate__c = null;
        update opp;
        
        //opp = [select id,DecideQuoteDate__c from Opportunity where id = :opp.id];
        //system.assertEquals(date.newinstance(2020, 11, 30), opp.DecideQuoteDate__c);

        Product2 product3 = new Product2( Name='テスト商品');
        product3.SFDA_Status__c = '有効';
        product3.Intra_Trade_List_RMB_1__c = 100;
        product3.Intra_Trade_List_RMB_Date1__c = date.today();
        product3.Intra_Trade_Cost_RMB_1__c = 200;
        product3.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '11111';
        product3.MDM_Model_No__c = '123';
        product3.ProductCode = 'OTV-SP1H-NA-12E';
        product3.CanNotCancelledGurantee__c=true;

        insert product3;

        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product3.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        //qli.PricebookEntry.Product2Id = product.ID;
        insert qli;

        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        
        System.Test.stopTest();
        StaticParameter.EscapeOppandStaTrigger = false;
        //Test.startTest();
        // NFM007より、送信しないこと
        //System.assertEquals('', NFM007Controller.debug_msg);
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c = '2';
        opp.oldData_flg__c = true;
        opp.Estimation_Decision__c = true;
        update opp;  
        //Test.stopTest();
    }
    
    static testMethod void testInsertTrue_5() {
        ControllerUtil.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001AgencyContractTrigger2 = true;
        StaticParameter.EscapeOppandStaTrigger = true;
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectCo1 = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency'];
        if (rectCo1.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 from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }

        // テストデータ
        Account company = new Account();
        company.RecordTypeId = rectCo[0].Id;
        company.Name         = 'NFM007TestCompany';
        upsert company;

        Account company1 = new Account();
        company1.RecordTypeId = rectCo1[0].Id;
        company1.Name         = 'NFM007TestCompany1';
        upsert company1;
        Account section = new Account();
        section.RecordTypeId = rectSct[0].Id;
        section.Name         = '*';
        section.Department_Class_Label__c = '消化科';
        section.ParentId                  = company.Id;
        section.Hospital_Department_Class__c = company.Id;
        upsert section;
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = 'NFM007TestDepart';
        depart.ParentId            = section.Id;
        depart.Department_Class__c = section.Id;
        depart.Hospital__c         = company.Id;
        upsert depart;
        //医疗器械经营许可证
        License_Information__c linc = new License_Information__c( name='Test20181204',
                                                LicenseType__c = '医疗器械经营许可证',
                                                BusinessLicense__c = '20180522',
                                                ValidFrom__c = date.newinstance(2018, 05, 22),
                                                ValidTo__c = date.newinstance(2088, 05, 22),
                                                Scope3__c = '6815;6822;6823;6825',
                                                LicenseAndAccount__c = company1.Id
                                                );
        insert linc;
        // 再取得
        //List<Id> accountIds = new Id[] {company.Id, section.Id, depart.Id};
        //List<Account> accList = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id in :accountIds order by Management_Code__c];

        // insert 時、SAP_Send_OK__c が true
        
        Opportunity opp = new Opportunity();
        opp.AccountId           = depart.Id;
        opp.Department_Class__c = section.Id;
        opp.Hospital__c         = company.Id;
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c  = '2';
        opp.Name                = 'GZ-SP-NFM007_1';
        opp.Trade__c            = '外貿';
        opp.StageName           = '引合';
        opp.Sales_Root__c       = '販売店';
        // opp.CloseDate           = date.newinstance(2022, 11, 30);
        opp.CloseDate           = date.today();
        opp.Agency1__c = company1.Id;
        opp.Authorized_DB_No__c = 'Test20180522';
        opp.Contract_DB_SalesDept_complite_day__c = date.newinstance(2019, 05, 22);
        opp.NotesApprovedNo__c = 'Test20180622';
        opp.Estimation_Id__c    = '';
        opp.multiYearWarranty__c =true;
        opp.CurrencyIsoCode = 'USD';
        insert opp;

        Quote quo = new Quote();
        quo.Name = '206';
        quo.OpportunityId = opp.Id;
        quo.Quote_No__c = '205';
        quo.Estimation_List_Price__c = 200;
        quo.Dealer_Final_Price__c = 202;
        quo.Stocking_Price__c = 204;
        quo.OCM_Sales_Forecast__c = 201;
        quo.OCM_Agent1_Price__c = 203;
        quo.Pricebook2Id = pricebookId;
        insert quo;
        System.Test.startTest();
        opp.Estimation_Decision__c = true;
        opp.Estimation_Id__c    = quo.ID;
        update opp;
        opp.DecideQuoteDate__c = date.newinstance(2020, 11, 30);
        update opp;
        
        //opp = [select id,DecideQuoteDate__c from Opportunity where id = :opp.id];
        //system.assertEquals(date.newinstance(2020, 11, 30), opp.DecideQuoteDate__c);

        Product2 product3 = new Product2( Name='テスト商品');
        product3.SFDA_Status__c = '有効';
        product3.Intra_Trade_List_RMB_1__c = 100;
        product3.Intra_Trade_List_RMB_Date1__c = date.today();
        product3.Intra_Trade_Cost_RMB_1__c = 200;
        product3.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product3.Manual_Entry__c = false;
        product3.Asset_Model_No__c = '11111';
        product3.MDM_Model_No__c = '123';
        product3.ProductCode = 'OTV-SP1H-NA-12E';
        product3.CanNotCancelledGurantee__c=true;

        insert product3;

        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product3.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'USD';
        insert entry;
        
        QuoteLineItem qli = new QuoteLineItem();
        qli.QuoteId = quo.Id;
        qli.Id__c = '210';
        qli.SFDA_Status__c = '有効';
        qli.Name__c = '211';
        qli.ListPrice__c = 212;
        qli.Quantity = 213;
        qli.UnitPrice__c = 215;
        qli.UnitPrice = 0;
        qli.Qty_Unit__c = '216';
        qli.Cost__c = 217;
        qli.BSS_Category__c = 'ET';
        qli.Subtotal__c = 218;
        qli.PricebookEntryId = entry.Id;
        //qli.PricebookEntry.Product2Id = product.ID;
        insert qli;

        OpportunityLineItem oppli = new OpportunityLineItem();
        oppli.OpportunityId = opp.Id;
        oppli.Id__c = '110';
        oppli.SFDA_Status__c = '有効';
        oppli.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        oppli.ListPrice__c = 112;
        oppli.Quantity = 113;
        oppli.UnitPrice = 114;
        oppli.UnitPrice__c = 115;
        oppli.Qty_Unit__c = '116';
        oppli.Cost__c = 117;
        oppli.BSS_Category__c = 'G&R';
        oppli.Item_Order__c = 1;
        oppli.PricebookEntryId = entry.Id;
        insert oppli;
        
        System.Test.stopTest();
        //Test.startTest();
        // NFM007より、送信しないこと
        //System.assertEquals('', NFM007Controller.debug_msg);
        StaticParameter.EscapeOppandStaTrigger = false;
        opp.SAP_Send_OK__c      = true;
        opp.Gurantee_Period__c = '2';
        opp.oldData_flg__c = true;
        opp.Estimation_Decision__c = true;
        update opp;  
        //Test.stopTest();
    }

    static testMethod void test_00() {
        NFM007Controller controller = new NFM007Controller();
        controller.test();
    }
}