From ffa387e35fb64107c944508c1131046d9e6b564d Mon Sep 17 00:00:00 2001
From: yusijie <ysj@hz-kingdee.com>
Date: 星期二, 27 二月 2024 13:55:36 +0800
Subject: [PATCH] 凯贝奈特新增收料单单据类型

---
 WebAPI/Controllers/BarCodeController.cs |  549 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 339 insertions(+), 210 deletions(-)

diff --git a/WebAPI/Controllers/BarCodeController.cs b/WebAPI/Controllers/BarCodeController.cs
index 9250a1e..fe0ca61 100644
--- a/WebAPI/Controllers/BarCodeController.cs
+++ b/WebAPI/Controllers/BarCodeController.cs
@@ -1,4 +1,5 @@
 锘縰sing DBUtility;
+using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
 using SQLHelper;
 using System;
@@ -13,6 +14,8 @@
 using System.Web.Script.Serialization;
 using WebAPI.Code;
 using WebAPI.Models;
+using WebAPI.Utility;
+
 namespace WebAPI.Controllers
 {
 
@@ -21,7 +24,8 @@
         private JsonResult objJsonResult = new JsonResult();
         private json objjson = new json();
         public new ClsCNSRM oCn = new ClsCNSRM();
-
+        //鑾峰彇绯荤粺鍙傛暟
+        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public T ScriptDeserialize<T>(string strJson)
         {
             JavaScriptSerializer js = new JavaScriptSerializer();
@@ -494,6 +498,7 @@
         /// <returns></returns>
         public object GetBarcodeSaveBill_Box([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
@@ -525,33 +530,9 @@
 
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
-                    if (oBill.CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                        objJsonResult.data = null;
-                        return objJsonResult;
-                    }
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                        if (oItemSub.HWBQty == 0 || oItemSub.HWXQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "澶栫鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                    }
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 || oItemSub.HWXQty == 0)
+                        continue;
                 }
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
@@ -585,6 +566,27 @@
                         HSumQty = ClsPub.isDoule(oItemSub.HQty);  //HWXQtyCol
                         for (int i = 0; i < HBQty; i++)
                         {
+                            LSH = LSH + 1;
+                            LSH2 = LSH.ToString();
+                            while (LSH2.Length < LSHlen)  //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
+                            {
+                                LSH2 = "0" + LSH2;
+                            }
+                            sDate = ClsPub.GetServerDate(0);
+                            sYear = ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
+                            sPeriod = "0" + ClsPub.isDate(sDate).Month.ToString();
+                            sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+                            sDay = "0" + ClsPub.isDate(sDate).Day.ToString();
+                            sDay = sDay.Substring(sDay.Length - 2, 2);
+                            //==================================
+                            TM = HNumber + sYear + sPeriod + sDay + LSH2;
+                            while (TM.Length < SumLen)  //濡傛灉鏉$爜灏忎簬12浣嶆暟鍓嶉潰琛�0
+                            {
+                                TM = "0" + TM;
+                            }
+                            //TM = "B" + TM;
+                            TM = "SRM" + "B" + TM;
+
                             if (HSumQty - HMinQty > 0)
                             {
                                 WeiShu = "";
@@ -602,8 +604,6 @@
                                 }
                                 HMinQty = HSumQty;
                             }
-                            TM = $"{oItemSub.HMaterID}#{HMinQty}";
-
                             Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
                             bar.HBarCode = TM;
                             bar.HMaterID = oItemSub.HMaterID;
@@ -629,6 +629,9 @@
                             bar.HSupID = oItemSub.HSupID;
                             bar.HEndQty = WeiShu;
                             bar.HMTONO = oItemSub.HMTONO;
+                            bar.HSupBatchNo = oItemSub.HSupBatchNo;
+                            bar.HSupMaterNumber = oItemSub.HSupMaterNumber;
+                            bar.HISKFPERIOD = oItemSub.HISKFPERIOD;
                             ls2.Add(bar);
                         }
                     }
@@ -695,7 +698,7 @@
                                 TM2 = "0" + TM2;
                             }
                             bar2.HMaterID = oItemSub2.HMaterID;
-                            bar2.HBarCode = oItemSub2.HBarCode.Split('#')[0] + "#" + HWXQty.ToString();
+                            bar2.HBarCode = oItemSub2.HBarCode + "-" + TM2;
                             bar2.HUnitID = oItemSub2.HUnitID;
                             bar2.HQty = HWXQty;
                             bar2.HBatchNo = DBUtility.ClsPub.isStrNull(oItemSub2.HBatchNo);
@@ -709,11 +712,15 @@
                             bar2.HSupID = oItemSub2.HSupID;
                             bar2.HEndQty = WeiShu1;
                             bar2.HMTONO = oItemSub2.HMTONO;
