高章伟
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
@isTest
public with sharing class RepairReceiptTriggerTest {
    public RepairReceiptTriggerTest() {
 
    }
 
    private static Id pricebookId = ControllerUtil.getStandardPricebook().Id;
    static Account createHospital( String hospitalName , String Sales) {
        StaticParameter.EscapeNFM001AgencyContractTrigger = true;
        StaticParameter.EscapeNFM001Trigger = true;
        // 病院を作る
        Account hospital = new Account();
        Id AgencyRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Agency').getRecordTypeId();
        hospital.recordtypeId = AgencyRecordTypeId;
        hospital.Name = hospitalName;
        hospital.Sales_Shop_Class__c = Sales;
        insert hospital;
        StaticParameter.EscapeAccountTrigger = true;
        return hospital;
    }
 
    static List<Account> selectStrategicDep( Account hospital) {
        // 戦略科室を得る
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI'];
        return strategicDep;
    }
 
    static Account createDep( Account hospital, Account strategicDep) {
        // 診療科を作る
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE DeveloperName = 'Department_GI'].id;
        dep.Name = 'test dep';
        dep.ParentId = strategicDep.Id;
        dep.Department_Class__c = strategicDep.Id;
        dep.Hospital__c = hospital.Id;
        dep.Sales_Shop_Class__c = '特約販売店(区域)';
        // dep.State_Text__c = '上海市';
        insert dep;
        return dep;
    }
 
    // static Asset createAsset( Account hospital, Account strategicDep, Account dep) {
    static Asset createAsset( Account hospital) {
 
        // 製品を作る
        Product2 productA = new Product2( Name = 'テスト商品');
        insert productA;
 
        // 価格表エントリを作成する
        PricebookEntry entry = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = productA.Id);
        entry.UnitPrice = 0;
        entry.IsActive = true;
        entry.UseStandardPrice = false;
        entry.CurrencyIsoCode = 'CNY';
        entry.Product2Id = productA.Id;
        insert entry;
 
        // 納入機器を作成する
        Asset asset = new Asset();
        asset.Name = 'テスト機器';
        // asset.AccountId = dep.Id;
        // asset.Department_Class__c = strategicDep.Id;
        // asset.Hospital__c = hospital.Id;
        asset.AccountId = hospital.Id;
        asset.SerialNumber = 'testserial';
        asset.Quantity = 3;
        // asset.Extend_Gurantee_DateTo_Text__c =Date.today().addDays(30);
        // asset.IS_Extend_Gurantee_Txt__c =true;
        // asset.Order_No__c = 'BJ_2020';
 
        insert asset;
 
        return asset;
    }
 
    @isTest
    static void test(){
        ControllerUtil.EscapeNFM001Trigger = true;
        // 病院、戦略科室、診療科の情報を作成します
        Account hospital1 = createHospital( 'test hospital1' , '特約販売店(区域)');
        Account hospital2 = createHospital( 'test hospital2' , '医疗修理经销商');
 
        Account hospital3 = createHospital( 'test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3test hospital3' , '特約販売店(区域)');
        Account hospital4 = createHospital( 'test hospital4' , '一級販売店');
        // Account[] strategicDep = selectStrategicDep( hospital1);
        // Account dep = createDep( hospital1, strategicDep[0]);
 
        // 納入機器を作る
        Asset asset = createAsset( hospital1);
        // 维修合同を作成する
        // Maintenance_Contract__c contract = createMaintenanceContract( hospital1, strategicDep[0], dep);
        // 中間テーブルを設ける
        // Maintenance_Contract_Asset__c middleTable = createMiddleTable( asset, contract);
 
 
        // 修理を作成する01
        Repair__c repair01 = new Repair__c();
        // repair01.Account__c = dep.Id;
        // repair01.Department_Class__c = strategicDep[0].Id;
        repair01.Dealer__c = hospital1.Id;
        repair01.Delivered_Product__c = asset.Id;
        repair01.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1000); // 维修合同判断日がサービス契約のだいぶ前
        repair01.Failure_Occurrence_Date__c  =Date.today();
        repair01.BilltoPartyNoAccount__c = '';
        insert repair01;
 
        // 修理を作成する02
        Repair__c repair02 = new Repair__c();
        // repair02.Account__c = dep.Id;
        // repair02.Department_Class__c = strategicDep[0].Id;
        repair02.Dealer__c = hospital3.Id;
        repair02.Delivered_Product__c = asset.Id;
        repair02.SERVICE_CONTRACT_JUDEGE_DAY__C = Date.today().addDays( -1000); // 维修合同判断日がサービス契約のだいぶ前
        repair02.Failure_Occurrence_Date__c  =Date.today();
        repair02.BilltoPartyNoAccount__c = '南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司/南京乐硕贸易有限公司';
        insert repair02;
 
        Date toDate = Date.today();
        Date expirationDate = toDate.toStartOfMonth()-1;
        Oly_TriggerHandler.bypass('RepairReceiptHandler');
        Repair_receipt__c rr = new Repair_receipt__c();
        rr.Name = '123456';
        rr.UniqueKey__c = '1234567';
        rr.Repair__c = System.Label.Olympus_Dummy_Repair;
        rr.Maintenance_Contract__c =  System.Label.Olympus_Dummy_MC;
        rr.PaymentAmount__c = Decimal.valueOf('1235');
        //rr.PaymentDate__c = NFMUtil.parseStr2Date('20190422');
        rr.PaymentDate__c = expirationDate;
        rr.Repair__c = repair01.Id;
        rr.BilltoPartyNoAccount__c = hospital1.Id;
        rr.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
 
        Repair_receipt__c rr2 = new Repair_receipt__c();
        rr2.Name = '123456-1';
        rr2.UniqueKey__c = '20200813';
        rr2.Repair__c = System.Label.Olympus_Dummy_Repair;
        rr2.Maintenance_Contract__c =  System.Label.Olympus_Dummy_MC;
        rr2.PaymentAmount__c = Decimal.valueOf('1235');
        //rr.PaymentDate__c = NFMUtil.parseStr2Date('20190422');
        rr2.PaymentDate__c = expirationDate;
        rr2.Repair__c = repair01.Id;
        rr2.BilltoPartyNoAccount__c = hospital2.Id;
        rr2.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
 
        Repair_receipt__c rr3 = new Repair_receipt__c();
        rr3.Name = '123456-11';
        rr3.UniqueKey__c = '20200815';
        rr3.Repair__c = System.Label.Olympus_Dummy_Repair;
        rr3.Maintenance_Contract__c =  System.Label.Olympus_Dummy_MC;
        rr3.PaymentAmount__c = Decimal.valueOf('1235');
        //rr3.PaymentDate__c = NFMUtil.parseStr2Date('20190422');
        rr3.PaymentDate__c = expirationDate;
        rr3.Repair__c = repair02.Id;
        rr3.BilltoPartyNoAccount__c = hospital3.Id;
        rr3.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
 
        Repair_receipt__c rr4 = new Repair_receipt__c();
        rr4.Name = '123456-12';
        rr4.UniqueKey__c = '20200825';
        rr4.Repair__c = System.Label.Olympus_Dummy_Repair;
        rr4.Maintenance_Contract__c =  System.Label.Olympus_Dummy_MC;
        rr4.PaymentAmount__c = Decimal.valueOf('1235');
        //rr4.PaymentDate__c = NFMUtil.parseStr2Date('20190422');
        rr4.PaymentDate__c = expirationDate;
        rr4.Repair__c = repair02.Id;
        rr4.BilltoPartyNoAccount__c = hospital4.Id;
        rr4.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
 
        List<Repair_receipt__c> rcs = new List<Repair_receipt__c>();
        rcs.add(rr);
        rcs.add(rr2);
        rcs.add(rr3);
        rcs.add(rr4);
        
 
        System.debug('repair01+++'+repair01);
        insert rcs;
        update rcs;
 
        // repair01 = [select id,name,BilltoPartyNoAccount__c from Repair__c where id = :repair01.Id];
        repair01 = [select id,name from Repair__c where id = :repair01.Id];
        System.debug('repair  01+++'+repair01);
        System.debug('111111111');
        // System.assertEquals(repair01.BilltoPartyNoAccount__c, 'test hospital1/test hospital2');
    } 
 
 
 
}