GWY
2022-05-16 a9baff8a4508c1850e650f68831d857b953eace4
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
<apex:page Controller="QuotePDFController" showHeader="false" sidebar="false" id="allPage" action="{!init}" >
    <!-- <apex:page Controller="QuotePDFController" showHeader="false" sidebar="false" id="allPage" action="{!init}" renderAs="pdf"> -->
<head>
    <style>
        @page {
            size: A4;
            margin: 1mm 1mm 1mm 1mm;
        }
    </style>
</head>
<body style="font-family: Arial Unicode MS; page-break-inside: auto">
    <div id="pdf-wrapper">
        <div class="pdf-page">
            <table border="0" width="100%" style="border-collapse: collapse;">
                <tr>
                    <td style="text-align:right;">{!quoteInfo.quoteDate}</td>
                </tr>
                <tr>
                    <td style="text-align:right;">{!$ObjectType.Quote.label}#{!quoteInfo.quoteNo}</td>
                </tr>
                <tr>
                    <td style="text-align:right;">{!$Label.Label_Total_pages}:{!pageCnt}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$Label.Label_From}:{!quoteInfo.dealerName}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$ObjectType.Contact.label}:<span id="dealerContactName">{!quoteInfo.dealerContactName}</span>&nbsp;&nbsp;&nbsp;&nbsp;{!$ObjectType.Contact.fields.MobilePhone.label}:<span>{!quoteInfo.dealerContactPhone}</span></td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$ObjectType.Account.fields.Address1__c.label}:{!quoteInfo.dealerAddress}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$ObjectType.Contact.fields.Phone.label}:{!quoteInfo.dealerPhone}&nbsp;&nbsp;&nbsp;&nbsp;{!$ObjectType.Contact.fields.Fax.label}:{!quoteInfo.dealerFax}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$ObjectType.Contact.fields.Email.label}:{!quoteInfo.dealerEmail}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">&nbsp;</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$Label.Label_To}:{!quoteInfo.accountName}</td>
                </tr>
                <tr>
                    <td style="text-align:left;" id="accountContactName">{!quoteInfo.accountContactName}</td>
                </tr>
                <tr>
                    <td style="text-align:left;">{!$ObjectType.Contact.fields.Phone.label}:<span id="accountContactPhone">{!quoteInfo.accountContactPhone}</span>&nbsp;&nbsp;&nbsp;&nbsp;{!$ObjectType.Contact.fields.Email.label}:<span id="accountContactEmail">{!quoteInfo.accountContactEmail}</span></td>
                </tr>
            </table>
        
            <br/>
            Quotation Sheet(Quotation #{!quoteInfo.quoteNo})<br/>
        
            <table border="1" width="100%" style="border-collapse: collapse;table-layout: fixed;">
                <colgroup>
                    <col width="10%" />
                    <col width="60%" />
                    <col width="10%" />
                    <col width="20%" />
                </colgroup>
                <tr style="text-align: center;">
                    <th>{!$Label.Label_Units}</th>
                    <th>{!$Label.Label_Description}</th>
                    <th>{!$ObjectType.QuoteLineItem.fields.Quantity.label}</th>
                    <th>{!$ObjectType.QuoteLineItem.fields.TotalPrice.label}{!currencyIsoCode}</th>
                </tr>
                <apex:repeat value="{!printRecords}" var="set">
                <tr>
                    <td style="text-align: center;"><apex:outputText value="{!set.units}" /></td>
                    <td><apex:outputText value="{!set.description}" /></td>
                    <td style="text-align: right;"><apex:outputText value="{!set.qty}" /></td>
                    <td style="text-align: right;"><apex:outputText value="{!set.total}" /></td>
                </tr>
                </apex:repeat>
            </table>
        
            <br/>
        
            Note:<br/>
        <!--     1)  The payment terms are {!quoteInfo.note1} .<br/>
            付款方式 {!quoteInfo.note2} 。<br/>
            2)  Quoation valid until {!quoteInfo.note3} .<br/>
            报价有效期到 {!quoteInfo.note3} 。<br/>
            3)  All the commodoties come with {!quoteInfo.note4} year's manufacturer warranty.<br/>
            所有商品含 {!quoteInfo.note4} 年厂家保修。<br/>
            4)  The above quotations are {!quoteInfo.note5} prices, Commodoties shipped to the clien's requirements.<br/>
            上述报价为 {!quoteInfo.note5} 价,商品送至客户指定地点。<br/>
            5)  The above quotations are all {!quoteInfo.note6}.<br/>
            上述报价均为 {!quoteInfo.note7} 价。<br/>
            6)  Configuration as per attached.<br/>
            配置清单详见附件。<br/> -->
            <apex:outputText value="{!quoteInfo.comment}" escape="false"/>
        <!--     1)  The above quotations are CIP prices, Commodities shipped to the client’s requirements.<br/>
            2)  The above quotations are all tax {!quoteInfo.note2}.<br/>
            3)  The payment terms are {!quoteInfo.note3}.<br/>
            4)  Quotation valid until {!quoteInfo.note4}.<br/>
            5)  All the commodities come with {!quoteInfo.note5} year’s manufacturer warranty.<br/>
            6)  Configuration as per attached.<br/>
            7)  Delivery lead time is {!quoteInfo.note7} days after receipt of payment.<br/> -->
            
        </div>
        <apex:outputPanel rendered="{!pageCnt > 1}" layout="none">
            <div style="page-break-after: always;"/>
        </apex:outputPanel>
        
        <apex:variable value="{!1}" var="cnt1" />
        <apex:repeat value="{!printRecords}" var="set">
            <!-- <apex:variable value="{!1}" var="cnt2" /> -->
            <apex:repeat value="{!set.setPage}" var="sp">
                <div class="pdf-page">
                    <table border="1" width="100%" style="border-collapse: collapse;table-layout: fixed; font-size: 12px;">
                        <colgroup>
                            <col width="3%" />
                            <col width="10%" />
                            <col width="15%" />
                            <col width="{!IF(isPrintPrice=='true', 23, 33)}%" />
                            <col width="{!IF(isPrintPrice=='true', 20, 33)}%" />
                            <col width="5%" />
                            <apex:outputPanel rendered="{!isPrintPrice=='true'}" layout="none">
                            <col width="12%" />
                            <col width="12%" />
                            </apex:outputPanel>
                        </colgroup>
                        <!-- <apex:outputPanel rendered="{!cnt2 == 1}" layout="none"> -->
                        <tr style="text-align: center;">
                            <td colspan="{!IF(isPrintPrice=='true', 8, 6)}">{!set.description}{!$Label.Label_Set_detail}</td>
                        </tr>
                        <!-- </apex:outputPanel> -->
                        <tr style="text-align: center;">
                            <td>{!$Label.Label_No}</td>
                            <td>{!$ObjectType.Product2.fields.ProductCode.label}</td>
                            <td>{!$ObjectType.Product2.fields.Product_ECCode__c.label}</td>
                            <td>{!$ObjectType.Product2.fields.Description.label}</td>
                            <td>{!$ObjectType.QuoteLineItem.fields.Description.label}</td>
                            <td>{!$ObjectType.QuoteLineItem.fields.Quantity.label}</td>
                            <apex:outputPanel rendered="{!isPrintPrice=='true'}" layout="none">
                            <td>{!$ObjectType.QuoteLineItem.fields.UnitPrice.label}{!currencyIsoCode}</td>
                            <td>{!$ObjectType.QuoteLineItem.fields.TotalPrice.label}{!currencyIsoCode}</td>
                            </apex:outputPanel>
                        </tr>
                        <apex:repeat value="{!sp}" var="line">
                        <tr>
                            <td style="text-align: center;"><apex:outputText value="{!line.lineNo}" /></td>
                            <td><apex:outputText escape="false" value="{!line.productCode}" /></td>
                            <td><apex:outputText escape="false" value="{!line.productEC}" /></td>
                            <td><apex:outputText escape="false" value="{!line.description}" /></td>
                            <td><apex:outputText escape="false" value="{!line.comment}" /></td>
                            <td style="text-align: right;"><apex:outputText value="{!line.quantity}" /></td>
                            <apex:outputPanel rendered="{!isPrintPrice=='true'}" layout="none">
                            <td style="text-align: right;"><apex:outputText value="{!line.price}" /></td>
                            <td style="text-align: right;"><apex:outputText value="{!line.totalPrice}" /></td>
                            </apex:outputPanel>
                        </tr>
                        </apex:repeat>
                    </table>
                </div>
            
    
            <apex:outputPanel rendered="{!cnt1 < pageCnt - 1}" layout="none">
                <div style="page-break-after: always;"/>
            </apex:outputPanel>
    
            <!-- <apex:variable value="{!cnt2 + 1}" var="cnt2" /> -->
            <apex:variable value="{!cnt1 + 1}" var="cnt1" />
            </apex:repeat>
        </apex:repeat>
    </div>
