From 01b5ef474e1a5d8dc682b64312f23bdbb0fdf3a7 Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期三, 12 四月 2023 16:26:48 +0800
Subject: [PATCH] 1.采购到货接口修改 2.停用设备过滤

---
 VueWebApi/DLL/DAL/AppPurchManagementDAL.cs |  291 +++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 248 insertions(+), 43 deletions(-)

diff --git a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
index 5d684bd..5897eb7 100644
--- a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
@@ -36,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 and A.status<>'CLOSED'" + search;
+                        where (isnull(B.quantity,0)-isnull(B.countarrivalquantity,0)+isnull(B.countreturnquantity,0))>0 and A.status<>'CLOSED'" + search;
                 dynamicParams.Add("@purchordercode", purchordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 if (data.Rows.Count > 0)
@@ -80,7 +80,7 @@
                         left  join TUom U on M.uom_code=U.code
                         left  join TCustomer C on B.customercode=C.code
                         left  join TOrganization T on A.departmentcode=T.org_code
-                        where B.quantity>B.countarrivalquantity and A.ordercode=@purchordercode";
+                        where (isnull(B.quantity,0)-isnull(B.countarrivalquantity,0)+isnull(B.countreturnquantity,0))>0 and A.ordercode=@purchordercode";
                 dynamicParams.Add("@purchordercode", purchordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 if (data.Rows.Count > 0)
@@ -116,7 +116,7 @@
         #endregion
 
         #region[閲囪喘鍒拌揣锛氭彁浜
-        public static ToMessage MesAppPurchOrderSave(string purordercode, string orderstaus, string username, List<AppPurchOrderSave> json)
+        public static ToMessage MesAppPurchOrderSave(string purordercode, string username, List<AppPurchOrderSave> json)
         {
             var sql = "";
             string djwo = "", numvalue = "";
@@ -159,7 +159,7 @@
                         hbillno = djwo,
                         hdate = DateTime.Now.ToString(),
                         hacceptdate = hacceptdate == "" ? null : hacceptdate,
-                        hbillstaus = orderstaus,
+                        hbillstaus = "NEW",
                         hdepartmentcode = dpartment,
                         hcustomercode = customercode,
                         hsourcebillno = purordercode,
@@ -234,17 +234,6 @@
                         }
                     });
                 }
-                //鏇存柊閲囪喘璁㈠崟涓昏〃锛氳鍗曠姸鎬�
-                sql = @"update T_PurchaseOrder set status=@status where ordercode=@ordercode";
-                list.Add(new
-                {
-                    str = sql,
-                    parm = new
-                    {
-                        status = orderstaus,
-                        ordercode = purordercode
-                    }
-                });
                 bool aa = DapperHelper.DoTransaction(list);
                 if (aa)
                 {
@@ -274,16 +263,25 @@
 
 
         #region[閲囪喘鍏ュ簱閫夋嫨鏈夊埌璐ч噰璐鍗昡
-        public static ToMessage MesAppPurchInStorSelectCGOrder()
+        public static ToMessage MesAppPurchInStorSelectCGOrder(string purchordercode)
         {
             string sql = "";
+            string search = "";
             var dynamicParams = new DynamicParameters();
             try
             {
+                if (purchordercode != "" && purchordercode != null) //璁㈠崟鍙蜂笉涓虹┖
+                {
+                    search += " and AA.ordercode like '%'+@purchordercode+'%' ";
+                }
                 //鏈夊埌璐ф垨鑰呴儴鍒嗗叆搴撶殑閲囪喘璁㈠崟
-                sql = @"select distinct A.ordercode   from T_PurchaseOrder A
+                sql = @"select distinct AA.ordercode  from(
+                        select A.ordercode,B.hbillstaus,S.hpartcode,MAX(S.hplanqty) as hplanqty,SUM(S.hqty) as hqty,SUM(S.hinqty) as hinqty,SUM(S.hreturnqty) as hreturnqty
+                        from T_PurchaseOrder A
                         inner join T_PurchaseArrivalOrder B on A.ordercode=B.hsourcebillno
-                        where B.hbillstaus in('BINARIVE','INARIVE','BINSTOG')";
+                        inner join T_PurchaseArrivalOrder_sub S on B.hbillno=S.hbillno
+                        group by A.ordercode,B.hbillstaus,S.hpartcode
+                        ) as AA where  (isnull(AA.hplanqty,0)-isnull(AA.hqty,0)+isnull(AA.hreturnqty,0))>0 and AA.hbillstaus='NEW' " + search;
                 var data = DapperHelper.selecttable(sql);
                 if (data.Rows.Count > 0)
                 {
@@ -322,7 +320,7 @@
                         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
+                        where B.hbillstaus='NEW' and A.ordercode=@ordercode
                         group by A.ordercode,M.partcode,M.partname,M.partspec,A.customercode,A.departmentcode";
                 dynamicParams.Add("@ordercode", ordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -472,7 +470,19 @@
                     //鏌ヨ姹囨�绘爣绛句俊鎭�
                     for (int j = 0; j < arra[i]["labcont"].Count(); j++)//寰幆鑾峰彇鏍囩淇℃伅
                     {
-
+                        //鏇存柊鏉$爜琛ㄤ粨搴撱�佸簱浣嶄俊鎭�
+                        sql = @"update T_BarCodeBill set storehouse_code=@storehouse_code,location_code=@location_code where hsourcebillno=@hsourcebillno and hbarcode=@hbarcode";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                storehouse_code = arra[i]["storehousecode"].ToString(),
+                                location_code = arra[i]["warehousecode"].ToString(),
+                                hsourcebillno = ordercode,
+                                hbarcode = arra[i]["labcont"][j]["labcode"].ToString()
+                            }
+                        });
                         //鏇存柊鍒拌揣鍗曞瓙琛ㄥ叆搴撴暟閲�
                         sql = @"update T_PurchaseArrivalOrder_sub set hinqty=isnull(hinqty,0)+@inqty where hbillno=@hbillno and hpartcode=@hpartcode";
                         list.Add(new
@@ -567,27 +577,6 @@
                      * **********************
                     **********************/
                 }
-                //鏇存柊閲囪喘瀹氬崟鐘舵��(閮ㄥ垎鍏ュ簱銆佸凡鍏ュ簱)
-                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)
@@ -630,9 +619,9 @@
                     search += " and A.ordercode like '%'+@purchordercode+'%' ";
                 }
                 //鏌ヨ鏈叧闂笖鏈夊埌璐х殑閲囪喘璁㈠崟
