source: branches/version-2_13-dev/data/class/SC_Fpdf.php @ 22779

Revision 22779, 12.8 KB checked in by Seasoft, 11 years ago (diff)

#2018 (帳票出力の備考にひらがな・カタカナを入力すると改行コードが文字化けします)

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