高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@isTest
private class BeforeOPDPDFExtensionControllerTest {
    
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    
    // 询价入口测试
    static testMethod void myUnitTest() {
        
        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;
        
        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.Name='aiueo';
        opp.StageName='contact';
        opp.Trade__c = '内貿';
        opp.CloseDate=Date.today();
        opp.CurrencyIsoCode = 'CNY';
        opp.Estimation_List_Price__c = 100;
        opp.Wholesale_Price__c = 101;
        opp.Dealer_Final_Price__c = 102;
        opp.OCM_Agent1_Price__c = 103;
        opp.Stocking_Price__c = 104;
        opp.Estimation_No__c = '105';
        opp.Estimation_Name__c = '106';
        opp.Estimation_Id__c = '107';
        insert opp;
        
        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;
        
        OpportunityLineItem oppli2 = new OpportunityLineItem();
        oppli2.OpportunityId = opp.Id;
        oppli2.Id__c = '110';
        oppli2.SFDA_Status__c = '有効';
        oppli2.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五';
        oppli2.ListPrice__c = 112;
        oppli2.Quantity = 113;
        oppli2.UnitPrice = 114;
        oppli2.UnitPrice__c = 115;
        oppli2.Qty_Unit__c = '116';
        oppli2.Cost__c = 117;
        oppli2.BSS_Category__c = 'G&R';
        oppli2.Item_Order__c = 1;
        oppli2.PricebookEntryId = entry.Id;
        insert oppli2;
        
        Common_Sequence__c cs = new Common_Sequence__c();
        cs.Name = 'test';
        cs.EvaluationPDF_NextValue__c = 1;
        insert cs;
        
        PageReference page = new PageReference('/apex/BeforeOPDPDF?oid=' + opp.Id);
        System.Test.setCurrentPage(page);
        BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController();
        // 初始化测试
        controller.startContract();
        
        System.assertEquals(1, controller.printRecords.size());
        System.assertEquals(3, controller.printRecords[0].size());
    }
    
    // 报价依赖入口测试
    static testMethod void myUnitTest2() {
        
        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;
        
        PricebookEntry entry = new PricebookEntry( Pricebook2Id=pricebookId, Product2Id=product.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        insert entry;
        
        QuoteIrai__c irai = new QuoteIrai__c();
        irai.IraiSubject__c = '委托01';
        irai.IraiUser__c = null;
        irai.CurrencyIsoCode = 'USD';
        insert irai;
        
        QuoteIraiLineItem__c item1 = new QuoteIraiLineItem__c();
        item1.SFDA_Status__c = '有効';
        item1.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十';
        item1.Quantity__c = 1;
        item1.ListPrice__c = 2150;
        item1.Product2__c = product.Id;
        item1.QuoteIrai__c = irai.Id;
        
        QuoteIraiLineItem__c item2 = new QuoteIraiLineItem__c();
        item2.SFDA_Status__c = '有効';
        item2.Name__c = '一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五';
        item2.Quantity__c = 1;
        item2.ListPrice__c = 2150;
        item2.Product2__c = product.Id;
        item2.QuoteIrai__c = irai.Id;
        
        insert new QuoteIraiLineItem__c[] {item1,item2};
        
        Common_Sequence__c cs = new Common_Sequence__c();
        cs.Name = 'test';
        cs.EvaluationPDF_NextValue__c = 1;
        insert cs;
        
        PageReference page = new PageReference('/apex/BeforeOPDPDF?qid=' + irai.Id);
        System.Test.setCurrentPage(page);
        BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController();
        // 初始化测试
        controller.startContract();
        
        System.assertEquals(1, controller.printRecords.size());
        System.assertEquals(3, controller.printRecords[0].size());
    }
    
    // 消耗品入口测试
    static testMethod void myUnitTest3() {
        
        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;
        
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc];
        
        Account company1 = new Account(
            RecordTypeId = rectCo[0].Id,
            Name = '病院テスト1'
        );
        insert company1;
        
        List<Account> dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c];
        
        Account depart1 = new Account();
        depart1.RecordTypeId = rectDpt[0].Id;
        depart1.Name         = '*';
        depart1.Department_Name__c  = '診療科1';
        depart1.ParentId            = dc1s[0].Id;
        depart1.Department_Class__c = dc1s[0].Id;
        depart1.Hospital__c         = company1.Id;
        insert depart1;
        
        RecordType rtDoc = [select id from RecordType where DeveloperName =:'Doctor'];
        
        Contact con1 = new Contact();
        con1.FirstName='ZZ';
        con1.LastName = '取引先責任者1';
        con1.RecordTypeId = rtDoc.id;
        con1.AccountId = depart1.Id;
        con1.Strategic_dept_Class__c = dc1s[0].Id;
        insert con1;
        
        ConsumableSample__c csample = new ConsumableSample__c(Contact__c = con1.Id);
        insert csample;
        
        ConsumableSampleLineItem__c csli = new ConsumableSampleLineItem__c(
            ConsumableSample__c = csample.Id,
            Product2__c = product.Id,
            Name__c = 'テスト商品'
        );
        insert csli;
        
        Common_Sequence__c cs = new Common_Sequence__c();
        cs.Name = 'test';
        cs.EvaluationPDF_NextValue__c = 1;
        insert cs;
        
        PageReference page = new PageReference('/apex/BeforeOPDPDF?csid=' + csample.Id);
        System.Test.setCurrentPage(page);
        BeforeOPDPDFExtensionController controller = new BeforeOPDPDFExtensionController();
        // 初始化测试
        controller.startContract();
        
        System.assertEquals(1, controller.printRecords.size());
    }
}