yangle
2022-09-15 ef74ca1a145013f325af41ecde9a4de3f5b158d8
WebAPI/Controllers/POStockInBillController.cs
@@ -709,6 +709,7 @@
                websLsmain.HDeptID = lsmain[0].HDeptID;
                websLsmain.HWHID = lsmain[0].HWHID;
                websLsmain.HSCWHID = 0;
                //websLsmain.HSPID = lsmain[0].HSPID;
                websLsmain.HSupID = lsmain[0].HSupID;
                websLsmain.HKeeperID = lsmain[0].HKeeperID;
                websLsmain.HSecManagerID = lsmain[0].HSecManagerID;
@@ -716,11 +717,13 @@
                websLsmain.HManagerID = 0;
                websLsmain.HBillerID = lsmain[0].HBillerID;
                websLsmain.HRemark = "";
                websLsmain.HExplanation = lsmain[0].HExplanation;
                websLsmain.HInnerBillNo = "";
                websLsmain.HRedBlueFlag = false;//false蓝字 true红字
                websLsmain.HMainSourceBillType = lsmain[0].HBillType;
                websLsmain.HExplanation = lsmain[0].HExplanation;
                websLsmain.HMaker = lsmain[0].HMaker;
                websLsmain.HSTOCKORGID = lsmain[0].HSTOCKORGID;
                websLsmain.HOWNERID = lsmain[0].HSTOCKORGID;
                if (webserver.set_SavePOStockInBill_New(websLsmain, sSourceBillType, ref DBUtility.ClsPub.sErrInfo))
                {
@@ -844,8 +847,6 @@
                return objJsonResult;
            }
        }
        [Route("POStockInBill/Delete_Json")]
        [HttpGet]
        public object Delete_Json(long HInterID, long HMaterID, long HAuxPropID, string HMTONo, long HSourceInterID, long HSourceEntryID, string sHBillType)
@@ -982,7 +983,6 @@
            }
            catch (Exception)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "删除失败!";
@@ -1000,25 +1000,27 @@
        {
            try
            {
                SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                string sql = $"select * from H_v_SRM_POInStockBillList where 单据号 ='{HBillno}'";
                ds = oCn.RunProcReturn(sql, "H_v_SRM_POInStockBillList");
                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;
                }
                json result = Get_ReciveBillCheckDate(HBillno);
                return result;
                //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                //string sql = $"select * from H_v_SRM_POInStockBillList where 单据号 ='{HBillno}'";
                //ds = oCn.RunProcReturn(sql, "H_v_SRM_POInStockBillList");
                //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)
            {
@@ -1058,7 +1060,7 @@
                    string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
                    DataTable dt = new DataTable();
                    List<string> fidList = new List<string>();
                    if (FCusName == "瑞与祺")
                    if (FCusName == "瑞与祺" || FCusName == "")
                    {
                        sql = string.Format(@"
SELECT T3.FNAME AS FTYPENAME,M.HBILLNO,B.HINTERID,B.HENTRYID,C.FID,C.FENTRYID, D.FBILLNO,B.HQTY,CD.FRECEIVEORGID,CDOO.FNUMBER AS FRECEIVENUMBER
@@ -1076,7 +1078,7 @@
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID and FLOCALEID=2052
LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS DOO ON D.FPURCHASEORGID = DOO.FORGID
@@ -1118,10 +1120,8 @@
                                model.Add("FPurOrgId", new JObject() { ["Fnumber"] = dr["FPURCHASEORGNUMBER"].ToString() }); //采购组织
                                model.Add("FSupplierId", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() }); //供应商
                                model.Add("FPURCHASERID", new JObject() { ["Fnumber"] = dr["FPURCHASERNUMBER"].ToString() }); //采购员
                                                                                                                              //model.Add("F_xbkf_Base", new JObject() { ["Fnumber"] = dr["FRECEIVEMENNUMBER"].ToString() }); //收料员
                                model.Add("FOwnerTypeIdHead", "BD_Supplier");//  货主类型
                                model.Add("FOwnerIdHead", new JObject() { ["Fnumber"] = dr["FSUPPLIERNUMBER"].ToString() });//货主 供应商 
                                                                                                                            //model.Add("F_XBKF_COMBO", dr["F_xbkf_Combo1"].ToString());//是否有票
                                JArray Fentity = new JArray();
                                foreach (var item in drs)
                                {
@@ -1174,7 +1174,7 @@
                                };
                                var loginRet = InvokeHelper.Login();
                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                                if (isSuccess == 0)
                                if (isSuccess <= 0)
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
@@ -1231,8 +1231,8 @@
JOIN {0}..T_PUR_POORDERENTRY_F CR ON    C.FENTRYID = CR.FENTRYID
LEFT JOIN {0}..T_ORG_ORGANIZATIONS CROO ON CR.FSETTLEORGID = CROO.FORGID
LEFT JOIN {0}..T_PUR_POORDER D ON C.FID =D.FID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE T2 ON D.FBILLTYPEID = T2.FBILLTYPEID
LEFT JOIN {0}..T_BAS_BILLTYPE_L T3 ON T2.FBILLTYPEID = T3.FBILLTYPEID  and FLOCALEID=2052
LEFT JOIN  {0}..V_BD_BUYER T4 ON D.FPURCHASERID =T4.FID
LEFT JOIN  {0}..T_HR_EMPINFO T5 ON D.F_XBKF_BASE1 = T5.FID
LEFT JOIN {0}..T_BD_SUPPLIER DS ON D.FSUPPLIERID = DS.FSUPPLIERID
@@ -1330,7 +1330,7 @@
                                };
                                var loginRet = InvokeHelper.Login();
                                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                                if (isSuccess == 0)
                                if (isSuccess < 0)
                                {
                                    objjson.code = "0";
                                    objjson.count = 0;
@@ -1338,7 +1338,7 @@
                                    objjson.data = null;
                                    return objjson;
                                }
                                LogService.Write("jsonRoot:" + jsonRoot.ToString());
                                //LogService.Write("jsonRoot:" + jsonRoot.ToString());
                                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                                //LogService.Write(result);
                                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
@@ -1371,7 +1371,7 @@
                        }
                    }
                }
                var check = Get_ReciveBillCheckDate(HBillNo);
                var check = Exec_ReciveBillCheck(HBillNo);
                if (check.code == "0")
                    return check;
                //if(check)
