1
yusijie
2025-04-07 175c63b06390015e40148dbd8b6065ebff737898
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
using Model;
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;
using SyntacticSugar.constant;
 
namespace WebAPI.Controllers
{
    //销售核销
    public class Xs_SellOutBillList_SecController : ApiController
    {
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 通用查询方法
        [Route("CommonModel/searchMethod")]
        [HttpGet]
        public object searchMethod(string sql,string user,string ModRightNameCheck)
        {
            try
            {
                
                //判断查询权限
                if (ModRightNameCheck !=null&&ModRightNameCheck != "")
                {
                    if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "无权限查询!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                ds = oCN.RunProcReturn(sql, sql);
 
                //获取列信息
                List<object> columnNameList = new List<object>(); //定义声明变量 ,把通过 new List<object>()创建的 实例,赋值给变量
                foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                {
                    Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // 将列名和数据类型信息拼接成一个JSON格式的字符串
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
 
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 通用方法
        [Route("CommonModel/commonMethod")]
        [HttpGet]
        public object commonMethod(string sql, string user, string ModRightNameCheck)
        {
            try
            {
 
                //判断查询权限
                if (ModRightNameCheck != null && ModRightNameCheck != "")
                {
                    if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, user))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "无权限查询!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
 
                oCN.RunProc(sql);
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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("Xs_SellOutBillList_Sec/addBillToWaitSecList")]
        [HttpGet]
        public object addBillToWaitSecList(int hmainid, string user)
        {
            try
            {
                string sql = "select * from Kf_ICStockBillMain where HBillType = '1205' and HInterID = " + hmainid;
                ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain");
 
                string sql1 = "insert into Xs_SellOutBillList_Sec(HMaker,HMakeDate,HMainSourceInterID,MainSourceBillNo,HMainSourceBillType) " +
                    " values(" +
                    "'" + user + "'" +
                    "," + "getdate()" + "" +
                    "," + hmainid + "" +
                    ",'" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'" +
                    ",'" + "1205" + "'" +
                    ")";
                oCN.RunProc(sql1);
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                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("Xs_SellOutBillList_Sec/SecToReceivableBill")]
        [HttpGet]
        public object SecToReceivableBill(string hmainidList, string user)
        {
            oCN.BeginTran();
            try
            {
                //将待核销列表中的数据标记为已核销
                string sql0 = $"update Xs_SellOutBillList_Sec set HSecEmp = '{user}',HSecTime = getdate() where HMainSourceInterID in ({hmainidList})";
                oCN.RunProc(sql0);
 
                //生成应付单
                string sql = $"select * from h_v_IF_SellOutBillList_EditInit where hmainid in ({ hmainidList})";
                ds = oCN.RunProcReturn(sql, "h_v_IF_SellOutBillList_EditInit");
                DAL.ClsXs_ReceivableBill oBill = new DAL.ClsXs_ReceivableBill();
                oBill.omodel.HInterID = DBUtility.ClsPub.CreateBillID("1426", ref DBUtility.ClsPub.sExeReturnInfo);
                oBill.omodel.HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("1426", ref DBUtility.ClsPub.sExeReturnInfo,false);
                oBill.omodel.HDate = DateTime.Now;
                oBill.omodel.HPeriod = DateTime.Now.Month;
                oBill.omodel.HYear = DateTime.Now.Year;
                oBill.omodel.HMainSourceInterID = 0;
                oBill.omodel.HMainSourceEntryID = 0;
                oBill.omodel.HMainSourceBillNo = "";
                oBill.omodel.HMainSourceBillType = "1205";
                oBill.omodel.HMaker = user;
                oBill.omodel.HMakeDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                oBill.omodel.HSSID = 0;
                oBill.omodel.HSellSID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSellSID"]);
                oBill.omodel.HReceiveDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                oBill.omodel.HCusID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HSupID"]);
                oBill.omodel.HCurID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HCurID"]);
                oBill.omodel.HExRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["汇率"]);
                oBill.omodel.HEmpID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HEmpID"]);
                oBill.omodel.HMangerID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HManagerID"]);
                oBill.omodel.HDeptID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HDeptID"]);
                oBill.omodel.HExplanation = "";
                oBill.omodel.HInnerBillNo = "";
                oBill.omodel.HRemark = "";
                oBill.omodel.HPriceType = "";
                oBill.omodel.HProjectID = 0;
 
                for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    Model.ClsXs_ReceivableBillSub oItemSub = new Model.ClsXs_ReceivableBillSub();
                    oItemSub.HInterID = oBill.omodel.HInterID;
                    oItemSub.HEntryID = (i + 1);
                    oItemSub.HBillNo_bak = oBill.omodel.HBillNo;
                    oItemSub.HMaterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HMaterID"]);
                    oItemSub.HUnitID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["HUnitID"]);
                    oItemSub.HQty = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["数量"]);
                    oItemSub.HPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["单价"]);
                    oItemSub.HTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]);
                    oItemSub.HDiscountRate = 1;
                    oItemSub.HRelTaxPrice = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["含税单价"]);
                    oItemSub.HTaxRate = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]);
                    oItemSub.HTaxMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["税率"]) * DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[0]["金额"]);
                    oItemSub.HlineTotal = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["价税合计"]);
                    oItemSub.HlineTotalBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["价税合计"]) * oBill.omodel.HExRate;
                    oItemSub.HMoney = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]);
                    oItemSub.HMoneyBB = DBUtility.ClsPub.isDoule(ds.Tables[0].Rows[i]["金额"]) * oBill.omodel.HExRate;
                    oItemSub.HRemark = "";
                    oItemSub.HSourceInterID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hmainid"]);
                    oItemSub.HSourceEntryID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[i]["hsubid"]);
                    oItemSub.HSourceBillNo =  DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[i]["单据号"]);
                    oItemSub.HSourceBillType = "1205";
                    oItemSub.HRelationQty = 0;
                    oItemSub.HRelationMoney = 0;
 
                    oBill.DetailColl.Add(oItemSub);
                }
 
                bool bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
 
                if (bResult)
                {
                    oCN.Commit();
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "核销成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "核销失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}