| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of EC-CUBE |
|---|
| 4 | * |
|---|
| 5 | * Copyright(c) 2000-2011 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 | |
|---|
| 30 | require(DATA_REALDIR . 'module/fpdf/fpdf.php'); |
|---|
| 31 | require(DATA_REALDIR . 'module/fpdi/japanese.php'); |
|---|
| 32 | define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/'); |
|---|
| 33 | |
|---|
| 34 | class SC_Fpdf extends PDF_Japanese { |
|---|
| 35 | function SC_Fpdf($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') { |
|---|
| 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[] = $this->lfConvSjis("商品名 / 商品コード / [ 規格 ]"); |
|---|
| 47 | $this->label_cell[] = $this->lfConvSjis("数量"); |
|---|
| 48 | $this->label_cell[] = $this->lfConvSjis("単価"); |
|---|
| 49 | $this->label_cell[] = $this->lfConvSjis("金額(税込)"); |
|---|
| 50 | |
|---|
| 51 | $this->arrMessage = array( |
|---|
| 52 | 'このたびはお買上げいただきありがとうございます。', |
|---|
| 53 | '下記の内容にて納品させていただきます。', |
|---|
| 54 | 'ご確認くださいますよう、お願いいたします。' |
|---|
| 55 | ); |
|---|
| 56 | |
|---|
| 57 | $this->lfAddGothicFont(); |
|---|
| 58 | |
|---|
| 59 | // SJISフォント |
|---|
| 60 | $this->AddSJISFont(); |
|---|
| 61 | $this->SetFont('SJIS'); |
|---|
| 62 | |
|---|
| 63 | //ページ総数取得 |
|---|
| 64 | $this->AliasNbPages(); |
|---|
| 65 | |
|---|
| 66 | // マージン設定 |
|---|
| 67 | $this->SetMargins(15, 20); |
|---|
| 68 | |
|---|
| 69 | // PDFを読み込んでページ数を取得 |
|---|
| 70 | $pageno = $this->setSourceFile($this->tpl_pdf); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | function setData($arrData) { |
|---|
| 74 | $this->arrData = $arrData; |
|---|
| 75 | |
|---|
| 76 | // ページ番号よりIDを取得 |
|---|
| 77 | $tplidx = $this->ImportPage(1); |
|---|
| 78 | |
|---|
| 79 | // ページを追加(新規) |
|---|
| 80 | $this->AddPage(); |
|---|
| 81 | |
|---|
| 82 | //表示倍率(100%) |
|---|
| 83 | $this->SetDisplayMode($this->tpl_dispmode); |
|---|
| 84 | |
|---|
| 85 | if (SC_Utils_Ex::sfIsInt($arrData['order_id'])) { |
|---|
| 86 | $this->disp_mode = true; |
|---|
| 87 | $order_id = $arrData['order_id']; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト |
|---|
| 91 | $this->useTemplate($tplidx); |
|---|
| 92 | |
|---|
| 93 | $this->setShopData(); |
|---|
| 94 | $this->setMessageData(); |
|---|
| 95 | $this->setOrderData(); |
|---|
| 96 | $this->setEtcData(); |
|---|
| 97 | |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | function setShopData() { |
|---|
| 101 | // ショップ情報 |
|---|
| 102 | |
|---|
| 103 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 104 | $arrInfo = $objDb->sfGetBasisData(); |
|---|
| 105 | |
|---|
| 106 | $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B'); //ショップ名 |
|---|
| 107 | $this->lfText(125, 63, $arrInfo['law_url'], 8); //URL |
|---|
| 108 | $this->lfText(125, 68, $arrInfo['law_company'], 8); //会社名 |
|---|
| 109 | $text = "〒 ".$arrInfo['law_zip01']." - ".$arrInfo['law_zip02']; |
|---|
| 110 | $this->lfText(125, 71, $text, 8); //郵便番号 |
|---|
| 111 | $text = $this->arrPref[$arrInfo['law_pref']].$arrInfo['law_addr01']; |
|---|
| 112 | $this->lfText(125, 74, $text, 8); //都道府県+住所1 |
|---|
| 113 | $this->lfText(125, 77, $arrInfo['law_addr02'], 8); //住所2 |
|---|
| 114 | |
|---|
| 115 | $text = "TEL: ".$arrInfo['law_tel01']."-".$arrInfo['law_tel02']."-".$arrInfo['law_tel03']; |
|---|
| 116 | //FAX番号が存在する場合、表示する |
|---|
| 117 | if (strlen($arrInfo['law_fax01']) > 0) { |
|---|
| 118 | $text .= " FAX: ".$arrInfo['law_fax01']."-".$arrInfo['law_fax02']."-".$arrInfo['law_fax03']; |
|---|
| 119 | } |
|---|
| 120 | $this->lfText(125, 80, $text, 8); //TEL・FAX |
|---|
| 121 | |
|---|
| 122 | if ( strlen($arrInfo['law_email']) > 0 ) { |
|---|
| 123 | $text = "Email: ".$arrInfo['law_email']; |
|---|
| 124 | $this->lfText(125, 83, $text, 8); //Email |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | //ロゴ画像 |
|---|
| 128 | $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png'; |
|---|
| 129 | $this->Image($logo_file, 124, 46, 40); |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | function setMessageData() { |
|---|
| 133 | // メッセージ |
|---|
| 134 | $this->lfText(27, 70, $this->arrData['msg1'], 8); //メッセージ1 |
|---|
| 135 | $this->lfText(27, 74, $this->arrData['msg2'], 8); //メッセージ2 |
|---|
| 136 | $this->lfText(27, 78, $this->arrData['msg3'], 8); //メッセージ3 |
|---|
| 137 | $text = "作成日: ".$this->arrData['year']."年".$this->arrData['month']."月".$this->arrData['day']."日"; |
|---|
| 138 | $this->lfText(158, 288, $text, 8); //作成日 |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | function setOrderData() { |
|---|
| 142 | // DBから受注情報を読み込む |
|---|
| 143 | $this->lfGetOrderData($this->arrData['order_id']); |
|---|
| 144 | |
|---|
| 145 | // 購入者情報 |
|---|
| 146 | $text = "〒 ".$this->arrDisp['order_zip01']." - ".$this->arrDisp['order_zip02']; |
|---|
| 147 | $this->lfText(23, 43, $text, 10); //購入者郵便番号 |
|---|
| 148 | $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01']; |
|---|
| 149 | $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1 |
|---|
| 150 | $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2 |
|---|
| 151 | $text = $this->arrDisp['order_name01']." ".$this->arrDisp['order_name02']." 様"; |
|---|
| 152 | $this->lfText(27, 59, $text, 11); //購入者氏名 |
|---|
| 153 | |
|---|
| 154 | // お届け先情報 |
|---|
| 155 | $this->SetFont('SJIS', '', 10); |
|---|
| 156 | $this->lfText(25, 125, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日 |
|---|
| 157 | $this->lfText(25, 135, $this->arrDisp['order_id'], 10); //注文番号 |
|---|
| 158 | |
|---|
| 159 | $this->SetFont('Gothic', 'B', 15); |
|---|
| 160 | $this->Cell(0, 10, $this->lfConvSjis($this->tpl_title), 0, 2, 'C', 0, ''); //文書タイトル(納品書・請求書) |
|---|
| 161 | $this->Cell(0, 66, '', 0, 2, 'R', 0, ''); |
|---|
| 162 | $this->Cell(5, 0, '', 0, 0, 'R', 0, ''); |
|---|
| 163 | $this->SetFont('SJIS', 'B', 15); |
|---|
| 164 | $this->Cell(67, 8, $this->lfConvSjis(number_format($this->arrDisp['payment_total'])." 円"), 0, 2, 'R', 0, ''); |
|---|
| 165 | $this->Cell(0, 45, '', 0, 2, '', 0, ''); |
|---|
| 166 | |
|---|
| 167 | $this->SetFont('SJIS', '', 8); |
|---|
| 168 | |
|---|
| 169 | $monetary_unit = $this->lfConvSjis("円"); |
|---|
| 170 | $point_unit = $this->lfConvSjis('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_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]); |
|---|
| 180 | |
|---|
| 181 | // 小計(商品毎) |
|---|
| 182 | $data[2] = $data[0] * $data[1]; |
|---|
| 183 | |
|---|
| 184 | $arrOrder[$i][0] = $this->lfConvSjis($this->arrDisp['product_name'][$i]." / "); |
|---|
| 185 | $arrOrder[$i][0] .= $this->lfConvSjis($this->arrDisp['product_code'][$i]." / "); |
|---|
| 186 | if ($this->arrDisp['classcategory_name1'][$i]) { |
|---|
| 187 | $arrOrder[$i][0] .= $this->lfConvSjis(" [ ".$this->arrDisp['classcategory_name1'][$i]); |
|---|
| 188 | if ($this->arrDisp['classcategory_name2'][$i] == "") { |
|---|
| 189 | $arrOrder[$i][0] .= " ]"; |
|---|
| 190 | } else { |
|---|
| 191 | $arrOrder[$i][0] .= $this->lfConvSjis(" * ".$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->lfConvSjis("商品合計"); |
|---|
| 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->lfConvSjis("送料"); |
|---|
| 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->lfConvSjis("手数料"); |
|---|
| 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->lfConvSjis("値引き"); |
|---|
| 227 | $arrOrder[$i][3] = "- ".number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']).$monetary_unit; |
|---|
| 228 | |
|---|
| 229 | $i++; |
|---|
| 230 | $arrOrder[$i][0] = ""; |
|---|
| 231 | $arrOrder[$i][1] = ""; |
|---|
| 232 | $arrOrder[$i][2] = $this->lfConvSjis("請求金額"); |
|---|
| 233 | $arrOrder[$i][3] = number_format($this->arrDisp['payment_total']).$monetary_unit; |
|---|
| 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] = ""; |
|---|
| 241 | $arrOrder[$i][3] = ""; |
|---|
| 242 | |
|---|
| 243 | $i++; |
|---|
| 244 | $arrOrder[$i][0] = ""; |
|---|
| 245 | $arrOrder[$i][1] = ""; |
|---|
| 246 | $arrOrder[$i][2] = $this->lfConvSjis("利用ポイント"); |
|---|
| 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->lfConvSjis("加算ポイント"); |
|---|
| 253 | $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | function setEtcData() { |
|---|
| 260 | $this->Cell(0, 10, '', 0, 1, 'C', 0, ''); |
|---|
| 261 | $this->SetFont('Gothic', 'B', 9); |
|---|
| 262 | $this->MultiCell(0, 6, $this->lfConvSjis("< 備 考 >"), 'T', 2, 'L', 0, ''); //備考 |
|---|
| 263 | $this->Ln(); |
|---|
| 264 | $this->SetFont('SJIS', '', 8); |
|---|
| 265 | $this->MultiCell(0, 4, $this->lfConvSjis($this->arrData['etc1']."\n".$this->arrData['etc2']."\n".$this->arrData['etc3']), '', 2, 'L', 0, ''); //備考 |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | function createPdf() { |
|---|
| 269 | // PDFをブラウザに送信 |
|---|
| 270 | ob_clean(); |
|---|
| 271 | if ($this->pdf_download == 1) { |
|---|
| 272 | if ($this->PageNo() == 1) { |
|---|
| 273 | $filename = "nouhinsyo-No".$this->arrData['order_id'].".pdf"; |
|---|
| 274 | } else { |
|---|
| 275 | $filename = "nouhinsyo.pdf"; |
|---|
| 276 | } |
|---|
| 277 | $this->Output($this->lfConvSjis($filename), 'D'); |
|---|
| 278 | } else { |
|---|
| 279 | $this->Output(); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | // 入力してPDFファイルを閉じる |
|---|
| 283 | $this->Close(); |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | // PDF_Japanese::Text へのパーサー |
|---|
| 287 | function lfText($x, $y, $text, $size = 0, $style = '') { |
|---|
| 288 | // 退避 |
|---|
| 289 | $bak_font_style = $this->FontStyle; |
|---|
| 290 | $bak_font_size = $this->FontSizePt; |
|---|
| 291 | |
|---|
| 292 | $this->SetFont('', $style, $size); |
|---|
| 293 | $this->Text($x, $y, $this->lfConvSjis($text)); |
|---|
| 294 | |
|---|
| 295 | // 復元 |
|---|
| 296 | $this->SetFont('', $bak_font_style, $bak_font_size); |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | // 受注データの取得 |
|---|
| 300 | function lfGetOrderData($order_id) { |
|---|
| 301 | if(SC_Utils_Ex::sfIsInt($order_id)) { |
|---|
| 302 | // DBから受注情報を読み込む |
|---|
| 303 | $objQuery = new SC_Query_Ex(); |
|---|
| 304 | $where = "order_id = ?"; |
|---|
| 305 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
|---|
| 306 | $this->arrDisp = $arrRet[0]; |
|---|
| 307 | list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']); |
|---|
| 308 | $this->arrDisp['point'] = $point; |
|---|
| 309 | |
|---|
| 310 | // 受注詳細データの取得 |
|---|
| 311 | $arrRet = $this->lfGetOrderDetail($order_id); |
|---|
| 312 | $arrRet = SC_Utils_Ex::sfSwapArray($arrRet); |
|---|
| 313 | $this->arrDisp = array_merge($this->arrDisp, $arrRet); |
|---|
| 314 | |
|---|
| 315 | // その他支払い情報を表示 |
|---|
| 316 | if($this->arrDisp["memo02"] != "") $this->arrDisp["payment_info"] = unserialize($this->arrDisp["memo02"]); |
|---|
| 317 | $this->arrDisp["payment_type"] = "お支払い"; |
|---|
| 318 | } |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | // 受注詳細データの取得 |
|---|
| 322 | function lfGetOrderDetail($order_id) { |
|---|
| 323 | $objQuery = new SC_Query_Ex(); |
|---|
| 324 | $col = "product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate"; |
|---|
| 325 | $where = "order_id = ?"; |
|---|
| 326 | $objQuery->setOrder("order_detail_id"); |
|---|
| 327 | $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id)); |
|---|
| 328 | return $arrRet; |
|---|
| 329 | } |
|---|
| 330 | |
|---|
| 331 | // 文字コードSJIS変換 -> japanese.phpで使用出来る文字コードはSJIS-winのみ |
|---|
| 332 | function lfConvSjis($conv_str) { |
|---|
| 333 | return mb_convert_encoding($conv_str, "SJIS-win", CHAR_CODE); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | /** |
|---|
| 337 | * ゴシックフォントを定義 |
|---|
| 338 | * |
|---|
| 339 | * @return void |
|---|
| 340 | */ |
|---|
| 341 | function lfAddGothicFont() { |
|---|
| 342 | $cw = $GLOBALS['SJIS_widths']; |
|---|
| 343 | $c_map = '90msp-RKSJ-H'; |
|---|
| 344 | $registry = array('ordering'=>'Japan1','supplement'=>2); |
|---|
| 345 | $this->AddCIDFonts('Gothic', 'KozGoPro-Medium-Acro,MS-PGothic,Osaka', $cw, $c_map, $registry); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | /** |
|---|
| 349 | * フッター |
|---|
| 350 | * |
|---|
| 351 | * 現状の PDF_Japanese#Footer の動作によって、生成される PDF がエラーとなるケースがあり、 |
|---|
| 352 | * そのエラーを抑える意図。 |
|---|
| 353 | * @return void |
|---|
| 354 | */ |
|---|
| 355 | function Footer() { |
|---|
| 356 | } |
|---|
| 357 | } |
|---|
| 358 | ?> |
|---|