+                            bar2.HSupBatchNo = DBUtility.ClsPub.isStrNull(oItemSub2.HSupBatchNo);
+                            bar2.HSupMaterNumber = DBUtility.ClsPub.isStrNull(oItemSub2.HSupMaterNumber);
+                            bar2.HISKFPERIOD = DBUtility.ClsPub.isInt(oItemSub2.HISKFPERIOD);
                             ls3.Add(bar2);
                             //LogService.Write("娴嬭瘯鍔�+++" + oItemSub2.HSupID);
                         }
                     }
                 }
+
                 string HBarCode = "";
                 string HBarCodeType = "";
                 Int64 HMaterID = 0;
@@ -732,7 +739,15 @@
                 string HKFDQDate = "";
                 string HWei = "";
                 string HMTONO = "";
+                string HSupBatchNo = "";
+                string HSupMaterNumber = "";
+                Int64 HISKFPERIOD = 0;
                 oCn.BeginTran();
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
+                {
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
                 {
                     //LogService.Write("寰幆绗簩娆�:" + oItemSub.HSupID);
@@ -755,13 +770,23 @@
                         HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
                         HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
                         HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                        HSupBatchNo = ClsPub.isStrNull(oItemSub.HSupBatchNo);
+                        HSupMaterNumber = ClsPub.isStrNull(oItemSub.HSupMaterNumber);
+                        HISKFPERIOD = DBUtility.ClsPub.isInt(oItemSub.HISKFPERIOD);
+
+                        if (FCusName.Contains("澶忓疂"))
+                        {
+                            HBarCode = $"{oItemSub.HMaterID}";
+                            HBarCodeType = "鍝佺鐮乢澶栫";
+                        }
                         string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
                                     ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
+                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO,HSupBatchNo,HSupMaterNumber,HProduceDate,HExpiryDate,HISKFPERIOD " +
                                     ") values ("
                                     + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
                                     + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')";
+                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "','" + HSupBatchNo+ "','" + HSupMaterNumber + "','" + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD +
+                                    ")";
                         oCn.RunProc(sql);
                         //LogService.Write(sql);
                         sql = "exec setLSH '" + DateTime.Today + "'";
@@ -790,13 +815,22 @@
                         HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
                         HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
                         HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                        HSupBatchNo = ClsPub.isStrNull(oItemSub.HSupBatchNo);
+                        HSupMaterNumber = ClsPub.isStrNull(oItemSub.HSupMaterNumber);
+                        HISKFPERIOD = ClsPub.isInt(oItemSub.HISKFPERIOD);
+                        if (FCusName.Contains("澶忓疂"))
+                        {
+                            HBarCode = $"{oItemSub.HMaterID}";
+                            HBarCodeType = "鍝佺鐮�";
+                        }
                         string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
                                     ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
+                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO ,HSupBatchNo,HSupMaterNumber,HProduceDate,HExpiryDate,HISKFPERIOD" +
                                     ") values ("
                                     + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
                                     + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')";
+                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO +  "','" +
+                                    HSupBatchNo + "','" + HSupMaterNumber + "','" + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
                         oCn.RunProc(sql);
                         //LogService.Write(sql);
                     }
@@ -854,6 +888,7 @@
         /// <returns></returns>
         public object GetBarcodeSaveBillOnlyInnerBox([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
@@ -880,32 +915,7 @@
 
                 List<Model.ClsGy_MaterialList_WMS_Model> ls = new List<Model.ClsGy_MaterialList_WMS_Model>();
                 List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
-                List<Model.ClsGy_BarCodeBill_WMS_Model> ls3 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
                 ls = oListModels.getObjectByJson_MaterialList(msg3);
-
-                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
-                {
-                    if (CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                        objJsonResult.data = null;
-                        return objJsonResult;
-                    }
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-
-                    }
-                }
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
                 int SumLen = 10;            //鎬婚暱搴�
@@ -922,6 +932,20 @@
                 LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //妫�楠屾墦鍗版暟閲忥紙HQTY锛夊拰鏈墦鍗版暟閲�
+                    string sql = $"select HQty -HBarcodeCount as HNotBarcodeCount ,* from Cg_POOrderBillSub where HEntryID = {oItemSub.HSourceEntryID}";
+                    DataSet ds = oCn.RunProcReturn(sql, "tables");
+                    if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) < oItemSub.HQty)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾湰娆$敓鎴愭潯鐮佹暟閲忎笉鑳借秴鍑烘湭鐢熸垚鏉$爜鏁伴噺";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
                     //鍐呯
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
@@ -981,6 +1005,11 @@
                 oCn.BeginTran();
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
                 {
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
+                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
+                {
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
                         HBarCode = oItemSub.HBarCode.ToString();
@@ -1012,40 +1041,28 @@
                         oCn.RunProc(sql);
                     }
                 }
