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

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