From d6b40e55405f2814e4663a3a4e537de57c48c20f Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期四, 11 八月 2022 19:57:54 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs |  142 +++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 117 insertions(+), 25 deletions(-)

diff --git a/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs b/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
index 2cc29ad..5b9802d 100644
--- a/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
+++ b/WebAPI/Controllers/SCGL/Sc_ComplementGoodsController.cs
@@ -64,6 +64,8 @@
                 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");
 
+                //bool a = AddSendGoodsBillSynChronizAtion("PLD00000112", ref DBUtility.ClsPub.sExeReturnInfo);
+
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
                 objJsonResult.Message = "Sucess锛�";
@@ -211,6 +213,9 @@
             public int? HMaterID = 0;
             public int? HWHID = 0;
             public int? HSPID = 0;
+            public int? HStockOutOrgID = 0;
+            public int? HStockInOrgID = 0;
+            public int? HSCWHID = 0;
         }
 
         [Route("Sc_ComplementGoods/JIT_SendGoodsBill")]
@@ -295,36 +300,47 @@
 
                 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");
 
+                long InterID = 0;
+                string HBillNo = "";
                 for (int i = 0; i < listCa.Count; i++)
                 {
-                    int a = -1;
-                    for (int j = 0; j < ds.Tables[0].Rows.Count; j++)
+                    //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;
+                    //    }
+                    //}
+
+                    // 鍒欎唬琛ㄩ厤閫佸崟娌℃湁鏁版嵁  闇�瑕佹坊鍔犳暟鎹�
+                    if (ds.Tables[0].Rows.Count == 0)
                     {
-                        if (ds.Tables[0].Rows[j]["HMaterID"].ToString() == listCa[i].HMaterID.ToString()&& ds.Tables[0].Rows[j]["HMainSourceEntryID"].ToString() == listCa[i].HEntryID.ToString())
+                        if (i == 0)
                         {
-                            a = j;
-                            break;
+                            InterID = DBUtility.ClsPub.CreateBillID_Prod("460201", ref DBUtility.ClsPub.sExeReturnInfo);
+                            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')");
                         }
-                    }
-
-                    //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)" +
+                            ",HMaterID,HQty,HWHID,HSPID,HISCheck,HCheckSubMan,HCheckSubDate,HStockOutOrgID,HStockInOrgID,HSCWHID)" +
                             $"values({InterID},'{HBillNo}',{i + 1}, {listCa[i].HMaterID},{listCa[i].鏈鎷f枡鏁伴噺}," +
-                            $" {listCa[i].HWHID},{listCa[i].HSPID},0,'{user}', GETDATE())");
+                            $" {listCa[i].HWHID},{listCa[i].HSPID},0,'{user}', GETDATE(),{listCa[i].HStockOutOrgID},{listCa[i].HStockInOrgID},{listCa[i].HSCWHID})");
+
+                        //鍚屾閲戣澏鐩存帴璋冩嫧鍗�
+                        if (AddSendGoodsBillSynChronizAtion(HBillNo, ref DBUtility.ClsPub.sExeReturnInfo))
+                        {
+
+                        }
                     }
                     else
                     {
@@ -332,10 +348,35 @@
                         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 ");
                     }
-                    //淇敼璋冩嫧鏁伴噺
-                    oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY=HSendQTY+{listCa[i].鏈鎷f枡鏁伴噺} where HMaterID={listCa[i].HMaterID} " +
-                        $" and HSourceInterID=(select top 1 HSourceInterID from JIT_ComplementGoodsBillSub_LK " +
-                        $"where HMaterID={listCa[i].HMaterID}  and HInterID={SourceInterID} order by HSourceInterID )  and HInterID={SourceInterID} ");
+
+                    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 = "鏂板鍗曟嵁鎴愬姛锛�";
@@ -349,6 +390,57 @@
                 throw (e);
             }
         }
+
+        //鍚屾閲戣澏鐩存帴璋冩嫧鍗�
+        public bool AddSendGoodsBillSynChronizAtion(string HBillNo, ref string sReturn)
+        {
+            ds = oCN.RunProcReturn("exec JIT_SendGoodsBillSynChronizAtion '" + HBillNo + "'", "JIT_SendGoodsBillSynChronizAtion");
+
+            foreach (DataRow dr in ds.Tables[0].Rows)
+            {
+                JObject model = new JObject();
+                model.Add("FBillTypeID", new JObject() { ["Fnumber"] = dr["FBillTypeID"].ToString() }); //鍗曟嵁绫诲瀷
+                model.Add("FDate", dr["FDate"].ToString());
+                model.Add("FBILLNO", dr["FBILLNO"].ToString());
+                model.Add("FStockOrgId", new JObject() { ["Fnumber"] = dr["FStockOrgId"].ToString() });
+                model.Add("FOwnerTypeIdHead", dr["FOwnerTypeIdHead"].ToString());
+                model.Add("FTransferBizType", dr["FTransferBizType"].ToString());
+                model.Add("FOwnerTypeOutIdHead", dr["FOwnerTypeOutIdHead"].ToString());
+                model.Add("FTransferDirect", dr["FTransferDirect"].ToString());
+                model.Add("FStockOutOrgId", new JObject() { ["Fnumber"] = dr["FStockOutOrgId"].ToString() });
+
+                JArray Fentity = new JArray();
+                JObject FentityModel = new JObject();
+                FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = dr["FMaterialId"].ToString() });
+                FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = dr["FUnitID"].ToString() });
+                FentityModel.Add("FBaseUnitId", new JObject() { ["Fnumber"] = dr["FBaseUnitId"].ToString() });
+                FentityModel.Add("FOwnerTypeId", dr["FOwnerTypeId"].ToString());
+                FentityModel.Add("FOwnerId", new JObject() { ["Fnumber"] = dr["FOwnerId"].ToString() });
+                FentityModel.Add("FOwnerTypeOutId", dr["FOwnerTypeOutId"].ToString());
+                FentityModel.Add("FOwnerOutId", new JObject() { ["Fnumber"] = dr["FOwnerOutId"].ToString() });
+                FentityModel.Add("FKeeperTypeId", dr["FKeeperTypeId"].ToString());
+                FentityModel.Add("FKeeperId", new JObject() { ["Fnumber"] = dr["FKeeperId"].ToString() });
+                FentityModel.Add("FKeeperTypeOutId", dr["FKeeperTypeOutId"].ToString());
+                FentityModel.Add("FKeeperOutId", new JObject() { ["Fnumber"] = dr["FKeeperOutId"].ToString() });
+                FentityModel.Add("FQty", dr["FQty"].ToString());
+
+                Fentity.Add(FentityModel);
+                model.Add("FBillEntry", Fentity);
+
+                JObject jsonRoot = new JObject()
+                {
+                    ["Creator"] = "",
+                    ["NeedUpDateFields"] = new JArray(),
+                    ["NeedReturnFields"] = new JArray(),
+                    ["IsDeleteEntry"] = "false",
+                    ["SubSystemId"] = "",
+                    ["IsVerifyBaseDataField"] = "false",
+                    ["Model"] = model
+                };
+
+            }
+            return true;
+        }
         #endregion
 
         #region 涓婃煡

--
Gitblit v1.9.1