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
RevLine 
[18233]1<?php
[17182]2/*
3 * This file is part of EC-CUBE
4 *
[20764]5 * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
[17182]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/*----------------------------------------------------------------------
[18043]25 * [名称] SC_Fpdf
[17182]26 * [概要] pdfファイルを表示する。
27 *----------------------------------------------------------------------
28 */
29
[19805]30require(DATA_REALDIR . 'module/fpdf/fpdf.php');
[20993]31require(DATA_REALDIR . 'module/fpdi/japanese.php');
[19807]32define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/');
[17182]33
34class SC_Fpdf {
[19735]35    function SC_Fpdf($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') {
[17182]36        // デフォルトの設定
[19807]37        $this->tpl_pdf = PDF_TEMPLATE_REALDIR . $tpl_pdf;  // テンプレートファイル
[17305]38        $this->pdf_download = $download;      // PDFのダウンロード形式(0:表示、1:ダウンロード)
39        $this->tpl_title = $title;
[20538]40        $this->tpl_dispmode = 'real';      // 表示モード
[17182]41        $masterData = new SC_DB_MasterData_Ex();
[19773]42        $this->arrPref = $masterData->getMasterData('mtb_pref');
[17182]43        $this->width_cell = array(110.3,12,21.7,24.5);
44
[20032]45        $this->label_cell[] = $this->lfConvSjis("商品名 / 商品コード / [ 規格 ]");
46        $this->label_cell[] = $this->lfConvSjis("数量");
47        $this->label_cell[] = $this->lfConvSjis("単価");
48        $this->label_cell[] = $this->lfConvSjis("金額(税込)");
[17182]49
50        $this->arrMessage = array(
[18097]51            'このたびはお買上げいただきありがとうございます。',
52            '下記の内容にて納品させていただきます。',
[19945]53            'ご確認くださいますよう、お願いいたします。'
[17182]54        );
55
56        $this->pdf  = new PDF_Japanese();
57
58        // SJISフォント
59        $this->pdf->AddSJISFont();
[21024]60        $this->pdf->SetFont('SJIS');
[17182]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);
[17305]70    }
[17182]71
[17305]72    function setData($arrData) {
73        $this->arrData = $arrData;
74
[17182]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
[18097]84        if (SC_Utils_Ex::sfIsInt($arrData['order_id'])) {
85            $this->disp_mode = true;
86            $order_id = $arrData['order_id'];
[17182]87        }
88
89        // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト
90        $this->pdf->useTemplate($tplidx);
91
92        $this->setShopData();
93        $this->setMessageData();
94        $this->setOrderData();
95        $this->setEtcData();
[18295]96
[17182]97    }
98
99    function setShopData() {
100        // ショップ情報
[18043]101
[20013]102        $objDb = new SC_Helper_DB_Ex();
103        $arrInfo = $objDb->sfGetBasisData();
[17182]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);        //会社名
[17909]108        $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02'];
[17182]109        $this->lfText(125, 71, $text, 8);  //郵便番号
[17909]110        $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01'];
[17182]111        $this->lfText(125, 74, $text, 8);  //都道府県+住所1
[17909]112        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);          //住所2
[18043]113
[17909]114        $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03'];
[18097]115        //FAX番号が存在する場合、表示する
[17909]116        if (strlen($arrInfo['law_fax01']) > 0) {
117            $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03'];
[17305]118        }
[17182]119        $this->lfText(125, 80, $text, 8);  //TEL・FAX
[17305]120
[18043]121        if ( strlen($arrInfo['law_email']) > 0 ) {
[17305]122            $text = "Email: ".$arrInfo['law_email'];
123            $this->lfText(125, 83, $text, 8);      //Email
124        }
[18016]125
126        //ロゴ画像
[19807]127        $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png';
[18016]128        $this->pdf->Image($logo_file, 124, 46, 40);
[17182]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        // お届け先情報
[21024]154        $this->pdf->SetFontSize(10);
[20013]155        $this->lfText(25, 125, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
156        $this->lfText(25, 135, $this->arrDisp['order_id'], 10); //注文番号
[17182]157
[21024]158        $this->pdf->SetFont('', 'B', 15);
[20032]159        $this->pdf->Cell(0, 10, $this->lfConvSjis($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
[17182]160        $this->pdf->Cell(0, 66, '', 0, 2, 'R', 0, '');
161        $this->pdf->Cell(5, 0, '', 0, 0, 'R', 0, '');
[20032]162        $this->pdf->Cell(67, 8, $this->lfConvSjis(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, '');
[17182]163        $this->pdf->Cell(0, 45, '', 0, 2, '', 0, '');
164
[21024]165        $this->pdf->SetFontSize(8);
[17182]166
[20032]167        $monetary_unit = $this->lfConvSjis("円");
[20538]168        $point_unit = $this->lfConvSjis('Pt');
[17182]169
170        // 購入商品情報
171        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
172
[18097]173            // 購入数量
174            $data[0] = $this->arrDisp['quantity'][$i];
[17182]175
[18097]176            // 税込金額(単価)
[19680]177            $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]);
[17182]178
[18097]179            // 小計(商品毎)
180            $data[2] = $data[0] * $data[1];
[17182]181
[20032]182            $arrOrder[$i][0]  = $this->lfConvSjis($this->arrDisp['product_name'][$i]." / ");
183            $arrOrder[$i][0] .= $this->lfConvSjis($this->arrDisp['product_code'][$i]." / ");
[18097]184            if ($this->arrDisp['classcategory_name1'][$i]) {
[20032]185                $arrOrder[$i][0] .= $this->lfConvSjis(" [ ".$this->arrDisp['classcategory_name1'][$i]);
[18097]186                if ($this->arrDisp['classcategory_name2'][$i] == "") {
187                    $arrOrder[$i][0] .= " ]";
188                } else {
[20032]189                    $arrOrder[$i][0] .= $this->lfConvSjis(" * ".$this->arrDisp['classcategory_name2'][$i]." ]");
[18097]190                }
[17182]191            }
[18097]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;
[17182]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] = "";
[20032]206        $arrOrder[$i][2] = $this->lfConvSjis("商品合計");
[17182]207        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
208
209        $i++;
210        $arrOrder[$i][0] = "";
211        $arrOrder[$i][1] = "";
[20032]212        $arrOrder[$i][2] = $this->lfConvSjis("送料");
[17182]213        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
214
215        $i++;
216        $arrOrder[$i][0] = "";
217        $arrOrder[$i][1] = "";
[20032]218        $arrOrder[$i][2] = $this->lfConvSjis("手数料");
[17182]219        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
220
221        $i++;
222        $arrOrder[$i][0] = "";
223        $arrOrder[$i][1] = "";
[20032]224        $arrOrder[$i][2] = $this->lfConvSjis("値引き");
[18043]225        $arrOrder[$i][3] = "- ".number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
[17182]226
227        $i++;
228        $arrOrder[$i][0] = "";
229        $arrOrder[$i][1] = "";
[20032]230        $arrOrder[$i][2] = $this->lfConvSjis("請求金額");
[17182]231        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
232
233        // ポイント表記
234        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
[18097]235            $i++;
236            $arrOrder[$i][0] = "";
237            $arrOrder[$i][1] = "";
238            $arrOrder[$i][2] = "";
239            $arrOrder[$i][3] = "";
[17182]240
[18097]241            $i++;
242            $arrOrder[$i][0] = "";
243            $arrOrder[$i][1] = "";
[20032]244            $arrOrder[$i][2] = $this->lfConvSjis("利用ポイント");
[18097]245            $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
[17182]246
[18097]247            $i++;
248            $arrOrder[$i][0] = "";
249            $arrOrder[$i][1] = "";
[20032]250            $arrOrder[$i][2] = $this->lfConvSjis("加算ポイント");
[18097]251            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
[17182]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, '');
[21024]259        $this->pdf->SetFontSize(9);
[20032]260        $this->pdf->MultiCell(0, 6, $this->lfConvSjis("< 備 考 >"), 'T', 2, 'L', 0, '');  //備考
[17182]261        $this->pdf->Ln();
[21024]262        $this->pdf->SetFontSize(8);
[20032]263        $this->pdf->MultiCell(0, 4, $this->lfConvSjis($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
[17182]264    }
265
266    function createPdf() {
267        // PDFをブラウザに送信
[18097]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            }
[20994]275            $this->pdf->Output($this->lfConvSjis($filename), 'D');
[17182]276        } else {
[18097]277            $this->pdf->Output();
[17182]278        }
279
280        // 入力してPDFファイルを閉じる
281        $this->pdf->Close();
282    }
283
284    // PDF_Japanese::Text へのパーサー
[21024]285    function lfText($x, $y, $text, $size = 0, $style = '') {
286        // 退避
287        $bak_font_style = $this->pdf->FontStyle;
288        $bak_font_size = $this->pdf->FontSizePt;
[17182]289
[21024]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);
[17182]295    }
296
297    // 受注データの取得
298    function lfGetOrderData($order_id) {
299        if(SC_Utils_Ex::sfIsInt($order_id)) {
300            // DBから受注情報を読み込む
[20507]301            $objQuery = new SC_Query_Ex();
[17182]302            $where = "order_id = ?";
303            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
304            $this->arrDisp = $arrRet[0];
[19864]305            list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
[18097]306            $this->arrDisp['point'] = $point;
[17182]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"]);
[20439]315            $this->arrDisp["payment_type"] = "お支払い";
[17182]316        }
317    }
318
319    // 受注詳細データの取得
320    function lfGetOrderDetail($order_id) {
[20507]321        $objQuery = new SC_Query_Ex();
[19653]322        $col = "product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
[18097]323        $where = "order_id = ?";
[20435]324        $objQuery->setOrder("order_detail_id");
[18097]325        $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
326        return $arrRet;
[17182]327    }
328
[18687]329    // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ
[20032]330    function lfConvSjis($conv_str) {
[20539]331        return mb_convert_encoding($conv_str, "SJIS-win", CHAR_CODE);
[17182]332    }
333
334}
335?>
Note: See TracBrowser for help on using the repository browser.