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

Revision 22857, 12.2 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。
  • 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    public 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    public 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    private function setShopData()
98    {
99        // ショップ情報
100
101        $objDb = new SC_Helper_DB_Ex();
102        $arrInfo = $objDb->sfGetBasisData();
103
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);
117
118        $text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03'];
119        //FAX番号が存在する場合、表示する
120        if (strlen($arrInfo['law_fax01']) > 0) {
121            $text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03'];
122        }
123        $this->lfText(125, 80, $text, 8);  //TEL・FAX
124
125        if (strlen($arrInfo['law_email']) > 0) {
126            $text = 'Email: '.$arrInfo['law_email'];
127            $this->lfText(125, 83, $text, 8);      //Email
128        }
129
130        //ロゴ画像
131        $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png';
132        $this->Image($logo_file, 124, 46, 40);
133    }
134
135    private function setMessageData()
136    {
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
141        $text = '作成日: '.$this->arrData['year'].'年'.$this->arrData['month'].'月'.$this->arrData['day'].'日';
142        $this->lfText(158, 288, $text, 8);  //作成日
143    }
144
145    private function setOrderData()
146    {
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        $this->Cell(67, 8, number_format($this->arrDisp['payment_total']).' 円', 0, 2, 'R', 0, '');
171        $this->Cell(0, 45, '', 0, 2, '', 0, '');
172
173        $this->SetFont('SJIS', '', 8);
174
175        $monetary_unit = '円';
176        $point_unit = 'Pt';
177
178        // 購入商品情報
179        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
180            // 購入数量
181            $data[0] = $this->arrDisp['quantity'][$i];
182
183            // 税込金額(単価)
184            $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i], $this->arrDisp['tax_rate'][$i], $this->arrDisp['tax_rule'][$i]);
185
186            // 小計(商品毎)
187            $data[2] = $data[0] * $data[1];
188
189            $arrOrder[$i][0]  = $this->arrDisp['product_name'][$i].' / ';
190            $arrOrder[$i][0] .= $this->arrDisp['product_code'][$i].' / ';
191            if ($this->arrDisp['classcategory_name1'][$i]) {
192                $arrOrder[$i][0] .= ' [ '.$this->arrDisp['classcategory_name1'][$i];
193                if ($this->arrDisp['classcategory_name2'][$i] == '') {
194                    $arrOrder[$i][0] .= ' ]';
195                } else {
196                    $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]';
197                }
198            }
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;
202        }
203
204        $arrOrder[$i][0] = '';
205        $arrOrder[$i][1] = '';
206        $arrOrder[$i][2] = '';
207        $arrOrder[$i][3] = '';
208
209        $i++;
210        $arrOrder[$i][0] = '';
211        $arrOrder[$i][1] = '';
212        $arrOrder[$i][2] = '商品合計';
213        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
214
215        $i++;
216        $arrOrder[$i][0] = '';
217        $arrOrder[$i][1] = '';
218        $arrOrder[$i][2] = '送料';
219        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
220
221        $i++;
222        $arrOrder[$i][0] = '';
223        $arrOrder[$i][1] = '';
224        $arrOrder[$i][2] = '手数料';
225        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
226
227        $i++;
228        $arrOrder[$i][0] = '';
229        $arrOrder[$i][1] = '';
230        $arrOrder[$i][2] = '値引き';
231        $arrOrder[$i][3] = '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
232
233        $i++;
234        $arrOrder[$i][0] = '';
235        $arrOrder[$i][1] = '';
236        $arrOrder[$i][2] = '請求金額';
237        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
238
239        // ポイント表記
240        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
241            $i++;
242            $arrOrder[$i][0] = '';
243            $arrOrder[$i][1] = '';
244            $arrOrder[$i][2] = '';
245            $arrOrder[$i][3] = '';
246
247            $i++;
248            $arrOrder[$i][0] = '';
249            $arrOrder[$i][1] = '';
250            $arrOrder[$i][2] = '利用ポイント';
251            $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
252
253            $i++;
254            $arrOrder[$i][0] = '';
255            $arrOrder[$i][1] = '';
256            $arrOrder[$i][2] = '加算ポイント';
257            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
258        }
259
260        $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
261    }
262
263    /**
264     * 備考の出力を行う
265     *
266     * @param  string $str 入力文字列
267     * @return string 変更後の文字列
268     */
269    private function setEtcData()
270    {
271        $this->Cell(0, 10, '', 0, 1, 'C', 0, '');
272        $this->SetFont('Gothic', 'B', 9);
273        $this->MultiCell(0, 6, '< 備考 >', 'T', 2, 'L', 0, '');
274        $this->SetFont('SJIS', '', 8);
275        $text = SC_Utils_Ex::rtrim($this->arrData['etc1'] . "\n" . $this->arrData['etc2'] . "\n" . $this->arrData['etc3']);
276        $this->MultiCell(0, 4, $text, '', 2, 'L', 0, '');
277    }
278
279    public function createPdf()
280    {
281        // PDFをブラウザに送信
282        ob_clean();
283        if ($this->pdf_download == 1) {
284            if ($this->PageNo() == 1) {
285                $filename = 'nouhinsyo-No'.$this->arrData['order_id'].'.pdf';
286            } else {
287                $filename = 'nouhinsyo.pdf';
288            }
289            $this->Output($this->lfConvSjis($filename), 'D');
290        } else {
291            $this->Output();
292        }
293
294        // 入力してPDFファイルを閉じる
295        $this->Close();
296    }
297
298    // PDF_Japanese::Text へのパーサー
299    private function lfText($x, $y, $text, $size = 0, $style = '')
300    {
301        // 退避
302        $bak_font_style = $this->FontStyle;
303        $bak_font_size = $this->FontSizePt;
304
305        $this->SetFont('', $style, $size);
306        $this->Text($x, $y, $text);
307
308        // 復元
309        $this->SetFont('', $bak_font_style, $bak_font_size);
310    }
311
312    // 受注データの取得
313    private function lfGetOrderData($order_id)
314    {
315        if (SC_Utils_Ex::sfIsInt($order_id)) {
316            // DBから受注情報を読み込む
317            $objPurchase = new SC_Helper_Purchase_Ex();
318            $this->arrDisp = $objPurchase->getOrder($order_id);
319            list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $this->arrDisp['use_point'], $this->arrDisp['add_point']);
320            $this->arrDisp['point'] = $point;
321
322            // 受注詳細データの取得
323            $arrRet = $objPurchase->getOrderDetail($order_id);
324            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
325            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
326
327            // その他支払い情報を表示
328            if ($this->arrDisp['memo02'] != '') {
329                $this->arrDisp['payment_info'] = unserialize($this->arrDisp['memo02']);
330            }
331            $this->arrDisp['payment_type'] = 'お支払い';
332        }
333    }
334}
Note: See TracBrowser for help on using the repository browser.