@isTest
private class QuotePDFExtensionControllerTest {

	private static Product2 productA = null;
	private static Product2 productB = null;
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
	static {
		productA = new Product2( Name='テスト商品');
		productB = new Product2( Name='テスト : 商品',ProduceCompany__c='#%生产企业名称:奥林巴斯苇音特&&和意北公司 Olympus Winter & Ibe GmbH;;住所:#Kuehnstr.61,22045 Hamburg ,Germany;Kuehnstr.61,22045 Hamburg ,Germany;联系方式:');
		insert productA;
		insert productB;
	}
	
	private static PricebookEntry buildPBA( String input) {
		PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productA.Id);
		entry.UnitPrice = 0;
		entry.IsActive = true;
		entry.UseStandardPrice = false;
		entry.CurrencyIsoCode = input;
		insert entry;
		return entry;
	}
	private static PricebookEntry buildPBB( String input) {
		PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=productB.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.CurrencyIsoCode = CurrencyIsoCode;
		return target;
	}
	
	private static QuoteLineItem insertQuoteLineItem01( Quote input, Pricebookentry entry) {
		QuoteLineItem target = new QuoteLineItem();
		target.QuoteId = input.Id;
		target.Quantity = 1;
//		target.TotalPrice = 100;
		target.UnitPrice = 0;
		target.UnitPrice__c = 10;
		target.PricebookEntryId = entry.Id;
		target.Name__c = 'aieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueo';
		insert target;
		return target;
	}

	private static QuoteLineItem insertQuoteLineItem02( Quote input, Pricebookentry entry) {
		QuoteLineItem target = new QuoteLineItem();
		target.QuoteId = input.Id;
		target.Quantity = 1;
//		target.TotalPrice = 100;
		target.UnitPrice = 0;
		target.UnitPrice__c = 10;
		target.PricebookEntryId = entry.Id;
		target.Name__c = 'a:ieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueoaieuoaiueo';
		insert target;
		return target;
	}
	
//	private static String opportunityNo = 'testOpp01';
	private static String quoteNo = 'textQutote01';
//	private static String departmentName = 'kashitsu';
	private static String trade = '内貿';
	private static String currencyCNY = 'RMB';
	
	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 test01() {
    	
    	// PricebookEntry
    	PricebookEntry entryCNY02 = buildPBA( 'CNY');
		PricebookEntry entryCNY01 = buildPBB( 'CNY');
    	
    	// 商談作成
    	Opportunity opp = buildOppInstance( trade, 'CNY');
    	opp.Pricebook2Id = pricebookId;
    	insert opp;
    	opp = [SElECT Id, Opportunity_no__c, CurrencyIsoCode FROM Opportunity WHERE Id = :opp.id];
    	System.assertEquals( 'CNY', opp.CurrencyIsoCode);
    	
    	// 見積作成
    	Quote quote = new Quote( Name='テスト見積');
    	quote.OpportunityId = opp.Id;
    	quote.Pricebook2Id = pricebookId;
    	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( 'CNY', quote.CurrencyIsoCode);
    	
    	// 見積品目作成
    	QuoteLineItem item01 = insertQuoteLineItem01( quote, entryCNY01);
    	QuoteLineItem item02 = insertQuoteLineItem02( quote, entryCNY02);
    	for ( Integer i = 0; i < 30; i++) {
    		item02 = insertQuoteLineItem02( quote, entryCNY02);
    	}
    	
        QuotePDFExtensionController target = new QuotePDFExtensionController( quote.id);
        QuotePDFExtensionController.Parameters params = target.params;
        
		System.assertEquals( quoteNo, params.quoteNo);
		System.assertEquals( currencyCNY, params.trade);
		
		System.assertEquals( isUnitPrice, params.isUnitPrice);
		System.assertEquals( isOfferAmount, params.isOfferAmount);
		System.assertEquals( isTotalPrice, params.isTotalPrice);
		System.assertEquals( isDiscountRate, params.isDiscountRate);
		System.assertEquals( isDiscountAmount, params.isDiscountAmount);
		System.assertEquals( isTradingPrice, params.isTradingPrice);
		System.assertEquals( isContractDetail, params.isContractDetail);
		
		target.startContract();
		target.startQuote();
		
		target.params.getAgentNameForContract();
		target.params.agent1Name ='aiueo';
		target.params.getAgentNameForContract();
		target.params.agent2Name = 'aiueo';
		target.params.getAgentNameForContract();
		target.params.agent1Name = null;
		target.params.getAgentNameForContract();
    }


    
    
}