From a667d4159bb3f1ba909b94d5b5dd7c6eb28e7197 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期五, 07 四月 2023 09:48:30 +0800
Subject: [PATCH] 1.添加质检方案基础资料 2.采购到货接口调整 3.入厂检验扫描标签添加标签判断 4.ERP订单下达生成工单接口修改 5.编码规则接口修改 6.采购退货查询采购订单接口开发、订单查找物料接口开发

---
 VueWebApi/DLL/DAL/AppPurchManagementDAL.cs |  329 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 313 insertions(+), 16 deletions(-)

diff --git a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
index c3c3b74..5d684bd 100644
--- a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
@@ -1,4 +1,5 @@
 锘縰sing Dapper;
+using Newtonsoft.Json.Linq;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -35,7 +36,7 @@
                 //鏌ヨ鏈叧闂笖鏈叏閮ㄥ埌璐х殑閲囪喘璁㈠崟
                 sql = @"select distinct A.ordercode  from T_PurchaseOrder A
                         inner join T_PurchaseOrder_sub B on A.ordercode=B.purchaseorder_code
-                        where B.countarrivalquantity<quantity" + search;
+                        where B.countarrivalquantity<quantity and A.status<>'CLOSED'" + search;
                 dynamicParams.Add("@purchordercode", purchordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 if (data.Rows.Count > 0)
@@ -109,7 +110,7 @@
         #region[閲囪喘鍒拌揣锛氱敓鎴愮郴缁熸潯鐮乚
         public static ToMessage MesAppPurchOrderLabelBarCode(string partcode, string arrivalqty, string onelableqty)
         {
-            mes = AppLableBarCode.EncodingSeach("2060", partcode, arrivalqty, onelableqty);
+            mes = AppLableBarCode.EncodingSeach("2018", partcode, arrivalqty, onelableqty);
             return mes;
         }
         #endregion
@@ -157,7 +158,7 @@
                     {
                         hbillno = djwo,
                         hdate = DateTime.Now.ToString(),
-                        hacceptdate =hacceptdate==""?null:hacceptdate,
+                        hacceptdate = hacceptdate == "" ? null : hacceptdate,
                         hbillstaus = orderstaus,
                         hdepartmentcode = dpartment,
                         hcustomercode = customercode,
@@ -178,7 +179,7 @@
                         parm = new
                         {
                             hbillno = djwo,
-                            rownumber=json[i].rownumber,
+                            rownumber = json[i].rownumber,
                             hpartcode = json[i].hpartcode,
                             hplanqty = decimal.Parse(json[i].hplanqty),
                             hqty = decimal.Parse(json[i].hqty),
@@ -192,8 +193,8 @@
                     for (int j = 0; j < json[i].children.Count; j++)
                     {
                         //鍐欏叆鏉$爜妗f琛�
-                        sql = @"insert into T_BarCodeBill(rightcode,hbillno,hbilltype,hbarcode,hbarcodestatus,hbarcodetype,hmaterialcode,hqty,hbatchno,hcustomercode,hdeptcode,hsourcebillno,hsourcebilltype,barcodeposition,lm_user,lm_date) 
-                        values(@rightcode,@hbillno,@hbilltype,@hbarcode,@hbarcodestatus,@hbarcodetype,@hmaterialcode,@hqty,@hbatchno,@hcustomercode,@hdeptcode,@hsourcebillno,@hsourcebilltype,@barcodeposition,@lm_user,@lm_date)";
+                        sql = @"insert into T_BarCodeBill(rightcode,hbillno,hbilltype,hbarcode,qualitystatus,hbarcodestatus,hbarcodetype,hmaterialcode,hqty,hbatchno,hcustomercode,hdeptcode,hsourcebillno,hsourcebilltype,barcodeposition,lm_user,lm_date) 
+                        values(@rightcode,@hbillno,@hbilltype,@hbarcode,@qualitystatus,@hbarcodestatus,@hbarcodetype,@hmaterialcode,@hqty,@hbatchno,@hcustomercode,@hdeptcode,@hsourcebillno,@hsourcebilltype,@barcodeposition,@lm_user,@lm_date)";
                         list.Add(new
                         {
                             str = sql,
@@ -203,6 +204,7 @@
                                 hbillno = djwo,
                                 hbilltype = "1103", //閲囪喘鍒拌揣鍗曠被鍨�
                                 hbarcode = json[i].children[j].labcode,
+                                qualitystatus= json[i].hischeck=="Y"? "TS" : "CS",
                                 hbarcodestatus = "Y",
                                 hbarcodetype = "P",
                                 hmaterialcode = json[i].children[j].partnumber,
@@ -212,7 +214,7 @@
                                 hdeptcode = dpartment,
                                 hsourcebillno = purordercode,
                                 hsourcebilltype = "1102",
-                                barcodeposition="2060;閲囪喘鍒拌揣",
+                                barcodeposition = "2060;閲囪喘鍒拌揣",
                                 lm_user = username,
                                 lm_date = DateTime.Now.ToString()
                             }
@@ -227,8 +229,8 @@
                         {
                             purordercode = purordercode,
                             materiel_code = json[i].hpartcode,
-                            rownumber=json[i].rownumber,
-                            hqty=decimal.Parse(json[i].hqty)
+                            rownumber = json[i].rownumber,
+                            hqty = decimal.Parse(json[i].hqty)
                         }
                     });
                 }
@@ -315,13 +317,13 @@
             try
             {
                 //閫夋嫨閲囪喘璁㈠崟甯﹀嚭璁㈠崟涓嬫湁鍒拌揣鐨勭墿鏂欎俊鎭�
-                sql = @"select A.ordercode,M.partcode,M.partname,M.partspec,avg(S.hplanqty) as hplanqty,sum(S.hqty) as hqty 
+                sql = @"select A.ordercode,M.partcode,M.partname,M.partspec,A.customercode,A.departmentcode,avg(S.hplanqty) as hplanqty,sum(S.hqty) as hqty 
                         from T_PurchaseOrder A
                         inner join T_PurchaseArrivalOrder B on A.ordercode=B.hsourcebillno
                         inner join T_PurchaseArrivalOrder_sub S on B.hbillno=S.hbillno
                         left  join TMateriel_Info M on S.hpartcode=M.partcode
                         where B.hbillstaus in('BINARIVE','INARIVE','BINSTOG') and A.ordercode=@ordercode
-                        group by A.ordercode,M.partcode,M.partname,M.partspec";
+                        group by A.ordercode,M.partcode,M.partname,M.partspec,A.customercode,A.departmentcode";
                 dynamicParams.Add("@ordercode", ordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 if (data.Rows.Count > 0)
@@ -349,15 +351,15 @@
         #endregion
 
         #region[閲囪喘鍏ュ簱鎵弿鏍囩鏉$爜甯﹀嚭鍒拌揣鍗曚俊鎭痌
-        public static ToMessage MesAppPurchInStorScanLabCode(string labcode,string ordercode)
+        public static ToMessage MesAppPurchInStorScanLabCode(string labcode, string ordercode)
         {
             string sql = "";
             var dynamicParams = new DynamicParameters();
             try
             {
                 //鍒ゆ柇鏉$爜鐘舵��
-                mes = LabCodeStatusMessage.LabCodeStatus("2060", "1103",labcode);//鍔熻兘缂栧彿銆佸崟鎹被鍨嬬紪鐮併�佹爣绛剧紪鐮�
-                if (mes.code == "300") 
+                mes = LabCodeStatusMessage.LabCodeStatus("2060", "1103", labcode);//鍔熻兘缂栧彿銆佸崟鎹被鍨嬬紪鐮併�佹爣绛剧紪鐮�
+                if (mes.code == "300")
                 {
                     return mes;
                 }
@@ -365,10 +367,10 @@
                 sql = @"select *   from T_BarCodeBill where hsourcebillno=@ordercode";
                 dynamicParams.Add("@ordercode", ordercode);
                 var data0 = DapperHelper.selectdata(sql, dynamicParams);
-                if (data0.Rows.Count < 0) 
+                if (data0.Rows.Count < 0)
                 {
                     mes.code = "300";
-                    mes.Message = "褰撳墠鏉$爜涓嶆槸閲囪喘璁㈠崟銆�"+ ordercode + "銆戠敓鎴愭潯鐮�!";
+                    mes.Message = "褰撳墠鏉$爜涓嶆槸閲囪喘璁㈠崟銆�" + ordercode + "銆戠敓鎴愭潯鐮�!";
                     mes.data = null;
                     return mes;
                 }
@@ -403,5 +405,300 @@
         }
         #endregion
 
+        #region[閲囪喘鍏ュ簱鎻愪氦]
+        public static ToMessage MesAppPurchInStorSave(string ordercode, string username, string incontent)
+        {
+            var sql = "";
+            string djwo = "", numvalue = "";
+            List<object> list = new List<object>();
+            List<ObjectData> obj = new List<ObjectData>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                string datetime = DateTime.Now.ToString(); //鑾峰彇绯荤粺鏃堕棿
+                mes = SeachEncode.EncodingSeach("2061");  //APP绔噰璐叆搴撶敓鎴愬崟鍙�
+                if (mes.code == "300")
+                {
+                    return mes;
+                }
+                else
+                {
+                    List<string> wo = (List<string>)mes.data;
+                    djwo = wo[0].ToString(); //鑾峰彇鍗曞彿
+                    numvalue = wo[1].ToString(); //鑾峰彇娴佹按鍙�
+                }
+                //鑾峰彇鎻愪氦淇℃伅
+                JArray arra = (JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(incontent);
+                list.Clear();
+                //鍐欏叆鍏ュ簱璁板綍涓昏〃
+                sql = @"insert into  TK_WMS_Inwh_Main(docu_typecode,hbillno,hsoucenillno,status,hcustomer,hdempart,lm_user,lm_date) 
+                                values(@docu_typecode,@hbillno,@hsoucenillno,@status,@hcustomer,@hdempart,@lm_user,@lm_date)";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        docu_typecode = "1201",
+                        hbillno = djwo,
+                        hsoucenillno = ordercode,
+                        status = "NEW",
+                        hcustomer = arra[0]["customercode"].ToString(),
+                        hdempart = arra[0]["departmentcode"].ToString(),
+                        lm_user = username,
+                        lm_date = datetime
+                    }
+                });
+                //鏍规嵁婧愬崟+鐗╂枡鏌ヨ閲囪喘璁㈠崟鍒拌揣鎬绘暟銆佸叆搴撴�绘暟
+                sql = @"select sum(B.quantity) as quantity,sum(B.countarrivalquantity) as countarrivalquantity,
+                        sum(B.countInquantity) as countInquantity
+                        from T_PurchaseOrder A
+                        inner join T_PurchaseOrder_sub B on A.ordercode=B.purchaseorder_code
+                        where  ordercode=@ordercode";
+                dynamicParams.Add("@ordercode", ordercode);
+                var data0 = DapperHelper.selectdata(sql, dynamicParams);
+                decimal quantity = decimal.Parse(data0.Rows[0]["quantity"].ToString()); //閲囪喘璁㈠崟绱浠诲姟鏁伴噺
+                decimal countarrivalquantity = decimal.Parse(data0.Rows[0]["countarrivalquantity"].ToString()); //閲囪喘璁㈠崟绱鍒拌揣鏁伴噺
+                decimal countInquantity = decimal.Parse(data0.Rows[0]["countInquantity"].ToString()); //閲囪喘璁㈠崟绱鍏ュ簱鏁伴噺
+
+                string storg = "";//閲囪喘璁㈠崟鍏ュ簱鐘舵��
+                decimal partlabqty = 0; //褰撳墠鏍囩绱鏁伴噺
+
+                for (int i = 1; i <= arra.Count; i++)//寰幆鑾峰彇鐗╂枡淇℃伅
+                {
+                    string labcode = "";//鏍囩淇℃伅
+                    decimal suminqty = 0; //鍗曟爣绛惧叆搴撴�绘暟閲�
+                    string batchno = ""; //鎵规鍙�
+                    
+                    //鏌ヨ姹囨�绘爣绛句俊鎭�
+                    for (int j = 0; j < arra[i]["labcont"].Count(); j++)//寰幆鑾峰彇鏍囩淇℃伅
+                    {
+
+                        //鏇存柊鍒拌揣鍗曞瓙琛ㄥ叆搴撴暟閲�
+                        sql = @"update T_PurchaseArrivalOrder_sub set hinqty=isnull(hinqty,0)+@inqty where hbillno=@hbillno and hpartcode=@hpartcode";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                hbillno = arra[i]["labcont"][j]["arrivelorder"].ToString(),
+                                hpartcode = arra[i]["partcode"].ToString(),
+                                hinqty = decimal.Parse(arra[i]["labcont"][j]["qty"].ToString())
+                            }
+                        });
+                        labcode = labcode + arra[i]["labcont"][j]["labcode"].ToString() + ",";
+                        suminqty = suminqty + decimal.Parse(arra[i]["labcont"][j]["qty"].ToString());
+                        partlabqty = partlabqty + decimal.Parse(arra[i]["labcont"][j]["qty"].ToString());
+                        batchno = arra[i]["labcont"][j]["batch"].ToString();
+                    }
+
+                    //鏇存柊閲囪喘璁㈠崟瀛愯〃鍏ュ簱鏁伴噺
+                    sql = @"update T_PurchaseOrder_sub set countInquantity=isnull(countInquantity,0)+@countInquantity 
+                            where purchaseorder_code=@purchaseorder_code and materiel_code=@materiel_code";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            purchaseorder_code = ordercode,
+                            materiel_code = arra[i]["partcode"].ToString(),
+                            countInquantity = partlabqty
+                        }
+                    });
+
+                    //鍐欏叆閲囪喘鍏ュ簱鍗曞瓙琛�
+                    sql = @"insert into  TK_WMS_Inwh_Sub(hbillno,labcode,rownumber,materiel_code,storehouse_code,location_code,qty,batchno) 
+                                values(@hbillno,@labcode,@rownumber,@materiel_code,@storehouse_code,@location_code,@qty,@batchno)";
+                    labcode = string.Format("'{0}'", labcode.Substring(0, labcode.Length - 1).Replace(",", "','"));
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            hbillno = djwo,
+                            labcode = labcode,
+                            rownumber = i,
+                            materiel_code = arra[i]["partcode"].ToString(),
+                            storehouse_code = arra[i]["storehousecode"].ToString(),
+                            location_code = arra[i]["warehousecode"].ToString(),
+                            qty = suminqty,
+                            batchno = batchno
+                        }
+                    });
+                    //鍐欏叆搴撳瓨琛ㄥ墠鏌ヨ褰撳墠鐗╂枡鍦ㄥ簱瀛樿〃涓槸鍚﹀瓨鍦�,鍐欏叆鎴栨洿鏂板簱瀛樿〃
+                    sql = @"select *  from TK_WMS_Stock where materiel_code=@materiel_code";
+                    dynamicParams.Add("@materiel_code", arra[i]["partcode"].ToString());
+                    var data1 = DapperHelper.selectdata(sql, dynamicParams);
+                    if (data1.Rows.Count > 0)
+                    {
+                        sql = @"update TK_WMS_Stock set qty=qty+@suminqty 
+                                where materiel_code=@materiel_code";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                materiel_code = arra[i]["partcode"].ToString(),
+                                suminqty = suminqty
+                            }
+                        });
+                    }
+                    else 
+                    {
+                        sql = @"insert into TK_WMS_Stock(materiel_code,batchno,storehouse_code,location_code,customercode,qty,lm_user,lm_date)
+                                values(materiel_code,batchno,storehouse_code,location_code,customercode,qty,lm_user,lm_date)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                materiel_code = arra[i]["partcode"].ToString(),
+                                batchno = batchno,
+                                storehouse_code= arra[i]["storehousecode"].ToString(),
+                                location_code= arra[i]["warehousecode"].ToString(),
+                                customercode= arra[i]["customercode"].ToString(),
+                                qty= suminqty,
+                                lm_user=username,
+                                lm_date= datetime,
+                            }
+                        });
+                    }
+                    /*鍐欏叆ERP閲囪喘鍏ュ簱鍗�************
+                     * ***********************
+                     * **********************
+                    **********************/
+                }
+                //鏇存柊閲囪喘瀹氬崟鐘舵��(閮ㄥ垎鍏ュ簱銆佸凡鍏ュ簱)
+                if ((countInquantity + partlabqty) < countarrivalquantity) //褰撳墠閲囪喘璁㈠崟绱宸插叆搴�+鏈鎬诲叆搴�<褰撳墠閲囪喘璁㈠崟绱鍒拌揣=閮ㄥ垎鍏ュ簱
+                {
+                    storg = "BINSTOG";
+                }
+                else
+                {
+                    storg = "INSTOG";
+                }
+                //鏇存柊閲囪喘璁㈠崟涓昏〃鍗曟嵁鐘舵��
+                sql = @"update T_PurchaseOrder set status=@storg 
+                            where ordercode=@ordercode";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        ordercode = ordercode,
+                        storg = storg
+                    }
+                });
+
+                bool aa = DapperHelper.DoTransaction(list);
+                if (aa)
+                {
+                    mes.code = "200";
+                    mes.count = 0;
+                    mes.Message = "鎿嶄綔鎴愬姛!";
+                    mes.data = null;
+                }
+                else
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "鎿嶄綔澶辫触!";
+                    mes.data = null;
+                }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+
+        #region[閲囪喘閫�璐э細鑾峰彇閲囪喘璁㈠崟鍒楄〃(宸插埌璐х殑閲囪喘璁㈠崟)]
+        public static ToMessage MesAppPurchaseReturnOrderSearch(string purchordercode)
+        {
+            string sql = "";
+            string search = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                if (purchordercode != "" && purchordercode != null) //璁㈠崟鍙蜂笉涓虹┖
+                {
+                    search += " and A.ordercode like '%'+@purchordercode+'%' ";
+                }
+                //鏌ヨ鏈叧闂笖鏈夊埌璐х殑閲囪喘璁㈠崟
+                sql = @"select distinct A.ordercode  from T_PurchaseOrder A
+                        inner join T_PurchaseOrder_sub B on A.ordercode=B.purchaseorder_code
+                        where B.countarrivalquantity<=quantity and A.status<>'CLOSED'" + search;
+                dynamicParams.Add("@purchordercode", purchordercode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "200";
+                    mes.Message = "鏌ヨ鎴愬姛!";
+                    mes.data = data;
+                }
+                else
+                {
+                    mes.code = "300";
+                    mes.Message = "鏃犺鍗曟暟鎹�!";
+                    mes.data = null;
+                }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
+        #region[閲囪喘閫�璐э細閫夋嫨閲囪喘璁㈠崟鑾峰彇鐗╂枡淇℃伅]
+        public static ToMessage MesAppPurchReturnOrderPartSearch(string purchordercode)
+        {
+            string sql = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鏍规嵁閲囪喘璁㈠崟鍙锋煡璇㈤潪鍏抽棴鐘舵�佷笅鏈夊埌璐т笖鍒拌揣鏁伴噺澶т簬0鐨勭墿鏂�
+                sql = @"select B.rownumber, B.materiel_code as partcode,M.partname,M.partspec,
+                        B.quantity,B.countarrivalquantity,U.code as uomcode,U.name as uomname
+                        from T_PurchaseOrder A
+                        inner join T_PurchaseOrder_sub B on A.ordercode=B.purchaseorder_code
+                        left  join TMateriel_Info M on B.materiel_code=M.partcode
+                        left  join TUom U on M.uom_code=U.code
+                        where B.countarrivalquantity>0 and A.status<>'CLOSED' and A.ordercode=@purchordercode";
+                dynamicParams.Add("@purchordercode", purchordercode);
+                var data = DapperHelper.selectdata(sql, dynamicParams);
+                if (data.Rows.Count > 0)
+                {
+                    mes.code = "200";
+                    mes.Message = "鏌ヨ鎴愬姛!";
+                    mes.data = data;
+                }
+                else
+                {
+                    mes.code = "300";
+                    mes.Message = "鏆傛棤鐗╂枡鏁版嵁!";
+                    mes.data = null;
+                }
+            }
+            catch (Exception e)
+            {
+                mes.code = "300";
+                mes.count = 0;
+                mes.Message = e.Message;
+                mes.data = null;
+            }
+            return mes;
+        }
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3