From 82de67c48acaf472a6f8bb8b53f3f4feec9f5e54 Mon Sep 17 00:00:00 2001
From: zrg <z1873@LAPTOP-EAVL132E>
Date: 星期五, 17 十月 2025 10:42:18 +0800
Subject: [PATCH] 1

---
 WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs |  223 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 210 insertions(+), 13 deletions(-)

diff --git a/WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs b/WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
index 516579d..e5006c0 100644
--- a/WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
+++ b/WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
@@ -282,7 +282,7 @@
 	                    ,HAddress,HSupID,HCurID,HWHID,HEmpID,HManagerID,HSecManagerID,HKeeperID,HDeptID,HExplanation,HRemark
                         ,HInnerBillNo,HSTOCKORGID,HOWNERID,HMaker,HMakeDate,HProjectID,HInvoiceBillNo)
                         values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 1201 + "','" +
-                    1201 + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "','" + HAddress +
+                    HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "','" + HAddress +
                     "'," + HSupID + "," + HCurID + "," + HWHID + "," + HEmpID + "," + HManagerID + "," + 
                     HSecManagerID + ","+ HKeeperID +"," + HDeptID + ",'" + HExplanation + "','" + HRemark
                     + "','" + HInnerBillNo + "'," + HSTOCKORGID + "," + HOWNERID + ",'" + HMaker + "',getdate(),"+ HProjectID + ",'"+ HInvoiceBillNo + "')";
