source: branches/comu-ver2/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php @ 17293

Revision 17293, 27.6 KB checked in by Yammy, 15 years ago (diff)

http://svn.ec-cube.net/open_trac/ticket/292
管理画面から新規注文入力/注文編集機能
コミット

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
Line 
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
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/* ペイジェント決済モジュール連携用 */
28if (file_exists(MODULE_PATH . 'mdl_paygent/include.php') === TRUE) {
29  require_once(MODULE_PATH . 'mdl_paygent/include.php');
30}
31
32/**
33 * 受注修正 のページクラス.
34 *
35 * @package Page
36 * @author LOCKON CO.,LTD.
37 * @version $Id$
38 */
39class LC_Page_Admin_Order_Edit extends LC_Page {
40
41    // {{{ properties
42
43    /** 表示モード */
44    var $disp_mode;
45
46    // }}}
47    // {{{ functions
48
49    /**
50     * Page を初期化する.
51     *
52     * @return void
53     */
54    function init() {
55        parent::init();
56        $this->tpl_mainpage = 'order/edit.tpl';
57        $this->tpl_subnavi = 'order/subnavi.tpl';
58        $this->tpl_mainno = 'order';
59        $this->tpl_subno = 'index';
60        $this->tpl_subtitle = '受注管理';
61        if (empty($_GET['order_id']) && empty($_POST['order_id'])) {
62            $this->tpl_subno = 'add';
63            $this->tpl_mode = 'add';
64            $this->tpl_subtitle = '新規受注入力';
65        }
66
67        $masterData = new SC_DB_MasterData_Ex();
68        $this->arrPref = $masterData->getMasterData("mtb_pref",
69                                 array("pref_id", "pref_name", "rank"));
70        $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status");
71       
72        /* ペイジェント決済モジュール連携用 */
73        if(function_exists("sfPaygentOrderPage")) {
74            $this->arrFormKind = sfPaygentOrderPage();
75        }
76    }
77
78    /**
79     * Page のプロセス.
80     *
81     * @return void
82     */
83    function process() {
84        $conn = new SC_DBConn();
85        $objView = new SC_AdminView();
86        $objSess = new SC_Session();
87        $objSiteInfo = new SC_SiteInfo();
88        $objDb = new SC_Helper_DB_Ex();
89        $arrInfo = $objSiteInfo->data;
90
91        // パラメータ管理クラス
92        $this->objFormParam = new SC_FormParam();
93        // パラメータ情報の初期化
94        $this->lfInitParam();
95
96        // 認証可否の判定
97        SC_Utils_Ex::sfIsSuccess($objSess);
98
99        // 検索パラメータの引き継ぎ
100        foreach ($_POST as $key => $val) {
101            if (ereg("^search_", $key)) {
102                $this->arrSearchHidden[$key] = $val;
103            }
104        }
105
106        // 表示モード判定
107        if(isset($_GET['order_id']) &&
108            SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
109            $this->disp_mode = true;
110            $order_id = $_GET['order_id'];
111        } else {
112            $order_id = $_POST['order_id'];
113        }
114        $this->tpl_order_id = $order_id;
115
116        // DBから受注情報を読み込む
117        $this->lfGetOrderData($order_id);
118
119        switch($_POST['mode']) {
120        case 'pre_edit':
121        case 'order_id':
122            break;
123        case 'edit':
124        case 'add':
125            // POST情報で上書き
126            $this->objFormParam->setParam($_POST);
127
128            // 入力値の変換
129            $this->objFormParam->convParam();
130            $this->arrErr = $this->lfCheek($arrInfo);
131            $this->arrErr = $this->lfCheckError();
132            if(count($this->arrErr) == 0) {
133                #if(count($this->arrErr) == 0) {
134                    if ($_POST['mode'] == 'add') {
135                        $this->lfRegistNewData();
136                        $text = "'新規受注を登録しました。'";
137                    } else {
138                        $this->lfRegistData($_POST['order_id']);
139                        $text = "'受注履歴を編集しました。'";
140                    }
141                    // DBから受注情報を再読込
142                    $this->lfGetOrderData($order_id);
143                    $this->tpl_onload = "window.alert(".$text.");";
144                #}
145            }
146            break;
147            // 再計算
148        case 'cheek':
149            // POST情報で上書き
150            $this->objFormParam->setParam($_POST);
151            // 入力値の変換
152            $this->objFormParam->convParam();
153            $this->arrErr = $this->lfCheckError();
154            #if(count($this->arrErr) == 0) {
155                $this->arrErr = $this->lfCheek($arrInfo);
156            #}
157            break;
158        /* ペイジェント決済モジュール連携用 */
159        case 'paygent_order':
160            $this->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id);
161            break;
162        // 商品削除
163        case 'delete_product':
164            $delete_no = $_POST['delete_no'];
165            foreach ($_POST AS $key=>$val) {
166                if (is_array($val)) {
167                    foreach ($val AS $k=>$v) {
168                        if ($k != $delete_no) {
169                            $arrData[$key][] = $v;
170                        }
171                    }
172                } else {
173                    $arrData[$key] = $val;
174                }
175            }
176            $this->lfReCheek($arrData, $arrInfo);
177            break;
178        // 商品追加ポップアップより商品選択後、商品情報取得
179        case 'select_product_detail':
180            // POST情報で上書き
181            $this->objFormParam->setParam($_POST);
182            if (!empty($_POST['add_product_id'])) {
183                $this->lfInsertProduct($_POST['add_product_id'], $_POST['add_classcategory_id1'], $_POST['add_classcategory_id2']);
184
185            } elseif (!empty($_POST['edit_product_id'])) {
186                $this->lfUpdateProduct($_POST['edit_product_id'], $_POST['edit_classcategory_id1'], $_POST['edit_classcategory_id2'], $_POST['no']);
187            }
188
189            $arrData = $_POST;
190            foreach ($this->arrForm AS $key=>$val) {
191                if (is_array($val)) {
192                    $arrData[$key] = $this->arrForm[$key]['value'];
193                } else {
194                    $arrData[$key] = $val;
195                }
196            }
197            $this->lfReCheek($arrData, $arrInfo);
198            break;
199        default:
200            break;
201        }
202
203        // 支払い方法の取得
204        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
205        // 配送時間の取得
206        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
207        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
208
209        $this->arrForm = $this->objFormParam->getFormParamList();
210        $this->product_count = count($this->arrForm['quantity']['value']);
211
212        // アンカーを設定
213        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
214            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
215        } else {
216            $anchor_hash = "";
217        }
218        $this->tpl_onload .= $anchor_hash;
219
220        $this->arrInfo = $arrInfo;
221
222        $objView->assignobj($this);
223        // 表示モード判定
224        if(!$this->disp_mode) {
225            $objView->display(MAIN_FRAME);
226        } else {
227            $objView->display('order/disp.tpl');
228        }
229    }
230
231
232    /**
233     * デストラクタ.
234     *
235     * @return void
236     */
237    function destroy() {
238        parent::destroy();
239    }
240
241    /* パラメータ情報の初期化 */
242    function lfInitParam() {
243        // 配送先情報
244        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
245        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
246        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
247        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
248        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("EXIST_CHECK", "NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
249        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
250        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
251        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
252        $this->objFormParam->addParam("住所1", "order_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
253        $this->objFormParam->addParam("住所2", "order_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
254        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
255        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
256        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
257
258        $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
259        $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
260        $this->objFormParam->addParam("フリガナ1", "deliv_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
261        $this->objFormParam->addParam("フリガナ2", "deliv_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
262        $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
263        $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
264        $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
265        $this->objFormParam->addParam("住所1", "deliv_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
266        $this->objFormParam->addParam("住所2", "deliv_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
267        $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
268        $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
269        $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
270        // 受注商品情報
271        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
272        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
273        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
274        $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
275        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
276        $this->objFormParam->addParam("配送時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
277        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
278        $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
279        $this->objFormParam->addParam("お支払方法名称", "payment_method");
280        $this->objFormParam->addParam("配送時間", "deliv_time");
281
282        // 受注詳細情報
283        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
284        $this->objFormParam->addParam("個数", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
285        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
286        $this->objFormParam->addParam("ポイント付与率", "point_rate");
287        $this->objFormParam->addParam("商品コード", "product_code");
288        $this->objFormParam->addParam("商品名", "product_name");
289        $this->objFormParam->addParam("規格1", "classcategory_id1");
290        $this->objFormParam->addParam("規格2", "classcategory_id2");
291        $this->objFormParam->addParam("規格名1", "classcategory_name1");
292        $this->objFormParam->addParam("規格名2", "classcategory_name2");
293        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
294        // DB読込用
295        $this->objFormParam->addParam("小計", "subtotal");
296        $this->objFormParam->addParam("合計", "total");
297        $this->objFormParam->addParam("支払い合計", "payment_total");
298        $this->objFormParam->addParam("加算ポイント", "add_point");
299        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
300        $this->objFormParam->addParam("消費税合計", "tax");
301        $this->objFormParam->addParam("最終保持ポイント", "total_point");
302        $this->objFormParam->addParam("顧客ID", "customer_id");
303        $this->objFormParam->addParam("現在のポイント", "point");
304        $this->objFormParam->addParam("受注番号", "order_id");
305        $this->objFormParam->addParam("受注日", "create_date");
306    }
307
308    function lfGetOrderData($order_id) {
309        if(SC_Utils_Ex::sfIsInt($order_id)) {
310            // DBから受注情報を読み込む
311            $objQuery = new SC_Query();
312            $objDb = new SC_Helper_DB_Ex();
313            $where = "order_id = ?";
314            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
315            $this->objFormParam->setParam($arrRet[0]);
316            list($point, $total_point) = $objDb->sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
317            $this->objFormParam->setValue('total_point', $total_point);
318            $this->objFormParam->setValue('point', $point);
319            $this->arrForm = $arrRet[0];
320            // 受注詳細データの取得
321            $arrRet = $this->lfGetOrderDetail($order_id);
322            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
323            $this->arrForm = array_merge($this->arrForm, $arrRet);
324            $this->objFormParam->setParam($arrRet);
325
326            // その他支払い情報を表示
327            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
328            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
329                $this->arrForm["payment_type"] = "クレジット決済";
330            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
331                $this->arrForm["payment_type"] = "コンビニ決済";
332            }else{
333                $this->arrForm["payment_type"] = "お支払い";
334            }
335        }
336    }
337
338    // 受注詳細データの取得
339    function lfGetOrderDetail($order_id) {
340        $objQuery = new SC_Query();
341        $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
342        $where = "order_id = ?";
343        $objQuery->setorder("classcategory_id1, classcategory_id2");
344        $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
345        return $arrRet;
346    }
347
348    /* 入力内容のチェック */
349    function lfCheckError() {
350        // 入力データを渡す。
351        $arrRet =  $this->objFormParam->getHashArray();
352        $objErr = new SC_CheckError($arrRet);
353        $objErr->arrErr = $this->objFormParam->checkError();
354
355        return $objErr->arrErr;
356    }
357
358    /* 計算処理 */
359    function lfCheek($arrInfo) {
360        $objDb = new SC_Helper_DB_Ex();
361        $arrVal = $this->objFormParam->getHashArray();
362        $arrErr = array();
363
364        // 商品の種類数
365        $max = count($arrVal['quantity']);
366        $subtotal = 0;
367        $totalpoint = 0;
368        $totaltax = 0;
369        for($i = 0; $i < $max; $i++) {
370            // 小計の計算
371            $subtotal += SC_Utils_Ex::sfPreTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
372            // 小計の計算
373            $totaltax += SC_Utils_Ex::sfTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
374            // 加算ポイントの計算
375            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
376        }
377
378        // 消費税
379        $arrVal['tax'] = $totaltax;
380        // 小計
381        $arrVal['subtotal'] = $subtotal;
382        // 合計
383        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
384        // お支払い合計
385        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
386
387        // 加算ポイント
388        $arrVal['add_point'] = SC_Utils_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point'], $arrInfo);
389
390        list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPoint($_POST['order_id'], $arrVal['use_point'], $arrVal['add_point']);
391
392        if($arrVal['total'] < 0) {
393            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
394        }
395
396        if($arrVal['payment_total'] < 0) {
397            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
398        }
399
400        if($arrVal['total_point'] < 0) {
401            $arrErr['total_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
402        }
403
404        $this->objFormParam->setParam($arrVal);
405        return $arrErr;
406    }
407
408    function lfReCheek($arrData, $arrInfo) {
409        // 情報上書き
410        $this->objFormParam->setParam($arrData);
411        // 入力値の変換
412        $this->objFormParam->convParam();
413        #if(count($this->arrErr) == 0) {
414            $this->arrErr = $this->lfCheek($arrInfo);
415        #}
416        $this->arrErr = $this->lfCheckError();
417    }
418
419    /* DB登録処理 */
420    function lfRegistData($order_id) {
421        $objQuery = new SC_Query();
422
423        $objQuery->begin();
424
425        // 入力データを渡す。
426        $arrRet =  $this->objFormParam->getHashArray();
427        foreach($arrRet as $key => $val) {
428            // 配列は登録しない
429            if(!is_array($val)) {
430                $sqlval[$key] = $val;
431            }
432        }
433
434        unset($sqlval['total_point']);
435        unset($sqlval['point']);
436
437        $where = "order_id = ?";
438
439        // 受注ステータスの判定
440        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
441            // 受注テーブルの発送済み日を更新する
442            $addcol['commit_date'] = "Now()";
443        }
444
445        /*
446         * XXX 本来なら配列だが, update 関数を string として
447         *     チェックしているため...
448         */
449        if (!isset($addcol)) $addcol = "";
450
451        // 受注テーブルの更新
452        $objQuery->update("dtb_order", $sqlval, $where, array($order_id), $addcol);
453
454        $sql = "";
455        $sql .= " UPDATE";
456        $sql .= "     dtb_order";
457        $sql .= " SET";
458        $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
459        $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
460        $sql .= " WHERE order_id = ?";
461
462        if ($arrRet['deliv_time_id'] == "") {
463            $deliv_time_id = 0;
464        }else{
465            $deliv_time_id = $arrRet['deliv_time_id'];
466        }
467        $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
468        $objQuery->query($sql, $arrUpdData);
469
470        // 受注詳細データの更新
471        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
472        $objQuery->delete("dtb_order_detail", $where, array($order_id));
473
474        $max = count($arrDetail);
475        for($i = 0; $i < $max; $i++) {
476            $sqlval = array();
477            $sqlval['order_id'] = $order_id;
478            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
479            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
480            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
481            $sqlval['price']  = $arrDetail[$i]['price'];
482            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
483            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
484            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
485            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
486            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
487            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
488            $objQuery->insert("dtb_order_detail", $sqlval);
489        }
490        $objQuery->commit();
491    }
492
493    /* DB登録処理(追加) */
494    function lfRegistNewData() {
495        $objQuery = new SC_Query();
496
497        $objQuery->begin();
498
499        // 入力データを渡す。
500        $arrRet =  $this->objFormParam->getHashArray();
501        foreach($arrRet as $key => $val) {
502            // 配列は登録しない
503            if(!is_array($val)) {
504                $sqlval[$key] = $val;
505            }
506        }
507        $order_id = $objQuery->nextval('dtb_order', 'order_id');
508        $sqlval['order_id'] = $order_id;
509        $sqlval['create_date'] = "Now()";
510
511        // 注文ステータス:指定が無ければ新規受付に設定
512        if($sqlval["status"] == ""){
513            $sqlval['status'] = '1';
514        }
515
516        // customer_id
517        if($sqlval["customer_id"] == ""){
518            $sqlval['customer_id'] = '0';
519        }
520
521        unset($sqlval['total_point']);
522        unset($sqlval['point']);
523
524        $where = "order_id = ?";
525
526        // 受注ステータスの判定
527        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
528            // 受注テーブルの発送済み日を更新する
529            $sqlval['commit_date'] = "Now()";
530        }
531
532        // 受注テーブルの登録
533        $objQuery->insert("dtb_order", $sqlval);
534
535        $sql = "";
536        $sql .= " UPDATE";
537        $sql .= "     dtb_order";
538        $sql .= " SET";
539        $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
540        $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
541        $sql .= " WHERE order_id = ?";
542
543        if ($arrRet['deliv_time_id'] == "") {
544            $deliv_time_id = 0;
545        }else{
546            $deliv_time_id = $arrRet['deliv_time_id'];
547        }
548        $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
549        $objQuery->query($sql, $arrUpdData);
550
551        // 受注詳細データの更新
552        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
553        $objQuery->delete("dtb_order_detail", $where, array($order_id));
554
555        $max = count($arrDetail);
556        for($i = 0; $i < $max; $i++) {
557            $sqlval = array();
558            $sqlval['order_id'] = $order_id;
559            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
560            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
561            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
562            $sqlval['price']  = $arrDetail[$i]['price'];
563            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
564            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
565            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
566            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
567            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
568            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
569            $objQuery->insert("dtb_order_detail", $sqlval);
570        }
571        $objQuery->commit();
572    }
573
574
575    function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) {
576        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
577        $this->arrForm = $this->objFormParam->getFormParamList();
578        $this->lfSetProductData($arrProduct);
579    }
580
581    function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) {
582        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
583        $this->arrForm = $this->objFormParam->getFormParamList();
584        $this->lfSetProductData($arrProduct, $no);
585    }
586
587    function lfSetProductData($arrProduct, $no = null) {
588        foreach ($arrProduct AS $key=>$val) {
589            if (!is_array($this->arrForm[$key]['value'])) {
590                unset($this->arrForm[$key]['value']);
591            }
592            if ($no === null) {
593                $this->arrForm[$key]['value'][] = $arrProduct[$key];
594            } else {
595                $this->arrForm[$key]['value'][$no] = $arrProduct[$key];
596            }
597        }
598    }
599
600    function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) {
601        $objDb = new SC_Helper_DB_Ex();
602        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
603        $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2));
604
605        $arrProduct['price'] = $arrRet['price02'];
606        $arrProduct['quantity'] = 1;
607        $arrProduct['product_id'] = $arrRet['product_id'];
608        $arrProduct['point_rate'] = $arrRet['point_rate'];
609        $arrProduct['product_code'] = $arrRet['product_code'];
610        $arrProduct['product_name'] = $arrRet['name'];
611        $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1'];
612        $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2'];
613        $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']];
614        $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']];
615
616        return $arrProduct;
617    }
618}
619?>
Note: See TracBrowser for help on using the repository browser.