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

Revision 19934, 43.2 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        // 複数配送設定表示
219        case 'multiple':
220            $this->objFormParam->setParam($_POST);
221            $this->tpl_onload = "win03('" . URL_PATH . ADMIN_DIR . "order/multiple.php', 'multiple', '600', '500');";
222            break;
223
224        // 複数配送設定を反映
225        case 'multiple_set_to':
226            $multipleSize = $_POST['multiple_size'];
227            $this->lfInitMultipleParam($multipleSize);
228            $this->objFormParam->setParam($_POST);
229            $this->setMultipleItemTo($multipleSize);
230            break;
231        default:
232            break;
233        }
234
235        // 支払い方法の取得
236        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
237
238        $this->arrForm = $this->objFormParam->getFormParamList();
239        // XXX 商品種別IDは0番目の配列を使用
240        $this->product_type_id = $this->arrForm['product_type_id']['value'][0];
241        $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id);
242        $this->product_count = count($this->arrForm['quantity']['value']);
243
244        // アンカーを設定
245        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
246            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
247        } else {
248            $anchor_hash = "";
249        }
250        $this->tpl_onload .= $anchor_hash;
251
252        $objSiteInfo = new SC_SiteInfo();
253        $this->arrInfo = $objSiteInfo->data;
254
255        // 表示モード判定
256        if(!$this->disp_mode) {
257            $this->setTemplate(MAIN_FRAME);
258        } else {
259            $this->setTemplate('order/disp.tpl');
260        }
261    }
262
263    /**
264     * デストラクタ.
265     *
266     * @return void
267     */
268    function destroy() {
269        parent::destroy();
270    }
271
272    /* パラメータ情報の初期化 */
273    function lfInitParam() {
274
275        // お客様情報
276        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
277        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
278        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
279        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
280        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
281        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
282        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
283        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
284        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
285        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
286        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
287        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
288        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
289
290        // 受注商品情報
291        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
292        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
293        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
294
295        // ポイント機能ON時のみ
296        if (USE_POINT !== false) {
297            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
298        }
299
300        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
301        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
302        $this->objFormParam->addParam("お支払方法名称", "payment_method");
303
304
305        // 受注詳細情報
306        $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
307        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
308        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
309        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
310        $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
311        $this->objFormParam->addParam("ポイント付与率", "point_rate");
312        $this->objFormParam->addParam("商品コード", "product_code");
313        $this->objFormParam->addParam("商品名", "product_name");
314        $this->objFormParam->addParam("規格名1", "classcategory_name1");
315        $this->objFormParam->addParam("規格名2", "classcategory_name2");
316        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
317        // DB読込用
318        $this->objFormParam->addParam("小計", "subtotal");
319        $this->objFormParam->addParam("合計", "total");
320        $this->objFormParam->addParam("支払い合計", "payment_total");
321        $this->objFormParam->addParam("加算ポイント", "add_point");
322        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
323        $this->objFormParam->addParam("消費税合計", "tax");
324        $this->objFormParam->addParam("最終保持ポイント", "total_point");
325        $this->objFormParam->addParam("顧客ID", "customer_id");
326        $this->objFormParam->addParam("現在のポイント", "point");
327        $this->objFormParam->addParam("注文番号", "order_id");
328        $this->objFormParam->addParam("受注日", "create_date");
329        $this->objFormParam->addParam("発送日", "commit_date");
330        $this->objFormParam->addParam("備考", "message");
331        $this->objFormParam->addParam("入金日", "payment_date");
332    }
333
334    /**
335     * お届け先用フォームの初期化
336     */
337    function lfInitShippingParam(&$arrShipping) {
338        $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
339        foreach ($arrShipping as $shipping) {
340            $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
341            $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
342            $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
343            $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
344            $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
345            $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
346            $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
347            $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
348            $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
349            $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
350            $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
351            $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
352            $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
353            $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
354            $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']);
355            $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
356            $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
357            $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
358            $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
359            $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
360            foreach ($shipping['shipment_item'] as $productClassId => $item) {
361                $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
362                $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId);
363                $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId);
364                $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId);
365                $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId);
366                $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
367                $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
368            }
369        }
370    }
371
372    /**
373     * 複数配送用フォームの初期化
374     */
375    function lfInitMultipleParam($size) {
376        for ($i = 0; $i < $size; $i++) {
377            $this->objFormParam->addParam("商品規格ID", "multiple_product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
378            $this->objFormParam->addParam("商品コード", "multiple_product_code" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
379            $this->objFormParam->addParam("商品名", "multiple_product_name" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
380            $this->objFormParam->addParam("規格1", "multiple_classcategory_name1" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
381            $this->objFormParam->addParam("規格2", "multiple_classcategory_name2" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
382            $this->objFormParam->addParam("単価", "multiple_price" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
383            $this->objFormParam->addParam("数量", "multiple_quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
384            $this->objFormParam->addParam("配送先住所", "multiple_shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
385        }
386    }
387
388
389    function setMultipleItemTo($size) {
390        $arrShipmentItem = array();
391        for ($i = 0; $i < $size; $i++) {
392            $shippingId = $this->objFormParam->getValue('multiple_shipping' . $i);
393            $productClassId = $this->objFormParam->getValue('multiple_product_class_id' . $i);
394
395            $name = $this->objFormParam->getValue('multiple_product_name' . $i);
396            $code = $this->objFormParam->getValue('multiple_product_code' . $i);
397            $class1 = $this->objFormParam->getValue('multiple_classcategory_name1' . $i);
398            $class2 = $this->objFormParam->getValue('multiple_classcategory_name2' . $i);
399            $price = $this->objFormParam->getValue('multiple_price' . $i);
400            $quantity = $this->objFormParam->getValue('multiple_quantity' . $i);
401
402            $arrShipmentItem[$shippingId][$productClassId]['shipping_id'] = $shippingId;
403            $arrShipmentItem[$shippingId][$productClassId]['product_class_id'] = $productClassId;
404            $arrShipmentItem[$shippingId][$productClassId]['classcategory_name1'] = $class1;
405            $arrShipmentItem[$shippingId][$productClassId]['classcategory_name2'] = $class2;
406            $arrShipmentItem[$shippingId][$productClassId]['price'] = $price;
407            $arrShipmentItem[$shippingId][$productClassId]['quantity'] += $quantity;
408        }
409
410        $this->arrShippingIds = array();
411        $this->arrProductClassIds = array();
412        foreach ($arrShipmentItem as $shippingId => $items) {
413
414            $this->arrForm['shipping_product_quantity' . '_' . $shippingId] = count($items);
415            $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shippingId,
416                                          $this->arrForm['shipping_product_quantity' . '_' . $shippingId]);
417
418            $this->arrShippingIds[] = $shippingId;
419            $this->arrProductClassIds[] = array_keys($items);
420
421            foreach ($items as $productClassId => $item) {
422                foreach ($item as $itemKey => $itemVal) {
423                    $this->arrForm[$itemKey . '_' . $shippingId . '_' . $productClassId] = $itemVal;
424                    $this->objFormParam->setValue($itemKey . '_' . $shippingId . '_' . $productClassId, $itemVal);
425                }
426            }
427        }
428    }
429
430    function lfGetOrderData($order_id) {
431        if(SC_Utils_Ex::sfIsInt($order_id)) {
432            // DBから受注情報を読み込む
433            $objQuery = new SC_Query();
434            $objDb = new SC_Helper_DB_Ex();
435            $where = "order_id = ?";
436            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
437            $this->objFormParam->setParam($arrRet[0]);
438            list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
439            $this->objFormParam->setValue('total_point', $db_point);
440            $this->objFormParam->setValue('point', $rollback_point);
441            $this->arrForm = $arrRet[0];
442
443            // 受注詳細データの取得
444            $arrRet = $this->lfGetOrderDetail($order_id);
445            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
446            $this->arrForm = array_merge($this->arrForm, $arrRet);
447            $this->objFormParam->setParam($arrRet);
448
449            $this->arrShipping = $this->lfGetShippingData($order_id);
450            $this->lfInitShippingParam($this->arrShipping);
451
452            $this->arrForm['shipping_quantity'] = count($this->arrShipping);
453            $this->objFormParam->setValue('shipping_quantity', $this->arrForm['shipping_quantity']);
454
455            // 配送情報の処理
456            foreach ($this->arrShipping as $shipping) {
457
458                $this->arrShippingIds[] = $shipping['shipping_id'];
459                $this->arrProductClassIds[] = array_keys($shipping['shipment_item']);
460
461                // お届け日の取得
462                if (!SC_Utils_Ex::isBlank($shipping["shipping_date"])) {
463                    $ts = strtotime($shipping["shipping_date"]);
464                    $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts));
465                    $this->arrForm['shipping_date_year_' . $shipping['shipping_id']] = date("Y", $ts);
466                    $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts));
467                    $this->arrForm['shipping_date_month_' . $shipping['shipping_id']] = date("n", $ts);
468                    $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts));
469                    $this->arrForm['shipping_date_day_' . $shipping['shipping_id']] = date("j", $ts);
470                }
471
472                // 配送内容の処理
473                foreach ($shipping as $shippingKey => $shippingVal) {
474
475                    $this->arrForm[$shippingKey . '_' . $shipping['shipping_id']] = $shippingVal;
476                    $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal);
477
478                    $this->arrForm['shipping_product_quantity' . '_' . $shipping['shipping_id']] = count($shipping['shipment_item']);
479                    $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'],
480                                                  $this->arrForm['shipping_product_quantity' . '_' . $shipping['shipping_id']]);
481
482                    // 配送商品の処理
483                    foreach ($shipping['shipment_item'] as $productClassId => $item) {
484                        foreach ($item as $itemKey => $itemVal) {
485                            $this->arrForm[$itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId] = $itemVal;
486                            $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal);
487                        }
488                    }
489                }
490            }
491
492            // その他支払い情報を表示
493            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
494            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
495                $this->arrForm["payment_type"] = "クレジット決済";
496            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
497                $this->arrForm["payment_type"] = "コンビニ決済";
498            }else{
499                $this->arrForm["payment_type"] = "お支払い";
500            }
501            // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため)
502            $this->arrDisp = $this->arrForm;
503        }
504    }
505
506    // 受注詳細データの取得
507    function lfGetOrderDetail($order_id) {
508        $objQuery = new SC_Query();
509        $from = <<< __EOS__
510                 dtb_order_detail T1
511            JOIN dtb_products_class T2
512              ON T1.product_class_id = T2.product_class_id
513__EOS__;
514        $arrRet = $objQuery->select("T1.*, T2.product_type_id", $from,
515                                    "order_id = ?", array($order_id));
516        return $arrRet;
517    }
518
519    /**
520     * 配送情報の取得.
521     * TODO リファクタリング
522     */
523    function lfGetShippingData($orderId) {
524        $objQuery =& SC_Query::getSingletonInstance();
525        $objProduct = new SC_Product();
526        $objQuery->setOrder('shipping_id');
527        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId));
528        foreach (array_keys($arrRet) as $key) {
529            $objQuery->setOrder('shipping_id');
530            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
531                                       array($orderId, $arrRet[$key]['shipping_id']));
532            foreach ($arrItems as $itemKey => $arrDetail) {
533                foreach ($arrDetail as $detailKey => $detailVal) {
534                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
535                }
536
537                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
538            }
539        }
540        return $arrRet;
541    }
542
543    /* 入力内容のチェック */
544    function lfCheckError() {
545        // 入力データを渡す。
546        $arrRet =  $this->objFormParam->getHashArray();
547        $objErr = new SC_CheckError($arrRet);
548        $objErr->arrErr = $this->objFormParam->checkError();
549
550        if (count($objErr->arrErr) >= 1) {
551            return $objErr->arrErr;
552        }
553
554        return $this->lfCheek();
555    }
556
557    /* 計算処理 */
558    function lfCheek() {
559        $objDb = new SC_Helper_DB_Ex();
560        $arrVal = $this->objFormParam->getHashArray();
561        $arrErr = array();
562
563        // 商品の種類数
564        $max = count($arrVal['quantity']);
565        $subtotal = 0;
566        $totalpoint = 0;
567        $totaltax = 0;
568        for($i = 0; $i < $max; $i++) {
569            // 小計の計算
570            $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
571            // 小計の計算
572            $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
573            // 加算ポイントの計算
574            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
575        }
576
577        // 消費税
578        $arrVal['tax'] = $totaltax;
579        // 小計
580        $arrVal['subtotal'] = $subtotal;
581        // 合計
582        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
583        // お支払い合計
584        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
585
586        // 加算ポイント
587        $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']);
588       
589        // 最終保持ポイント
590        $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point'];
591       
592        if ($arrVal['total'] < 0) {
593            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
594        }
595
596        if ($arrVal['payment_total'] < 0) {
597            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
598        }
599        //新規追加受注のみ
600        if ($_POST['mode'] == "add") {
601            if ($arrVal['total_point'] < 0) {
602                    $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
603            }
604        }
605
606        $this->objFormParam->setParam($arrVal);
607        return $arrErr;
608    }
609
610    /**
611     * DB更新処理
612     *
613     * @param integer $order_id 注文番号
614     * @return void
615     */
616    function lfRegistData($order_id) {
617        $objQuery = new SC_Query();
618
619        $sqlval = $this->lfMakeSqlvalForDtbOrder();
620
621        $where = "order_id = ?";
622
623        $objQuery->begin();
624
625        // 受注.対応状況の更新
626        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']);
627        unset($sqlval['status']);
628        unset($sqlval['add_point']);
629        unset($sqlval['use_point']);
630
631        // 受注テーブルの更新
632        $this->registerOrder($sqlval, $order_id);
633
634        // 受注テーブルの名称列を更新
635        //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
636
637        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
638
639
640        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算
641        $max = count($arrDetail);
642        $k = 0;
643        $arrStockData = array();
644        for($i = 0; $i < $max; $i++) {
645            if (!empty($arrDetail[$i]['product_id'])) {
646                $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
647                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) {
648                    // 数量が変更された商品
649                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
650                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity'];
651                    ++$k;
652                } elseif (empty($arrPreDetail)) {
653                    // 新しく追加された商品 もしくは 違う商品に変更された商品
654                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
655                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity'];
656                    ++$k;
657                }
658                $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
659            }
660        }
661
662        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品
663        $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id));
664        foreach ($arrPreDetail AS $key=>$val) {
665            $arrStockData[$k]['product_class_id'] = $val['product_class_id'];
666            $arrStockData[$k]['quantity'] = $val['quantity'];
667            ++$k;
668        }
669
670        // 受注詳細データの初期化
671        $objQuery->delete("dtb_order_detail", $where, array($order_id));
672
673        // 受注詳細データの更新
674        $max = count($arrDetail);
675        for ($i = 0; $i < $max; $i++) {
676            $sqlval = array();
677            $sqlval['order_id'] = $order_id;
678            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
679            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
680            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
681            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
682            $sqlval['price']  = $arrDetail[$i]['price'];
683            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
684            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
685            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
686            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
687            $objQuery->insert("dtb_order_detail", $sqlval);
688        }
689
690        // 在庫数調整
691        $status = $sqlval['status'];
692        if (ORDER_DELIV != $status && ORDER_CANCEL != $status) {
693            $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_class_id = ?";
694            foreach ($arrStockData AS $key=>$val) {
695                $stock_sqlval = array();
696                $stock_sqlval[] = $val['quantity'];
697                $stock_sqlval[] = $val['product_class_id'];
698
699                $objQuery->query($stock_sql, $stock_sqlval);
700            }
701        }
702
703        $objQuery->commit();
704    }
705
706    /**
707     * DB登録処理
708     *
709     * @return integer 注文番号
710     */
711    function lfRegistNewData() {
712        $objQuery = new SC_Query();
713
714        $sqlval = $this->lfMakeSqlvalForDtbOrder();
715
716        // ポイントは別登録
717        $addPoint = $sqlval['add_point'];
718        $usePoint = $sqlval['use_point'];
719        $sqlval['add_point'] = 0;
720        $sqlval['use_point'] = 0;
721
722        // customer_id
723        if ($sqlval["customer_id"] == "") {
724            $sqlval['customer_id'] = '0';
725        }
726
727        $sqlval['create_date'] = 'Now()';       // 受注日
728
729        $objQuery->begin();
730
731        // 受注テーブルの登録
732        $order_id = $objQuery->nextVal('dtb_order_order_id');
733        $sqlval['order_id'] = $order_id;
734        $objQuery->insert("dtb_order", $sqlval);
735
736
737        // 受注.対応状況の更新
738        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint);
739
740        // 受注テーブルの名称列を更新
741        SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
742
743        // 受注詳細データの更新
744        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
745        $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id));
746
747        $max = count($arrDetail);
748        for ($i = 0; $i < $max; $i++) {
749            $sqlval = array();
750            $sqlval['order_id'] = $order_id;
751            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
752            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
753            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
754            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
755            $sqlval['price']  = $arrDetail[$i]['price'];
756            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
757            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
758            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
759            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
760
761            $objQuery->insert("dtb_order_detail", $sqlval);
762
763
764            // 在庫数減少処理
765            // 現在の実在庫数取得
766            $pre_stock = $objQuery->getOne("SELECT stock FROM dtb_products_class WHERE product_class_id = ?", array($arrDetail[$i]['product_class_id']));
767
768            $stock_sqlval = array();
769            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']);
770            if ($stock_sqlval['stock'] === 0) {
771                $stock_sqlval['stock'] = '0';
772        }
773
774            $st_params = array();
775            $st_params[] = $arrDetail[$i]['product_class_id'];
776
777            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_class_id = ?', $st_params);
778        }
779        $objQuery->commit();
780
781        return $order_id;
782    }
783
784    /**
785     * 受注を登録する
786     */
787    function registerOrder($sqlval, $order_id) {
788        $table = 'dtb_order';
789        $objQuery = SC_Query::getSingletonInstance();
790        $cols = $objQuery->listTableFields($table);
791        $dest = array();
792        foreach ($sqlval as $key => $val) {
793            if (in_array($cols, $key)) {
794                $dest[$key] = $val;
795            }
796        }
797        $result = $objQuery->update($table, $dest, "order_id = ?", array($order_id));
798        if ($result == 0) {
799            $dest['order_id'] = $order_id;
800            $result = $objQuery->insert($table, $dest);
801        }
802    }
803
804    function lfInsertProduct($product_class_id) {
805        $objProduct = new SC_Product();
806        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
807        $this->arrForm = $this->objFormParam->getFormParamList();
808        $existes = false;
809        $existes_key = NULL;
810        // 既に同じ商品がないか、確認する
811        if (!empty($this->arrForm['product_class_id']['value'])) {
812            foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) {
813                // 既に同じ商品がある場合
814                if ($val == $product_class_id) {
815                    $existes = true;
816                    $existes_key = $key;
817                }
818            }
819        }
820
821        if ($existes) {
822        // 既に同じ商品がある場合
823            ++$this->arrForm['quantity']['value'][$existes_key];
824        } else {
825        // 既に同じ商品がない場合
826            $this->lfSetProductData($arrProduct);
827        }
828    }
829
830    function lfUpdateProduct($product_class_id, $no) {
831        $objProduct = new SC_Product();
832        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
833        $this->arrForm = $this->objFormParam->getFormParamList();
834        $this->lfSetProductData($arrProduct, $no);
835    }
836
837    function lfSetProductData($arrProduct, $no = null) {
838        foreach ($arrProduct AS $key=>$val) {
839            if (!is_array($this->arrForm[$key]['value'])) {
840                unset($this->arrForm[$key]['value']);
841            }
842            if ($no === null) {
843                $this->arrForm[$key]['value'][] = $val;
844            } else {
845                $this->arrForm[$key]['value'][$no] = $val;
846            }
847        }
848    }
849
850    function lfGetProductsClass($productsClass) {
851        $arrProduct['price'] = $productsClass['price02'];
852        $arrProduct['quantity'] = 1;
853        $arrProduct['product_id'] = $productsClass['product_id'];
854        $arrProduct['product_class_id'] = $productsClass['product_class_id'];
855        $arrProduct['point_rate'] = $productsClass['point_rate'];
856        $arrProduct['product_code'] = $productsClass['product_code'];
857        $arrProduct['product_name'] = $productsClass['name'];
858        $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1'];
859        $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2'];
860
861        return $arrProduct;
862    }
863
864
865    /**
866     * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
867     * @param int $edit_customer_id 顧客ID
868     */
869    function lfSetCustomerInfo($edit_customer_id = ""){
870        // 顧客IDが指定されている場合のみ、処理を実行する
871        if( $edit_customer_id === "" ) return ;
872
873        // 検索で選択された顧客IDが入力されている場合
874        if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){
875            $objQuery = new SC_Query();
876
877            // 顧客情報を取得する
878            $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id));
879
880            // 顧客情報を取得する事が出来たら、テンプレートに値を渡す
881            if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){
882                // カラム名にorder_を付ける(テンプレート側でorder_がついている為
883                foreach($arrCustomerInfo[0] as $index=>$customer_info){
884                    // customer_idにはorder_を付けないようにする
885                    $order_index = ($index == 'customer_id') ? $index : 'order_'.$index;
886                    $arrCustomer[$order_index] = $customer_info;
887                }
888            }
889
890            // hiddenに渡す
891            $this->edit_customer_id = $edit_customer_id;
892
893            // 受注日に現在の時刻を取得し、表示させる
894            $create_date = $objQuery->getAll('SELECT now() as create_date;');
895            $arrCustomer['create_date'] = $create_date[0]['create_date'];
896
897            // 情報上書き
898            $this->objFormParam->setParam($arrCustomer);
899            // 入力値の変換
900            $this->objFormParam->convParam();
901        }
902    }
903
904    /**
905     * 受注テーブルの登録・更新用データの共通部分を作成する
906     *
907     * @return array
908     */
909    function lfMakeSqlvalForDtbOrder() {
910
911        // 入力データを取得する
912        $sqlval = $this->objFormParam->getHashArray();
913        foreach ($sqlval as $key => $val) {
914            // 配列は登録しない
915            if (is_array($val)) {
916                unset($sqlval[$key]);
917            }
918        }
919
920        // 受注テーブルに書き込まない列を除去
921        unset($sqlval['total_point']);
922        unset($sqlval['point']);
923        unset($sqlval['commit_date']);
924
925        // 更新日時
926        $sqlval['update_date'] = 'Now()';
927
928        return $sqlval;
929   }
930}
931?>
Note: See TracBrowser for help on using the repository browser.