source: branches/version-2_5-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php @ 18819

Revision 18819, 37.6 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) 入金日追加、規格対応(規格構成変更と並行で作業中なので、作業途中の部分有)

  • 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        $objView = new SC_AdminView();
110        $objSess = new SC_Session();
111        $objDb = new SC_Helper_DB_Ex();
112        $objDate = new SC_Date(1901);
113        $this->arrYearDelivDate = $objDate->getYear('', date('Y'), '');
114        $this->arrMonthDelivDate = $objDate->getMonth(true);
115        $this->arrDayDelivDate = $objDate->getDay(true);
116
117        // パラメータ管理クラス
118        $this->objFormParam = new SC_FormParam();
119        // パラメータ情報の初期化
120        $this->lfInitParam();
121
122        // 認証可否の判定
123        SC_Utils_Ex::sfIsSuccess($objSess);
124
125        // 検索パラメータの引き継ぎ
126        foreach ($_POST as $key => $val) {
127            if (ereg("^search_", $key)) {
128                $this->arrSearchHidden[$key] = $val;
129            }
130        }
131
132        // 表示モード判定
133        if(isset($_GET['order_id']) &&
134            SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
135            $this->disp_mode = true;
136            $order_id = $_GET['order_id'];
137        } else {
138            $order_id = $_POST['order_id'];
139        }
140        $this->tpl_order_id = $order_id;
141
142        // DBから受注情報を読み込む
143        $this->lfGetOrderData($order_id);
144
145        switch($_POST['mode']) {
146        case 'pre_edit':
147        case 'order_id':
148            break;
149        case 'edit':
150        case 'add':
151            // POST情報で上書き
152            $this->objFormParam->setParam($_POST);
153
154            // 入力値の変換
155            $this->objFormParam->convParam();
156            $this->arrErr = $this->lfCheckError();
157
158            if(count($this->arrErr) == 0) {
159                if ($_POST['mode'] == 'add') {
160                    $order_id = $this->lfRegistNewData();
161
162                    $this->tpl_order_id = $order_id;
163                    $this->tpl_mode = 'edit';
164
165                    $arrData['order_id'] = $order_id;
166                    $this->objFormParam->setParam($arrData);
167
168                    $text = "'新規受注を登録しました。'";
169                } else {
170                    $this->lfRegistData($_POST['order_id']);
171                    $text = "'受注履歴を編集しました。'";
172                }
173                // DBから受注情報を再読込
174                $this->lfGetOrderData($order_id);
175                $this->tpl_onload = "window.alert(".$text.");";
176            }
177            break;
178            // 再計算
179        case 'cheek':
180        //支払い方法の選択
181        case 'payment':
182            // POST情報で上書き
183            $this->objFormParam->setParam($_POST);
184            // 入力値の変換
185            $this->objFormParam->convParam();
186            $this->arrErr = $this->lfCheckError();
187            break;
188        /* ペイジェント決済モジュール連携用 */
189        case 'paygent_order':
190            $this->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id);
191            break;
192        /* 商品削除*/
193        case 'delete_product':
194            $delete_no = $_POST['delete_no'];
195            foreach ($_POST AS $key=>$val) {
196                if (is_array($val)) {
197                    foreach ($val AS $k=>$v) {
198                        if ($k != $delete_no) {
199                            $arrData[$key][] = $v;
200                        }
201                    }
202                } else {
203                    $arrData[$key] = $val;
204                }
205            }
206            // 情報上書き
207            $this->objFormParam->setParam($arrData);
208            // 入力値の変換
209            $this->objFormParam->convParam();
210            $this->arrErr = $this->lfCheckError();
211            break;
212        /* 商品追加ポップアップより商品選択後、商品情報取得*/
213        case 'select_product_detail':
214            // POST情報で上書き
215            $this->objFormParam->setParam($_POST);
216            if (!empty($_POST['add_product_id'])) {
217                $this->lfInsertProduct($_POST['add_product_id'], $_POST['add_classcategory_id1'], $_POST['add_classcategory_id2']);
218            } elseif (!empty($_POST['edit_product_id'])) {
219                $this->lfUpdateProduct($_POST['edit_product_id'], $_POST['edit_classcategory_id1'], $_POST['edit_classcategory_id2'], $_POST['no']);
220            }
221            $arrData = $_POST;
222            foreach ($this->arrForm AS $key=>$val) {
223                if (is_array($val)) {
224                    $arrData[$key] = $this->arrForm[$key]['value'];
225                } else {
226                    $arrData[$key] = $val;
227                }
228            }
229            // 情報上書き
230            $this->objFormParam->setParam($arrData);
231            // 入力値の変換
232            $this->objFormParam->convParam();
233            $this->arrErr = $this->lfCheckError();
234            break;
235        /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/
236        case 'search_customer':
237            // POST情報で上書き
238            $this->objFormParam->setParam($_POST);
239
240            // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
241            $this->lfSetCustomerInfo($_POST['edit_customer_id']);
242
243            break;
244        /* F-REGI決済モジュール連携用 */
245        case 'fregi_status':
246            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
247            $this->fregi_err = $objFregiConfig->getSaleInfo($order_id, $this->arrDisp);
248            $this->lfGetOrderData($order_id);
249            break;
250        case 'fregi_card':
251            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
252            $this->fregi_card_err = $objFregiConfig->setCardInfo($_POST['card_status'], $order_id, $this->arrDisp);
253            $this->lfGetOrderData($order_id);
254            break;
255        /* SPS決済モジュール連携用 */
256        case 'sps_request':
257            $objErr = new SC_CheckError($_POST);
258            $objErr->doFunc(array("年","sps_year"), array('EXIST_CHECK'));
259            $objErr->doFunc(array("月","sps_month"), array('EXIST_CHECK'));
260            $objErr->doFunc(array("日","sps_date"), array('EXIST_CHECK'));
261            $objErr->doFunc(array("売上・返金日", "sps_year", "sps_month", "sps_date"), array("CHECK_DATE"));
262            if ($objErr->arrErr) {
263                $this->arrErr = $objErr->arrErr;
264                break;
265            }
266            $sps_return = sfSpsRequest( $order_id, $_POST['request_type'] );
267            // DBから受注情報を再読込
268            $this->lfGetOrderData($order_id);
269            $this->tpl_onload = "window.alert('".$sps_return."');";
270            break;
271
272        /* GMOPG連携用 */
273        case 'gmopg_order_edit':
274            require_once(MODULE_PATH . 'mdl_gmopg/class/LC_Mdl_GMOPG_OrderEdit.php');
275            $objGMOOrderEdit = new LC_MDL_GMOPG_OrderEdit;
276            $this->gmopg_order_edit_result = $objGMOOrderEdit->proccess();
277            $this->lfGetOrderData($order_id);
278            break;
279        default:
280            break;
281        }
282
283        // 支払い方法の取得
284        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
285        // お届け時間の取得
286        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
287        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
288
289        $this->arrForm = $this->objFormParam->getFormParamList();
290        $this->product_count = count($this->arrForm['quantity']['value']);
291
292        // アンカーを設定
293        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
294            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
295        } else {
296            $anchor_hash = "";
297        }
298        $this->tpl_onload .= $anchor_hash;
299
300        $objSiteInfo = new SC_SiteInfo();
301        $this->arrInfo = $objSiteInfo->data;
302
303        /**
304         * SPS決済 クレジット判定用処理
305         */
306        if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) {
307            $objQuery = new SC_Query();
308            $this->paymentType = $objQuery->getAll("SELECT module_code, memo03 FROM dtb_payment WHERE payment_id = ? ", array($this->arrForm["payment_id"]['value']));
309            $objDate = new SC_Date();
310            $objDate->setStartYear(RELEASE_YEAR);
311            $this->arrYear = $objDate->getYear();
312            $this->arrMonth = $objDate->getMonth();
313            $this->arrDay = $objDate->getDay();
314        }
315
316        $objView->assignobj($this);
317        // 表示モード判定
318        if(!$this->disp_mode) {
319            $objView->display(MAIN_FRAME);
320        } else {
321            $objView->display('order/disp.tpl');
322        }
323    }
324
325    /**
326     * デストラクタ.
327     *
328     * @return void
329     */
330    function destroy() {
331        parent::destroy();
332    }
333
334    /* パラメータ情報の初期化 */
335    function lfInitParam() {
336
337        // お客様情報
338        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
339        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
340        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
341        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
342        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
343        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
344        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
345        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
346        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
347        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
348        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
349        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
350        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
351
352        // お届け先情報
353        $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
354        $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
355        $this->objFormParam->addParam("フリガナ1", "deliv_kana01", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
356        $this->objFormParam->addParam("フリガナ2", "deliv_kana02", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
357        $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
358        $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
359        $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
360        $this->objFormParam->addParam("住所1", "deliv_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
361        $this->objFormParam->addParam("住所2", "deliv_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
362        $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
363        $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
364        $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
365
366
367        // 受注商品情報
368        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
369        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
370        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
371
372        // ポイント機能ON時のみ
373        if (USE_POINT !== false) {
374            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
375        }
376
377        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
378        $this->objFormParam->addParam("お届け時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
379        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
380        $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
381        $this->objFormParam->addParam("お支払方法名称", "payment_method");
382        $this->objFormParam->addParam("お届け時間", "deliv_time");
383
384        // 受注詳細情報
385        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
386        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
387        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
388        $this->objFormParam->addParam("ポイント付与率", "point_rate");
389        $this->objFormParam->addParam("商品コード", "product_code");
390        $this->objFormParam->addParam("商品名", "product_name");
391        $this->objFormParam->addParam("規格1", "classcategory_id1");
392        $this->objFormParam->addParam("規格2", "classcategory_id2");
393        $this->objFormParam->addParam("規格名1", "classcategory_name1");
394        $this->objFormParam->addParam("規格名2", "classcategory_name2");
395        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
396        // DB読込用
397        $this->objFormParam->addParam("小計", "subtotal");
398        $this->objFormParam->addParam("合計", "total");
399        $this->objFormParam->addParam("支払い合計", "payment_total");
400        $this->objFormParam->addParam("加算ポイント", "add_point");
401        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
402        $this->objFormParam->addParam("消費税合計", "tax");
403        $this->objFormParam->addParam("最終保持ポイント", "total_point");
404        $this->objFormParam->addParam("顧客ID", "customer_id");
405        $this->objFormParam->addParam("現在のポイント", "point");
406        $this->objFormParam->addParam("注文番号", "order_id");
407        $this->objFormParam->addParam("受注日", "create_date");
408        $this->objFormParam->addParam("発送日", "commit_date");
409        $this->objFormParam->addParam("備考", "message");
410        $this->objFormParam->addParam("入金日", "payment_date");
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        $addPoint = $sqlval['add_point'];
642        $usePoint = $sqlval['use_point'];
643        $sqlval['add_point'] = 0;
644        $sqlval['use_point'] = 0;
645
646        // customer_id
647        if ($sqlval["customer_id"] == "") {
648            $sqlval['customer_id'] = '0';
649        }
650
651        $sqlval['create_date'] = 'Now()';       // 受注日
652
653        $objQuery->begin();
654
655        // 受注テーブルの登録
656        $order_id = $objQuery->nextVal('dtb_order_order_id');
657        $sqlval['order_id'] = $order_id;
658        $objQuery->insert("dtb_order", $sqlval);
659
660
661        // 受注.対応状況の更新
662        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint);
663
664        // 受注テーブルの名称列を更新
665        SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
666
667        // 受注詳細データの更新
668        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
669        $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id));
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
686            $objQuery->insert("dtb_order_detail", $sqlval);
687
688
689            // 在庫数減少処理
690            // 現在の実在庫数取得
691            $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']));
692
693            $stock_sqlval = array();
694            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']);
695            if ($stock_sqlval['stock'] === 0) {
696                $stock_sqlval['stock'] = '0';
697        }
698
699            $st_params = array();
700            $st_params[] = $arrDetail[$i]['product_id'];
701            $st_params[] = $arrDetail[$i]['classcategory_id1'];
702            $st_params[] = $arrDetail[$i]['classcategory_id2'];
703
704            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?', $st_params);
705        }
706        $objQuery->commit();
707
708        return $order_id;
709    }
710
711    function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) {
712        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
713        $this->arrForm = $this->objFormParam->getFormParamList();
714        $existes = false;
715        $existes_key = NULL;
716        // 既に同じ商品がないか、確認する
717        if (!empty($this->arrForm['product_id']['value'])) {
718            foreach ($this->arrForm['product_id']['value'] AS $key=>$val) {
719                // 既に同じ商品がある場合
720                if ($val == $product_id && $this->arrForm['product_id']['classcategory_id1'][$key] == $classcategory_id1 && $this->arrForm['product_id']['classcategory_id2'][$key] == $classcategory_id2) {
721                    $existes = true;
722                    $existes_key = $key;
723                }
724            }
725        }
726
727        if ($existes) {
728        // 既に同じ商品がある場合
729            ++$this->arrForm['quantity']['value'][$existes_key];
730        } else {
731        // 既に同じ商品がない場合
732            $this->lfSetProductData($arrProduct);
733        }
734    }
735
736    function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) {
737        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
738        $this->arrForm = $this->objFormParam->getFormParamList();
739        $this->lfSetProductData($arrProduct, $no);
740    }
741
742    function lfSetProductData($arrProduct, $no = null) {
743        foreach ($arrProduct AS $key=>$val) {
744            if (!is_array($this->arrForm[$key]['value'])) {
745                unset($this->arrForm[$key]['value']);
746            }
747            if ($no === null) {
748                $this->arrForm[$key]['value'][] = $arrProduct[$key];
749            } else {
750                $this->arrForm[$key]['value'][$no] = $arrProduct[$key];
751            }
752        }
753    }
754
755    function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) {
756        $objDb = new SC_Helper_DB_Ex();
757        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
758        $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2), true);
759
760        $arrProduct['price'] = $arrRet['price02'];
761        $arrProduct['quantity'] = 1;
762        $arrProduct['product_id'] = $arrRet['product_id'];
763        $arrProduct['point_rate'] = $arrRet['point_rate'];
764        $arrProduct['product_code'] = $arrRet['product_code'];
765        $arrProduct['product_name'] = $arrRet['name'];
766        $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1'];
767        $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2'];
768        $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']];
769        $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']];
770
771        return $arrProduct;
772    }
773
774    /**
775     * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
776     * @param int $edit_customer_id 顧客ID
777     */
778    function lfSetCustomerInfo($edit_customer_id = ""){
779        // 顧客IDが指定されている場合のみ、処理を実行する
780        if( $edit_customer_id === "" ) return ;
781
782        // 検索で選択された顧客IDが入力されている場合
783        if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){
784            $objQuery = new SC_Query();
785
786            // 顧客情報を取得する
787            $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id));
788
789            // 顧客情報を取得する事が出来たら、テンプレートに値を渡す
790            if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){
791                // カラム名にorder_を付ける(テンプレート側でorder_がついている為
792                foreach($arrCustomerInfo[0] as $index=>$customer_info){
793                    // customer_idにはorder_を付けないようにする
794                    $order_index = ($index == 'customer_id') ? $index : 'order_'.$index;
795                    $arrCustomer[$order_index] = $customer_info;
796                }
797            }
798
799            // hiddenに渡す
800            $this->edit_customer_id = $edit_customer_id;
801
802            // 受注日に現在の時刻を取得し、表示させる
803            $create_date = $objQuery->getAll('SELECT now() as create_date;');
804            $arrCustomer['create_date'] = $create_date[0]['create_date'];
805
806            // 情報上書き
807            $this->objFormParam->setParam($arrCustomer);
808            // 入力値の変換
809            $this->objFormParam->convParam();
810        }
811    }
812
813    /**
814     * 受注テーブルの登録・更新用データの共通部分を作成する
815     *
816     * @return array
817     */
818    function lfMakeSqlvalForDtbOrder() {
819
820        // 入力データを取得する
821        $sqlval = $this->objFormParam->getHashArray();
822        foreach ($sqlval as $key => $val) {
823            // 配列は登録しない
824            if (is_array($val)) {
825                unset($sqlval[$key]);
826            }
827        }
828
829        // 受注テーブルに書き込まない列を除去
830        unset($sqlval['total_point']);
831        unset($sqlval['point']);
832        unset($sqlval['commit_date']);
833
834        // 更新日時
835        $sqlval['update_date'] = 'Now()';
836
837        return $sqlval;
838   }
839}
840?>
Note: See TracBrowser for help on using the repository browser.