[18233] | 1 | <?php |
---|
[17182] | 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[21867] | 5 | * Copyright(c) 2000-2012 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 | |
---|
[21826] | 24 | /** |
---|
| 25 | * PDF 納品書を出力する |
---|
| 26 | * |
---|
| 27 | * TODO ページクラスとすべき要素を多々含んでいるように感じる。 |
---|
[17182] | 28 | */ |
---|
| 29 | |
---|
[19807] | 30 | define('PDF_TEMPLATE_REALDIR', TEMPLATE_ADMIN_REALDIR . 'pdf/'); |
---|
[17182] | 31 | |
---|
[21826] | 32 | class SC_Fpdf extends SC_Helper_FPDI { |
---|
[21767] | 33 | function __construct($download, $title, $tpl_pdf = 'nouhinsyo1.pdf') { |
---|
[21358] | 34 | $this->FPDF(); |
---|
[17182] | 35 | // デフォルトの設定 |
---|
[19807] | 36 | $this->tpl_pdf = PDF_TEMPLATE_REALDIR . $tpl_pdf; // テンプレートファイル |
---|
[17305] | 37 | $this->pdf_download = $download; // PDFのダウンロード形式(0:表示、1:ダウンロード) |
---|
| 38 | $this->tpl_title = $title; |
---|
[20538] | 39 | $this->tpl_dispmode = 'real'; // 表示モード |
---|
[17182] | 40 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[19773] | 41 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
[17182] | 42 | $this->width_cell = array(110.3,12,21.7,24.5); |
---|
| 43 | |
---|
[22408] | 44 | $this->label_cell[] = t('c_Product name / Product code / [Specification]_01'); |
---|
| 45 | $this->label_cell[] = t('c_Quantity_01'); |
---|
| 46 | $this->label_cell[] = t('c_Unit price_01'); |
---|
| 47 | $this->label_cell[] = t('c_Amount with tax_01'); |
---|
[17182] | 48 | |
---|
| 49 | $this->arrMessage = array( |
---|
[22100] | 50 | t('SC_Fpdf_014'), |
---|
| 51 | t('SC_Fpdf_015'), |
---|
| 52 | t('SC_Fpdf_016') |
---|
[17182] | 53 | ); |
---|
| 54 | |
---|
| 55 | // SJISフォント |
---|
[21358] | 56 | $this->AddSJISFont(); |
---|
| 57 | $this->SetFont('SJIS'); |
---|
[17182] | 58 | |
---|
| 59 | //ページ総数取得 |
---|
[21358] | 60 | $this->AliasNbPages(); |
---|
[17182] | 61 | |
---|
| 62 | // マージン設定 |
---|
[21358] | 63 | $this->SetMargins(15, 20); |
---|
[17182] | 64 | |
---|
| 65 | // PDFを読み込んでページ数を取得 |
---|
[21926] | 66 | $this->pageno = $this->setSourceFile($this->tpl_pdf); |
---|
[17305] | 67 | } |
---|
[17182] | 68 | |
---|
[17305] | 69 | function setData($arrData) { |
---|
| 70 | $this->arrData = $arrData; |
---|
| 71 | |
---|
[17182] | 72 | // ページ番号よりIDを取得 |
---|
[21358] | 73 | $tplidx = $this->ImportPage(1); |
---|
[17182] | 74 | |
---|
| 75 | // ページを追加(新規) |
---|
[21358] | 76 | $this->AddPage(); |
---|
[17182] | 77 | |
---|
| 78 | //表示倍率(100%) |
---|
[21358] | 79 | $this->SetDisplayMode($this->tpl_dispmode); |
---|
[17182] | 80 | |
---|
[18097] | 81 | if (SC_Utils_Ex::sfIsInt($arrData['order_id'])) { |
---|
| 82 | $this->disp_mode = true; |
---|
[17182] | 83 | } |
---|
| 84 | |
---|
| 85 | // テンプレート内容の位置、幅を調整 ※useTemplateに引数を与えなければ100%表示がデフォルト |
---|
[21358] | 86 | $this->useTemplate($tplidx); |
---|
[17182] | 87 | |
---|
| 88 | $this->setShopData(); |
---|
| 89 | $this->setMessageData(); |
---|
| 90 | $this->setOrderData(); |
---|
| 91 | $this->setEtcData(); |
---|
[18295] | 92 | |
---|
[17182] | 93 | } |
---|
| 94 | |
---|
| 95 | function setShopData() { |
---|
| 96 | // ショップ情報 |
---|
[18043] | 97 | |
---|
[20013] | 98 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 99 | $arrInfo = $objDb->sfGetBasisData(); |
---|
[17182] | 100 | |
---|
[21719] | 101 | // ショップ名 |
---|
| 102 | $this->lfText(125, 60, $arrInfo['shop_name'], 8, 'B'); |
---|
| 103 | // URL |
---|
| 104 | $this->lfText(125, 63, $arrInfo['law_url'], 8); |
---|
| 105 | // 会社名 |
---|
| 106 | $this->lfText(125, 68, $arrInfo['law_company'], 8); |
---|
| 107 | // 郵便番号 |
---|
[22205] | 108 | // $text = '〒 ' . $arrInfo['law_zip01'] . ' - ' . $arrInfo['law_zip02']; |
---|
[22300] | 109 | $text = t('SC_Fpdf_021') . $arrInfo['law_zipcode']; |
---|
[21719] | 110 | $this->lfText(125, 71, $text, 8); |
---|
| 111 | // 都道府県+所在地 |
---|
| 112 | $text = $this->arrPref[$arrInfo['law_pref']] . $arrInfo['law_addr01']; |
---|
| 113 | $this->lfText(125, 74, $text, 8); |
---|
| 114 | $this->lfText(125, 77, $arrInfo['law_addr02'], 8); |
---|
[18043] | 115 | |
---|
[21515] | 116 | $text = 'TEL: '.$arrInfo['law_tel01'].'-'.$arrInfo['law_tel02'].'-'.$arrInfo['law_tel03']; |
---|
[18097] | 117 | //FAX番号が存在する場合、表示する |
---|
[17909] | 118 | if (strlen($arrInfo['law_fax01']) > 0) { |
---|
[22300] | 119 | $text .= ' FAX: '.$arrInfo['law_fax01'].'-'.$arrInfo['law_fax02'].'-'.$arrInfo['law_fax03']; |
---|
[17305] | 120 | } |
---|
[17182] | 121 | $this->lfText(125, 80, $text, 8); //TEL・FAX |
---|
[17305] | 122 | |
---|
[21442] | 123 | if (strlen($arrInfo['law_email']) > 0) { |
---|
[21514] | 124 | $text = 'Email: '.$arrInfo['law_email']; |
---|
[17305] | 125 | $this->lfText(125, 83, $text, 8); //Email |
---|
| 126 | } |
---|
[18016] | 127 | |
---|
| 128 | //ロゴ画像 |
---|
[19807] | 129 | $logo_file = PDF_TEMPLATE_REALDIR . 'logo.png'; |
---|
[21358] | 130 | $this->Image($logo_file, 124, 46, 40); |
---|
[17182] | 131 | } |
---|
| 132 | |
---|
| 133 | function setMessageData() { |
---|
| 134 | // メッセージ |
---|
| 135 | $this->lfText(27, 70, $this->arrData['msg1'], 8); //メッセージ1 |
---|
| 136 | $this->lfText(27, 74, $this->arrData['msg2'], 8); //メッセージ2 |
---|
| 137 | $this->lfText(27, 78, $this->arrData['msg3'], 8); //メッセージ3 |
---|
[22030] | 138 | $tokens = array( |
---|
| 139 | 'T_YEAR' => $this->arrData['year'], |
---|
| 140 | 'T_MONTH' => $this->arrData['month'], |
---|
| 141 | 'T_DAY' => $this->arrData['day'] |
---|
| 142 | ); |
---|
[22100] | 143 | $text = t('SC_Fpdf_017', $tokens); |
---|
[17182] | 144 | $this->lfText(158, 288, $text, 8); //作成日 |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | function setOrderData() { |
---|
[21926] | 148 | $arrOrder = array(); |
---|
[17182] | 149 | // DBから受注情報を読み込む |
---|
| 150 | $this->lfGetOrderData($this->arrData['order_id']); |
---|
| 151 | |
---|
| 152 | // 購入者情報 |
---|
[22205] | 153 | // $text = '〒 '.$this->arrDisp['order_zip01'].' - '.$this->arrDisp['order_zip02']; |
---|
[22300] | 154 | $text = t('SC_Fpdf_021') . $this->arrDisp['order_zipcode']; |
---|
[17182] | 155 | $this->lfText(23, 43, $text, 10); //購入者郵便番号 |
---|
| 156 | $text = $this->arrPref[$this->arrDisp['order_pref']] . $this->arrDisp['order_addr01']; |
---|
| 157 | $this->lfText(27, 47, $text, 10); //購入者都道府県+住所1 |
---|
| 158 | $this->lfText(27, 51, $this->arrDisp['order_addr02'], 10); //購入者住所2 |
---|
[22300] | 159 | $text = t('SC_Fpdf_018', array('T_LASTNAME' => $this->arrDisp['order_name01'], 'T_FIRSTNAME' => $this->arrDisp['order_name02'])); |
---|
[17182] | 160 | $this->lfText(27, 59, $text, 11); //購入者氏名 |
---|
| 161 | |
---|
| 162 | // お届け先情報 |
---|
[21358] | 163 | $this->SetFont('SJIS', '', 10); |
---|
[20013] | 164 | $this->lfText(25, 125, SC_Utils_Ex::sfDispDBDate($this->arrDisp['create_date']), 10); //ご注文日 |
---|
| 165 | $this->lfText(25, 135, $this->arrDisp['order_id'], 10); //注文番号 |
---|
[17182] | 166 | |
---|
[21358] | 167 | $this->SetFont('Gothic', 'B', 15); |
---|
[21826] | 168 | $this->Cell(0, 10, $this->tpl_title, 0, 2, 'C', 0, ''); //文書タイトル(納品書・請求書) |
---|
[21358] | 169 | $this->Cell(0, 66, '', 0, 2, 'R', 0, ''); |
---|
| 170 | $this->Cell(5, 0, '', 0, 0, 'R', 0, ''); |
---|
| 171 | $this->SetFont('SJIS', 'B', 15); |
---|
[22300] | 172 | $this->Cell(67, 8, t('SC_Fpdf_019', array('T_FIELD' => number_format($this->arrDisp['payment_total']))), 0, 2, 'R', 0, ''); |
---|
[21358] | 173 | $this->Cell(0, 45, '', 0, 2, '', 0, ''); |
---|
[17182] | 174 | |
---|
[21358] | 175 | $this->SetFont('SJIS', '', 8); |
---|
[17182] | 176 | |
---|
[22100] | 177 | $point_unit = t('SC_Fpdf_020'); |
---|
[17182] | 178 | |
---|
| 179 | // 購入商品情報 |
---|
| 180 | for ($i = 0; $i < count($this->arrDisp['quantity']); $i++) { |
---|
| 181 | |
---|
[18097] | 182 | // 購入数量 |
---|
| 183 | $data[0] = $this->arrDisp['quantity'][$i]; |
---|
[17182] | 184 | |
---|
[18097] | 185 | // 税込金額(単価) |
---|
[19680] | 186 | $data[1] = SC_Helper_DB_Ex::sfCalcIncTax($this->arrDisp['price'][$i]); |
---|
[17182] | 187 | |
---|
[18097] | 188 | // 小計(商品毎) |
---|
| 189 | $data[2] = $data[0] * $data[1]; |
---|
[17182] | 190 | |
---|
[21826] | 191 | $arrOrder[$i][0] = $this->arrDisp['product_name'][$i].' / '; |
---|
| 192 | $arrOrder[$i][0] .= $this->arrDisp['product_code'][$i].' / '; |
---|
[18097] | 193 | if ($this->arrDisp['classcategory_name1'][$i]) { |
---|
[21826] | 194 | $arrOrder[$i][0] .= ' [ '.$this->arrDisp['classcategory_name1'][$i]; |
---|
[21514] | 195 | if ($this->arrDisp['classcategory_name2'][$i] == '') { |
---|
| 196 | $arrOrder[$i][0] .= ' ]'; |
---|
[18097] | 197 | } else { |
---|
[21826] | 198 | $arrOrder[$i][0] .= ' * '.$this->arrDisp['classcategory_name2'][$i].' ]'; |
---|
[18097] | 199 | } |
---|
[17182] | 200 | } |
---|
[18097] | 201 | $arrOrder[$i][1] = number_format($data[0]); |
---|
[22300] | 202 | $arrOrder[$i][2] = t('SC_Fpdf_019', array('T_FIELD' => number_format($data[1]))); |
---|
| 203 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => number_format($data[2]))); |
---|
[17182] | 204 | |
---|
| 205 | } |
---|
| 206 | |
---|
[21514] | 207 | $arrOrder[$i][0] = ''; |
---|
| 208 | $arrOrder[$i][1] = ''; |
---|
| 209 | $arrOrder[$i][2] = ''; |
---|
| 210 | $arrOrder[$i][3] = ''; |
---|
[17182] | 211 | |
---|
| 212 | $i++; |
---|
[21514] | 213 | $arrOrder[$i][0] = ''; |
---|
| 214 | $arrOrder[$i][1] = ''; |
---|
[22408] | 215 | $arrOrder[$i][2] = t('c_Product total_01'); |
---|
[22300] | 216 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => number_format($this->arrDisp['subtotal']))); |
---|
[17182] | 217 | |
---|
| 218 | $i++; |
---|
[21514] | 219 | $arrOrder[$i][0] = ''; |
---|
| 220 | $arrOrder[$i][1] = ''; |
---|
[22408] | 221 | $arrOrder[$i][2] = t('c_Shipping fee_01'); |
---|
[22300] | 222 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => number_format($this->arrDisp['deliv_fee']))); |
---|
[17182] | 223 | |
---|
| 224 | $i++; |
---|
[21514] | 225 | $arrOrder[$i][0] = ''; |
---|
| 226 | $arrOrder[$i][1] = ''; |
---|
[22408] | 227 | $arrOrder[$i][2] = t('c_Processing fee_01'); |
---|
[22300] | 228 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => number_format($this->arrDisp['charge']))); |
---|
[17182] | 229 | |
---|
| 230 | $i++; |
---|
[21514] | 231 | $arrOrder[$i][0] = ''; |
---|
| 232 | $arrOrder[$i][1] = ''; |
---|
[22100] | 233 | $arrOrder[$i][2] = t('SC_Fpdf_008'); |
---|
[22300] | 234 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => '- '.number_format(($this->arrDisp['use_point'] * POINT_VALUE) + $this->arrDisp['discount']))); |
---|
[17182] | 235 | |
---|
| 236 | $i++; |
---|
[21514] | 237 | $arrOrder[$i][0] = ''; |
---|
| 238 | $arrOrder[$i][1] = ''; |
---|
[22100] | 239 | $arrOrder[$i][2] = t('SC_Fpdf_009'); |
---|
[22300] | 240 | $arrOrder[$i][3] = t('SC_Fpdf_019', array('T_FIELD' => number_format($this->arrDisp['payment_total']))); |
---|
[17182] | 241 | |
---|
| 242 | // ポイント表記 |
---|
| 243 | if ($this->arrData['disp_point'] && $this->arrDisp['customer_id']) { |
---|
[18097] | 244 | $i++; |
---|
[21514] | 245 | $arrOrder[$i][0] = ''; |
---|
| 246 | $arrOrder[$i][1] = ''; |
---|
| 247 | $arrOrder[$i][2] = ''; |
---|
| 248 | $arrOrder[$i][3] = ''; |
---|
[17182] | 249 | |
---|
[18097] | 250 | $i++; |
---|
[21514] | 251 | $arrOrder[$i][0] = ''; |
---|
| 252 | $arrOrder[$i][1] = ''; |
---|
[22100] | 253 | $arrOrder[$i][2] = t('SC_Fpdf_010'); |
---|
[18097] | 254 | $arrOrder[$i][3] = number_format($this->arrDisp['use_point']).$point_unit; |
---|
[17182] | 255 | |
---|
[18097] | 256 | $i++; |
---|
[21514] | 257 | $arrOrder[$i][0] = ''; |
---|
| 258 | $arrOrder[$i][1] = ''; |
---|
[22100] | 259 | $arrOrder[$i][2] = t('SC_Fpdf_011'); |
---|
[18097] | 260 | $arrOrder[$i][3] = number_format($this->arrDisp['add_point']).$point_unit; |
---|
[17182] | 261 | } |
---|
| 262 | |
---|
[21358] | 263 | $this->FancyTable($this->label_cell, $arrOrder, $this->width_cell); |
---|
[17182] | 264 | } |
---|
| 265 | |
---|
[22058] | 266 | /** |
---|
| 267 | * 備考の出力を行う |
---|
| 268 | * |
---|
| 269 | * @param string $str 入力文字列 |
---|
| 270 | * @return string 変更後の文字列 |
---|
| 271 | */ |
---|
[17182] | 272 | function setEtcData() { |
---|
[21358] | 273 | $this->Cell(0, 10, '', 0, 1, 'C', 0, ''); |
---|
| 274 | $this->SetFont('Gothic', 'B', 9); |
---|
[22100] | 275 | $this->MultiCell(0, 6, t('SC_Fpdf_012'), 'T', 2, 'L', 0, ''); //備考 |
---|
[21358] | 276 | $this->SetFont('SJIS', '', 8); |
---|
[22058] | 277 | $text = SC_Utils_Ex::rtrim($this->arrData['etc1'] . "\n" . $this->arrData['etc2'] . "\n" . $this->arrData['etc3']); |
---|
| 278 | $this->MultiCell(0, 4, $text, '', 2, 'L', 0, ''); |
---|
[17182] | 279 | } |
---|
| 280 | |
---|
| 281 | function createPdf() { |
---|
| 282 | // PDFをブラウザに送信 |
---|
[18097] | 283 | ob_clean(); |
---|
| 284 | if ($this->pdf_download == 1) { |
---|
[21358] | 285 | if ($this->PageNo() == 1) { |
---|
[21515] | 286 | $filename = 'nouhinsyo-No'.$this->arrData['order_id'].'.pdf'; |
---|
[18097] | 287 | } else { |
---|
[21514] | 288 | $filename = 'nouhinsyo.pdf'; |
---|
[18097] | 289 | } |
---|
[21358] | 290 | $this->Output($this->lfConvSjis($filename), 'D'); |
---|
[17182] | 291 | } else { |
---|
[21358] | 292 | $this->Output(); |
---|
[17182] | 293 | } |
---|
| 294 | |
---|
| 295 | // 入力してPDFファイルを閉じる |
---|
[21358] | 296 | $this->Close(); |
---|
[17182] | 297 | } |
---|
| 298 | |
---|
| 299 | // PDF_Japanese::Text へのパーサー |
---|
[21024] | 300 | function lfText($x, $y, $text, $size = 0, $style = '') { |
---|
| 301 | // 退避 |
---|
[21358] | 302 | $bak_font_style = $this->FontStyle; |
---|
| 303 | $bak_font_size = $this->FontSizePt; |
---|
[17182] | 304 | |
---|
[21358] | 305 | $this->SetFont('', $style, $size); |
---|
[21826] | 306 | $this->Text($x, $y, $text); |
---|
[21024] | 307 | |
---|
| 308 | // 復元 |
---|
[21358] | 309 | $this->SetFont('', $bak_font_style, $bak_font_size); |
---|
[17182] | 310 | } |
---|
| 311 | |
---|
| 312 | // 受注データの取得 |
---|
| 313 | function lfGetOrderData($order_id) { |
---|
[21441] | 314 | if (SC_Utils_Ex::sfIsInt($order_id)) { |
---|
[17182] | 315 | // DBから受注情報を読み込む |
---|
[21750] | 316 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21514] | 317 | $where = 'order_id = ?'; |
---|
| 318 | $arrRet = $objQuery->select('*', 'dtb_order', $where, array($order_id)); |
---|
[17182] | 319 | $this->arrDisp = $arrRet[0]; |
---|
[19864] | 320 | list($point) = SC_Helper_Customer_Ex::sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']); |
---|
[18097] | 321 | $this->arrDisp['point'] = $point; |
---|
[17182] | 322 | |
---|
| 323 | // 受注詳細データの取得 |
---|
| 324 | $arrRet = $this->lfGetOrderDetail($order_id); |
---|
| 325 | $arrRet = SC_Utils_Ex::sfSwapArray($arrRet); |
---|
| 326 | $this->arrDisp = array_merge($this->arrDisp, $arrRet); |
---|
| 327 | |
---|
| 328 | // その他支払い情報を表示 |
---|
[21684] | 329 | if ($this->arrDisp['memo02'] != '') { |
---|
| 330 | $this->arrDisp['payment_info'] = unserialize($this->arrDisp['memo02']); |
---|
| 331 | } |
---|
[22100] | 332 | $this->arrDisp['payment_type'] = t('SC_Fpdf_013'); |
---|
[17182] | 333 | } |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | // 受注詳細データの取得 |
---|
| 337 | function lfGetOrderDetail($order_id) { |
---|
[21750] | 338 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21514] | 339 | $col = 'product_id, product_class_id, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate'; |
---|
| 340 | $where = 'order_id = ?'; |
---|
[21481] | 341 | $objQuery->setOrder('order_detail_id'); |
---|
| 342 | $arrRet = $objQuery->select($col, 'dtb_order_detail', $where, array($order_id)); |
---|
[18097] | 343 | return $arrRet; |
---|
[17182] | 344 | } |
---|
| 345 | } |
---|