source: branches/version-2_5-dev/data/class/SC_Fpdf.php @ 19680

Revision 19680, 14.2 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)

  • 「pretax」は収入に関する税込みを意味する英単語だと思いますので、より適切と考えられる「including tax」を基にした単語「inctax」に書き換えます。またメソッド名としては「calculate」を基にした「calc」を前置するように改めます。英文法・命名規則的に正しいか確信はないのですが少なくとも現状よりは理想に近づくと考えます。
  • Property svn:eol-style set to LF
  • 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-2010 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_PATH . 'pdf/japanese.php');
31define('PDF_TEMPLATE_DIR', DATA_PATH . 'pdf/');
32
33class SC_Fpdf {
34    function SC_Fpdf($download, $title, $tpl_pdf = "template_nouhin01.pdf") {
35        // デフォルトの設定
36        $this->tpl_pdf = PDF_TEMPLATE_DIR . $tpl_pdf;  // テンプレートファイル
37        $this->pdf_download = $download;      // PDFのダウンロード形式(0:表示、1:ダウンロード)
38        $this->tpl_title = $title;
39        $this->tpl_dispmode = "real";      // 表示モード
40        $masterData = new SC_DB_MasterData_Ex();
41        $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
42        $this->width_cell = array(110.3,12,21.7,24.5);
43
44        $this->label_cell[] = $this->sjis_conv("商品名 / 商品コード / [ 規格 ]");
45        $this->label_cell[] = $this->sjis_conv("数量");
46        $this->label_cell[] = $this->sjis_conv("単価");
47        $this->label_cell[] = $this->sjis_conv("金額(税込)");
48
49        $this->arrMessage = array(
50            'このたびはお買上げいただきありがとうございます。',
51            '下記の内容にて納品させていただきます。',
52            'ご確認いただきますよう、お願いいたします。'
53        );
54
55        $this->pdf  = new PDF_Japanese();
56
57        // SJISフォント
58        $this->pdf->AddSJISFont();
59
60        //ページ総数取得
61        $this->pdf->AliasNbPages();
62
63        // マージン設定
64        $this->pdf->SetMargins(15, 20);
65
66        // PDFを読み込んでページ数を取得
67        $pageno = $this->pdf->setSourceFile($this->tpl_pdf);
68    }
69
70    function setData($arrData) {
71        $this->arrData = $arrData;
72
73        // ページ番号よりIDを取得
74        $tplidx = $this->pdf->ImportPage(1);
75
76        // ページを追加(新規)
77        $this->pdf->AddPage();
78
79        //表示倍率(100%)
80        $this->pdf->SetDisplayMode($this->tpl_dispmode);
81
82        if (SC_Utils_Ex::sfIsInt($arrData['order_id'])) {
83            $this->disp_mode = true;
84            $order_id = $arrData['order_id'];
85        }
86
87        // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト
88        $this->pdf->useTemplate($tplidx);
89
90        $this->setShopData();
91        $this->setMessageData();
92        $this->setOrderData();
93        $this->setEtcData();
94
95    }
96
97    function setShopData() {
98        // ショップ情報
99
100        $objInfo = new SC_SiteInfo();
101        $arrInfo = $objInfo->data;
102
103        $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');          //ショップ名
104        $this->lfText(125, 63, $arrInfo['law_url'], 8);          //URL
105        $this->lfText(125, 68, $arrInfo['law_company'], 8);        //会社名
106        $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02'];
107        $this->lfText(125, 71, $text, 8);  //郵便番号
108        $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01'];
109        $this->lfText(125, 74, $text, 8);  //都道府県+住所1
110        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);          //住所2
111
112        $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03'];
113        //FAX番号が存在する場合、表示する
114        if (strlen($arrInfo['law_fax01']) > 0) {
115            $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03'];
116        }
117        $this->lfText(125, 80, $text, 8);  //TEL・FAX
118
119        if ( strlen($arrInfo['law_email']) > 0 ) {
120            $text = "Email: ".$arrInfo['law_email'];
121            $this->lfText(125, 83, $text, 8);      //Email
122        }
123
124        //ロゴ画像
125        $logo_file = PDF_TEMPLATE_DIR . 'logo.png';
126        $this->pdf->Image($logo_file, 124, 46, 40);
127    }
128
129    function setMessageData() {
130        // メッセージ
131        $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
132        $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
133        $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
134        $text = "作成日: ".$this->arrData['year']."年".$this->arrData['month']."月".$this->arrData['day']."日";
135        $this->lfText(158, 288, $text, 8);  //作成日
136    }
137
138    function setOrderData() {
139        // DBから受注情報を読み込む
140        $this->lfGetOrderData($this->arrData['order_id']);
141
142        // 購入者情報
143        $text = "〒 ".$this->arrDisp['order_zip01']." - ".$this->arrDisp['order_zip02'];
144        $this->lfText(23, 43, $text, 10); //購入者郵便番号
145        $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
146        $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
147        $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
148        $text = $this->arrDisp['order_name01']." ".$this->arrDisp['order_name02']." 様";
149        $this->lfText(27, 59, $text, 11); //購入者氏名
150
151        // お届け先情報
152        $this->pdf->SetFont('SJIS', '', 10);
153        $text = "〒 ".$this->arrDisp['deliv_zip01']." - ".$this->arrDisp['deliv_zip02'];
154        $this->lfText(22, 128, $text, 10); //お届け先郵便番号
155        $text = $this->arrPref[$this->arrDisp['deliv_pref']] . $this->arrDisp['deliv_addr01'];
156        $this->lfText(26, 132, $text, 10); //お届け先都道府県+住所1
157        $this->lfText(26, 136, $this->arrDisp['deliv_addr02'], 10); //お届け先住所2
158        $text = $this->arrDisp['deliv_name01']." ".$this->arrDisp['deliv_name02']." 様";
159        $this->lfText(26, 140, $text, 10); //お届け先氏名
160
161        $this->lfText(144, 121, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
162        $this->lfText(144, 131, $this->arrDisp['order_id'], 10); //注文番号
163
164        $this->pdf->SetFont('SJIS', 'B', 15);
165        $this->pdf->Cell(0, 10, $this->sjis_conv($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
166        $this->pdf->Cell(0, 66, '', 0, 2, 'R', 0, '');
167        $this->pdf->Cell(5, 0, '', 0, 0, 'R', 0, '');
168        $this->pdf->Cell(67, 8, $this->sjis_conv(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, '');
169        $this->pdf->Cell(0, 45, '', 0, 2, '', 0, '');
170
171        $this->pdf->SetFont('SJIS', '', 8);
172
173        $monetary_unit = $this->sjis_conv("円");
174        $point_unit = $this->sjis_conv("Pt");
175
176        // 購入商品情報
177        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
178
179            // 購入数量
180            $data[0] = $this->arrDisp['quantity'][$i];
181
182            // 税込金額(単価)
183            $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]);
184
185            // 小計(商品毎)
186            $data[2] = $data[0] * $data[1];
187
188            $arrOrder[$i][0]  = $this->sjis_conv($this->arrDisp['product_name'][$i]." / ");
189            $arrOrder[$i][0] .= $this->sjis_conv($this->arrDisp['product_code'][$i]." / ");
190            if ($this->arrDisp['classcategory_name1'][$i]) {
191                $arrOrder[$i][0] .= $this->sjis_conv(" [ ".$this->arrDisp['classcategory_name1'][$i]);
192                if ($this->arrDisp['classcategory_name2'][$i] == "") {
193                    $arrOrder[$i][0] .= " ]";
194                } else {
195                    $arrOrder[$i][0] .= $this->sjis_conv(" * ".$this->arrDisp['classcategory_name2'][$i]." ]");
196                }
197            }
198            $arrOrder[$i][1]  = number_format($data[0]);
199            $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
200            $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
201
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] = $this->sjis_conv("商品合計");
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] = $this->sjis_conv("送料");
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] = $this->sjis_conv("手数料");
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] = $this->sjis_conv("値引き");
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] = $this->sjis_conv("請求金額");
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] = $this->sjis_conv("利用ポイント");
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] = $this->sjis_conv("加算ポイント");
257            $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
258
259            $i++;
260            $arrOrder[$i][0] = "";
261            $arrOrder[$i][1] = "";
262            $arrOrder[$i][2] = $this->sjis_conv("所有ポイント");
263            $arrOrder[$i][3] = number_format($this->arrDisp['point']).$point_unit;
264        }
265
266        $this->pdf->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
267    }
268
269    function setEtcData() {
270        $this->pdf->Cell(0, 10, '', 0, 1, 'C', 0, '');
271        $this->pdf->SetFont('SJIS', '', 9);
272        $this->pdf->MultiCell(0, 6, $this->sjis_conv("< 備 考 >"), 'T', 2, 'L', 0, '');  //備考
273        $this->pdf->Ln();
274        $this->pdf->SetFont('SJIS', '', 8);
275        $this->pdf->MultiCell(0, 4, $this->sjis_conv($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
276    }
277
278    function createPdf() {
279        // PDFをブラウザに送信
280        ob_clean();
281        if ($this->pdf_download == 1) {
282            if ($this->pdf->PageNo() == 1) {
283                $filename = "nouhinsyo-No".$this->arrData['order_id'].".pdf";
284            } else {
285                $filename = "nouhinsyo.pdf";
286            }
287            $this->pdf->Output($this->sjis_conv($filename), D);
288        } else {
289            $this->pdf->Output();
290        }
291
292        // 入力してPDFファイルを閉じる
293        $this->pdf->Close();
294    }
295
296    // PDF_Japanese::Text へのパーサー
297    function lfText($x, $y, $text, $size, $style = '') {
298        $text = mb_convert_encoding($text, "SJIS-win", CHAR_CODE);
299
300        $this->pdf->SetFont('SJIS', $style, $size);
301        $this->pdf->Text($x, $y, $text);
302    }
303
304    // 受注データの取得
305    function lfGetOrderData($order_id) {
306        if(SC_Utils_Ex::sfIsInt($order_id)) {
307            // DBから受注情報を読み込む
308            $objQuery = new SC_Query();
309            $where = "order_id = ?";
310            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
311            $this->arrDisp = $arrRet[0];
312            list($point) = SC_Helper_DB_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
313            $this->arrDisp['point'] = $point;
314
315            // 受注詳細データの取得
316            $arrRet = $this->lfGetOrderDetail($order_id);
317            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
318            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
319            #$objFormParam->setParam($arrRet);
320
321            // その他支払い情報を表示
322            if($this->arrDisp["memo02"] != "") $this->arrDisp["payment_info"] = unserialize($this->arrDisp["memo02"]);
323            if($this->arrDisp["memo01"] == PAYMENT_CREDIT_ID){
324                  $this->arrDisp["payment_type"] = "クレジット決済";
325            } elseif ($this->arrDisp["memo01"] == PAYMENT_CONVENIENCE_ID) {
326                  $this->arrDisp["payment_type"] = "コンビニ決済";
327            } else {
328                  $this->arrDisp["payment_type"] = "お支払い";
329            }
330        }
331    }
332
333    // 受注詳細データの取得
334    function lfGetOrderDetail($order_id) {
335        $objQuery = new SC_Query();
336        $col = "product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
337        $where = "order_id = ?";
338        $objQuery->setOrder("product_class_id");
339        $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
340        return $arrRet;
341    }
342
343    // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ
344    function sjis_conv($conv_str) {
345        return (mb_convert_encoding($conv_str, "SJIS-win", CHAR_CODE));
346    }
347
348}
349?>
Note: See TracBrowser for help on using the repository browser.