1
zrg
2026-04-07 ec622206f5adcbd7cb96f06d75ec03e6dc83a7fd
WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
@@ -1,6 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NPOI.SS.Formula.Functions;
using Pub_Class;
using System;
using System.Collections;
@@ -9,6 +8,7 @@
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
using System.Windows.Forms;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
@@ -143,6 +143,188 @@
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return res;
            }
        }
        #endregion
        #region 采购入库保存
        /// <summary>
        /// 保存销售出库单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("Kf_POStockInBill/SaveSellOutBillList")]
        [HttpPost]
        public object SaveSellOutBillList([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string user = sArray[2].ToString();
            string OperationType = sArray[3].ToString();
            ListModels oListModels = new ListModels();
            try
            {
                //判断权限
                //if (!DBUtility.ClsPub.Security_Log("Kf_SellOutBill_Edit", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无保存权限";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                DAL.ClsKf_POStockInBill1 oBill = new DAL.ClsKf_POStockInBill1();
                List<Model.ClsKf_SellOutBillMain> lsmain = new List<Model.ClsKf_SellOutBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getSellOutBillMainByJson(msg2);
                foreach (Model.ClsKf_SellOutBillMain oItem in lsmain)
                {
                    oItem.HMaker = user;
                    oItem.HUpDater = user;
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                List<Model.ClsKf_SellOutBillSub> ls = new List<Model.ClsKf_SellOutBillSub>();
                ls = oListModels.getSellOutBillSubByJson(msg3);
                int i = 0;
                foreach (Model.ClsKf_SellOutBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;
                    oItemSub.HCloseMan = "";
                    oBill.DetailColl.Add(oItemSub);
                }
                //进行 会计期间 结账 的判断和控制
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = DateTime.Now;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.Message = s;
                    return objJsonResult;
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (Convert.ToInt32(OperationType) == 1)                                //新增保存
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (Convert.ToInt32(OperationType) == 4)                          //下推保存
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else                                                                    //编辑保存
                {
                    if (BillOld.ShowBill(lsmain[0].HInterID, ref s) == false)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据有误!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    //判断是否可编辑
                    if (BillOld.omodel.HChecker != "" && BillOld.omodel.HChecker != null)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据已经被审核,不允许修改!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (BillOld.omodel.HBillStatus > 1)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld, ref s))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = s + ",不允许修改";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                //自动审核设置
                if (Convert.ToInt32(OperationType) == 1 || Convert.ToInt32(OperationType) == 4)
                {
                    objJsonResult.HInterID = oBill.omodel.HInterID.ToString(); //返回主ID
                    //系统参数  自动审核
                    string sReturn = "";
                    if (oSystemParameter.ShowBill(ref sReturn) == true)
                    {
                        if (oSystemParameter.omodel.Kf_SellOutBill_AutoCheck == "Y") //系统参数  自动审核
                        {
                            objJsonResult.Verify = "Y";
                        }
                        else
                        {
                            objJsonResult.Verify = "N";
                        }
                    }
                }
                else
                {
                    objJsonResult.HInterID = oBill.omodel.HInterID.ToString(); //返回主ID
                    objJsonResult.Verify = "N";
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
@@ -617,6 +799,102 @@
            }
        }
        #endregion
        #region 采购入库单 - 托数变更功能
        [Route("Kf_POStockInBill/UpdatePallet")]
        [HttpPost]
        public object UpdatePallet([FromBody] JObject data)
        {
            try
            {
                long hmainid = data["hmainid"]?.ToObject<long>() ?? 0;
                int newPallet = data["newPallet"]?.ToObject<int>() ?? 0;
                string operatorName = data["operator"]?.ToString() ?? "";
                if (hmainid <= 0)
                    return new { code = "0", count = 0, Message = "单据ID不能为空!" };
                if (newPallet < 0)
                    return new { code = "0", count = 0, Message = "托数不能为负数!" };
                // 直接更新托数
                string updateSql = $@"
                    UPDATE  Kf_ICStockBillMain
                    SET HPackQtys = {newPallet}
                    WHERE HInterID = {hmainid}";
                oCN.RunProc(updateSql);
                return new
                {
                    code = "1",
                    count = 1,
                    Message = "托数修改成功!"
                };
            }
            catch (Exception e)
            {
                return new
                {
                    code = "0",
                    count = 0,
                    Message = "修改失败:" + e.Message
                };
            }
        }
        #endregion
        #region 采购入库单 - 贴标签数变更功能
        [Route("Kf_POStockInBill/UpdateHTagCount")]
        [HttpPost]
        public object UpdateHTagCount([FromBody] JObject data)
        {
            try
            {
                long hmainid = data["hmainid"]?.ToObject<long>() ?? 0;
                int newPallet = data["newPallet"]?.ToObject<int>() ?? 0;
                string operatorName = data["operator"]?.ToString() ?? "";
                if (hmainid <= 0)
                    return new { code = "0", count = 0, Message = "单据ID不能为空!" };
                if (newPallet <= 0)
                    return new { code = "0", count = 0, Message = "贴标签数必须大于0!" };
                // 直接更新托数
                string updateSql = $@"
                    UPDATE  Kf_ICStockBillMain
                    SET HTagCount = {newPallet}
                    WHERE HInterID = {hmainid}";
                oCN.RunProc(updateSql);
                return new
                {
                    code = "1",
                    count = 1,
                    Message = "托数修改成功!"
                };
            }
            catch (Exception e)
            {
                return new
                {
                    code = "0",
                    count = 0,
                    Message = "修改失败:" + e.Message
                };
            }
        }
        #endregion
        #region 查找记录功能
        /// <summary>