source: branches/comu-ver2/data/class/SC_Fpdf.php @ 18052

Revision 18052, 14.3 KB checked in by Seasoft, 15 years ago (diff)

・店舗基本情報の取得処理にランタイムのキャッシュ機構を設け、店舗基本情報を深く渡し回す実装を改めた。
・SC_Utils 冒頭のコメントに従い、インスタンスを生成していた処理を、Helper クラスへ移す。計算処理のみ SC_Utils に残す。

Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 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    function setShopData() {
97        // ショップ情報
98
99        $objInfo = new SC_SiteInfo();
100        $arrInfo = $objInfo->data;
101
102        $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B');          //ショップ名
103        $this->lfText(125, 63, $arrInfo['law_url'], 8);          //URL
104        $this->lfText(125, 68, $arrInfo['law_company'], 8);        //会社名
105        $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02'];
106        $this->lfText(125, 71, $text, 8);  //郵便番号
107        $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01'];
108        $this->lfText(125, 74, $text, 8);  //都道府県+住所1
109        $this->lfText(125, 77, $arrInfo['law_addr02'], 8);          //住所2
110
111        $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03'];
112        //FAX番号が存在する場合、表示する
113        if (strlen($arrInfo['law_fax01']) > 0) {
114            $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03'];
115        }
116        $this->lfText(125, 80, $text, 8);  //TEL・FAX
117
118        if ( strlen($arrInfo['law_email']) > 0 ) {
119            $text = "Email: ".$arrInfo['law_email'];
120            $this->lfText(125, 83, $text, 8);      //Email
121        }
122
123        //ロゴ画像
124        $logo_file = PDF_TEMPLATE_DIR . 'logo.png';
125        $this->pdf->Image($logo_file, 124, 46, 40);
126    }
127
128    function setMessageData() {
129        // メッセージ
130        $this->lfText(27, 70, $this->arrData['msg1'], 8);  //メッセージ1
131        $this->lfText(27, 74, $this->arrData['msg2'], 8);  //メッセージ2
132        $this->lfText(27, 78, $this->arrData['msg3'], 8);  //メッセージ3
133        $text = "作成日: ".$this->arrData['year']."年".$this->arrData['month']."月".$this->arrData['day']."日";
134        $this->lfText(158, 288, $text, 8);  //作成日
135    }
136
137    function setOrderData() {
138        // DBから受注情報を読み込む
139        $this->lfGetOrderData($this->arrData['order_id']);
140
141        // 購入者情報
142        $text = "〒 ".$this->arrDisp['order_zip01']." - ".$this->arrDisp['order_zip02'];
143        $this->lfText(23, 43, $text, 10); //購入者郵便番号
144        $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01'];
145        $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1
146        $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2
147        $text = $this->arrDisp['order_name01']." ".$this->arrDisp['order_name02']." 様";
148        $this->lfText(27, 59, $text, 11); //購入者氏名
149
150        // お届け先情報
151        $this->pdf->SetFont('SJIS', '', 10);
152        $text = "〒 ".$this->arrDisp['deliv_zip01']." - ".$this->arrDisp['deliv_zip02'];
153        $this->lfText(22, 128, $text, 10); //お届け先郵便番号
154        $text = $this->arrPref[$this->arrDisp['deliv_pref']] . $this->arrDisp['deliv_addr01'];
155        $this->lfText(26, 132, $text, 10); //お届け先都道府県+住所1
156        $this->lfText(26, 136, $this->arrDisp['deliv_addr02'], 10); //お届け先住所2
157        $text = $this->arrDisp['deliv_name01']." ".$this->arrDisp['deliv_name02']." 様";
158        $this->lfText(26, 140, $text, 10); //お届け先氏名
159
160        $this->lfText(144, 121, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日
161        $this->lfText(144, 131, $this->arrDisp['order_id'], 10); //注文番号
162
163        $this->pdf->SetFont('SJIS', 'B', 15);
164        $this->pdf->Cell(0, 10, $this->sjis_conv($this->tpl_title), 0, 2, 'C', 0, '');  //文書タイトル(納品書・請求書)
165        $this->pdf->Cell(0, 66, '', 0, 2, 'R', 0, '');
166        $this->pdf->Cell(5, 0, '', 0, 0, 'R', 0, '');
167        $this->pdf->Cell(67, 8, $this->sjis_conv(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, '');
168        $this->pdf->Cell(0, 45, '', 0, 2, '', 0, '');
169
170        $this->pdf->SetFont('SJIS', '', 8);
171
172        $monetary_unit = $this->sjis_conv("円");
173        $point_unit = $this->sjis_conv("Pt");
174
175        // 購入商品情報
176        for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) {
177
178          // 購入数量
179          $data[0] = $this->arrDisp['quantity'][$i];
180
181          // 税込金額(単価)
182          $data[1] = SC_Helper_DB_Ex::sfPreTax($this->arrDisp['price'][$i]);
183
184          // 小計(商品毎)
185          $data[2] = $data[0] * $data[1];
186
187          $arrOrder[$i][0]  = $this->sjis_conv($this->arrDisp['product_name'][$i]." / ");
188          $arrOrder[$i][0] .= $this->sjis_conv($this->arrDisp['product_code'][$i]." / ");
189          if($this->arrDisp['classcategory_name1'][$i]) {
190            $arrOrder[$i][0] .= $this->sjis_conv(" [ ".$this->arrDisp['classcategory_name1'][$i]);
191            if($this->arrDisp['classcategory_name2'][$i] == "") {
192              $arrOrder[$i][0] .= " ]";
193            } else {
194              $arrOrder[$i][0] .= $this->sjis_conv(" * ".$this->arrDisp['classcategory_name2'][$i]." ]");
195            }
196          }
197          $arrOrder[$i][1]  = number_format($data[0]);
198          $arrOrder[$i][2]  = number_format($data[1]).$monetary_unit;
199          $arrOrder[$i][3]  = number_format($data[2]).$monetary_unit;
200
201        }
202
203        $arrOrder[$i][0] = "";
204        $arrOrder[$i][1] = "";
205        $arrOrder[$i][2] = "";
206        $arrOrder[$i][3] = "";
207
208        $i++;
209        $arrOrder[$i][0] = "";
210        $arrOrder[$i][1] = "";
211        $arrOrder[$i][2] = $this->sjis_conv("商品合計");
212        $arrOrder[$i][3] = number_format($this->arrDisp['subtotal']).$monetary_unit;
213
214        $i++;
215        $arrOrder[$i][0] = "";
216        $arrOrder[$i][1] = "";
217        $arrOrder[$i][2] = $this->sjis_conv("送料");
218        $arrOrder[$i][3] = number_format($this->arrDisp['deliv_fee']).$monetary_unit;
219
220        $i++;
221        $arrOrder[$i][0] = "";
222        $arrOrder[$i][1] = "";
223        $arrOrder[$i][2] = $this->sjis_conv("手数料");
224        $arrOrder[$i][3] = number_format($this->arrDisp['charge']).$monetary_unit;
225
226        $i++;
227        $arrOrder[$i][0] = "";
228        $arrOrder[$i][1] = "";
229        $arrOrder[$i][2] = $this->sjis_conv("値引き");
230        $arrOrder[$i][3] = "- ".number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit;
231
232        $i++;
233        $arrOrder[$i][0] = "";
234        $arrOrder[$i][1] = "";
235        $arrOrder[$i][2] = $this->sjis_conv("請求金額");
236        $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit;
237
238        $i++;
239        $arrOrder[$i][0] = "";
240        $arrOrder[$i][1] = "";
241        $arrOrder[$i][2] = "";
242        $arrOrder[$i][3] = "";
243
244        // ポイント表記
245        if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) {
246          $i++;
247          $arrOrder[$i][0] = "";
248          $arrOrder[$i][1] = "";
249          $arrOrder[$i][2] = $this->sjis_conv("利用ポイント");
250          $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit;
251
252          $i++;
253          $arrOrder[$i][0] = "";
254          $arrOrder[$i][1] = "";
255          $arrOrder[$i][2] = $this->sjis_conv("加算ポイント");
256          $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit;
257
258          $i++;
259          $arrOrder[$i][0] = "";
260          $arrOrder[$i][1] = "";
261          $arrOrder[$i][2] = $this->sjis_conv("所有ポイント");
262          $arrOrder[$i][3] = number_format($this->arrDisp['point']).$point_unit;
263        }
264
265        $this->pdf->FancyTable($this->label_cell, $arrOrder, $this->width_cell);
266    }
267
268    function setEtcData() {
269        $this->pdf->Cell(0, 10, '', 0, 1, 'C', 0, '');
270        $this->pdf->SetFont('SJIS', '', 9);
271        $this->pdf->MultiCell(0, 6, $this->sjis_conv("< 備 考 >"), 'T', 2, 'L', 0, '');  //備考
272        $this->pdf->Ln();
273        $this->pdf->SetFont('SJIS', '', 8);
274        $this->pdf->MultiCell(0, 4, $this->sjis_conv($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, '');  //備考
275    }
276
277    function createPdf() {
278        // PDFをブラウザに送信
279ob_clean();
280        if($this->pdf_download == 1) {
281          if ($this->pdf->PageNo() == 1) {
282            $filename = "nouhinsyo-No".$this->arrData['order_id'].".pdf";
283          } else {
284            $filename = "nouhinsyo.pdf";
285          }
286          $this->pdf->Output($this->sjis_conv($filename), D);
287        } else {
288          $this->pdf->Output();
289        }
290
291        // 入力してPDFファイルを閉じる
292        $this->pdf->Close();
293    }
294
295    // PDF_Japanese::Text へのパーサー
296    function lfText($x, $y, $text, $size, $style = '') {
297        $text = mb_convert_encoding($text, "SJIS", CHAR_CODE);
298
299        $this->pdf->SetFont('SJIS', $style, $size);
300        $this->pdf->Text($x, $y, $text);
301    }
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            #$objFormParam->setParam($arrRet[0]);
312            list($point, $total_point) = SC_Helper_DB_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
313            #$objFormParam->setValue('total_point', $total_point);
314            #$objFormParam->setValue('point', $point);
315            $arrRet[0]['total_point'] = $total_point;
316            $arrRet[0]['point'] = $point;
317            $this->arrDisp = $arrRet[0];
318
319            // 受注詳細データの取得
320            $arrRet = $this->lfGetOrderDetail($order_id);
321            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
322            $this->arrDisp = array_merge($this->arrDisp, $arrRet);
323            #$objFormParam->setParam($arrRet);
324
325            // その他支払い情報を表示
326            if($this->arrDisp["memo02"] != "") $this->arrDisp["payment_info"] = unserialize($this->arrDisp["memo02"]);
327            if($this->arrDisp["memo01"] == PAYMENT_CREDIT_ID){
328                  $this->arrDisp["payment_type"] = "クレジット決済";
329            } elseif ($this->arrDisp["memo01"] == PAYMENT_CONVENIENCE_ID) {
330                  $this->arrDisp["payment_type"] = "コンビニ決済";
331            } else {
332                  $this->arrDisp["payment_type"] = "お支払い";
333            }
334        }
335    }
336
337    // 受注詳細データの取得
338    function lfGetOrderDetail($order_id) {
339      $objQuery = new SC_Query();
340      $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
341      $where = "order_id = ?";
342      $objQuery->setorder("classcategory_id1, classcategory_id2");
343      $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
344      return $arrRet;
345    }
346
347    // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJISのみ
348    function sjis_conv($conv_str) {
349      return (mb_convert_encoding($conv_str, "SJIS", CHAR_CODE));
350    }
351
352
353}
354?>
Note: See TracBrowser for help on using the repository browser.