@isTest
private class SI_NewQuoteEntryControllerTest {

    private static Product2 product = null;
    private static Pricebook2 pricebook = null;


    private static  Opportunity opprtunity = null;

    static final String RC_HOSPITAL = '病院';
    static final String RC_OPP = '引合';
    static final String RC_SENRYAKUKASHITSUBUNRUI = '戦略科室分類 消化科';
    static final String RC_BYOUIN = '病院';
    static final String RC_SHINRYOUKA = '診療科 その他';
    static final String RC_HANBAOITEN = '販売店';
    static final String RC_KEIYAKU = '契約';

    static {
        product = new Product2( Name = 'テスト商品');
        insert product;
        system.debug('##product.Id=[' + product.Id + ']' );

        pricebook = ControllerUtil.getStandardPricebook();
        system.debug('##pricebook.Id=[' + pricebook.Id + ']' );
    }

    private static PricebookEntry buildPB( String input) {
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product.Id);

        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = input;
        insert entry;
        return entry;
    }

    private static Opportunity buildOppInstance( String inputTrade, String CurrencyIsoCode) {
        Opportunity target = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today());
        target.Trade__c = inputTrade;
        target.owner_not_automatically_update__c = true;
        target.CurrencyIsoCode = CurrencyIsoCode;
        target.Wholesale_Price__c = 9000;
        return target;
    }

    private static QuoteLineItem insertQuoteLineItem( Quote input, Pricebookentry entry) {
        QuoteLineItem target = new QuoteLineItem();
        target.QuoteId = input.Id;
        target.Quantity = 1;
        target.Cost_Subtotal__c = 0;
        target.Cost__c = 200;
        //        target.TotalPrice = 100;
        target.UnitPrice = 10;
        target.PricebookEntryId = entry.Id;
        insert target;
        return target;
    }


    private static String quoteNo = 'textQutote01';
    public static String trade = '内貿';
    public static String CurrencyIso = 'CNY';

    private static Boolean isUnitPrice = true;
    private static Boolean isOfferAmount = true;
    private static Boolean isTotalPrice = true;
    private static Boolean isDiscountRate = true;
    private static Boolean isDiscountAmount = true;
    private static Boolean isTradingPrice = true;
    private static Boolean isContractDetail = true;

    private static Date offerExpireDate = Date.today();
    private static String clientName = 'test client';
    private static String offerComment = 'test comment';
    private static Date offerPrintDate = Date.today();
    private static String agentName = 'test agent name';

    static testMethod void TestInit01() {
        system.debug('---------------------------------------Start initTest-----');
        SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
        //Line 119 UserのQuote_Correct__c、Quote_Special_Operation__c、SAP_Send_OFF__cをテストため。
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = false;
        u1.Quote_Special_Operation__c = true;
        u1.Cost_Referable__c = true;
        update u1;

        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');

        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.owner_not_automatically_update__c = true;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;

        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);
        SI_NewQuoteEntryController.QELine sqline_Win = new SI_NewQuoteEntryController.QELine(item01, 0, 'Win');
        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
        System.Test.startTest();
        test1( opp, quote , QuotePage);
        test2( opp, quote , QuotePage);
        test3( opp, quote , QuotePage);
        test4( opp, quote , QuotePage);
        System.Test.stopTest();
        //        test5( opp, quote , QuotePage);
        //        test6( opp, quote , QuotePage);
        //        test7( opp, quote , QuotePage);




        system.debug('---------------------------------------End initTest-----');
    }

    static testMethod void testInit02() {
        system.debug('---------------------------------------Start initTest-----');
        SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
        //Line 119 UserのQuote_Correct__c、Quote_Special_Operation__c、SAP_Send_OFF__cをテストため。
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = true;
        u1.Quote_Special_Operation__c = false;
        u1.Cost_Referable__c = true;
        update u1;

        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');
        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.owner_not_automatically_update__c = true;
        opp.Trade__c = trade;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;

        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);

        System.Test.startTest();
        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
        //        test1( opp, quote , QuotePage);
        //        test2( opp, quote , QuotePage);
        //        test3( opp, quote , QuotePage);
        //        test4( opp, quote , QuotePage);
                test5( opp, quote , QuotePage);
                //test6( opp, quote , QuotePage);
                //test7( opp, quote , QuotePage);
        System.Test.stopTest();



        system.debug('---------------------------------------End initTest-----');
    }

    static testMethod void testInit02_01() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
            //Line 119 UserのQuote_Correct__c、Quote_Special_Operation__c、SAP_Send_OFF__cをテストため。
            String userId = UserInfo.getUserId();
            User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
            u1.Quote_Correct__c = true;
            u1.Quote_Special_Operation__c = false;
            u1.Cost_Referable__c = true;
            update u1;

            // PricebookEntry
            PricebookEntry entryUSD = buildPB( 'USD');
            PricebookEntry entryCNY = buildPB( 'CNY');
            // 引合作成
            Opportunity opp = buildOppInstance( trade, CurrencyIso);
            opp.owner_not_automatically_update__c = true;
            opp.Trade__c = trade;
            opp.Sales_Root__c = 'AAA';
            opp.Pricebook2Id = pricebook.id;
            insert opp;

            //見積データ作成
            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;

            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            quote.Cancel_Decide__c = false;
            insert quote;
            quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
            System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

            // 見積品目作成
            QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
            QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);

            System.Test.startTest();
            //見積データ検索
            opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
            //test5( opp, quote , QuotePage);
            test6( opp, quote , QuotePage);
            //test7( opp, quote , QuotePage);
            System.Test.stopTest();
        }
    }

    static testMethod void testInit02_02() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
            //Line 119 UserのQuote_Correct__c、Quote_Special_Operation__c、SAP_Send_OFF__cをテストため。
            String userId = UserInfo.getUserId();
            User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
            u1.Quote_Correct__c = true;
            u1.Quote_Special_Operation__c = false;
            u1.Cost_Referable__c = true;
            update u1;

            // PricebookEntry
            PricebookEntry entryUSD = buildPB( 'USD');
            PricebookEntry entryCNY = buildPB( 'CNY');
            // 引合作成
            Opportunity opp = buildOppInstance( trade, CurrencyIso);
            opp.owner_not_automatically_update__c = true;
            opp.Trade__c = trade;
            opp.Sales_Root__c = 'AAA';
            opp.Pricebook2Id = pricebook.id;
            insert opp;

            //見積データ作成
            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;

            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            insert quote;
            quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
            System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

            // 見積品目作成
            QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
            QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);

            System.Test.startTest();
            //見積データ検索
            opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
            //test5( opp, quote , QuotePage);
            //test6( opp, quote , QuotePage);
            test7( opp, quote , QuotePage);
            System.Test.stopTest();
        }
    }

    static testMethod void TestInit03() {
        system.debug('---------------------------------------Start initTest-----');
        SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = true;
        u1.Quote_Special_Operation__c = true;
        u1.Cost_Referable__c = false;
        update u1;

        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');
        CurrencyIso = 'USD';
        trade = '外貿';
        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.owner_not_automatically_update__c = true;
        opp.Trade__c = trade;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;

        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryUSD);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryUSD);

        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
        System.Test.startTest();
        test1( opp, quote , QuotePage);
        test2( opp, quote , QuotePage);
        test3( opp, quote , QuotePage);
        test4( opp, quote , QuotePage);
        //        test5( opp, quote , QuotePage);
        //        test6( opp, quote , QuotePage);
        //        test7( opp, quote , QuotePage);
        System.Test.stopTest();




        system.debug('---------------------------------------End initTest-----');
    }

    static testMethod void testInit04() {
        system.debug('---------------------------------------Start initTest-----');
        SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
        String userId = UserInfo.getUserId();
        User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
        u1.Quote_Correct__c = true;
        u1.Quote_Special_Operation__c = false;
        u1.Cost_Referable__c = true;
        update u1;

        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');
        CurrencyIso = 'USD';
        trade = '外貿';
        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.owner_not_automatically_update__c = true;
        opp.Trade__c = trade;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;

        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

        // 見積品目作成
        QuoteLineItem item01 = insertQuoteLineItem( quote, entryUSD);
        QuoteLineItem item02 = insertQuoteLineItem( quote, entryUSD);

        System.Test.startTest();
        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];

        //System.Test.startTest();
        //        test1( opp, quote , QuotePage);
        //        test2( opp, quote , QuotePage);
        //        test3( opp, quote , QuotePage);
        //        test4( opp, quote , QuotePage);
        test5( opp, quote , QuotePage);
        //System.Test.stopTest();

        //test6( opp, quote , QuotePage);
        //test7( opp, quote , QuotePage);
        System.Test.stopTest();


        system.debug('---------------------------------------End initTest-----');
    }

    static testMethod void testInit04_01() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
            String userId = UserInfo.getUserId();
            User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
            u1.Quote_Correct__c = true;
            u1.Quote_Special_Operation__c = false;
            u1.Cost_Referable__c = true;
            update u1;

            // PricebookEntry
            PricebookEntry entryUSD = buildPB( 'USD');
            PricebookEntry entryCNY = buildPB( 'CNY');
            CurrencyIso = 'USD';
            trade = '外貿';
            // 引合作成
            Opportunity opp = buildOppInstance( trade, CurrencyIso);
            opp.owner_not_automatically_update__c = true;
            opp.Trade__c = trade;
            opp.Sales_Root__c = 'AAA';
            opp.Pricebook2Id = pricebook.id;
            insert opp;

            //見積データ作成
            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;

            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            insert quote;
            quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
            System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

            // 見積品目作成
            QuoteLineItem item01 = insertQuoteLineItem( quote, entryUSD);
            QuoteLineItem item02 = insertQuoteLineItem( quote, entryUSD);

            System.Test.startTest();
            //見積データ検索
            opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
            //test5( opp, quote , QuotePage);
            //System.Test.stopTest();
            test6( opp, quote , QuotePage);
            //test7( opp, quote , QuotePage);
            System.Test.stopTest();
        }
    }

    static testMethod void testInit04_02() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
            String userId = UserInfo.getUserId();
            User u1 = [SELECT Id, Quote_Correct__c, Quote_Special_Operation__c, Cost_Referable__c FROM User WHERE Id = :userId];
            u1.Quote_Correct__c = true;
            u1.Quote_Special_Operation__c = false;
            u1.Cost_Referable__c = true;
            update u1;

            // PricebookEntry
            PricebookEntry entryUSD = buildPB( 'USD');
            PricebookEntry entryCNY = buildPB( 'CNY');
            CurrencyIso = 'USD';
            trade = '外貿';
            // 引合作成
            Opportunity opp = buildOppInstance( trade, CurrencyIso);
            opp.owner_not_automatically_update__c = true;
            opp.Trade__c = trade;
            opp.Sales_Root__c = 'AAA';
            opp.Pricebook2Id = pricebook.id;
            insert opp;

            //見積データ作成
            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;

            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            insert quote;
            quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
            System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

            // 見積品目作成
            QuoteLineItem item01 = insertQuoteLineItem( quote, entryUSD);
            QuoteLineItem item02 = insertQuoteLineItem( quote, entryUSD);

            System.Test.startTest();
            //見積データ検索
            opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
            //test5( opp, quote , QuotePage);
            //System.Test.stopTest();
            //test6( opp, quote , QuotePage);
            test7( opp, quote , QuotePage);
            System.Test.stopTest();
        }
    }

    static testMethod void TestInit05() {
        system.debug('---------------------------------------Start initTest-----');
        SI_NewQuoteEntryController QuotePage = new SI_NewQuoteEntryController();
        //Line 119 UserのQuote_Correct__c、Quote_Special_Operation__c、SAP_Send_OFF__cをテストため。
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User hpOwner = new User(Test_staff__c = true, Job_Category__c = '销售服务' , LastName = 'hp', FirstName = 'owner', Alias = 'hp', 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;
        String userId = hpOwner.id;
        // PricebookEntry
        PricebookEntry entryUSD = buildPB( 'USD');
        PricebookEntry entryCNY = buildPB( 'CNY');

        // 引合作成
        Opportunity opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.owner_not_automatically_update__c = true;
        opp.Sales_Root__c = 'AAA';
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //見積データ作成
        Quote quote = new Quote( Name = 'テスト見積');
        quote.OpportunityId = opp.Id;
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;

        quote.Unit_Price__c = isUnitPrice;
        quote.Offer_Amount__c = isOfferAmount;
        quote.TOTAL__c = isTotalPrice;
        quote.Discount__c = isDiscountRate;
        quote.Pricing__c = isDiscountAmount;
        quote.Preferential_Trading_Price__c = isTradingPrice;
        quote.Contract__c = isContractDetail;
        quote.Quote_Comment__c = offerComment;
        insert quote;
        quote = [SELECT Id, OpportunityId, Quote_no__c, Quote_No_Auto__c, CurrencyIsoCode FROM Quote WHERE Id = :quote.id];
        System.assertEquals( CurrencyIso, quote.CurrencyIsoCode);

        // 見積品目作成
        //        QuoteLineItem item01 = insertQuoteLineItem( quote, entryCNY);
        //        QuoteLineItem item02 = insertQuoteLineItem( quote, entryCNY);

        //見積データ検索
        opprtunity = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
        System.Test.startTest();
        //        test1( opp, quote , QuotePage);
        //        test2( opp, quote , QuotePage);
        //        test3( opp, quote , QuotePage);
        //        test5( opp, quote , QuotePage);
        //        test6( opp, quote , QuotePage);
        //        test7( opp, quote , QuotePage);
        test8( opp, quote , QuotePage);
        System.Test.stopTest();



        system.debug('---------------------------------------End initTest-----');
    }
    private  static void test1( Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);
        QuotePage.oppId = opp.id;
        QuotePage.quoId = quote.id;
        QuotePage.init();
        boolean hiddenSaveBtn = QuotePage.getHiddenSaveBtn();
        QuotePage.rowIdx = 1;
        QuotePage.addRow();
        QuotePage.DownloadCsv();
        QuotePage.QuoteConfirm();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }

    private  static void test2( Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        system.debug('---------------------------------------Start initTest2-----');
        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry?oppId=' + opprtunity.id );
        System.Test.setCurrentPage(page);

        QuotePage.oppId = opp.id;
        QuotePage.quoId = quote.id;
        QuotePage.init();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }

    private  static void test3( Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);

        QuotePage.oppId = opp.id;
        QuotePage.init();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }

    private static void test4(Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.Pricebook2Id = pricebook.id;
        insert opp;

        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);

        QuotePage.oppId = opp.id;
        QuotePage.init();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }

    private static void test5(Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {

        //販売店
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Delete_Flag__c = false;
        insert sellerA;

        //契約
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
        Account keiyaku = new Account(Name = '*');
        keiyaku.RecordTypeId = recKeiyaku.id;
        keiyaku.Agent_Ref__c = sellerA.id;
        keiyaku.ParentId = sellerA.id;
        keiyaku.Delete_Flag__c = false;
        keiyaku.Special__c = true;
        insert keiyaku;

        opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.Pricebook2Id = pricebook.id;
        opp.AccountId = keiyaku.id;
        opp.Hospital__c = keiyaku.id;
        opp.SAP_Send_OK__c = true;
        insert opp;


        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);

        //Apexpages.currentPage().getParameters().put('id', quote.id);
        QuotePage.oppId = opp.id;
        QuotePage.init();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }

    private static void test6(Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        insert sellerA;

        //契約
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
        Account keiyaku = new Account(Name = '*');
        keiyaku.RecordTypeId = recKeiyaku.id;
        keiyaku.Agent_Ref__c = sellerA.id;
        keiyaku.ParentId = sellerA.id;
        keiyaku.Delete_Flag__c = false;
        insert keiyaku;


        opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.Pricebook2Id = pricebook.id;
        opp.AccountId = keiyaku.id;
        opp.Hospital__c = keiyaku.id;
        opp.is_CheckTarget_TF__c = true;
        insert opp;


        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);

        Apexpages.currentPage().getParameters().put('id', quote.id);
        QuotePage.oppId = null;
        QuotePage.init();
        QuotePage.Save();
        QuotePage.DownloadCsv();
        QuotePage.QuoteConfirm();
        User u = new User(id = UserInfo.getUserId());
        u.SI_Stock_Checker__c = null;
        update u;
        QuotePage.submitOppoApplyStock();
        u.Province__c = '四川省';
        update u;
        QuotePage.submitOppoApplyStock();
        u.Province__c = '海南省';
        update u;
        opp.is_CheckTarget_TF__c = true;
        update opp;
        QuotePage.submitOppoApplyStock();
        QuotePage.Back();
        //##ページデバッグセクション　終了
    }

    private static void test7(Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeAccountTrigger = true;
        ControllerUtil.EscapeNFM001Trigger = true;
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeSyncProduct2Trigger = true;
        Oly_TriggerHandler.bypass('PowerBIBaseHandler');

        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        insert sellerA;

        //契約
        RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
        Account keiyaku = new Account(Name = '*');
        keiyaku.RecordTypeId = recKeiyaku.id;
        keiyaku.Agent_Ref__c = sellerA.id;
        keiyaku.ParentId = sellerA.id;
        keiyaku.Delete_Flag__c = false;
        insert keiyaku;


        opp = buildOppInstance( trade, CurrencyIso);
        opp.Trade__c = trade;
        opp.Sales_Root__c = '販売店';
        opp.StageName = '引合';
        opp.Fixed_Check__c = false;
        opp.Pricebook2Id = pricebook.id;
        opp.AccountId = keiyaku.id;
        opp.Hospital__c = keiyaku.id;
        insert opp;

        delete quote;

        Product2 product1 = new Product2( Name = 'テスト商品');
        insert product1;
        system.debug('##product.Id=[' + product1.Id + ']' );

        PricebookEntry pE = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product1.Id);

        pE.UnitPrice = 0;
        pE.IsActive = true;
        pE.UseStandardPrice = false;
        pE.CurrencyIsoCode = CurrencyIso;
        //pE.
        insert pE;

        OpportunityLineItem oli = new OpportunityLineItem();
        //target.QuoteId = input.Id;
        oli.Quantity = 1;
        //    target.TotalPrice = 100;
        oli.UnitPrice = 0;
        oli.PricebookEntryId = pE.Id;
        oli.OpportunityId = opp.id;
        //oli.op
        insert oli;

        //##ページデバッグセクション　開始
        PageReference page = new PageReference('/apex/NewQuoteEntry');
        System.Test.setCurrentPage(page);

        Apexpages.currentPage().getParameters().put('oppid', opp.id);
        //Apexpages.currentPage().getParameters().put('id', quote.id);
        QuotePage.oppId = null;
        QuotePage.quoId = null;
        QuotePage.init();
        QuotePage.Save();
        //##ページデバッグセクション　終了
    }
    // OpportunityLineItem=0件のテスト
    private static void test8(Opportunity opp, Quote quote , SI_NewQuoteEntryController QuotePage) {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
            Account hospital = new Account(Name = 'テスト病院');
            hospital.RecordTypeId = recByoin.id;
            hospital.Site = 'テスト病院部門';
            hospital.Alias_Name2__c = 'テスト病院別名';
            //        insert hospital;

            RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
            Account sellerA = new Account(Name = '販売店');
            sellerA.RecordTypeId = recHanbaiten.id;
            //        sellerA.Hospital__c = hospital.id;
            insert sellerA;

            //契約
            RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
            Account keiyaku = new Account(Name = '*');
            keiyaku.RecordTypeId = recKeiyaku.id;
            keiyaku.Agent_Ref__c = sellerA.id;
            keiyaku.ParentId = sellerA.id;
            keiyaku.Site = 'テスト病院部門';
            keiyaku.Delete_Flag__c = false;
            insert keiyaku;


            opp = buildOppInstance( trade, CurrencyIso);
            opp.Trade__c = trade;
            opp.Sales_Root__c = '販売店';
            opp.StageName = '引合';
            opp.Fixed_Check__c = false;
            opp.Pricebook2Id = pricebook.id;
            opp.AccountId = keiyaku.id;
            opp.Hospital__c = keiyaku.id;
            insert opp;

            //        delete quote;

            Product2 product1 = new Product2( Name = 'テスト商品');
            insert product1;
            system.debug('##product.Id=[' + product1.Id + ']' );

            PricebookEntry pE = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product1.Id);

            pE.UnitPrice = 0;
            pE.IsActive = true;
            pE.UseStandardPrice = false;
            pE.CurrencyIsoCode = CurrencyIso;
            //pE.
            insert pE;

            //##ページデバッグセクション　開始
            PageReference page = new PageReference('/apex/NewQuoteEntry');
            System.Test.setCurrentPage(page);

            Apexpages.currentPage().getParameters().put('oppid', opp.id);
            //Apexpages.currentPage().getParameters().put('id', quote.id);
            QuotePage.oppId = null;
            QuotePage.quoId = null;
            QuotePage.init();
            QuotePage.Save();
            //##ページデバッグセクション　終了
            //
        }
    }
    private static testMethod void check_QuoteEntryController001() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            StaticParameter.EscapeNFM001AgencyContractTrigger = true;
            StaticParameter.EscapeAccountTrigger = true;
            ControllerUtil.EscapeNFM001Trigger = true;
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');
            StaticParameter.EscapeSyncOpportunityTrigger = true;
            StaticParameter.EscapeNFM007Trigger = true;
            StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
            Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
            StaticParameter.EscapeSyncOpportunityTrigger = true;
            StaticParameter.EscapeSyncProduct2Trigger = true;
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');

            RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
            Account hospital = new Account(Name = 'テスト病院');
            hospital.RecordTypeId = recByoin.id;
            hospital.Site = 'テスト病院部門';
            hospital.Alias_Name2__c = 'テスト病院別名';
            insert hospital;

            RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
            Account sellerA = new Account(Name = '販売店');
            sellerA.RecordTypeId = recHanbaiten.id;
            sellerA.Hospital__c = hospital.id;
            insert sellerA;

            RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
            Account contractA = new Account(Name = '*');
            contractA.RecordTypeId = recKeiyaku.id;
            contractA.Agent_Ref__c = sellerA.id;
            contractA.ParentId = sellerA.id;
            insert contractA;


            Opportunity opp = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today());
            opp.Trade__c = '内貿';
            opp.CurrencyIsoCode = CurrencyIso;
            opp.Sales_Root__c = '販売店';
            opp.StageName = '引合';
            opp.owner_not_automatically_update__c = true;
            opp.Fixed_Check__c = false;
            opp.Pricebook2Id = pricebook.id;
            opp.Purchase_Type__c = '一般引合';
            opp.Promise_Class__c = '内貿';
            opp.Fund_Basis__c = '政府資金';
            opp.AccountId = contractA.id;
            opp.Hospital__c = contractA.id;
            opp.Agency1__c = sellerA.id;
            opp.Agency2__c = sellerA.id;
            opp.Wholesale_Price__c = 9000;
            opp.Stock_Confrim_Date__c = Date.today();
            insert opp;

            Product2 product1 = new Product2( Name = '11111');
            product1.SFDA_Status__c = '不要';
            product1.Intra_Trade_List_RMB_1__c = 100;
            product1.Intra_Trade_List_RMB_Date1__c = date.today();
            product1.Intra_Trade_Cost_RMB_1__c = 200;
            product1.Intra_Trade_Cost_RMB_Date1__c = date.today();
            product1.Manual_Entry__c = false;
            product1.Asset_Model_No__c = '11111';
            product1.ProductCode = 'OTV-SP1H-NA-12E';
            insert product1;
            system.debug('##product.Id=[' + product1.Id + ']' );

            Product2 product2 = new Product2( Name = '11112');
            product2.SFDA_Status__c = '不要';
            product2.Intra_Trade_List_RMB_1__c = 100;
            product2.Intra_Trade_List_RMB_Date1__c = date.today();
            product2.Intra_Trade_Cost_RMB_1__c = 200;
            product2.Intra_Trade_Cost_RMB_Date1__c = date.today();
            product2.Manual_Entry__c = false;
            product2.Asset_Model_No__c = '11112';
            //        product2.ProductCode = 'OTV-SP1H-NA-12E';
            insert product2;
            system.debug('##product1.Id=[' + product1.Id + ']' );
            system.debug('##product2.Id=[' + product2.Id + ']' );

            PricebookEntry pE = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product1.Id);

            pE.UnitPrice = 0;
            pE.IsActive = true;
            pE.UseStandardPrice = false;
            pE.CurrencyIsoCode = CurrencyIso;
            //pE.
            insert pE;

            PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);

            pE2.UnitPrice = 0;
            pE2.IsActive = true;
            pE2.UseStandardPrice = false;
            pE2.CurrencyIsoCode = CurrencyIso;
            //pE.
            insert pE2;

            OpportunityLineItem oli = new OpportunityLineItem();
            //target.QuoteId = input.Id;
            oli.Quantity = 1;
            //    target.TotalPrice = 100;
            oli.UnitPrice = 10;
            oli.PricebookEntryId = pE.Id;
            oli.OpportunityId = opp.id;
            oli.Cost__c = 100;
            //oli.op
            insert oli;

            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;
            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            quote.QuoteName__c = 'テスト見積';
            quote.Dealer_Final_Price__c = 100;
            quote.Quote_Adjust_Calculate__c = 10;
            quote.Quote_Adjust_Amount__c = 10;
            quote.OCM_Agent1_Price__c = 10;
            quote.Agent1_Agent2_Price__c = 10;

            insert quote;

            // セット品
            Product_Set__c ps1 = new Product_Set__c();
            ps1.Name = 'セット品１';
            ps1.Product_Set_CD__c = '111111';
            ps1.Description__c = '説明';
            ps1.Qty__c = 10;
            //ps1.Valid__c = true;
            ps1.Valid_Date__c = date.today().addDays(-5);
            insert ps1;

            Product_Set_Detail__c psd1 = new Product_Set_Detail__c();
            psd1.Product_Set__c = ps1.id;
            psd1.Price__c = 100;
            psd1.Quantity__c = 10;
            psd1.Product__c = product1.id;

            insert psd1;

            IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
            ISOhead.name = '*';
            ISOhead.Opportunity_ID__c = opp.id;
            ISOhead.Approval_Date__c = Date.today();
            ISOhead.Public_Hospital_TF__c = true;
            ISOhead.Preparation_Stage_TF__c = true;
            ISOhead.Data_Check_TF__c = true;
            ISOhead.Operating_Room_Plane_Graph_TF__c = true;
            ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
            insert ISOhead;

            System.Test.startTest();
            //##ページデバッグセクション　開始
            PageReference page = new PageReference('/apex/NewQuoteEntry');
            System.Test.setCurrentPage(page);

            Apexpages.currentPage().getParameters().put('oppid', opp.id);
            SI_NewQuoteEntryController controller = new SI_NewQuoteEntryController();
            //Apexpages.currentPage().getParameters().put('id', quote.id);
            controller.testI();
            controller.oppId = null;
            controller.quoId = null;
            controller.enableSales = false;
            controller.init();
            controller.dataCheck();
            controller.select_index = 0;
            controller.Product_text = product1.id;
            controller.setProduct_text = ps1.id;
            controller.setProductEntry();
            //        controller.settingProduct2();
            controller.OppReflection();
            controller.PriceStatusUpdate();
            controller.SalesId1 = sellerA.id;
            controller.SalesId2 = sellerA.id;
            controller.getSalesId1();
            controller.getSalesId2();
            controller.cancel();

            Quote quoteAfterInsert = [SELECT OpportunityId, Pricebook2Id, Name, Quote_No__c, Unit_Price__c, Offer_Amount__c, TOTAL__c,
                                      Discount__c, Pricing__c, Preferential_Trading_Price__c, Contract__c, Quote_Comment__c,
                                      QuoteName__c, Dealer_Final_Price__c, Quote_Adjust_Calculate__c, Quote_Adjust_Amount__c,
                                      OCM_Agent1_Price__c, Agent1_Agent2_Price__c
                                      FROM Quote WHERE Id = :quote.id];
            system.assertEquals( quote.OCM_Agent1_Price__c, quoteAfterInsert.OCM_Agent1_Price__c);

            controller.enableSales = false;
            controller.opp.Agency1__c = null;
            controller.quo.OCM_Agent1_Price__c = null;
            controller.quo.OCM_Agent1_Price_Page__c = null;
            controller.opp.Agency2__c = null;
            controller.quo.Agent1_Agent2_Price__c = null;
            controller.quo.QuoteName__c = 'aaa';
            controller.quo.Dealer_Final_Price__c = 100;
            controller.quo.Quote_Adjust_Calculate__c = 100;
            controller.quo.Quote_Adjust_Amount__c = 10;
            controller.quo.Quote_Expiration_Date__c = date.today();
            controller.oppId = opp.id;
            //        controller.PricebookId = pricebook.id;
            SI_NewQuoteEntryController.QELine act = new SI_NewQuoteEntryController.QELine(oli, 0);

            act.Asset_Model = '11111';

            act.pageObject.Quantity__c = 10;
            act.pageObject.UnitPrice = 100;
            act.pageObject.Subtotal__c = 1000;
            act.pageObject.PricebookEntryId = pE2.id;
            List<SI_NewQuoteEntryController.QELine> actList = new List<SI_NewQuoteEntryController.QELine>();
            actList.add(act);
            controller.activities = actList;
            controller.dataEntry();
            controller.dataCheck();
            controller.enableSales = true;
            controller.QuoteDecision();
            controller.enableSales = false;
            act.Asset_Model = null;
            controller.quo.QuoteName__c = 'aaa';
            controller.quo.Dealer_Final_Price_Page__c = 100;
            controller.qb.Quote_Adjust_Calculate = 100;
            controller.quo.Quote_Adjust_Amount_Page__c = 10;
            controller.QuoteDecision();
            controller.Print();

            actList = new List<SI_NewQuoteEntryController.QELine>();
            actList.add(act);
            controller.activities = actList;
            controller.excel_text = 'OTV-SP1H-NA-12E\t1';
            controller.excelImport();
            Add_Report.getProduct2(product2.id);

            //   QELine(QELine tmp, Integer i) 関数をテスト
            actList = new List<SI_NewQuoteEntryController.QELine>();
            act.Asset_Model = null;
            actList.add(act);
            controller.activities = actList;
            controller.excel_text = 'OTV-SP1H-NA-12E\t1';
            controller.excelImport();
            Add_Report.getProduct2(product2.id);

            //  dataCheckDecide関数をチェック
            controller.enableSales = true;
            controller.QuoteDecision = false;
            controller.QuoteDecision();
            controller.Print();
            //##ページデバッグセクション　終了
            System.Test.stopTest();
        }

    }

    static testMethod void dataEntryTest() {
        Profile p = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        User MacOwner = new User(Test_staff__c = true, Batch_User__c  = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id);
        system.runAs(MacOwner) {
            StaticParameter.EscapeNFM001AgencyContractTrigger = true;
            StaticParameter.EscapeAccountTrigger = true;
            ControllerUtil.EscapeNFM001Trigger = true;
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');
            StaticParameter.EscapeSyncOpportunityTrigger = true;
            StaticParameter.EscapeNFM007Trigger = true;
            StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
            Oly_TriggerHandler.bypass('AgencyOppUpdHandler');
            StaticParameter.EscapeSyncOpportunityTrigger = true;
            StaticParameter.EscapeSyncProduct2Trigger = true;
            Oly_TriggerHandler.bypass('PowerBIBaseHandler');

            RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
            Account hospital = new Account(Name = 'テスト病院');
            hospital.RecordTypeId = recByoin.id;
            hospital.Site = 'テスト病院部門';
            hospital.Alias_Name2__c = 'テスト病院別名';
            insert hospital;

            RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
            Account sellerA = new Account(Name = '販売店');
            sellerA.RecordTypeId = recHanbaiten.id;
            sellerA.Hospital__c = hospital.id;
            insert sellerA;

            RecordType recKeiyaku = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_KEIYAKU limit 1];
            Account contractA = new Account(Name = '*');
            contractA.RecordTypeId = recKeiyaku.id;
            contractA.Agent_Ref__c = sellerA.id;
            contractA.ParentId = sellerA.id;
            insert contractA;


            Opportunity opp = new Opportunity( Name = 'aiueo', StageName = 'contact', CloseDate = Date.today());
            opp.Trade__c = '内貿';
            opp.CurrencyIsoCode = CurrencyIso;
            opp.Sales_Root__c = '販売店';
            opp.StageName = '引合';
            opp.Fixed_Check__c = false;
            opp.owner_not_automatically_update__c = true;
            opp.Pricebook2Id = pricebook.id;
            opp.Purchase_Type__c = '一般引合';
            opp.Promise_Class__c = '内貿';
            opp.Fund_Basis__c = '政府資金';
            opp.AccountId = contractA.id;
            opp.Hospital__c = contractA.id;
            opp.Agency1__c = sellerA.id;
            opp.Agency2__c = sellerA.id;
            opp.Wholesale_Price__c = 9000;
            opp.Stock_Confrim_Date__c = Date.today();
            insert opp;

            Product2 product1 = new Product2( Name = '11111');
            product1.SFDA_Status__c = '不要';
            product1.Intra_Trade_List_RMB_1__c = 100;
            product1.Intra_Trade_List_RMB_Date1__c = date.today();
            product1.Intra_Trade_Cost_RMB_1__c = 200;
            product1.Intra_Trade_Cost_RMB_Date1__c = date.today();
            product1.Manual_Entry__c = false;
            product1.Asset_Model_No__c = '11111';
            product1.ProductCode = 'OTV-SP1H-NA-12E';
            insert product1;
            system.debug('##product.Id=[' + product1.Id + ']' );

            Product2 product2 = new Product2( Name = '11112');
            product2.SFDA_Status__c = '不要';
            product2.Intra_Trade_List_RMB_1__c = 100;
            product2.Intra_Trade_List_RMB_Date1__c = date.today();
            product2.Intra_Trade_Cost_RMB_1__c = 200;
            product2.Intra_Trade_Cost_RMB_Date1__c = date.today();
            product2.Manual_Entry__c = false;
            product2.Asset_Model_No__c = '11112';
            //        product2.ProductCode = 'OTV-SP1H-NA-12E';
            insert product2;
            system.debug('##product1.Id=[' + product1.Id + ']' );
            system.debug('##product2.Id=[' + product2.Id + ']' );

            PricebookEntry pE = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product1.Id);

            pE.UnitPrice = 0;
            pE.IsActive = true;
            pE.UseStandardPrice = false;
            pE.CurrencyIsoCode = CurrencyIso;
            //pE.
            insert pE;

            PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);

            pE2.UnitPrice = 0;
            pE2.IsActive = true;
            pE2.UseStandardPrice = false;
            pE2.CurrencyIsoCode = CurrencyIso;
            //pE.
            insert pE2;

            OpportunityLineItem oli = new OpportunityLineItem();
            //target.QuoteId = input.Id;
            oli.Quantity = 1;
            //    target.TotalPrice = 100;
            oli.UnitPrice = 10;
            oli.PricebookEntryId = pE.Id;
            oli.OpportunityId = opp.id;
            oli.Cost__c = 100;
            //oli.op
            insert oli;

            Quote quote = new Quote( Name = 'テスト見積');
            quote.OpportunityId = opp.Id;
            quote.Pricebook2Id = pricebook.id;
            quote.Quote_No__c = quoteNo;
            quote.Unit_Price__c = isUnitPrice;
            quote.Offer_Amount__c = isOfferAmount;
            quote.TOTAL__c = isTotalPrice;
            quote.Discount__c = isDiscountRate;
            quote.Pricing__c = isDiscountAmount;
            quote.Preferential_Trading_Price__c = isTradingPrice;
            quote.Contract__c = isContractDetail;
            quote.Quote_Comment__c = offerComment;
            quote.QuoteName__c = 'テスト見積';
            quote.Dealer_Final_Price__c = 100;
            quote.Quote_Adjust_Calculate__c = 10;
            quote.Quote_Adjust_Amount__c = 10;
            quote.OCM_Agent1_Price__c = 10;
            quote.Agent1_Agent2_Price__c = 10;

            insert quote;

            // セット品
            Product_Set__c ps1 = new Product_Set__c();
            ps1.Name = 'セット品１';
            ps1.Product_Set_CD__c = '111111';
            ps1.Description__c = '説明';
            ps1.Qty__c = 10;
            //ps1.Valid__c = true;
            ps1.Valid_Date__c = date.today().addDays(-5);
            insert ps1;

            Product_Set_Detail__c psd1 = new Product_Set_Detail__c();
            psd1.Product_Set__c = ps1.id;
            psd1.Price__c = 100;
            psd1.Quantity__c = 10;
            psd1.Product__c = product1.id;

            insert psd1;

            System.Test.startTest();
            // 20211013 lt add 注释掉
            //SI_NewQuoteEntryController.QELine sqline = new SI_NewQuoteEntryController.QELine(2, true ,'String VenderName','String ProductSetName', pE.id, 'String Asset_Model', 'String StorageStatus', ' String ProductCode', 'String Id_c', 'String SFDA_Status_c', 'String Sales_Possibility_c', 'String Name_c', 'String BSS_Category_c', 2, 123, 21, 312, 123, 1.1, 1.1, '', 1.1,0);

            //##ページデバッグセクション　開始
            PageReference page = new PageReference('/apex/NewQuoteEntry');
            System.Test.setCurrentPage(page);

            Apexpages.currentPage().getParameters().put('oppid', opp.id);
            SI_NewQuoteEntryController controller = new SI_NewQuoteEntryController();
            //Apexpages.currentPage().getParameters().put('id', quote.id);
            controller.oppId = null;
            controller.quoId = null;
            controller.enableSales = false;
            controller.init();
            controller.dataCheck();
            controller.select_index = 0;
            controller.Product_text = product1.id;
            controller.setProduct_text = ps1.id;
            controller.setProductEntry();
            //        controller.settingProduct2();
            controller.OppReflection();
            controller.activities[0].Asset_Model = 'test';
            controller.PriceStatusUpdate();
            controller.SalesId1 = sellerA.id;
            controller.SalesId2 = sellerA.id;
            controller.getSalesId1();
            controller.getSalesId2();
            controller.cancel();

            Quote quoteAfterInsert = [SELECT OpportunityId, Pricebook2Id, Name, Quote_No__c, Unit_Price__c, Offer_Amount__c, TOTAL__c,
                                      Discount__c, Pricing__c, Preferential_Trading_Price__c, Contract__c, Quote_Comment__c,
                                      QuoteName__c, Dealer_Final_Price__c, Quote_Adjust_Calculate__c, Quote_Adjust_Amount__c,
                                      OCM_Agent1_Price__c, Agent1_Agent2_Price__c
                                      FROM Quote WHERE Id = :quote.id];
            system.assertEquals( quote.OCM_Agent1_Price__c, quoteAfterInsert.OCM_Agent1_Price__c);

            controller.enableSales = false;
            controller.opp.Agency1__c = null;
            controller.quo.OCM_Agent1_Price__c = null;
            controller.opp.Agency2__c = null;
            controller.quo.Agent1_Agent2_Price__c = null;
            controller.quo.QuoteName__c = 'aaa';
            controller.quo.Dealer_Final_Price_Page__c = 100;
            controller.quo.Dealer_Final_Price__c = 100;
            controller.qb.Quote_Adjust_Calculate = 100;
            controller.quo.Quote_Adjust_Calculate__c = 100;
            controller.quo.Quote_Adjust_Amount_Page__c = 10;
            controller.quo.Quote_Adjust_Amount__c = 10;
            controller.quo.Quote_Expiration_Date__c = date.today();
            controller.oppId = opp.id;
            //        controller.PricebookId = pricebook.id;
            SI_NewQuoteEntryController.QELine act = new SI_NewQuoteEntryController.QELine(oli, 0);

            act.Asset_Model = '11111';

            act.pageObject.Quantity__c = 10;
            act.pageObject.UnitPrice_Page__c = 100;
            act.pageObject.UnitPrice = 100;
            act.pageObject.Subtotal__c = 1000;
            act.pageObject.PricebookEntryId = pE2.id;
            act.pageObject.Id__c = product2.id;
            List<SI_NewQuoteEntryController.QELine> actList = new List<SI_NewQuoteEntryController.QELine>();
            actList.add(act);
            controller.activities = actList;
            controller.save();
            controller.dataEntry();
            controller.dataCheck();
            controller.QuoteDecision();
            controller.Print();

            actList = new List<SI_NewQuoteEntryController.QELine>();
            actList.add(act);
            controller.activities = actList;
            controller.excel_text = 'OTV-SP1H-NA-12E\t1';
            controller.excelImport();
            Add_Report.getProduct2(product2.id);

            //   QELine(QELine tmp, Integer i) 関数をテスト
            actList = new List<SI_NewQuoteEntryController.QELine>();
            act.Asset_Model = null;
            actList.add(act);
            controller.activities = actList;
            controller.excel_text = 'OTV-SP1H-NA-12E\t1';
            controller.excelImport();
            Add_Report.getProduct2(product2.id);

            //  dataCheckDecide関数をチェック
            controller.enableSales = true;

            IS_Opportunity_Demand__c ISOhead = new IS_Opportunity_Demand__c();
            ISOhead.name = '*';
            ISOhead.Opportunity_ID__c = opp.id;
            ISOhead.Approval_Date__c = Date.today();
            ISOhead.Public_Hospital_TF__c = true;
            ISOhead.Preparation_Stage_TF__c = true;
            ISOhead.Data_Check_TF__c = true;
            ISOhead.Operating_Room_Plane_Graph_TF__c = true;
            ISOhead.Demonstration_Area_Plane_Graph_TF__c = true;
            insert ISOhead;

            controller.QuoteDecision = false;
            controller.QuoteDecision();
            controller.Print();
            //##ページデバッグセクション　終了

            System.Test.stopTest();
        }
    }
    static testMethod void dataEntryTest2() {
        RecordType recByoin = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_BYOUIN limit 1];
        Account hospital = new Account(Name = 'テスト病院');
        hospital.RecordTypeId = recByoin.id;
        hospital.Site = 'テスト病院部門';
        hospital.Alias_Name2__c = 'テスト病院別名';
        insert hospital;

        RecordType recHanbaiten = [select id from RecordType where IsActive = true and SobjectType = 'Account' and Name = :RC_HANBAOITEN limit 1];
        Account sellerA = new Account(Name = '販売店');
        sellerA.RecordTypeId = recHanbaiten.id;
        sellerA.Hospital__c = hospital.id;
        insert sellerA;

        Product2 product2 = new Product2( Name = '11112');
        product2.SFDA_Status__c = '不要';
        product2.Intra_Trade_List_RMB_1__c = 100;
        product2.Intra_Trade_List_RMB_Date1__c = date.today();
        product2.Intra_Trade_List_RMB_End_Date1__c = date.today().addDays(1);
        product2.Intra_Trade_Cost_RMB_1__c = 200;
        product2.Intra_Trade_Cost_RMB_Date1__c = date.today();
        product2.Intra_Trade_Cost_RMB_End_Date1__c = date.today().addDays(1);
        product2.Manual_Entry__c = false;
        product2.Asset_Model_No__c = '11112';
        product2.MDM_Model_No__c = '11112';
        insert product2;

        PricebookEntry pE2 = new PricebookEntry( Pricebook2Id = pricebook.Id, Product2Id = product2.Id);
        pE2.UnitPrice = 0;
        pE2.IsActive = true;
        pE2.UseStandardPrice = false;
        pE2.CurrencyIsoCode = CurrencyIso;
        insert pE2;

        Opportunity opp1 = buildOppInstance( trade, CurrencyIso);
        opp1.Trade__c = trade;
        opp1.owner_not_automatically_update__c = true;
        opp1.Sales_Root__c = 'AAA';
        opp1.Pricebook2Id = pricebook.id;
        opp1.Estimation_Decision__c=true;
        insert opp1;

        OpportunityLineItem oli = new OpportunityLineItem();
        oli.Quantity = 1;
        oli.UnitPrice = 10;
        oli.PricebookEntryId = pE2.Id;
        oli.OpportunityId = opp1.id;
        oli.Cost__c = 100;
        insert oli;

        SI_NewQuoteEntryController.QELine act = new SI_NewQuoteEntryController.QELine(oli, 0);
        act.Asset_Model = '';
        act.pageObject.Quantity__c = 10;
        act.pageObject.UnitPrice = 100;
        act.pageObject.Subtotal__c = 1000;
        act.pageObject.PricebookEntryId = pE2.id;
        List<SI_NewQuoteEntryController.QELine> actList = new List<SI_NewQuoteEntryController.QELine>();
        actList.add(act);

        SI_NewQuoteEntryController controller = new SI_NewQuoteEntryController();
        controller.oppId=opp1.Id;
        controller.enableSales=true;
        Quote quote=new Quote();
        quote.QuoteName__c = 'テスト見積';
        quote.Dealer_Final_Price_Page__c = 100;
        quote.Quote_Adjust_Amount_Page__c = 10;
        quote.Quote_Expiration_Date__c = date.today();
        quote.Agency1__c = sellerA.id;
        quote.OCM_Agent1_Price_Page__c = 1243;
        quote.OpportunityId = opp1.id;
        quote.Name ='テスト見積';
        quote.Pricebook2Id = pricebook.id;
        quote.Quote_No__c = quoteNo;
        insert quote;
        system.debug('act2++++++++++'+pE2);

        QuoteLineItem item02 = new QuoteLineItem();
        item02.Name__c = 'テスト商品';
        item02.QuoteId = quote.Id;
        item02.Quantity = 1;
        item02.Cost_Subtotal__c = 0;
        item02.Cost__c = 200;
        item02.UnitPrice = 10;
        item02.PricebookEntryId = pE2.Id;
        insert item02;

        // quote.QuoteName__c = 'テスト見積';
        // quote.QuoteName__c = 'テスト見積';
        controller.quo=quote;
        SI_NewQuoteEntryController.QuoteBean qbs=new SI_NewQuoteEntryController.QuoteBean();
        qbs.Quote_Adjust_Calculate = 100;
        controller.qb = qbs;
        controller.rowIdx=1;
        controller.activities=actList;
        controller.opp=opp1;
        controller.addMultipleRow();
        SI_NewQuoteEntryController.QELine actList12 = new SI_NewQuoteEntryController.QELine(10,true,'aaa',Date.today(),'bbb',pE2.Id,'ddd','eee','fff','ggg','hhh','iii','jjj','kkk',10,1.1,2.2,3.3,4.0,5.5,6.6,'lll',7.7,8.8);
        system.debug('xxxxxxxxxxxxxxxxxxxxxxxx++++++++++++++++++++++++');
    }
}