source: branches/version-2_12-dev/data/class/SC_Fpdf.php @ 21719

Revision 21719, 13.9 KB checked in by Seasoft, 12 years ago (diff)

#1431 (用語の揺れ)

  • 所在地

#1613 (typo修正・ソース整形・ソースコメントの改善)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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_REALDIR . 'module/fpdf/fpdf.php';
31require DATA_REALDIR . 'module/fpdi/japanese.php';
32define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/');
33
34class SC_Fpdf extends PDF_Japanese {
35    function SC_Fpdf($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') {
36        $this->FPDF();
37        // デフォルトの設定
38        $this->tpl_pdf = PDF_TEMPLATE_REALDIR . $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');
44        $this->width_cell = array(110.3,12,21.7,24.5);
45
46        $this->label_cell[] = $this->lfConvSjis('商品名 / 商品コード / [ 規格 ]');
47        $this->label_cell[] = $this->lfConvSjis('数量');
48        $this->label_cell[] = $this->lfConvSjis('単価');
49        $this->label_cell[] = $this->lfConvSjis('金額(税込)');
50
51        $this->arrMessage = array(
52            'このたびはお買上げいただきありがとうございます。',
53            '下記の内容にて納品させていただきます。',
54            'ご確認くださいますよう、お願いいたします。'
55        );
56
57        $this->lfAddGothicFont();
58
59        // SJISフォント
60        $this->AddSJISFont();
61        $this->SetFont('SJIS');
62
63        //ページ総数取得
64        $this->AliasNbPages();
65
66        // マージン設定
67        $this->SetMargins(15, 20);
68
69        // PDFを読み込んでページ数を取得
70        $pageno = $this->setSourceFile($this->tpl_pdf);
71    }
72
73    function setData($arrData) {
74        $this->arrData = $arrData;
75
76        // ページ番号よりIDを取得
77        $tplidx = $this->ImportPage(1);
78
79        // ページを追加(新規)
80        $this->AddPage();
81
82        //表示倍率(100%)
83        $this->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->useTemplate($tplidx);
92
93        $this->setShopData();
94        $this->setMessageData();
95        $this->setOrderData();
96        $this->setEtcData();
97
98    }
99
100    function setShopData() {
101        // ショップ情報
102
103        $objDb = new SC_Helper_DB_Ex();
104        $arrInfo = $objDb->sfGetBasisData();
105
106        // ショップ名
107        $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');
108        // URL
109        $this->lfText(125, 63, $arrInfo['law_url'], 8);
110        // 会社名
111        $this->lfText(125, 68, $arrInfo['law_company'], 8);
112        // 郵便番号
113        $text = '〒 ' . $arrInfo['law_zip01'] . ' - ' . $arrInfo['law_zip02'];
114        $this->lfText(125, 71, $text, 8);
115        // 都道府県+所在地
116        $text = $this->arrPref[$arrInfo['law_pref']] . $arrInfo['law_addr01'];
117        $this->lfText(125, 74, $text, 8);
118        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);
119
120        $text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03'];
121        //FAX番号が存在する場合、表示する
122        if (strlen($arrInfo['law_fax01']) > 0) {
123            $text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03'];
124        }
125        $this->lfText(125, 80, $text, 8);  //TEL・FAX
126
127        if (strlen($arrInfo['law_email']) > 0) {
128            $text = 'Email: '.$arrInfo['law_email'];
129            $this->lfText(125, 83, $text, 8);      //Email
130        }
131
132        //ロゴ画像
133        $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png';
134        $this->Image($logo_file, 124, 46, 40);
135    }
136
137    function setMessageData() {
138        // メッセージ
139        $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
140        $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
141        $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
142        $text = '作成日: '.$this->arrData['year'].'年'.$this->arrData['month'].'月'.$this->arrData['day'].'日';
143        $this->lfText(158, 288, $text, 8);  //作成日
144    }
145
146    function setOrderData() {
147        // DBから受注情報を読み込む
148        $this->lfGetOrderData($this->arrData['order_id']);
149
150        // 購入者情報
151        $text = '〒 '.$this->arrDisp['order_zip01'].' - '.$this->arrDisp['order_zip02'];
152        $this->lfText(23, 43, $text, 10); //購入者郵便番号
153        $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
154        $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
155        $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
156        $text = $this->arrDisp['order_name01'].' '.$this->arrDisp['order_name02'].' 様';
157        $this->lfText(27, 59, $text, 11); //購入者氏名
158
159        // お届け先情報
160        $this->SetFont('SJIS', '', 10);
161        $this->lfText(25, 125, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
162        $this->lfText(25, 135, $this->arrDisp['order_id'], 10); //注文番号
163
164        $this->SetFont('Gothic', 'B', 15);
165        $this->Cell(0, 10, $this->lfConvSjis($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
166        $this->Cell(0, 66, '', 0, 2, 'R', 0, '');
167        $this->Cell(5, 0, '', 0, 0, 'R', 0, '');
168        $this->SetFont('SJIS', 'B', 15);
169        $this->Cell(67, 8, $this->lfConvSjis(number_format($this->arrDisp['payment_total']).' 円'), 0, 2, 'R', 0, '');
170        $this->Cell(0, 45, '', 0, 2, '', 0, '');
171
172        $this->SetFont('SJIS', '', 8);
173
174        $monetary_unit = $this->lfConvSjis('円');
175        $point_unit = $this->lfConvSjis('Pt');
176
177        // 購入商品情報
178        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
179
180            // 購入数量
181            $data[0] = $this->arrDisp['quantity'][$i];
182
183            // 税込金額(単価)
184            $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]);
185
186            // 小計(商品毎)
187            $data[2] = $data[0] * $data[1];
188
189            $arrOrder[$i][0]  = $this->lfConvSjis($this->arrDisp['product_name'][$i].' / ');
190            $arrOrder[$i][0] .= $this->lfConvSjis($this->arrDisp['product_code'][$i].' / ');
191            if ($this->arrDisp['classcategory_name1'][$i]) {
192                $arrOrder[$i][0] .= $this->lfConvSjis(' [ '.$this->arrDisp['classcategory_name1'][$i]);
193                if ($this->arrDisp['classcategory_name2'][$i] == '') {
194                    $arrOrder[$i][0] .= ' ]';
195                } else {
196                    $arrOrder[$i][0] .= $this->lfConvSjis(' * '.$this->arrDisp['classcategory_name2'][$i].' ]');
197                }
198            }
199            $arrOrder[$i][1]  = number_format($data[0]);
200            $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
201            $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
202
203        }
204
205        $arrOrder[$i][0] = '';
206        $arrOrder[$i][1] = '';
207        $arrOrder[$i][2] = '';
208        $arrOrder[$i][3] = '';
209
210        $i++;
211        $arrOrder[$i][0] = '';
212        $arrOrder[$i][1] = '';
213        $arrOrder[$i][2] = $this->lfConvSjis('商品合計');
214        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
215
216        $i++;
217        $arrOrder[$i][0] = '';
218        $arrOrder[$i][1] = '';
219        $arrOrder[$i][2] = $this->lfConvSjis('送料');
220        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
221
222        $i++;
223        $arrOrder[$i][0] = '';
224        $arrOrder[$i][1] = '';
225        $arrOrder[$i][2] = $this->lfConvSjis('手数料');
226        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
227
228        $i++;
229        $arrOrder[$i][0] = '';
230        $arrOrder[$i][1] = '';
231        $arrOrder[$i][2] = $this->lfConvSjis('値引き');
232        $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
233
234        $i++;
235        $arrOrder[$i][0] = '';
236        $arrOrder[$i][1] = '';
237        $arrOrder[$i][2] = $this->lfConvSjis('請求金額');
238        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
239
240        // ポイント表記
241        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
242            $i++;
243            $arrOrder[$i][0] = '';
244            $arrOrder[$i][1] = '';
245            $arrOrder[$i][2] = '';
246            $arrOrder[$i][3] = '';
247
248            $i++;
249            $arrOrder[$i][0] = '';
250            $arrOrder[$i][1] = '';
251            $arrOrder[$i][2] = $this->lfConvSjis('利用ポイント');
252            $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
253
254            $i++;
255            $arrOrder[$i][0] = '';
256            $arrOrder[$i][1] = '';
257            $arrOrder[$i][2] = $this->lfConvSjis('加算ポイント');
258            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
259        }
260
261        $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
262    }
263
264    function setEtcData() {
265        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
266        $this->SetFont('Gothic', 'B', 9);
267        $this->MultiCell(0, 6, $this->lfConvSjis('< 備 考 >'), 'T', 2, 'L', 0, '');  //備考
268        $this->Ln();
269        $this->SetFont('SJIS', '', 8);
270        $this->MultiCell(0, 4, $this->lfConvSjis($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
271    }
272
273    function createPdf() {
274        // PDFをブラウザに送信
275        ob_clean();
276        if ($this->pdf_download == 1) {
277            if ($this->PageNo() == 1) {
278                $filename = 'nouhinsyo-No'.$this->arrData['order_id'].'.pdf';
279            } else {
280                $filename = 'nouhinsyo.pdf';
281            }
282            $this->Output($this->lfConvSjis($filename), 'D');
283        } else {
284            $this->Output();
285        }
286
287        // 入力してPDFファイルを閉じる
288        $this->Close();
289    }
290
291    // PDF_Japanese::Text へのパーサー
292    function lfText($x, $y, $text, $size = 0, $style = '') {
293        // 退避
294        $bak_font_style = $this->FontStyle;
295        $bak_font_size = $this->FontSizePt;
296
297        $this->SetFont('', $style, $size);
298        $this->Text($x, $y, $this->lfConvSjis($text));
299
300        // 復元
301        $this->SetFont('', $bak_font_style, $bak_font_size);
302    }
303
304    // 受注データの取得
305    function lfGetOrderData($order_id) {
306        if (SC_Utils_Ex::sfIsInt($order_id)) {
307            // DBから受注情報を読み込む
308            $objQuery = new SC_Query_Ex();
309            $where = 'order_id = ?';
310            $arrRet = $objQuery->select('*', 'dtb_order', $where, array($order_id));
311            $this->arrDisp = $arrRet[0];
312            list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
313            $this->arrDisp['point'] = $point;
314
315            // 受注詳細データの取得
316            $arrRet = $this->lfGetOrderDetail($order_id);
317            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
318            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
319
320            // その他支払い情報を表示
321            if ($this->arrDisp['memo02'] != '') {
322                $this->arrDisp['payment_info'] = unserialize($this->arrDisp['memo02']);
323            }
324            $this->arrDisp['payment_type'] = 'お支払い';
325        }
326    }
327
328    // 受注詳細データの取得
329    function lfGetOrderDetail($order_id) {
330        $objQuery = new SC_Query_Ex();
331        $col = 'product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate';
332        $where = 'order_id = ?';
333        $objQuery->setOrder('order_detail_id');
334        $arrRet = $objQuery->select($col, 'dtb_order_detail', $where, array($order_id));
335        return $arrRet;
336    }
337
338    // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ
339    function lfConvSjis($conv_str) {
340        return mb_convert_encoding($conv_str, 'SJIS-win', CHAR_CODE);
341    }
342
343    /**
344     * ゴシックフォントを定義
345     *
346     * @return void
347     */
348    function lfAddGothicFont() {
349        $cw = $GLOBALS['SJIS_widths'];
350        $c_map = '90msp-RKSJ-H';
351        $registry = array('ordering'=>'Japan1','supplement'=>2);
352        $this->AddCIDFonts('Gothic', 'KozGoPro-Medium-Acro,MS-PGothic,Osaka', $cw, $c_map, $registry);
353    }
354
355    /**
356     * フッター
357     *
358     * 現状の PDF_Japanese#Footer の動作によって、生成される PDF がエラーとなるケースがあり、
359     * そのエラーを抑える意図。
360     * @return void
361     */
362    function Footer() {
363    }
364}
Note: See TracBrowser for help on using the repository browser.