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

Revision 18234, 33.6 KB checked in by Seasoft, 15 years ago (diff)

#528(改行コードが混在している)

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