liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
public with sharing class MaintenanceContractVMPDFController {
    /** 処理対象の見積オブジェクトです。 */
    public EstimateInfo targetObj { get; private set; }
    /** 見積オブジェクトのリスト(改ページ用) */
    public List<EstimateInfo> targetObjList { get; private set; }
    /** 1ページに表示する明細の数です。 */
    private Integer rowSize = 13; // TODO ラベルに定義
    
    private Integer nameMax = 23;
    private Integer commentMax = 5;
    //2021-11-30 fy add LJPH-C8W8FV 置顶 start
    public List<String> TopProductModel =new List<String>();
    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
    private Integer lineNo = 0;
    // 参保价格汇总
    public Decimal benchmark_priceSum { get; private set; }
    public Date estimateendDate  { get; private set; }
    public Integer year { get; private set; }
    
    public Integer getTargetObjSize() {
        return this.targetObjList.size();
    }
 
    public MaintenanceContractVMPDFController(ApexPages.StandardController controller) {     
    }
 public void init() {
     //2021-11-30 fy add LJPH-C8W8FV 置顶 start
    TopProductModel.add('CF-LV1I');
    TopProductModel.add('CF-LV1L');
    TopProductModel.add('CV-V1');
    TopProductModel.add('GIF-LV1');
    TopProductModel.add('OER-AW');
    TopProductModel.add('OER-A');
    //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        String targetEstimateId = ApexPages.currentPage().getParameters().get('id');
        // 見積情報を取得、必ずあるはず
        // TODO 書き方修正
        // 
        estimateendDate = null;
        benchmark_priceSum = 0;
        List<Maintenance_Contract_Estimate__c> mceList = 
                [SELECT Id, Name, Maintenance_Contract__c, Estimate_Target__c, Dealer__r.Name, CreatedDate,
                        Maintenance_Contract__r.Management_Code__c,
                        Maintenance_Contract__r.Hospital__r.Name, Department__c,
                        Contract_Range__c, Contract_Esti_Start_Date__c, Contract_Esti_End_Date__c,
                        Contract_Start_Date__c, Contract_End_Date__c,
                        Estimate_Trial_Money__c, Asset_Repair_Sum_Price__c, Maintenance_Price__c, NotUse_Oxygenated_Water__c,
                        Examination_Price__c, Service_contract_target_number__c, Append_Condition_Price__c,
                        Discount_Price__c, Discount_Percentage__c, Last_Discount__c, Asset_Sum_Price__c,
                        Print_Contract__c, Print_RepairPrice__c, Print_DiscountPercentage__c,
                        Print_DiscountPrice__c, Print_ListPrice__c, Print_MaintePrice__c, Print_SumPrice__c,
                        Submit_quotation_day__c,Maintenance_Contract__r.RecordType.Name,Maintenance_Contract__r.Service_Contract_Staff__r.Name,
                        Maintenance_Contract__r.Contract_create_reason__c,NewEstimation_Amount__c,Maintenance_Contract__r.Estimate_Contract_endDate__c,
                        Print_Simplify__c,New_contract_offer__c,Request_quotation_Amount__c,Service_DiscountPercentage__c,
                        GuidePrice_Up__c,GuidePrice_Down__c,Service_Discount_Price__c,New_Contract_Type_TxT__c,
                        //URF限次合同2期 XXF 20220920 start
                        URF_P_MaxRepairCount__c,URF_V_MaxRepairCount__c,URF_Contract__c,
                        URF_P_RepairTime__c,URF_V_RepairTime__c
                        //URF限次合同2期 XXF 20220920 end
                   FROM Maintenance_Contract_Estimate__c WHERE Id = :targetEstimateId]
        ;
        system.debug('维修合同报价:'+mceList+'---'+'维修合同id:'+targetEstimateId);
        // 見積を取得できない場合
        if (mceList.size() == 0) {
            throw new ControllerUtil.myException('报价不存在');
        }
        this.targetObj = new EstimateInfo(mceList);
        if (this.targetObj.estimate.Submit_quotation_day__c == null) {
            estimateendDate = date.today().addMonths(3);
        }else{
            estimateendDate = this.targetObj.estimate.Submit_quotation_day__c.addMonths(3);
        }
        targetObjList = new List<EstimateInfo>();
        // ページ毎に見積の情報(製品はページ毎にバラバラ)
        EstimateInfo tmpTargetObj = new EstimateInfo(mceList);
        // 新品と酸化水の金額を算出するため、製品を一リストに集約
        EstimateInfo targetObjForSum = this.targetObj;
        
        // 合計の出力フラグによりページ毎の行数を変更
        if (!this.targetObj.estimate.Print_SumPrice__c) {
            rowSize = rowSize + 3;
        }
        if (!this.targetObj.estimate.Print_MaintePrice__c) {
            rowSize = rowSize + 1;
        }
        system.debug('详细:'+this.targetObj.estimate.Print_ListPrice__c+
            '简约:'+this.targetObj.estimate.Print_Simplify__c+
            '修理:'+this.targetObj.estimate.Print_RepairPrice__c);
        // 明細の設定
        Integer cnt = 1;
        // 最近一期合同结束日
        Date lastDate = null;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        List<Maintenance_Contract_Asset_Estimate__c> mcaeList = [SELECT Id, Name, Asset__c,
        Asset__r.Name, Asset__r.SerialNumber, Asset__r.InstallDate,
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        Asset__r.OwnershipMachine_No__c,
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        Product_Manual__c, Product_Manual__r.Maintenance_Price_Month__c, Product_Manual__r.Name, 
        //2021-11-30 fy add LJPH-C8W8FV 置顶 start
        Product_Manual__r.Asset_Model_No__c,
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        IsNew__c,
        Maintenance_Price_Month__c, Estimate_List_Price__c,
        Check_Result__c, Repair_Price__c, Check_Object__c, Comment__c,Asset__r.CurrentContract_Asset_Price__c,
        Check_Result_Formula__c,Maintenance_Contract_Estimate__r.Management_Code__c,
        //消费率  维修合同价格 打印PDF  
        Asset_Consumption_rate__c,Maintenance_Contract_Estimate__r.Maintenance_Contract__r.Contract_Consumption_rate__c,
        Asset__r.Maintenance_RMB__c,Estimate_Cost__c,Estimate_List_Price_All__c,Adjustment_ratio_Upper__c,Adjustment_ratio_Lower__c,
        Maintenance_Contract_Estimate__r.Discount_Percentage__c,Asset__r.CurrentContract_F_asset__r.Estimate_Cost_formula__c,
        Asset__r.CurrentContract_F__r.Maintenance_Contract_No_F__c,Adjustment_Upper_price__c,Adjustment_Lower_price__c,
        Benchmark_price__c,Asset__r.CurrentContract_F__r.Contract_End_Date__c
   FROM Maintenance_Contract_Asset_Estimate__c
  WHERE Maintenance_Contract_Estimate__c = :this.targetObj.estimate.Id
  ORDER BY Product_Manual__c, Asset__r.SerialNumber, Asset__r.Name, Asset__r.Department_Name__c, Asset__r.InstallDate];
 
        List<Maintenance_Contract_Asset_Estimate__c> topAsset =new List<Maintenance_Contract_Asset_Estimate__c>();
        List<Maintenance_Contract_Asset_Estimate__c> otherAsset =new List<Maintenance_Contract_Asset_Estimate__c>();
        
        for(Maintenance_Contract_Asset_Estimate__c tarAsse : mcaeList){
            system.debug('sss===' + tarAsse.Product_Manual__r.Asset_Model_No__c);
            system.debug('yyy===' + tarAsse.Asset__r.OwnershipMachine_No__c);
            if(TopProductModel.contains(tarAsse.Asset__r.OwnershipMachine_No__c)||TopProductModel.contains(tarAsse.Product_Manual__r.Asset_Model_No__c)){
                topAsset.add(tarAsse);
            }else{
                otherAsset.add(tarAsse);
            }
        }
        topAsset.addAll(otherAsset);
        mcaeList=topAsset;
        //2021-11-30 fy add LJPH-C8W8FV 置顶 end
        for(Maintenance_Contract_Asset_Estimate__c mcae : mcaeList) {
            //for(Integer a=0;a<20;a++){
            //tmpTargetObj.addAssetInfo(mcae);
            //targetObjForSum.addAssetInfo(mcae);
            //
            system.debug('实际报价金额:'+mcae.Estimate_Cost__c+'最近一期金额:'+mcae.Asset__r.CurrentContract_Asset_Price__c);
            String sname = '';
            benchmark_priceSum = benchmark_priceSum + mcae.Benchmark_price__c;
            if (mcae.Asset__c != null) {
 
                if (lastDate == null || mcae.Asset__r.CurrentContract_F__r.Contract_End_Date__c > lastDate) {
                    lastDate = mcae.Asset__r.CurrentContract_F__r.Contract_End_Date__c;
                }
 
                sname = mcae.Asset__r.Name == null ? '' : mcae.Asset__r.Name;
            } else if (mcae.Product_Manual__c != null) {
                sname = mcae.Product_Manual__r.Name == null ? '' : mcae.Product_Manual__r.Name;
            }
            String smodelNo = '';
            String scomment = mcae.Comment__c == null ? '' : mcae.Comment__c;
            if (sname.indexOf(':') >= 0) {
                smodelNo = sname.subString(0, sname.indexOf(':')+1);
                sname = sname.subString(sname.indexOf(':')+1);
            } else if (sname.indexOf(':') >= 0) {
                smodelNo = sname.subString(0, sname.indexOf(':')+1);
                sname = sname.subString(sname.indexOf(':')+1);
            } else {
                smodelNo = '';
            }
            Integer iname = (sname.length() / nameMax) + (Math.mod(sname.length(), nameMax) > 0 ? 1 : 0);
            if (iname == 0) {
                iname = 1;
            }
            Integer icomment = (scomment.length() / commentMax) + (Math.mod(scomment.length(), commentMax) > 0 ? 1 : 0);
            if (icomment == 0) {
                icomment = 1;
            }
            Integer icnt = iname;
            if (iname < icomment) {
                icnt = icomment;
            }
            if (icnt > 1) {
                for (Integer i = 0; i < icnt; i++) {
                    if  (i == 0) {
                        String printName = '';
                        if (i + 1 == iname) {
                            printName = smodelNo + sname;
                        } else {
                            printName = smodelNo + sname.substring(0, nameMax);
                        }
                        if (i + 1 == icomment) {
                            mcae.Comment__c = scomment;
                        } else {
                            mcae.Comment__c = scomment.substring(0, commentMax);
                        }
                        lineNo += 1;
                        tmpTargetObj.addAssetInfo(lineNo, mcae, printName);
                        targetObjForSum.addAssetInfo(lineNo, mcae, printName);
                    } else {
                        String printName = '';
                        Maintenance_Contract_Asset_Estimate__c newmcae = mcae.clone();
                        if (i < iname) {
                            if (i + 1 == iname) {
                                printName = sname.substring(i*nameMax);
                            } else {
                                printName = sname.substring(i*nameMax, (i+1)*nameMax);
                            }
                        } else {
                            printName = '';
                        }
                        if (i < icomment) {
                            if (i + 1 == icomment) {
                                newmcae.Comment__c = scomment.substring(i*commentMax);
                            } else {
                                newmcae.Comment__c = scomment.substring(i*commentMax, (i+1)*commentMax);
                            }
                        } else {
                            newmcae.Comment__c = '';
                        }
                        tmpTargetObj.addAssetInfo(lineNo, newmcae, printName);
                        targetObjForSum.addAssetInfo(lineNo, newmcae, printName);
                        
                        AssetInfo ainfo = tmpTargetObj.assetInfoList.get(tmpTargetObj.assetInfoList.size()-1);
                        ainfo.lineNo = null;
                        ainfo.assetModelNo = null;
                        ainfo.assetSerialNumber = null;
                        ainfo.installDate = null;
                        ainfo.mcae.Check_Result__c = null;
                        ainfo.listPrice = 0.0;
                        ainfo.repairPrice = 0.0;
                        ainfo.newDiscount = 0.0;
                        ainfo.quantity = null;
                        ainfo.mcae.Repair_Price__c = null;
                        ainfo.mcae.Estimate_List_Price__c = null;
 
                        AssetInfo ainfo2 = targetObjForSum.assetInfoList.get(targetObjForSum.assetInfoList.size()-1);
                        ainfo2.lineNo = null;
                        ainfo2.assetModelNo = null;
                        ainfo2.assetSerialNumber = null;
                        ainfo2.installDate = null;
                        ainfo2.mcae.Check_Result__c = null;
                        ainfo2.listPrice = 0.0;
                        ainfo2.repairPrice = 0.0;
                        ainfo2.newDiscount = 0.0;
                        ainfo2.quantity = null;
                        ainfo2.mcae.Repair_Price__c = null;
                        ainfo2.mcae.Estimate_List_Price__c = null;
                    }
                    // 改ページ判断
                    if (cnt == this.rowSize) {
                        cnt = 0;
                        targetObjList.add(tmpTargetObj);
                        tmpTargetObj = new EstimateInfo(mceList);
                    }
                    cnt++;
                }
            } else {
                lineNo += 1;
                tmpTargetObj.addAssetInfo(lineNo, mcae, null);
                targetObjForSum.addAssetInfo(lineNo, mcae, null);
                // 改ページ判断
                if (cnt == this.rowSize) {
                    cnt = 0;
                    targetObjList.add(tmpTargetObj);
                    tmpTargetObj = new EstimateInfo(mceList);
                }
                cnt++;
            }
//            }
        }
        // 新品优惠
        lineNo += 1;
        Boolean rs = tmpTargetObj.addNewDiscountLine(lineNo, targetObjForSum.assetInfoList);
        targetObjForSum.addNewDiscountLine(lineNo, targetObjForSum.assetInfoList);
        if (!rs) {
            lineNo -= 1;
        }
        // xudan 20140424 バグ修正、ちょうど改ページ後の第一行目に、新品优惠を出すかどうかの判断を修正
        if (tmpTargetObj.assetInfoList.size() > 0 && tmpTargetObj.assetInfoList[tmpTargetObj.assetInfoList.size() - 1].assetName == '新品优惠') {
            if (cnt == this.rowSize) {
                cnt = 0;
                targetObjList.add(tmpTargetObj);
                tmpTargetObj = new EstimateInfo(mceList);
            }
            cnt++;
        }
        
        // 酸化水非使用
        if (tmpTargetObj.estimate.NotUse_Oxygenated_Water__c) {
            lineNo += 1;
            tmpTargetObj.addOxyDiscount(lineNo, targetObjForSum.assetInfoList);
            targetObjForSum.addOxyDiscount(lineNo, targetObjForSum.assetInfoList);
            if (cnt == this.rowSize) {
                cnt = 0;
                targetObjList.add(tmpTargetObj);
                tmpTargetObj = new EstimateInfo(mceList);
            }
            cnt++;
        }
        
        // 遡るIdx、端数処理金額をどんなページに置くかを制御
        Integer backIdx = this.calcBackIdx(cnt);
        // 遡るIdx、端数処理金額をどんな行に置くかを制御
        Integer backDetailIdx = this.calcBackDetailIdx(cnt);
        
        // 定期点検
        //lineNo += 1;
        //tmpTargetObj.addExaminationPrice(lineNo, tmpTargetObj.estimate);
        //targetObjForSum.addExaminationPrice(lineNo, tmpTargetObj.estimate);
        
        targetObjList.add(tmpTargetObj);
        
        // 会計年度計算、ただしここは 日本の年度ではない
//        Integer y = this.targetObj.estimate.Contract_Esti_Start_Date__c.year();
//        Integer m = this.targetObj.estimate.Contract_Esti_Start_Date__c.month();
        Integer y = this.targetObj.estimate.Contract_Start_Date__c.year();
        Integer m = this.targetObj.estimate.Contract_Start_Date__c.month();
        if (m >= 4) {
            this.year = y;
        } else {
            this.year = y;  // y - 1;
        }
        
        // 合計金額との端数処理の場合、修理金額を無視
        // 実際金額との端数処理の場合、修理金額を含む(実際=合計+修理-优惠)
        Boolean countRepair = false;
        Decimal finalPrice = 0;
        // listpriceと実際金額の差額対応,端数処理
        if (!this.targetObj.estimate.Print_SumPrice__c && this.targetObj.estimate.Print_MaintePrice__c) {
            //this.targetObj.estimate.Examination_Price__c = (this.targetObj.estimate.Examination_Price__c * (1 - this.targetObj.estimate.Discount_Percentage__c / 100)).setScale(2, RoundingMode.HALF_UP);
            // listpriceと実際金額の差額対応
//            finalPrice = this.targetObj.estimate.Maintenance_Price__c - this.targetObj.estimate.Examination_Price__c;
            finalPrice = this.targetObj.estimate.Request_quotation_Amount__c;
            countRepair = true;
        }
        // listpriceと合計金額の差額対応,端数処理
        else {
//            finalPrice = this.targetObj.estimate.Estimate_Trial_Money__c - this.targetObj.estimate.Examination_Price__c;
            finalPrice = this.targetObj.estimate.Request_quotation_Amount__c;
        }
        
        Decimal tmpPrice = 0;
        for (Integer i = 0; i < targetObjForSum.assetInfoList.size(); i++) {
            tmpPrice += targetObjForSum.assetInfoList[i].listPrice != null ? targetObjForSum.assetInfoList[i].listPrice : 0;
            if (countRepair) {
                if (targetObjForSum.assetInfoList[i].repairPrice != null) {
                    tmpPrice += targetObjForSum.assetInfoList[i].repairPrice;
                }
            }
system.debug('tmpPrice:::' + tmpPrice);
        }
system.debug('finalPrice:::' + finalPrice);
system.debug('targetObjList.size():::' + targetObjList.size());
system.debug('backIdx:::' + backIdx);
system.debug('backDetailIdx:::' + backDetailIdx);
        if (finalPrice - tmpPrice != 0) {
            // targetObjList.size()=ページ数 
            if (targetObjList.size() - 1 - backIdx >= 0) {
                // assetSize=ページ内の明細行数
                Integer assetSize = targetObjList[targetObjList.size() - 1 - backIdx].assetInfoList.size();
                if (assetSize - 1 - backDetailIdx >= 0) {
                    targetObjList[targetObjList.size() - 1 - backIdx].assetInfoList[assetSize - 1 - backDetailIdx].listPrice += finalPrice - tmpPrice;
                }
            }
        }
        if (lastDate > estimateendDate) {
            estimateendDate = lastDate;
        }
        
        
    }
    
    /**
    * 遡るIdx計算
    */
    private Integer calcBackIdx(Integer cnt) {
        // 定期点検行の前ちょうどに改ページ
        if (cnt == 1) {
            // 最後ページは明細がない、誤差補正金額を前ページの明細に加算
            return 1;
        } else {
            // 最後ページは明細があり、誤差補正金額をこのページの明細に加算
            return 0;
        }
    }
    
    /**
    * 遡るIdx計算
    */
    private Integer calcBackDetailIdx(Integer cnt) {
        // 定期点検行の前ちょうどに改ページ
        if (cnt == 1) {
            // 最後ページは定期点検しかない、誤差補正金額を前ページの最後行に加算
            return 0;
        } else {
            // 最後ページは明細があり、誤差補正金額をこのページの定期点検行の上に加算
            return 1;
        }
    }
 
    /**
     * 印刷するデータを格納するオブジェクを定義する、親
     */
    public class EstimateInfo {
        public Maintenance_Contract_Estimate__c estimate {get; private set;}
        public String createdDate {get; private set;}
        // 有效期(即报价截止日)
        // public Date expiringDate {get; private set;}
        public List<AssetInfo> assetInfoList {get; private set;}
        
        public EstimateInfo(List<Maintenance_Contract_Estimate__c> estimateList) {
            if (estimateList.size() > 0) {
                this.estimate = estimateList[0];
                this.createdDate = estimateList[0].CreatedDate.format('yyyy/MM/dd');
                this.assetInfoList = new List<AssetInfo>();
            // if (estimateList[0].Submit_quotation_day__c != null) {
            //      this.expiringDate = estimateList[0].Submit_quotation_day__c.addMonths(+3);
            //      system.debug('报价提出日+3个月:'+this.expiringDate);
            //     }  
 
               
            }
        }
        
        public void addAssetInfo(Integer lno, Maintenance_Contract_Asset_Estimate__c mcae, String printName) {
            this.assetInfoList.add(new AssetInfo(lno, mcae, estimate, printName));
        }
        
        public Boolean addNewDiscountLine(Integer lno, List<AssetInfo> tmpAssetInfoList) {
            AssetInfo tmpNewDiscount = new AssetInfo(lno);
            tmpNewDiscount.assetModelNo = '新品优惠';
            tmpNewDiscount.assetName = '新品优惠';
            tmpNewDiscount.assetSerialNumber = '-';
            tmpNewDiscount.installDate = '-';
            tmpNewDiscount.quantity = null;
            for (AssetInfo ai : tmpAssetInfoList) {
                tmpNewDiscount.listPrice -= ai.newDiscount;
            }
            if (tmpNewDiscount.listPrice < 0) {
                assetInfoList.add(tmpNewDiscount);
                return true;
            }
            return false;
        }
        
        public void addOxyDiscount(Integer lno, List<AssetInfo> tmpAssetInfoList) {
            AssetInfo tmpOxyDiscount = new AssetInfo(lno);
            tmpOxyDiscount.assetModelNo = '酸化水';
            tmpOxyDiscount.assetName = '酸化水';
            tmpOxyDiscount.assetSerialNumber = '-';
            tmpOxyDiscount.installDate = '-';
            tmpOxyDiscount.quantity = null;
            
            Decimal tmpPrice = 0;
            // 消毒液折扣=(定价-新品折扣)*0.1 
            for (AssetInfo ai : tmpAssetInfoList) {
                // 新品优惠を追加した場合、新品优惠行をスキップ
                if (ai.assetName != '新品优惠') {
                    system.debug(ai.listPrice);
                    system.debug(ai.newDiscount);
                    tmpPrice += ai.listPrice - ai.newDiscount;
                    system.debug(tmpPrice);
                }
            }
            tmpOxyDiscount.listPrice -= tmpPrice * 0.1;
            assetInfoList.add(tmpOxyDiscount);
        }
        
//         public void addExaminationPrice(Integer lno, Maintenance_Contract_Estimate__c mce) {
//             AssetInfo tmpCheckPrice = new AssetInfo(lno);
//             tmpCheckPrice.assetModelNo = '定期点检';
//             tmpCheckPrice.assetName = '定期点检';
//             tmpCheckPrice.assetSerialNumber = '-';
//             tmpCheckPrice.installDate = '-';
//             tmpCheckPrice.quantity = Integer.valueOf(mce.Service_contract_target_number__c);
//             tmpCheckPrice.listPrice = null;
// //            tmpCheckPrice.listPrice = mce.Examination_Price__c;
// //            if (!mce.Print_SumPrice__c && mce.Print_MaintePrice__c) {
// //                tmpCheckPrice.listPrice = (mce.Examination_Price__c * (1 - mce.Discount_Percentage__c / 100)).setScale(2, RoundingMode.HALF_UP);
// //            }
//             assetInfoList.add(tmpCheckPrice);
//         }
    }
 
    /**
     * 印刷するデータを格納するオブジェクを定義する、子供
     */
    public class AssetInfo {
        public Integer lineNo {get; private set;}
        public Maintenance_Contract_Asset_Estimate__c mcae {get; private set;}
        public Decimal listPrice {get; private set;}
        public Decimal repairPrice {get; private set;}
        public Decimal newDiscount {get; private set;}
        public String assetModelNo {get; private set;}
        public String assetName {get; private set;}
        public String assetSerialNumber {get; private set;}
        public Integer quantity {get; private set;}
        public String installDate {get; private set;}
        
        public AssetInfo(Integer lineNo) {
            this.lineNo = lineNo;
            this.listPrice = 0.0;
            this.repairPrice = 0.0;
            this.newDiscount = 0.0;
            this.mcae = null;
        }
        
        public AssetInfo(Integer lineNo, Maintenance_Contract_Asset_Estimate__c mcae, Maintenance_Contract_Estimate__c estimate, String printName) {
            this.lineNo = lineNo;
            this.mcae = mcae;
            this.listPrice = 0.0;
            this.newDiscount = 0.0;
            this.repairPrice = 0.0;
            this.quantity = 1;
            
            Decimal month = estimate.Contract_Range__c;
            if (month > 12) {
                month = 12;
            }
            
            if (mcae.Asset__c != null) {
                // Assetある
                if (printName == null) {
                    this.assetName = mcae.Asset__r.Name;
                } else {
                    this.assetName = printName;
                }
                this.assetSerialNumber = mcae.Asset__r.SerialNumber;
                this.listPrice = estimate.Contract_Range__c * mcae.Estimate_List_Price__c;
                this.installDate = mcae.Asset__r.InstallDate != null ? String.valueOf(mcae.Asset__r.InstallDate).replace('-', '/') : '';
                if (mcae.IsNew__c) {
                    this.listPrice = estimate.Contract_Range__c * mcae.Maintenance_Price_Month__c;
//                    this.newDiscount = estimate.Contract_Range__c * (mcae.Maintenance_Price_Month__c - mcae.Estimate_List_Price__c);
                    this.newDiscount = month * (mcae.Maintenance_Price_Month__c - mcae.Estimate_List_Price__c);
                }
            } else if (mcae.Product_Manual__c != null) {
                // 手入力
                if (printName == null) {
                    this.assetName = mcae.Product_Manual__r.Name;
                } else {
                    this.assetName = printName;
                }
                this.assetSerialNumber = '新购入';
                this.installDate = '新购入';
                this.listPrice = estimate.Contract_Range__c * mcae.Product_Manual__r.Maintenance_Price_Month__c;
//                this.newDiscount = estimate.Contract_Range__c * (mcae.Product_Manual__r.Maintenance_Price_Month__c - mcae.Estimate_List_Price__c);
                this.newDiscount = month * (mcae.Product_Manual__r.Maintenance_Price_Month__c - mcae.Estimate_List_Price__c);
            } else {}
            
            if (mcae.Repair_Price__c != null) {
                this.repairPrice = mcae.Repair_Price__c;
            }
            
            // 合計金額出さずに実際金額を出す場合、値引きで表示、四捨五入
            if (!estimate.Print_SumPrice__c && estimate.Print_MaintePrice__c) {
                this.listPrice = (this.listPrice * (1 - estimate.Discount_Percentage__c / 100)).setScale(2, RoundingMode.HALF_UP);
                this.newDiscount = (this.newDiscount * (1 - estimate.Discount_Percentage__c / 100)).setScale(2, RoundingMode.HALF_UP);
            }
            
            // 名前 ':' の対応
            this.assetName = assetName == null ? '' : assetName;
            if (this.assetName.indexOf(':') >= 0) {
                this.assetModelNo = this.assetName.subString(0, this.assetName.indexOf(':'));
                this.assetName = this.assetName.subString(this.assetName.indexOf(':')+1);
            } else if (this.assetName.indexOf(':') >= 0) {
                this.assetModelNo = this.assetName.subString(0, this.assetName.indexOf(':'));
                this.assetName = this.assetName.subString(this.assetName.indexOf(':')+1);
            } else {
                this.assetModelNo = '';
            }
        }
    }
}