yl
2023-02-07 5ac69a2a0e5a0f1433b4497bc5273bdae656221c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using VueWebApi.Models;
using VueWebApi.Tools;
 
namespace VueWebApi.DLL.DAL
{
    public class AppPurchManagementDAL
    {
        public static DataTable dt;    //定义全局变量dt
        public static bool res;       //定义全局变量dt
        public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
        public static string strProcName = ""; //定义全局sql变量
        public static List<SqlParameter> listStr = new List<SqlParameter>(); //定义全局参数集合
        public static SqlParameter[] parameters; //定义全局SqlParameter参数数组
 
        #region[采购到货:获取采购订单列表]
        public static ToMessage MesAppPurchOrderSearch(string purchordercode)
        {
            string sql = "";
            string search = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                if (purchordercode != "" && purchordercode != null) //订单号不为空
                {
                    search += " and A.ordercode like '%'+@purchordercode+'%' ";
                    //dynamicParams.Add("@purchordercode", 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" + 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 MesAppPurchOrderPartSearch(string purchordercode)
        {
            string sql = "";
            var dynamicParams = new DynamicParameters();
            try
            {
                //根据采购订单号查询物料信息,供应商信息
                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);
                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 MesAppPurchOrderLabelBarCode(string partcode, string arrivalqty, string 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++)
                    {
                        //写入条码档案表
                        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
    }
}