Index: trunk/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
===================================================================
--- trunk/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php	(revision 18432)
+++ trunk/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php	(revision 18562)
@@ -111,4 +111,8 @@
         $objSiteInfo = new SC_SiteInfo();
         $objDb = new SC_Helper_DB_Ex();
+        $objDate = new SC_Date(1901); 
+        $this->arrYearDelivDate = $objDate->getYear('', date('Y'), '');
+        $this->arrMonthDelivDate = $objDate->getMonth(true);
+        $this->arrDayDelivDate = $objDate->getDay(true);
         $arrInfo = $objSiteInfo->data;
 
@@ -283,5 +287,5 @@
         // 支払い方法の取得
         $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
-        // 配送時間の取得
+        // お届け時間の取得
         $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
         $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
@@ -343,11 +347,11 @@
         $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
         $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
-        $this->objFormParam->addParam("住所1", "order_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-        $this->objFormParam->addParam("住所2", "order_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $this->objFormParam->addParam("住所1", "order_addr01", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $this->objFormParam->addParam("住所2", "order_addr02", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
         $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
         $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
         $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
 
-        // 配送先情報
+        // お届け先情報
         $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
         $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
@@ -357,6 +361,6 @@
         $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
         $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
-        $this->objFormParam->addParam("住所1", "deliv_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
-        $this->objFormParam->addParam("住所2", "deliv_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $this->objFormParam->addParam("住所1", "deliv_addr01", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $this->objFormParam->addParam("住所2", "deliv_addr02", MTEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
         $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
         $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
@@ -375,9 +379,9 @@
 
         $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
-        $this->objFormParam->addParam("配送時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
+        $this->objFormParam->addParam("お届け時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
         $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
-        $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
+        $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
         $this->objFormParam->addParam("お支払方法名称", "payment_method");
-        $this->objFormParam->addParam("配送時間", "deliv_time");
+        $this->objFormParam->addParam("お届け時間", "deliv_time");
 
         // 受注詳細情報
@@ -406,4 +410,5 @@
         $this->objFormParam->addParam("受注日", "create_date");
         $this->objFormParam->addParam("発送日", "commit_date");
+        $this->objFormParam->addParam("お届け日", "deliv_date"); 
     }
 
@@ -419,5 +424,11 @@
             $this->objFormParam->setValue('total_point', $total_point);
             $this->objFormParam->setValue('point', $point);
+            $delivDate = split(" ", $arrRet[0]["deliv_date"]);
+            $delivDate = split("-", $delivDate[0]);
+            $this->objFormParam->setValue('deliv_date_year', $delivDate[0]);
+            $this->objFormParam->setValue('deliv_date_month', isset($delivDate[1]) ? $delivDate[1] : "");
+            $this->objFormParam->setValue('deliv_date_day', isset($delivDate[2]) ? $delivDate[2] : "");
             $this->arrForm = $arrRet[0];
+
             // 受注詳細データの取得
             $arrRet = $this->lfGetOrderDetail($order_id);
@@ -456,4 +467,10 @@
         $objErr = new SC_CheckError($arrRet);
         $objErr->arrErr = $this->objFormParam->checkError();
+
+        $objErr->doFunc(array("お届け日", "deliv_date_year", "deliv_date_month", "deliv_date_day"), array("CHECK_DATE"));
+
+        if (count($objErr->arrErr) >= 1) {
+            return $objErr->arrErr;
+        }
 
         return $objErr->arrErr;
@@ -538,7 +555,16 @@
             }
         }
+        $sqlval['update_date'] = 'Now()';
+
+        if (strlen($sqlval['deliv_date_year']) >= 0) {
+            $sqlval['deliv_date'] = $sqlval['deliv_date_year'] . '-' . $sqlval['deliv_date_month'] . '-' . $sqlval['deliv_date_day'];
+        }
+        unset($sqlval['deliv_date_year']);
+        unset($sqlval['deliv_date_month']);
+        unset($sqlval['deliv_date_day']);
 
         unset($sqlval['total_point']);
         unset($sqlval['point']);
+        unset($sqlval['commit_date']);
 
         $where = "order_id = ?";
@@ -574,9 +600,48 @@
         $objQuery->query($sql, $arrUpdData);
 
+        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
+
+
+        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算
+        $max = count($arrDetail);
+        $k = 0;
+        $arrStockData = array();
+        for($i = 0; $i < $max; $i++) {
+            if (!empty($arrDetail[$i]['product_id'])) {
+                $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?", array($order_id, $arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2']));
+                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) {
+                    // 数量が変更された商品
+                    $arrStockData[$k]['product_id'] = $arrDetail[$i]['product_id'];
+                    $arrStockData[$k]['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
+                    $arrStockData[$k]['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
+                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity'];
+                    ++$k;
+                } elseif (empty($arrPreDetail)) {
+                    // 新しく追加された商品 もしくは 違う商品に変更された商品
+                    $arrStockData[$k]['product_id'] = $arrDetail[$i]['product_id'];
+                    $arrStockData[$k]['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
+                    $arrStockData[$k]['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
+                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity'];
+                    ++$k;
+                }
+                $objQuery->delete("dtb_order_detail", "order_id = ? AND product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?", array($order_id, $arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2']));
+            }
+        }
+
+        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品
+        $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id));
+        foreach ($arrPreDetail AS $key=>$val) {
+            $arrStockData[$k]['product_id'] = $val['product_id'];
+            $arrStockData[$k]['classcategory_id1'] = $val['classcategory_id1'];
+            $arrStockData[$k]['classcategory_id2'] = $val['classcategory_id2'];
+            $arrStockData[$k]['quantity'] = $val['quantity'];
+            ++$k;
+        }
+
+        // 受注詳細データの初期化
+        $objQuery->delete("dtb_order_detail", $where, array($order_id));
+
+
         // 受注詳細データの更新
-        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
-        $objQuery->delete("dtb_order_detail", $where, array($order_id));
-
-
         $max = count($arrDetail);
         for($i = 0; $i < $max; $i++) {
@@ -596,4 +661,18 @@
         }
 
+        // 在庫数調整
+        $status = $sqlval['status'];
+        if (ORDER_DELIV != $status && ORDER_CANCEL != $status) {
+            $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?;";
+            foreach ($arrStockData AS $key=>$val) {
+                $stock_sqlval = array();
+                $stock_sqlval[] = $val['quantity'];
+                $stock_sqlval[] = $val['product_id'];
+                $stock_sqlval[] = $val['classcategory_id1'];
+                $stock_sqlval[] = $val['classcategory_id2'];
+
+                $objQuery->query($stock_sql, $stock_sqlval);
+            }
+        }
 
         $objQuery->commit();
@@ -683,5 +762,24 @@
             $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
             $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
+
             $objQuery->insert("dtb_order_detail", $sqlval);
+
+
+            // 在庫数減少処理
+            // 現在の実在庫数取得
+            $pre_stock = $objQuery->getone("SELECT stock FROM dtb_products_class WHERE product_id = ? AND classcategory_id1 = ?  AND classcategory_id2 = ?", array($arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2']));
+
+            $stock_sqlval = array();
+            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']);
+            if ($stock_sqlval['stock'] === 0) {
+                $stock_sqlval['stock'] = '0';
+            }
+
+            $st_params = array();
+            $st_params[] = $arrDetail[$i]['product_id'];
+            $st_params[] = $arrDetail[$i]['classcategory_id1'];
+            $st_params[] = $arrDetail[$i]['classcategory_id2'];
+
+            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?', $st_params);
         }
         $objQuery->commit();
