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
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
 
 
namespace WebAPI.Controllers.CJGL
{
    public class Cj_SendGoodsBillController : ApiController
    {
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 车间收料列表 查询
        //过滤条件
        public class JIT_SendGoodsBill
        {
            public DateTime HBeginDate;
            public DateTime HEndDate;
            public string HBillNo { get; set; }
            public string HDeptName { get; set; }
            public string MaterialCode { get; set; }
            public string MaterialName { get; set; }
            public string MaterialModel { get; set; }
            public string Arbitrarily { get; set; }
            public string HBillStatus { get; set; }
            public int? HOrgID;
        }
 
        [Route("Cj_SendGoodsBill/Cj_SendGoodsBillList")]
        [HttpGet]
        public object Cj_SendGoodsBillList(string sWhere,string user)
        {
            try
            {
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("JIT_SendGoodsBill_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = new DataTable();
                    return objJsonResult;
                }
 
                //反序列化传递的值
                JIT_SendGoodsBill com = JsonConvert.DeserializeObject<JIT_SendGoodsBill>(sWhere.ToString());
 
                ds = oCN.RunProcReturn($"exec h_p_JIT_DeptCheckGoodsBillList_Query '{com.HBeginDate}','{com.HEndDate.AddDays(1).AddSeconds(-1)}','{com.HBillNo}','{com.HDeptName}'," +
                   $"'{com.MaterialCode}','{com.MaterialName}','{com.MaterialModel}','{com.HOrgID}','{com.HBillStatus}'", "h_p_JIT_DeptCheckGoodsBillList_Query");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 车间收料列表 确认收料
        [Route("Cj_SendGoodsBill/DeptCheckGoodsBillList_Check")]
        [HttpGet]
        public object DeptCheckGoodsBillList_Check(string HInterID,string HEntryID,string User)
        {
            try
            {
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("JIT_SendGoodsBill_Check", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无审核权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                ds = oCN.RunProcReturn($"exec h_p_JIT_DeptCheckGoodsBillList_Check '{HInterID}','{HEntryID}','{User}'", "h_p_JIT_DeptCheckGoodsBillList_Check");
 
                objJsonResult.code = ds.Tables[0].Rows[0][0].ToString();
                objJsonResult.count = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                objJsonResult.Message = ds.Tables[0].Rows[0][1].ToString();
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 车间收料列表 撤销确认收料
        [Route("Cj_SendGoodsBill/DeptCheckGoodsBillList_revoke")]
        [HttpGet]
        public object DeptCheckGoodsBillList_revoke(string HInterID, string HEntryID, string User)
        {
            try
            {
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("JIT_SendGoodsBill_Check", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无审核权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
              oCN.RunProc($"update JIT_SendGoodsBillMain set HChecker='' ,HCheckDate=null,HBillStatus=1  where HInterID='{HInterID}'");
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "已完成撤销";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 车间收料列表 删除
        [Route("Cj_SendGoodsBill/DeleteBill")]
        [HttpGet]
        public object DeleteBill(string HInterID,string HEntryID, string User)
        {
            try
            {
                DataSet dataset = new DataSet();
                //获取车间配送单据数据
                dataset = oCN.RunProcReturn($"select * from JIT_SendGoodsBillMain a inner join JIT_SendGoodsBillSub b on a.HInterID = b.HInterID where  a.HInterID={HInterID} and HEntryID={HEntryID}  ", "JIT_SendGoodsBillMain");
 
                var HQty = double.Parse(dataset.Tables[0].Rows[0]["HQty"].ToString());
 
                //获取拣料配送单的数据
                ds = oCN.RunProcReturn($"select * from JIT_ComplementGoodsBillMain a inner join JIT_ComplementGoodsBillSub b on a.HInterID = b.HInterID where  a.HInterID={(dataset.Tables[0].Rows[0]["HMainSourceInterID"].ToString())} and  b.HMaterID={(dataset.Tables[0].Rows[0]["HMaterID"].ToString())} and  b.HWHID={(dataset.Tables[0].Rows[0]["HWHID"].ToString())} ", "JIT_ComplementGoodsBillMain");
 
                //获取拣料配送单_LK表 数据
                ds = oCN.RunProcReturn($"select * from JIT_ComplementGoodsBillSub_LK where  HInterID={(ds.Tables[0].Rows[0]["HInterID"].ToString())} and HSendQTY<>0 order by HSendQTY", "JIT_SendGoodsBillMain");
 
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var HSendQTY = double.Parse(ds.Tables[0].Rows[i]["HSendQTY"].ToString());
 
                    //修改调拨数量 
                    oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY=HSendQTY-{(HSendQTY > HQty ? HQty : HSendQTY)} where HInterID={ds.Tables[0].Rows[i]["HInterID"].ToString()}  and HEntryID={ds.Tables[0].Rows[i]["HEntryID"].ToString()} ");
 
                    HQty -= HSendQTY;
                    if (HQty <= 0)
                    {
                        break;
                    }
                }
 
                dataset = oCN.RunProcReturn($"select * from JIT_SendGoodsBillMain a inner join JIT_SendGoodsBillSub b on a.HInterID = b.HInterID where  a.HInterID={HInterID} ", "JIT_SendGoodsBillMain");
 
                //删除数据
                if (dataset.Tables[0].Rows.Count != 1)
                {
                    oCN.RunProc($"delete from  JIT_SendGoodsBillSub  where HInterID='{HInterID}' and HEntryID={HEntryID} ");
                }
                else
                {
                   
                    oCN.RunProc($"delete from  JIT_SendGoodsBillMain  where HInterID='{HInterID}'");
                    oCN.RunProc($"delete from  JIT_SendGoodsBillSub  where HInterID='{HInterID}' and HEntryID={HEntryID} ");
                }
              
 
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "已完成删除";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}