1
duhe
2025-03-31 9b4915b7b3669ffe80774740bd06c547ece49494
WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
@@ -9,12 +9,15 @@
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
{
    //采购入库单Controller
    public class Kf_POStockInBillController : ApiController
    {
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        //public DAL.ClsCg_POInStockBill BillOld = new DAL.ClsCg_POInStockBill();
        public DAL.ClsKf_POStockInBill BillOld = new DAL.ClsKf_POStockInBill();
@@ -86,6 +89,64 @@
                return objJsonResult;
            }
        }
        #region 采购入库单分页列表
        [Route("Kf_POStockInBill/page")]
        [HttpGet]
        public object Kf_POStockInBillPage(string sWhere, string user, int page, int size)
        {
            DataSet ds;
            json res = new json();
            try
            {
                List<object> columnNameList = new List<object>();
                //判断权限
                //if (!DBUtility.ClsPub.Security_Log("Kf_POStockInBillList", 1, false, user))
                //{
                //    objJsonResult.code = CodeConstant.FAIL;
                //    objJsonResult.count = CountConstant.FAIL;
                //    objJsonResult.Message = "您没有该模块权限,请与管理员联系!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                sWhere = sWhere.Replace("'", "''");
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("exec h_p_Kf_POStockInBillList_New " + page + "," + size + ",''", "h_p_Kf_POStockInBillList_New");
                }
                else
                {
                    ds = oCN.RunProcReturn("exec h_p_Kf_POStockInBillList_New " + page + "," + size + ",'" + sWhere + "'", "h_p_Kf_POStockInBillList_New");
                }
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                res.code = CodeConstant.SUCCEED;
                res.count = int.Parse(ds.Tables[1].Rows[0]["count"].ToString());
                res.Message = "Sucess!";
                res.list = columnNameList;
                res.data = ds.Tables[0];
                return res;
            }
            catch (Exception e)
            {
                res.code = CodeConstant.FAIL;
                res.count = CountConstant.FAIL;
                res.Message = "Exception!" + e.ToString();
                res.data = null;
                return res;
            }
        }
        #endregion
        #region 采购入库单 保存/编辑功能
        [Route("Kf_POStockInBill/POStockInBillEdit")]
@@ -191,7 +252,7 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_Kf_POStockInBillList");
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid=" + HInterID, "h_v_Kf_POStockInBillList");
                if ((OperationType == 1 || OperationType == 2 || OperationType == 4) && ds.Tables[0].Rows.Count == 0)//新增
                {
@@ -221,7 +282,7 @@
                       ,HAddress,HSupID,HCurID,HWHID,HEmpID,HManagerID,HSecManagerID,HKeeperID,HDeptID,HExplanation,HRemark
                        ,HInnerBillNo,HSTOCKORGID,HOWNERID,HMaker,HMakeDate,HProjectID,HInvoiceBillNo)
                        values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 1201 + "','" +
                    1201 + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "','" + HAddress +
                    HBillSubType + "','" + HDate + "','" + HBillNo + "','" + HBillStatus + "','" + HAddress +
                    "'," + HSupID + "," + HCurID + "," + HWHID + "," + HEmpID + "," + HManagerID + "," + 
                    HSecManagerID + ","+ HKeeperID +"," + HDeptID + ",'" + HExplanation + "','" + HRemark
                    + "','" + HInnerBillNo + "'," + HSTOCKORGID + "," + HOWNERID + ",'" + HMaker + "',getdate(),"+ HProjectID + ",'"+ HInvoiceBillNo + "')";