@@ -413,14 +413,14 @@
             {
                 ClsKf_ICStockBillSub oSub = (ClsKf_ICStockBillSub)list[i1];
                 i++;
-                if (oSub.HQty <= 0 || oSub.HQty == null)
-                {
-                    objJsonResult.code = "0";
-                    objJsonResult.count = 0;
-                    objJsonResult.Message = "绗�" + i + "琛岋紝鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0";
-                    objJsonResult.data = null;
-                    return objJsonResult;
-                }
+                //if (oSub.HQty <= 0 || oSub.HQty == null)
+                //{
+                //    objJsonResult.code = "0";
+                //    objJsonResult.count = 0;
+                //    objJsonResult.Message = "绗�" + i + "琛岋紝鏁伴噺涓嶈兘涓�0鎴栬�呭皬浜�0";
+                //    objJsonResult.data = null;
+                //    return objJsonResult;
+                //}
 
                 if (oSub.HMaterID == 0)
                 {
@@ -631,7 +631,7 @@
             try
             {
 
-                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid =" + HInterID, "h_v_Kf_POStockInBillList");
+                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillEdit where hmainid =" + HInterID, "h_v_Kf_POStockInBillList");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
                     objJsonResult.code = "0";
@@ -728,7 +728,7 @@
                     {
                         objJsonResult.code = "0";
                         objJsonResult.count = 0;
-                        objJsonResult.Message = "鍗曟嵁宸插叧闂�!涓嶈兘鍐嶆瀹℃牳锛�";
+                        objJsonResult.Message = "鍗曟嵁宸插叧闂�!";
                         objJsonResult.data = null;
                         return objJsonResult;
                     }
@@ -736,7 +736,7 @@
                     {
                         objJsonResult.code = "0";
                         objJsonResult.count = 0;
-                        objJsonResult.Message = "鍗曟嵁宸蹭綔搴�!涓嶈兘鍐嶆瀹℃牳锛�";
+                        objJsonResult.Message = "鍗曟嵁宸蹭綔搴�!";
                         objJsonResult.data = null;
                         return objJsonResult;
                     }
@@ -1360,6 +1360,43 @@
             {
 
                 ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid =" + HInterID + " and hsubid = " + HSubID, "h_v_Kf_POStockInBillList");
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏈煡璇㈠埌婧愬崟淇℃伅锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "Sucess锛�";
+                    objJsonResult.data = ds.Tables[0];
+                    return objJsonResult;
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 閲囪喘鍏ュ簱鍗�  鏍规嵁涓诲唴鐮佷笌瀛愬唴鐮佽幏鍙栭噰璐叆搴撳崟鏁版嵁
+        [Route("Kf_POStockInBill/loadKf_POStockInBillEdit_Push")]
+        [HttpGet]
+        public object loadKf_POStockInBillEdit_Push(long HInterID, long HSubID)
+        {
+            try
+            {
+
+                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillEdit where hmainid =" + HInterID + " and hsubid = " + HSubID, "h_v_Kf_POStockInBillEdit");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
                     objJsonResult.code = "0";
@@ -2030,7 +2067,7 @@
                 }
                 string sql = "select * from h_v_Kf_POStockInBillQuerySub where hmainid =  " + hmainid;
 
-                ds = oCN.RunProcReturn(sql + " order by hsubid desc", "h_v_Kf_POStockInBillQuerySub");
+                ds = oCN.RunProcReturn(sql + " order by hsubid ASC", "h_v_Kf_POStockInBillQuerySub");
 
 
                 foreach (DataColumn col in ds.Tables[0].Columns)
@@ -2058,5 +2095,165 @@
         }
         #endregion
 
+
+        #region 閲囪喘鍏ュ簱鍗� 瀹℃牳鍚屾 璋冪敤API
+        [Route("Kf_POStockInBill/Kf_POStockInBillSaveApi")]
+        [HttpPost]
+        public object Kf_POStockInBillSaveApi([FromBody] JObject sMainSub)
+        {
+            try
+            { 
+                oCN.BeginTran();
+                LogService.Write("閲囪喘鍏ュ簱鍗曞悓姝�,淇濆瓨鏂规硶鎵ц锛�" + sMainSub.ToString());
+
+                var model = sMainSub["model"].ToString();
+                var entry = sMainSub["model"]["HENTRY"].ToString();
+
+                model = "[" + model.ToString() + "]";
+                List<ClsKf_ICStockBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ICStockBillMain>>(model);
+                List<ClsKf_ICStockBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ICStockBillSub>>(entry);
+
+                // 鍒ゆ柇 鏁版嵁搴撲腑鏄惁瀛樺湪id鍜屽崟鎹彿鐩哥瓑鐨勫崟鎹紝瀛樺湪锛屽垯閲嶅缓锛屽彧鏈塱d鍙风浉绛夛紝鍒欑敵璇锋柊鐨刬d鍙�
+                var ds1 = oCN.RunProcReturn($@"
+                select hmainid HInterID, 鍗曟嵁鍙� HBillNO from h_v_Kf_POStockInBillList where hmainid = {mainList[0].HInterID}
+                ", "h_v_Kf_POStockInBillList");
+
+                if (ds1.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows[0]["HInterID"] != null)
+                {
+                    if (string.Equals(ds1.Tables[0].Rows[0]["HBillNo"].ToString(), mainList[0].HBillNo, StringComparison.OrdinalIgnoreCase))
+                    {
+                        string sql = string.Empty;
+                        sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
+                        oCN.RunProc(sql);
+                        sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
+                        oCN.RunProc(sql);
+                    }
+                    else
+                    {
+                        // 閲嶆柊鐢宠HInterID
+                        var HInterID_Exch = DBUtility.ClsPub.CreateBillID("1201", ref DBUtility.ClsPub.sExeReturnInfo);
+                        mainList[0].HInterID = HInterID_Exch;
+
+                        foreach (var oSub in subList)
+                        {
+                            oSub.HInterID = HInterID_Exch;
+                        }
+
+                    }
+                }
+               
+                // 涓昏〃
+                // 涓昏〃鎻掑叆
+                oCN.RunProc($@"Insert Into Kf_ICStockBillMain 
+                (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus
+                ,HAddress,HSupID,HCurID,HWHID,HEmpID,HManagerID,HSecManagerID,HKeeperID,HDeptID,HExplanation,HRemark
+                ,HInnerBillNo,HSTOCKORGID,HOWNERID,HMaker,HMakeDate,HProjectID,HInvoiceBillNo
+                ,HChecker, HCheckDate)
+                values(
+                '{mainList[0].HInterID}',
+                '{mainList[0].HYear}',
+                '{mainList[0].HPeriod}',
+                '{mainList[0].HBillType}',
+                '{mainList[0].HBillSubType}',
+                '{mainList[0].HDate}',
+                '{mainList[0].HBillNo}',
+                {mainList[0].HBillStatus},
+                '{mainList[0].HAddress}',
+                '{mainList[0].HSupID}',
+                '{mainList[0].HCurID}',
+                '{mainList[0].HWHID}',
+                '{mainList[0].HEmpID}',
+                '{mainList[0].HManagerID}',
+                '{mainList[0].HSecManagerID}',
+                '{mainList[0].HKeeperID}',
+                '{mainList[0].HDeptID}',
+                '{mainList[0].HExplanation}',
+                '{mainList[0].HRemark}',
+                '{mainList[0].HInnerBillNo}',
+                {mainList[0].HSTOCKORGID},
+                '{mainList[0].HOWNERID}',
+                '{mainList[0].HMaker}',
+                '{mainList[0].HMakeDate}',
+                '{mainList[0].HProjectID}',
+                '{mainList[0].HInvoiceBillNo}',
+                '{mainList[0].HChecker}',
+                '{mainList[0].HCheckDate}'
+                )
+            ");
+
+                // 瀛愯〃鎻掑叆
+                foreach (var osub in subList)
+                {
+                   
+                    oCN.RunProc($@"Insert into Kf_ICStockBillSub 
+                    (HInterID,HEntryID,HMaterID,HUnitID,HQtyMust,HQty,HPrice
+                    ,HMoney,HOrderPrice,HWHID,HSPID,HRelationQty,HBatchNo
+                    ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType
+                    ,HPOOrderInterID,HPOOrderEntryID ,HPOOrderBillNo
+                    ,HPropertyID,HSecUnitID,HSecUnitRate,HPlanMode,HRemark,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo
+                    ,HTaxRate,HTaxPrice,HlineTotal) 
+                    values (
+                        '{osub.HInterID}', 
+                        '{osub.HEntryID}', 
+                        '{osub.HMaterID}',
+                        '{osub.HUnitID}', 
+                        '{osub.HQtyMust}', 
+                        '{osub.HQty}',
+                        '{osub.HPrice}',
+                        '{osub.HMoney}',
+                        '{osub.HOrderPrice}',
+                        '{osub.HWHID}',
+                        '{osub.HSPID}',
+                        '{osub.HRelationQty}',
+                        '{osub.HBatchNo}',
+                        '{osub.HSourceInterID}',
+                        '{osub.HSourceEntryID}',
+                        '{osub.HSourceBillNo}',
+                        '{osub.HSourceBillType}',
+                        '{osub.HPOOrderInterID}',
+                        '{osub.HPOOrderEntryID}',
+                        '{osub.HPOOrderBillNo}',
+                        '{osub.HPropertyID}',
+                        '{osub.HSecUnitID}',
+                        '{osub.HSecUnitRate}',
+                        '{osub.HPlanMode}',
+                        '{osub.HRemark}',
+                        '{osub.HSeOrderInterID}',
+                        '{osub.HSeOrderEntryID}',
+                        '{osub.HSeOrderBillNo}',
+                        '{osub.HTaxRate}',
+                        '{osub.HTaxPrice}',
+                        '{osub.HlineTotal}'
+                    )
+                    ");
+                }
+
+                //閲囪喘鍏ュ簱鍗曟柊澧炲洖濉噰璐叆搴撳叧鑱旀暟閲�
+                oCN.RunProc("exec h_p_Cg_UpDateRelation_POOrderToPOStockIn_Add " + mainList[0].HInterID);
+
+                //閲囪喘鍏ュ簱鍗曟柊澧炲洖濉敹鏂欓�氱煡鍗曞叧鑱旀暟閲�
+                oCN.RunProc("exec h_p_Cg_UpDateRelation_POInStockToPOStockIn_Add " + mainList[0].HInterID);
+
+
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "鍗曟嵁淇濆瓨鎴愬姛锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write("閲囪喘鍏ュ簱鍗曞悓姝ュ紓甯�,淇濆瓨鏂规硶鎵ц瀹屾垚寮傚父锛�" + e.Message.ToString());
+
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1