@@ -1410,6 +1410,11 @@
            return HInterID;
        }
        /// <summary>
        /// 到货确认扫收料通知单号 获取表体和表头数据
        /// </summary>
        /// <param name="HBarCode"></param>
        /// <returns></returns>
        public json Get_ReciveBillCheckDate(string HBarCode)
        {
            json objjson = new json();
@@ -1438,7 +1443,7 @@
                    else
                    {
                        objjson.code = "0";
                        objjson.count = 0;
                        objjson.count = 0;
                        objjson.Message = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]);
                        objjson.data = null;
                        return objjson;
@@ -1452,15 +1457,194 @@
                objjson.Message = "没有返回任何记录!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }
        [Route("POStockInBillList/AuditPOInStockBillPost")]
        [HttpPost]
        public object AuditPOInStockBill([FromBody] JObject msg)
        {
            try
            {
                string _msg = msg["msg"].ToString();
                _msg = _msg.Replace("\\", "");
                _msg = _msg.Replace("\n", "");
                List<Models.ReciveBill_FastModel> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Models.ReciveBill_FastModel>>(_msg);
                DAL.ClsCg_POInStockBill oBill = new DAL.ClsCg_POInStockBill();
                var hinterID = list[0].HInterID;
                var FID = list[0].FID;
                oCn.BeginTran();
                string sql = string.Empty;
                foreach (var item in list)
                {
                    if (item.HSQty == 0)
                        continue;
                    sql = $"update Cg_POInStockBillSub set Hqty = {item.HSQty} where HInterID ={item.HInterID} and HEntryID = {item.HEntryID}";
                    oCn.RunProc(sql);
                }
                oCn.RunProc("exec h_p_Cg_UpDatePOOrderRelation_Del " + hinterID);//删除关联关系
                JObject jsonRoot = new JObject();
                jsonRoot.Add("Creator", "");
                jsonRoot.Add("NeedUpDateFields", new JArray());
                jsonRoot.Add("NeedReturnFields", new JArray());
                jsonRoot.Add("IsDeleteEntry", "false");
                jsonRoot.Add("SubSystemId", "");
                jsonRoot.Add("IsVerifyBaseDataField", "");
                JObject jsonModel = new JObject();
                jsonModel.Add("FID", FID);
                JArray Entry = new JArray();
                foreach (var item in list)
                {
                    if (item.HSQty == 0)
                        continue;
                    JObject jsonFPOOrderEntry = new JObject();
                    jsonFPOOrderEntry.Add("FEntryID", item.FEntryID);
                    jsonFPOOrderEntry.Add("FHQty ", item.HSQty); ;
                    Entry.Add(jsonFPOOrderEntry);
                }
                jsonModel.Add("FEntity", Entry);
                jsonRoot.Add("Model", jsonModel);
                var loginRet = InvokeHelper.Login();
                var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
                if (isSuccess <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = loginRet;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                var result = InvokeHelper.Save("PUR_ReceiveBill", jsonRoot.ToString());
                //LogService.Write(result);
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() == "TRUE")
                {
                    LogService.Write("收料通知单修改失败jsonRoot:" + jsonRoot.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单更新失败" + result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                var json = new
                {
                    Ids = FID,
                };
                //提交
                var _result = InvokeHelper.Submit("PUR_ReceiveBill", JsonConvert.SerializeObject(json));
                var _saveObj = JObject.Parse(_result);
                if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("收料通知单提交失败jsonRoot:" + jsonRoot.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单提交失败" + _result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //审核
                _result = InvokeHelper.Audit("PUR_ReceiveBill", JsonConvert.SerializeObject(json));
                _saveObj = JObject.Parse(_result);
                if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("收料通知单审核失败jsonRoot:" + jsonRoot.ToString());
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "金蝶收料通知单审核失败jsonRoot" + _result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                sql = string.Format(@"update Cg_POInStockBillMain set
HBillStatus = 2 ,
HCheckDate   = getdate()
where HInterID in ({0})",  HInterID);
                oCn.RunProc(sql);//更新mes状态
                //更新成功后 同步更新金蝶
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "操作成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "异常!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        /// <summary>
        /// 到货确认 扫条码 校验
        /// </summary>
        /// <param name="HBarcode"></param>
        /// <param name="HInterID"></param>
        /// <returns></returns>
        [Route("POStockInBillList/Get_ReciveBillByBarcode")]
        [HttpGet]
        public object Get_ReciveBillByBarcode(string HBarcode, string HInterID)
        {
            try
            {
                //校验条码是否存在
                string sql = $"select* from  Gy_BarCodeBill where HSourceInterID ={HInterID} and HBarCode = '{HBarcode}'";
                DataSet ds = oCn.RunProcReturn(sql, "H_v_SRM_POOrderBillList");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "条码不存在!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
                //SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
                //string sql = $"select * from H_v_SRM_POInStockBillList where 单据号 ='{HBillno}'";
                //ds = oCn.RunProcReturn(sql, "H_v_SRM_POInStockBillList");
                //if (ds == null || ds.Tables[0].Rows.Count == 0)
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "没有返回任何记录!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
                //else
                //{
                //}
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        //收料通知单审核 审核提交
        [Route("POStockInBillList/Exec_ReciveBillCheck")]
        [HttpGet]
        public object Exec_ReciveBillCheck(string HBarCode)
        public json Exec_ReciveBillCheck(string HBarCode)
        {
            json objjson = new json();
            try
            {
                //修改金蝶生产单的状态
@@ -1470,11 +1654,11 @@
                if (isSuccess == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "操作失败,金蝶账号登录异常。" + loginRet;
                    objJsonResult.data = null;
                    return objJsonResult;
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "操作失败,金蝶账号登录异常。" + loginRet;
                    objjson.data = null;
                    return objjson;
                }
                var json = new
                {
@@ -1499,25 +1683,25 @@
                //判断审核是否成功
                if (JObject.Parse(result2)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "审核收料通知单失败!单据号:" + HBarCode;
                    objJsonResult.data = null;
                    return objJsonResult;
                    objjson.code = "0";
                    objjson.count = 0;
                    objjson.Message = "审核收料通知单失败!单据号:" + HBarCode;
                    objjson.data = null;
                    return objjson;
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "审核成功!";
                objJsonResult.data = 1;
                return objJsonResult;
                return objjson;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
                objjson.code = "0";
                objjson.count = 0;
                objjson.Message = "没有返回任何记录!" + e.ToString();
                objjson.data = null;
                return objjson;
            }
        }