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

Revision 19963, 51.7 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        if (!SC_Utils_Ex::isBlank($order_id)) {
120            $this->lfGetOrderData($order_id);
121        }
122
123        switch($_POST['mode']) {
124        case 'pre_edit':
125        case 'order_id':
126            break;
127        case 'edit':
128        case 'add':
129            // POST情報で上書き
130            $this->objFormParam->setParam($_POST);
131
132            // 入力値の変換
133            $this->objFormParam->convParam();
134            $this->arrErr = $this->lfCheckError();
135
136            if(count($this->arrErr) == 0) {
137                if ($_POST['mode'] == 'add') {
138                    $order_id = $this->lfRegistNewData($objPurchase);
139
140                    $this->tpl_order_id = $order_id;
141                    $this->tpl_mode = 'edit';
142
143                    $arrData['order_id'] = $order_id;
144                    $this->objFormParam->setParam($arrData);
145
146                    $text = "'新規受注を登録しました。'";
147                } else {
148                    $this->lfRegistData($_POST['order_id'], $objPurchase);
149                    $text = "'受注履歴を編集しました。'";
150                }
151                // DBから受注情報を再読込
152                $this->lfGetOrderData($order_id);
153                $this->lfInitShippingParam($this->arrShipping);
154                $this->objFormParam->setParam($_POST);
155                $this->tpl_onload = "window.alert(".$text.");";
156            }
157            break;
158        // 再計算
159        case 'cheek':
160        //支払い方法の選択
161        case 'payment':
162            // POST情報で上書き
163            $this->lfInitShippingParam($this->arrShipping);
164            $this->objFormParam->setParam($_POST);
165            // 入力値の変換
166            $this->objFormParam->convParam();
167            $this->arrErr = $this->lfCheckError();
168            break;
169
170        /* 商品削除*/
171        case 'delete_product':
172            $delete_no = $_POST['delete_no'];
173            foreach ($_POST AS $key=>$val) {
174                if (is_array($val)) {
175                    foreach ($val AS $k=>$v) {
176                        if ($k != $delete_no) {
177                            $arrData[$key][] = $v;
178                        }
179                    }
180                } else {
181                    $arrData[$key] = $val;
182                }
183            }
184            // 情報上書き
185            $this->lfInitShippingParam($this->arrShipping);
186            $this->objFormParam->setParam($arrData);
187            // 入力値の変換
188            $this->objFormParam->convParam();
189            $this->arrErr = $this->lfCheckError();
190            break;
191        /* 商品追加ポップアップより商品選択後、商品情報取得*/
192        case 'select_product_detail':
193            // POST情報で上書き
194            $this->objFormParam->setParam($_POST);
195            if (!empty($_POST['add_product_class_id'])) {
196                $this->lfInsertProduct($_POST['add_product_class_id']);
197            } elseif (!empty($_POST['edit_product_class_id'])) {
198                $this->lfUpdateProduct($_POST['edit_product_class_id'], $_POST['no']);
199            }
200            $arrData = $_POST;
201            foreach ($this->arrForm AS $key=>$val) {
202                if (is_array($val)) {
203                    $arrData[$key] = $this->arrForm[$key]['value'];
204                } else {
205                    $arrData[$key] = $val;
206                }
207            }
208
209            // 情報上書き
210            $this->lfInitShippingParam($this->arrShipping);
211            $this->objFormParam->setParam($arrData);
212            // 入力値の変換
213            $this->objFormParam->convParam();
214            $this->arrErr = $this->lfCheckError();
215            break;
216        /* 顧客検索ポップアップより顧客指定後、顧客情報取得*/
217        case 'search_customer':
218            // POST情報で上書き
219            $this->lfInitShippingParam($this->arrShipping);
220            $this->objFormParam->setParam($_POST);
221
222            // 検索結果から顧客IDを指定された場合、顧客情報をフォームに代入する
223            $this->lfSetCustomerInfo($_POST['edit_customer_id']);
224
225            break;
226
227        // 複数配送設定表示
228        case 'multiple':
229            $this->lfInitShippingParam($this->arrShipping);
230            $this->objFormParam->setParam($_POST);
231            // 入力値の変換
232            $this->objFormParam->convParam();
233            $this->arrErr = $this->lfCheckError();
234            break;
235
236        // 複数配送設定を反映
237        case 'multiple_set_to':
238            $multipleSize = $_POST['multiple_size'];
239            $this->lfInitMultipleParam($multipleSize);
240            $this->objFormParam->setParam($_POST);
241            $this->lfInitShippingParam($this->arrShipping);
242            $this->setMultipleItemTo($multipleSize);
243            break;
244
245        // お届け先の追加
246        case 'append_shipping':
247            $this->lfInitShippingParam($this->arrShipping, true);
248            $this->objFormParam->setParam($_POST);
249            // 入力値の変換
250            $this->objFormParam->convParam();
251            break;
252
253        default:
254            // お届け先の初期表示
255            $this->lfInitShippingParam();
256            break;
257        }
258
259        // 支払い方法の取得
260        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
261
262        $this->arrForm = $this->objFormParam->getFormParamList();
263
264        // XXX 商品種別IDは0番目の配列を使用
265        $this->product_type_id = $this->arrForm['product_type_id']['value'][0];
266        $this->arrDelivTime = $objPurchase->getDelivTime($this->product_type_id);
267        $this->product_count = count($this->arrForm['quantity']['value']);
268
269        // アンカーを設定
270        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
271            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
272        } else {
273            $anchor_hash = "";
274        }
275        $this->tpl_onload .= $anchor_hash;
276
277        $objSiteInfo = new SC_SiteInfo();
278        $this->arrInfo = $objSiteInfo->data;
279        // 表示モード判定
280        if(!$this->disp_mode) {
281            $this->setTemplate(MAIN_FRAME);
282        } else {
283            $this->setTemplate('order/disp.tpl');
284        }
285    }
286
287    /**
288     * デストラクタ.
289     *
290     * @return void
291     */
292    function destroy() {
293        parent::destroy();
294    }
295
296    /* パラメータ情報の初期化 */
297    function lfInitParam() {
298
299        // お客様情報
300        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
301        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
302        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
303        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
304        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
305        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
306        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
307        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
308        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
309        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
310        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
311        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
312        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
313
314        // 受注商品情報
315        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
316        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
317        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
318
319        // ポイント機能ON時のみ
320        if (USE_POINT !== false) {
321            $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
322        }
323
324        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
325        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
326        $this->objFormParam->addParam("お支払方法名称", "payment_method");
327
328        // 受注詳細情報
329        $this->objFormParam->addParam("商品種別ID", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
330        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
331        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
332        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
333        $this->objFormParam->addParam("商品規格ID", "product_class_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
334        $this->objFormParam->addParam("ポイント付与率", "point_rate");
335        $this->objFormParam->addParam("商品コード", "product_code");
336        $this->objFormParam->addParam("商品名", "product_name");
337        $this->objFormParam->addParam("規格名1", "classcategory_name1");
338        $this->objFormParam->addParam("規格名2", "classcategory_name2");
339        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
340        // DB読込用
341        $this->objFormParam->addParam("小計", "subtotal");
342        $this->objFormParam->addParam("合計", "total");
343        $this->objFormParam->addParam("支払い合計", "payment_total");
344        $this->objFormParam->addParam("加算ポイント", "add_point");
345        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
346        $this->objFormParam->addParam("消費税合計", "tax");
347        $this->objFormParam->addParam("最終保持ポイント", "total_point");
348        $this->objFormParam->addParam("顧客ID", "customer_id");
349        $this->objFormParam->addParam("現在のポイント", "point");
350        $this->objFormParam->addParam("注文番号", "order_id");
351        $this->objFormParam->addParam("受注日", "create_date");
352        $this->objFormParam->addParam("発送日", "commit_date");
353        $this->objFormParam->addParam("備考", "message");
354        $this->objFormParam->addParam("入金日", "payment_date");
355    }
356
357    /**
358     * お届け先用フォームの初期化
359     */
360    function lfInitShippingParam($arrShipping = array(), $add = false) {
361        if (empty($arrShipping) && !$add) {
362            $arrShipping[0]['shipping_id'] = 0;
363            $this->arrShippingIds[0] = 0;
364            $_POST['shipping_quantity'] = 1;
365        }
366
367        if ($add) {
368            $_POST['shipping_quantity'] = $_POST['shipping_quantity'] + 1;
369        }
370        for ($i = 0; $i < $_POST['shipping_quantity']; $i++) {
371            $arrShipping[$i]['shipping_id'] = $i;
372            $this->arrShippingIds[$i] = $i;
373        }
374
375        $this->objFormParam->addParam("配送数", "shipping_quantity", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
376        $this->objFormParam->setValue('shipping_quantity', $_POST['shipping_quantity']);
377
378        foreach ($arrShipping as $shipping) {
379            $this->objFormParam->addParam("配送ID", "shipping_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), 0);
380            $this->objFormParam->addParam("お名前1", "shipping_name01_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
381            $this->objFormParam->addParam("お名前2", "shipping_name02_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
382            $this->objFormParam->addParam("お名前(フリガナ・姓)", "shipping_kana01_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
383            $this->objFormParam->addParam("お名前(フリガナ・名)", "shipping_kana02_" . $shipping['shipping_id'], STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
384            $this->objFormParam->addParam("郵便番号1", "shipping_zip01_" . $shipping['shipping_id'], ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
385            $this->objFormParam->addParam("郵便番号2", "shipping_zip02_" . $shipping['shipping_id'], ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
386            $this->objFormParam->addParam("都道府県", "shipping_pref_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
387            $this->objFormParam->addParam("住所1", "shipping_addr01_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
388            $this->objFormParam->addParam("住所2", "shipping_addr02_" . $shipping['shipping_id'], MTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
389            $this->objFormParam->addParam("電話番号1", "shipping_tel01_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
390            $this->objFormParam->addParam("電話番号2", "shipping_tel02_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
391            $this->objFormParam->addParam("電話番号3", "shipping_tel03_" . $shipping['shipping_id'], TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
392            $this->objFormParam->addParam("お届け時間ID", "time_id_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
393            $this->objFormParam->addParam("お届け時間", "shipping_time_" . $shipping['shipping_id']);
394            $this->objFormParam->addParam("お届け日(年)", "shipping_date_year_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
395            $this->objFormParam->addParam("お届け日(月)", "shipping_date_month_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
396            $this->objFormParam->addParam("お届け日(日)", "shipping_date_day_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
397            $this->objFormParam->addParam("お届け日", "shipping_date_" . $shipping['shipping_id'], STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
398            $this->objFormParam->addParam("配送商品規格数", "shipping_product_quantity_" . $shipping['shipping_id'], INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
399            foreach (array_keys($shipping['shipment_item']) as $productClassId) {
400                $this->objFormParam->addParam("商品規格ID", "product_class_id_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
401                $this->objFormParam->addParam("商品コード", "product_code_" . $shipping['shipping_id'] . '_' . $productClassId, $item['product_code']);
402                $this->objFormParam->addParam("商品名", "product_name_" . $shipping['shipping_id'] . '_' . $productClassId);
403                $this->objFormParam->addParam("規格名1", "classcategory_name1_" . $shipping['shipping_id'] . '_' . $productClassId);
404                $this->objFormParam->addParam("規格名2", "classcategory_name2_" . $shipping['shipping_id'] . '_' . $productClassId);
405                $this->objFormParam->addParam("単価", "price_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
406                $this->objFormParam->addParam("数量", "quantity_" . $shipping['shipping_id'] . '_' . $productClassId, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
407            }
408        }
409    }
410
411    /**
412     * 複数配送用フォームの初期化
413     */
414    function lfInitMultipleParam($size) {
415        for ($i = 0; $i < $size; $i++) {
416            $this->objFormParam->addParam("商品規格ID", "multiple_product_class_id" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
417            $this->objFormParam->addParam("商品コード", "multiple_product_code" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
418            $this->objFormParam->addParam("商品名", "multiple_product_name" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
419            $this->objFormParam->addParam("規格1", "multiple_classcategory_name1" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
420            $this->objFormParam->addParam("規格2", "multiple_classcategory_name2" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
421            $this->objFormParam->addParam("単価", "multiple_price" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
422            $this->objFormParam->addParam("数量", "multiple_quantity" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
423            $this->objFormParam->addParam("配送先住所", "multiple_shipping" . $i, INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
424        }
425    }
426
427
428    function setMultipleItemTo($size) {
429        $arrShipmentItem = array();
430        for ($i = 0; $i < $size; $i++) {
431            $shippingId = $this->objFormParam->getValue('multiple_shipping' . $i);
432            $productClassId = $this->objFormParam->getValue('multiple_product_class_id' . $i);
433
434            $name = $this->objFormParam->getValue('multiple_product_name' . $i);
435            $code = $this->objFormParam->getValue('multiple_product_code' . $i);
436            $class1 = $this->objFormParam->getValue('multiple_classcategory_name1' . $i);
437            $class2 = $this->objFormParam->getValue('multiple_classcategory_name2' . $i);
438            $price = $this->objFormParam->getValue('multiple_price' . $i);
439            $quantity = $this->objFormParam->getValue('multiple_quantity' . $i);
440
441            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['shipping_id'] = $shippingId;
442            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_class_id'] = $productClassId;
443            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_name'] = $name;
444            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['product_code'] = $code;
445            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['classcategory_name1'] = $class1;
446            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['classcategory_name2'] = $class2;
447            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['price'] = $price;
448            $this->arrShipping[$shippingId]['shipment_item'][$productClassId]['quantity'] += $quantity;
449        }
450
451        $arrQuantity = array();
452        $this->arrShippingIds = array();
453        $this->arrProductClassIds = array();
454        foreach ($this->arrShipping as $shippingId => $items) {
455
456            $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shippingId, count($items['shipment_item']));
457
458            $this->arrShippingIds[] = $shippingId;
459            $this->arrProductClassIds[] = array_keys($items['shipment_item']);
460
461            foreach ($items['shipment_item'] as $productClassId => $item) {
462                $arrQuantity[$productClassId] += $item['quantity'];
463                foreach ($item as $itemKey => $itemVal) {
464                    $arrParam[$itemKey . '_' . $shippingId . '_' . $productClassId] = $itemVal;
465                    $this->objFormParam->setValue($itemKey . '_' . $shippingId . '_' . $productClassId, $itemVal);
466                    $this->arrForm[$itemKey . '_' . $shippingId . '_' . $productClassId]['value'] = $itemVal;
467                }
468            }
469        }
470
471        // 受注商品の数量を変更
472        $dest = array();
473        foreach ($arrQuantity as $productClassId => $quantity) {
474            foreach ($this->arrForm['product_class_id'] as $n => $orderProductClassId) {
475                if ($productClassId == $orderProductClassId) {
476                    $dest['quantity'][$n] = $quantity;
477                }
478            }
479        }
480
481        // $this->arrShipping の内容で, 再度パラメータを初期化する
482        $this->lfInitShippingParam($this->arrShipping);
483        $this->objFormParam->setParam($arrParam);
484        $this->objFormParam->setParam($dest);
485    }
486
487    function lfGetOrderData($order_id) {
488        if(SC_Utils_Ex::sfIsInt($order_id)) {
489            // DBから受注情報を読み込む
490            $objQuery = new SC_Query();
491            $objDb = new SC_Helper_DB_Ex();
492            $where = "order_id = ?";
493            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
494            $this->objFormParam->setParam($arrRet[0]);
495            list($db_point, $rollback_point) = $objDb->sfGetRollbackPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
496            $this->objFormParam->setValue('total_point', $db_point);
497            $this->objFormParam->setValue('point', $rollback_point);
498            $this->arrForm = $arrRet[0];
499
500            // 受注詳細データの取得
501            $arrRet = $this->lfGetOrderDetail($order_id);
502            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
503            $this->arrForm = array_merge($this->arrForm, $arrRet);
504            $this->objFormParam->setParam($arrRet);
505
506            $this->arrShipping = $this->lfGetShippingData($order_id);
507            $this->lfInitShippingParam($this->arrShipping);
508
509            $this->objFormParam->setValue('shipping_quantity', count($this->arrShipping));
510
511            // 配送情報の処理
512            foreach ($this->arrShipping as $shipping) {
513
514                $this->arrShippingIds[] = $shipping['shipping_id'];
515                $this->arrProductClassIds[] = array_keys($shipping['shipment_item']);
516
517                // お届け日の取得
518                if (!SC_Utils_Ex::isBlank($shipping["shipping_date"])) {
519                    $ts = strtotime($shipping["shipping_date"]);
520                    $this->objFormParam->setValue('shipping_date_year_' . $shipping['shipping_id'], date("Y", $ts));
521                    $this->objFormParam->setValue('shipping_date_month_' . $shipping['shipping_id'], date("n", $ts));
522                    $this->objFormParam->setValue('shipping_date_day_' . $shipping['shipping_id'], date("j", $ts));
523                }
524
525                // 配送内容の処理
526                foreach ($shipping as $shippingKey => $shippingVal) {
527
528                    $this->objFormParam->setValue($shippingKey . '_' . $shipping['shipping_id'], $shippingVal);
529
530                    $this->objFormParam->setValue('shipping_product_quantity' . '_' . $shipping['shipping_id'], count($shipping['shipment_item']));
531
532                    // 配送商品の処理
533                    foreach ($shipping['shipment_item'] as $productClassId => $item) {
534                        foreach ($item as $itemKey => $itemVal) {
535                            $this->objFormParam->setValue($itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId, $itemVal);
536                            $this->arrForm[$itemKey . '_' . $shipping['shipping_id'] . '_' . $productClassId]['value'] = $itemVal;
537                        }
538                    }
539                }
540            }
541
542            // その他支払い情報を表示
543            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
544            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
545                $this->arrForm["payment_type"] = "クレジット決済";
546            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
547                $this->arrForm["payment_type"] = "コンビニ決済";
548            }else{
549                $this->arrForm["payment_type"] = "お支払い";
550            }
551            // 受注データを表示用配列に代入(各EC-CUBEバージョンと決済モジュールとのデータ連携保全のため)
552            $this->arrDisp = $this->arrForm;
553        } else {
554            $this->lfInitShippingParam($this->arrShipping);
555            $this->objFormParam->setParam($_POST);
556        }
557    }
558
559    // 受注詳細データの取得
560    function lfGetOrderDetail($order_id) {
561        $objQuery = new SC_Query();
562        $col = "T1.product_id, T1.product_class_id, T1.product_name, "
563            . "T1.product_code, T1.classcategory_name1, T1.classcategory_name2, "
564            . "T1.price, T1.quantity, T1.point_rate, T2.product_type_id";
565        $from = <<< __EOS__
566                 dtb_order_detail T1
567            JOIN dtb_products_class T2
568               ON T1.product_class_id = T2.product_class_id
569__EOS__;
570        $arrRet = $objQuery->select($col, $from,
571                                    "order_id = ?", array($order_id));
572        return $arrRet;
573    }
574
575    /**
576     * 配送情報の取得.
577     * TODO リファクタリング
578     */
579    function lfGetShippingData($orderId) {
580        $objQuery =& SC_Query::getSingletonInstance();
581        $objProduct = new SC_Product();
582        $objQuery->setOrder('shipping_id');
583        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($orderId));
584        foreach (array_keys($arrRet) as $key) {
585            $objQuery->setOrder('shipping_id');
586            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
587                                          array($orderId, $arrRet[$key]['shipping_id']));
588            foreach ($arrItems as $itemKey => $arrDetail) {
589                foreach ($arrDetail as $detailKey => $detailVal) {
590                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
591                }
592
593                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
594            }
595        }
596        return $arrRet;
597    }
598
599    /* 入力内容のチェック */
600    function lfCheckError() {
601        // 入力データを渡す。
602        $arrRet =  $this->objFormParam->getHashArray();
603        $objErr = new SC_CheckError($arrRet);
604        $objErr->arrErr = $this->objFormParam->checkError();
605
606        if (count($objErr->arrErr) >= 1) {
607            return $objErr->arrErr;
608        }
609
610        return $this->lfCheek();
611    }
612
613    /* 計算処理 */
614    function lfCheek() {
615        $objDb = new SC_Helper_DB_Ex();
616        $arrVal = $this->objFormParam->getHashArray();
617        $arrErr = array();
618
619        // 商品の種類数
620        $max = count($arrVal['quantity']);
621        $subtotal = 0;
622        $totalpoint = 0;
623        $totaltax = 0;
624        for($i = 0; $i < $max; $i++) {
625            // 小計の計算
626            $subtotal += SC_Helper_DB_Ex::sfCalcIncTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
627            // 小計の計算
628            $totaltax += SC_Helper_DB_Ex::sfTax($arrVal['price'][$i]) * $arrVal['quantity'][$i];
629            // 加算ポイントの計算
630            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
631        }
632
633        // 消費税
634        $arrVal['tax'] = $totaltax;
635        // 小計
636        $arrVal['subtotal'] = $subtotal;
637        // 合計
638        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
639        // お支払い合計
640        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
641
642        // 加算ポイント
643        $arrVal['add_point'] = SC_Helper_DB_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point']);
644       
645        // 最終保持ポイント
646        $arrVal['total_point'] = $this->objFormParam->getValue('point') - $arrVal['use_point'] + $arrVal['add_point'];
647       
648        if ($arrVal['total'] < 0) {
649            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
650        }
651
652        if ($arrVal['payment_total'] < 0) {
653            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
654        }
655        //新規追加受注のみ
656        if ($_POST['mode'] == "add") {
657            if ($arrVal['total_point'] < 0) {
658                $arrErr['use_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
659            }
660        }
661
662        $this->objFormParam->setParam($arrVal);
663        return $arrErr;
664    }
665
666    /**
667     * DB更新処理
668     *
669     * TODO リファクタリング
670     *
671     * @param integer $order_id 注文番号
672     * @return void
673     */
674    function lfRegistData($order_id, &$objPurchase) {
675        $objQuery = new SC_Query();
676
677        $sqlval = $this->lfMakeSqlvalForDtbOrder();
678
679        $where = "order_id = ?";
680
681        $objQuery->begin();
682
683        // 受注.対応状況の更新
684        SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, $sqlval['status'], $sqlval['add_point'], $sqlval['use_point']);
685        unset($sqlval['status']);
686        unset($sqlval['add_point']);
687        unset($sqlval['use_point']);
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.