</body>
<style>
    /* 20220221 PI改造 by 徐亮 start */
    body{margin: 0 auto;width: 780px;}
    .title1{height: 30px;}
    .title2{height: 110px;}
    /* 20220221 PI改造 by 徐亮 end */
</style>
<!-- 20220221 PI改造 by 徐亮 start  -->
<apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
<script src="../../soap/ajax/53.0/connection.js" type="text/javascript"></script>
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.jspdf)}"/>
<apex:includeScript value="{!URLFOR($Resource.html2canvas)}"/>
 
<!-- 20220221 PI改造 by 徐亮 end  -->
<!-- 20220221 PI改造 by 徐亮 start  -->
<script>
    AWSService.sfSessionId = '{!GETSESSIONID()}';
    sforce.connection.serverUrl = '{!$Site.Prefix}/services/Soap/u/53.0';
    var staticResourceContact = JSON.parse('{!staticResourceContact}');
    var staticResourceOpportunity = JSON.parse('{!staticResourceOpportunity}');
    var staticResourceFile = JSON.parse('{!staticResourceFile}');
    function Fun(pdf) {
 
        var form = jQuery("<form method='post'></form>");
        jQuery(document.body).append(form);
        let href = window.location.href
        let arr = href.split('/')
        form.attr({ "action": staticResourceFile.hostUrl + staticResourceFile.extraInfo + "?from=" + encodeURIComponent(href) + "&fileName=" + encodeURIComponent(arr[arr.length - 1].split('?')[0]) });
        // form.attr({"action":"http://127.0.0.1:8080/a/d?from="+encodeURIComponent(window.location.href)});
        let input = jQuery("<input type='hidden'/>");
        input.attr({ "name": "base64Str" });
        input.val(pdf.output('datauristring').substr(28));
        form.append(input);
        form.submit();
 
        // jQuery("body > *").each(function(){
        //     jQuery(this).css('display','none');
        // })
        // jQuery("body").append('<embed style="position:absolute; left: 0; top: 0;" width="100%" height="100%" src="'+pdf.output('datauristring')+'" type="application/pdf"/>')
 
    }
 
    let id = "pdf-wrapper";
    var target = document.getElementById(id);
    // 把imageDta转换成url
        // page_height:一页的高度
        function ImageDataToUrl(img_data,page_height){
            let cvs = document.createElement("CANVAS");
            cvs.width = img_data.width;
            cvs.height = page_height;
            var ctx= cvs.getContext("2d");
            ctx.fillStyle="white";
            ctx.fillRect(0,0,cvs.width,cvs.height);// 填充canvas所有区域为白色
            ctx.putImageData(img_data,0,0);
            return cvs.toDataURL('image/jpeg', 1.0);
        }
        function jsPdfDownload() {
    
            let jtargets = jQuery("#pdf-wrapper .pdf-page");
            let j_arr = new Array(jtargets.length + 1).join(0).split('').map(function () { return false });
            let landscape = false;
            let pw = 595.28;
            let ph = 841.89;
            const marginw = 40;
            const marginh = 40;
    
            let orientation = '';
            if (landscape) {
                pw += ph; ph = pw - ph; pw = pw - ph;
                orientation = 'l';
            }
            var pdf = new jsPDF(orientation, 'pt', 'a4');// 第一个参数填字母l,注意不是数字1,为横向pdf
            jtargets.each(function (i, e) {
                e.style.background = "#FFFFFF";
            })
    
            let rei = 0;
            let recursion = null;
            recursion = function (i) {
                if (i >= jtargets.length) {
                    Fun(pdf);
                    return;
                }
                e = jtargets[i];
                html2canvas(e, {
                    scale: 2,
                    onrendered: function (canvas) {
                        /**
                        本方法需要做几个事情
                        1.需要把canvas的内容分页显示到pdf的页中
                        2.canvas的宽高需要和pdf的宽高进行映射
                        3.截取到的内容需要放进一页宽高的canvas里面,并对其余区域刷白
                        */
                        var ctx = canvas.getContext("2d");
                        let canvas_max_page_num = 9;
                        let canvas_current_page_num = 0;
                        var contentWidth = canvas.width;
                        var contentHeight = canvas.height;
    
                        
                        //未生成pdf的html页面高度
                        var leftHeight = contentHeight;
                        //页面偏移
                        var position = 0;
                        
                        //a4纸的尺寸[595.28,841.89],html页面生成的canvas在pdf中图片的宽高
                        var outputWidth = pw - 2 * marginw;//595.28//左右边距20
                        let rate = outputWidth / 780;//输出宽度和内容宽度的比例
                        var outputHeight = ph - 2 * marginh;//左右边距20
                        let onePdfPageInCanvasHeight = contentWidth/outputWidth*outputHeight;//一页pdf在canvas中的高度;
                        //var pageData = canvas.toDataURL('image/jpeg', 1.0);
                        var pageData = null;
                        var imgData = null;
                        
                        var captureHeight = null;// 截取的当前canvas页的高度
                        
                        let j = i;
                        while(position < contentHeight){
                            
                            if (j++) {
                                pdf.addPage();
                            }
 
                            if(position+onePdfPageInCanvasHeight>contentHeight){
                                captureHeight = contentHeight-position;
                            }else{
                                captureHeight = onePdfPageInCanvasHeight;
                            }
    
                            imgData = ctx.getImageData(0,position,contentWidth,captureHeight);
                            pageData = ImageDataToUrl(imgData,onePdfPageInCanvasHeight);
                            pdf.addImage(pageData, 'JPEG', marginw, marginh, outputWidth, outputHeight);//左右边距20,被输出的图片会被拉伸为outputWidth,outputHeight的宽高
                            canvas_current_page_num++;
                            position += onePdfPageInCanvasHeight;
                            if (canvas_max_page_num > 0 && canvas_current_page_num >= canvas_max_page_num) {
                                break;
                            }
                        }
    
                        recursion(i + 1);
                    }
                })
            };
            recursion(rei);
    
    
    
        }
    
        //blockme();
        document.body.onload = function(){
            
            let i = 0;
            let Foo = function(){
                if ( i == 2) {
                    if(confirm("PDF已加载完毕,是否显示?")){
                        jsPdfDownload(); 
                    }
                }
            }
 
            AWSService.query(staticResourceContact.queryUrl, '{!quoteInfo.conAwsDataId}', function(data){
                //unblockUI();
                document.getElementById("accountContactName").innerHTML = data.object.lastName;
                document.getElementById("accountContactPhone").innerHTML = data.object.phone;
                document.getElementById("accountContactEmail").innerHTML = data.object.email;
                i++;
                Foo();
            }, staticResourceContact.token);
 
            AWSService.query(staticResourceOpportunity.queryUrl, '{!quoteInfo.oppAwsDataId}', function(data){
                //unblockUI();
                document.getElementById("dealerContactName").innerHTML = data.object.dealerSalesStaffName;
                i++;
                Foo();
            }, staticResourceOpportunity.token);
        }
        
        
    
</script>
<!-- 20220221 PI改造 by 徐亮 end  -->
</apex:page>