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