1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | // {{{ requires |
---|
25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /* GMO決済モジュール連携用 */ |
---|
28 | if (file_exists(MODULE_PATH . 'mdl_gmopg/inc/include.php') === TRUE) { |
---|
29 | require_once(MODULE_PATH . 'mdl_gmopg/inc/include.php'); |
---|
30 | } |
---|
31 | |
---|
32 | /* ペイジェント決済モジュール連携用 */ |
---|
33 | if (file_exists(MODULE_PATH . 'mdl_paygent/include.php') === TRUE) { |
---|
34 | require_once(MODULE_PATH . 'mdl_paygent/include.php'); |
---|
35 | } |
---|
36 | |
---|
37 | /* F-REGI決済モジュール連携用 */ |
---|
38 | if (file_exists(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php') === TRUE) { |
---|
39 | require_once(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php'); |
---|
40 | } |
---|
41 | |
---|
42 | /* SPS決済モジュール連携用 */ |
---|
43 | if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) { |
---|
44 | require_once(MODULE_PATH . 'mdl_sps/request.php'); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | /** |
---|
49 | * 受注修正 のページクラス. |
---|
50 | * |
---|
51 | * @package Page |
---|
52 | * @author LOCKON CO.,LTD. |
---|
53 | * @version $Id$ |
---|
54 | */ |
---|
55 | class LC_Page_Admin_Order_Edit extends LC_Page { |
---|
56 | |
---|
57 | // {{{ properties |
---|
58 | |
---|
59 | /** 表示モード */ |
---|
60 | var $disp_mode; |
---|
61 | |
---|
62 | // }}} |
---|
63 | // {{{ functions |
---|
64 | |
---|
65 | /** |
---|
66 | * Page を初期化する. |
---|
67 | * |
---|
68 | * @return void |
---|
69 | */ |
---|
70 | function init() { |
---|
71 | parent::init(); |
---|
72 | $this->tpl_mainpage = 'order/edit.tpl'; |
---|
73 | $this->tpl_subnavi = 'order/subnavi.tpl'; |
---|
74 | $this->tpl_mainno = 'order'; |
---|
75 | $this->tpl_subno = 'index'; |
---|
76 | $this->tpl_subtitle = '受注管理'; |
---|
77 | if (empty($_GET['order_id']) && empty($_POST['order_id'])) { |
---|
78 | $this->tpl_subno = 'add'; |
---|
79 | $this->tpl_mode = 'add'; |
---|
80 | $this->tpl_subtitle = '新規受注入力'; |
---|
81 | } |
---|
82 | |
---|
83 | $masterData = new SC_DB_MasterData_Ex(); |
---|
84 | $this->arrPref = $masterData->getMasterData("mtb_pref", |
---|
85 | array("pref_id", "pref_name", "rank")); |
---|
86 | $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status"); |
---|
87 | |
---|
88 | /* ペイジェント決済モジュール連携用 */ |
---|
89 | if(function_exists("sfPaygentOrderPage")) { |
---|
90 | $this->arrDispKind = sfPaygentOrderPage(); |
---|
91 | } |
---|
92 | |
---|
93 | /* F-REGI決済モジュール連携用 */ |
---|
94 | if (file_exists(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php') === TRUE) { |
---|
95 | global $arrFregiPayment; |
---|
96 | $this->arrFregiPayment = $arrFregiPayment; |
---|
97 | global $arrFregiDispKind; |
---|
98 | $this->arrFregiDispKind = $arrFregiDispKind; |
---|
99 | } |
---|
100 | $this->httpCacheControl('nocache'); |
---|
101 | } |
---|
102 | |
---|
103 | /** |
---|
104 | * Page のプロセス. |
---|
105 | * |
---|
106 | * @return void |
---|
107 | */ |
---|
108 | function process() { |
---|
109 | $conn = new SC_DBConn(); |
---|
110 | $objView = new SC_AdminView(); |
---|
111 | $objSess = new SC_Session(); |
---|
112 | $objDb = new SC_Helper_DB_Ex(); |
---|
113 | $objDate = new SC_Date(1901); |
---|
114 | $this->arrYearDelivDate = $objDate->getYear('', date('Y'), ''); |
---|
115 | $this->arrMonthDelivDate = $objDate->getMonth(true); |
---|
116 | $this->arrDayDelivDate = $objDate->getDay(true); |
---|
117 | |
---|
118 | // パラメータ管理クラス |
---|
119 | $this->objFormParam = new SC_FormParam(); |
---|
120 | // パラメータ情報の初期化 |
---|
121 | $this->lfInitParam(); |
---|
122 | |
---|
123 | // 認証可否の判定 |
---|
124 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
125 | |
---|
126 | // 検索パラメータの引き継ぎ |
---|
127 | foreach ($_POST as $key => $val) { |
---|
128 | if (ereg("^search_", $key)) { |
---|
129 | $this->arrSearchHidden[$key] = $val; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | // 表示モード判定 |
---|
134 | if(isset($_GET['order_id']) && |
---|
135 | SC_Utils_Ex::sfIsInt($_GET['order_id'])) { |
---|
136 | $this->disp_mode = true; |
---|
137 | $order_id = $_GET['order_id']; |
---|
138 | } else { |
---|
139 | $order_id = $_POST['order_id']; |
---|
140 | } |
---|
141 | $this->tpl_order_id = $order_id; |
---|
142 | |
---|
143 | // DBから受注情報を読み込む |
---|
144 | $this->lfGetOrderData($order_id); |
---|
145 | |
---|
146 | switch($_POST['mode']) { |
---|
147 | case 'pre_edit': |
---|
148 | case 'order_id': |
---|
149 | break; |
---|
150 | case 'edit': |
---|
151 | case 'add': |
---|
152 | // POST情報で上書き |
---|
153 | $this->objFormParam->setParam($_POST); |
---|
154 | |
---|
155 | // 入力値の変換 |
---|
156 | $this->objFormParam->convParam(); |
---|
157 | $this->arrErr = $this->lfCheckError(); |
---|
158 | |
---|
159 | if(count($this->arrErr) == 0) { |
---|
160 | if ($_POST['mode'] == 'add') { |
---|
161 | $order_id = $this->lfRegistNewData(); |
---|
162 | |
---|
163 | $this->tpl_order_id = $order_id; |
---|
164 | $this->tpl_mode = 'edit'; |
---|
165 | |
---|
166 | $arrData['order_id'] = $order_id; |
---|
167 | $this->objFormParam->setParam($arrData); |
---|
168 | |
---|
169 | $text = "'新規受注を登録しました。'"; |
---|
170 | } else { |
---|
171 | $this->lfRegistData($_POST['order_id']); |
---|
172 | $text = "'受注履歴を編集しました。'"; |
---|
173 | } |
---|
174 | // DBから受注情報を再読込 |
---|
175 | $this->lfGetOrderData($order_id); |
---|
176 | $this->tpl_onload = "window.alert(".$text.");"; |
---|
177 | } |
---|
178 | break; |
---|
179 | // 再計算 |
---|
180 | case 'cheek': |
---|
181 | //支払い方法の選択 |
---|
182 | case 'payment': |
---|
183 | // POST情報で上書き |
---|
184 | $this->objFormParam->setParam($_POST); |
---|
185 | // 入力値の変換 |
---|
186 | $this->objFormParam->convParam(); |
---|
187 | $this->arrErr = $this->lfCheckError(); |
---|
188 | break; |
---|
189 | /* ペイジェント決済モジュール連携用 */ |
---|
190 | case 'paygent_order': |
---|
191 | $this->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id); |
---|
192 | break; |
---|
193 | /* 商品削除*/ |
---|
194 | case 'delete_product': |
---|
195 | $delete_no = $_POST['delete_no']; |
---|
196 | foreach ($_POST AS $key=>$val) { |
---|
197 | if (is_array($val)) { |
---|
198 | foreach ($val AS $k=>$v) { |
---|
199 | if ($k != $delete_no) { |
---|
200 | $arrData[$key][] = $v; |
---|
201 | } |
---|
202 | } |
---|
203 | } else { |
---|
204 | $arrData[$key] = $val; |
---|
205 | } |
---|
206 | } |
---|
207 | // 情報上書き |
---|
208 | $this->objFormParam->setParam($arrData); |
---|
209 | // 入力値の変換 |
---|
210 | $this->objFormParam->convParam(); |
---|
211 | $this->arrErr = $this->lfCheckError(); |
---|
212 | break; |
---|
213 | /* 商品追加ポップアップより商品選択後、商品情報取得*/ |
---|
214 | case 'select_product_detail': |
---|
215 | // POST情報で上書き |
---|
216 | $this->objFormParam->setParam($_POST); |
---|
217 | if (!empty($_POST['add_product_id'])) { |
---|
218 | $this->lfInsertProduct($_POST['add_product_id'], $_POST['add_classcategory_id1'], $_POST['add_classcategory_id2']); |
---|
219 | } elseif (!empty($_POST['edit_product_id'])) { |
---|
220 | $this->lfUpdateProduct($_POST['edit_product_id'], $_POST['edit_classcategory_id1'], $_POST['edit_classcategory_id2'], $_POST['no']); |
---|
221 | } |
---|
222 | $arrData = $_POST; |
---|
223 | foreach ($this->arrForm AS $key=>$val) { |
---|
224 | if (is_array($val)) { |
---|
225 | $arrData[$key] = $this->arrForm[$key]['value']; |
---|
226 | } else { |
---|
227 | $arrData[$key] = $val; |
---|
228 | } |
---|
229 | } |
---|
230 | // 情報上書き |
---|
231 | $this->objFormParam->setParam($arrData); |
---|
232 | // 入力値の変換 |
---|
233 | $this->objFormParam->convParam(); |
---|
234 | $this->arrErr = $this->lfCheckError(); |
---|
235 | break; |
---|
236 | /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/ |
---|
237 | case 'search_customer': |
---|
238 | // POST情報で上書き |
---|
239 | $this->objFormParam->setParam($_POST); |
---|
240 | |
---|
241 | // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
242 | $this->lfSetCustomerInfo($_POST['edit_customer_id']); |
---|
243 | |
---|
244 | break; |
---|
245 | /* F-REGI決済モジュール連携用 */ |
---|
246 | case 'fregi_status': |
---|
247 | $objFregiConfig = new LC_Page_Mdl_Fregi_Config(); |
---|
248 | $this->fregi_err = $objFregiConfig->getSaleInfo($order_id, $this->arrDisp); |
---|
249 | $this->lfGetOrderData($order_id); |
---|
250 | break; |
---|
251 | case 'fregi_card': |
---|
252 | $objFregiConfig = new LC_Page_Mdl_Fregi_Config(); |
---|
253 | $this->fregi_card_err = $objFregiConfig->setCardInfo($_POST['card_status'], $order_id, $this->arrDisp); |
---|
254 | $this->lfGetOrderData($order_id); |
---|
255 | break; |
---|
256 | /* SPS決済モジュール連携用 */ |
---|
257 | case 'sps_request': |
---|
258 | $objErr = new SC_CheckError($_POST); |
---|
259 | $objErr->doFunc(array("年","sps_year"), array('EXIST_CHECK')); |
---|
260 | $objErr->doFunc(array("月","sps_month"), array('EXIST_CHECK')); |
---|
261 | $objErr->doFunc(array("日","sps_date"), array('EXIST_CHECK')); |
---|
262 | $objErr->doFunc(array("売上・返金日", "sps_year", "sps_month", "sps_date"), array("CHECK_DATE")); |
---|
263 | if ($objErr->arrErr) { |
---|
264 | $this->arrErr = $objErr->arrErr; |
---|
265 | break; |
---|
266 | } |
---|
267 | $sps_return = sfSpsRequest( $order_id, $_POST['request_type'] ); |
---|
268 | // DBから受注情報を再読込 |
---|
269 | $this->lfGetOrderData($order_id); |
---|
270 | $this->tpl_onload = "window.alert('".$sps_return."');"; |
---|
271 | break; |
---|
272 | |
---|
273 | /* GMOPG連携用 */ |
---|
274 | case 'gmopg_order_edit': |
---|
275 | require_once(MODULE_PATH . 'mdl_gmopg/class/LC_Mdl_GMOPG_OrderEdit.php'); |
---|
276 | $objGMOOrderEdit = new LC_MDL_GMOPG_OrderEdit; |
---|
277 | $this->gmopg_order_edit_result = $objGMOOrderEdit->proccess(); |
---|
278 | $this->lfGetOrderData($order_id); |
---|
279 | break; |
---|
280 | default: |
---|
281 | break; |
---|
282 | } |
---|
283 | |
---|
284 | // 支払い方法の取得 |
---|
285 | $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method"); |
---|
286 | // お届け時間の取得 |
---|
287 | $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id')); |
---|
288 | $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time'); |
---|
289 | |
---|
290 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
291 | $this->product_count = count($this->arrForm['quantity']['value']); |
---|
292 | |
---|
293 | // アンカーを設定 |
---|
294 | if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) { |
---|
295 | $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'"; |
---|
296 | } else { |
---|
297 | $anchor_hash = ""; |
---|
298 | } |
---|
299 | $this->tpl_onload .= $anchor_hash; |
---|
300 | |
---|
301 | $objSiteInfo = new SC_SiteInfo(); |
---|
302 | $this->arrInfo = $objSiteInfo->data; |
---|
303 | |
---|
304 | /** |
---|
305 | * SPS決済 クレジット判定用処理 |
---|
306 | */ |
---|
307 | if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) { |
---|
308 | $objQuery = new SC_Query(); |
---|
309 | $this->paymentType = $objQuery->getall("SELECT module_code, memo03 FROM dtb_payment WHERE payment_id = ? ", array($this->arrForm["payment_id"]['value'])); |
---|
310 | $objDate = new SC_Date(); |
---|
311 | $objDate->setStartYear(RELEASE_YEAR); |
---|
312 | $this->arrYear = $objDate->getYear(); |
---|
313 | $this->arrMonth = $objDate->getMonth(); |
---|
314 | $this->arrDay = $objDate->getDay(); |
---|
315 | } |
---|
316 | |
---|
317 | $objView->assignobj($this); |
---|
318 | // 表示モード判定 |
---|
319 | if(!$this->disp_mode) { |
---|
320 | $objView->display(MAIN_FRAME); |
---|
321 | } else { |
---|
322 | $objView->display('order/disp.tpl'); |
---|
323 | } |
---|
324 | } |
---|
325 | |
---|
326 | /** |
---|
327 | * デストラクタ. |
---|
328 | * |
---|
329 | * @return void |
---|
330 | */ |
---|
331 | function destroy() { |
---|
332 | parent::destroy(); |
---|
333 | } |
---|
334 | |
---|
335 | /* パラメータ情報の初期化 */ |
---|
336 | function lfInitParam() { |
---|
337 | |
---|
338 | // お客様情報 |
---|
339 | $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
340 | $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
341 | $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
342 | $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
343 | $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK")); |
---|
344 | $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
345 | $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
346 | $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
347 | $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
348 | $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
349 | $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
350 | $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
351 | $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
352 | |
---|
353 | // お届け先情報 |
---|
354 | $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
355 | $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
356 | $this->objFormParam->addParam("フリガナ1", "deliv_kana01", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
357 | $this->objFormParam->addParam("フリガナ2", "deliv_kana02", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
358 | $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
359 | $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK")); |
---|
360 | $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
361 | $this->objFormParam->addParam("住所1", "deliv_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
362 | $this->objFormParam->addParam("住所2", "deliv_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
363 | $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
364 | $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
365 | $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK")); |
---|
366 | |
---|
367 | |
---|
368 | // 受注商品情報 |
---|
369 | $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
370 | $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
371 | $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
372 | |
---|
373 | // ポイント機能ON時のみ |
---|
374 | if (USE_POINT !== false) { |
---|
375 | $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
376 | } |
---|
377 | |
---|
378 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
379 | $this->objFormParam->addParam("お届け時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
380 | $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
381 | $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
382 | $this->objFormParam->addParam("お支払方法名称", "payment_method"); |
---|
383 | $this->objFormParam->addParam("お届け時間", "deliv_time"); |
---|
384 | |
---|
385 | // 受注詳細情報 |
---|
386 | $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
387 | $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
388 | $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0'); |
---|
389 | $this->objFormParam->addParam("ポイント付与率", "point_rate"); |
---|
390 | $this->objFormParam->addParam("商品コード", "product_code"); |
---|
391 | $this->objFormParam->addParam("商品名", "product_name"); |
---|
392 | $this->objFormParam->addParam("規格1", "classcategory_id1"); |
---|
393 | $this->objFormParam->addParam("規格2", "classcategory_id2"); |
---|
394 | $this->objFormParam->addParam("規格名1", "classcategory_name1"); |
---|
395 | $this->objFormParam->addParam("規格名2", "classcategory_name2"); |
---|
396 | $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
397 | // DB読込用 |
---|
398 | $this->objFormParam->addParam("小計", "subtotal"); |
---|
399 | $this->objFormParam->addParam("合計", "total"); |
---|
400 | $this->objFormParam->addParam("支払い合計", "payment_total"); |
---|
401 | $this->objFormParam->addParam("加算ポイント", "add_point"); |
---|
402 | $this->objFormParam->addParam("お誕生日ポイント", "birth_point"); |
---|
403 | $this->objFormParam->addParam("消費税合計", "tax"); |
---|
404 | $this->objFormParam->addParam("最終保持ポイント", "total_point"); |
---|
405 | $this->objFormParam->addParam("顧客ID", "customer_id"); |
---|
406 | $this->objFormParam->addParam("現在のポイント", "point"); |
---|
407 | $this->objFormParam->addParam("注文番号", "order_id"); |
---|
408 | $this->objFormParam->addParam("受注日", "create_date"); |
---|
409 | $this->objFormParam->addParam("発送日", "commit_date"); |
---|
410 | $this->objFormParam->addParam("備考", "message"); |
---|
411 | } |
---|
412 | |
---|
413 | function lfGetOrderData($order_id) { |
---|
414 | if(SC_Utils_Ex::sfIsInt($order_id)) { |
---|
415 | // DBから受注情報を読み込む |
---|
416 | $objQuery = new SC_Query(); |
---|
417 | $objDb = new SC_Helper_DB_Ex(); |
---|
418 | $where = "order_id = ?"; |
---|
419 | $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id)); |
---|
420 | $this->objFormParam->setParam($arrRet[0]); |
---|
421 | list($point, $total_point) = $objDb->sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']); |
---|
422 | $this->objFormParam->setValue('total_point', $total_point); |
---|
423 | $this->objFormParam->setValue('point', $point); |
---|
424 | $this->arrForm = $arrRet[0]; |
---|
425 | |
---|
426 | // 受注詳細データの取得 |
---|
427 | $arrRet = $this->lfGetOrderDetail($order_id); |
---|
428 | $arrRet = SC_Utils_Ex::sfSwapArray($arrRet); |
---|
429 | $this->arrForm = array_merge($this->arrForm, $arrRet); |
---|
430 | $this->objFormParam->setParam($arrRet); |
---|
431 | |
---|
432 | // その他支払い情報を表示 |
---|
433 | if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]); |
---|
434 | if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){ |
---|
435 | $this->arrForm["payment_type"] = "クレジット決済"; |
---|
436 | }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){ |
---|
437 | $this->arrForm["payment_type"] = "コンビニ決済"; |
---|
438 | }else{ |
---|
439 | $this->arrForm["payment_type"] = "お支払い"; |
---|
440 | } |
---|
441 | // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため) |
---|
442 | $this->arrDisp = $this->arrForm; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | // 受注詳細データの取得 |
---|
447 | function lfGetOrderDetail($order_id) { |
---|
448 | $objQuery = new SC_Query(); |
---|
449 | $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate"; |
---|
450 | $where = "order_id = ?"; |
---|
451 | $objQuery->setorder("classcategory_id1, classcategory_id2"); |
---|
452 | $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id)); |
---|
453 | return $arrRet; |
---|
454 | } |
---|
455 | |
---|
456 | /* 入力内容のチェック */ |
---|
457 | function lfCheckError() { |
---|
458 | // 入力データを渡す。 |
---|
459 | $arrRet = $this->objFormParam->getHashArray(); |
---|
460 | $objErr = new SC_CheckError($arrRet); |
---|
461 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
462 | |
---|
463 | if (count($objErr->arrErr) >= 1) { |
---|
464 | return $objErr->arrErr; |
---|
465 | } |
---|
466 | |
---|
467 | return $this->lfCheek(); |
---|
468 | } |
---|
469 | |
---|
470 | /* 計算処理 */ |
---|
471 | function lfCheek() { |
---|
472 | $objDb = new SC_Helper_DB_Ex(); |
---|
473 | $arrVal = $this->objFormParam->getHashArray(); |
---|
474 | $arrErr = array(); |
---|
475 | |
---|
476 | // 商品の種類数 |
---|
477 | $max = count($arrVal['quantity']); |
---|
478 | $subtotal = 0; |
---|
479 | $totalpoint = 0; |
---|
480 | $totaltax = 0; |
---|
481 | for($i = 0; $i < $max; $i++) { |
---|
482 | // 小計の計算 |
---|
483 | $subtotal += SC_Helper_DB_Ex::sfPreTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
484 | // 小計の計算 |
---|
485 | $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i]; |
---|
486 | // 加算ポイントの計算 |
---|
487 | $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i]; |
---|
488 | } |
---|
489 | |
---|
490 | // 消費税 |
---|
491 | $arrVal['tax'] = $totaltax; |
---|
492 | // 小計 |
---|
493 | $arrVal['subtotal'] = $subtotal; |
---|
494 | // 合計 |
---|
495 | $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge']; |
---|
496 | // お支払い合計 |
---|
497 | $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE); |
---|
498 | |
---|
499 | // 加算ポイント |
---|
500 | $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']); |
---|
501 | |
---|
502 | if (strlen($_POST['customer_id']) > 0){ |
---|
503 | list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPointFromCid($_POST['customer_id'], $arrVal['use_point'], $arrVal['add_point']); |
---|
504 | }else{ |
---|
505 | list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPoint($_POST['order_id'], $arrVal['use_point'], $arrVal['add_point']); |
---|
506 | } |
---|
507 | if ($arrVal['total'] < 0) { |
---|
508 | $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
509 | } |
---|
510 | |
---|
511 | if ($arrVal['payment_total'] < 0) { |
---|
512 | $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />'; |
---|
513 | } |
---|
514 | //新規追加受注のみ |
---|
515 | if ($_POST['mode'] == "add") { |
---|
516 | if ($arrVal['total_point'] < 0) { |
---|
517 | $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />'; |
---|
518 | } |
---|
519 | } |
---|
520 | |
---|
521 | $this->objFormParam->setParam($arrVal); |
---|
522 | return $arrErr; |
---|
523 | } |
---|
524 | |
---|
525 | /** |
---|
526 | * DB更新処理 |
---|
527 | * |
---|
528 | * @param integer $order_id 注文番号 |
---|
529 | * @return void |
---|
530 | */ |
---|
531 | function lfRegistData($order_id) { |
---|
532 | $objQuery = new SC_Query(); |
---|
533 | |
---|
534 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
535 | |
---|
536 | $where = "order_id = ?"; |
---|
537 | |
---|
538 | $objQuery->begin(); |
---|
539 | |
---|
540 | // 受注.対応状況の更新 |
---|
541 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']); |
---|
542 | unset($sqlval['status']); |
---|
543 | unset($sqlval['add_point']); |
---|
544 | unset($sqlval['use_point']); |
---|
545 | |
---|
546 | // 受注テーブルの更新 |
---|
547 | $objQuery->update("dtb_order", $sqlval, $where, array($order_id)); |
---|
548 | |
---|
549 | // 受注テーブルの名称列を更新 |
---|
550 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
551 | |
---|
552 | // 受注詳細データの更新 |
---|
553 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2")); |
---|
554 | $objQuery->delete("dtb_order_detail", $where, array($order_id)); |
---|
555 | |
---|
556 | $max = count($arrDetail); |
---|
557 | for ($i = 0; $i < $max; $i++) { |
---|
558 | $sqlval = array(); |
---|
559 | $sqlval['order_id'] = $order_id; |
---|
560 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
561 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
562 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
563 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
564 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
565 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
566 | $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1']; |
---|
567 | $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2']; |
---|
568 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
569 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
570 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
571 | } |
---|
572 | |
---|
573 | $objQuery->commit(); |
---|
574 | } |
---|
575 | |
---|
576 | /** |
---|
577 | * DB登録処理 |
---|
578 | * |
---|
579 | * @return integer 注文番号 |
---|
580 | */ |
---|
581 | function lfRegistNewData() { |
---|
582 | $objQuery = new SC_Query(); |
---|
583 | |
---|
584 | $sqlval = $this->lfMakeSqlvalForDtbOrder(); |
---|
585 | |
---|
586 | // 受注テーブルに書き込まない列を除去 |
---|
587 | unset($sqlval['order_id']); |
---|
588 | |
---|
589 | // ポイントは別登録 |
---|
590 | $addPoint = $sqlval['add_point']; |
---|
591 | $usePoint = $sqlval['use_point']; |
---|
592 | $sqlval['add_point'] = 0; |
---|
593 | $sqlval['use_point'] = 0; |
---|
594 | |
---|
595 | // customer_id |
---|
596 | if ($sqlval["customer_id"] == "") { |
---|
597 | $sqlval['customer_id'] = '0'; |
---|
598 | } |
---|
599 | |
---|
600 | $sqlval['create_date'] = 'Now()'; // 受注日 |
---|
601 | |
---|
602 | $objQuery->begin(); |
---|
603 | |
---|
604 | // 受注テーブルの登録 |
---|
605 | $objQuery->insert("dtb_order", $sqlval); |
---|
606 | $order_id = $objQuery->currval('dtb_order', 'order_id'); |
---|
607 | |
---|
608 | // 受注.対応状況の更新 |
---|
609 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint); |
---|
610 | |
---|
611 | // 受注テーブルの名称列を更新 |
---|
612 | SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id); |
---|
613 | |
---|
614 | // 受注詳細データの更新 |
---|
615 | $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2")); |
---|
616 | $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id)); |
---|
617 | |
---|
618 | $max = count($arrDetail); |
---|
619 | for ($i = 0; $i < $max; $i++) { |
---|
620 | $sqlval = array(); |
---|
621 | $sqlval['order_id'] = $order_id; |
---|
622 | $sqlval['product_id'] = $arrDetail[$i]['product_id']; |
---|
623 | $sqlval['product_code'] = $arrDetail[$i]['product_code']; |
---|
624 | $sqlval['product_name'] = $arrDetail[$i]['product_name']; |
---|
625 | $sqlval['price'] = $arrDetail[$i]['price']; |
---|
626 | $sqlval['quantity'] = $arrDetail[$i]['quantity']; |
---|
627 | $sqlval['point_rate'] = $arrDetail[$i]['point_rate']; |
---|
628 | $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1']; |
---|
629 | $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2']; |
---|
630 | $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; |
---|
631 | $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; |
---|
632 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
633 | } |
---|
634 | |
---|
635 | $objQuery->commit(); |
---|
636 | |
---|
637 | return $order_id; |
---|
638 | } |
---|
639 | |
---|
640 | function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) { |
---|
641 | $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2); |
---|
642 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
643 | $existes = false; |
---|
644 | $existes_key = NULL; |
---|
645 | // 既に同じ商品がないか、確認する |
---|
646 | if (!empty($this->arrForm['product_id']['value'])) { |
---|
647 | foreach ($this->arrForm['product_id']['value'] AS $key=>$val) { |
---|
648 | // 既に同じ商品がある場合 |
---|
649 | if ($val == $product_id && $this->arrForm['product_id']['classcategory_id1'][$key] == $classcategory_id1 && $this->arrForm['product_id']['classcategory_id2'][$key] == $classcategory_id2) { |
---|
650 | $existes = true; |
---|
651 | $existes_key = $key; |
---|
652 | } |
---|
653 | } |
---|
654 | } |
---|
655 | |
---|
656 | if ($existes) { |
---|
657 | // 既に同じ商品がある場合 |
---|
658 | ++$this->arrForm['quantity']['value'][$existes_key]; |
---|
659 | } else { |
---|
660 | // 既に同じ商品がない場合 |
---|
661 | $this->lfSetProductData($arrProduct); |
---|
662 | } |
---|
663 | } |
---|
664 | |
---|
665 | function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) { |
---|
666 | $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2); |
---|
667 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
668 | $this->lfSetProductData($arrProduct, $no); |
---|
669 | } |
---|
670 | |
---|
671 | function lfSetProductData($arrProduct, $no = null) { |
---|
672 | foreach ($arrProduct AS $key=>$val) { |
---|
673 | if (!is_array($this->arrForm[$key]['value'])) { |
---|
674 | unset($this->arrForm[$key]['value']); |
---|
675 | } |
---|
676 | if ($no === null) { |
---|
677 | $this->arrForm[$key]['value'][] = $arrProduct[$key]; |
---|
678 | } else { |
---|
679 | $this->arrForm[$key]['value'][$no] = $arrProduct[$key]; |
---|
680 | } |
---|
681 | } |
---|
682 | } |
---|
683 | |
---|
684 | function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) { |
---|
685 | $objDb = new SC_Helper_DB_Ex(); |
---|
686 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
687 | $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2), true); |
---|
688 | |
---|
689 | $arrProduct['price'] = $arrRet['price02']; |
---|
690 | $arrProduct['quantity'] = 1; |
---|
691 | $arrProduct['product_id'] = $arrRet['product_id']; |
---|
692 | $arrProduct['point_rate'] = $arrRet['point_rate']; |
---|
693 | $arrProduct['product_code'] = $arrRet['product_code']; |
---|
694 | $arrProduct['product_name'] = $arrRet['name']; |
---|
695 | $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1']; |
---|
696 | $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2']; |
---|
697 | $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']]; |
---|
698 | $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']]; |
---|
699 | |
---|
700 | return $arrProduct; |
---|
701 | } |
---|
702 | |
---|
703 | /** |
---|
704 | * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する |
---|
705 | * @param int $edit_customer_id 顧客ID |
---|
706 | */ |
---|
707 | function lfSetCustomerInfo($edit_customer_id = ""){ |
---|
708 | // 顧客IDが指定されている場合のみ、処理を実行する |
---|
709 | if( $edit_customer_id === "" ) return ; |
---|
710 | |
---|
711 | // 検索で選択された顧客IDが入力されている場合 |
---|
712 | if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){ |
---|
713 | $objQuery = new SC_Query(); |
---|
714 | |
---|
715 | // 顧客情報を取得する |
---|
716 | $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id)); |
---|
717 | |
---|
718 | // 顧客情報を取得する事が出来たら、テンプレートに値を渡す |
---|
719 | if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){ |
---|
720 | // カラム名にorder_を付ける(テンプレート側でorder_がついている為 |
---|
721 | foreach($arrCustomerInfo[0] as $index=>$customer_info){ |
---|
722 | // customer_idにはorder_を付けないようにする |
---|
723 | $order_index = ($index == 'customer_id') ? $index : 'order_'.$index; |
---|
724 | $arrCustomer[$order_index] = $customer_info; |
---|
725 | } |
---|
726 | } |
---|
727 | |
---|
728 | // hiddenに渡す |
---|
729 | $this->edit_customer_id = $edit_customer_id; |
---|
730 | |
---|
731 | // 受注日に現在の時刻を取得し、表示させる |
---|
732 | $create_date = $objQuery->getall('SELECT now() as create_date;'); |
---|
733 | $arrCustomer['create_date'] = $create_date[0]['create_date']; |
---|
734 | |
---|
735 | // 情報上書き |
---|
736 | $this->objFormParam->setParam($arrCustomer); |
---|
737 | // 入力値の変換 |
---|
738 | $this->objFormParam->convParam(); |
---|
739 | } |
---|
740 | } |
---|
741 | |
---|
742 | /** |
---|
743 | * 受注テーブルの登録・更新用データの共通部分を作成する |
---|
744 | * |
---|
745 | * @return array |
---|
746 | */ |
---|
747 | function lfMakeSqlvalForDtbOrder() { |
---|
748 | |
---|
749 | // 入力データを取得する |
---|
750 | $sqlval = $this->objFormParam->getHashArray(); |
---|
751 | foreach ($sqlval as $key => $val) { |
---|
752 | // 配列は登録しない |
---|
753 | if (is_array($val)) { |
---|
754 | unset($sqlval[$key]); |
---|
755 | } |
---|
756 | } |
---|
757 | |
---|
758 | // 受注テーブルに書き込まない列を除去 |
---|
759 | unset($sqlval['total_point']); |
---|
760 | unset($sqlval['point']); |
---|
761 | unset($sqlval['commit_date']); |
---|
762 | |
---|
763 | // 更新日時 |
---|
764 | $sqlval['update_date'] = 'Now()'; |
---|
765 | |
---|
766 | return $sqlval; |
---|
767 | } |
---|
768 | } |
---|
769 | ?> |
---|