@@ -232,7 +293,7 @@
                { //修改
                    DataSet dss;
                    dss = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_Kf_POStockInBillList");
                    dss = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid=" + HInterID , "h_v_Kf_POStockInBillList");
                    //判断是否可编辑
                    if (dss.Tables[0].Rows[0]["审核人"].ToString() != "" && dss.Tables[0].Rows[0]["审核人"] != null)
                    {
@@ -252,7 +313,7 @@
                    }
                    String sql = $@"update Kf_ICStockBillMain  set " +
                                "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" +
                                "HRemark='" + HRemark + "', HUpDater='" + HMaker + "', HUpDateDate=getdate()" + ",HBillNo='" + HBillNo + "'" +
                                 ",HSupID=" + HSupID + ",HCurID=" + HCurID + ",HSecManagerID=" + HSecManagerID + ", HSTOCKORGID=" + HSTOCKORGID + ",HKeeperID=" + HKeeperID + ",HWHID = " + HWHID
                                 + ",HEmpID=" + HEmpID + ",HManagerID=" + HManagerID + ",HDeptID=" + HDeptID + ",HOWNERID=" + HOWNERID
                                 + ",HAddress='" + HAddress + "',HInnerBillNo='" + HInnerBillNo + "',HProjectID="+ HProjectID + ",HInvoiceBillNo='"+ HInvoiceBillNo + "' where HInterID=" + HInterID;
@@ -276,6 +337,30 @@
                //采购入库单新增回填收料通知单关联数量
                oCN.RunProc("exec h_p_Cg_UpDateRelation_POInStockToPOStockIn_Add " + HInterID);
                //自动审核设置
                if ((OperationType == 1 || OperationType == 2 || OperationType == 4))
                {
                    objJsonResult.HInterID = HInterID.ToString(); //返回主ID
                    //系统参数  自动审核
                    string sReturn = "";
                    if (oSystemParameter.ShowBill(ref sReturn) == true)
                    {
                        if (oSystemParameter.omodel.Kf_POStockInBill_AutoCheck == "Y") //系统参数  自动审核
                        {
                            objJsonResult.Verify = "Y";
                        }
                        else
                        {
                            objJsonResult.Verify = "N";
                        }
                    }
                }
                else if (OperationType == 3)
                {
                    objJsonResult.HInterID = HInterID.ToString(); //返回主ID
                    objJsonResult.Verify = "N";
                }
                if (objJsonResult.code == "0")
@@ -328,14 +413,14 @@
            {
                ClsKf_ICStockBillSub oSub = (ClsKf_ICStockBillSub)list[i1];
                i++;
                if (oSub.HQty <= 0 || oSub.HQty == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //if (oSub.HQty <= 0 || oSub.HQty == null)
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                if (oSub.HMaterID == 0)
                {
@@ -546,7 +631,7 @@
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid =" + HInterID, "h_v_Kf_POStockInBillList");
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillEdit where hmainid =" + HInterID, "h_v_Kf_POStockInBillList");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
@@ -643,7 +728,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已关闭!不能再次审核!";
                        objJsonResult.Message = "单据已关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -651,7 +736,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已作废!不能再次审核!";
                        objJsonResult.Message = "单据已作废!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -1303,6 +1388,43 @@
        }
        #endregion
        #region 采购入库单  根据主内码与子内码获取采购入库单数据
        [Route("Kf_POStockInBill/loadKf_POStockInBillEdit_Push")]
        [HttpGet]
        public object loadKf_POStockInBillEdit_Push(long HInterID, long HSubID)
        {
            try
            {
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillEdit where hmainid =" + HInterID + " and hsubid = " + HSubID, "h_v_Kf_POStockInBillEdit");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未查询到源单信息!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    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("Kf_POStockInBill/RejectCheckFlow_POOrderBill")]
        [HttpGet]
@@ -1819,5 +1941,159 @@
        }
        #endregion
        #region 采购入库单下推查询列表
        [Route("Kf_POStockInBill/PushList")]
        [HttpGet]
        public object PushList(string HBillNo, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                string sql = "select * from h_v_Kf_POStockInBillList where 单据号 = '" + HBillNo + "' and 状态 = '已审核' and 实收数量 - 关联数量 > 0";
                ds = oCN.RunProcReturn(sql, "h_v_Kf_POStockInBillList");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "找不到符合条件单据!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 采购入库单查询列表
        [Route("Kf_POStockInBill/QueryList")]
        [HttpGet]
        public object QueryList(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_POStockInBillQuery", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无权限查看!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql = "select * from h_v_Kf_POStockInBillQuery where 1 = 1 ";
                if (sWhere == "" || sWhere == null)
                {
                    ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillQuery  order by hmainid desc", "h_v_Kf_POStockInBillQuery");
                }
                else
                {
                    ds = oCN.RunProcReturn(sql + sWhere + " order by hmainid desc", "h_v_Kf_POStockInBillQuery");
                }
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 采购入库单查询子列表
        [Route("Kf_POStockInBill/QuerySubList")]
        [HttpGet]
        public object QuerySubList(string hmainid, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //判断是否有查询权限
                if (!DBUtility.ClsPub.Security_Log("Kf_POStockInBillQuery", 1, false, user))
                {
                    objJsonResult.code = CodeConstant.FAIL;
                    objJsonResult.count = CountConstant.FAIL;
                    objJsonResult.Message = "无权限查看!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sql = "select * from h_v_Kf_POStockInBillQuerySub where hmainid =  " + hmainid;
                ds = oCN.RunProcReturn(sql + " order by hsubid ASC", "h_v_Kf_POStockInBillQuerySub");
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = CodeConstant.SUCCEED;
                objJsonResult.count = CountConstant.SUCCEED;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = CodeConstant.FAIL;
                objJsonResult.count = CountConstant.FAIL;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}