[15594] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
[15594] | 6 | * |
---|
| 7 | * http://www.lockon.co.jp/ |
---|
[16582] | 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. |
---|
[15594] | 22 | */ |
---|
| 23 | |
---|
| 24 | // {{{ requires |
---|
[19805] | 25 | require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); |
---|
[15594] | 26 | |
---|
| 27 | /** |
---|
| 28 | * 受注修正 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
| 32 | * @version $Id$ |
---|
| 33 | */ |
---|
[19661] | 34 | class LC_Page_Admin_Order_Edit extends LC_Page_Admin { |
---|
[15594] | 35 | |
---|
| 36 | // {{{ properties |
---|
| 37 | |
---|
| 38 | /** 表示モード */ |
---|
| 39 | var $disp_mode; |
---|
| 40 | |
---|
| 41 | // }}} |
---|
| 42 | // {{{ functions |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Page を初期化する. |
---|
| 46 | * |
---|
| 47 | * @return void |
---|
| 48 | */ |
---|
| 49 | function init() { |
---|
| 50 | parent::init(); |
---|
| 51 | $this->tpl_mainpage = 'order/edit.tpl'; |
---|
[17293] | 52 | $this->tpl_subnavi = 'order/subnavi.tpl'; |
---|
| 53 | $this->tpl_mainno = 'order'; |
---|
| 54 | $this->tpl_subno = 'index'; |
---|
| 55 | $this->tpl_subtitle = '受注管理'; |
---|
| 56 | if (empty($_GET['order_id']) && empty($_POST['order_id'])) { |
---|
| 57 | $this->tpl_subno = 'add'; |
---|
| 58 | $this->tpl_mode = 'add'; |
---|
| 59 | $this->tpl_subtitle = '新規受注入力'; |
---|
| 60 | } |
---|
[15594] | 61 | |
---|
| 62 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[19773] | 63 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
[17293] | 64 | $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status"); |
---|
[17886] | 65 | |
---|
[18187] | 66 | $this->httpCacheControl('nocache'); |
---|
[15594] | 67 | } |
---|
| 68 | |
---|
| 69 | /** |
---|
| 70 | * Page のプロセス. |
---|
| 71 | * |
---|
| 72 | * @return void |
---|
| 73 | */ |
---|
| 74 | function process() { |
---|
[19661] | 75 | $this->action(); |
---|
| 76 | $this->sendResponse(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * Page のアクション. |
---|
| 81 | * |
---|
| 82 | * @return void |
---|
| 83 | */ |
---|
| 84 | function action() { |
---|
[15594] | 85 | $objSess = new SC_Session(); |
---|
| 86 | $objDb = new SC_Helper_DB_Ex(); |
---|
[19923] | 87 | $objDate = new SC_Date(1970); |
---|
| 88 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
| 89 | $this->arrYearShippingDate = $objDate->getYear('', date('Y'), ''); |
---|
| 90 | $this->arrMonthShippingDate = $objDate->getMonth(true); |
---|
| 91 | $this->arrDayShippingDate = $objDate->getDay(true); |
---|
[15594] | 92 | |
---|
| 93 | // パラメータ管理クラス |
---|
| 94 | $this->objFormParam = new SC_FormParam(); |
---|
| 95 | // パラメータ情報の初期化 |
---|
| 96 | $this->lfInitParam(); |
---|
| 97 | |
---|
| 98 | // 認証可否の判定 |
---|
| 99 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
| 100 | |
---|
| 101 | // 検索パラメータの引き継ぎ |
---|
| 102 | foreach ($_POST as $key => $val) { |
---|
| 103 | if (ereg("^search_", $key)) { |
---|
| 104 | $this->arrSearchHidden[$key] = $val; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | // 表示モード判定 |
---|
| 109 | if(isset($_GET['order_id']) && |
---|
| 110 | SC_Utils_Ex::sfIsInt($_GET['order_id'])) { |
---|
| 111 | $this->disp_mode = true; |
---|
| 112 | $order_id = $_GET['order_id']; |
---|
| 113 | } else { |
---|
| 114 | $order_id = $_POST['order_id']; |
---|
| 115 | } |
---|
| 116 | $this->tpl_order_id = $order_id; |
---|
| 117 | |
---|
| 118 | // DBから受注情報を読み込む |
---|
| 119 | $this->lfGetOrderData($order_id); |
---|
| 120 | |
---|
| 121 | switch($_POST['mode']) { |
---|
| 122 | case 'pre_edit': |
---|
| 123 | case 'order_id': |
---|
| 124 | break; |
---|
| 125 | case 'edit': |
---|
[17293] | 126 | case 'add': |
---|
[15594] | 127 | // POST情報で上書き |
---|
| 128 | $this->objFormParam->setParam($_POST); |
---|
| 129 | |
---|
| 130 | // 入力値の変換 |
---|
| 131 | $this->objFormParam->convParam(); |
---|
[18087] | 132 | $this->arrErr = $this->lfCheckError(); |
---|
[18055] | 133 | |
---|
[15594] | 134 | if(count($this->arrErr) == 0) { |
---|
[18068] | 135 | if ($_POST['mode'] == 'add') { |
---|
[18100] | 136 | $order_id = $this->lfRegistNewData(); |
---|
[18068] | 137 | |
---|
[18100] | 138 | $this->tpl_order_id = $order_id; |
---|
| 139 | $this->tpl_mode = 'edit'; |
---|
[18068] | 140 | |
---|
[18100] | 141 | $arrData['order_id'] = $order_id; |
---|
| 142 | $this->objFormParam->setParam($arrData); |
---|
[18068] | 143 | |
---|
| 144 | $text = "'新規受注を登録しました。'"; |
---|
| 145 | } else { |
---|
| 146 | $this->lfRegistData($_POST['order_id']); |
---|
| 147 | $text = "'受注履歴を編集しました。'"; |
---|
| 148 | } |
---|
| 149 | // DBから受注情報を再読込 |
---|
| 150 | $this->lfGetOrderData($order_id); |
---|
| 151 | $this->tpl_onload = "window.alert(".$text.");"; |
---|
[15594] | 152 | } |
---|
| 153 | break; |
---|
| 154 | // 再計算 |
---|
| 155 | case 'cheek': |
---|
[18464] | 156 | //支払い方法の選択 |
---|
| 157 | case 'payment': |
---|
[15594] | 158 | // POST情報で上書き |
---|
| 159 | $this->objFormParam->setParam($_POST); |
---|
| 160 | // 入力値の変換 |
---|
| 161 | $this->objFormParam->convParam(); |
---|
[18087] | 162 | $this->arrErr = $this->lfCheckError(); |
---|
[15594] | 163 | break; |
---|
[19912] | 164 | |
---|
[18037] | 165 | /* 商品削除*/ |
---|
| 166 | case 'delete_product': |
---|
| 167 | $delete_no = $_POST['delete_no']; |
---|
| 168 | foreach ($_POST AS $key=>$val) { |
---|
| 169 | if (is_array($val)) { |
---|
| 170 | foreach ($val AS $k=>$v) { |
---|
| 171 | if ($k != $delete_no) { |
---|
| 172 | $arrData[$key][] = $v; |
---|
| 173 | } |
---|
| 174 | } |
---|
| 175 | } else { |
---|
| 176 | $arrData[$key] = $val; |
---|
| 177 | } |
---|
| 178 | } |
---|
[18055] | 179 | // 情報上書き |
---|
| 180 | $this->objFormParam->setParam($arrData); |
---|
| 181 | // 入力値の変換 |
---|
| 182 | $this->objFormParam->convParam(); |
---|
[18087] | 183 | $this->arrErr = $this->lfCheckError(); |
---|
[18037] | 184 | break; |
---|
| 185 | /* 商品追加ポップアップより商品選択後、商品情報取得*/ |
---|
| 186 | case 'select_product_detail': |
---|
| 187 | // POST情報で上書き |
---|
| 188 | $this->objFormParam->setParam($_POST); |
---|
[18875] | 189 | if (!empty($_POST['add_product_class_id'])) { |
---|
| 190 | $this->lfInsertProduct($_POST['add_product_class_id']); |
---|
| 191 | } elseif (!empty($_POST['edit_product_class_id'])) { |
---|
| 192 | $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']); |
---|
[18037] | 193 | } |
---|
| 194 | $arrData = $_POST; |
---|
| 195 | foreach ($this->arrForm AS $key=>$val) { |
---|
| 196 | if (is_array($val)) { |
---|
| 197 | $arrData[$key] = $this->arrForm[$key]['value']; |
---|
| 198 | } else { |
---|
| 199 | $arrData[$key] = $val; |
---|
| 200 | } |
---|
| 201 | } |
---|
[18055] | 202 | // 情報上書き |
---|
| 203 | $this->objFormParam->setParam($arrData); |
---|
| 204 | // 入力値の変換 |
---|
| 205 | $this->objFormParam->convParam(); |
---|
[18087] | 206 | $this->arrErr = $this->lfCheckError(); |
---|
[18037] | 207 | break; |
---|
[18068] | 208 | /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/ |
---|
| 209 | case 'search_customer': |
---|
| 210 | // POST情報で上書き |
---|
| 211 | $this->objFormParam->setParam($_POST); |
---|
| 212 | |
---|
| 213 | // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
| 214 | $this->lfSetCustomerInfo($_POST['edit_customer_id']); |
---|
| 215 | |
---|
| 216 | break; |
---|
[17887] | 217 | |
---|
[19934] | 218 | // 複数配送設定表示 |
---|
| 219 | case 'multiple': |
---|
| 220 | $this->objFormParam->setParam($_POST); |
---|
| 221 | $this->tpl_onload = "win03('" . URL_PATH . ADMIN_DIR . "order/multiple.php', 'multiple', '600', '500');"; |
---|
| 222 | break; |
---|
| 223 | |
---|
| 224 | // 複数配送設定を反映 |
---|
| 225 | case 'multiple_set_to': |
---|
| 226 | $multipleSize = $_POST['multiple_size']; |
---|
| 227 | $this->lfInitMultipleParam($multipleSize); |
---|
| 228 | $this->objFormParam->setParam($_POST); |
---|
| 229 | $this->setMultipleItemTo($multipleSize); |
---|
| 230 | break; |
---|
[15594] | 231 | default: |
---|
| 232 | break; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | // 支払い方法の取得 |
---|
| 236 | $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method"); |
---|
| 237 | |
---|
| 238 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
[19923] | 239 | // XXX 商品種別IDは0番目の配列を使用 |
---|
| 240 | $this->product_type_id = $this->arrForm['product_type_id']['value'][0]; |
---|
| 241 | $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id); |
---|
[17293] | 242 | $this->product_count = count($this->arrForm['quantity']['value']); |
---|
[15594] | 243 | |
---|
[17293] | 244 | // アンカーを設定 |
---|
| 245 | if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
| 246 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
| 247 | } else { |
---|
| 248 | $anchor_hash = ""; |
---|
| 249 | } |
---|
| 250 | $this->tpl_onload .= $anchor_hash; |
---|
| 251 | |
---|
[18052] | 252 | $objSiteInfo = new SC_SiteInfo(); |
---|
| 253 | $this->arrInfo = $objSiteInfo->data; |
---|
[15594] | 254 | |
---|
| 255 | // 表示モード判定 |
---|
| 256 | if(!$this->disp_mode) { |
---|
[19661] | 257 | $this->setTemplate(MAIN_FRAME); |
---|
[15594] | 258 | } else { |
---|
[19661] | 259 | $this->setTemplate('order/disp.tpl'); |
---|
[15594] | 260 | } |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | /** |
---|
| 264 | * デストラクタ. |
---|
| 265 | * |
---|
| 266 | * @return void |
---|
| 267 | */ |
---|
| 268 | function destroy() { |
---|
| 269 | parent::destroy(); |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | /* パラメータ情報の初期化 */ |
---|
| 273 | function lfInitParam() { |
---|
[18037] | 274 | |
---|
[17508] | 275 | // お客様情報 |
---|
| 276 | $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 277 | $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 278 | $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 279 | $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 280 | $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 281 | $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
| 282 | $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
| 283 | $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
[18642] | 284 | $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 285 | $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
[17508] | 286 | $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
| 287 | $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
| 288 | $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
[17293] | 289 | |
---|
[15594] | 290 | // 受注商品情報 |
---|
| 291 | $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[18308] | 292 | $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[19919] | 293 | $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[18054] | 294 | |
---|
| 295 | // ポイント機能ON時のみ |
---|
| 296 | if (USE_POINT !== false) { |
---|
| 297 | $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 298 | } |
---|
| 299 | |
---|
[15594] | 300 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 301 | $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 302 | $this->objFormParam->addParam("お支払方法名称", "payment_method"); |
---|
| 303 | |
---|
[19912] | 304 | |
---|
[15594] | 305 | // 受注詳細情報 |
---|
[19923] | 306 | $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[15594] | 307 | $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[17444] | 308 | $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[15594] | 309 | $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[18872] | 310 | $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
[15594] | 311 | $this->objFormParam->addParam("ポイント付与率", "point_rate"); |
---|
| 312 | $this->objFormParam->addParam("商品コード", "product_code"); |
---|
| 313 | $this->objFormParam->addParam("商品名", "product_name"); |
---|
| 314 | $this->objFormParam->addParam("規格名1", "classcategory_name1"); |
---|
| 315 | $this->objFormParam->addParam("規格名2", "classcategory_name2"); |
---|
| 316 | $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
| 317 | // DB読込用 |
---|
| 318 | $this->objFormParam->addParam("小計", "subtotal"); |
---|
| 319 | $this->objFormParam->addParam("合計", "total"); |
---|
| 320 | $this->objFormParam->addParam("支払い合計", "payment_total"); |
---|
| 321 | $this->objFormParam->addParam("加算ポイント", "add_point"); |
---|
| 322 | $this->objFormParam->addParam("お誕生日ポイント", "birth_point"); |
---|
| 323 | $this->objFormParam->addParam("消費税合計", "tax"); |
---|
| 324 | $this->objFormParam->addParam("最終保持ポイント", "total_point"); |
---|
| 325 | $this->objFormParam->addParam("顧客ID", "customer_id"); |
---|
| 326 | $this->objFormParam->addParam("現在のポイント", "point"); |
---|
[17994] | 327 | $this->objFormParam->addParam("注文番号", "order_id"); |
---|
[17293] | 328 | $this->objFormParam->addParam("受注日", "create_date"); |
---|
[18068] | 329 | $this->objFormParam->addParam("発送日", "commit_date"); |
---|
[18136] | 330 | $this->objFormParam->addParam("備考", "message"); |
---|
[18819] | 331 | $this->objFormParam->addParam("入金日", "payment_date"); |
---|
[15594] | 332 | } |
---|
| 333 | |
---|
[19919] | 334 | /** |
---|
| 335 | * お届け先用フォームの初期化 |
---|
| 336 | */ |
---|
| 337 | function lfInitShippingParam(&$arrShipping) { |
---|
| 338 | $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 339 | foreach ($arrShipping as $shipping) { |
---|
| 340 | $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 341 | $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 342 | $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 343 | $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 344 | $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 345 | $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
| 346 | $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
| 347 | $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 348 | $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 349 | $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 350 | $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
| 351 | $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
| 352 | $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
[19923] | 353 | $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 354 | $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']); |
---|
| 355 | $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 356 | $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 357 | $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 358 | $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
[19919] | 359 | $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 360 | foreach ($shipping['shipment_item'] as $productClassId => $item) { |
---|
| 361 | $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 362 | $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
| 363 | $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
| 364 | $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
| 365 | $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId); |
---|
| 366 | $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
| 367 | $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | |
---|
[19934] | 372 | /** |
---|
| 373 | * 複数配送用フォームの初期化 |
---|
| 374 | */ |
---|
| 375 | function lfInitMultipleParam($size) { |
---|
| 376 | for ($i = 0; $i < $size; $i++) { |
---|
| 377 | $this->objFormParam->addParam("商品規格ID", "multiple_product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 378 | $this->objFormParam->addParam("商品コード", "multiple_product_code" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 379 | $this->objFormParam->addParam("商品名", "multiple_product_name" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 380 | $this->objFormParam->addParam("規格1", "multiple_classcategory_name1" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 381 | $this->objFormParam->addParam("規格2", "multiple_classcategory_name2" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 382 | $this->objFormParam->addParam("単価", "multiple_price" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 383 | $this->objFormParam->addParam("数量", "multiple_quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1); |
---|
| 384 | $this->objFormParam->addParam("配送先住所", "multiple_shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 385 | } |
---|
| 386 | } |
---|
[19919] | 387 | |
---|
[19934] | 388 | |
---|
| 389 | function setMultipleItemTo($size) { |
---|
| 390 | $arrShipmentItem = array(); |
---|
| 391 | for ($i = 0; $i < $size; $i++) { |
---|
| 392 | $shippingId = $this->objFormParam->getValue('multiple_shipping' . $i); |
---|
| 393 | $productClassId = $this->objFormParam->getValue('multiple_product_class_id' . $i); |
---|
| 394 | |
---|
| 395 | $name = $this->objFormParam->getValue('multiple_product_name' . $i); |
---|
| 396 | $code = $this->objFormParam->getValue('multiple_product_code' . $i); |
---|
| 397 | $class1 = $this->objFormParam->getValue('multiple_classcategory_name1' . $i); |
---|
| 398 | $class2 = $this->objFormParam->getValue('multiple_classcategory_name2' . $i); |
---|
| 399 | $price = $this->objFormParam->getValue('multiple_price' . $i); |
---|
| 400 | $quantity = $this->objFormParam->getValue('multiple_quantity' . $i); |
---|
| 401 | |
---|
| 402 | $arrShipmentItem[$shippingId][$productClassId]['shipping_id'] = $shippingId; |
---|
| 403 | $arrShipmentItem[$shippingId][$productClassId]['product_class_id'] = $productClassId; |
---|
| 404 | $arrShipmentItem[$shippingId][$productClassId]['classcategory_name1'] = $class1; |
---|
| 405 | $arrShipmentItem[$shippingId][$productClassId]['classcategory_name2'] = $class2; |
---|
| 406 | $arrShipmentItem[$shippingId][$productClassId]['price'] = $price; |
---|
| 407 | $arrShipmentItem[$shippingId][$productClassId]['quantity'] += $quantity; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | $this->arrShippingIds = array(); |
---|
| 411 | $this->arrProductClassIds = array(); |
---|
| 412 | foreach ($arrShipmentItem as $shippingId => $items) { |
---|
| 413 | |
---|
[19935] | 414 | $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shippingId, count($items)); |
---|
[19934] | 415 | |
---|
| 416 | $this->arrShippingIds[] = $shippingId; |
---|
| 417 | $this->arrProductClassIds[] = array_keys($items); |
---|
| 418 | |
---|
| 419 | foreach ($items as $productClassId => $item) { |
---|
| 420 | foreach ($item as $itemKey => $itemVal) { |
---|
| 421 | $this->objFormParam->setValue($itemKey . '_' . $shippingId . '_' . $productClassId, $itemVal); |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | } |
---|
| 425 | } |
---|
| 426 | |
---|
[15594] | 427 | function lfGetOrderData($order_id) { |
---|
| 428 | if(SC_Utils_Ex::sfIsInt($order_id)) { |
---|
| 429 | // DBから受注情報を読み込む |
---|
| 430 | $objQuery = new SC_Query(); |
---|
| 431 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 432 | $where = "order_id = ?"; |
---|
| 433 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
---|
| 434 | $this->objFormParam->setParam($arrRet[0]); |
---|
[19919] | 435 | list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']); |
---|
[19674] | 436 | $this->objFormParam->setValue('total_point', $db_point); |
---|
| 437 | $this->objFormParam->setValue('point', $rollback_point); |
---|
[17293] | 438 | $this->arrForm = $arrRet[0]; |
---|
[18235] | 439 | |
---|
[15594] | 440 | // 受注詳細データの取得 |
---|
| 441 | $arrRet = $this->lfGetOrderDetail($order_id); |
---|
| 442 | $arrRet = SC_Utils_Ex::sfSwapArray($arrRet); |
---|
[17293] | 443 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
[15594] | 444 | $this->objFormParam->setParam($arrRet); |
---|
| 445 | |
---|
[19912] | 446 | $this->arrShipping = $this->lfGetShippingData($order_id); |
---|
| 447 | $this->lfInitShippingParam($this->arrShipping); |
---|
[19919] | 448 | |
---|
[19935] | 449 | $this->objFormParam->setValue('shipping_quantity', count($this->arrShipping)); |
---|
[19919] | 450 | |
---|
[19923] | 451 | // 配送情報の処理 |
---|
[19912] | 452 | foreach ($this->arrShipping as $shipping) { |
---|
[19919] | 453 | |
---|
| 454 | $this->arrShippingIds[] = $shipping['shipping_id']; |
---|
| 455 | $this->arrProductClassIds[] = array_keys($shipping['shipment_item']); |
---|
[19923] | 456 | |
---|
| 457 | // お届け日の取得 |
---|
[19928] | 458 | if (!SC_Utils_Ex::isBlank($shipping["shipping_date"])) { |
---|
| 459 | $ts = strtotime($shipping["shipping_date"]); |
---|
| 460 | $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts)); |
---|
| 461 | $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts)); |
---|
| 462 | $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts)); |
---|
| 463 | } |
---|
[19923] | 464 | |
---|
| 465 | // 配送内容の処理 |
---|
[19912] | 466 | foreach ($shipping as $shippingKey => $shippingVal) { |
---|
[19919] | 467 | |
---|
| 468 | $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal); |
---|
| 469 | |
---|
[19935] | 470 | $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'], count($shipping['shipment_item'])); |
---|
[19919] | 471 | |
---|
[19923] | 472 | // 配送商品の処理 |
---|
[19919] | 473 | foreach ($shipping['shipment_item'] as $productClassId => $item) { |
---|
| 474 | foreach ($item as $itemKey => $itemVal) { |
---|
| 475 | $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal); |
---|
| 476 | } |
---|
| 477 | } |
---|
[19912] | 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
[15594] | 481 | // その他支払い情報を表示 |
---|
[17293] | 482 | if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]); |
---|
| 483 | if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){ |
---|
| 484 | $this->arrForm["payment_type"] = "クレジット決済"; |
---|
| 485 | }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){ |
---|
| 486 | $this->arrForm["payment_type"] = "コンビニ決済"; |
---|
[15594] | 487 | }else{ |
---|
[17293] | 488 | $this->arrForm["payment_type"] = "お支払い"; |
---|
[15594] | 489 | } |
---|
[18089] | 490 | // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため) |
---|
| 491 | $this->arrDisp = $this->arrForm; |
---|
[15594] | 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | // 受注詳細データの取得 |
---|
| 496 | function lfGetOrderDetail($order_id) { |
---|
| 497 | $objQuery = new SC_Query(); |
---|
[19923] | 498 | $from = <<< __EOS__ |
---|
| 499 | dtb_order_detail T1 |
---|
| 500 | JOIN dtb_products_class T2 |
---|
| 501 | ON T1.product_class_id = T2.product_class_id |
---|
| 502 | __EOS__; |
---|
| 503 | $arrRet = $objQuery->select("T1.*, T2.product_type_id", $from, |
---|
| 504 | "order_id = ?", array($order_id)); |
---|
[15594] | 505 | return $arrRet; |
---|
| 506 | } |
---|
| 507 | |
---|
[19912] | 508 | /** |
---|
| 509 | * 配送情報の取得. |
---|
| 510 | * TODO リファクタリング |
---|
| 511 | */ |
---|
| 512 | function lfGetShippingData($orderId) { |
---|
| 513 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 514 | $objProduct = new SC_Product(); |
---|
| 515 | $objQuery->setOrder('shipping_id'); |
---|
| 516 | $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId)); |
---|
| 517 | foreach (array_keys($arrRet) as $key) { |
---|
| 518 | $objQuery->setOrder('shipping_id'); |
---|
| 519 | $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?", |
---|
| 520 | array($orderId, $arrRet[$key]['shipping_id'])); |
---|
| 521 | foreach ($arrItems as $itemKey => $arrDetail) { |
---|
| 522 | foreach ($arrDetail as $detailKey => $detailVal) { |
---|
| 523 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']); |
---|
| 527 | } |
---|
| 528 | } |
---|
| 529 | return $arrRet; |
---|
| 530 | } |
---|
| 531 | |
---|
[15594] | 532 | /* 入力内容のチェック */ |
---|
| 533 | function lfCheckError() { |
---|
| 534 | // 入力データを渡す。 |
---|
| 535 | $arrRet = $this->objFormParam->getHashArray(); |
---|
| 536 | $objErr = new SC_CheckError($arrRet); |
---|
| 537 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
| 538 | |
---|
[18087] | 539 | if (count($objErr->arrErr) >= 1) { |
---|
| 540 | return $objErr->arrErr; |
---|
| 541 | } |
---|
[18819] | 542 | |
---|
[18087] | 543 | return $this->lfCheek(); |
---|
[15594] | 544 | } |
---|
| 545 | |
---|
| 546 | /* 計算処理 */ |
---|
[18087] | 547 | function lfCheek() { |
---|
[15594] | 548 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 549 | $arrVal = $this->objFormParam->getHashArray(); |
---|
| 550 | $arrErr = array(); |
---|
| 551 | |
---|
| 552 | // 商品の種類数 |
---|
| 553 | $max = count($arrVal['quantity']); |
---|
| 554 | $subtotal = 0; |
---|
| 555 | $totalpoint = 0; |
---|
| 556 | $totaltax = 0; |
---|
| 557 | for($i = 0; $i < $max; $i++) { |
---|
| 558 | // 小計の計算 |
---|
[19680] | 559 | $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
[15594] | 560 | // 小計の計算 |
---|
[18052] | 561 | $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
[15594] | 562 | // 加算ポイントの計算 |
---|
| 563 | $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i]; |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | // 消費税 |
---|
| 567 | $arrVal['tax'] = $totaltax; |
---|
| 568 | // 小計 |
---|
| 569 | $arrVal['subtotal'] = $subtotal; |
---|
| 570 | // 合計 |
---|
| 571 | $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge']; |
---|
| 572 | // お支払い合計 |
---|
| 573 | $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE); |
---|
| 574 | |
---|
| 575 | // 加算ポイント |
---|
[18052] | 576 | $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']); |
---|
[19674] | 577 | |
---|
| 578 | // 最終保持ポイント |
---|
| 579 | $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point']; |
---|
| 580 | |
---|
[18077] | 581 | if ($arrVal['total'] < 0) { |
---|
[15594] | 582 | $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
| 583 | } |
---|
| 584 | |
---|
[18077] | 585 | if ($arrVal['payment_total'] < 0) { |
---|
[15594] | 586 | $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
| 587 | } |
---|
[18077] | 588 | //新規追加受注のみ |
---|
[18087] | 589 | if ($_POST['mode'] == "add") { |
---|
[18077] | 590 | if ($arrVal['total_point'] < 0) { |
---|
| 591 | $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; |
---|
| 592 | } |
---|
[15594] | 593 | } |
---|
| 594 | |
---|
| 595 | $this->objFormParam->setParam($arrVal); |
---|
| 596 | return $arrErr; |
---|
| 597 | } |
---|
| 598 | |
---|
[18100] | 599 | /** |
---|
| 600 | * DB更新処理 |
---|
| 601 | * |
---|
| 602 | * @param integer $order_id 注文番号 |
---|
| 603 | * @return void |
---|
| 604 | */ |
---|
[15594] | 605 | function lfRegistData($order_id) { |
---|
| 606 | $objQuery = new SC_Query(); |
---|
| 607 | |
---|
[18329] | 608 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
[15594] | 609 | |
---|
| 610 | $where = "order_id = ?"; |
---|
| 611 | |
---|
[18329] | 612 | $objQuery->begin(); |
---|
| 613 | |
---|
[18100] | 614 | // 受注.対応状況の更新 |
---|
| 615 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']); |
---|
| 616 | unset($sqlval['status']); |
---|
| 617 | unset($sqlval['add_point']); |
---|
| 618 | unset($sqlval['use_point']); |
---|
[15594] | 619 | |
---|
| 620 | // 受注テーブルの更新 |
---|
[19919] | 621 | $this->registerOrder($sqlval, $order_id); |
---|
[18819] | 622 | |
---|
[18023] | 623 | // 受注テーブルの名称列を更新 |
---|
[19919] | 624 | //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
[18819] | 625 | |
---|
[18872] | 626 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2")); |
---|
[18646] | 627 | |
---|
| 628 | |
---|
| 629 | // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算 |
---|
| 630 | $max = count($arrDetail); |
---|
| 631 | $k = 0; |
---|
| 632 | $arrStockData = array(); |
---|
| 633 | for($i = 0; $i < $max; $i++) { |
---|
| 634 | if (!empty($arrDetail[$i]['product_id'])) { |
---|
[18872] | 635 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
[18646] | 636 | if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) { |
---|
| 637 | // 数量が変更された商品 |
---|
[18872] | 638 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[18646] | 639 | $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity']; |
---|
| 640 | ++$k; |
---|
| 641 | } elseif (empty($arrPreDetail)) { |
---|
| 642 | // 新しく追加された商品 もしくは 違う商品に変更された商品 |
---|
[18872] | 643 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[18646] | 644 | $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity']; |
---|
| 645 | ++$k; |
---|
| 646 | } |
---|
[18872] | 647 | $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
[18646] | 648 | } |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品 |
---|
| 652 | $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id)); |
---|
| 653 | foreach ($arrPreDetail AS $key=>$val) { |
---|
[18872] | 654 | $arrStockData[$k]['product_class_id'] = $val['product_class_id']; |
---|
[18646] | 655 | $arrStockData[$k]['quantity'] = $val['quantity']; |
---|
| 656 | ++$k; |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | // 受注詳細データの初期化 |
---|
[15594] | 660 | $objQuery->delete("dtb_order_detail", $where, array($order_id)); |
---|
| 661 | |
---|
[18646] | 662 | // 受注詳細データの更新 |
---|
[15594] | 663 | $max = count($arrDetail); |
---|
[18100] | 664 | for ($i = 0; $i < $max; $i++) { |
---|
[15594] | 665 | $sqlval = array(); |
---|
| 666 | $sqlval['order_id'] = $order_id; |
---|
| 667 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
[18872] | 668 | $sqlval['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[15594] | 669 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
| 670 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
| 671 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
| 672 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
| 673 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
| 674 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
| 675 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
| 676 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
| 677 | } |
---|
[18074] | 678 | |
---|
[18646] | 679 | // 在庫数調整 |
---|
| 680 | $status = $sqlval['status']; |
---|
| 681 | if (ORDER_DELIV != $status && ORDER_CANCEL != $status) { |
---|
[18872] | 682 | $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_class_id = ?"; |
---|
[18646] | 683 | foreach ($arrStockData AS $key=>$val) { |
---|
| 684 | $stock_sqlval = array(); |
---|
| 685 | $stock_sqlval[] = $val['quantity']; |
---|
[18872] | 686 | $stock_sqlval[] = $val['product_class_id']; |
---|
[18646] | 687 | |
---|
| 688 | $objQuery->query($stock_sql, $stock_sqlval); |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | |
---|
[15594] | 692 | $objQuery->commit(); |
---|
| 693 | } |
---|
[17293] | 694 | |
---|
[18100] | 695 | /** |
---|
| 696 | * DB登録処理 |
---|
| 697 | * |
---|
| 698 | * @return integer 注文番号 |
---|
| 699 | */ |
---|
[17293] | 700 | function lfRegistNewData() { |
---|
| 701 | $objQuery = new SC_Query(); |
---|
| 702 | |
---|
[18329] | 703 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
[17293] | 704 | |
---|
[18100] | 705 | // ポイントは別登録 |
---|
| 706 | $addPoint = $sqlval['add_point']; |
---|
| 707 | $usePoint = $sqlval['use_point']; |
---|
| 708 | $sqlval['add_point'] = 0; |
---|
| 709 | $sqlval['use_point'] = 0; |
---|
| 710 | |
---|
[17293] | 711 | // customer_id |
---|
[18100] | 712 | if ($sqlval["customer_id"] == "") { |
---|
[17293] | 713 | $sqlval['customer_id'] = '0'; |
---|
| 714 | } |
---|
[18037] | 715 | |
---|
[18100] | 716 | $sqlval['create_date'] = 'Now()'; // 受注日 |
---|
[17293] | 717 | |
---|
[18329] | 718 | $objQuery->begin(); |
---|
| 719 | |
---|
[17293] | 720 | // 受注テーブルの登録 |
---|
[18788] | 721 | $order_id = $objQuery->nextVal('dtb_order_order_id'); |
---|
| 722 | $sqlval['order_id'] = $order_id; |
---|
[17293] | 723 | $objQuery->insert("dtb_order", $sqlval); |
---|
[18037] | 724 | |
---|
[18788] | 725 | |
---|
[18100] | 726 | // 受注.対応状況の更新 |
---|
| 727 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint); |
---|
| 728 | |
---|
[18023] | 729 | // 受注テーブルの名称列を更新 |
---|
[18100] | 730 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
[18037] | 731 | |
---|
[17293] | 732 | // 受注詳細データの更新 |
---|
[18872] | 733 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2")); |
---|
[18100] | 734 | $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id)); |
---|
[17293] | 735 | |
---|
| 736 | $max = count($arrDetail); |
---|
[18100] | 737 | for ($i = 0; $i < $max; $i++) { |
---|
[17293] | 738 | $sqlval = array(); |
---|
| 739 | $sqlval['order_id'] = $order_id; |
---|
| 740 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
[18872] | 741 | $sqlval['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[17293] | 742 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
| 743 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
| 744 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
| 745 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
| 746 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
| 747 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
| 748 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
[18646] | 749 | |
---|
[17293] | 750 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
[18646] | 751 | |
---|
| 752 | |
---|
| 753 | // 在庫数減少処理 |
---|
| 754 | // 現在の実在庫数取得 |
---|
[18872] | 755 | $pre_stock = $objQuery->getOne("SELECT stock FROM dtb_products_class WHERE product_class_id = ?", array($arrDetail[$i]['product_class_id'])); |
---|
[18646] | 756 | |
---|
| 757 | $stock_sqlval = array(); |
---|
| 758 | $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']); |
---|
| 759 | if ($stock_sqlval['stock'] === 0) { |
---|
| 760 | $stock_sqlval['stock'] = '0'; |
---|
[17293] | 761 | } |
---|
[18100] | 762 | |
---|
[18646] | 763 | $st_params = array(); |
---|
[18872] | 764 | $st_params[] = $arrDetail[$i]['product_class_id']; |
---|
[18646] | 765 | |
---|
[18872] | 766 | $objQuery->update("dtb_products_class", $stock_sqlval, 'product_class_id = ?', $st_params); |
---|
[18646] | 767 | } |
---|
[17293] | 768 | $objQuery->commit(); |
---|
[18068] | 769 | |
---|
| 770 | return $order_id; |
---|
[17293] | 771 | } |
---|
| 772 | |
---|
[19919] | 773 | /** |
---|
| 774 | * 受注を登録する |
---|
| 775 | */ |
---|
| 776 | function registerOrder($sqlval, $order_id) { |
---|
| 777 | $table = 'dtb_order'; |
---|
| 778 | $objQuery = SC_Query::getSingletonInstance(); |
---|
| 779 | $cols = $objQuery->listTableFields($table); |
---|
| 780 | $dest = array(); |
---|
| 781 | foreach ($sqlval as $key => $val) { |
---|
| 782 | if (in_array($cols, $key)) { |
---|
| 783 | $dest[$key] = $val; |
---|
| 784 | } |
---|
| 785 | } |
---|
| 786 | $result = $objQuery->update($table, $dest, "order_id = ?", array($order_id)); |
---|
| 787 | if ($result == 0) { |
---|
[19920] | 788 | $dest['order_id'] = $order_id; |
---|
[19919] | 789 | $result = $objQuery->insert($table, $dest); |
---|
| 790 | } |
---|
| 791 | } |
---|
| 792 | |
---|
[18875] | 793 | function lfInsertProduct($product_class_id) { |
---|
| 794 | $objProduct = new SC_Product(); |
---|
| 795 | $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); |
---|
[17293] | 796 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
[18014] | 797 | $existes = false; |
---|
| 798 | $existes_key = NULL; |
---|
[18312] | 799 | // 既に同じ商品がないか、確認する |
---|
[18872] | 800 | if (!empty($this->arrForm['product_class_id']['value'])) { |
---|
| 801 | foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) { |
---|
[18312] | 802 | // 既に同じ商品がある場合 |
---|
[18875] | 803 | if ($val == $product_class_id) { |
---|
[18014] | 804 | $existes = true; |
---|
| 805 | $existes_key = $key; |
---|
| 806 | } |
---|
| 807 | } |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | if ($existes) { |
---|
[18312] | 811 | // 既に同じ商品がある場合 |
---|
[18014] | 812 | ++$this->arrForm['quantity']['value'][$existes_key]; |
---|
| 813 | } else { |
---|
[18312] | 814 | // 既に同じ商品がない場合 |
---|
[18014] | 815 | $this->lfSetProductData($arrProduct); |
---|
| 816 | } |
---|
[17293] | 817 | } |
---|
| 818 | |
---|
[18875] | 819 | function lfUpdateProduct($product_class_id, $no) { |
---|
| 820 | $objProduct = new SC_Product(); |
---|
| 821 | $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id)); |
---|
[17293] | 822 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
| 823 | $this->lfSetProductData($arrProduct, $no); |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | function lfSetProductData($arrProduct, $no = null) { |
---|
| 827 | foreach ($arrProduct AS $key=>$val) { |
---|
| 828 | if (!is_array($this->arrForm[$key]['value'])) { |
---|
| 829 | unset($this->arrForm[$key]['value']); |
---|
| 830 | } |
---|
| 831 | if ($no === null) { |
---|
[18875] | 832 | $this->arrForm[$key]['value'][] = $val; |
---|
[17293] | 833 | } else { |
---|
[18875] | 834 | $this->arrForm[$key]['value'][$no] = $val; |
---|
[17293] | 835 | } |
---|
| 836 | } |
---|
| 837 | } |
---|
| 838 | |
---|
[18875] | 839 | function lfGetProductsClass($productsClass) { |
---|
| 840 | $arrProduct['price'] = $productsClass['price02']; |
---|
[17293] | 841 | $arrProduct['quantity'] = 1; |
---|
[18875] | 842 | $arrProduct['product_id'] = $productsClass['product_id']; |
---|
| 843 | $arrProduct['product_class_id'] = $productsClass['product_class_id']; |
---|
| 844 | $arrProduct['point_rate'] = $productsClass['point_rate']; |
---|
| 845 | $arrProduct['product_code'] = $productsClass['product_code']; |
---|
| 846 | $arrProduct['product_name'] = $productsClass['name']; |
---|
| 847 | $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1']; |
---|
| 848 | $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2']; |
---|
[17293] | 849 | |
---|
| 850 | return $arrProduct; |
---|
| 851 | } |
---|
[18068] | 852 | |
---|
[18875] | 853 | |
---|
[18068] | 854 | /** |
---|
| 855 | * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
| 856 | * @param int $edit_customer_id 顧客ID |
---|
| 857 | */ |
---|
| 858 | function lfSetCustomerInfo($edit_customer_id = ""){ |
---|
| 859 | // 顧客IDが指定されている場合のみ、処理を実行する |
---|
| 860 | if( $edit_customer_id === "" ) return ; |
---|
| 861 | |
---|
| 862 | // 検索で選択された顧客IDが入力されている場合 |
---|
| 863 | if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){ |
---|
| 864 | $objQuery = new SC_Query(); |
---|
| 865 | |
---|
| 866 | // 顧客情報を取得する |
---|
| 867 | $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id)); |
---|
| 868 | |
---|
| 869 | // 顧客情報を取得する事が出来たら、テンプレートに値を渡す |
---|
| 870 | if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){ |
---|
| 871 | // カラム名にorder_を付ける(テンプレート側でorder_がついている為 |
---|
| 872 | foreach($arrCustomerInfo[0] as $index=>$customer_info){ |
---|
| 873 | // customer_idにはorder_を付けないようにする |
---|
| 874 | $order_index = ($index == 'customer_id') ? $index : 'order_'.$index; |
---|
| 875 | $arrCustomer[$order_index] = $customer_info; |
---|
| 876 | } |
---|
| 877 | } |
---|
| 878 | |
---|
| 879 | // hiddenに渡す |
---|
| 880 | $this->edit_customer_id = $edit_customer_id; |
---|
| 881 | |
---|
| 882 | // 受注日に現在の時刻を取得し、表示させる |
---|
[18675] | 883 | $create_date = $objQuery->getAll('SELECT now() as create_date;'); |
---|
[18068] | 884 | $arrCustomer['create_date'] = $create_date[0]['create_date']; |
---|
| 885 | |
---|
| 886 | // 情報上書き |
---|
| 887 | $this->objFormParam->setParam($arrCustomer); |
---|
| 888 | // 入力値の変換 |
---|
| 889 | $this->objFormParam->convParam(); |
---|
| 890 | } |
---|
| 891 | } |
---|
[18329] | 892 | |
---|
| 893 | /** |
---|
| 894 | * 受注テーブルの登録・更新用データの共通部分を作成する |
---|
| 895 | * |
---|
| 896 | * @return array |
---|
| 897 | */ |
---|
| 898 | function lfMakeSqlvalForDtbOrder() { |
---|
| 899 | |
---|
| 900 | // 入力データを取得する |
---|
| 901 | $sqlval = $this->objFormParam->getHashArray(); |
---|
| 902 | foreach ($sqlval as $key => $val) { |
---|
| 903 | // 配列は登録しない |
---|
| 904 | if (is_array($val)) { |
---|
| 905 | unset($sqlval[$key]); |
---|
| 906 | } |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | // 受注テーブルに書き込まない列を除去 |
---|
| 910 | unset($sqlval['total_point']); |
---|
| 911 | unset($sqlval['point']); |
---|
| 912 | unset($sqlval['commit_date']); |
---|
| 913 | |
---|
| 914 | // 更新日時 |
---|
| 915 | $sqlval['update_date'] = 'Now()'; |
---|
| 916 | |
---|
| 917 | return $sqlval; |
---|
| 918 | } |
---|
[15594] | 919 | } |
---|
| 920 | ?> |
---|