-                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls3)
+                //鏆傛椂鍙洖濉叧鑱旀暟閲�
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
-                    //LogService.Write("寰幆绗笁娆�:" + oItemSub.HSupID);
-                    if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    //鏇存柊 宸叉墦鍗版暟閲�
+                    if (oItemSub.HSourceBillType == "1102")
                     {
-                        HBarCode = oItemSub.HBarCode.ToString();
-                        HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
-                        HBarCodeType = "绠卞彿鍐呮潯鐮�";
-                        HMaterID = ClsPub.isLong(oItemSub.HMaterID);
-                        HUnitID = ClsPub.isLong(oItemSub.HUnitID);
-                        HQty2 = ClsPub.isDoule(oItemSub.HQty);
-                        HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
-                        HSupID = oItemSub.HSupID;
-                        HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
-                        HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
-                        HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
-                        HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
-                        HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
-                        HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
-                        HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
-                        HWei = ClsPub.isStrNull(oItemSub.HEndQty);
-                        string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
-                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
-                                    ") values ("
-                                    + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
-                                    + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')";
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
+                        string sql = string.Empty;
+                        sql = string.Format(@"
+update t1 set  
+t1.HBarcodeCount = 
+isnull((select sum(HQty)from Gy_BarCodeBill where HSourceInterID = t1.HInterID and HSourceEntryID = t1.HEntryID and HBarCodeType ='{2}'),0)
+from Cg_POOrderBillSub t1 
+where t1.HInterID = {0} and t1.HEntryID ={1}", oItemSub.HSourceInterID, oItemSub.HSourceEntryID, _HBarCodeType);
                         oCn.RunProc(sql);
                     }
                 }
-                //鏆傛椂鍙洖濉叧鑱旀暟閲�
-                string _sql = "exec H_p_SRM_BarCodeBill_Update_UpdateBillRelateData " + linterid.ToString();
-                oCn.RunProc(_sql);
                 oCn.Commit();
             }
             catch (Exception e)
@@ -1348,29 +1365,21 @@
         /// <param name="OnePage"></param>
         /// <returns></returns>
         [Route("GetBarCodeShowList")]
