source: branches/version-2_4/data/class/SC_Fpdf.php @ 18102

Revision 18102, 14.5 KB checked in by kajiwara, 15 years ago (diff)

#466 ロゴの表示が乱れる問題を修正

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/*----------------------------------------------------------------------
25 * [名称] SC_Fpdf
26 * [概要] pdfファイルを表示する。
27 *----------------------------------------------------------------------
28 */
29
30require(DATA_PATH . 'pdf/japanese.php');
31define('PDF_TEMPLATE_DIR', DATA_PATH . 'pdf/');
32define('PDF_IMG_DIR', HTML_PATH. USER_DIR. USER_PACKAGE_DIR. TEMPLATE_NAME. '/img/pdf/');
33
34class SC_Fpdf {
35    function SC_Fpdf($download, $title, $tpl_pdf = "template_nouhin01.pdf") {
36        $this->arrData = $arrData;
37        // デフォルトの設定
38        $this->tpl_pdf = PDF_TEMPLATE_DIR . $tpl_pdf;  // テンプレートファイル
39        $this->pdf_download = $download;      // PDFのダウンロード形式(0:表示、1:ダウンロード)
40        $this->tpl_title = $title;
41        $this->tpl_dispmode = "real";      // 表示モード
42        $masterData = new SC_DB_MasterData_Ex();
43        $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
44        $this->width_cell = array(110.3,12,21.7,24.5);
45
46        $this->label_cell[] = $this->sjis_conv("商品名 / 商品コード / [ 規格 ]");
47        $this->label_cell[] = $this->sjis_conv("数量");
48        $this->label_cell[] = $this->sjis_conv("単価");
49        $this->label_cell[] = $this->sjis_conv("金額(税込)");
50
51        $this->arrMessage = array(
52          'このたびはお買上げいただきありがとうございます。',
53          '下記の内容にて納品させていただきます。',
54          'ご確認いただきますよう、お願いいたします。'
55        );
56
57        $this->pdf  = new PDF_Japanese();
58
59        // SJISフォント
60        $this->pdf->AddSJISFont();
61
62        //ページ総数取得
63        $this->pdf->AliasNbPages();
64
65        // マージン設定
66        $this->pdf->SetMargins(15, 20);
67
68        // PDFを読み込んでページ数を取得
69        $pageno = $this->pdf->setSourceFile($this->tpl_pdf);
70    }
71
72
73    function setData($arrData) {
74        $this->arrData = $arrData;
75
76        // ページ番号よりIDを取得
77        $tplidx = $this->pdf->ImportPage(1);
78
79        // ページを追加(新規)
80        $this->pdf->AddPage();
81
82        //表示倍率(100%)
83        $this->pdf->SetDisplayMode($this->tpl_dispmode);
84
85        if(SC_Utils_Ex::sfIsInt($arrData['order_id'])) {
86          $this->disp_mode = true;
87          $order_id = $arrData['order_id'];
88        }
89
90        // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト
91        $this->pdf->useTemplate($tplidx);
92
93        $this->setShopData();
94        $this->setMessageData();
95        $this->setOrderData();
96        $this->setEtcData();
97
98    }
99
100    function setShopData() {
101        // ショップ情報
102
103        $objInfo = new SC_SiteInfo();
104        $arrInfo = $objInfo->data;
105
106        $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');          //ショップ名
107        $this->lfText(125, 63, $arrInfo['law_url'], 8);          //URL
108        $this->lfText(125, 68, $arrInfo['law_company'], 8);        //会社名
109        $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02'];
110        $this->lfText(125, 71, $text, 8);  //郵便番号
111        $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01'];
112        $this->lfText(125, 74, $text, 8);  //都道府県+住所1
113        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);          //住所2
114
115        $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03'];
116        if ( strlen($arrInfo['law_fax01']) > 0 && strlen($arrInfo['law_fax02']) > 0 && strlen($arrInfo['law_fax03']) > 0 ) {
117            $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03'];
118        }
119        $this->lfText(125, 80, $text, 8);  //TEL・FAX
120
121        if ( strlen($arrInfo['law_email']) > 0 ) {
122            $text = "Email: ".$arrInfo['law_email'];
123            $this->lfText(125, 83, $text, 8);      //Email
124        }
125
126        //ロゴ画像
127        $logo_file = PDF_TEMPLATE_DIR . 'logo.png';
128        $this->pdf->Image($logo_file, 124, 46, 40);
129    }
130
131    function setMessageData() {
132        // メッセージ
133        $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
134        $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
135        $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
136        $text = "作成日: ".$this->arrData['year']."年".$this->arrData['month']."月".$this->arrData['day']."日";
137        $this->lfText(158, 288, $text, 8);  //作成日
138    }
139
140    function setOrderData() {
141        // ショップ情報
142        $objInfo = new SC_SiteInfo();
143        $arrInfo = $objInfo->data;
144        // DBから受注情報を読み込む
145        $this->lfGetOrderData($this->arrData['order_id']);
146
147        // 購入者情報
148        $text = "〒 ".$this->arrDisp['order_zip01']." - ".$this->arrDisp['order_zip02'];
149        $this->lfText(23, 43, $text, 10); //購入者郵便番号
150        $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
151        $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
152        $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
153        $text = $this->arrDisp['order_name01']." ".$this->arrDisp['order_name02']." 様";
154        $this->lfText(27, 59, $text, 11); //購入者氏名
155
156        // お届け先情報
157        $this->pdf->SetFont('SJIS', '', 10);
158        $text = "〒 ".$this->arrDisp['deliv_zip01']." - ".$this->arrDisp['deliv_zip02'];
159        $this->lfText(22, 128, $text, 10); //お届け先郵便番号
160        $text = $this->arrPref[$this->arrDisp['deliv_pref']] . $this->arrDisp['deliv_addr01'];
161        $this->lfText(26, 132, $text, 10); //お届け先都道府県+住所1
162        $this->lfText(26, 136, $this->arrDisp['deliv_addr02'], 10); //お届け先住所2
163        $text = $this->arrDisp['deliv_name01']." ".$this->arrDisp['deliv_name02']." 様";
164        $this->lfText(26, 140, $text, 10); //お届け先氏名
165
166        $this->lfText(144, 121, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
167        $this->lfText(144, 131, $this->arrDisp['order_id'], 10); //注文番号
168
169        $this->pdf->SetFont('SJIS', 'B', 15);
170        $this->pdf->Cell(0, 10, $this->sjis_conv($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
171        $this->pdf->Cell(0, 66, '', 0, 2, 'R', 0, '');
172        $this->pdf->Cell(5, 0, '', 0, 0, 'R', 0, '');
173        $this->pdf->Cell(67, 8, $this->sjis_conv(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, '');
174        $this->pdf->Cell(0, 45, '', 0, 2, '', 0, '');
175
176        $this->pdf->SetFont('SJIS', '', 8);
177
178        $monetary_unit = $this->sjis_conv("円");
179        $point_unit = $this->sjis_conv("pt");
180
181        // 購入商品情報
182        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
183
184          // 購入数量
185          $data[0] = $this->arrDisp['quantity'][$i];
186
187          // 税込金額(単価)
188          $data[1] = SC_Utils_Ex::sfPreTax($this->arrDisp['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']);
189
190          // 小計(商品毎)
191          $data[2] = $data[0] * $data[1];
192
193          $arrOrder[$i][0]  = $this->sjis_conv($this->arrDisp['product_name'][$i]." / ");
194          $arrOrder[$i][0] .= $this->sjis_conv($this->arrDisp['product_code'][$i]." / ");
195          if($this->arrDisp['classcategory_name1'][$i]) {
196            $arrOrder[$i][0] .= $this->sjis_conv(" [ ".$this->arrDisp['classcategory_name1'][$i]);
197            if($this->arrDisp['classcategory_name2'][$i] == "") {
198              $arrOrder[$i][0] .= " ]";
199            } else {
200              $arrOrder[$i][0] .= $this->sjis_conv(" * ".$this->arrDisp['classcategory_name2'][$i]." ]");
201            }
202          }
203          $arrOrder[$i][1]  = number_format($data[0]);
204          $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
205          $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
206
207        }
208
209        $arrOrder[$i][0] = "";
210        $arrOrder[$i][1] = "";
211        $arrOrder[$i][2] = "";
212        $arrOrder[$i][3] = "";
213
214        $i++;
215        $arrOrder[$i][0] = "";
216        $arrOrder[$i][1] = "";
217        $arrOrder[$i][2] = $this->sjis_conv("商品合計");
218        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
219
220        $i++;
221        $arrOrder[$i][0] = "";
222        $arrOrder[$i][1] = "";
223        $arrOrder[$i][2] = $this->sjis_conv("送料");
224        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
225
226        $i++;
227        $arrOrder[$i][0] = "";
228        $arrOrder[$i][1] = "";
229        $arrOrder[$i][2] = $this->sjis_conv("手数料");
230        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
231
232        $i++;
233        $arrOrder[$i][0] = "";
234        $arrOrder[$i][1] = "";
235        $arrOrder[$i][2] = $this->sjis_conv("値引き");
236        $arrOrder[$i][3] = "- ".number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
237
238        $i++;
239        $arrOrder[$i][0] = "";
240        $arrOrder[$i][1] = "";
241        $arrOrder[$i][2] = $this->sjis_conv("請求金額");
242        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
243
244        $i++;
245        $arrOrder[$i][0] = "";
246        $arrOrder[$i][1] = "";
247        $arrOrder[$i][2] = "";
248        $arrOrder[$i][3] = "";
249
250        // ポイント表記
251        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
252          $i++;
253          $arrOrder[$i][0] = "";
254          $arrOrder[$i][1] = "";
255          $arrOrder[$i][2] = $this->sjis_conv("利用ポイント");
256          $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
257
258          $i++;
259          $arrOrder[$i][0] = "";
260          $arrOrder[$i][1] = "";
261          $arrOrder[$i][2] = $this->sjis_conv("加算ポイント");
262          $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
263
264          $i++;
265          $arrOrder[$i][0] = "";
266          $arrOrder[$i][1] = "";
267          $arrOrder[$i][2] = $this->sjis_conv("所有ポイント");
268          $arrOrder[$i][3] = number_format($this->arrDisp['point']).$point_unit;
269        }
270
271        $this->pdf->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
272    }
273
274    function setEtcData() {
275        $this->pdf->Cell(0, 10, '', 0, 1, 'C', 0, '');
276        $this->pdf->SetFont('SJIS', '', 9);
277        $this->pdf->MultiCell(0, 6, $this->sjis_conv("< 備 考 >"), 'T', 2, 'L', 0, '');  //備考
278        $this->pdf->Ln();
279        $this->pdf->SetFont('SJIS', '', 8);
280        $this->pdf->MultiCell(0, 4, $this->sjis_conv($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
281    }
282
283    function createPdf() {
284        // PDFをブラウザに送信
285ob_clean();
286        if ($this->pdf->PageNo() == 1) {
287            $filename = "nouhinsyo-No".$this->arrData['order_id'].".pdf";
288          } else {
289            $filename = "nouhinsyo.pdf";
290          }
291          $this->pdf->Output($this->sjis_conv($filename), D);
292
293        // 入力してPDFファイルを閉じる
294        $this->pdf->Close();
295    }
296
297    // PDF_Japanese::Text へのパーサー
298    function lfText($x, $y, $text, $size, $style = '') {
299        $text = mb_convert_encoding($text, "SJIS", CHAR_CODE);
300
301        $this->pdf->SetFont('SJIS', $style, $size);
302        $this->pdf->Text($x, $y, $text);
303    }
304
305
306    // 受注データの取得
307    function lfGetOrderData($order_id) {
308        if(SC_Utils_Ex::sfIsInt($order_id)) {
309            // DBから受注情報を読み込む
310            $objQuery = new SC_Query();
311            $where = "order_id = ?";
312            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
313            #$objFormParam->setParam($arrRet[0]);
314            list($point, $total_point) = SC_Helper_DB_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
315            #$objFormParam->setValue('total_point', $total_point);
316            #$objFormParam->setValue('point', $point);
317            $arrRet[0]['total_point'] = $total_point;
318            $arrRet[0]['point'] = $point;
319            $this->arrDisp = $arrRet[0];
320
321            // 受注詳細データの取得
322            $arrRet = $this->lfGetOrderDetail($order_id);
323            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
324            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
325            #$objFormParam->setParam($arrRet);
326
327            // その他支払い情報を表示
328            if($this->arrDisp["memo02"] != "") $this->arrDisp["payment_info"] = unserialize($this->arrDisp["memo02"]);
329            if($this->arrDisp["memo01"] == PAYMENT_CREDIT_ID){
330                  $this->arrDisp["payment_type"] = "クレジット決済";
331            } elseif ($this->arrDisp["memo01"] == PAYMENT_CONVENIENCE_ID) {
332                  $this->arrDisp["payment_type"] = "コンビニ決済";
333            } else {
334                  $this->arrDisp["payment_type"] = "お支払い";
335            }
336        }
337    }
338
339    // 受注詳細データの取得
340    function lfGetOrderDetail($order_id) {
341      $objQuery = new SC_Query();
342      $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
343      $where = "order_id = ?";
344      $objQuery->setorder("classcategory_id1, classcategory_id2");
345      $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
346      return $arrRet;
347    }
348
349    // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJISのみ
350    function sjis_conv($conv_str) {
351      return (mb_convert_encoding($conv_str, "SJIS", CHAR_CODE));
352    }
353
354
355}
356?>
Note: See TracBrowser for help on using the repository browser.