source: branches/version-2/data/class/SC_Fpdf.php @ 17724

Revision 17724, 14.4 KB checked in by takegami, 15 years ago (diff)

#375 解決

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