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

Revision 19923, 39.0 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

  • お届け日/お届け時間が反映されるよう修正
  • 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_REALDIR . "pages/admin/LC_Page_Admin.php");
26
27/**
28 * 受注修正 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Order_Edit extends LC_Page_Admin {
35
36    // {{{ properties
37
38    /** 表示モード */
39    var $disp_mode;
40
41    // }}}
42    // {{{ functions
43
44    /**
45     * Page を初期化する.
46     *
47     * @return void
48     */
49    function init() {
50        parent::init();
51        $this->tpl_mainpage = 'order/edit.tpl';
52        $this->tpl_subnavi = 'order/subnavi.tpl';
53        $this->tpl_mainno = 'order';
54        $this->tpl_subno = 'index';
55        $this->tpl_subtitle = '受注管理';
56        if (empty($_GET['order_id']) && empty($_POST['order_id'])) {
57            $this->tpl_subno = 'add';
58            $this->tpl_mode = 'add';
59            $this->tpl_subtitle = '新規受注入力';
60        }
61
62        $masterData = new SC_DB_MasterData_Ex();
63        $this->arrPref = $masterData->getMasterData('mtb_pref');
64        $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status");
65
66        $this->httpCacheControl('nocache');
67    }
68
69    /**
70     * Page のプロセス.
71     *
72     * @return void
73     */
74    function process() {
75        $this->action();
76        $this->sendResponse();
77    }
78
79    /**
80     * Page のアクション.
81     *
82     * @return void
83     */
84    function action() {
85        $objSess = new SC_Session();
86        $objDb = new SC_Helper_DB_Ex();
87        $objDate = new SC_Date(1970);
88        $objPurchase = new SC_Helper_Purchase_Ex();
89        $this->arrYearShippingDate = $objDate->getYear('', date('Y'), '');
90        $this->arrMonthShippingDate = $objDate->getMonth(true);
91        $this->arrDayShippingDate = $objDate->getDay(true);
92
93        // パラメータ管理クラス
94        $this->objFormParam = new SC_FormParam();
95        // パラメータ情報の初期化
96        $this->lfInitParam();
97
98        // 認証可否の判定
99        SC_Utils_Ex::sfIsSuccess($objSess);
100
101        // 検索パラメータの引き継ぎ
102        foreach ($_POST as $key => $val) {
103            if (ereg("^search_", $key)) {
104                $this->arrSearchHidden[$key] = $val;
105            }
106        }
107
108        // 表示モード判定
109        if(isset($_GET['order_id']) &&
110            SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
111            $this->disp_mode = true;
112            $order_id = $_GET['order_id'];
113        } else {
114            $order_id = $_POST['order_id'];
115        }
116        $this->tpl_order_id = $order_id;
117
118        // DBから受注情報を読み込む
119        $this->lfGetOrderData($order_id);
120
121        switch($_POST['mode']) {
122        case 'pre_edit':
123        case 'order_id':
124            break;
125        case 'edit':
126        case 'add':
127            // POST情報で上書き
128            $this->objFormParam->setParam($_POST);
129
130            // 入力値の変換
131            $this->objFormParam->convParam();
132            $this->arrErr = $this->lfCheckError();
133
134            if(count($this->arrErr) == 0) {
135                if ($_POST['mode'] == 'add') {
136                    $order_id = $this->lfRegistNewData();
137
138                    $this->tpl_order_id = $order_id;
139                    $this->tpl_mode = 'edit';
140
141                    $arrData['order_id'] = $order_id;
142                    $this->objFormParam->setParam($arrData);
143
144                    $text = "'新規受注を登録しました。'";
145                } else {
146                    $this->lfRegistData($_POST['order_id']);
147                    $text = "'受注履歴を編集しました。'";
148                }
149                // DBから受注情報を再読込
150                $this->lfGetOrderData($order_id);
151                $this->tpl_onload = "window.alert(".$text.");";
152            }
153            break;
154            // 再計算
155        case 'cheek':
156        //支払い方法の選択
157        case 'payment':
158            // POST情報で上書き
159            $this->objFormParam->setParam($_POST);
160            // 入力値の変換
161            $this->objFormParam->convParam();
162            $this->arrErr = $this->lfCheckError();
163            break;
164
165        /* 商品削除*/
166        case 'delete_product':
167            $delete_no = $_POST['delete_no'];
168            foreach ($_POST AS $key=>$val) {
169                if (is_array($val)) {
170                    foreach ($val AS $k=>$v) {
171                        if ($k != $delete_no) {
172                            $arrData[$key][] = $v;
173                        }
174                    }
175                } else {
176                    $arrData[$key] = $val;
177                }
178            }
179            // 情報上書き
180            $this->objFormParam->setParam($arrData);
181            // 入力値の変換
182            $this->objFormParam->convParam();
183            $this->arrErr = $this->lfCheckError();
184            break;
185        /* 商品追加ポップアップより商品選択後、商品情報取得*/
186        case 'select_product_detail':
187            // POST情報で上書き
188            $this->objFormParam->setParam($_POST);
189            if (!empty($_POST['add_product_class_id'])) {
190                $this->lfInsertProduct($_POST['add_product_class_id']);
191            } elseif (!empty($_POST['edit_product_class_id'])) {
192                $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']);
193            }
194            $arrData = $_POST;
195            foreach ($this->arrForm AS $key=>$val) {
196                if (is_array($val)) {
197                    $arrData[$key] = $this->arrForm[$key]['value'];
198                } else {
199                    $arrData[$key] = $val;
200                }
201            }
202            // 情報上書き
203            $this->objFormParam->setParam($arrData);
204            // 入力値の変換
205            $this->objFormParam->convParam();
206            $this->arrErr = $this->lfCheckError();
207            break;
208        /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/
209        case 'search_customer':
210            // POST情報で上書き
211            $this->objFormParam->setParam($_POST);
212
213            // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
214            $this->lfSetCustomerInfo($_POST['edit_customer_id']);
215
216            break;
217
218        default:
219            break;
220        }
221
222        // 支払い方法の取得
223        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
224
225        $this->arrForm = $this->objFormParam->getFormParamList();
226        // XXX 商品種別IDは0番目の配列を使用
227        $this->product_type_id = $this->arrForm['product_type_id']['value'][0];
228        $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id);
229        $this->product_count = count($this->arrForm['quantity']['value']);
230
231        // アンカーを設定
232        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
233            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
234        } else {
235            $anchor_hash = "";
236        }
237        $this->tpl_onload .= $anchor_hash;
238
239        $objSiteInfo = new SC_SiteInfo();
240        $this->arrInfo = $objSiteInfo->data;
241
242        // 表示モード判定
243        if(!$this->disp_mode) {
244            $this->setTemplate(MAIN_FRAME);
245        } else {
246            $this->setTemplate('order/disp.tpl');
247        }
248    }
249
250    /**
251     * デストラクタ.
252     *
253     * @return void
254     */
255    function destroy() {
256        parent::destroy();
257    }
258
259    /* パラメータ情報の初期化 */
260    function lfInitParam() {
261
262        // お客様情報
263        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
264        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
265        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
266        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
267        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
268        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
269        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
270        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
271        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
272        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
273        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
274        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
275        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
276
277        // 受注商品情報
278        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
279        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
280        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
281
282        // ポイント機能ON時のみ
283        if (USE_POINT !== false) {
284            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
285        }
286
287        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
288        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
289        $this->objFormParam->addParam("お支払方法名称", "payment_method");
290
291
292        // 受注詳細情報
293        $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
294        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
295        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
296        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
297        $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
298        $this->objFormParam->addParam("ポイント付与率", "point_rate");
299        $this->objFormParam->addParam("商品コード", "product_code");
300        $this->objFormParam->addParam("商品名", "product_name");
301        $this->objFormParam->addParam("規格名1", "classcategory_name1");
302        $this->objFormParam->addParam("規格名2", "classcategory_name2");
303        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
304        // DB読込用
305        $this->objFormParam->addParam("小計", "subtotal");
306        $this->objFormParam->addParam("合計", "total");
307        $this->objFormParam->addParam("支払い合計", "payment_total");
308        $this->objFormParam->addParam("加算ポイント", "add_point");
309        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
310        $this->objFormParam->addParam("消費税合計", "tax");
311        $this->objFormParam->addParam("最終保持ポイント", "total_point");
312        $this->objFormParam->addParam("顧客ID", "customer_id");
313        $this->objFormParam->addParam("現在のポイント", "point");
314        $this->objFormParam->addParam("注文番号", "order_id");
315        $this->objFormParam->addParam("受注日", "create_date");
316        $this->objFormParam->addParam("発送日", "commit_date");
317        $this->objFormParam->addParam("備考", "message");
318        $this->objFormParam->addParam("入金日", "payment_date");
319    }
320
321    /**
322     * お届け先用フォームの初期化
323     */
324    function lfInitShippingParam(&$arrShipping) {
325        $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
326        foreach ($arrShipping as $shipping) {
327            $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
328            $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
329            $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
330            $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
331            $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
332            $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
333            $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
334            $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
335            $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
336            $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
337            $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
338            $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
339            $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
340            $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
341            $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']);
342            $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
343            $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
344            $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
345            $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
346            $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
347            foreach ($shipping['shipment_item'] as $productClassId => $item) {
348                $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
349                $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId);
350                $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId);
351                $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId);
352                $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId);
353                $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
354                $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
355            }
356        }
357    }
358
359
360    function lfGetOrderData($order_id) {
361        if(SC_Utils_Ex::sfIsInt($order_id)) {
362            // DBから受注情報を読み込む
363            $objQuery = new SC_Query();
364            $objDb = new SC_Helper_DB_Ex();
365            $where = "order_id = ?";
366            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
367            $this->objFormParam->setParam($arrRet[0]);
368            list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
369            $this->objFormParam->setValue('total_point', $db_point);
370            $this->objFormParam->setValue('point', $rollback_point);
371            $this->arrForm = $arrRet[0];
372
373            // 受注詳細データの取得
374            $arrRet = $this->lfGetOrderDetail($order_id);
375            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
376            $this->arrForm = array_merge($this->arrForm, $arrRet);
377            $this->objFormParam->setParam($arrRet);
378
379            $this->arrShipping = $this->lfGetShippingData($order_id);
380            $this->lfInitShippingParam($this->arrShipping);
381
382            $this->arrForm['shipping_quantity'] = count($this->arrShipping);
383            $this->objFormParam->setValue('shipping_quantity', $this->arrForm['shipping_quantity']);
384
385            // 配送情報の処理
386            foreach ($this->arrShipping as $shipping) {
387
388                $this->arrShippingIds[] = $shipping['shipping_id'];
389                $this->arrProductClassIds[] = array_keys($shipping['shipment_item']);
390
391                // お届け日の取得
392                $ts = strtotime($shipping["shipping_date"]);
393                $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts));
394                $this->arrForm['shipping_date_year_' . $shipping['shipping_id']] = date("Y", $ts);
395                $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts));
396                $this->arrForm['shipping_date_month_' . $shipping['shipping_id']] = date("n", $ts);
397                $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts));
398                $this->arrForm['shipping_date_day_' . $shipping['shipping_id']] = date("j", $ts);
399
400                // 配送内容の処理
401                foreach ($shipping as $shippingKey => $shippingVal) {
402
403                    $this->arrForm[$shippingKey . '_' . $shipping['shipping_id']] = $shippingVal;
404                    $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal);
405
406                    $this->arrForm['shipping_product_quantity' . '_' . $shipping['shipping_id']] = count($shipping['shipment_item']);
407                    $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'],
408                                                  $this->arrForm['shipping_product_quantity' . '_' . $shipping['shipping_id']]);
409
410                    // 配送商品の処理
411                    foreach ($shipping['shipment_item'] as $productClassId => $item) {
412                        foreach ($item as $itemKey => $itemVal) {
413                            $this->arrForm[$itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId] = $itemVal;
414                            $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal);
415                        }
416                    }
417                }
418            }
419
420            // その他支払い情報を表示
421            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
422            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
423                $this->arrForm["payment_type"] = "クレジット決済";
424            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
425                $this->arrForm["payment_type"] = "コンビニ決済";
426            }else{
427                $this->arrForm["payment_type"] = "お支払い";
428            }
429            // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため)
430            $this->arrDisp = $this->arrForm;
431        }
432    }
433
434    // 受注詳細データの取得
435    function lfGetOrderDetail($order_id) {
436        $objQuery = new SC_Query();
437        $from = <<< __EOS__
438                 dtb_order_detail T1
439            JOIN dtb_products_class T2
440              ON T1.product_class_id = T2.product_class_id
441__EOS__;
442        $arrRet = $objQuery->select("T1.*, T2.product_type_id", $from,
443                                    "order_id = ?", array($order_id));
444        return $arrRet;
445    }
446
447    /**
448     * 配送情報の取得.
449     * TODO リファクタリング
450     */
451    function lfGetShippingData($orderId) {
452        $objQuery =& SC_Query::getSingletonInstance();
453        $objProduct = new SC_Product();
454        $objQuery->setOrder('shipping_id');
455        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId));
456        foreach (array_keys($arrRet) as $key) {
457            $objQuery->setOrder('shipping_id');
458            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
459                                       array($orderId, $arrRet[$key]['shipping_id']));
460            foreach ($arrItems as $itemKey => $arrDetail) {
461                foreach ($arrDetail as $detailKey => $detailVal) {
462                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
463                }
464
465                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
466            }
467        }
468        return $arrRet;
469    }
470
471    /* 入力内容のチェック */
472    function lfCheckError() {
473        // 入力データを渡す。
474        $arrRet =  $this->objFormParam->getHashArray();
475        $objErr = new SC_CheckError($arrRet);
476        $objErr->arrErr = $this->objFormParam->checkError();
477
478        if (count($objErr->arrErr) >= 1) {
479            return $objErr->arrErr;
480        }
481
482        return $this->lfCheek();
483    }
484
485    /* 計算処理 */
486    function lfCheek() {
487        $objDb = new SC_Helper_DB_Ex();
488        $arrVal = $this->objFormParam->getHashArray();
489        $arrErr = array();
490
491        // 商品の種類数
492        $max = count($arrVal['quantity']);
493        $subtotal = 0;
494        $totalpoint = 0;
495        $totaltax = 0;
496        for($i = 0; $i < $max; $i++) {
497            // 小計の計算
498            $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
499            // 小計の計算
500            $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
501            // 加算ポイントの計算
502            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
503        }
504
505        // 消費税
506        $arrVal['tax'] = $totaltax;
507        // 小計
508        $arrVal['subtotal'] = $subtotal;
509        // 合計
510        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
511        // お支払い合計
512        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
513
514        // 加算ポイント
515        $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']);
516       
517        // 最終保持ポイント
518        $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point'];
519       
520        if ($arrVal['total'] < 0) {
521            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
522        }
523
524        if ($arrVal['payment_total'] < 0) {
525            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
526        }
527        //新規追加受注のみ
528        if ($_POST['mode'] == "add") {
529            if ($arrVal['total_point'] < 0) {
530                    $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
531            }
532        }
533
534        $this->objFormParam->setParam($arrVal);
535        return $arrErr;
536    }
537
538    /**
539     * DB更新処理
540     *
541     * @param integer $order_id 注文番号
542     * @return void
543     */
544    function lfRegistData($order_id) {
545        $objQuery = new SC_Query();
546
547        $sqlval = $this->lfMakeSqlvalForDtbOrder();
548
549        $where = "order_id = ?";
550
551        $objQuery->begin();
552
553        // 受注.対応状況の更新
554        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']);
555        unset($sqlval['status']);
556        unset($sqlval['add_point']);
557        unset($sqlval['use_point']);
558
559        // 受注テーブルの更新
560        $this->registerOrder($sqlval, $order_id);
561
562        // 受注テーブルの名称列を更新
563        //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
564
565        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
566
567
568        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算
569        $max = count($arrDetail);
570        $k = 0;
571        $arrStockData = array();
572        for($i = 0; $i < $max; $i++) {
573            if (!empty($arrDetail[$i]['product_id'])) {
574                $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
575                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) {
576                    // 数量が変更された商品
577                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
578                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity'];
579                    ++$k;
580                } elseif (empty($arrPreDetail)) {
581                    // 新しく追加された商品 もしくは 違う商品に変更された商品
582                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
583                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity'];
584                    ++$k;
585                }
586                $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
587            }
588        }
589
590        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品
591        $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id));
592        foreach ($arrPreDetail AS $key=>$val) {
593            $arrStockData[$k]['product_class_id'] = $val['product_class_id'];
594            $arrStockData[$k]['quantity'] = $val['quantity'];
595            ++$k;
596        }
597
598        // 受注詳細データの初期化
599        $objQuery->delete("dtb_order_detail", $where, array($order_id));
600
601        // 受注詳細データの更新
602        $max = count($arrDetail);
603        for ($i = 0; $i < $max; $i++) {
604            $sqlval = array();
605            $sqlval['order_id'] = $order_id;
606            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
607            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
608            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
609            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
610            $sqlval['price']  = $arrDetail[$i]['price'];
611            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
612            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
613            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
614            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
615            $objQuery->insert("dtb_order_detail", $sqlval);
616        }
617
618        // 在庫数調整
619        $status = $sqlval['status'];
620        if (ORDER_DELIV != $status && ORDER_CANCEL != $status) {
621            $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_class_id = ?";
622            foreach ($arrStockData AS $key=>$val) {
623                $stock_sqlval = array();
624                $stock_sqlval[] = $val['quantity'];
625                $stock_sqlval[] = $val['product_class_id'];
626
627                $objQuery->query($stock_sql, $stock_sqlval);
628            }
629        }
630
631        $objQuery->commit();
632    }
633
634    /**
635     * DB登録処理
636     *
637     * @return integer 注文番号
638     */
639    function lfRegistNewData() {
640        $objQuery = new SC_Query();
641
642        $sqlval = $this->lfMakeSqlvalForDtbOrder();
643
644        // ポイントは別登録
645        $addPoint = $sqlval['add_point'];
646        $usePoint = $sqlval['use_point'];
647        $sqlval['add_point'] = 0;
648        $sqlval['use_point'] = 0;
649
650        // customer_id
651        if ($sqlval["customer_id"] == "") {
652            $sqlval['customer_id'] = '0';
653        }
654
655        $sqlval['create_date'] = 'Now()';       // 受注日
656
657        $objQuery->begin();
658
659        // 受注テーブルの登録
660        $order_id = $objQuery->nextVal('dtb_order_order_id');
661        $sqlval['order_id'] = $order_id;
662        $objQuery->insert("dtb_order", $sqlval);
663
664
665        // 受注.対応状況の更新
666        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint);
667
668        // 受注テーブルの名称列を更新
669        SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
670
671        // 受注詳細データの更新
672        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
673        $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id));
674
675        $max = count($arrDetail);
676        for ($i = 0; $i < $max; $i++) {
677            $sqlval = array();
678            $sqlval['order_id'] = $order_id;
679            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
680            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
681            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
682            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
683            $sqlval['price']  = $arrDetail[$i]['price'];
684            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
685            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
686            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
687            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
688
689            $objQuery->insert("dtb_order_detail", $sqlval);
690
691
692            // 在庫数減少処理
693            // 現在の実在庫数取得
694            $pre_stock = $objQuery->getOne("SELECT stock FROM dtb_products_class WHERE product_class_id = ?", array($arrDetail[$i]['product_class_id']));
695
696            $stock_sqlval = array();
697            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']);
698            if ($stock_sqlval['stock'] === 0) {
699                $stock_sqlval['stock'] = '0';
700        }
701
702            $st_params = array();
703            $st_params[] = $arrDetail[$i]['product_class_id'];
704
705            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_class_id = ?', $st_params);
706        }
707        $objQuery->commit();
708
709        return $order_id;
710    }
711
712    /**
713     * 受注を登録する
714     */
715    function registerOrder($sqlval, $order_id) {
716        $table = 'dtb_order';
717        $objQuery = SC_Query::getSingletonInstance();
718        $cols = $objQuery->listTableFields($table);
719        $dest = array();
720        foreach ($sqlval as $key => $val) {
721            if (in_array($cols, $key)) {
722                $dest[$key] = $val;
723            }
724        }
725        $result = $objQuery->update($table, $dest, "order_id = ?", array($order_id));
726        if ($result == 0) {
727            $dest['order_id'] = $order_id;
728            $result = $objQuery->insert($table, $dest);
729        }
730    }
731
732    function lfInsertProduct($product_class_id) {
733        $objProduct = new SC_Product();
734        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
735        $this->arrForm = $this->objFormParam->getFormParamList();
736        $existes = false;
737        $existes_key = NULL;
738        // 既に同じ商品がないか、確認する
739        if (!empty($this->arrForm['product_class_id']['value'])) {
740            foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) {
741                // 既に同じ商品がある場合
742                if ($val == $product_class_id) {
743                    $existes = true;
744                    $existes_key = $key;
745                }
746            }
747        }
748
749        if ($existes) {
750        // 既に同じ商品がある場合
751            ++$this->arrForm['quantity']['value'][$existes_key];
752        } else {
753        // 既に同じ商品がない場合
754            $this->lfSetProductData($arrProduct);
755        }
756    }
757
758    function lfUpdateProduct($product_class_id, $no) {
759        $objProduct = new SC_Product();
760        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
761        $this->arrForm = $this->objFormParam->getFormParamList();
762        $this->lfSetProductData($arrProduct, $no);
763    }
764
765    function lfSetProductData($arrProduct, $no = null) {
766        foreach ($arrProduct AS $key=>$val) {
767            if (!is_array($this->arrForm[$key]['value'])) {
768                unset($this->arrForm[$key]['value']);
769            }
770            if ($no === null) {
771                $this->arrForm[$key]['value'][] = $val;
772            } else {
773                $this->arrForm[$key]['value'][$no] = $val;
774            }
775        }
776    }
777
778    function lfGetProductsClass($productsClass) {
779        $arrProduct['price'] = $productsClass['price02'];
780        $arrProduct['quantity'] = 1;
781        $arrProduct['product_id'] = $productsClass['product_id'];
782        $arrProduct['product_class_id'] = $productsClass['product_class_id'];
783        $arrProduct['point_rate'] = $productsClass['point_rate'];
784        $arrProduct['product_code'] = $productsClass['product_code'];
785        $arrProduct['product_name'] = $productsClass['name'];
786        $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1'];
787        $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2'];
788
789        return $arrProduct;
790    }
791
792
793    /**
794     * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
795     * @param int $edit_customer_id 顧客ID
796     */
797    function lfSetCustomerInfo($edit_customer_id = ""){
798        // 顧客IDが指定されている場合のみ、処理を実行する
799        if( $edit_customer_id === "" ) return ;
800
801        // 検索で選択された顧客IDが入力されている場合
802        if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){
803            $objQuery = new SC_Query();
804
805            // 顧客情報を取得する
806            $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id));
807
808            // 顧客情報を取得する事が出来たら、テンプレートに値を渡す
809            if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){
810                // カラム名にorder_を付ける(テンプレート側でorder_がついている為
811                foreach($arrCustomerInfo[0] as $index=>$customer_info){
812                    // customer_idにはorder_を付けないようにする
813                    $order_index = ($index == 'customer_id') ? $index : 'order_'.$index;
814                    $arrCustomer[$order_index] = $customer_info;
815                }
816            }
817
818            // hiddenに渡す
819            $this->edit_customer_id = $edit_customer_id;
820
821            // 受注日に現在の時刻を取得し、表示させる
822            $create_date = $objQuery->getAll('SELECT now() as create_date;');
823            $arrCustomer['create_date'] = $create_date[0]['create_date'];
824
825            // 情報上書き
826            $this->objFormParam->setParam($arrCustomer);
827            // 入力値の変換
828            $this->objFormParam->convParam();
829        }
830    }
831
832    /**
833     * 受注テーブルの登録・更新用データの共通部分を作成する
834     *
835     * @return array
836     */
837    function lfMakeSqlvalForDtbOrder() {
838
839        // 入力データを取得する
840        $sqlval = $this->objFormParam->getHashArray();
841        foreach ($sqlval as $key => $val) {
842            // 配列は登録しない
843            if (is_array($val)) {
844                unset($sqlval[$key]);
845            }
846        }
847
848        // 受注テーブルに書き込まない列を除去
849        unset($sqlval['total_point']);
850        unset($sqlval['point']);
851        unset($sqlval['commit_date']);
852
853        // 更新日時
854        $sqlval['update_date'] = 'Now()';
855
856        return $sqlval;
857   }
858}
859?>
Note: See TracBrowser for help on using the repository browser.