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

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