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

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

備考が表示されない不具合を修正。

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