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

Revision 23605, 12.3 KB checked in by kimoto, 12 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

Scrutinizer Auto-Fixes

This patch was automatically generated as part of the following inspection:
 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/d8722894-69a6-4b1b-898d-43618035c60d

Enabled analysis tools:

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