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

Revision 20116, 51.8 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
66
67        $this->httpCacheControl('nocache');
68    }
69
70    /**
71     * Page のプロセス.
72     *
73     * @return void
74     */
75    function process() {
76        $this->action();
77        $this->sendResponse();
78    }
79
80    /**
81     * Page のアクション.
82     *
83     * @return void
84     */
85    function action() {
86        $objSess = new SC_Session();
87        $objDb = new SC_Helper_DB_Ex();
88        $objDate = new SC_Date(1970);
89        $objPurchase = new SC_Helper_Purchase_Ex();
90        $this->arrYearShippingDate = $objDate->getYear('', date('Y'), '');
91        $this->arrMonthShippingDate = $objDate->getMonth(true);
92        $this->arrDayShippingDate = $objDate->getDay(true);
93
94        // パラメータ管理クラス
95        $this->objFormParam = new SC_FormParam();
96        // パラメータ情報の初期化
97        $this->lfInitParam();
98
99        // 認証可否の判定
100        SC_Utils_Ex::sfIsSuccess($objSess);
101
102        // 検索パラメータの引き継ぎ
103        foreach ($_POST as $key => $val) {
104            if (ereg("^search_", $key)) {
105                $this->arrSearchHidden[$key] = $val;
106            }
107        }
108
109        // 表示モード判定
110        if(isset($_GET['order_id']) &&
111           SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
112            $this->disp_mode = true;
113            $order_id = $_GET['order_id'];
114        } else {
115            $order_id = $_POST['order_id'];
116        }
117        $this->tpl_order_id = $order_id;
118
119        // DBから受注情報を読み込む
120        if (!SC_Utils_Ex::isBlank($order_id)) {
121            $this->lfGetOrderData($order_id);
122        }
123
124        switch($this->getMode()) {
125        case 'pre_edit':
126        case 'order_id':
127            break;
128        case 'edit':
129        case 'add':
130            // POST情報で上書き
131            $this->lfInitShippingParam($this->arrShipping);
132            $this->objFormParam->setParam($_POST);
133
134            // 入力値の変換
135            $this->objFormParam->convParam();
136            $this->arrErr = $this->lfCheckError();
137
138            if(count($this->arrErr) == 0) {
139                //TODO 要リファクタリング(MODE if利用)
140                if ($this->getMode() == 'add') {
141                    $order_id = $this->lfRegistNewData($objPurchase);
142
143                    $this->tpl_order_id = $order_id;
144                    $this->tpl_mode = 'edit';
145
146                    $arrData['order_id'] = $order_id;
147                    $this->objFormParam->setParam($arrData);
148
149                    $text = "'新規受注を登録しました。'";
150                } else {
151                    $this->lfRegistData($_POST['order_id'], $objPurchase);
152                    $text = "'受注履歴を編集しました。'";
153                }
154                // DBから受注情報を再読込
155                $this->lfGetOrderData($order_id);
156                $this->lfInitShippingParam($this->arrShipping);
157                $this->tpl_onload = "window.alert(".$text.");";
158            }
159            break;
160        // 再計算
161        case 'cheek':
162        //支払い方法の選択
163        case 'payment':
164            // POST情報で上書き
165            $this->lfInitShippingParam($this->arrShipping);
166            $this->objFormParam->setParam($_POST);
167            // 入力値の変換
168            $this->objFormParam->convParam();
169            $this->arrErr = $this->lfCheckError();
170            break;
171
172        /* 商品削除*/
173        case 'delete_product':
174            $delete_no = $_POST['delete_no'];
175            foreach ($_POST AS $key=>$val) {
176                if (is_array($val)) {
177                    foreach ($val AS $k=>$v) {
178                        if ($k != $delete_no) {
179                            $arrData[$key][] = $v;
180                        }
181                    }
182                } else {
183                    $arrData[$key] = $val;
184                }
185            }
186            // 情報上書き
187            $this->lfInitShippingParam($this->arrShipping);
188            $this->objFormParam->setParam($arrData);
189            // 入力値の変換
190            $this->objFormParam->convParam();
191            $this->arrErr = $this->lfCheckError();
192            break;
193        /* 商品追加ポップアップより商品選択後、商品情報取得*/
194        case 'select_product_detail':
195            // POST情報で上書き
196            $this->objFormParam->setParam($_POST);
197            if (!empty($_POST['add_product_class_id'])) {
198                $this->lfInsertProduct($_POST['add_product_class_id']);
199            } elseif (!empty($_POST['edit_product_class_id'])) {
200                $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']);
201            }
202            $arrData = $_POST;
203            foreach ($this->arrForm AS $key=>$val) {
204                if (is_array($val)) {
205                    $arrData[$key] = $this->arrForm[$key]['value'];
206                } else {
207                    $arrData[$key] = $val;
208                }
209            }
210
211            // 情報上書き
212            $this->lfInitShippingParam($this->arrShipping);
213            $this->objFormParam->setParam($arrData);
214            // 入力値の変換
215            $this->objFormParam->convParam();
216            $this->arrErr = $this->lfCheckError();
217            break;
218        /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/
219        case 'search_customer':
220            // POST情報で上書き
221            $this->lfInitShippingParam($this->arrShipping);
222            $this->objFormParam->setParam($_POST);
223
224            // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
225            $this->lfSetCustomerInfo($_POST['edit_customer_id']);
226
227            break;
228
229        // 複数配送設定表示
230        case 'multiple':
231            $this->lfInitShippingParam($this->arrShipping);
232            $this->objFormParam->setParam($_POST);
233            // 入力値の変換
234            $this->objFormParam->convParam();
235            $this->arrErr = $this->lfCheckError();
236            break;
237
238        // 複数配送設定を反映
239        case 'multiple_set_to':
240            $multipleSize = $_POST['multiple_size'];
241            $this->lfInitMultipleParam($multipleSize);
242            $this->objFormParam->setParam($_POST);
243            $this->lfInitShippingParam($this->arrShipping);
244            $this->setMultipleItemTo($multipleSize);
245            break;
246
247        // お届け先の追加
248        case 'append_shipping':
249            $this->lfInitShippingParam($this->arrShipping, true);
250            $this->objFormParam->setParam($_POST);
251            // 入力値の変換
252            $this->objFormParam->convParam();
253            break;
254
255        default:
256            // お届け先の初期表示
257            $this->lfInitShippingParam();
258            break;
259        }
260
261        // 支払い方法の取得
262        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
263
264        $this->arrForm = $this->objFormParam->getFormParamList();
265
266        // XXX 商品種別IDは0番目の配列を使用
267        $this->product_type_id = $this->arrForm['product_type_id']['value'][0];
268        $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id);
269        $this->product_count = count($this->arrForm['quantity']['value']);
270
271        // アンカーを設定
272        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
273            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
274        } else {
275            $anchor_hash = "";
276        }
277        $this->tpl_onload .= $anchor_hash;
278
279        $objSiteInfo = new SC_SiteInfo();
280        $this->arrInfo = $objSiteInfo->data;
281        // 表示モード判定
282        if(!$this->disp_mode) {
283            $this->setTemplate(MAIN_FRAME);
284        } else {
285            $this->setTemplate('order/disp.tpl');
286        }
287    }
288
289    /**
290     * デストラクタ.
291     *
292     * @return void
293     */
294    function destroy() {
295        parent::destroy();
296    }
297
298    /* パラメータ情報の初期化 */
299    function lfInitParam() {
300
301        // お客様情報
302        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
303        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
304        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
305        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
306        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
307        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
308        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
309        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
310        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
311        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
312        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
313        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
314        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
315
316        // 受注商品情報
317        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
318        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
319        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
320
321        // ポイント機能ON時のみ
322        if (USE_POINT !== false) {
323            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
324        }
325
326        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
327        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
328        $this->objFormParam->addParam("お支払方法名称", "payment_method");
329
330        // 受注詳細情報
331        $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
332        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
333        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
334        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
335        $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
336        $this->objFormParam->addParam("ポイント付与率", "point_rate");
337        $this->objFormParam->addParam("商品コード", "product_code");
338        $this->objFormParam->addParam("商品名", "product_name");
339        $this->objFormParam->addParam("規格名1", "classcategory_name1");
340        $this->objFormParam->addParam("規格名2", "classcategory_name2");
341        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
342        // DB読込用
343        $this->objFormParam->addParam("小計", "subtotal");
344        $this->objFormParam->addParam("合計", "total");
345        $this->objFormParam->addParam("支払い合計", "payment_total");
346        $this->objFormParam->addParam("加算ポイント", "add_point");
347        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
348        $this->objFormParam->addParam("消費税合計", "tax");
349        $this->objFormParam->addParam("最終保持ポイント", "total_point");
350        $this->objFormParam->addParam("顧客ID", "customer_id");
351        $this->objFormParam->addParam("現在のポイント", "point");
352        $this->objFormParam->addParam("注文番号", "order_id");
353        $this->objFormParam->addParam("受注日", "create_date");
354        $this->objFormParam->addParam("発送日", "commit_date");
355        $this->objFormParam->addParam("備考", "message");
356        $this->objFormParam->addParam("入金日", "payment_date");
357        $this->objFormParam->addParam("アクセス端末", "device_type_id");
358    }
359
360    /**
361     * お届け先用フォームの初期化
362     */
363    function lfInitShippingParam($arrShipping = array(), $add = false) {
364        if (empty($arrShipping) && !$add) {
365            $arrShipping[0]['shipping_id'] = 0;
366            $this->arrShippingIds[0] = 0;
367            $_POST['shipping_quantity'] = 1;
368        }
369
370        if ($add) {
371            $_POST['shipping_quantity'] = $_POST['shipping_quantity'] + 1;
372        }
373        for ($i = 0; $i < $_POST['shipping_quantity']; $i++) {
374            $arrShipping[$i]['shipping_id'] = $i;
375            $this->arrShippingIds[$i] = $i;
376        }
377
378        $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
379        $this->objFormParam->setValue('shipping_quantity', $_POST['shipping_quantity']);
380
381        foreach ($arrShipping as $shipping) {
382            $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), 0);
383            $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
384            $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
385            $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
386            $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
387            $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
388            $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
389            $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
390            $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
391            $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
392            $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
393            $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
394            $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
395            $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
396            $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']);
397            $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
398            $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
399            $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
400            $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
401            $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
402            foreach (array_keys($shipping['shipment_item']) as $productClassId) {
403                $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
404                $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId, $item['product_code']);
405                $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId);
406                $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId);
407                $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId);
408                $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
409                $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
410            }
411        }
412    }
413
414    /**
415     * 複数配送用フォームの初期化
416     */
417    function lfInitMultipleParam($size) {
418        for ($i = 0; $i < $size; $i++) {
419            $this->objFormParam->addParam("商品規格ID", "multiple_product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
420            $this->objFormParam->addParam("商品コード", "multiple_product_code" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
421            $this->objFormParam->addParam("商品名", "multiple_product_name" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
422            $this->objFormParam->addParam("規格1", "multiple_classcategory_name1" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
423            $this->objFormParam->addParam("規格2", "multiple_classcategory_name2" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
424            $this->objFormParam->addParam("単価", "multiple_price" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
425            $this->objFormParam->addParam("数量", "multiple_quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
426            $this->objFormParam->addParam("配送先住所", "multiple_shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
427        }
428    }
429
430
431    function setMultipleItemTo($size) {
432        $arrShipmentItem = array();
433        for ($i = 0; $i < $size; $i++) {
434            $shippingId = $this->objFormParam->getValue('multiple_shipping' . $i);
435            $productClassId = $this->objFormParam->getValue('multiple_product_class_id' . $i);
436
437            $name = $this->objFormParam->getValue('multiple_product_name' . $i);
438            $code = $this->objFormParam->getValue('multiple_product_code' . $i);
439            $class1 = $this->objFormParam->getValue('multiple_classcategory_name1' . $i);
440            $class2 = $this->objFormParam->getValue('multiple_classcategory_name2' . $i);
441            $price = $this->objFormParam->getValue('multiple_price' . $i);
442            $quantity = $this->objFormParam->getValue('multiple_quantity' . $i);
443
444            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['shipping_id'] = $shippingId;
445            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_class_id'] = $productClassId;
446            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_name'] = $name;
447            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_code'] = $code;
448            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['classcategory_name1'] = $class1;
449            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['classcategory_name2'] = $class2;
450            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['price'] = $price;
451            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['quantity'] += $quantity;
452        }
453
454        $arrQuantity = array();
455        $this->arrShippingIds = array();
456        $this->arrProductClassIds = array();
457        foreach ($this->arrShipping as $shippingId => $items) {
458
459            $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shippingId, count($items['shipment_item']));
460
461            $this->arrShippingIds[] = $shippingId;
462            $this->arrProductClassIds[] = array_keys($items['shipment_item']);
463
464            foreach ($items['shipment_item'] as $productClassId => $item) {
465                $arrQuantity[$productClassId] += $item['quantity'];
466                foreach ($item as $itemKey => $itemVal) {
467                    $arrParam[$itemKey . '_' . $shippingId . '_' . $productClassId] = $itemVal;
468                    $this->objFormParam->setValue($itemKey . '_' . $shippingId . '_' . $productClassId, $itemVal);
469                    $this->arrForm[$itemKey . '_' . $shippingId . '_' . $productClassId]['value'] = $itemVal;
470                }
471            }
472        }
473
474        // 受注商品の数量を変更
475        $dest = array();
476        foreach ($arrQuantity as $productClassId => $quantity) {
477            foreach ($this->arrForm['product_class_id'] as $n => $orderProductClassId) {
478                if ($productClassId == $orderProductClassId) {
479                    $dest['quantity'][$n] = $quantity;
480                }
481            }
482        }
483
484        // $this->arrShipping の内容で, 再度パラメータを初期化する
485        $this->lfInitShippingParam($this->arrShipping);
486        $this->objFormParam->setParam($arrParam);
487        $this->objFormParam->setParam($dest);
488    }
489
490    function lfGetOrderData($order_id) {
491        if(SC_Utils_Ex::sfIsInt($order_id)) {
492            // DBから受注情報を読み込む
493            $objQuery = new SC_Query();
494            $objDb = new SC_Helper_DB_Ex();
495            $where = "order_id = ?";
496            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
497            $this->objFormParam->setParam($arrRet[0]);
498            list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
499            $this->objFormParam->setValue('total_point', $db_point);
500            $this->objFormParam->setValue('point', $rollback_point);
501            $this->arrForm = $arrRet[0];
502
503            // 受注詳細データの取得
504            $arrRet = $this->lfGetOrderDetail($order_id);
505            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
506            $this->arrForm = array_merge($this->arrForm, $arrRet);
507            $this->objFormParam->setParam($arrRet);
508
509            $this->arrShipping = $this->lfGetShippingData($order_id);
510            $this->lfInitShippingParam($this->arrShipping);
511
512            $this->objFormParam->setValue('shipping_quantity', count($this->arrShipping));
513
514            // 配送情報の処理
515            foreach ($this->arrShipping as $shipping) {
516
517                $this->arrShippingIds[] = $shipping['shipping_id'];
518                $this->arrProductClassIds[] = array_keys($shipping['shipment_item']);
519
520                // お届け日の取得
521                if (!SC_Utils_Ex::isBlank($shipping["shipping_date"])) {
522                    $ts = strtotime($shipping["shipping_date"]);
523                    $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts));
524                    $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts));
525                    $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts));
526                }
527
528                // 配送内容の処理
529                foreach ($shipping as $shippingKey => $shippingVal) {
530
531                    $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal);
532
533                    $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'], count($shipping['shipment_item']));
534
535                    // 配送商品の処理
536                    foreach ($shipping['shipment_item'] as $productClassId => $item) {
537                        foreach ($item as $itemKey => $itemVal) {
538                            $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal);
539                            $this->arrForm[$itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId]['value'] = $itemVal;
540                        }
541                    }
542                }
543            }
544
545            // その他支払い情報を表示
546            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
547            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
548                $this->arrForm["payment_type"] = "クレジット決済";
549            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
550                $this->arrForm["payment_type"] = "コンビニ決済";
551            }else{
552                $this->arrForm["payment_type"] = "お支払い";
553            }
554            // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため)
555            $this->arrDisp = $this->arrForm;
556        } else {
557            $this->lfInitShippingParam($this->arrShipping);
558            $this->objFormParam->setParam($_POST);
559        }
560    }
561
562    // 受注詳細データの取得
563    function lfGetOrderDetail($order_id) {
564        $objQuery = new SC_Query();
565        $col = "T1.product_id, T1.product_class_id, T1.product_name, "
566            . "T1.product_code, T1.classcategory_name1, T1.classcategory_name2, "
567            . "T1.price, T1.quantity, T1.point_rate, T2.product_type_id";
568        $from = <<< __EOS__
569                 dtb_order_detail T1
570            JOIN dtb_products_class T2
571               ON T1.product_class_id = T2.product_class_id
572__EOS__;
573        $arrRet = $objQuery->select($col, $from,
574                                    "order_id = ?", array($order_id));
575        return $arrRet;
576    }
577
578    /**
579     * 配送情報の取得.
580     * TODO リファクタリング
581     */
582    function lfGetShippingData($orderId) {
583        $objQuery =& SC_Query::getSingletonInstance();
584        $objProduct = new SC_Product();
585        $objQuery->setOrder('shipping_id');
586        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId));
587        foreach (array_keys($arrRet) as $key) {
588            $objQuery->setOrder('shipping_id');
589            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
590                                          array($orderId, $arrRet[$key]['shipping_id']));
591            foreach ($arrItems as $itemKey => $arrDetail) {
592                foreach ($arrDetail as $detailKey => $detailVal) {
593                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
594                }
595
596                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
597            }
598        }
599        return $arrRet;
600    }
601
602    /* 入力内容のチェック */
603    function lfCheckError() {
604        // 入力データを渡す。
605        $arrRet =  $this->objFormParam->getHashArray();
606        $objErr = new SC_CheckError($arrRet);
607        $objErr->arrErr = $this->objFormParam->checkError();
608
609        if (count($objErr->arrErr) >= 1) {
610            return $objErr->arrErr;
611        }
612
613        return $this->lfCheek();
614    }
615
616    /* 計算処理 */
617    function lfCheek() {
618        $objDb = new SC_Helper_DB_Ex();
619        $arrVal = $this->objFormParam->getHashArray();
620        $arrErr = array();
621
622        // 商品の種類数
623        $max = count($arrVal['quantity']);
624        $subtotal = 0;
625        $totalpoint = 0;
626        $totaltax = 0;
627        for($i = 0; $i < $max; $i++) {
628            // 小計の計算
629            $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
630            // 小計の計算
631            $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
632            // 加算ポイントの計算
633            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
634        }
635
636        // 消費税
637        $arrVal['tax'] = $totaltax;
638        // 小計
639        $arrVal['subtotal'] = $subtotal;
640        // 合計
641        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
642        // お支払い合計
643        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
644
645        // 加算ポイント
646        $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']);
647
648        // 最終保持ポイント
649        $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point'];
650
651        if ($arrVal['total'] < 0) {
652            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
653        }
654
655        if ($arrVal['payment_total'] < 0) {
656            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
657        }
658        //新規追加受注のみ TODO 要リファクタリング(MODE if利用)
659        if ($this->getMode() == "add") {
660            if ($arrVal['total_point'] < 0) {
661                $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
662            }
663        }
664
665        $this->objFormParam->setParam($arrVal);
666        return $arrErr;
667    }
668
669    /**
670     * DB更新処理
671     *
672     * TODO リファクタリング
673     *
674     * @param integer $order_id 注文番号
675     * @return void
676     */
677    function lfRegistData($order_id, &$objPurchase) {
678        $objQuery = new SC_Query();
679
680        $sqlval = $this->lfMakeSqlvalForDtbOrder();
681
682        $where = "order_id = ?";
683
684        $objQuery->begin();
685
686        // 受注.対応状況の更新
687        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point'], $sqlval);
688
689        // 受注テーブルの更新
690        $this->registerOrder($sqlval, $order_id);
691
692        // 受注テーブルの名称列を更新
693        //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
694
695        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
696
697
698        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算
699        $max = count($arrDetail);
700        $k = 0;
701        $arrStockData = array();
702        for($i = 0; $i < $max; $i++) {
703            if (!empty($arrDetail[$i]['product_id'])) {
704                $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
705                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) {
706                    // 数量が変更された商品
707                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
708                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity'];
709                    ++$k;
710                } elseif (empty($arrPreDetail)) {
711                    // 新しく追加された商品 もしくは 違う商品に変更された商品
712                    $arrStockData[$k]['product_class_id'] = $arrDetail[$i]['product_class_id'];
713                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity'];
714                    ++$k;
715                }
716                $objQuery->delete("dtb_order_detail", "order_id = ? AND product_class_id = ?", array($order_id, $arrDetail[$i]['product_class_id']));
717            }
718        }
719
720        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品
721        $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id));
722        foreach ($arrPreDetail AS $key=>$val) {
723            $arrStockData[$k]['product_class_id'] = $val['product_class_id'];
724            $arrStockData[$k]['quantity'] = $val['quantity'];
725            ++$k;
726        }
727
728        // 受注詳細データの初期化
729        $objQuery->delete("dtb_order_detail", $where, array($order_id));
730
731        // 受注詳細データの更新
732        $max = count($arrDetail);
733        for ($i = 0; $i < $max; $i++) {
734            $sqlval = array();
735            $sqlval['order_id'] = $order_id;
736            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
737            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
738            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
739            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
740            $sqlval['price']  = $arrDetail[$i]['price'];
741            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
742            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
743            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
744            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
745            $objQuery->insert("dtb_order_detail", $sqlval);
746        }
747
748        // 在庫数調整
749        $status = $sqlval['status'];
750        if (ORDER_DELIV != $status && ORDER_CANCEL != $status) {
751            $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_class_id = ?";
752            foreach ($arrStockData AS $key=>$val) {
753                $stock_sqlval = array();
754                $stock_sqlval[] = $val['quantity'];
755                $stock_sqlval[] = $val['product_class_id'];
756
757                $objQuery->query($stock_sql, $stock_sqlval);
758            }
759        }
760
761        // 配送情報の初期化
762        // FIXME UPDATE/INSERT にする
763        $objQuery->delete('dtb_shipping', "order_id = ?", array($order_id));
764        $objQuery->delete('dtb_shipment_item', "order_id = ?", array($order_id));
765
766        //        $arrParams = $this->objFormParam->getHashArray();
767        $arrParams = $_POST;
768        // 配送ID の配列を取得
769        $shippingIds = array();
770        foreach (array_keys($arrParams) as $key) {
771            if (preg_match('/^shipping_id_/', $key)) {
772                $shippingIds[] = $arrParams[$key];
773            }
774        }
775
776        $cols = $objQuery->listTableFields('dtb_shipping');
777
778        foreach ($shippingIds as $shipping_id) {
779
780            $arrParams['shipping_date_' .  $shipping_id] = SC_Utils_Ex::sfGetTimestamp($arrParams['shipping_date_year_' . $shipping_id],
781                                                                                       $arrParams['shipping_date_month_' . $shipping_id],
782                                                                                       $arrParams['shipping_date_day_' . $shipping_id]);
783            $dest = array();
784            foreach ($arrParams as $key => $val) {
785                $key = preg_replace('/_' . $shipping_id . '$/', '', $key);
786                if (in_array($key, $cols)) {
787                    $dest[$key] = $val;
788                }
789            }
790
791            if (SC_Utils::isBlank($dest['deliv_id'])) {
792                // XXX 商品種別IDは0番目の配列を使用
793                $product_type_id = $this->objFormParam->getValue('product_type_id');
794                $dest['deliv_id'] = $objPurchase->getDeliv($product_type_id[0]);
795            }
796
797            $dest['shipping_id'] = $shipping_id;
798            $dest['order_id'] = $order_id;
799            $dest['create_date'] = 'Now()';
800            $dest['update_date'] = 'Now()';
801            $objQuery->insert('dtb_shipping', $dest);
802
803            // 商品規格ID の配列を取得
804            $productClassIds = array();
805            foreach (array_keys($arrParams) as $key) {
806                if (preg_match('/^product_class_id_' . $shipping_id . '_/', $key)) {
807                    $productClassIds[] = $arrParams[$key];
808                }
809            }
810
811            foreach ($productClassIds as $product_class_id) {
812                $item['shipping_id'] = $shipping_id;
813                $item['order_id'] = $order_id;
814                $item['product_class_id'] = $product_class_id;
815                $item['product_name'] = $arrParams['product_name_' . $shipping_id . '_' . $product_class_id];
816                $item['product_code'] = $arrParams['product_code_' . $shipping_id . '_' . $product_class_id];
817                $item['classcategory_name1'] = $arrParams['classcategory_name1_' . $shipping_id . '_' . $product_class_id];
818                $item['classcategory_name2'] = $arrParams['classcategory_name2_' . $shipping_id . '_' . $product_class_id];
819                $item['price'] = $arrParams['price_' . $shipping_id . '_' . $product_class_id];
820                $item['quantity'] = $arrParams['quantity_' . $shipping_id . '_' . $product_class_id];
821                $objQuery->insert("dtb_shipment_item", $item);
822            }
823        }
824        $objQuery->commit();
825    }
826
827    /**
828     * DB登録処理
829     *
830     * @return integer 注文番号
831     */
832    function lfRegistNewData(&$objPurchase) {
833        $objQuery = new SC_Query();
834
835        $sqlval = $this->lfMakeSqlvalForDtbOrder();
836
837        // ポイントは別登録
838        $addPoint = $sqlval['add_point'];
839        $usePoint = $sqlval['use_point'];
840        $sqlval['add_point'] = 0;
841        $sqlval['use_point'] = 0;
842
843        // customer_id
844        if ($sqlval["customer_id"] == "") {
845            $sqlval['customer_id'] = '0';
846        }
847
848        $sqlval['create_date'] = 'Now()';       // 受注日
849
850        $objQuery->begin();
851
852        // 受注テーブルの登録
853        $order_id = $objQuery->nextVal('dtb_order_order_id');
854        $sqlval['order_id'] = $order_id;
855        $this->registerOrder($sqlval, $order_id);
856
857        // 受注.対応状況の更新
858        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint);
859
860        // 受注テーブルの名称列を更新
861        //SC_Helper_DB_Ex::sfUpdateOrderNameCol($order_id);
862
863        // 受注詳細データの更新
864        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_class_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_name1", "classcategory_name2"));
865        $objQuery->delete("dtb_order_detail", 'order_id = ?', array($order_id));
866
867        $max = count($arrDetail);
868        for ($i = 0; $i < $max; $i++) {
869            $sqlval = array();
870            $sqlval['order_id'] = $order_id;
871            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
872            $sqlval['product_class_id']  = $arrDetail[$i]['product_class_id'];
873            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
874            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
875            $sqlval['price']  = $arrDetail[$i]['price'];
876            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
877            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
878            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
879            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
880
881            $objQuery->insert("dtb_order_detail", $sqlval);
882
883
884            // 在庫数減少処理
885            // 現在の実在庫数取得
886            $pre_stock = $objQuery->getOne("SELECT stock FROM dtb_products_class WHERE product_class_id = ?", array($arrDetail[$i]['product_class_id']));
887
888            $stock_sqlval = array();
889            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']);
890            if ($stock_sqlval['stock'] === 0) {
891                $stock_sqlval['stock'] = '0';
892            }
893
894            $st_params = array();
895            $st_params[] = $arrDetail[$i]['product_class_id'];
896
897            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_class_id = ?', $st_params);
898        }
899
900        $arrParams = $this->objFormParam->getHashArray();
901        // 配送ID の配列を取得
902        $shippingIds = array();
903        foreach (array_keys($arrParams) as $key) {
904            if (preg_match('/^shipping_id_/', $key)) {
905                $shippingIds[] = $arrParams[$key];
906            }
907        }
908
909        $cols = $objQuery->listTableFields('dtb_shipping');
910        foreach ($shippingIds as $shipping_id) {
911
912            $arrParams['shipping_date_' .  $shipping_id] = SC_Utils_Ex::sfGetTimestamp($arrParams['shipping_date_year_' . $shipping_id],
913                                                                                       $arrParams['shipping_date_month_' . $shipping_id],
914                                                                                       $arrParams['shipping_date_day_' . $shipping_id]);
915            $dest = array();
916            foreach ($arrParams as $key => $val) {
917                $key = preg_replace('/_' . $shipping_id . '$/', '', $key);
918                if (in_array($key, $cols)) {
919                    $dest[$key] = $val;
920                }
921            }
922            if (SC_Utils::isBlank($dest['deliv_id'])) {
923                // XXX 商品種別IDは0番目の配列を使用
924                $product_type_id = $this->objFormParam->getValue('product_type_id');
925                $dest['deliv_id'] = $objPurchase->getDeliv($product_type_id[0]);
926            }
927
928            $dest['shipping_id'] = $shipping_id;
929            $dest['order_id'] = $order_id;
930            $dest['create_date'] = 'Now()';
931            $dest['update_date'] = 'Now()';
932            $objQuery->insert('dtb_shipping', $dest);
933
934            // 商品規格ID の配列を取得
935            $productClassIds = array();
936            foreach (array_keys($arrParams) as $key) {
937                if (preg_match('/^product_class_id_' . $shipping_id . '_/', $key)) {
938                    $productClassIds[] = $arrParams[$key];
939                }
940            }
941
942            foreach ($productClassIds as $product_class_id) {
943                $item['shipping_id'] = $shipping_id;
944                $item['order_id'] = $order_id;
945                $item['product_class_id'] = $product_class_id;
946                $item['product_name'] = $arrParams['product_name_' . $shipping_id . '_' . $product_class_id];
947                $item['product_code'] = $arrParams['product_code_' . $shipping_id . '_' . $product_class_id];
948                $item['classcategory_name1'] = $arrParams['classcategory_name1_' . $shipping_id . '_' . $product_class_id];
949                $item['classcategory_name2'] = $arrParams['classcategory_name2_' . $shipping_id . '_' . $product_class_id];
950                $item['price'] = $arrParams['price_' . $shipping_id . '_' . $product_class_id];
951                $item['quantity'] = $arrParams['quantity_' . $shipping_id . '_' . $product_class_id];
952                $objQuery->insert("dtb_shipment_item", $item);
953            }
954        }
955
956        $objQuery->commit();
957
958        return $order_id;
959    }
960
961    /**
962     * 受注を登録する
963     */
964    function registerOrder($sqlval, $order_id) {
965        $table = 'dtb_order';
966        $objQuery = SC_Query::getSingletonInstance();
967        $cols = $objQuery->listTableFields($table);
968        $dest = array();
969        foreach ($sqlval as $key => $val) {
970            if (in_array($key, $cols)) {
971                $dest[$key] = $val;
972            }
973        }
974
975        $exists = $objQuery->count("dtb_order", "order_id = ?", array($order_id));
976        if ($exists > 0) {
977            $objQuery->update($table, $dest, "order_id = ?", array($order_id));
978        } else {
979            $dest['order_id'] = $order_id;
980            $result = $objQuery->insert($table, $dest);
981        }
982    }
983
984    function lfInsertProduct($product_class_id) {
985        $objProduct = new SC_Product();
986        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
987        $this->arrForm = $this->objFormParam->getFormParamList();
988        $existes = false;
989        $existes_key = NULL;
990        // 既に同じ商品がないか、確認する
991        if (!empty($this->arrForm['product_class_id']['value'])) {
992            foreach ($this->arrForm['product_class_id']['value'] AS $key=>$val) {
993                // 既に同じ商品がある場合
994                if ($val == $product_class_id) {
995                    $existes = true;
996                    $existes_key = $key;
997                }
998            }
999        }
1000
1001        if ($existes) {
1002            // 既に同じ商品がある場合
1003            ++$this->arrForm['quantity']['value'][$existes_key];
1004        } else {
1005            // 既に同じ商品がない場合
1006            $this->lfSetProductData($arrProduct);
1007        }
1008    }
1009
1010    function lfUpdateProduct($product_class_id, $no) {
1011        $objProduct = new SC_Product();
1012        $arrProduct = $this->lfGetProductsClass($objProduct->getDetailAndProductsClass($product_class_id));
1013        $this->arrForm = $this->objFormParam->getFormParamList();
1014        $this->lfSetProductData($arrProduct, $no);
1015    }
1016
1017    function lfSetProductData($arrProduct, $no = null) {
1018        foreach ($arrProduct AS $key=>$val) {
1019            if (!is_array($this->arrForm[$key]['value'])) {
1020                unset($this->arrForm[$key]['value']);
1021            }
1022            if ($no === null) {
1023                $this->arrForm[$key]['value'][] = $val;
1024            } else {
1025                $this->arrForm[$key]['value'][$no] = $val;
1026            }
1027        }
1028    }
1029
1030    function lfGetProductsClass($productsClass) {
1031        $arrProduct['price'] = $productsClass['price02'];
1032        $arrProduct['quantity'] = 1;
1033        $arrProduct['product_id'] = $productsClass['product_id'];
1034        $arrProduct['product_class_id'] = $productsClass['product_class_id'];
1035        $arrProduct['product_type_id'] = $productsClass['product_type_id'];
1036        $arrProduct['point_rate'] = $productsClass['point_rate'];
1037        $arrProduct['product_code'] = $productsClass['product_code'];
1038        $arrProduct['product_name'] = $productsClass['name'];
1039        $arrProduct['classcategory_name1'] = $productsClass['classcategory_name1'];
1040        $arrProduct['classcategory_name2'] = $productsClass['classcategory_name2'];
1041        return $arrProduct;
1042    }
1043
1044
1045    /**
1046     * 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
1047     * @param int $edit_customer_id 顧客ID
1048     */
1049    function lfSetCustomerInfo($edit_customer_id = ""){
1050        // 顧客IDが指定されている場合のみ、処理を実行する
1051        if( $edit_customer_id === "" ) return ;
1052
1053        // 検索で選択された顧客IDが入力されている場合
1054        if( is_null($edit_customer_id) === false && 0 < strlen($edit_customer_id) && SC_Utils_Ex::sfIsInt($edit_customer_id) ){
1055            $objQuery = new SC_Query();
1056
1057            // 顧客情報を取得する
1058            $arrCustomerInfo = $objQuery->select('*', 'dtb_customer', 'customer_id = ? AND del_flg = 0', array($edit_customer_id));
1059
1060            // 顧客情報を取得する事が出来たら、テンプレートに値を渡す
1061            if( 0 < count($arrCustomerInfo) && is_array($arrCustomerInfo) === true){
1062                // カラム名にorder_を付ける(テンプレート側でorder_がついている為
1063                foreach($arrCustomerInfo[0] as $index=>$customer_info){
1064                    // customer_idにはorder_を付けないようにする
1065                    $order_index = ($index == 'customer_id') ? $index : 'order_'.$index;
1066                    $arrCustomer[$order_index] = $customer_info;
1067                }
1068            }
1069
1070            // hiddenに渡す
1071            $this->edit_customer_id = $edit_customer_id;
1072
1073            // 受注日に現在の時刻を取得し、表示させる
1074            $create_date = $objQuery->getAll('SELECT now() as create_date;');
1075            $arrCustomer['create_date'] = $create_date[0]['create_date'];
1076
1077            // 情報上書き
1078            $this->objFormParam->setParam($arrCustomer);
1079            // 入力値の変換
1080            $this->objFormParam->convParam();
1081        }
1082    }
1083
1084    /**
1085     * 受注テーブルの登録・更新用データの共通部分を作成する
1086     *
1087     * @return array
1088     */
1089    function lfMakeSqlvalForDtbOrder() {
1090
1091        // 入力データを取得する
1092        $sqlval = $this->objFormParam->getHashArray();
1093        foreach ($sqlval as $key => $val) {
1094            // 配列は登録しない
1095            if (is_array($val)) {
1096                unset($sqlval[$key]);
1097            }
1098        }
1099
1100        // 受注テーブルに書き込まない列を除去
1101        unset($sqlval['total_point']);
1102        unset($sqlval['point']);
1103        unset($sqlval['commit_date']);
1104
1105        // 更新日時
1106        $sqlval['update_date'] = 'Now()';
1107
1108        return $sqlval;
1109    }
1110}
1111?>
Note: See TracBrowser for help on using the repository browser.