source: branches/version-2_11-dev/data/class/SC_Fpdf.php @ 21024

Revision 21024, 13.3 KB checked in by Seasoft, 13 years ago (diff)

#1399 (SC_Fpdf#lfText フォントファミリーの指定を上書きしている)
#1403 (SC_Fpdf#lfText 戻った後も、引数 $size, $style の影響を受ける)
#1404 (SC_Fpdf#lfText で SC_Fpdf#lfConvSjis を使用していない)
#1405 (SC_Fpdf#lfText 第4引数($size)省略可能に)

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