-                sql = @"select distinct A.ordercode  from T_PurchaseOrder A
+                sql = @"select distinct A.id,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;
+                        where (isnull(B.countarrivalquantity,0)-isnull(B.countreturnquantity,0))>0 and A.status<>'CLOSED'" + search;
                 dynamicParams.Add("@purchordercode", purchordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
                 if (data.Rows.Count > 0)
@@ -700,5 +689,221 @@
         }
         #endregion
 
+        #region[閲囪喘閫�璐у崟锛氭壂鎻忔爣绛綸
+        public static ToMessage MesAppPurchReturnInStorScanLabCode(string ordercode, string partcode, string labcode)
+        {
+            string sql = "";
+            string search = "";
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                //鏍规嵁閲囪喘璁㈠崟鍙枫�佺墿鏂欑紪鐮併�佹爣绛炬潯鐮佹煡鎵炬爣绛句俊鎭�
+                sql = @"select A.hbarcode,A.hcustomercode,C.name as hcustomercode,
+                       A.hbatchno,A.qualitystatus,A.location_code,L.name as location_name,A.hqty  
+                       from T_BarCodeBill A
+                       left join TCustomer C on A.hcustomercode=C.code
+                       left join T_Sec_Loca L on A.location_code=L.code
+                       where A.rightcode=@rightcode and A.hbilltype=@hbilltype and A.hbarcodestatus='Y' 
+                       and  A.hsourcebillno=@hsourcebillno and A.hmaterialcode=@hmaterialcode and A.hbarcode=@labcode";
+                dynamicParams.Add("@rightcode", "2060");
+                dynamicParams.Add("@hbilltype", "1103");
+                dynamicParams.Add("@hsourcebillno", ordercode);
+                dynamicParams.Add("@hmaterialcode", partcode);
+                dynamicParams.Add("@labcode", labcode);
+                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 MesAppPurchReturnInStorSave(string orderid, 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("2074");  //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  T_PurchaseReturnOrder(orderdate,ordercode,status,departmentcode,customercode,saleorderid,saleordercode,lm_user,lm_date) 
+                                values(@orderdate,@ordercode,@status,@departmentcode,@customercode,@saleorderid,@saleordercode,@lm_user,@lm_date)";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        orderdate= datetime,
+                        ordercode= djwo,
+                        status="NEW",
+                        departmentcode= arra[0]["departmentcode"].ToString(),
+                        customercode= arra[0]["customercode"].ToString(),
+                        saleorderid= orderid,
+                        saleordercode=ordercode,
+                        lm_user= username,
+                        lm_date= datetime
+                    }
+                });
+                //鏍规嵁婧愬崟+鐗╂枡鏌ヨ閲囪喘璁㈠崟鍒拌揣鎬绘暟銆佸叆搴撴�绘暟
+                sql = @"select sum(B.quantity) as quantity,sum(B.countarrivalquantity) as countarrivalquantity,
+                        sum(B.countInquantity) as countInquantity,sum(B.countreturnquantity) as countreturnquantity
+                        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()); //閲囪喘璁㈠崟绱鍏ュ簱鏁伴噺
+                decimal countreturnquantity = decimal.Parse(data0.Rows[0]["countreturnquantity"].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 hreturnqty=isnull(hreturnqty,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 countreturnquantity=isnull(countreturnquantity,0)+@countreturnquantity
+                            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(),
+                            countreturnquantity = partlabqty
+                        }
+                    });
+
+                    //鍐欏叆閲囪喘閫�璐у崟瀛愯〃
+                    sql = @"insert into  T_PurchaseReturnOrder_sub(purchaseorder_code,labcode,rownumber,materiel_code,customercode,quantity,batchno) 
+                                values(@purchaseorder_code,@labcode,@rownumber,@materiel_code,@customercode,@quantity,@batchno)";
+                    labcode = string.Format("'{0}'", labcode.Substring(0, labcode.Length - 1).Replace(",", "','"));
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            purchaseorder_code = djwo,
+                            labcode = labcode,
+                            rownumber = i,
+                            materiel_code = arra[i]["partcode"].ToString(),
+                            customercode = arra[0]["customercode"].ToString(),
+                            quantity = 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
+                            }
+                        });
+                    }
+                    /*鍐欏叆ERP閲囪喘閫�璐у崟************
+                     * ***********************
+                     * **********************
+                    **********************/
+                }
+
+                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
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3