Index: /branches/version-2_4-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
===================================================================
--- /branches/version-2_4-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php	(revision 18474)
+++ /branches/version-2_4-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php	(revision 18478)
@@ -112,7 +112,7 @@
         $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);
+        $this->arrYearDelivDate = $objDate->getYear('', date('Y'), ''); 
+        $this->arrMonthDelivDate = $objDate->getMonth(true); 
+        $this->arrDayDelivDate = $objDate->getDay(true);
         $arrInfo = $objSiteInfo->data;
 
@@ -381,8 +381,5 @@
         $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_year", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
- 		    $this->objFormParam->addParam("お届け日(月)", "deliv_date_month", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
- 		    $this->objFormParam->addParam("お届け日(日)", "deliv_date_day", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_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");
@@ -428,8 +425,8 @@
             $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] : "");
+            $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];
 
@@ -603,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++) {
@@ -625,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();
@@ -712,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();
