From 87ac94a6c85292aa8afc39d98c3ef455ef95aebc Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期日, 12 六月 2022 16:09:09 +0800
Subject: [PATCH] 1

---
 WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs |  247 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 244 insertions(+), 3 deletions(-)

diff --git a/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs b/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
index 07f34a6..96f2adb 100644
--- a/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
+++ b/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
@@ -60,9 +60,9 @@
                 //鍙嶅簭鍒楀寲浼犻�掔殑鍊�
                 ComplementGoods com = JsonConvert.DeserializeObject<ComplementGoods>(sWhere.ToString());
 
-                
+
                 ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoodsBillList_Query '{com.MaterialNumber}','{com.MaterialName}','{com.MaterialModel}','{com.HGD}'," +
-                    $"'{com.HWHName}','{com.HDeptName}','{com.Organization}','{com.user}','{com.HJLStatus}','{com.HBeginDate}','{com.HEndDate}'" ,"h_p_JIT_ComplementGoodsBillList_Query");
+                    $"'{com.HWHName}','{com.HDeptName}','{com.Organization}','{com.user}','{com.HJLStatus}','{com.HBeginDate}','{com.HEndDate}'", "h_p_JIT_ComplementGoodsBillList_Query");
 
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
@@ -84,7 +84,7 @@
         #region 鎷f枡閰嶉�佸崟 鍒犻櫎
         [Route("Sc_ComplementGoods/DelComplementGoodsList")]
         [HttpGet]
-        public object DelComplementGoodsList(string HInterID, string HEntryID,string HOrgID, string user)
+        public object DelComplementGoodsList(string HInterID, string HEntryID, string HOrgID, string user)
         {
             try
             {
@@ -94,6 +94,17 @@
                     objJsonResult.code = "0";
                     objJsonResult.count = 0;
                     objJsonResult.Message = "鏃犲垹闄ゆ潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                ds = oCN.RunProcReturn($"select HISCheck from JIT_SendGoodsBillMain where HMainSourceInterID={HInterID} ", "JIT_SendGoodsBillMain");
+
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "褰撳墠鍗曟嵁宸查厤閫�,涓嶈兘鍒犻櫎!";
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
@@ -188,5 +199,235 @@
             }
         }
         #endregion
