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

Revision 17232, 14.1 KB checked in by satou, 16 years ago (diff)

納品書発行機能 by Yammy (merge r17182)

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