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
/**
@description 收货清单明细生成PDF
*/
public without sharing class ReceivingNotePDFController {
 
    private final static Integer LINE_COUNT_PER_PAGE = 13; //每页13条明细
    private String receivingNoteId;
    public List<PDFPage> pages { get; set; } // 所有PDF页的内容
    public Integer pageCnt { get; set; }
    public ReceivingNote__c receivingNoteHeadShow { get; set; }
    public String errorMessage{get;set;}
 
    public ReceivingNotePDFController() {
        receivingNoteId = ApexPages.currentPage().getParameters().get('rnid');
        receivingNoteHeadShow = new ReceivingNote__c();
        pages = new List<PDFPage>();
    }
 
    /**
    @description 收货单PDF画面初始化
    */
    public void init() {
        List<ReceivingNote__c> receivingNoteList = new List<ReceivingNote__c>();
        if(receivingNoteId!=null){
            receivingNoteList = [
                    SELECT Sales_order_number__c      //合同编码字段
                         , OrderCode__c              //订单编码
                         , ApprovalNumber__c          //采购申请决裁号
                         , DateOfDelivery__c          //发货日
                         , Internal_asset_location__c //备品存放地
                         //20210312 you WLIG-BV8CHF start
                        //, ReceivingNoteNo__c //清单编号
                        , ReceivingNoteNo_New__c
                        //20210312 you WLIG-BV8CHF end
                         , QRId__c                     //二维码
                      FROM ReceivingNote__c
                     WHERE Id = :receivingNoteId
                ];
        }
 
        if(receivingNoteList.size()>0){
            receivingNoteHeadShow = receivingNoteList[0];
        }
        else{
            errorMessage = '收货清单Id不存在';
            return;
        }
 
        List<ReceivingNoteDetail__c> rndList = new List<ReceivingNoteDetail__c>();
 
        rndList = [
                SELECT ReceivingNoteDetailNo__c
                     , OT_CODE__c
                     , Fixture_Model_No_F__c
                     , Fixture_Model_Name_F__c
                     , Internal_Asset_number_key__c
                     , SerialNumber_F__c
                     , PeriodOfUse__c
                     , Packing_list_Fixture_F__c
                     , EquipmentSet_Managment_Code__c
                     , Salesdepartment__c
                     , SalesProvince__c
                     , Product_category__c
                     , Equipment_Type__c
                     , Manage_type__c
                     , unknow_serial_NO_product__c
                     , Asset_loaner_category_F__c
                     , Loaner_accsessary__c
                     , RND_Status__c
 
                  FROM ReceivingNoteDetail__c
                 WHERE ReceivingNoteSummary__r.ReceivingNote__c = :receivingNoteId
                   AND Delete_Flag__c = false
                   AND Change_Point__c != '删除'
                 ORDER BY ReceivingNoteSummary__c, Name ASC NULLS LAST
                ];
 
        // 用行数算出页数
        Integer pageCount = rndList.size() / LINE_COUNT_PER_PAGE;
        if (Math.mod(rndList.size(), LINE_COUNT_PER_PAGE) > 0) {
            pageCount += 1;
        }
 
        //新建一页
        PDFPage pdfPage = new PDFPage();
 
        for (Integer i = 0; i < pageCount * LINE_COUNT_PER_PAGE; i++) {
            // 有明细则用明细,没明细则用空行填满页面
            if ( i < rndList.size()) {
                pdfPage.lineList.add(rndList[i]);
            } else {
                pdfPage.lineList.add(new ReceivingNoteDetail__c());
            }
 
            // 装满一页 ,则新造一页
            if (pdfPage.lineList.size() >= LINE_COUNT_PER_PAGE) {
                pages.add(pdfPage);
                pdfPage = new PDFPage();
            }
        }
 
        pageCnt = pages.size();
 
    }
 
    /**
    @description 一页pdf上的内容
    */
    public class PDFPage {
        public List<ReceivingNoteDetail__c> lineList { get; private set; }
        /**
        @description
        */
        public PDFPage() {
            lineList = new List<ReceivingNoteDetail__c>();
        }
    }
 
}