+
+        #region 浠撳簱鍙戞枡
+        //鍙傛暟
+        public class SendGoodsBill
+        {
+            public int? 鏈嫞鏂欐暟閲� = 0;
+            public int? 鏈�澶ф嫞鏂欐暟閲� = 0;
+            public int? 鏈鎷f枡鏁伴噺 = 0;
+            public int? HEntryID = 0;
+            public int? HMaterID = 0;
+            public int? HWHID = 0;
+            public int? HSPID = 0;
+        }
+
+        [Route("Sc_ComplementGoods/JIT_SendGoodsBill")]
+        [HttpPost]
+        public object JIT_SendGoodsBill([FromBody] JObject msg)
+        {
+            var _value = msg["msg"].ToString();
+            string[] sArray = _value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            string SourceInterID = sArray[2].ToString();
+            string SourceBillNo = sArray[3].ToString();
+            try
+            {
+                msg2 = msg2.Replace("\\", "");
+                msg2 = msg2.Replace("\n", "");
+
+                List<SendGoodsBill> listCa = new List<SendGoodsBill>();
+                //鑾峰彇琛ㄦ牸鏁版嵁闆嗗悎
+                listCa = JsonConvert.DeserializeObject<List<SendGoodsBill>>(msg2.ToString());
+
+                for (int i = 0; i < listCa.Count; i++)
+                {
+                    if (listCa[i].鏈鎷f枡鏁伴噺 > listCa[i].鏈�澶ф嫞鏂欐暟閲�)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鏈鎷f枡鏁伴噺瓒呰繃鏈�澶ф嫞鏂欐暟閲�!";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    if (listCa[i].鏈鎷f枡鏁伴噺 > listCa[i].鏈嫞鏂欐暟閲�)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "鏈鎷f枡鏁伴噺瓒呰繃鏈嫞鏂欐暟閲�!";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                bool flag = false;
+                flag = AddSendGoodsBill(listCa, SourceInterID, SourceBillNo, user, ref DBUtility.ClsPub.sExeReturnInfo);
+
+
+                if (flag)
+                {
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "閰嶉�佹垚鍔�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "閰嶉�佸け璐�!";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        //鏂板
+        public bool AddSendGoodsBill(List<SendGoodsBill> listCa, string SourceInterID, string SourceBillNo, string user, ref string sReturn)
+        {
+            try
+            {
+                oCN.BeginTran();
+
+                //oCN.RunProc($"delete from JIT_SendGoodsBillMain where HMainSourceInterID={SourceInterID} and HMainSourceBillNo='{SourceBillNo}' and HBillStatus=1");
+
+                //oCN.RunProc($"delete from JIT_SendGoodsBillSub where HInterID in (select HInterID from JIT_SendGoodsBillMain where HMainSourceInterID={SourceInterID} and HMainSourceBillNo='{SourceBillNo}' and HBillStatus=1)");
+
+                ds = oCN.RunProcReturn($"select a.HMainSourceEntryID,b.HMaterID  from JIT_SendGoodsBillMain a  with(nolock) inner join JIT_SendGoodsBillSub b with(nolock) on a.HInterID = b.HInterID where a.HMainSourceInterID={SourceInterID} and a.HBillStatus=1", "JIT_SendGoodsBillMain");
+
+                for (int i = 0; i < listCa.Count; i++)
+                {
+                    int a = -1;
+                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
+                    {
+                        if (ds.Tables[0].Rows[j]["HMaterID"].ToString() == listCa[i].HMaterID.ToString()&& ds.Tables[0].Rows[j]["HMainSourceEntryID"].ToString() == listCa[i].HEntryID.ToString())
+                        {
+                            a = j;
+                            break;
+                        }
+                    }
+
+                    //a=0  鍒欎唬琛ㄩ厤閫佸崟娌℃湁鏁版嵁  闇�瑕佹坊鍔犳暟鎹�
+                    if (a == -1 )
+                    {
+                        long InterID = DBUtility.ClsPub.CreateBillID_Prod("460201", ref DBUtility.ClsPub.sExeReturnInfo);
+                        string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("460201", ref DBUtility.ClsPub.sExeReturnInfo, true);
+
+                        //娣诲姞涓昏〃鏁版嵁
+                        oCN.RunProc("insert into JIT_SendGoodsBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate" +
+                            ",HBillNo,HBillStatus,HMaker,HMakeDate,HISCheck, HMainSourceInterID, HMainSourceEntryID" +
+                            ", HMainSourceBillNo, HMainSourceBillType)" +
+                           $"values({DateTime.Now.Year},{DateTime.Now.Month},'460201','460201',{InterID}, GETDATE(), '{HBillNo}'," +
+                           $" 1,'{user}', GETDATE(), 0, {SourceInterID}, {listCa[i].HEntryID}, '{SourceBillNo}', '4602')");
+
+                        //娣诲姞瀛愯〃鏁版嵁
+                        oCN.RunProc("insert into JIT_SendGoodsBillSub(HInterID,HBillNo_bak,HEntryID" +
+                            ",HMaterID,HQty,HWHID,HSPID,HISCheck,HCheckSubMan,HCheckSubDate)" +
+                            $"values({InterID},'{HBillNo}',{i + 1}, {listCa[i].HMaterID},{listCa[i].鏈鎷f枡鏁伴噺}," +
+                            $" {listCa[i].HWHID},{listCa[i].HSPID},0,'{user}', GETDATE())");
+                    }
+                    else
+                    {
+                        //淇敼閰嶉�佸崟鐨勯厤閫佹暟閲�
+                        oCN.RunProc($"update b  set b.HQty=b.HQty+{listCa[i].鏈鎷f枡鏁伴噺} from JIT_SendGoodsBillMain a  with(nolock) inner join JIT_SendGoodsBillSub b with(nolock) on a.HInterID = b.HInterID  " +
+                            $"where  HMainSourceInterID ={SourceInterID} and b.HMaterID ={listCa[i].HMaterID} and a.HBillStatus =1 ");
+                    }
+
+                    DataSet dsTable = new DataSet();
+                    //鏌ヨJIT_ComplementGoodsBillSub_LK
+                    dsTable = oCN.RunProcReturn($"select  * from JIT_ComplementGoodsBillSub_LK where HMaterID={listCa[i].HMaterID}  and HInterID={SourceInterID} order by HSourceInterID ", "JIT_ComplementGoodsBillSub_LK");
+
+                    for (int j = 0; j < dsTable.Tables[0].Rows.Count; j++)
+                    {
+                        if (double.Parse(dsTable.Tables[0].Rows[j]["HCallQTY"].ToString()) != double.Parse(dsTable.Tables[0].Rows[j]["HSendQTY"].ToString()))
+                        {
+                            if (double.Parse(dsTable.Tables[0].Rows[j]["HSendQTY"].ToString()) + listCa[i].鏈鎷f枡鏁伴噺 > double.Parse(dsTable.Tables[0].Rows[j]["HCallQTY"].ToString()))
+                            {
+                                var HCallQTY = double.Parse(dsTable.Tables[0].Rows[j]["HCallQTY"].ToString()) - double.Parse(dsTable.Tables[0].Rows[j]["HSendQTY"].ToString());
+                                //淇敼璋冩嫧鏁伴噺 瓒呭嚭閮ㄥ垎缁欎簣涓嬩竴鍒楁暟鎹�
+                                oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY=HSendQTY+{HCallQTY} where HMaterID={listCa[i].HMaterID} " +
+                                    $" and HSourceInterID={double.Parse(dsTable.Tables[0].Rows[j]["HSourceInterID"].ToString())} and HInterID={SourceInterID} ");
+
+                                oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY=HSendQTY+{(listCa[i].鏈鎷f枡鏁伴噺 - HCallQTY)} where HMaterID={listCa[i].HMaterID} " +
+                                   $" and HSourceInterID={dsTable.Tables[0].Rows[j + 1]["HSourceInterID"].ToString()} and HInterID={SourceInterID} ");
+                                break;
+                            }
+                            else
+                            {
+                                //淇敼璋冩嫧鏁伴噺
+                                oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY=HSendQTY+{listCa[i].鏈鎷f枡鏁伴噺} where HMaterID={listCa[i].HMaterID} " +
+                                    $" and HSourceInterID={dsTable.Tables[0].Rows[j]["HSourceInterID"].ToString()} and HInterID={SourceInterID} ");
+                                break;
+                            }
+                        }
+                    }
+                }
+
+                sReturn = "鏂板鍗曟嵁鎴愬姛锛�";
+                oCN.Commit();
+                return true;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                sReturn = e.Message;
+                throw (e);
+            }
+        }
+        #endregion
+
+        #region 涓婃煡
+        [Route("Sc_ComplementGoods/ComplementGoodsList_Sc")]
+        [HttpGet]
+        public object ComplementGoodsList_Sc(string HInterID, string HMaterID)
+        {
+            try
+            {
+
+                ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoodsBillList_UpQuery '{HInterID}',{HMaterID}", "h_p_JIT_ComplementGoodsBillList_UpQuery");
+
+                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("Sc_ComplementGoods/JIT_SendGoodsBillList_Xc")]
+        [HttpGet]
+        public object JIT_SendGoodsBillList_Xc(string HInterID, string HMaterID)
+        {
+            try
+            {
+
+                ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoodsBillList_DownQuery '{HInterID}',{HMaterID}", "h_p_JIT_ComplementGoodsBillList_DownQuery");
+
+                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
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1