source: branches/version-2/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php @ 18432

Revision 18432, 35.2 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.2 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=207

  • 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/* GMO決済モジュール連携用 */
28if (file_exists(MODULE_PATH . 'mdl_gmopg/inc/include.php') === TRUE) {
29  require_once(MODULE_PATH . 'mdl_gmopg/inc/include.php');
30}
31
32/* ペイジェント決済モジュール連携用 */
33if (file_exists(MODULE_PATH . 'mdl_paygent/include.php') === TRUE) {
34    require_once(MODULE_PATH . 'mdl_paygent/include.php');
35}
36
37/* F-REGI決済モジュール連携用 */
38if (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決済モジュール連携用 */
43if (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 */
55class 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    }
101
102    /**
103     * Page のプロセス.
104     *
105     * @return void
106     */
107    function process() {
108        $conn = new SC_DBConn();
109        $objView = new SC_AdminView();
110        $objSess = new SC_Session();
111        $objSiteInfo = new SC_SiteInfo();
112        $objDb = new SC_Helper_DB_Ex();
113        $arrInfo = $objSiteInfo->data;
114
115        // パラメータ管理クラス
116        $this->objFormParam = new SC_FormParam();
117        // パラメータ情報の初期化
118        $this->lfInitParam();
119
120        // 認証可否の判定
121        SC_Utils_Ex::sfIsSuccess($objSess);
122
123        // 検索パラメータの引き継ぎ
124        foreach ($_POST as $key => $val) {
125            if (ereg("^search_", $key)) {
126                $this->arrSearchHidden[$key] = $val;
127            }
128        }
129
130        // 表示モード判定
131        if(isset($_GET['order_id']) &&
132            SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
133            $this->disp_mode = true;
134            $order_id = $_GET['order_id'];
135        } else {
136            $order_id = $_POST['order_id'];
137        }
138        $this->tpl_order_id = $order_id;
139
140        // DBから受注情報を読み込む
141        $this->lfGetOrderData($order_id);
142
143        switch($_POST['mode']) {
144        case 'pre_edit':
145        case 'order_id':
146            break;
147        case 'edit':
148        case 'add':
149            // POST情報で上書き
150            $this->objFormParam->setParam($_POST);
151
152            // 入力値の変換
153            $this->objFormParam->convParam();
154            $this->arrErr = $this->lfCheckError();
155            $this->arrErr = array_merge( (array) $this->arrErr, (array)$this->lfCheek($arrInfo, $_POST['mode']) );
156
157            if(count($this->arrErr) == 0) {
158                if ($_POST['mode'] == 'add') {
159                    $order_id = $this->lfRegistNewData();
160
161                    $this->tpl_order_id = $order_id;
162                    $this->tpl_mode = 'edit';
163
164                    $arrData['order_id'] = $order_id;
165                    $this->objFormParam->setParam($arrData);
166
167                    $text = "'新規受注を登録しました。'";
168                } else {
169                    $this->lfRegistData($_POST['order_id']);
170                    $text = "'受注履歴を編集しました。'";
171                }
172                // DBから受注情報を再読込
173                $this->lfGetOrderData($order_id);
174                $this->tpl_onload = "window.alert(".$text.");";
175            }
176            break;
177        // 再計算
178        case 'cheek':
179        //支払い方法の選択
180        case 'payment':
181            // POST情報で上書き
182            $this->objFormParam->setParam($_POST);
183            // 入力値の変換
184            $this->objFormParam->convParam();
185            $this->arrErr = $this->lfCheckError();
186            if(count($this->arrErr) == 0) {
187                $this->arrErr = $this->lfCheek($arrInfo, $_POST['mode']);
188            }
189            break;
190        /* ペイジェント決済モジュール連携用 */
191        case 'paygent_order':
192            $this->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id);
193            break;
194        /* 商品削除*/
195        case 'delete_product':
196            $delete_no = $_POST['delete_no'];
197            foreach ($_POST AS $key=>$val) {
198                if (is_array($val)) {
199                    foreach ($val AS $k=>$v) {
200                        if ($k != $delete_no) {
201                            $arrData[$key][] = $v;
202                        }
203                    }
204                } else {
205                    $arrData[$key] = $val;
206                }
207            }
208            // 情報上書き
209            $this->objFormParam->setParam($arrData);
210            // 入力値の変換
211            $this->objFormParam->convParam();
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            break;
235        /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/
236        case 'search_customer':
237            // POST情報で上書き
238            $this->objFormParam->setParam($_POST);
239
240            // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
241            $this->lfSetCustomerInfo($_POST['edit_customer_id']);
242
243            break;
244        /* F-REGI決済モジュール連携用 */
245        case 'fregi_status':
246            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
247            $this->fregi_err = $objFregiConfig->getSaleInfo($order_id, $this->arrDisp);
248            $this->lfGetOrderData($order_id);
249            break;
250        case 'fregi_card':
251            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
252            $this->fregi_card_err = $objFregiConfig->setCardInfo($_POST['card_status'], $order_id, $this->arrDisp);
253            $this->lfGetOrderData($order_id);
254            break;
255        /* SPS決済モジュール連携用 */
256        case 'sps_request':
257            $objErr = new SC_CheckError($_POST);
258            $objErr->doFunc(array("年","sps_year"), array('EXIST_CHECK'));
259            $objErr->doFunc(array("月","sps_month"), array('EXIST_CHECK'));
260            $objErr->doFunc(array("日","sps_date"), array('EXIST_CHECK'));
261            $objErr->doFunc(array("売上・返金日", "sps_year", "sps_month", "sps_date"), array("CHECK_DATE"));
262            if ($objErr->arrErr) {
263                $this->arrErr = $objErr->arrErr;
264                break;
265            }
266            $sps_return = sfSpsRequest( $order_id, $_POST['request_type'] );
267            // DBから受注情報を再読込
268            $this->lfGetOrderData($order_id);
269            $this->tpl_onload = "window.alert('".$sps_return."');";
270            break;
271
272        /* GMOPG連携用 */
273        case 'gmopg_order_edit':
274            require_once(MODULE_PATH . 'mdl_gmopg/class/LC_Mdl_GMOPG_OrderEdit.php');
275            $objGMOOrderEdit = new LC_MDL_GMOPG_OrderEdit;
276            $this->gmopg_order_edit_result = $objGMOOrderEdit->proccess();
277            $this->lfGetOrderData($order_id);
278            break;
279        default:
280            break;
281        }
282
283        // 支払い方法の取得
284        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
285        // 配送時間の取得
286        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
287        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
288
289        $this->arrForm = $this->objFormParam->getFormParamList();
290        $this->product_count = count($this->arrForm['quantity']['value']);
291
292        // アンカーを設定
293        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
294            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
295        } else {
296            $anchor_hash = "";
297        }
298        $this->tpl_onload .= $anchor_hash;
299
300        $this->arrInfo = $arrInfo;
301
302        /**
303         * SPS決済 クレジット判定用処理
304         */
305        if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) {
306            $objQuery = new SC_Query();
307            $this->paymentType = $objQuery->getall("SELECT module_code, memo03 FROM dtb_payment WHERE payment_id = ? ", array($this->arrForm["payment_id"]['value']));
308            $objDate = new SC_Date();
309            $objDate->setStartYear(RELEASE_YEAR);
310            $this->arrYear = $objDate->getYear();
311            $this->arrMonth = $objDate->getMonth();
312            $this->arrDay = $objDate->getDay();
313        }
314
315        $objView->assignobj($this);
316        // 表示モード判定
317        if(!$this->disp_mode) {
318            $objView->display(MAIN_FRAME);
319        } else {
320            $objView->display('order/disp.tpl');
321        }
322    }
323
324    /**
325     * デストラクタ.
326     *
327     * @return void
328     */
329    function destroy() {
330        parent::destroy();
331    }
332
333    /* パラメータ情報の初期化 */
334    function lfInitParam() {
335
336        // お客様情報
337        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
338        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
339        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
340        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
341        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("EXIST_CHECK", "NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
342        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
343        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
344        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
345        $this->objFormParam->addParam("住所1", "order_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
346        $this->objFormParam->addParam("住所2", "order_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
347        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
348        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
349        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
350
351        // 配送先情報
352        $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
353        $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
354        $this->objFormParam->addParam("フリガナ1", "deliv_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
355        $this->objFormParam->addParam("フリガナ2", "deliv_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
356        $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
357        $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
358        $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
359        $this->objFormParam->addParam("住所1", "deliv_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
360        $this->objFormParam->addParam("住所2", "deliv_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
361        $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
362        $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
363        $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
364
365
366        // 受注商品情報
367        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
368        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
369        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
370
371        // ポイント機能ON時のみ
372        if( USE_POINT === true ){
373            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
374        }
375
376        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
377        $this->objFormParam->addParam("配送時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
378        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
379        $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
380        $this->objFormParam->addParam("お支払方法名称", "payment_method");
381        $this->objFormParam->addParam("配送時間", "deliv_time");
382
383        // 受注詳細情報
384        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
385        $this->objFormParam->addParam("個数", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
386        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
387        $this->objFormParam->addParam("ポイント付与率", "point_rate");
388        $this->objFormParam->addParam("商品コード", "product_code");
389        $this->objFormParam->addParam("商品名", "product_name");
390        $this->objFormParam->addParam("規格1", "classcategory_id1");
391        $this->objFormParam->addParam("規格2", "classcategory_id2");
392        $this->objFormParam->addParam("規格名1", "classcategory_name1");
393        $this->objFormParam->addParam("規格名2", "classcategory_name2");
394        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
395        // DB読込用
396        $this->objFormParam->addParam("小計", "subtotal");
397        $this->objFormParam->addParam("合計", "total");
398        $this->objFormParam->addParam("支払い合計", "payment_total");
399        $this->objFormParam->addParam("加算ポイント", "add_point");
400        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
401        $this->objFormParam->addParam("消費税合計", "tax");
402        $this->objFormParam->addParam("最終保持ポイント", "total_point");
403        $this->objFormParam->addParam("顧客ID", "customer_id");
404        $this->objFormParam->addParam("現在のポイント", "point");
405        $this->objFormParam->addParam("注文番号", "order_id");
406        $this->objFormParam->addParam("受注日", "create_date");
407        $this->objFormParam->addParam("発送日", "commit_date");
408    }
409
410    function lfGetOrderData($order_id) {
411        if(SC_Utils_Ex::sfIsInt($order_id)) {
412            // DBから受注情報を読み込む
413            $objQuery = new SC_Query();
414            $objDb = new SC_Helper_DB_Ex();
415            $where = "order_id = ?";
416            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
417            $this->objFormParam->setParam($arrRet[0]);
418            list($point, $total_point) = $objDb->sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
419            $this->objFormParam->setValue('total_point', $total_point);
420            $this->objFormParam->setValue('point', $point);
421            $this->arrForm = $arrRet[0];
422            // 受注詳細データの取得
423            $arrRet = $this->lfGetOrderDetail($order_id);
424            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
425            $this->arrForm = array_merge($this->arrForm, $arrRet);
426            $this->objFormParam->setParam($arrRet);
427
428            // その他支払い情報を表示
429            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
430            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
431                $this->arrForm["payment_type"] = "クレジット決済";
432            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
433                $this->arrForm["payment_type"] = "コンビニ決済";
434            }else{
435                $this->arrForm["payment_type"] = "お支払い";
436            }
437            //受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため)
438            $this->arrDisp = $this->arrForm;
439        }
440    }
441
442    // 受注詳細データの取得
443    function lfGetOrderDetail($order_id) {
444        $objQuery = new SC_Query();
445        $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
446        $where = "order_id = ?";
447        $objQuery->setorder("classcategory_id1, classcategory_id2");
448        $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
449        return $arrRet;
450    }
451
452    /* 入力内容のチェック */
453    function lfCheckError() {
454        // 入力データを渡す。
455        $arrRet =  $this->objFormParam->getHashArray();
456        $objErr = new SC_CheckError($arrRet);
457        $objErr->arrErr = $this->objFormParam->checkError();
458
459        return $objErr->arrErr;
460    }
461
462    /* 計算処理 */
463    function lfCheek($arrInfo,$mode = "") {
464        $objDb = new SC_Helper_DB_Ex();
465        $arrVal = $this->objFormParam->getHashArray();
466        $arrErr = array();
467
468        // 商品の種類数
469        $max = count($arrVal['quantity']);
470        $subtotal = 0;
471        $totalpoint = 0;
472        $totaltax = 0;
473        for($i = 0; $i < $max; $i++) {
474            // 小計の計算
475            $subtotal += SC_Utils_Ex::sfPreTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
476            // 小計の計算
477            $totaltax += SC_Utils_Ex::sfTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
478            // 加算ポイントの計算
479            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
480        }
481
482        // 消費税
483        $arrVal['tax'] = $totaltax;
484        // 小計
485        $arrVal['subtotal'] = $subtotal;
486        // 合計
487        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
488        // お支払い合計
489        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
490
491        // 加算ポイント
492        $arrVal['add_point'] = SC_Utils_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point'], $arrInfo);
493
494        if (strlen($_POST['customer_id']) >0){
495            list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPointFromCid($_POST['customer_id'], $arrVal['use_point'], $arrVal['add_point']);
496        }else{
497            list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPoint($_POST['order_id'], $arrVal['use_point'], $arrVal['add_point']);
498        }
499        if($arrVal['total'] < 0) {
500            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
501        }
502
503        if($arrVal['payment_total'] < 0) {
504            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
505        }
506        //新規追加受注のみ
507        if ($mode == "add"){
508            if($arrVal['total_point'] < 0) {
509                $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
510            }
511        }
512
513        $this->objFormParam->setParam($arrVal);
514        return $arrErr;
515    }
516
517    function lfReCheek($arrData, $arrInfo) {
518        // 情報上書き
519        $this->objFormParam->setParam($arrData);
520        // 入力値の変換
521        $this->objFormParam->convParam();
522        #if(count($this->arrErr) == 0) {
523            $this->arrErr = $this->lfCheek($arrInfo);
524        #}
525    }
526    /* DB登録処理 */
527    function lfRegistData($order_id) {
528        $objQuery = new SC_Query();
529
530        $objQuery->begin();
531
532        // 入力データを渡す。
533        $arrRet =  $this->objFormParam->getHashArray();
534        foreach($arrRet as $key => $val) {
535            // 配列は登録しない
536            if(!is_array($val)) {
537                $sqlval[$key] = $val;
538            }
539        }
540
541        unset($sqlval['total_point']);
542        unset($sqlval['point']);
543
544        $where = "order_id = ?";
545
546        /*
547         * XXX 本来なら配列だが, update 関数を string として
548         *     チェックしているため...
549         */
550        if (!isset($addcol)) $addcol = "";
551
552        // 受注テーブルの更新
553        $objQuery->update("dtb_order", $sqlval, $where, array($order_id), $addcol);
554
555        $sql = "";
556        $sql .= " UPDATE";
557        $sql .= "     dtb_order";
558        $sql .= " SET";
559        $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
560        $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
561        // 受注ステータスの判定
562        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
563            // 受注テーブルの発送済み日を更新する
564            $sql .= "     ,commit_date = NOW()";
565        }
566        $sql .= " WHERE order_id = ?";
567
568        if ($arrRet['deliv_time_id'] == "") {
569            $deliv_time_id = 0;
570        }else{
571            $deliv_time_id = $arrRet['deliv_time_id'];
572        }
573        $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
574        $objQuery->query($sql, $arrUpdData);
575
576        // 受注詳細データの更新
577        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
578        $objQuery->delete("dtb_order_detail", $where, array($order_id));
579
580
581        $max = count($arrDetail);
582        for($i = 0; $i < $max; $i++) {
583            $sqlval = array();
584            $sqlval['order_id'] = $order_id;
585            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
586            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
587            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
588            $sqlval['price']  = $arrDetail[$i]['price'];
589            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
590            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
591            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
592            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
593            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
594            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
595            $objQuery->insert("dtb_order_detail", $sqlval);
596        }
597
598
599        $objQuery->commit();
600    }
601
602    /* DB登録処理(追加) */
603    function lfRegistNewData() {
604        $objQuery = new SC_Query();
605
606        $objQuery->begin();
607
608        // 入力データを渡す。
609        $arrRet =  $this->objFormParam->getHashArray();
610        foreach($arrRet as $key => $val) {
611            // 配列は登録しない
612            if(!is_array($val)) {
613                $sqlval[$key] = $val;
614            }
615        }
616
617        // postgresqlとmysqlとで処理を分ける
618        if (DB_TYPE == "pgsql") {
619            $order_id = $objQuery->nextval("dtb_order","order_id");
620        }elseif (DB_TYPE == "mysql") {
621            $order_id = $objQuery->get_auto_increment("dtb_order");
622        }
623
624        $sqlval['order_id'] = $order_id;
625        $sqlval['create_date'] = "Now()";
626
627        // 注文ステータス:指定が無ければ新規受付に設定
628        if($sqlval["status"] == ""){
629            $sqlval['status'] = '1';
630        }
631
632        // customer_id
633        if($sqlval["customer_id"] == ""){
634            $sqlval['customer_id'] = '0';
635        }
636
637        unset($sqlval['total_point']);
638        unset($sqlval['point']);
639
640        $where = "order_id = ?";
641
642        // 受注ステータスの判定
643        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
644            // 受注テーブルの発送済み日を更新する
645            $sqlval['commit_date'] = "Now()";
646        }
647
648        // 受注テーブルの登録
649        $objQuery->insert("dtb_order", $sqlval);
650
651        $sql = "";
652        $sql .= " UPDATE";
653        $sql .= "     dtb_order";
654        $sql .= " SET";
655        $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
656        $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
657        $sql .= " WHERE order_id = ?";
658
659        if ($arrRet['deliv_time_id'] == "") {
660            $deliv_time_id = 0;
661        } else {
662            $deliv_time_id = $arrRet['deliv_time_id'];
663        }
664        $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
665        $objQuery->query($sql, $arrUpdData);
666
667        // 受注詳細データの更新
668        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
669        $objQuery->delete("dtb_order_detail", $where, array($order_id));
670
671        $max = count($arrDetail);
672        for($i = 0; $i < $max; $i++) {
673            $sqlval = array();
674            $sqlval['order_id'] = $order_id;
675            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
676            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
677            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
678            $sqlval['price']  = $arrDetail[$i]['price'];
679            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
680            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
681            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
682            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
683            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
684            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
685            $objQuery->insert("dtb_order_detail", $sqlval);
686        }
687        $objQuery->commit();
688
689        return $order_id;
690    }
691
692    function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) {
693        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
694        $this->arrForm = $this->objFormParam->getFormParamList();
695        $existes = false;
696        $existes_key = NULL;
697        // 既に同じ商品がないか、確認する
698        if (!empty($this->arrForm['product_id']['value'])) {
699            foreach ($this->arrForm['product_id']['value'] AS $key=>$val) {
700                if ($val == $product_id && $this->arrForm['product_id']['classcategory_id1'][$key] == $classcategory_id1 && $this->arrForm['product_id']['classcategory_id2'][$key] == $classcategory_id2) {
701                    // 既に同じ商品がある
702                    $existes = true;
703                    $existes_key = $key;
704                }
705            }
706        }
707
708        if ($existes) {
709            // 既に同じ商品がある場合
710            ++$this->arrForm['quantity']['value'][$existes_key];
711        } else {
712            // 既に同じ商品がない場合
713            $this->lfSetProductData($arrProduct);
714        }
715    }
716
717    function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) {
718        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
719        $this->arrForm = $this->objFormParam->getFormParamList();
720        $this->lfSetProductData($arrProduct, $no);
721    }
722
723    function lfSetProductData($arrProduct, $no = null) {
724        foreach ($arrProduct AS $key=>$val) {
725            if (!is_array($this->arrForm[$key]['value'])) {
726                unset($this->arrForm[$key]['value']);
727            }
728            if ($no === null) {
729                $this->arrForm[$key]['value'][] = $arrProduct[$key];
730            } else {
731                $this->arrForm[$key]['value'][$no] = $arrProduct[$key];
732            }
733        }
734    }
735
736    function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) {
737        $objDb = new SC_Helper_DB_Ex();
738        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
739        $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2));
740
741        $arrProduct['price'] = $arrRet['price02'];
742        $arrProduct['quantity'] = 1;
743        $arrProduct['product_id'] = $arrRet['product_id'];
744        $arrProduct['point_rate'] = $arrRet['point_rate'];
745        $arrProduct['product_code'] = $arrRet['product_code'];
746        $arrProduct['product_name'] = $arrRet['name'];
747        $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1'];
748        $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2'];
749        $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']];
750        $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']];
751
752        return $arrProduct;
753    }
754
755    /**
756     * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
757     * @param int $edit_customer_id 顧客ID
758     */
759    function lfSetCustomerInfo($edit_customer_id = ""){
760        // 顧客IDが指定されている場合のみ、処理を実行する
761        if( $edit_customer_id === "" ) return ;
762
763        // 検索で選択された顧客IDが入力されている場合
764        if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){
765            $objQuery = new SC_Query();
766
767            // 顧客情報を取得する
768            $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id));
769
770            // 顧客情報を取得する事が出来たら、テンプレートに値を渡す
771            if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){
772                // カラム名にorder_を付ける(テンプレート側でorder_がついている為
773                foreach($arrCustomerInfo[0] as $index=>$customer_info){
774                    // customer_idにはorder_を付けないようにする
775                    $order_index = ($index == 'customer_id') ? $index : 'order_'.$index;
776                    $arrCustomer[$order_index] = $customer_info;
777                }
778            }
779
780            // hiddenに渡す
781            $this->edit_customer_id = $edit_customer_id;
782
783            // 受注日に現在の時刻を取得し、表示させる
784            $create_date = $objQuery->getall('SELECT now() as create_date;');
785            $arrCustomer['create_date'] = $create_date[0]['create_date'];
786
787            // 情報上書き
788            $this->objFormParam->setParam($arrCustomer);
789            // 入力値の変換
790            $this->objFormParam->convParam();
791        }
792    }
793}
794?>
Note: See TracBrowser for help on using the repository browser.