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

Revision 18734, 43.1 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

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