From 5ac69a2a0e5a0f1433b4497bc5273bdae656221c Mon Sep 17 00:00:00 2001
From: yl <ykxkd@outlook.com>
Date: 星期二, 07 二月 2023 16:53:18 +0800
Subject: [PATCH] 采购到货生成条码、采购到货提交接口

---
 VueWebApi/DLL/DAL/AppPurchManagementDAL.cs |  164 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 160 insertions(+), 4 deletions(-)

diff --git a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
index fc7f4eb..3d116af 100644
--- a/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
+++ b/VueWebApi/DLL/DAL/AppPurchManagementDAL.cs
@@ -5,6 +5,7 @@
 using System.Data.SqlClient;
 using System.Linq;
 using System.Web;
+using VueWebApi.Models;
 using VueWebApi.Tools;
 
 namespace VueWebApi.DLL.DAL
@@ -69,14 +70,15 @@
             try
             {
                 //鏍规嵁閲囪喘璁㈠崟鍙锋煡璇㈢墿鏂欎俊鎭紝渚涘簲鍟嗕俊鎭�
-                sql = @"select B.materiel_code as partcode,M.partname,M.partspec,M.is_batchno,
-                        B.quantity,B.customercode,C.name as customername,U.code as uomcode,U.name as uomname,
-                        A.ordercode,B.countarrivalquantity  
+                sql = @"select B.rownumber, B.materiel_code as partcode,M.partname,M.partspec,M.is_batchno,
+                        B.quantity,B.customercode,C.name as customername,A.departmentcode,T.org_name as departmentname,U.code as uomcode,U.name as uomname,
+                        A.ordercode,B.countarrivalquantity,A.acceptdate  
                         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
                         left  join TCustomer C on B.customercode=C.code
+                        left  join TOrganization T on A.departmentcode=T.org_code
                         where A.ordercode=@purchordercode";
                 dynamicParams.Add("@purchordercode", purchordercode);
                 var data = DapperHelper.selectdata(sql, dynamicParams);
@@ -107,7 +109,161 @@
         #region[閲囪喘鍒拌揣锛氱敓鎴愮郴缁熸潯鐮乚
         public static ToMessage MesAppPurchOrderLabelBarCode(string partcode, string arrivalqty, string onelableqty)
         {
-            mes = AppLableBarCode.EncodingSeach("2060",partcode, arrivalqty, onelableqty);
+            mes = AppLableBarCode.EncodingSeach("2060", partcode, arrivalqty, onelableqty);
+            return mes;
+        }
+        #endregion
+
+        #region[閲囪喘鍒拌揣锛氭彁浜
+        public static ToMessage MesAppPurchOrderSave(string purordercode, string orderstaus, string username, List<AppPurchOrderSave> json)
+        {
+            var sql = "";
+            string djwo = "", numvalue = "";
+            List<object> list = new List<object>();
+            var dynamicParams = new DynamicParameters();
+            try
+            {
+                list.Clear();
+                mes = SeachEncode.EncodingSeach("2060");  //APP绔噰璐埌璐х敓鎴愬崟鍙�
+                if (mes.code == "300")
+                {
+                    return mes;
+                }
+                else
+                {
+                    List<string> wo = (List<string>)mes.data;
+                    djwo = wo[0].ToString(); //鑾峰彇鍗曞彿
+                    numvalue = wo[1].ToString(); //鑾峰彇娴佹按鍙�
+                }
+                if (json == null || json.Count <= 0)
+                {
+                    mes.code = "300";
+                    mes.count = 0;
+                    mes.Message = "鐗╂枡淇℃伅涓嶈兘涓虹┖!";
+                    mes.data = null;
+                    return mes;
+                }
+                //Lambda琛ㄨ揪寮忚繃婊よ幏鍙栭璁″埌璐ф棩鏈熴�侀儴闂ㄣ�佷緵搴斿晢
+                string hacceptdate = json.Select(p => p.hacceptdate).ToList().Distinct().ToString(); //棰勮鍒拌揣鏃ユ湡
+                string dpartment = json.Select(p => p.hdepartmentcode).ToList().Distinct().ToString(); //閮ㄩ棬
+                string customercode = json.Select(p => p.hcustomercode).ToList().Distinct().ToString(); //渚涘簲鍟�
+                //鍐欏叆閲囪喘鍒拌揣鍗曚富琛�
+                sql = @"insert into T_PurchaseArrivalOrder(hbillno,hdate,hacceptdate,hbillstaus,hdepartmentcode,hcustomercode,hsourcebillno,lm_user,lm_date) 
+                        values(@hbillno,@hdate,@hacceptdate,@hbillstaus,@hdepartmentcode,@hcustomercode,@hsourcebillno,@lm_user,@lm_date)";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        hbillno = djwo,
+                        hdate = DateTime.Now.ToString(),
+                        hacceptdate = Convert.ToDateTime(hacceptdate),
+                        hbillstaus = orderstaus,
+                        hdepartmentcode = dpartment,
+                        hcustomercode = customercode,
+                        hsourcebillno = purordercode,
+                        lm_user = username,
+                        lm_date = DateTime.Now.ToString()
+                    }
+                });
+                //寰幆鑾峰彇鐗╀俊鎭�
+                for (int i = 0; i < json.Count; i++)
+                {
+                    //鍐欏叆閲囪喘鍒拌揣鍗曞瓙琛�
+                    sql = @"insert into T_PurchaseArrivalOrder_sub(hbillno,hpartcode,hplanqty,hqty,hacceptdate,hischeck,hbatchno) 
+                        values(@hbillno,@hpartcode,@hplanqty,@hqty,@hacceptdate,@hischeck,@hbatchno)";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            hbillno = djwo,
+                            hpartcode = json[i].hpartcode,
+                            hplanqty = decimal.Parse(json[i].hplanqty),
+                            hqty = decimal.Parse(json[i].hqty),
+                            hacceptdate = Convert.ToDateTime(hacceptdate),
+                            hischeck = json[i].hischeck,
+                            hbatchno = json[i].hbatchno
+                        }
+                    });
+
+                    //寰幆鑾峰彇鐗╂枡鐢熸垚鏍囩淇℃伅
+                    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,lm_user,lm_date) 
+                        values(@rightcode,hbillno,@hbilltype,@hbarcode,@hbarcodestatus,@hbarcodetype,@hmaterialcode,@hqty,@hbatchno,@hcustomercode,@hdeptcode,@hsourcebillno,@hsourcebilltype,@lm_user,@lm_date)";
+                        list.Add(new
+                        {
+                            str = sql,
+                            parm = new
+                            {
+                                rightcode = "2060",
+                                hbillno = djwo,
+                                hbilltype = "1103", //閲囪喘鍒拌揣鍗曠被鍨�
+                                hbarcode = json[i].children[j].labcode,
+                                hbarcodestatus = "Y",
+                                hbarcodetype = "P",
+                                hmaterialcode = json[i].children[j].partnumber,
+                                hqty = decimal.Parse(json[i].children[j].labqty),
+                                hbatchno = json[i].hbatchno,
+                                hcustomercode = customercode,
+                                hdeptcode = dpartment,
+                                hsourcebillno = purordercode,
+                                hsourcebilltype = "1102",
+                                lm_user = username,
+                                lm_date = DateTime.Now.ToString()
+                            }
+                        });
+                    }
+                    //鏇存柊閲囪喘璁㈠崟瀛愯〃锛氱疮璁″埌璐ф暟閲�
+                    sql = @"update T_PurchaseOrder_sub set countarrivalquantity=countarrivalquantity+@hqty where ordercode=@purordercode and materiel_code=@materiel_code and rownumber=@rownumber";
+                    list.Add(new
+                    {
+                        str = sql,
+                        parm = new
+                        {
+                            purordercode = purordercode,
+                            materiel_code = json[i].hpartcode,
+                            rownumber=json[i].rownumber,
+                            hqty=decimal.Parse(json[i].hqty)
+                        }
+                    });
+                }
+                //鏇存柊閲囪喘璁㈠崟涓昏〃锛氳鍗曠姸鎬�
+                sql = @"update T_PurchaseOrder set status=@status where ordercode=@purordercode";
+                list.Add(new
+                {
+                    str = sql,
+                    parm = new
+                    {
+                        status = orderstaus,
+                        ordercode = purordercode
+                    }
+                });
+                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

--
Gitblit v1.9.3