1
llj
2025-10-16 b8f6235347ad2690727347e6ffa4693606d80b7d
WebAPI/Controllers/CGGL/Kf_POStockInBillController.cs
@@ -728,7 +728,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已关闭!不能再次审核!";
                        objJsonResult.Message = "单据已关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -736,7 +736,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "单据已作废!不能再次审核!";
                        objJsonResult.Message = "单据已作废!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -1360,6 +1360,43 @@
            {
                ds = oCN.RunProcReturn("select * from h_v_Kf_POStockInBillList where hmainid =" + HInterID + " and hsubid = " + HSubID, "h_v_Kf_POStockInBillList");
                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/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";
@@ -2058,5 +2095,146 @@
        }
        #endregion
        #region 采购入库单 审核同步 调用API
        [Route("Kf_POStockInBill/Kf_POStockInBillSaveApi")]
        [HttpPost]
        public object Kf_POStockInBillSaveApi([FromBody] JObject sMainSub)
        {
            try
            {
                oCN.BeginTran();
                LogService.Write("生产入库单同步,保存方法执行:" + sMainSub.ToString());
                var model = sMainSub["model"].ToString();
                var entry = sMainSub["model"]["HENTRY"].ToString();
                model = "[" + model.ToString() + "]";
                List<ClsKf_ICStockBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ICStockBillMain>>(model);
                List<ClsKf_ICStockBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ICStockBillSub>>(entry);
                // 判断 数据库中是否存在id和单据号相等的打单据,存在,则重建,只有id号相等,则申请新的id号
                var ds1 = oCN.RunProcReturn($@"
                select hmainid HInterID, 单据号 HBillNO from h_v_Kf_POStockInBillList where hmainid = {mainList[0].HInterID}
                ", "h_v_Kf_POStockInBillList");
                if (ds1.Tables[0].Rows.Count > 0 && ds1.Tables[0].Rows[0]["HInterID"] != null)
                {
                    if (string.Equals(ds1.Tables[0].Rows[0]["HBillNo"].ToString(), mainList[0].HBillNo, StringComparison.OrdinalIgnoreCase))
                    {
                        string sql = string.Empty;
                        sql = $"delete Kf_ICStockBillMain where HinterID = {mainList[0].HInterID}";
                        oCN.RunProc(sql);
                        sql = $"delete Kf_ICStockBillSub where HinterID = {mainList[0].HInterID}";
                        oCN.RunProc(sql);
                    }
                    else
                    {
                        // 重新申请HInterID
                        var HInterID_Exch = DBUtility.ClsPub.CreateBillID("1201", ref DBUtility.ClsPub.sExeReturnInfo);
                        mainList[0].HInterID = HInterID_Exch;
                        foreach (var oSub in subList)
                        {
                            oSub.HInterID = HInterID_Exch;
                        }
                    }
                }
                // 主表
                oCN.RunProc($@"Insert Into Kf_ICStockBillMain
                    (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate
                   ,HBillNo,HBillStatus,HSupID,HManagerID,HEmpID,HDeptID,HSecManagerID,HKeeperID,HRemark,HMaker,HMakeDate,HCurID,HExRate,HWHID,HInnerBillNo,HExplanation
                    ,HChecker, HCheckDate, HSTOCKORGID)
                    values(
                    '{mainList[0].HInterID}',
                    '{mainList[0].HYear}',
                    '{mainList[0].HPeriod}',
                    '{mainList[0].HBillType}',
                    '{mainList[0].HBillSubType}',
                    '{mainList[0].HDate}',
                    '{mainList[0].HBillNo}',
                    {mainList[0].HBillStatus},
                    '{mainList[0].HSupID}',
                    '{mainList[0].HManagerID}',
                    '{mainList[0].HEmpID}',
                    '{mainList[0].HDeptID}',
                    '{mainList[0].HSecManagerID}',
                    '{mainList[0].HKeeperID}',
                    '{mainList[0].HRemark}',
                    '{mainList[0].HMaker}',
                    '{mainList[0].HMakeDate}',
                    '{mainList[0].HCurID}',
                    '{mainList[0].HWHID}',
                    '{mainList[0].HInnerBillNo}',
                    '{mainList[0].HExplanation}',
                    '{mainList[0].HChecker}',
                    '{mainList[0].HCheckDate}',
                    {mainList[0].HSTOCKORGID}
                    )
                ");
                // 子表
                foreach (var osub in subList)
                {
                    oCN.RunProc($@"Insert into Kf_ICStockBillSub
                    (HInterID,HEntryID,HMaterID,HUnitID,HQtyMust,HQty,HPrice
                   ,HMoney,HWHID,HSPID,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HPOOrderInterID
                    ,HPOOrderEntryID,HPOORderBillNo,HSecUnitID,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo,HRelationQty,HSecUnitRate,HPropertyID)
                    values (
                        '{osub.HInterID}',
                        '{osub.HEntryID}',
                        '{osub.HMaterID}',
                        '{osub.HUnitID}',
                        '{osub.HQtyMust}',
                        '{osub.HQty}',
                        '{osub.HPrice}',
                        '{osub.HMoney}',
                        '{osub.HWHID}',
                        '{osub.HSPID}',
                        '{osub.HRemark}',
                        '{osub.HSourceInterID}',
                        '{osub.HSourceEntryID}',
                        '{osub.HSourceBillNo}',
                        '{osub.HSourceBillType}',
                        '{osub.HPOOrderInterID}',
                        '{osub.HPOOrderEntryID}',
                        '{osub.HPOOrderBillNo}',
                        '{osub.HSecUnitID}',
                        '{osub.HSeOrderInterID}',
                        '{osub.HSeOrderEntryID}',
                        '{osub.HSeOrderBillNo}',
                        '{osub.HRelationQty}',
                        '{osub.HSecUnitRate}',
                        '{osub.HPropertyID}'
                    )
                    ");
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "单据保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                LogService.Write("生产入库单同步异常,保存方法执行完成异常:" + e.Message.ToString());
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "保存失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}