source: branches/version-2_12-multilang/data/class/SC_Fpdf.php @ 22100

Revision 22100, 12.7 KB checked in by pineray, 11 years ago (diff)

#163 (テキスト出力多言語対応)

グローバル化に伴い、不要となった SC_I18n を削除.

  • 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-2012 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 * PDF 納品書を出力する
26 *
27 * TODO ページクラスとすべき要素を多々含んでいるように感じる。
28 */
29
30define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/');
31
32class SC_Fpdf extends SC_Helper_FPDI {
33    function __construct($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') {
34        $this->FPDF();
35        // デフォルトの設定
36        $this->tpl_pdf = PDF_TEMPLATE_REALDIR . $tpl_pdf;  // テンプレートファイル
37        $this->pdf_download = $download;      // PDFのダウンロード形式(0:表示、1:ダウンロード)
38        $this->tpl_title = $title;
39        $this->tpl_dispmode = 'real';      // 表示モード
40        $masterData = new SC_DB_MasterData_Ex();
41        $this->arrPref = $masterData->getMasterData('mtb_pref');
42        $this->width_cell = array(110.3,12,21.7,24.5);
43
44        $this->label_cell[] = t('SC_Fpdf_001');
45        $this->label_cell[] = t('SC_Fpdf_002');
46        $this->label_cell[] = t('SC_Fpdf_003');
47        $this->label_cell[] = t('SC_Fpdf_004');
48
49        $this->arrMessage = array(
50            t('SC_Fpdf_014'),
51            t('SC_Fpdf_015'),
52            t('SC_Fpdf_016')
53        );
54
55        // SJISフォント
56        $this->AddSJISFont();
57        $this->SetFont('SJIS');
58
59        //ページ総数取得
60        $this->AliasNbPages();
61
62        // マージン設定
63        $this->SetMargins(15, 20);
64
65        // PDFを読み込んでページ数を取得
66        $this->pageno = $this->setSourceFile($this->tpl_pdf);
67    }
68
69    function setData($arrData) {
70        $this->arrData = $arrData;
71
72        // ページ番号よりIDを取得
73        $tplidx = $this->ImportPage(1);
74
75        // ページを追加(新規)
76        $this->AddPage();
77
78        //表示倍率(100%)
79        $this->SetDisplayMode($this->tpl_dispmode);
80
81        if (SC_Utils_Ex::sfIsInt($arrData['order_id'])) {
82            $this->disp_mode = true;
83        }
84
85        // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト
86        $this->useTemplate($tplidx);
87
88        $this->setShopData();
89        $this->setMessageData();
90        $this->setOrderData();
91        $this->setEtcData();
92
93    }
94
95    function setShopData() {
96        // ショップ情報
97
98        $objDb = new SC_Helper_DB_Ex();
99        $arrInfo = $objDb->sfGetBasisData();
100
101        // ショップ名
102        $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');
103        // URL
104        $this->lfText(125, 63, $arrInfo['law_url'], 8);
105        // 会社名
106        $this->lfText(125, 68, $arrInfo['law_company'], 8);
107        // 郵便番号
108        $text = '〒 ' . $arrInfo['law_zip01'] . ' - ' . $arrInfo['law_zip02'];
109        $this->lfText(125, 71, $text, 8);
110        // 都道府県+所在地
111        $text = $this->arrPref[$arrInfo['law_pref']] . $arrInfo['law_addr01'];
112        $this->lfText(125, 74, $text, 8);
113        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);
114
115        $text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03'];
116        //FAX番号が存在する場合、表示する
117        if (strlen($arrInfo['law_fax01']) > 0) {
118            $text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03'];
119        }
120        $this->lfText(125, 80, $text, 8);  //TEL・FAX
121
122        if (strlen($arrInfo['law_email']) > 0) {
123            $text = 'Email: '.$arrInfo['law_email'];
124            $this->lfText(125, 83, $text, 8);      //Email
125        }
126
127        //ロゴ画像
128        $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png';
129        $this->Image($logo_file, 124, 46, 40);
130    }
131
132    function setMessageData() {
133        // メッセージ
134        $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
135        $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
136        $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
137        $tokens = array(
138            'T_YEAR' => $this->arrData['year'],
139            'T_MONTH' => $this->arrData['month'],
140            'T_DAY' => $this->arrData['day']
141        );
142        $text = t('SC_Fpdf_017', $tokens);
143        $this->lfText(158, 288, $text, 8);  //作成日
144    }
145
146    function setOrderData() {
147        $arrOrder = array();
148        // DBから受注情報を読み込む
149        $this->lfGetOrderData($this->arrData['order_id']);
150
151        // 購入者情報
152        $text = '〒 '.$this->arrDisp['order_zip01'].' - '.$this->arrDisp['order_zip02'];
153        $this->lfText(23, 43, $text, 10); //購入者郵便番号
154        $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
155        $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
156        $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
157        $text = $this->arrDisp['order_name01'].' '.$this->arrDisp['order_name02'].' 様';
158        $this->lfText(27, 59, $text, 11); //購入者氏名
159
160        // お届け先情報
161        $this->SetFont('SJIS', '', 10);
162        $this->lfText(25, 125, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
163        $this->lfText(25, 135, $this->arrDisp['order_id'], 10); //注文番号
164
165        $this->SetFont('Gothic', 'B', 15);
166        $this->Cell(0, 10, $this->tpl_title, 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
167        $this->Cell(0, 66, '', 0, 2, 'R', 0, '');
168        $this->Cell(5, 0, '', 0, 0, 'R', 0, '');
169        $this->SetFont('SJIS', 'B', 15);
170        $tokens = array(
171            'T_PRICE' => number_format($this->arrDisp['payment_total']),
172            'T_UNIT' => t('SC_Fpdf_019')
173        );
174        $this->Cell(67, 8, t('SC_Fpdf_018', $tokens), 0, 2, 'R', 0, '');
175        $this->Cell(0, 45, '', 0, 2, '', 0, '');
176
177        $this->SetFont('SJIS', '', 8);
178
179        $monetary_unit = t('SC_Fpdf_019');
180        $point_unit = t('SC_Fpdf_020');
181
182        // 購入商品情報
183        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
184
185            // 購入数量
186            $data[0] = $this->arrDisp['quantity'][$i];
187
188            // 税込金額(単価)
189            $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]);
190
191            // 小計(商品毎)
192            $data[2] = $data[0] * $data[1];
193
194            $arrOrder[$i][0]  = $this->arrDisp['product_name'][$i].' / ';
195            $arrOrder[$i][0] .= $this->arrDisp['product_code'][$i].' / ';
196            if ($this->arrDisp['classcategory_name1'][$i]) {
197                $arrOrder[$i][0] .= ' [ '.$this->arrDisp['classcategory_name1'][$i];
198                if ($this->arrDisp['classcategory_name2'][$i] == '') {
199                    $arrOrder[$i][0] .= ' ]';
200                } else {
201                    $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]';
202                }
203            }
204            $arrOrder[$i][1]  = number_format($data[0]);
205            $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
206            $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
207
208        }
209
210        $arrOrder[$i][0] = '';
211        $arrOrder[$i][1] = '';
212        $arrOrder[$i][2] = '';
213        $arrOrder[$i][3] = '';
214
215        $i++;
216        $arrOrder[$i][0] = '';
217        $arrOrder[$i][1] = '';
218        $arrOrder[$i][2] = t('SC_Fpdf_005');
219        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
220
221        $i++;
222        $arrOrder[$i][0] = '';
223        $arrOrder[$i][1] = '';
224        $arrOrder[$i][2] = t('SC_Fpdf_006');
225        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
226
227        $i++;
228        $arrOrder[$i][0] = '';
229        $arrOrder[$i][1] = '';
230        $arrOrder[$i][2] = t('SC_Fpdf_007');
231        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
232
233        $i++;
234        $arrOrder[$i][0] = '';
235        $arrOrder[$i][1] = '';
236        $arrOrder[$i][2] = t('SC_Fpdf_008');
237        $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
238
239        $i++;
240        $arrOrder[$i][0] = '';
241        $arrOrder[$i][1] = '';
242        $arrOrder[$i][2] = t('SC_Fpdf_009');
243        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
244
245        // ポイント表記
246        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
247            $i++;
248            $arrOrder[$i][0] = '';
249            $arrOrder[$i][1] = '';
250            $arrOrder[$i][2] = '';
251            $arrOrder[$i][3] = '';
252
253            $i++;
254            $arrOrder[$i][0] = '';
255            $arrOrder[$i][1] = '';
256            $arrOrder[$i][2] = t('SC_Fpdf_010');
257            $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
258
259            $i++;
260            $arrOrder[$i][0] = '';
261            $arrOrder[$i][1] = '';
262            $arrOrder[$i][2] = t('SC_Fpdf_011');
263            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
264        }
265
266        $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
267    }
268
269    /**
270     * 備考の出力を行う
271     *
272     * @param string $str 入力文字列
273     * @return string 変更後の文字列
274     */
275    function setEtcData() {
276        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
277        $this->SetFont('Gothic', 'B', 9);
278        $this->MultiCell(0, 6, t('SC_Fpdf_012'), 'T', 2, 'L', 0, '');  //備考
279        $this->SetFont('SJIS', '', 8);
280        $text = SC_Utils_Ex::rtrim($this->arrData['etc1'] . "\n" . $this->arrData['etc2'] . "\n" . $this->arrData['etc3']);
281        $this->MultiCell(0, 4, $text, '', 2, 'L', 0, '');
282    }
283
284    function createPdf() {
285        // PDFをブラウザに送信
286        ob_clean();
287        if ($this->pdf_download == 1) {
288            if ($this->PageNo() == 1) {
289                $filename = 'nouhinsyo-No'.$this->arrData['order_id'].'.pdf';
290            } else {
291                $filename = 'nouhinsyo.pdf';
292            }
293            $this->Output($this->lfConvSjis($filename), 'D');
294        } else {
295            $this->Output();
296        }
297
298        // 入力してPDFファイルを閉じる
299        $this->Close();
300    }
301
302    // PDF_Japanese::Text へのパーサー
303    function lfText($x, $y, $text, $size = 0, $style = '') {
304        // 退避
305        $bak_font_style = $this->FontStyle;
306        $bak_font_size = $this->FontSizePt;
307
308        $this->SetFont('', $style, $size);
309        $this->Text($x, $y, $text);
310
311        // 復元
312        $this->SetFont('', $bak_font_style, $bak_font_size);
313    }
314
315    // 受注データの取得
316    function lfGetOrderData($order_id) {
317        if (SC_Utils_Ex::sfIsInt($order_id)) {
318            // DBから受注情報を読み込む
319            $objQuery =& SC_Query_Ex::getSingletonInstance();
320            $where = 'order_id = ?';
321            $arrRet = $objQuery->select('*', 'dtb_order', $where, array($order_id));
322            $this->arrDisp = $arrRet[0];
323            list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
324            $this->arrDisp['point'] = $point;
325
326            // 受注詳細データの取得
327            $arrRet = $this->lfGetOrderDetail($order_id);
328            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
329            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
330
331            // その他支払い情報を表示
332            if ($this->arrDisp['memo02'] != '') {
333                $this->arrDisp['payment_info'] = unserialize($this->arrDisp['memo02']);
334            }
335            $this->arrDisp['payment_type'] = t('SC_Fpdf_013');
336        }
337    }
338
339    // 受注詳細データの取得
340    function lfGetOrderDetail($order_id) {
341        $objQuery =& SC_Query_Ex::getSingletonInstance();
342        $col = 'product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate';
343        $where = 'order_id = ?';
344        $objQuery->setOrder('order_detail_id');
345        $arrRet = $objQuery->select($col, 'dtb_order_detail', $where, array($order_id));
346        return $arrRet;
347    }
348}
Note: See TracBrowser for help on using the repository browser.