wtt
2025-04-02 95257e3cf13f5ab3779908f46e0c4c12e1f095b4
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
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 Cg_POStockInBillList_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("Cg_POStockInBillList_Sec/addBillToWaitSecList")]
        [HttpGet]
        public object addBillToWaitSecList(int hmainid, string user)
        {
            try
            {
                string sql = "select * from Kf_ICStockBillMain where HBillType = '1201' and HInterID = " + hmainid;
                ds = oCN.RunProcReturn(sql, "Kf_ICStockBillMain");
 
                string sql1 = "insert into Cg_POStockInBillList_Sec(HMaker,HMakeDate,HMainSourceInterID,MainSourceBillNo,HMainSourceBillType) " +
                    " values(" +
                    "'" + user + "'" +
                    "," + "getdate()" + "" +
                    "," + hmainid + "" +
                    ",'" + ds.Tables[0].Rows[0]["HBillNo"].ToString() + "'" +
                    ",'" + "1201" + "'" +
                    ")";
                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("Cg_POStockInBillList_Sec/SecToPayableBill")]
        [HttpGet]
        public object SecToPayableBill(string hmainidList, string user)
        {
            oCN.BeginTran();
            try
            {
                //将待核销列表中的数据标记为已核销
                string sql0 = $"update Cg_POStockInBillList_Sec set HSecEmp = '{user}',HSecTime = getdate() where HMainSourceInterID in ({hmainidList})";
                oCN.RunProc(sql0);
 
                //生成应付单
                string sql = $"select * from h_v_Kf_POStockInBillEdit where hmainid in ({ hmainidList})";
                ds = oCN.RunProcReturn(sql, "h_v_Kf_POStockInBillEdit");
                DAL.ClsCg_PayableBill oBill = new DAL.ClsCg_PayableBill();
                oBill.omodel.HInterID = DBUtility.ClsPub.CreateBillID("1114", ref DBUtility.ClsPub.sExeReturnInfo);
                oBill.omodel.HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("1114", 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 = "1201";
                oBill.omodel.HMaker = user;
                oBill.omodel.HMakeDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                oBill.omodel.HSSID = 0; ;
                oBill.omodel.HPSStyleID = DBUtility.ClsPub.isLong(ds.Tables[0].Rows[0]["HPSStyleID"]); ; ;
                oBill.omodel.HReceiveDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                oBill.omodel.HSupID = 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.HInvoiceBillNo = "";
                oBill.omodel.HProjectID = 0;
 
                for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    Model.ClsCg_PayableSub oItemSub = new Model.ClsCg_PayableSub();
                    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[i]["税率"]);
                    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 = "1201";
                    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
    }
}