-        [HttpGet]
-        public object GetBarCodeShowList(string HSupNo, string sqlWhere)
+        [HttpPost]
+        public object GetBarCodeShowList([FromBody] JObject msg)
         {
-            string msg = "";
+            string HSupNo = msg["HSupNo"].ToString(); string sqlWhere = msg["sqlWhere"].ToString();
+            //娣诲姞鍒楀悕
+            List<object> columnNameList = new List<object>();           
             try
             {
                 string VsWhere = "";
                 string PcWhere = "";
                 SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
                 DataSet ds;
-                //鍏朵粬杩囨护
-                if (msg.Trim() == "")
-                {
-                    msg = " Where hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛=''" + HSupNo.Trim() + "'') " + sqlWhere;
-                    // msg = " Where   hsupid in (select hsupid from Gy_UserSupplierRelation where HUserID=^^" + System.Web.HttpContext.Current.Session["HUserName"].ToString() + "^^)";
-                }
-                else
-                {
-                    msg = msg + " and   hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛=''" + HSupNo.Trim() + "'') " + sqlWhere;
-                    // msg = msg + " Where   hsupid in (select hsupid from Gy_UserSupplierRelation where HUserID=^^" + System.Web.HttpContext.Current.Session["HUserName"].ToString() + "^^)";
-                }
-                //杞崲鐗规畩瀛楃
-                if (Common.SQLtoChange(msg, ref VsWhere, ref PcWhere) == false)
+                string sql = " Where hsupid in (select HSupID from h_v_Gy_UserSupplierList where 鐢ㄦ埛=''" + HSupNo.Trim() + "'') " + sqlWhere;
+
+                if (Common.SQLtoChange(sql, ref VsWhere, ref PcWhere) == false)
                 {
                     objjson.code = "0";
                     objjson.count = 0;
@@ -1392,10 +1401,18 @@
                 }
                 else
                 {
+                    foreach (DataColumn col in ds.Tables[0].Columns)
+                    {
+                        Type dataType = col.DataType;
+                        string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
+                        columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//鑾峰彇鍒癉ataColumn鍒楀璞$殑鍒楀悕
+                    }
+
                     objjson.code = "0";
                     objjson.count = 10000;
                     objjson.Message = "鑾峰彇鎴愬姛";
                     objjson.data = ds.Tables[0];
+                    objjson.list = columnNameList;
                     return objjson;
                 }
             }
@@ -1470,15 +1487,12 @@
         /// <summary>
         /// 鏉$爜鐢熸垚琛ㄤ綋锛堥噰璐鍗曪級
         /// </summary>
-        /// <param name="sMsg"></param>
+        /// <param name="sMsg">閲囪喘璁㈠崟HinterID</param>
         /// <returns></returns>
         public object GetHBarCodeShowBillSubBycg(string sMsg)
         {
             try
             {
-                DataSet ds;
-                string s = "";
-                string ShowItem = " * ";//鏄剧ず鐨勫瓧娈�
                 if (DBUtility.ClsPub.isLong(sMsg) == 0)
                 {
                     objjson.code = "0";
@@ -1487,9 +1501,18 @@
                     objjson.data = null;
                     return objjson;
                 }
+                //棰勫鐞� 淇敼閲囪喘璁㈠崟鐨勯��鏂欐暟閲�
+                var kdTbaleName = Util.GetConfigKey(AppDomain.CurrentDomain.BaseDirectory + "/Config/kdapi.config", "DataBaseName");
+                string sql = $@"update t1 set 
+ t1.HMrbQty = t2.FMRBQTY
+ from Cg_POOrderBillSub t1 
+ join {kdTbaleName}..T_PUR_POORDERENTRY_R t2 
+ on t1.HEntryID = t2.FENTRYID
+ where t1.HInterID = {sMsg} ";//sMsg 閲囪喘璁㈠崟hinterid
+                oCn.RunProc(sql);
                 DAL.ClsWeb_BarCodeBill oClsWeb_BarCodeBill = new DAL.ClsWeb_BarCodeBill();
-                string sql = string.Format(@"select * from h_v_Cg_POOrderBillSub_ForWeb2 where HInterID = " + sMsg);
-                ds = oCn.RunProcReturn(sql, "h_v_Cg_POOrderBillSub_ForWeb2");
+                sql = string.Format(@"select * from h_v_Cg_POOrderBillSub_ForWeb2 where HInterID = " + sMsg);
+                DataSet ds = oCn.RunProcReturn(sql, "h_v_Cg_POOrderBillSub_ForWeb2");
                 //ds = oClsWeb_BarCodeBill.ShowBillSub(DBUtility.ClsPub.isLong(sMsg), ShowItem, ref DBUtility.ClsPub.sExeReturnInfo);
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
@@ -1528,11 +1551,12 @@
         /// <returns></returns>
         public object GetBarcodeSaveBillBoxBycg([FromBody] JObject msg)
         {
+            string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
             var _value = msg["msg"].ToString();
             string msg1 = _value.ToString();
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
-            string msg2 = sArray[0].ToString();
-            string msg3 = sArray[1].ToString();
+            string msg2 = sArray[0].ToString();//
+            string msg3 = sArray[1].ToString();// 
             string UserName = "";
             ListModels oListModels = new ListModels();
             try
@@ -1546,46 +1570,15 @@
                     UserName = oItem.HMaker;
                 }
                 DAL.ClsWeb_BarCodeBill oBill = new DAL.ClsWeb_BarCodeBill();
-
                 msg3 = msg3.Substring(1, msg3.Length - 2);
                 msg3 = msg3.Replace("\\", "");
                 msg3 = msg3.Replace("\n", "");  //\n
-
                 List<Model.ClsGy_MaterialList_WMS_Model> ls = new List<Model.ClsGy_MaterialList_WMS_Model>();
-                List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
-                List<Model.ClsGy_BarCodeBill_WMS_Model> ls3 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();
-                ls = oListModels.getObjectByJson_MaterialList(msg3);
+                List<Model.ClsGy_BarCodeBill_WMS_Model> ls2 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();//澶栫model
+                List<Model.ClsGy_BarCodeBill_WMS_Model> ls3 = new List<Model.ClsGy_BarCodeBill_WMS_Model>();//鍐呯model
 
-                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
-                {
-                    if (oBill.CheckBarCode(oItemSub.HSourceInterID, oItemSub.HSourceEntryID) == false)
-                    {
-                        objJsonResult.code = "0";
-                        objJsonResult.count = 0;
-                        objJsonResult.Message = "宸插瓨鍦ㄦ潯鐮侊紝涓嶅厑璁搁噸澶嶇敓鎴愶紒";
-                        objJsonResult.data = null;
-                        return objJsonResult;
-                    }
-                    if (msg2 != string.Empty)
-                    {
-                        if (oItemSub.HBQty == 0 || oItemSub.HMinQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "鍐呯鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                        if (oItemSub.HWBQty == 0 || oItemSub.HWXQty == 0)
-                        {
-                            objJsonResult.code = "0";
-                            objJsonResult.count = 0;
-                            objJsonResult.Message = "澶栫鍖呰鏁颁笉鑳戒负0锛�";
-                            objJsonResult.data = null;
-                            return objJsonResult;
-                        }
-                    }
-                }
+                ls = oListModels.getObjectByJson_MaterialList(msg3);//鍒楄〃鏁版嵁model
+
                 long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
                 int LSHlen = 6;             //娴佹按鍙烽暱搴�
                 int SumLen = 10;            //鎬婚暱搴�
@@ -1604,12 +1597,48 @@
                 string WeiShu = ""; //灏炬暟
                 DataSet Ds;
                 SQLHelper.ClsCNSRM oCn = new SQLHelper.ClsCNSRM();
+                oCn.BeginTran();
                 Ds = oCn.RunProcReturn("exec GetLSH '" + DateTime.Today + "'", "GetLSH");
                 LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
                 foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
+                    //鏁伴噺涓�0 璺宠繃
+                    if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 || oItemSub.HWXQty == 0)
+                        continue;
+                    //妫�楠屾墦鍗版暟閲忥紙HQTY锛夊拰鏈墦鍗版暟閲�
+                    string sql = $"select HQty + isnull(HMrbQty,0) - HBarcodeCount as HNotBarcodeCount ,* from Cg_POOrderBillSub where HEntryID = {oItemSub.HSourceEntryID}";
+                    DataSet ds = oCn.RunProcReturn(sql, "tables");
+
+                    if (ds.Tables[0].Rows.Count > 0 && Convert.ToDouble(ds.Tables[0].Rows[0][0]) < oItemSub.HQty)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾湰娆$敓鎴愭潯鐮佹暟閲忎笉鑳借秴鍑烘湭鐢熸垚鏉$爜鏁伴噺";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //鏍¢獙鎵瑰彿 鍜� 鐢熶骇鏃ユ湡
+                    sql = $"select top 1 HKFDate from Gy_BarCodeBill where HSupID = '{oItemSub.HSupID}' and HBatchNo = '{oItemSub.HBatchNo.TrimStart().TrimEnd()}' and HMaterID ={oItemSub.HMaterID} and isnull(HKFDate, '') <> ''";
+                    LogService.Write($"sql:{sql}");
+                    DataTable dt = oCn.RunProcReturn(sql, "tables").Tables[0];
+                    if (dt.Rows.Count > 0)
+                    {
+                        LogService.Write($"HKFDate:{dt.Rows[0][0]}");
+                        sql = $"select DATEDIFF(D,{dt.Rows[0][0]},{oItemSub.HKFDate})";
+                        ds = oCn.RunProcReturn(sql, "tables2");
+                        LogService.Write($"DATEDIFF:{Convert.ToInt32(ds.Tables[0].Rows[0][0])}");
+                        if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) != 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = $"鐗╂枡缂栫爜{oItemSub.HMaterNumber}锛屾壒鍙穥oItemSub.HBatchNo.TrimStart().TrimEnd()},鐢熶骇鏃ユ湡涓簕dt.Rows[0][0]},璇锋牳瀵�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                    }
                     if (ClsPub.isLong(oItemSub.HMaterID) != 0)
                     {
+
                         HNumber = oItemSub.HMaterID.ToString();
                         //HNumber = HNumber.Replace(".", "");
                         //HQty = Math.Ceiling(HBQty + ClsPub.isDoule(oItemSub.HWBQty));
@@ -1619,8 +1648,8 @@
                         HSumQty = ClsPub.isDoule(oItemSub.HQty);  //浜у搧鏁伴噺
                         for (int i = 0; i < HBQty; i++)
                         {
-                            //  瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
-                            TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{oItemSub.HQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
+                            ////  瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
+                            //TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{oItemSub.HQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
 
                             if (HSumQty - HMinQty > 0)
                             {
@@ -1640,7 +1669,36 @@
                                 HMinQty = HSumQty;
                             }
 
+                            //瀹夌憺鏉$爜瑙勫垯锛氱墿鏂欑紪鐮侊紙绯荤粺浠e叆锛堾鐗╂枡鍚嶇О锛堢郴缁熶唬鍏ワ級@瑙勬牸鍨嬪彿锛堢郴缁熶唬鍏ワ級@鐢熶骇鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鏁伴噺锛堟墜宸ヨ緭鍏ワ級@澶辨晥鏃ユ湡锛堟墜宸ヨ緭鍏ワ級@鎵规鍙凤紙鎵嬪伐浠e叆锛堾渚涘簲鍟嗗悕绉帮紙绯荤粺浠e叆锛堾閲囪喘璁㈠崟鍙凤紙绯荤粺浠e叆锛�
+                            TM = $"{oItemSub.HMaterNumber}@{oItemSub.HMaterName}@{oItemSub.HMaterModel}@{oItemSub.HKFDate}@{HMinQty}@{oItemSub.HKFDQDate}@{oItemSub.HBatchNo.TrimStart().TrimEnd()}@{oItemSub.HSupName}@{oItemSub.HSourceBillNo}";
                             Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
+
+                            var HBarCode_verify = TM.Split('@'); //鏍¢獙鏉$爜淇℃伅
+                            var HMaterNumber_verify = HBarCode_verify[0]; //鏍¢獙鐗╂枡缂栫爜
+                            var HMaterName_verify = HBarCode_verify[1]; //鏍¢獙鐗╂枡鍚嶇О
+                            var HMaterModel_verify = HBarCode_verify[2]; //鏍¢獙瑙勬牸鍨嬪彿
+                            var HSupName_verify = HBarCode_verify[7]; //鏍¢獙渚涘簲鍟�
+                            var HSourceBillNo_verify = HBarCode_verify[8]; //鏍¢獙閲囪喘璁㈠崟鍙�
+
+                            sql = $"select * from Gy_Material where HNumber = '{HMaterNumber_verify}' and HName = '{HMaterName_verify}'";
+                            DataSet verifyMatInfo = oCn.RunProcReturn(sql, "tables");
+
+                            sql = $"select * from Cg_POOrderBillMain where HBillNo = '{HSourceBillNo_verify}'";
+                            DataSet verifyBillInfo = oCn.RunProcReturn(sql, "tables");
+
+                            sql = $"select * from Gy_Supplier where HName = '{HSupName_verify}'";
+                            DataSet verifySupInfo = oCn.RunProcReturn(sql, "tables");
+
+                            if (verifyMatInfo.Tables[0].Rows.Count <= 0 || verifyBillInfo.Tables[0].Rows.Count <= 0 || verifySupInfo.Tables[0].Rows.Count <= 0)
+                            {
+                                oCn.RollBack();
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = $"鏉$爜淇℃伅鏍¢獙鍑洪敊锛岃閲嶆柊鐢熸垚鏉$爜";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+
                             bar.HBarCode = TM;
                             bar.HMaterID = oItemSub.HMaterID;
                             //bar.HMaterNumber = oItemSub.HMaterNumber;
@@ -1663,10 +1721,12 @@
                             bar.HSupID = oItemSub.HSupID;
                             bar.HEndQty = WeiShu;
                             bar.HMTONO = oItemSub.HMTONO;
+                            bar.HISKFPERIOD = oItemSub.HISKFPERIOD;
                             ls2.Add(bar);
                         }
                     }
                 }
+                oCn.Commit();
                 foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub2 in ls2)
                 {
                     if (ClsPub.isLong(oItemSub2.HMaterID) != 0)
@@ -1677,6 +1737,7 @@
                         int SumLen2 = 4;
                         string TM2 = "";
                         double HWXQty = 0;
+                        double HBarcodeQty = ClsPub.isDoule(oItemSub2.HQty);
 
                         LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]) + 1;
                         //
@@ -1728,10 +1789,7 @@
                                 TM2 = "0" + TM2;
                             }
                             bar2.HMaterID = oItemSub2.HMaterID;
-
-
-                            bar2.HBarCode = oItemSub2.HBarCode + "-" + TM2;
-
+                            bar2.HBarCode = oItemSub2.HBarCode.Replace(HBarcodeQty.ToString(), HWXQty.ToString());
                             bar2.HUnitID = oItemSub2.HUnitID;
                             bar2.HQty = HWXQty;
                             bar2.HBatchNo = DBUtility.ClsPub.isStrNull(oItemSub2.HBatchNo);
@@ -1745,6 +1803,7 @@
                             bar2.HSupID = oItemSub2.HSupID;
                             bar2.HEndQty = WeiShu1;
                             bar2.HMTONO = oItemSub2.HMTONO;
+                            bar2.HISKFPERIOD = oItemSub2.HISKFPERIOD;
                             ls3.Add(bar2);
                         }
                     }
