高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class CurrentPeriodPaymentAmountBatchTest {
    
    @isTest static void test_method_one() {
        ControllerUtil.EscapeNFM001Trigger = true;
 
 
        Profile p = [select Id from Profile where id =: System.Label.ProfileId_SystemAdmin];
        User u1 = new User(Test_staff__c = true);
        u1.LastName = '_サンブリッジ';
        u1.FirstName = 'あ';
        u1.Alias = 'あ';
        u1.Email = 'olympusTest01@sunbridge.com';
        u1.Username = 'olympusTest01@sunbridge.com';
        u1.CommunityNickname = 'あ';
        u1.IsActive = true;
        u1.EmailEncodingKey = 'ISO-2022-JP';
        u1.TimeZoneSidKey = 'Asia/Tokyo';
        u1.LocaleSidKey = 'ja_JP';
        u1.LanguageLocaleKey = 'ja';
        u1.ProfileId = p.Id;
        u1.Job_Category__c = '销售服务';
        u1.Province__c = '東京';
        insert u1;
 
        User u2 = new User(Test_staff__c = true);
        u2.LastName = '_サンブリッジ';
        u2.FirstName = 'い';
        u2.Alias = 'い';
        u2.Email = 'olympusTest02@sunbridge.com';
        u2.Username = 'olympusTest02@sunbridge.com';
        u2.CommunityNickname = 'い';
        u2.IsActive = true;
        u2.EmailEncodingKey = 'ISO-2022-JP';
        u2.TimeZoneSidKey = 'Asia/Tokyo';
        u2.LocaleSidKey = 'ja_JP';
        u2.LanguageLocaleKey = 'ja';
        u2.ProfileId = p.Id;
        u2.Job_Category__c = '销售推广';
        u2.Province__c = '東京';
        insert u2;
 
        system.runAs(u1) {
            List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
            if (rectCo.size() == 0) {
                throw new ControllerUtil.myException('not found 病院 recodetype');
            }
            List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 消化科'];
            if (rectSct.size() == 0) {
                throw new ControllerUtil.myException('not found 戦略科室分類 消化科 recodetype');
            }
            List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
            if (rectDpt.size() == 0) {
                throw new ControllerUtil.myException('not found 診療科 消化科 recodetype');
            }
            // テストデータ
            Account company = new Account();
            company.RecordTypeId = rectCo[0].Id;
            company.Name         = 'NFM108TestCompany';
            company.FSE_SP_Main_Leader__c = u1.Id;
            company.FSE_GI_Main_Leader__c = u1.Id;
            upsert company;
            Account section = [Select Id, Name, Department_Class_Label__c, ParentId from Account where ParentId = :company.Id and RecordTypeId = :rectSct[0].Id];
 
            Account depart = new Account();
            depart.RecordTypeId        = rectDpt[0].Id;
            depart.Name                = '*';
            depart.Department_Name__c  = 'NFM108TestDepart';
            depart.ParentId            = section.Id;
            depart.Department_Class__c = section.Id;
            depart.Hospital__c         = company.Id;
            upsert depart;
 
            // 再取得
            List<Account> accList = new List<Account>();
            company = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :company.Id];
            accList.add(company);
            section = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :section.Id];
            accList.add(section);
            depart = [select Management_Code__c, Management_Code_Auto__c, Name, Id from Account where Id = :depart.Id];
            accList.add(depart);
 
            List<Product2> prdList = new List<Product2>();
            Product2 prd1 = new Product2();
            prd1.ProductCode_Ext__c     = 'NFM108Prd1';
            prd1.ProductCode            = 'NFM108Prd1';
            prd1.Repair_Product_Code__c = 'NFM108Prd1_RP';
            prd1.Name                   = 'NFM108Prd1';
            prd1.Manual_Entry__c        = false;
            prdList.add(prd1);
            Product2 prd2 = new Product2();
            prd2.ProductCode_Ext__c     = 'NFM108Prd2';
            prd2.ProductCode            = 'NFM108Prd2';
            prd2.Repair_Product_Code__c = 'NFM108Prd2_RP';
            prd2.Name                   = 'NFM108Prd2';
            prd2.Manual_Entry__c        = false;
            prdList.add(prd2);
            insert prdList;
 
            Asset ast = new Asset();
            ast.Name                             = 'NFM108Ast1';
            ast.AccountId                        = depart.Id;
            ast.Department_Class__c              = section.Id;
            ast.Hospital__c                      = company.Id;
            ast.Product2Id                       = prd1.Id;
            ast.SerialNumber                     = 'NFM108SerialNumber';
            ast.Guarantee_period_for_products__c = Date.today();
            ast.InstallDate                      = Date.today();
            insert ast;
            ast = [select Id, Name, Product_Serial_No__c, AccountId, Department_Class__c, Department_Class__r.Management_Code_Auto__c, Hospital__c, Product2Id, Product2.ProductCode, Product2.Repair_Product_Code__c, SerialNumber
                                     from Asset
                                    where Id = :ast.Id];
 
            Repair__c rpr = new Repair__c();
            rpr.SAPRepairNo__c   = 'NFM108SAP';
            rpr.Account__c             = depart.Id;
            rpr.Department_Class__c    = section.Id;
            rpr.Hospital__c            = company.Id;
            rpr.Delivered_Product__c   = ast.Id;
            rpr.SalesOfficeCode_selection__c = '北京';
            rpr.LastIssueCumulativePaybackAmount__c = 0;
            insert rpr;
            rpr = [select Id, Name, Delivered_Product__c, SAPRepairNo__c from Repair__c where Id = :rpr.Id];
            String strSFDCRepairNo = rpr.Name + ':123';
 
            Maintenance_Contract__c mc1 = new Maintenance_Contract__c();
            mc1.Name = 'mc1';
            mc1.Past_update_contract__c = true;
            mc1.RecordTypeId = '01210000000QjeFAAS';
            mc1.CurrencyIsoCode = 'CNY';
            mc1.Status__c = '契約';
            mc1.Hospital__c = company.Id;
            mc1.Department_Class__c = section.Id;
            mc1.Department__c = depart.Id;
            mc1.Maintenance_Contract_No__c = 'mc1';
            mc1.Contract_Conclusion_Date__c = Date.today();
            mc1.Contract_End_Date__c = Date.today().addDays(1);
            mc1.SalesOfficeCode_selection__c = '北京RC';
            mc1.LastIssueCumulativePaybackAmount__c = 0;
            mc1.Service_Contract_Staff__c = u1.Id;
            insert mc1;
 
 
            Date toDate = Date.today();
            Date expirationDate = Date.newInstance(toDate.year(), 3, 31);
            Repair_receipt__c rr = new Repair_receipt__c();
            rr.Name = '123456';
            rr.UniqueKey__c = '1234567';
            rr.Repair__c = rpr.Id;
            rr.Maintenance_Contract__c =  mc1.Id;
            rr.PaymentAmount__c = Decimal.valueOf('1235');
            rr.PaymentDate__c = expirationDate;
            rr.DeadlineLastMonthPeriodPaymentAmountFigu__c = 2;
            insert rr;
 
            System.Test.StartTest();
            Id execBTId = Database.executeBatch(new CurrentPeriodPaymentAmountBatch(),100);
            List<String> idList = new List<String>();
            idList.add(rr.id);
            execBTId = Database.executeBatch(new CurrentPeriodPaymentAmountBatch(idList),100);
            System.Test.StopTest();
            List<Repair__c> repairList = [select Id,Name,
                                    LastIssueCumulativePaybackAmount__c,
                                    LastIssueCumulativePayback__c
                                            from Repair__c];
            //若此处通不过,请修改修理字段"上期止累计回款(后台用)"的过滤条件,改为当前财年的4月1日
            System.assertEquals(1235,repairList[0].LastIssueCumulativePayback__c);
            System.assertEquals(1235,repairList[0].LastIssueCumulativePaybackAmount__c); 
            List<Maintenance_Contract__c> mcList = [select Id,Name,
                                    LastIssueCumulativePayback__c,
                                    LastIssueCumulativePaybackAmount__c
                                            from Maintenance_Contract__c]; 
            //若此处通不过,请修改维修合同字段"上期止累计回款(后台用)"的过滤条件,改为当前财年的4月1日                                
            System.assertEquals(1235,mcList[0].LastIssueCumulativePaybackAmount__c);                                                              
            
 
        }
 
        
    }
    
}