1
zrg
2025-10-17 82de67c48acaf472a6f8bb8b53f3f4feec9f5e54
WebAPI/Controllers/²Ö´æ¹ÜÀí/ÑéÊÕÈë¿â/Kf_ProductInBillController.cs
@@ -1652,5 +1652,152 @@
            }
        }
        #endregion
        #region ç”Ÿäº§å…¥åº“单 å®¡æ ¸åŒæ­¥æ’ä»¶ è°ƒç”¨æŽ¥å£
        [Route("Kf_ProductInBill/Kf_ProductInBillSaveApi")]
        [HttpPost]
        public object Kf_ProductInBillSaveApi([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_ProductInBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ProductInBillMain>>(model);
                List<ClsKf_ProductInBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsKf_ProductInBillSub>>(entry);
                // åˆ¤æ–­ æ•°æ®åº“中是否存在id和单据号相等的打单据,存在,则重建,只有id号相等,则申请新的id号
                var ds1 = oCn.RunProcReturn($@"
                select hmainid HInterID, å•据号 HBillNO from h_v_Kf_ProductInBillList where hmainid = {mainList[0].HInterID}
                ", "h_v_Kf_ProductInBillList");
                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("1202", 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].HExRate}',
                    '{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.RunProc("exec h_p_Kf_UpDateRelation_ProductInToICMO_Add " + mainList[0].HInterID);
                //生产入库单新增回填生产汇报单关联数量
                oCn.RunProc("exec h_p_Kf_UpDateRelation_ProductInToICMOReport_Add " + mainList[0].HInterID);
                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
    }
}