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

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