@@ -1767,69 +1826,128 @@
                 string HKFDQDate = "";
                 string HWei = "";
                 string HMTONO = "";
+                Int64 HISKFPERIOD = 0;
                 oCn.BeginTran();
-                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls2)
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
                 {
-                    if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    oCn.RunProc($"update Gy_BarCodeBill set  HPrintQty += 1   where HPrintQty = 0 and  HSourceInterID={oItemSub.HSourceInterID} and HSourceEntryID = {oItemSub.HSourceEntryID}");
+                }
+                //澶栫
+                var oItemSubGroup = ls2.GroupBy(x => new { x.HSourceEntryID }).Select(y => new Model.ClsGy_BarCodeBill_WMS_Model { HSourceEntryID = y.Key.HSourceEntryID });
+                foreach (var oitem in oItemSubGroup)
+                {
+                    var SubModel = ls2.Where(x => x.HSourceEntryID == oitem.HSourceEntryID).ToList();
+                    int count = 1;
+                    foreach (var oItemSub in SubModel)
                     {
-                        HBarCode = oItemSub.HBarCode.ToString();
-                        HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
-                        HBarCodeType = "绠卞彿鏉$爜";
-                        HMaterID = ClsPub.isLong(oItemSub.HMaterID);
-                        HUnitID = ClsPub.isLong(oItemSub.HUnitID);
-                        HQty2 = ClsPub.isDoule(oItemSub.HQty);
-                        HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
-                        HSupID = oItemSub.HSupID;
-                        HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
-                        HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
-                        HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
-                        HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
-                        HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
-                        HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
-                        HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
-                        HWei = ClsPub.isStrNull(oItemSub.HEndQty);
-                        oCn.RunProc("insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
-                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
-                                    ") values ("
-                                    + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
-                                    + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')");
-                        oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
+                        if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                        {
+                            HBarCode = oItemSub.HBarCode.ToString();
+                            HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
+                            HBarCodeType = "绠卞彿鏉$爜";
+                            HMaterID = ClsPub.isLong(oItemSub.HMaterID);
+                            HUnitID = ClsPub.isLong(oItemSub.HUnitID);
+                            HQty2 = ClsPub.isDoule(oItemSub.HQty);
+                            HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
+                            HSupID = oItemSub.HSupID;
+                            HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
+                            HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
+                            HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
+                            HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
+                            HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
+                            HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
+                            HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
+                            HISKFPERIOD = ClsPub.isInt(oItemSub.HISKFPERIOD);
+                            HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                            if (FCusName.Contains("澶忓疂"))
+                            {
+                                HBarCode = $"{oItemSub.HMaterID}";
+                                HBarCodeType = "鍝佺鐮乢澶栫";
+                            }
+                            string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
+                                        ",HBatchNo,HBarcodeQtys,HBarcodeNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
+                                        ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO,HProduceDate,HExpiryDate,HISKFPERIOD" +
+                                        ") values ("
+                                        + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
+                                        + "','" + HBatchNo + "','" + SubModel.Count + "','" + count + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
+                                        + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "','"
+                                        + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
+                            oCn.RunProc(sql);
+                            oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
+                            count++;
+                        }
                     }
                 }
-                foreach (Model.ClsGy_BarCodeBill_WMS_Model oItemSub in ls3)
+                //鍐呯
+                var _oItemSubGroup = ls3.GroupBy(x => new { x.HSourceEntryID }).Select(y => new Model.ClsGy_BarCodeBill_WMS_Model { HSourceEntryID = y.Key.HSourceEntryID });
+                foreach (var oitem in _oItemSubGroup)
                 {
-                    if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                    var SubModel = ls3.Where(x => x.HSourceEntryID == oitem.HSourceEntryID).ToList();
+                    int _count = 1;
+                    foreach (var oItemSub in SubModel)
                     {
-                        HBarCode = oItemSub.HBarCode.ToString();
-                        HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
-                        HBarCodeType = "绠卞彿鍐呮潯鐮�";
-                        HMaterID = ClsPub.isLong(oItemSub.HMaterID);
-                        HUnitID = ClsPub.isLong(oItemSub.HUnitID);
-                        HQty2 = ClsPub.isDoule(oItemSub.HQty);
-                        HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
-                        HSupID = oItemSub.HSupID;
-                        HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
-                        HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
-                        HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
-                        HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
-                        HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
-                        HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
-                        HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
-                        HWei = ClsPub.isStrNull(oItemSub.HEndQty);
-                        oCn.RunProc("insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
-                                    ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
-                                    ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO " +
-                                    ") values ("
-                                    + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
-                                    + "','" + HBatchNo + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
-                                    + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "')");
+                        if (ClsPub.isLong(oItemSub.HMaterID) != 0)
+                        {
+                            HBarCode = oItemSub.HBarCode.ToString();
+                            HMTONO = ClsPub.isStrNull(oItemSub.HMTONO);
+                            HBarCodeType = "绠卞彿鍐呮潯鐮�";
+                            HMaterID = ClsPub.isLong(oItemSub.HMaterID);
+                            HUnitID = ClsPub.isLong(oItemSub.HUnitID);
+                            HQty2 = ClsPub.isDoule(oItemSub.HQty);
+                            HBatchNo = ClsPub.isStrNull(oItemSub.HBatchNo);
+                            HSupID = oItemSub.HSupID;
+                            HKFPeriod = ClsPub.isInt(oItemSub.HKFPeriod);
+                            HKFDate = ClsPub.isStrNull(oItemSub.HKFDate);
+                            HKFDQDate = ClsPub.isStrNull(oItemSub.HKFDQDate);
+                            HSourceInterID = ClsPub.isLong(oItemSub.HSourceInterID);
+                            HSourceEntryID = ClsPub.isLong(oItemSub.HSourceEntryID);
+                            HSourceBillNo = ClsPub.isStrNull(oItemSub.HSourceBillNo);
+                            HSourceBillType = ClsPub.isStrNull(oItemSub.HSourceBillType);
+                            HWei = ClsPub.isStrNull(oItemSub.HEndQty);
+                            HISKFPERIOD = ClsPub.isInt(oItemSub.HISKFPERIOD);
+                            if (FCusName.Contains("澶忓疂"))
+                            {
+                                HBarCode = $"{oItemSub.HMaterID}";
+                                HBarCodeType = "鍝佺鐮�";
+                            }
+                            string sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
+                                      ",HBatchNo,HBarcodeQtys,HBarcodeNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
+                                      ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO,HProduceDate,HExpiryDate,HISKFPERIOD" +
+                                      ") values ("
+                                      + linterid.ToString() + ",'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID + "," + HUnitID + "," + HQty2 + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
+                                      + "','" + HBatchNo + "','" + SubModel.Count + "','" + _count + "'," + HSupID + "," + HGroupID + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + HPrintQty + ",'" + HWei + "',1"
+                                      + "," + HSourceInterID + "," + HSourceEntryID + ",'" + HSourceBillNo + "','" + HSourceBillType + "','" + HMTONO + "','" 
+                                      + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
+                            oCn.RunProc(sql);
+                            _count++;
+                        }
                     }
                 }
                 //鏆傛椂鍙洖濉叧鑱旀暟閲�
-                oCn.RunProc("exec H_p_SRM_BarCodeBill_Update_UpdateBillRelateData " + linterid.ToString());
+                foreach (Model.ClsGy_MaterialList_WMS_Model oItemSub in ls)
+                {
+                    if (oItemSub.HQty == 0)
+                        continue;
+                    //鏇存柊鏉$爜妗f 璇ユ簮鍗曞叾瀹冩潯鐮侀粯璁ゅ凡缁忔墦鍗拌繃涓�娆�
+                    //鏇存柊 宸叉墦鍗版暟閲�
+                    if (oItemSub.HSourceBillType == "1102")
+                    {
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
+                        string sql = string.Empty;
+                        sql = string.Format(@"
+update t1 set  
+t1.HBarcodeCount = 
+isnull((select sum(HQty)from Gy_BarCodeBill where HSourceInterID = t1.HInterID and HSourceEntryID = t1.HEntryID and HBarCodeType ='{2}'),0)
+from Cg_POOrderBillSub t1 
+where t1.HInterID = {0} and t1.HEntryID ={1}", oItemSub.HSourceInterID, oItemSub.HSourceEntryID, _HBarCodeType);
+                        oCn.RunProc(sql);
+                    }
+                }
                 oCn.Commit();
+
             }
             catch (Exception e)
             {
@@ -1956,12 +2074,20 @@
         }
 
         [Route("DeltetBarCodeBill")]
-        [HttpGet]
-        public object DeltetBarCodeBill(string HInterID, string HUserName)
+        [HttpPost]
+        public object DeltetBarCodeBill([FromBody] JObject oData)
         {
             SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
             try
             {
+                var _value = oData["oData"].ToString();
+                string msg1 = _value.ToString();
+                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+                string HInter = sArray[0].ToString();
+                string HInterID = HInter.Replace("\"", "");
+                string HUserName = sArray[1].ToString();
+
+                string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                 string sql = "select HItemID,HBarCode,HSourceInterID,HSourceEntryID,HQty,HBarCodeType,HSourceBillType from Gy_BarCodeBill where  HItemID in(" + HInterID + ") ";
                 //LogService.Write("鍒犻櫎sql:" + sql);
                 oCN.BeginTran();
@@ -1970,9 +2096,12 @@
                 {
                     foreach (DataRow dr in dt.Rows)
                     {
+                        string _HBarCodeType = "绠卞彿鏉$爜";
+                        if (FCusName.Contains("澶忓疂"))
+                            _HBarCodeType = "鍝佺鐮�";
                         WebAPIController.Add_Log("鏉$爜妗f鍒犻櫎", HUserName, "鍗曞彿" + dr["HBarCode"].ToString());
                         //鍙嶅啓鎵撳嵃鏁伴噺鍒伴噰璐鍗曞瓙琛�
-                        if (dr["HBarCodeType"].ToString() == "绠卞彿鍐呮潯鐮�" && dr["HSourceBillType"].ToString() == "1102")
+                        if (dr["HBarCodeType"].ToString() == _HBarCodeType && dr["HSourceBillType"].ToString() == "1102")
                             oCN.RunProc($"update Cg_POOrderBillSub set HBarcodeCount -= {dr["HQty"]} where  HInterID ={dr["HSourceInterID"]} and  HEntryID ={dr["HSourceEntryID"]}");
                         //鍙嶅啓鎵撳嵃鏁伴噺鍒板澶栬鍗�
                         if (dr["HBarCodeType"].ToString() == "绠卞彿鍐呮潯鐮�" && dr["HSourceBillType"].ToString() == "1601")
@@ -1983,7 +2112,7 @@
                         //oCN.RunProc($"update WW_EntrustOrderBillSub set HBarcodeCount -= {dr["HQty"]} where  HInterID ={dr["HSourceInterID"]} and  HEntryID ={dr["HSourceEntryID"]}");
                     }
                 }
-                //oCN.RunProc("Delete From Gy_BarCodeBill where HItemID in(" + HInterID + ") ");
+                oCN.RunProc("Delete From Gy_BarCodeBill where HItemID in(" + HInterID + ") ");
                 oCN.Commit();
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;

--
Gitblit v1.9.1