[15594] | 1 | <?php |
---|
| 2 | /* |
---|
[16582] | 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[21867] | 5 | * Copyright(c) 2000-2012 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 |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/order/LC_Page_Admin_Order_Ex.php'; |
---|
[15594] | 26 | |
---|
| 27 | /** |
---|
| 28 | * 受注修正 のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
| 32 | * @version $Id$ |
---|
| 33 | */ |
---|
[20180] | 34 | class LC_Page_Admin_Order_Edit extends LC_Page_Admin_Order_Ex { |
---|
[15594] | 35 | |
---|
[20943] | 36 | var $arrShippingKeys = array( |
---|
| 37 | 'shipping_id', |
---|
| 38 | 'shipping_name01', |
---|
| 39 | 'shipping_name02', |
---|
| 40 | 'shipping_kana01', |
---|
| 41 | 'shipping_kana02', |
---|
| 42 | 'shipping_tel01', |
---|
| 43 | 'shipping_tel02', |
---|
| 44 | 'shipping_tel03', |
---|
| 45 | 'shipping_fax01', |
---|
| 46 | 'shipping_fax02', |
---|
| 47 | 'shipping_fax03', |
---|
| 48 | 'shipping_pref', |
---|
| 49 | 'shipping_zip01', |
---|
| 50 | 'shipping_zip02', |
---|
| 51 | 'shipping_addr01', |
---|
| 52 | 'shipping_addr02', |
---|
| 53 | 'shipping_date_year', |
---|
| 54 | 'shipping_date_month', |
---|
| 55 | 'shipping_date_day', |
---|
| 56 | 'time_id', |
---|
| 57 | ); |
---|
| 58 | |
---|
| 59 | var $arrShipmentItemKeys = array( |
---|
| 60 | 'shipment_product_class_id', |
---|
| 61 | 'shipment_product_code', |
---|
| 62 | 'shipment_product_name', |
---|
| 63 | 'shipment_classcategory_name1', |
---|
| 64 | 'shipment_classcategory_name2', |
---|
| 65 | 'shipment_price', |
---|
| 66 | 'shipment_quantity', |
---|
| 67 | ); |
---|
| 68 | |
---|
[15594] | 69 | // }}} |
---|
| 70 | // {{{ functions |
---|
| 71 | |
---|
| 72 | /** |
---|
| 73 | * Page を初期化する. |
---|
| 74 | * |
---|
| 75 | * @return void |
---|
| 76 | */ |
---|
| 77 | function init() { |
---|
| 78 | parent::init(); |
---|
| 79 | $this->tpl_mainpage = 'order/edit.tpl'; |
---|
[17293] | 80 | $this->tpl_mainno = 'order'; |
---|
[20911] | 81 | $this->tpl_maintitle = '受注管理'; |
---|
| 82 | $this->tpl_subtitle = '受注登録'; |
---|
[15594] | 83 | |
---|
| 84 | $masterData = new SC_DB_MasterData_Ex(); |
---|
[19773] | 85 | $this->arrPref = $masterData->getMasterData('mtb_pref'); |
---|
[21481] | 86 | $this->arrORDERSTATUS = $masterData->getMasterData('mtb_order_status'); |
---|
[19975] | 87 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
[17886] | 88 | |
---|
[20499] | 89 | $objDate = new SC_Date_Ex(RELEASE_YEAR); |
---|
[20180] | 90 | $this->arrYearShippingDate = $objDate->getYear('', date('Y'), ''); |
---|
| 91 | $this->arrMonthShippingDate = $objDate->getMonth(true); |
---|
| 92 | $this->arrDayShippingDate = $objDate->getDay(true); |
---|
| 93 | |
---|
| 94 | // 支払い方法の取得 |
---|
[21481] | 95 | $this->arrPayment = SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method'); |
---|
[20180] | 96 | |
---|
| 97 | // 配送業者の取得 |
---|
[21481] | 98 | $this->arrDeliv = SC_Helper_DB_Ex::sfGetIDValueList('dtb_deliv', 'deliv_id', 'name'); |
---|
[20180] | 99 | |
---|
[22197] | 100 | $this->arrInfo = SC_Helper_DB_Ex::sfGetBasisData(); |
---|
| 101 | |
---|
[18187] | 102 | $this->httpCacheControl('nocache'); |
---|
[15594] | 103 | } |
---|
| 104 | |
---|
| 105 | /** |
---|
| 106 | * Page のプロセス. |
---|
| 107 | * |
---|
| 108 | * @return void |
---|
| 109 | */ |
---|
| 110 | function process() { |
---|
[19661] | 111 | $this->action(); |
---|
| 112 | $this->sendResponse(); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Page のアクション. |
---|
| 117 | * |
---|
| 118 | * @return void |
---|
| 119 | */ |
---|
| 120 | function action() { |
---|
[21591] | 121 | |
---|
[19923] | 122 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
[20501] | 123 | $objFormParam = new SC_FormParam_Ex(); |
---|
[15594] | 124 | |
---|
[20970] | 125 | // パラメーター情報の初期化 |
---|
[20180] | 126 | $this->lfInitParam($objFormParam); |
---|
| 127 | $objFormParam->setParam($_REQUEST); |
---|
| 128 | $objFormParam->convParam(); |
---|
| 129 | $order_id = $objFormParam->getValue('order_id'); |
---|
[21036] | 130 | $arrValuesBefore = array(); |
---|
[15594] | 131 | |
---|
| 132 | // DBから受注情報を読み込む |
---|
[19963] | 133 | if (!SC_Utils_Ex::isBlank($order_id)) { |
---|
[20180] | 134 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
| 135 | $this->tpl_subno = 'index'; |
---|
[21036] | 136 | $arrValuesBefore['payment_id'] = $objFormParam->getValue('payment_id'); |
---|
| 137 | $arrValuesBefore['payment_method'] = $objFormParam->getValue('payment_method'); |
---|
[20180] | 138 | } else { |
---|
| 139 | $this->tpl_subno = 'add'; |
---|
| 140 | $this->tpl_mode = 'add'; |
---|
[21036] | 141 | $arrValuesBefore['payment_id'] = NULL; |
---|
| 142 | $arrValuesBefore['payment_method'] = NULL; |
---|
[21222] | 143 | // お届け先情報を空情報で表示 |
---|
| 144 | $arrShippingIds[] = null; |
---|
| 145 | $objFormParam->setValue('shipping_id', $arrShippingIds); |
---|
[21420] | 146 | |
---|
[21419] | 147 | // 新規受注登録で入力エラーがあった場合の画面表示用に、会員の現在ポイントを取得 |
---|
[21069] | 148 | if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) { |
---|
| 149 | $customer_id = $objFormParam->getValue('customer_id'); |
---|
| 150 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
| 151 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
[21774] | 152 | |
---|
| 153 | // 新規受注登録で、ポイント利用できるように現在ポイントを設定 |
---|
| 154 | $objFormParam->setValue('point', $arrCustomer['point']); |
---|
[21069] | 155 | } |
---|
[19963] | 156 | } |
---|
[15594] | 157 | |
---|
[20180] | 158 | $this->arrSearchHidden = $objFormParam->getSearchArray(); |
---|
| 159 | |
---|
[21441] | 160 | switch ($this->getMode()) { |
---|
[21526] | 161 | case 'pre_edit': |
---|
| 162 | case 'order_id': |
---|
| 163 | break; |
---|
[20180] | 164 | |
---|
[21526] | 165 | case 'edit': |
---|
[20180] | 166 | $objFormParam->setParam($_POST); |
---|
| 167 | $objFormParam->convParam(); |
---|
| 168 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 169 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
[21526] | 170 | $message = '受注を編集しました。'; |
---|
| 171 | $order_id = $this->doRegister($order_id, $objPurchase, $objFormParam, $message, $arrValuesBefore); |
---|
[20577] | 172 | if ($order_id >= 0) { |
---|
| 173 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
| 174 | } |
---|
| 175 | $this->tpl_onload = "window.alert('" . $message . "');"; |
---|
[18068] | 176 | } |
---|
[21526] | 177 | break; |
---|
[20180] | 178 | |
---|
[21526] | 179 | case 'add': |
---|
| 180 | if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
---|
| 181 | $objFormParam->setParam($_POST); |
---|
| 182 | $objFormParam->convParam(); |
---|
| 183 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 184 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
| 185 | $message = '受注を登録しました。'; |
---|
| 186 | $order_id = $this->doRegister(null, $objPurchase, $objFormParam, $message, $arrValuesBefore); |
---|
| 187 | if ($order_id >= 0) { |
---|
| 188 | $this->tpl_mode = 'edit'; |
---|
| 189 | $objFormParam->setValue('order_id', $order_id); |
---|
| 190 | $this->setOrderToFormParam($objFormParam, $order_id); |
---|
| 191 | } |
---|
| 192 | $this->tpl_onload = "window.alert('" . $message . "');"; |
---|
| 193 | } |
---|
| 194 | } |
---|
[20180] | 195 | |
---|
[21526] | 196 | break; |
---|
[19912] | 197 | |
---|
[21526] | 198 | // 再計算 |
---|
| 199 | case 'recalculate': |
---|
| 200 | //支払い方法の選択 |
---|
| 201 | case 'payment': |
---|
| 202 | // 配送業者の選択 |
---|
| 203 | case 'deliv': |
---|
| 204 | $objFormParam->setParam($_POST); |
---|
| 205 | $objFormParam->convParam(); |
---|
| 206 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 207 | break; |
---|
[20180] | 208 | |
---|
[21526] | 209 | // 商品削除 |
---|
| 210 | case 'delete_product': |
---|
| 211 | $objFormParam->setParam($_POST); |
---|
| 212 | $objFormParam->convParam(); |
---|
| 213 | $delete_no = $objFormParam->getValue('delete_no'); |
---|
| 214 | $this->doDeleteProduct($delete_no, $objFormParam); |
---|
| 215 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 216 | break; |
---|
[19963] | 217 | |
---|
[21526] | 218 | // 商品追加ポップアップより商品選択 |
---|
| 219 | case 'select_product_detail': |
---|
| 220 | $objFormParam->setParam($_POST); |
---|
| 221 | $objFormParam->convParam(); |
---|
| 222 | $this->doRegisterProduct($objFormParam); |
---|
| 223 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 224 | break; |
---|
[17887] | 225 | |
---|
[21526] | 226 | // 会員検索ポップアップより会員指定 |
---|
| 227 | case 'search_customer': |
---|
| 228 | $objFormParam->setParam($_POST); |
---|
| 229 | $objFormParam->convParam(); |
---|
| 230 | $this->setCustomerTo($objFormParam->getValue('edit_customer_id'), |
---|
| 231 | $objFormParam); |
---|
| 232 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 233 | break; |
---|
[19934] | 234 | |
---|
[21526] | 235 | // 複数配送設定表示 |
---|
| 236 | case 'multiple': |
---|
| 237 | $objFormParam->setParam($_POST); |
---|
| 238 | $objFormParam->convParam(); |
---|
| 239 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
| 240 | break; |
---|
[19963] | 241 | |
---|
[21526] | 242 | // 複数配送設定を反映 |
---|
| 243 | case 'multiple_set_to': |
---|
| 244 | $this->lfInitMultipleParam($objFormParam); |
---|
| 245 | $objFormParam->setParam($_POST); |
---|
| 246 | $objFormParam->convParam(); |
---|
| 247 | $this->setMultipleItemTo($objFormParam); |
---|
| 248 | break; |
---|
[19963] | 249 | |
---|
[21526] | 250 | // お届け先の追加 |
---|
| 251 | case 'append_shipping': |
---|
| 252 | $objFormParam->setParam($_POST); |
---|
| 253 | $objFormParam->convParam(); |
---|
| 254 | $this->addShipping($objFormParam); |
---|
| 255 | break; |
---|
| 256 | |
---|
| 257 | default: |
---|
| 258 | break; |
---|
[15594] | 259 | } |
---|
| 260 | |
---|
[20180] | 261 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
[20943] | 262 | $this->arrAllShipping = $objFormParam->getSwapArray(array_merge($this->arrShippingKeys, $this->arrShipmentItemKeys)); |
---|
[20180] | 263 | $this->arrDelivTime = $objPurchase->getDelivTime($objFormParam->getValue('deliv_id')); |
---|
| 264 | $this->tpl_onload .= $this->getAnchorKey($objFormParam); |
---|
[21036] | 265 | if ($arrValuesBefore['payment_id']) |
---|
| 266 | $this->arrPayment[$arrValuesBefore['payment_id']] = $arrValuesBefore['payment_method']; |
---|
[21592] | 267 | |
---|
[15594] | 268 | } |
---|
| 269 | |
---|
| 270 | /** |
---|
| 271 | * デストラクタ. |
---|
| 272 | * |
---|
| 273 | * @return void |
---|
| 274 | */ |
---|
| 275 | function destroy() { |
---|
| 276 | parent::destroy(); |
---|
| 277 | } |
---|
| 278 | |
---|
[20180] | 279 | /** |
---|
[20970] | 280 | * パラメーター情報の初期化を行う. |
---|
[20180] | 281 | * |
---|
| 282 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 283 | * @return void |
---|
| 284 | */ |
---|
| 285 | function lfInitParam(&$objFormParam) { |
---|
[20970] | 286 | // 検索条件のパラメーターを初期化 |
---|
[20180] | 287 | parent::lfInitParam($objFormParam); |
---|
[18037] | 288 | |
---|
[17508] | 289 | // お客様情報 |
---|
[21514] | 290 | $objFormParam->addParam('注文者 お名前(姓)', 'order_name01', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 291 | $objFormParam->addParam('注文者 お名前(名)', 'order_name02', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 292 | $objFormParam->addParam('注文者 お名前(フリガナ・姓)', 'order_kana01', STEXT_LEN, 'KVCa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 293 | $objFormParam->addParam('注文者 お名前(フリガナ・名)', 'order_kana02', STEXT_LEN, 'KVCa', array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 294 | $objFormParam->addParam('メールアドレス', 'order_email', null, 'KVCa', array('NO_SPTAB', 'EMAIL_CHECK', 'EMAIL_CHAR_CHECK')); |
---|
| 295 | $objFormParam->addParam('郵便番号1', 'order_zip01', ZIP01_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK')); |
---|
| 296 | $objFormParam->addParam('郵便番号2', 'order_zip02', ZIP02_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK')); |
---|
| 297 | $objFormParam->addParam('都道府県', 'order_pref', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 298 | $objFormParam->addParam('住所1', 'order_addr01', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 299 | $objFormParam->addParam('住所2', 'order_addr02', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 300 | $objFormParam->addParam('電話番号1', 'order_tel01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 301 | $objFormParam->addParam('電話番号2', 'order_tel02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 302 | $objFormParam->addParam('電話番号3', 'order_tel03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
[21839] | 303 | $objFormParam->addParam('FAX番号1', 'order_fax01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 304 | $objFormParam->addParam('FAX番号2', 'order_fax02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 305 | $objFormParam->addParam('FAX番号3', 'order_fax03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
[17293] | 306 | |
---|
[15594] | 307 | // 受注商品情報 |
---|
[21514] | 308 | $objFormParam->addParam('値引き', 'discount', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 309 | $objFormParam->addParam('送料', 'deliv_fee', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 310 | $objFormParam->addParam('手数料', 'charge', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
[18054] | 311 | |
---|
| 312 | // ポイント機能ON時のみ |
---|
| 313 | if (USE_POINT !== false) { |
---|
[21514] | 314 | $objFormParam->addParam('利用ポイント', 'use_point', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[18054] | 315 | } |
---|
| 316 | |
---|
[21514] | 317 | $objFormParam->addParam('配送業者', 'deliv_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 318 | $objFormParam->addParam('お支払い方法', 'payment_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 319 | $objFormParam->addParam('対応状況', 'status', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 320 | $objFormParam->addParam('お支払方法名称', 'payment_method'); |
---|
[15594] | 321 | |
---|
| 322 | // 受注詳細情報 |
---|
[21514] | 323 | $objFormParam->addParam('商品種別ID', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 324 | $objFormParam->addParam('単価', 'price', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 325 | $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 326 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 327 | $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 328 | $objFormParam->addParam('ポイント付与率', 'point_rate'); |
---|
| 329 | $objFormParam->addParam('商品コード', 'product_code'); |
---|
| 330 | $objFormParam->addParam('商品名', 'product_name'); |
---|
| 331 | $objFormParam->addParam('規格名1', 'classcategory_name1'); |
---|
| 332 | $objFormParam->addParam('規格名2', 'classcategory_name2'); |
---|
[22197] | 333 | $objFormParam->addParam('税率', 'tax_rate'); |
---|
| 334 | $objFormParam->addParam('課税規則', 'tax_rule'); |
---|
[21514] | 335 | $objFormParam->addParam('メモ', 'note', MTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK')); |
---|
| 336 | $objFormParam->addParam('削除用項番', 'delete_no', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[20180] | 337 | |
---|
[15594] | 338 | // DB読込用 |
---|
[21514] | 339 | $objFormParam->addParam('小計', 'subtotal'); |
---|
| 340 | $objFormParam->addParam('合計', 'total'); |
---|
| 341 | $objFormParam->addParam('支払い合計', 'payment_total'); |
---|
| 342 | $objFormParam->addParam('加算ポイント', 'add_point'); |
---|
[21653] | 343 | $objFormParam->addParam('お誕生日ポイント', 'birth_point', null, 'n', array(), 0); |
---|
[21514] | 344 | $objFormParam->addParam('消費税合計', 'tax'); |
---|
| 345 | $objFormParam->addParam('最終保持ポイント', 'total_point'); |
---|
| 346 | $objFormParam->addParam('会員ID', 'customer_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 347 | $objFormParam->addParam('会員ID', 'edit_customer_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 348 | $objFormParam->addParam('現在のポイント', 'customer_point'); |
---|
| 349 | $objFormParam->addParam('受注前ポイント', 'point'); |
---|
| 350 | $objFormParam->addParam('注文番号', 'order_id'); |
---|
| 351 | $objFormParam->addParam('受注日', 'create_date'); |
---|
| 352 | $objFormParam->addParam('発送日', 'commit_date'); |
---|
| 353 | $objFormParam->addParam('備考', 'message'); |
---|
| 354 | $objFormParam->addParam('入金日', 'payment_date'); |
---|
| 355 | $objFormParam->addParam('端末種別', 'device_type_id'); |
---|
[22197] | 356 | $objFormParam->addParam('税率', 'order_tax_rate'); |
---|
| 357 | $objFormParam->addParam('課税規則', 'order_tax_rule'); |
---|
[15594] | 358 | |
---|
[20180] | 359 | // 複数情報 |
---|
[21514] | 360 | $objFormParam->addParam('配送数', 'shipping_quantity', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 361 | $objFormParam->addParam('配送ID', 'shipping_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), 0); |
---|
| 362 | $objFormParam->addParam('お名前(姓)', 'shipping_name01', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 363 | $objFormParam->addParam('お名前(名)', 'shipping_name02', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 364 | $objFormParam->addParam('お名前(フリガナ・姓)', 'shipping_kana01', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 365 | $objFormParam->addParam('お名前(フリガナ・名)', 'shipping_kana02', STEXT_LEN, 'KVCa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 366 | $objFormParam->addParam('郵便番号1', 'shipping_zip01', ZIP01_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK')); |
---|
| 367 | $objFormParam->addParam('郵便番号2', 'shipping_zip02', ZIP02_LEN, 'n', array('NUM_CHECK', 'NUM_COUNT_CHECK')); |
---|
| 368 | $objFormParam->addParam('都道府県', 'shipping_pref', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 369 | $objFormParam->addParam('住所1', 'shipping_addr01', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 370 | $objFormParam->addParam('住所2', 'shipping_addr02', MTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 371 | $objFormParam->addParam('電話番号1', 'shipping_tel01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 372 | $objFormParam->addParam('電話番号2', 'shipping_tel02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 373 | $objFormParam->addParam('電話番号3', 'shipping_tel03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
[21840] | 374 | $objFormParam->addParam('FAX番号1', 'shipping_fax01', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 375 | $objFormParam->addParam('FAX番号2', 'shipping_fax02', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
| 376 | $objFormParam->addParam('FAX番号3', 'shipping_fax03', TEL_ITEM_LEN, 'n', array('MAX_LENGTH_CHECK' ,'NUM_CHECK')); |
---|
[21514] | 377 | $objFormParam->addParam('お届け時間ID', 'time_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 378 | $objFormParam->addParam('お届け日(年)', 'shipping_date_year', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 379 | $objFormParam->addParam('お届け日(月)', 'shipping_date_month', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 380 | $objFormParam->addParam('お届け日(日)', 'shipping_date_day', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 381 | $objFormParam->addParam('お届け日', 'shipping_date', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 382 | $objFormParam->addParam('配送商品数量', 'shipping_product_quantity', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[19963] | 383 | |
---|
[21514] | 384 | $objFormParam->addParam('商品規格ID', 'shipment_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 385 | $objFormParam->addParam('商品コード', 'shipment_product_code'); |
---|
| 386 | $objFormParam->addParam('商品名', 'shipment_product_name'); |
---|
| 387 | $objFormParam->addParam('規格名1', 'shipment_classcategory_name1'); |
---|
| 388 | $objFormParam->addParam('規格名2', 'shipment_classcategory_name2'); |
---|
| 389 | $objFormParam->addParam('単価', 'shipment_price', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
| 390 | $objFormParam->addParam('数量', 'shipment_quantity', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '0'); |
---|
[19963] | 391 | |
---|
[21514] | 392 | $objFormParam->addParam('商品項番', 'no', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 393 | $objFormParam->addParam('追加商品規格ID', 'add_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 394 | $objFormParam->addParam('修正商品規格ID', 'edit_product_class_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 395 | $objFormParam->addParam('アンカーキー', 'anchor_key', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
[19919] | 396 | } |
---|
| 397 | |
---|
[19934] | 398 | /** |
---|
[20180] | 399 | * 複数配送用フォームの初期化を行う. |
---|
| 400 | * |
---|
| 401 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 402 | * @return void |
---|
[19934] | 403 | */ |
---|
[20180] | 404 | function lfInitMultipleParam(&$objFormParam) { |
---|
[21514] | 405 | $objFormParam->addParam('商品規格ID', 'multiple_product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
| 406 | $objFormParam->addParam('商品コード', 'multiple_product_code', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 407 | $objFormParam->addParam('商品名', 'multiple_product_name', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 408 | $objFormParam->addParam('規格1', 'multiple_classcategory_name1', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 409 | $objFormParam->addParam('規格2', 'multiple_classcategory_name2', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 410 | $objFormParam->addParam('単価', 'multiple_price', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
| 411 | $objFormParam->addParam('数量', 'multiple_quantity', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'), 1); |
---|
[21549] | 412 | $objFormParam->addParam('お届け先', 'multiple_shipping_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK')); |
---|
[19934] | 413 | } |
---|
[19919] | 414 | |
---|
[20180] | 415 | /** |
---|
| 416 | * 複数配送入力フォームで入力された値を SC_FormParam へ設定する. |
---|
| 417 | * |
---|
| 418 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 419 | * @return void |
---|
| 420 | */ |
---|
| 421 | function setMultipleItemTo(&$objFormParam) { |
---|
| 422 | $arrMultipleKey = array('multiple_shipping_id', |
---|
| 423 | 'multiple_product_class_id', |
---|
| 424 | 'multiple_product_name', |
---|
| 425 | 'multiple_product_code', |
---|
| 426 | 'multiple_classcategory_name1', |
---|
| 427 | 'multiple_classcategory_name2', |
---|
| 428 | 'multiple_price', |
---|
| 429 | 'multiple_quantity'); |
---|
| 430 | $arrMultipleParams = $objFormParam->getSwapArray($arrMultipleKey); |
---|
[19934] | 431 | |
---|
[20180] | 432 | /* |
---|
| 433 | * 複数配送フォームの入力値を shipping_id ごとにマージ |
---|
| 434 | * |
---|
[21549] | 435 | * $arrShipmentItem[お届け先ID][商品規格ID]['shipment_(key)'] = 値 |
---|
[20180] | 436 | */ |
---|
[19934] | 437 | $arrShipmentItem = array(); |
---|
[20180] | 438 | foreach ($arrMultipleParams as $arrMultiple) { |
---|
| 439 | $shipping_id = $arrMultiple['multiple_shipping_id']; |
---|
| 440 | $product_class_id = $arrMultiple['multiple_product_class_id']; |
---|
| 441 | foreach ($arrMultiple as $key => $val) { |
---|
| 442 | if ($key == 'multiple_quantity') { |
---|
| 443 | $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] += $val; |
---|
| 444 | } else { |
---|
| 445 | $arrShipmentItem[$shipping_id][$product_class_id][str_replace('multiple', 'shipment', $key)] = $val; |
---|
| 446 | } |
---|
| 447 | } |
---|
[19934] | 448 | } |
---|
| 449 | |
---|
[20180] | 450 | /* |
---|
[21549] | 451 | * フォームのお届け先ごとの配列を生成 |
---|
[20180] | 452 | * |
---|
[20943] | 453 | * $arrShipmentForm['(key)'][$shipping_id][$item_index] = 値 |
---|
[21549] | 454 | * $arrProductQuantity[$shipping_id] = お届け先ごとの配送商品数量 |
---|
[20180] | 455 | */ |
---|
| 456 | $arrShipmentForm = array(); |
---|
| 457 | $arrProductQuantity = array(); |
---|
| 458 | $arrShippingIds = $objFormParam->getValue('shipping_id'); |
---|
[20943] | 459 | foreach ($arrShippingIds as $shipping_id) { |
---|
[20180] | 460 | $item_index = 0; |
---|
| 461 | foreach ($arrShipmentItem[$shipping_id] as $product_class_id => $shipment_item) { |
---|
| 462 | foreach ($shipment_item as $key => $val) { |
---|
[20943] | 463 | $arrShipmentForm[$key][$shipping_id][$item_index] = $val; |
---|
[19934] | 464 | } |
---|
[20180] | 465 | // 受注商品の数量を設定 |
---|
| 466 | $arrQuantity[$product_class_id] += $shipment_item['shipment_quantity']; |
---|
| 467 | $item_index++; |
---|
[19934] | 468 | } |
---|
[21549] | 469 | // お届け先ごとの配送商品数量を設定 |
---|
[20943] | 470 | $arrProductQuantity[$shipping_id] = count($arrShipmentItem[$shipping_id]); |
---|
[19934] | 471 | } |
---|
[19949] | 472 | |
---|
[20180] | 473 | $objFormParam->setParam($arrShipmentForm); |
---|
| 474 | $objFormParam->setValue('shipping_product_quantity', $arrProductQuantity); |
---|
| 475 | |
---|
[19949] | 476 | // 受注商品の数量を変更 |
---|
[20180] | 477 | $arrDest = array(); |
---|
[21224] | 478 | foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) { |
---|
| 479 | $arrDest['quantity'][$n] = 0; |
---|
| 480 | } |
---|
[20180] | 481 | foreach ($arrQuantity as $product_class_id => $quantity) { |
---|
| 482 | foreach ($objFormParam->getValue('product_class_id') as $n => $order_product_class_id) { |
---|
| 483 | if ($product_class_id == $order_product_class_id) { |
---|
| 484 | $arrDest['quantity'][$n] = $quantity; |
---|
[19949] | 485 | } |
---|
| 486 | } |
---|
| 487 | } |
---|
[20180] | 488 | $objFormParam->setParam($arrDest); |
---|
[19934] | 489 | } |
---|
| 490 | |
---|
[20180] | 491 | /** |
---|
| 492 | * 受注データを取得して, SC_FormParam へ設定する. |
---|
| 493 | * |
---|
| 494 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 495 | * @param integer $order_id 取得元の受注ID |
---|
| 496 | * @return void |
---|
| 497 | */ |
---|
| 498 | function setOrderToFormParam(&$objFormParam, $order_id) { |
---|
| 499 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
[18235] | 500 | |
---|
[20180] | 501 | // 受注詳細を設定 |
---|
| 502 | $arrOrderDetail = $objPurchase->getOrderDetail($order_id, false); |
---|
| 503 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrOrderDetail)); |
---|
[15594] | 504 | |
---|
[20943] | 505 | $arrShippingsTmp = $objPurchase->getShippings($order_id); |
---|
| 506 | $arrShippings = array(); |
---|
| 507 | foreach ($arrShippingsTmp as $row) { |
---|
| 508 | // お届け日の処理 |
---|
[21481] | 509 | if (!SC_Utils_Ex::isBlank($row['shipping_date'])) { |
---|
| 510 | $ts = strtotime($row['shipping_date']); |
---|
[20943] | 511 | $row['shipping_date_year'] = date('Y', $ts); |
---|
| 512 | $row['shipping_date_month'] = date('n', $ts); |
---|
| 513 | $row['shipping_date_day'] = date('j', $ts); |
---|
[20180] | 514 | } |
---|
[20943] | 515 | $arrShippings[$row['shipping_id']] = $row; |
---|
[20180] | 516 | } |
---|
| 517 | $objFormParam->setValue('shipping_quantity', count($arrShippings)); |
---|
| 518 | $objFormParam->setParam(SC_Utils_Ex::sfSwapArray($arrShippings)); |
---|
[19919] | 519 | |
---|
[20180] | 520 | /* |
---|
| 521 | * 配送商品を設定 |
---|
| 522 | * |
---|
[20943] | 523 | * $arrShipmentItem['shipment_(key)'][$shipping_id][$item_index] = 値 |
---|
[21549] | 524 | * $arrProductQuantity[$shipping_id] = お届け先ごとの配送商品数量 |
---|
[20180] | 525 | */ |
---|
| 526 | $arrProductQuantity = array(); |
---|
| 527 | $arrShipmentItem = array(); |
---|
[20943] | 528 | foreach ($arrShippings as $shipping_id => $arrShipping) { |
---|
| 529 | $arrProductQuantity[$shipping_id] = count($arrShipping['shipment_item']); |
---|
[20180] | 530 | foreach ($arrShipping['shipment_item'] as $item_index => $arrItem) { |
---|
| 531 | foreach ($arrItem as $item_key => $item_val) { |
---|
[20943] | 532 | $arrShipmentItem['shipment_' . $item_key][$shipping_id][$item_index] = $item_val; |
---|
[19928] | 533 | } |
---|
[19912] | 534 | } |
---|
[15594] | 535 | } |
---|
[20180] | 536 | $objFormParam->setValue('shipping_product_quantity', $arrProductQuantity); |
---|
| 537 | $objFormParam->setParam($arrShipmentItem); |
---|
[15594] | 538 | |
---|
[20180] | 539 | /* |
---|
| 540 | * 受注情報を設定 |
---|
| 541 | * $arrOrderDetail と項目が重複しており, $arrOrderDetail は連想配列の値 |
---|
| 542 | * が渡ってくるため, $arrOrder で上書きする. |
---|
| 543 | */ |
---|
| 544 | $arrOrder = $objPurchase->getOrder($order_id); |
---|
| 545 | $objFormParam->setParam($arrOrder); |
---|
| 546 | |
---|
[21165] | 547 | // ポイントを設定 |
---|
| 548 | list($db_point, $rollback_point) = SC_Helper_DB_Ex::sfGetRollbackPoint( |
---|
| 549 | $order_id, $arrOrder['use_point'], $arrOrder['add_point'], $arrOrder['status'] |
---|
| 550 | ); |
---|
[20180] | 551 | $objFormParam->setValue('total_point', $db_point); |
---|
| 552 | $objFormParam->setValue('point', $rollback_point); |
---|
[20442] | 553 | |
---|
[21003] | 554 | if (!SC_Utils_Ex::isBlank($objFormParam->getValue('customer_id'))) { |
---|
[21004] | 555 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($objFormParam->getValue('customer_id')); |
---|
| 556 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
[20442] | 557 | } |
---|
[15594] | 558 | } |
---|
| 559 | |
---|
[19912] | 560 | /** |
---|
[20180] | 561 | * 入力内容のチェックを行う. |
---|
| 562 | * |
---|
| 563 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 564 | * @return array エラーメッセージの配列 |
---|
[19912] | 565 | */ |
---|
[20180] | 566 | function lfCheckError(&$objFormParam) { |
---|
[21311] | 567 | $objProduct = new SC_Product_Ex(); |
---|
| 568 | |
---|
[20226] | 569 | $arrErr = $objFormParam->checkError(); |
---|
[19912] | 570 | |
---|
[20180] | 571 | if (!SC_Utils_Ex::isBlank($objErr->arrErr)) { |
---|
[20226] | 572 | return $arrErr; |
---|
[18087] | 573 | } |
---|
[18819] | 574 | |
---|
[20180] | 575 | $arrValues = $objFormParam->getHashArray(); |
---|
[15594] | 576 | |
---|
| 577 | // 商品の種類数 |
---|
[20180] | 578 | $max = count($arrValues['quantity']); |
---|
[15594] | 579 | $subtotal = 0; |
---|
| 580 | $totalpoint = 0; |
---|
| 581 | $totaltax = 0; |
---|
[21441] | 582 | for ($i = 0; $i < $max; $i++) { |
---|
[15594] | 583 | // 小計の計算 |
---|
[22197] | 584 | $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i]; |
---|
[15594] | 585 | // 小計の計算 |
---|
[22197] | 586 | $totaltax += SC_Utils_Ex::sfTax($arrValues['price'][$i], $arrValues['tax_rate'][$i], $arrValues['tax_rule'][$i]) * $arrValues['quantity'][$i]; |
---|
[15594] | 587 | // 加算ポイントの計算 |
---|
[20180] | 588 | $totalpoint += SC_Utils_Ex::sfPrePoint($arrValues['price'][$i], $arrValues['point_rate'][$i]) * $arrValues['quantity'][$i]; |
---|
[20719] | 589 | |
---|
| 590 | // 在庫数のチェック |
---|
| 591 | $arrProduct = $objProduct->getDetailAndProductsClass($arrValues['product_class_id'][$i]); |
---|
| 592 | |
---|
| 593 | // 編集前の値と比較するため受注詳細を取得 |
---|
| 594 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
| 595 | $arrOrderDetail = SC_Utils_Ex::sfSwapArray($objPurchase->getOrderDetail($objFormParam->getValue('order_id'), false)); |
---|
| 596 | |
---|
| 597 | if ($arrProduct['stock_unlimited'] != '1' |
---|
| 598 | && $arrProduct['stock'] < $arrValues['quantity'][$i] - $arrOrderDetail['quantity'][$i]) { |
---|
| 599 | $class_name1 = $arrValues['classcategory_name1'][$i]; |
---|
| 600 | $class_name1 = SC_Utils_Ex::isBlank($class_name1) ? 'なし' : $class_name1; |
---|
| 601 | $class_name2 = $arrValues['classcategory_name2'][$i]; |
---|
| 602 | $class_name2 = SC_Utils_Ex::isBlank($class_name2) ? 'なし' : $class_name2; |
---|
| 603 | $arrErr['quantity'][$i] .= $arrValues['product_name'][$i] |
---|
[21019] | 604 | . '/(' . $class_name1 . ')/(' . $class_name2 . ') の在庫が不足しています。 設定できる数量は「' |
---|
[20719] | 605 | . ($arrOrderDetail['quantity'][$i] + $arrProduct['stock']) . '」までです。<br />'; |
---|
| 606 | } |
---|
[15594] | 607 | } |
---|
| 608 | |
---|
| 609 | // 消費税 |
---|
[20180] | 610 | $arrValues['tax'] = $totaltax; |
---|
[15594] | 611 | // 小計 |
---|
[20180] | 612 | $arrValues['subtotal'] = $subtotal; |
---|
[15594] | 613 | // 合計 |
---|
[20180] | 614 | $arrValues['total'] = $subtotal - $arrValues['discount'] + $arrValues['deliv_fee'] + $arrValues['charge']; |
---|
[15594] | 615 | // お支払い合計 |
---|
[20180] | 616 | $arrValues['payment_total'] = $arrValues['total'] - ($arrValues['use_point'] * POINT_VALUE); |
---|
[15594] | 617 | |
---|
| 618 | // 加算ポイント |
---|
[20180] | 619 | $arrValues['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrValues['use_point']); |
---|
[20041] | 620 | |
---|
[19674] | 621 | // 最終保持ポイント |
---|
[21101] | 622 | $arrValues['total_point'] = $objFormParam->getValue('point') - $arrValues['use_point']; |
---|
[20041] | 623 | |
---|
[20180] | 624 | if ($arrValues['total'] < 0) { |
---|
[20226] | 625 | $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
[15594] | 626 | } |
---|
| 627 | |
---|
[20180] | 628 | if ($arrValues['payment_total'] < 0) { |
---|
[20226] | 629 | $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
[15594] | 630 | } |
---|
[20180] | 631 | |
---|
| 632 | if ($arrValues['total_point'] < 0) { |
---|
[20226] | 633 | $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; |
---|
[15594] | 634 | } |
---|
| 635 | |
---|
[20180] | 636 | $objFormParam->setParam($arrValues); |
---|
[20226] | 637 | return $arrErr; |
---|
[15594] | 638 | } |
---|
| 639 | |
---|
[18100] | 640 | /** |
---|
| 641 | * DB更新処理 |
---|
| 642 | * |
---|
[20180] | 643 | * @param integer $order_id 受注ID |
---|
| 644 | * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス |
---|
| 645 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
[20577] | 646 | * @param string $message 通知メッセージ |
---|
[21036] | 647 | * @param array $arrValuesBefore 更新前の受注情報 |
---|
[20180] | 648 | * @return integer $order_id 受注ID |
---|
[20577] | 649 | * |
---|
| 650 | * エラー発生時は負数を返す。 |
---|
[18100] | 651 | */ |
---|
[21036] | 652 | function doRegister($order_id, &$objPurchase, &$objFormParam, &$message, &$arrValuesBefore) { |
---|
[15594] | 653 | |
---|
[20507] | 654 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20180] | 655 | $arrValues = $objFormParam->getDbArray(); |
---|
[15594] | 656 | |
---|
[21514] | 657 | $where = 'order_id = ?'; |
---|
[15594] | 658 | |
---|
[18329] | 659 | $objQuery->begin(); |
---|
[21118] | 660 | |
---|
[21036] | 661 | // 支払い方法が変更されたら、支払い方法名称も更新 |
---|
| 662 | if ($arrValues['payment_id'] != $arrValuesBefore['payment_id']) { |
---|
| 663 | $arrValues['payment_method'] = $this->arrPayment[$arrValues['payment_id']]; |
---|
| 664 | $arrValuesBefore['payment_id'] = NULL; |
---|
| 665 | } |
---|
[18329] | 666 | |
---|
[15594] | 667 | // 受注テーブルの更新 |
---|
[20180] | 668 | $order_id = $objPurchase->registerOrder($order_id, $arrValues); |
---|
[18819] | 669 | |
---|
[21527] | 670 | $arrDetail = $objFormParam->getSwapArray(array( |
---|
| 671 | 'product_id', |
---|
| 672 | 'product_class_id', |
---|
| 673 | 'product_code', |
---|
| 674 | 'product_name', |
---|
| 675 | 'price', 'quantity', |
---|
| 676 | 'point_rate', |
---|
| 677 | 'classcategory_name1', |
---|
| 678 | 'classcategory_name2', |
---|
[22197] | 679 | 'tax_rate', |
---|
| 680 | 'tax_rule' |
---|
[21527] | 681 | )); |
---|
[18819] | 682 | |
---|
[18646] | 683 | // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算 |
---|
| 684 | $max = count($arrDetail); |
---|
| 685 | $k = 0; |
---|
| 686 | $arrStockData = array(); |
---|
[21441] | 687 | for ($i = 0; $i < $max; $i++) { |
---|
[18646] | 688 | if (!empty($arrDetail[$i]['product_id'])) { |
---|
[21515] | 689 | $arrPreDetail = $objQuery->select('*', 'dtb_order_detail', 'order_id = ? AND product_class_id = ?', array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
[18646] | 690 | if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) { |
---|
| 691 | // 数量が変更された商品 |
---|
[18872] | 692 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[18646] | 693 | $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity']; |
---|
| 694 | ++$k; |
---|
| 695 | } elseif (empty($arrPreDetail)) { |
---|
| 696 | // 新しく追加された商品 もしくは 違う商品に変更された商品 |
---|
[18872] | 697 | $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id']; |
---|
[18646] | 698 | $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity']; |
---|
| 699 | ++$k; |
---|
| 700 | } |
---|
[21514] | 701 | $objQuery->delete('dtb_order_detail', 'order_id = ? AND product_class_id = ?', array($order_id, $arrDetail[$i]['product_class_id'])); |
---|
[18646] | 702 | } |
---|
| 703 | } |
---|
| 704 | |
---|
| 705 | // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品 |
---|
[21515] | 706 | $arrPreDetail = $objQuery->select('*', 'dtb_order_detail', 'order_id = ?', array($order_id)); |
---|
[18646] | 707 | foreach ($arrPreDetail AS $key=>$val) { |
---|
[18872] | 708 | $arrStockData[$k]['product_class_id'] = $val['product_class_id']; |
---|
[18646] | 709 | $arrStockData[$k]['quantity'] = $val['quantity']; |
---|
| 710 | ++$k; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | // 受注詳細データの更新 |
---|
[20180] | 714 | $objPurchase->registerOrderDetail($order_id, $arrDetail); |
---|
[18074] | 715 | |
---|
[18646] | 716 | // 在庫数調整 |
---|
[20180] | 717 | if (ORDER_DELIV != $arrValues['status'] |
---|
| 718 | && ORDER_CANCEL != $arrValues['status']) { |
---|
| 719 | foreach ($arrStockData AS $stock) { |
---|
| 720 | $objQuery->update('dtb_products_class', array(), |
---|
| 721 | 'product_class_id = ?', |
---|
| 722 | array($stock['product_class_id']), |
---|
| 723 | array('stock' => 'stock + ?'), |
---|
| 724 | array($stock['quantity'])); |
---|
[18646] | 725 | } |
---|
| 726 | } |
---|
| 727 | |
---|
[20943] | 728 | $arrAllShipping = $objFormParam->getSwapArray($this->arrShippingKeys); |
---|
| 729 | $arrAllShipmentItem = $objFormParam->getSwapArray($this->arrShipmentItemKeys); |
---|
[19949] | 730 | |
---|
[20804] | 731 | $arrDelivTime = $objPurchase->getDelivTime($objFormParam->getValue('deliv_id')); |
---|
| 732 | |
---|
[20180] | 733 | $arrShippingValues = array(); |
---|
| 734 | foreach ($arrAllShipping as $shipping_index => $arrShipping) { |
---|
| 735 | $shipping_id = $arrShipping['shipping_id']; |
---|
| 736 | $arrShippingValues[$shipping_index] = $arrShipping; |
---|
[19949] | 737 | |
---|
[20180] | 738 | $arrShippingValues[$shipping_index]['shipping_date'] |
---|
| 739 | = SC_Utils_Ex::sfGetTimestamp($arrShipping['shipping_date_year'], |
---|
| 740 | $arrShipping['shipping_date_month'], |
---|
| 741 | $arrShipping['shipping_date_day']); |
---|
[19963] | 742 | |
---|
[20180] | 743 | // 配送業者IDを取得 |
---|
| 744 | $arrShippingValues[$shipping_index]['deliv_id'] = $objFormParam->getValue('deliv_id'); |
---|
[19949] | 745 | |
---|
[20804] | 746 | // お届け時間名称を取得 |
---|
| 747 | $arrShippingValues[$shipping_index]['shipping_time'] = $arrDelivTime[$arrShipping['time_id']]; |
---|
| 748 | |
---|
[20180] | 749 | // 複数配送の場合は配送商品を登録 |
---|
| 750 | if (!SC_Utils_Ex::isBlank($arrAllShipmentItem)) { |
---|
| 751 | $arrShipmentValues = array(); |
---|
[19963] | 752 | |
---|
[20180] | 753 | foreach ($arrAllShipmentItem[$shipping_index] as $key => $arrItem) { |
---|
| 754 | $i = 0; |
---|
| 755 | foreach ($arrItem as $item) { |
---|
| 756 | $arrShipmentValues[$shipping_index][$i][str_replace('shipment_', '', $key)] = $item; |
---|
| 757 | $i++; |
---|
| 758 | } |
---|
[19949] | 759 | } |
---|
[20180] | 760 | $objPurchase->registerShipmentItem($order_id, $shipping_id, |
---|
| 761 | $arrShipmentValues[$shipping_index]); |
---|
[19949] | 762 | } |
---|
| 763 | } |
---|
[20180] | 764 | $objPurchase->registerShipping($order_id, $arrShippingValues, false); |
---|
[15594] | 765 | $objQuery->commit(); |
---|
[20180] | 766 | return $order_id; |
---|
[15594] | 767 | } |
---|
[17293] | 768 | |
---|
[18100] | 769 | /** |
---|
[20180] | 770 | * 受注商品の追加/更新を行う. |
---|
[18100] | 771 | * |
---|
[20180] | 772 | * 小画面で選択した受注商品をフォームに反映させる. |
---|
| 773 | * |
---|
| 774 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 775 | * @return void |
---|
[18100] | 776 | */ |
---|
[20180] | 777 | function doRegisterProduct(&$objFormParam) { |
---|
| 778 | $product_class_id = $objFormParam->getValue('add_product_class_id'); |
---|
| 779 | if (SC_Utils_Ex::isBlank($product_class_id)) { |
---|
| 780 | $product_class_id = $objFormParam->getValue('edit_product_class_id'); |
---|
[20415] | 781 | $changed_no = $objFormParam->getValue('no'); |
---|
[17293] | 782 | } |
---|
[21331] | 783 | // FXIME バリデーションを通さず $objFormParam の値で DB 問い合わせしている。(管理機能ため、さほど問題は無いと思うものの…) |
---|
[18037] | 784 | |
---|
[21331] | 785 | // 商品規格IDが指定されていない場合、例外エラーを発生 |
---|
| 786 | if (strlen($product_class_id) === 0) { |
---|
[21582] | 787 | trigger_error('商品規格指定なし', E_USER_ERROR); |
---|
[21331] | 788 | } |
---|
| 789 | |
---|
[20415] | 790 | // 選択済みの商品であれば数量を1増やす |
---|
[20180] | 791 | $exists = false; |
---|
| 792 | $arrExistsProductClassIds = $objFormParam->getValue('product_class_id'); |
---|
[21935] | 793 | foreach ($arrExistsProductClassIds as $key => $value) { |
---|
[20180] | 794 | $exists_product_class_id = $arrExistsProductClassIds[$key]; |
---|
| 795 | if ($exists_product_class_id == $product_class_id) { |
---|
| 796 | $exists = true; |
---|
[20982] | 797 | $exists_no = $key; |
---|
[20180] | 798 | $arrExistsQuantity = $objFormParam->getValue('quantity'); |
---|
| 799 | $arrExistsQuantity[$key]++; |
---|
| 800 | $objFormParam->setValue('quantity', $arrExistsQuantity); |
---|
[19963] | 801 | } |
---|
[18646] | 802 | } |
---|
[19963] | 803 | |
---|
[20180] | 804 | // 新しく商品を追加した場合はフォームに登録 |
---|
[20415] | 805 | // 商品を変更した場合は、該当行を変更 |
---|
[20180] | 806 | if (!$exists) { |
---|
[20487] | 807 | $objProduct = new SC_Product_Ex(); |
---|
[20180] | 808 | $arrProduct = $objProduct->getDetailAndProductsClass($product_class_id); |
---|
[21331] | 809 | |
---|
| 810 | // 一致する商品規格がない場合、例外エラーを発生 |
---|
| 811 | if (empty($arrProduct)) { |
---|
[21582] | 812 | trigger_error('商品規格一致なし', E_USER_ERROR); |
---|
[21331] | 813 | } |
---|
| 814 | |
---|
[20180] | 815 | $arrProduct['quantity'] = 1; |
---|
| 816 | $arrProduct['price'] = $arrProduct['price02']; |
---|
[22197] | 817 | $arrProduct['tax_rate'] = $objFormParam->getValue('order_tax_rate') == '' ? $this->arrInfo['tax'] : $objFormParam->getValue('order_tax_rate'); |
---|
| 818 | $arrProduct['tax_rule'] = $objFormParam->getValue('order_tax_rule') == '' ? $this->arrInfo['tax_rule'] : $objFormParam->getValue('order_tax_rule'); |
---|
[20180] | 819 | $arrProduct['product_name'] = $arrProduct['name']; |
---|
[21981] | 820 | |
---|
[21527] | 821 | $arrUpdateKeys = array( |
---|
| 822 | 'product_id', 'product_class_id', 'product_type_id', 'point_rate', |
---|
| 823 | 'product_code', 'product_name', 'classcategory_name1', 'classcategory_name2', |
---|
[22197] | 824 | 'quantity', 'price', 'tax_rate', 'tax_rule' |
---|
[21527] | 825 | ); |
---|
[20180] | 826 | foreach ($arrUpdateKeys as $key) { |
---|
| 827 | $arrValues = $objFormParam->getValue($key); |
---|
[21870] | 828 | // FIXME getValueで文字列が返る場合があるので配列であるかをチェック |
---|
[21981] | 829 | if (!is_array($arrValues)) { |
---|
[21870] | 830 | $arrValues = array(); |
---|
| 831 | } |
---|
[21981] | 832 | |
---|
[20415] | 833 | if (isset($changed_no)) { |
---|
| 834 | $arrValues[$changed_no] = $arrProduct[$key]; |
---|
| 835 | } else { |
---|
[21117] | 836 | $added_no = 0; |
---|
| 837 | if (is_array($arrExistsProductClassIds)) { |
---|
| 838 | $added_no = count($arrExistsProductClassIds); |
---|
| 839 | } |
---|
| 840 | $arrValues[$added_no] = $arrProduct[$key]; |
---|
[20415] | 841 | } |
---|
[20180] | 842 | $objFormParam->setValue($key, $arrValues); |
---|
[19963] | 843 | } |
---|
[20982] | 844 | } elseif (isset($changed_no) && $exists_no != $changed_no) { |
---|
[20416] | 845 | // 変更したが、選択済みの商品だった場合は、変更対象行を削除。 |
---|
[20415] | 846 | $this->doDeleteProduct($changed_no, $objFormParam); |
---|
[19963] | 847 | } |
---|
[17293] | 848 | } |
---|
| 849 | |
---|
[19919] | 850 | /** |
---|
[20180] | 851 | * 受注商品を削除する. |
---|
| 852 | * |
---|
| 853 | * @param integer $delete_no 削除する受注商品の項番 |
---|
| 854 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 855 | * @return void |
---|
[19919] | 856 | */ |
---|
[20180] | 857 | function doDeleteProduct($delete_no, &$objFormParam) { |
---|
[21527] | 858 | $arrDeleteKeys = array( |
---|
| 859 | 'product_id', 'product_class_id', 'product_type_id', 'point_rate', |
---|
| 860 | 'product_code', 'product_name', 'classcategory_name1', 'classcategory_name2', |
---|
[22197] | 861 | 'quantity', 'price', 'tax_rate', 'tax_rule' |
---|
[21527] | 862 | ); |
---|
[20180] | 863 | foreach ($arrDeleteKeys as $key) { |
---|
| 864 | $arrNewValues = array(); |
---|
| 865 | $arrValues = $objFormParam->getValue($key); |
---|
| 866 | foreach ($arrValues as $index => $val) { |
---|
| 867 | if ($index != $delete_no) { |
---|
| 868 | $arrNewValues[] = $val; |
---|
[18014] | 869 | } |
---|
| 870 | } |
---|
[20180] | 871 | $objFormParam->setValue($key, $arrNewValues); |
---|
[18014] | 872 | } |
---|
[17293] | 873 | } |
---|
| 874 | |
---|
[20180] | 875 | /** |
---|
| 876 | * お届け先を追加する. |
---|
| 877 | * |
---|
| 878 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 879 | * @return void |
---|
| 880 | */ |
---|
| 881 | function addShipping(&$objFormParam) { |
---|
| 882 | $objFormParam->setValue('shipping_quantity', |
---|
| 883 | $objFormParam->getValue('shipping_quantity') + 1); |
---|
| 884 | $arrShippingIds = $objFormParam->getValue('shipping_id'); |
---|
| 885 | $arrShippingIds[] = max($arrShippingIds) + 1; |
---|
| 886 | $objFormParam->setValue('shipping_id', $arrShippingIds); |
---|
[17293] | 887 | } |
---|
| 888 | |
---|
[18068] | 889 | /** |
---|
[21419] | 890 | * 会員情報をフォームに設定する. |
---|
[20180] | 891 | * |
---|
[21419] | 892 | * @param integer $customer_id 会員ID |
---|
[20180] | 893 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 894 | * @return void |
---|
[18068] | 895 | */ |
---|
[20180] | 896 | function setCustomerTo($customer_id, &$objFormParam) { |
---|
| 897 | $arrCustomer = SC_Helper_Customer_Ex::sfGetCustomerDataFromId($customer_id); |
---|
| 898 | foreach ($arrCustomer as $key => $val) { |
---|
| 899 | $objFormParam->setValue('order_' . $key, $val); |
---|
[18068] | 900 | } |
---|
[20180] | 901 | $objFormParam->setValue('customer_id', $customer_id); |
---|
[20442] | 902 | $objFormParam->setValue('customer_point', $arrCustomer['point']); |
---|
[18068] | 903 | } |
---|
[18329] | 904 | |
---|
| 905 | /** |
---|
[20180] | 906 | * アンカーキーを取得する. |
---|
[18329] | 907 | * |
---|
[20180] | 908 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
| 909 | * @return アンカーキーの文字列 |
---|
[18329] | 910 | */ |
---|
[20180] | 911 | function getAnchorKey(&$objFormParam) { |
---|
| 912 | $ancor_key = $objFormParam->getValue('anchor_key'); |
---|
| 913 | if (!SC_Utils_Ex::isBlank($ancor_key)) { |
---|
| 914 | return "location.hash='#" . htmlentities(urlencode($ancor_key), ENT_QUOTES) . "'"; |
---|
[18329] | 915 | } |
---|
[20180] | 916 | return ''; |
---|
[19963] | 917 | } |
---|
[15594] | 918 | } |
---|