duhe
2023-09-07 2fa45c3a43e907ad22dcfada5be88c0f31115e31
WebAPI/Controllers/Sc_ProcessMangementController.cs
@@ -6,10 +6,12 @@
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Web.Http;
using WebAPI.DLL;
using WebAPI.Models;
using WebAPI.Service;
using Kingdee.BOS.WebApi.Client;
namespace WebAPI.Controllers
{
@@ -18,8 +20,8 @@
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
@@ -188,6 +190,8 @@
            }
        }
        #endregion
        #region 斯莫尔 末道工序汇报列表  汇报 入库
        /// <summary>
        /// 生成 生产汇报单  
@@ -274,7 +278,6 @@
        //        model.Add("FBillType", new JObject() { ["Fnumber"] = "SCHBD01_SYS" }); //单据类型生产汇报“SCHBD02_SYS” 入库汇报SCHBD01_SYS
        //        model.Add("FPrdOrgId", new JObject() { ["Fnumber"] = dr1["FPrdOrgNUMBER"].ToString() }); //生产组织1
        //        model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //单据日期1
        //        model.Add("FHZYMESFLAG", "是");//  是否为MES同步
        //        model.Add("FBillNo", BillNo);
        //        JArray Fentity = new JArray();
@@ -302,19 +305,15 @@
        //            FentityModel.Add("FFailQty", item["不良数量"].ToString());//不合格数量
        //            FentityModel.Add("FStockInOrgId ", new JObject() { ["Fnumber"] = OrganizationNUM });// 入库组织 
        //            FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = dr1["FStockNUM"].ToString() }); // 仓库 
        //            FentityModel.Add("FMOID", dr1["FMOID"].ToString());//
        //            FentityModel.Add("FMOBILLNO", dr1["FMOBILLNO"].ToString());//  
        //            FentityModel.Add("FMOENTRYID", dr1["FMOENTRYID"].ToString());//  
        //            FentityModel.Add("FMOENTRYSEQ", dr1["FMOENTRYSEQ"].ToString());//
        //            FentityModel.Add("FOwnerTypeId", dr1["FOWNERTYPEID"].ToString()); //货主类型:FOwnerTypeId(必填项)
        //            FentityModel.Add("FOwnerId", new JObject() { ["Fnumber"] = dr1["FOwnerNumber"].ToString() }); //货主:FOwnerId(必填项)
        //            FentityModel.Add("FBomId", new JObject() { ["Fnumber"] = dr1["FBOMNUM"].ToString() }); //BOM版本:FBomId(必填项)
        //            FentityModel.Add("FBomId", new JObject() { ["F    number"] = dr1["FBOMNUM"].ToString() }); //BOM版本:FBomId(必填项)
        //            FentityModel.Add("FCostRate", dr1["FCostRate"].ToString());// 成本权重
        //            FentityModel.Add("FISBACKFLUSH", dr1["FISBACKFLUSH"].ToString() == "1" ? true : false);// 倒冲领料
        //            FentityModel.Add("FMOMAINENTRYID", dr1["FMOENTRYID"].ToString());//
        //            FentityModel.Add("F_bsv_Base1", new JObject() { ["Fnumber"] = dr1["FPREBDONENUMBER"].ToString() }); //包装标识
        //            FentityModel.Add("FLot", new JObject() { ["FNumber"] = dr1["FBATCHNO"].ToString() }); //批号
        //            FentityModel.Add("F_bsv_Text", dr1["工序流转卡号"].ToString()); //流转卡号
        //            JArray Fentity2 = new JArray();
        //            JObject FentityModel2 = new JObject();
        //            FentityModel2.Add("FEntity_Link_FFlowId", "f6e6eec3-5267-4f02-8593-b633da508a72");
@@ -327,9 +326,6 @@
        //            FentityModel2.Add("FEntity_Link_FBaseQuaQtyOld", item["合格数量"].ToString());
        //            FentityModel2.Add("FEntity_Link_FBaseQuaQty", item["合格数量"].ToString());
        //            Fentity2.Add(FentityModel2);
        //            FentityModel.Add("FEntity_Link", Fentity2);
        //            FentityModel.Add("FBFLowId", new JObject() { ["FID"] = "f6e6eec3-5267-4f02-8593-b633da508a72" }); //
        //            Fentity.Add(FentityModel);
        //        }
        //        model.Add("FEntity", Fentity); //明细信息                       
        //        JObject jsonRoot = new JObject()
@@ -409,6 +405,10 @@
        {
            try
            {
                string sErr = "";
                oSystemParameter.ShowBill(ref sErr);
                //获取生产汇报单最大InterID和单据号
                Int64 HInterID = DBUtility.ClsPub.CreateBillID("3711", ref DBUtility.ClsPub.sExeReturnInfo);
                string HBillNo = DBUtility.ClsPub.CreateBillCode("3711", ref DBUtility.ClsPub.sExeReturnInfo, true);
@@ -416,11 +416,19 @@
                string OrganizationNUM = oCN.RunProcReturn("select HNumber from Xt_ORGANIZATIONS where HItemID=" + OrganizationID, "Xt_ORGANIZATIONS").Tables[0].Rows[0]["HNumber"].ToString();
                //根据工序汇报单主ID获取工序汇报入库单的数据
                DataSet ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_LastProc where HInterID=" + InterID, "h_v_MES_StationOutBillList_LastProc");
                if (ds.Tables[0].Rows.Count <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "生成生产汇报单过程中没有查询到出站单";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataRow dr = ds.Tables[0].Rows[0];
                //保存
                oCN.BeginTran();
                DataSet DsTable = oCN.RunProcReturn($"select * from Sc_ICMOReportBillMain where HBillNo='{HBillNo}'"  , "Sc_ICMOReportBillMain");
                DataSet DsTable = oCN.RunProcReturn($"select * from Sc_ICMOReportBillMain where HBillNo='{HBillNo}'", "Sc_ICMOReportBillMain");
                if (DsTable.Tables[0].Rows.Count > 0)
                {
                    objJsonResult.code = "0";
@@ -429,18 +437,18 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                    //生产汇报单主表
                    oCN.RunProc("Insert Into Sc_ICMOReportBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
                ",HYear,HPeriod,HRemark,HEmpID,HEmpNumber" +
                ",HGroupID,HDeptID,HDeptNumber" +
                ",HMainSourceBillNo,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillType" +
                ") " +
                " values('3711','3711'," + HInterID.ToString() + ",'" + BillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" +
                ",DATENAME(YEAR,GETDATE()),0,'','" + dr["HEmpID"].ToString() + "','" + dr["操作员代码"].ToString() +
                "','" + dr["HGroupID"].ToString() + "',0,''" +
                ",'" + BillNo.ToString() + "'," + InterID.ToString() + ", 0,'3791'" +
                ") ");
                //生产汇报单主表
                oCN.RunProc("Insert Into Sc_ICMOReportBillMain   " +
            "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
            ",HYear,HPeriod,HRemark,HEmpID,HEmpNumber" +
            ",HGroupID,HDeptID,HDeptNumber" +
            ",HMainSourceBillNo,HMainSourceInterID,HMainSourceEntryID,HMainSourceBillType" +
            ") " +
            " values('3711','3711'," + HInterID.ToString() + ",'" + BillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" +
            ",DATENAME(YEAR,GETDATE()),0,'','" + dr["HEmpID"].ToString() + "','" + dr["操作员代码"].ToString() +
            "','" + dr["HGroupID"].ToString() + "',0,''" +
            ",'" + BillNo.ToString() + "'," + InterID.ToString() + ", 0,'3791'" +
            ") ");
                //生产汇报单子表
                oCN.RunProc("Insert into Sc_ICMOReportBillSub " +
                      " (HInterID,HEntryID,HMaterID,HMaterNumber" +
@@ -481,7 +489,7 @@
                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //单据日期1
                model.Add("FHZYMESFLAG", "是");//  是否为MES同步
                model.Add("FBillNo", BillNo);
                JArray Fentity = new JArray();
                foreach (DataRow item in ds.Tables[0].Rows)
@@ -517,7 +525,10 @@
                    FentityModel.Add("FCostRate", dr1["FCostRate"].ToString());// 成本权重
                    FentityModel.Add("FISBACKFLUSH", dr1["FISBACKFLUSH"].ToString() == "1" ? true : false);// 倒冲领料
                    FentityModel.Add("FMOMAINENTRYID", dr1["FMOENTRYID"].ToString());//
                    FentityModel.Add("F_bsv_Base1", new JObject() { ["Fnumber"] = dr1["FPREBDONENUMBER"].ToString() }); //包装标识
                    if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                    {
                        FentityModel.Add("F_bsv_Base1", new JObject() { ["Fnumber"] = dr1["FPREBDONENUMBER"].ToString() });//包装标识
                    }
                    FentityModel.Add("FLot", new JObject() { ["FNumber"] = dr1["FBATCHNO"].ToString() }); //批号
                    FentityModel.Add("F_bsv_Text", dr1["工序流转卡号"].ToString()); //流转卡号
                    JArray Fentity2 = new JArray();
@@ -548,7 +559,7 @@
                    //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能
                    ["Model"] = model
                };
                string result = InvokeHelper.Save("PRD_MORPT", JsonConvert.SerializeObject(jsonRoot));//保存
                //判断保存是否成功
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
@@ -582,7 +593,7 @@
                    return objJsonResult;
                }
                oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo+"'");
                oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo + "'");
                oCN.Commit();
                objJsonResult.code = "0";
@@ -622,6 +633,19 @@
                ////根据工序汇报单主ID获取工序汇报入库单的数据
                //DataSet ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_LastProc where HInterID=" + InterID, "h_v_MES_StationOutBillList_LastProc");
                //DataRow dr = ds.Tables[0].Rows[0];
                //判断入库的合格数量是否为0
                var DTable = oCN.RunProcReturn("select * from  Sc_StationOutBillMain where HBillNo='" + BillNo + "' ", "Sc_StationOutBillMain").Tables[0];
                if (double.Parse(DTable.Rows[0]["HQty"].ToString()) == 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 2;
                    objJsonResult.Message = "合格数量为0,不需要入库!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //保存
                oCN.BeginTran();
                //生产汇报单主表
@@ -669,8 +693,18 @@
                //
                //DataSet ds1 = oCN.RunProcReturn("select * from  h_v_TOERPProcduct_LastProc where HLastProc = '是' and  hbillno='" + BillNo.ToString() + "'", "h_v_TOERPProcduct_LastProc");
                DataSet ds1 = oCN.RunProcReturn("exec h_p_TOERPProcduct_LastProc '" + BillNo + "'", "h_p_TOERPProcduct_LastProc");
                if (ds1 == null || ds1.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "未找到对应的本地或金蝶云生产汇报单记录;1.未查询到对应的生产汇报单;2.请确保当前工序是末道工序3.汇报单对应的入库数量已满 请在金蝶云查看入库记录!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                DataRow dr1 = ds1.Tables[0].Rows[0];
                if (ds1.Tables[0].Rows.Count <= 0)
                if (double.Parse(dr1[0].ToString()) <= 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -678,6 +712,48 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                string sErr = "";
                if (oSystemParameter.ShowBill(ref sErr))
                {
                    if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                    {
                        //判断金蝶云是否已经有入库的数据
                        ds = oCN.RunProcReturn($@"select * from AIS20220308151944..T_PRD_INSTOCK where FBILLNO='{BillNo}'", "T_PRD_INSTOCK");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "当前出站单号已入库,请不要重新入库!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        //判断金蝶云生产汇报单 数量 是否 大于 末道出站数量
                        ds = oCN.RunProcReturn($@"select sum(FFinishQty)-sum(FSTOCKINQUASELQTY)-(select HQty from Sc_StationOutBillMain where HBillNo='{BillNo}')
                        from  AIS20220308151944..T_PRD_MORPT rpt3
                        left join AIS20220308151944..T_PRD_MORPTENTRY  rpt2 on rpt3.FID = rpt2.FID
                        left join AIS20220308151944..T_PRD_MORPTENTRY_A  rpt1 on rpt2.FID = rpt1.FID
                        where F_bsv_Text=(select HProcExchBillNo from Sc_StationOutBillMain where HBillNo='{BillNo}')", "SumCount");
                        if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) < 0)
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "金蝶云汇报数量小于本地出站数量!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                }
                JObject model = new JObject();
                model.Add("FBillType", new JObject() { ["FNumber"] = "SCRKD01_SYS" }); //单据类型
@@ -710,7 +786,21 @@
                    FentityModel.Add("FBaseRealQty", item["数量"].ToString());//
                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//
                    FentityModel.Add("FOwnerId", new JObject() { ["FNumber"] = item["HPrdOrgNumber"].ToString() });//
                    FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumber"].ToString() }); // 仓库
                    if (oSystemParameter.ShowBill(ref sErr))
                    {
                        if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                        {
                            if (oSystemParameter.omodel.MES_StationOutBill_InStockType == "工艺路线")
                            {
                                FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumbers"].ToString() }); // 仓库
                            }
                            else if (oSystemParameter.omodel.MES_StationOutBill_InStockType == "工序")
                            {
                                FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumber"].ToString() }); // 仓库
                            }
                        }
                    }
                    FentityModel.Add("FLot", new JObject() { ["FNumber"] = item["HBatchNo"].ToString() }); //批号
                    FentityModel.Add("FISBACKFLUSH", "true");//  
                    FentityModel.Add("FWorkShopId1", new JObject() { ["FNumber"] = item["HWorkShopNumber"].ToString() }); //  生产车间
@@ -734,18 +824,18 @@
                    FentityModel.Add("F_bsv_Base1", new JObject() { ["FNumber"] = item["HBZBS"].ToString() });//
                    FentityModel.Add("F_BSV_TEXT", item["HLZKH"].ToString());//  
                    FentityModel.Add("F_BSV_TEXT1", item["HWYID"].ToString());//
                                                                               //批号
                                                                               //FFLOWID FFLOWLINEID FRULEID FSTABLENAME
                                                                               //f6e6eec3 - 5267 - 4f02 - 8593 - b633da508a72    3   PRD_MO2MORPT T_PRD_MOENTRY
                                                                               //业务流程图:FEntity_Link_FFlowId
                                                                               //推进路线:FEntity_Link_FFlowLineId
                                                                               //转换规则:FEntity_Link_FRuleId
                                                                               //源单表内码:FEntity_Link_FSTableId
                                                                               //源单表:FEntity_Link_FSTableName
                                                                               //源单内码:FEntity_Link_FSBillId
                                                                               //源单分录内码:FEntity_Link_FSId
                                                                               //原始携带量:FEntity_Link_FBaseQuaQtyOld
                                                                               //修改携带量:FEntity_Link_FBaseQuaQty
                                                                              //批号
                                                                              //FFLOWID FFLOWLINEID FRULEID FSTABLENAME
                                                                              //f6e6eec3 - 5267 - 4f02 - 8593 - b633da508a72    3   PRD_MO2MORPT T_PRD_MOENTRY
                                                                              //业务流程图:FEntity_Link_FFlowId
                                                                              //推进路线:FEntity_Link_FFlowLineId
                                                                              //转换规则:FEntity_Link_FRuleId
                                                                              //源单表内码:FEntity_Link_FSTableId
                                                                              //源单表:FEntity_Link_FSTableName
                                                                              //源单内码:FEntity_Link_FSBillId
                                                                              //源单分录内码:FEntity_Link_FSId
                                                                              //原始携带量:FEntity_Link_FBaseQuaQtyOld
                                                                              //修改携带量:FEntity_Link_FBaseQuaQty
@@ -753,7 +843,7 @@
                    JObject FentityModel2 = new JObject();
                    FentityModel2.Add("FEntity_Link_FFlowId", "f6e6eec3-5267-4f02-8593-b633da508a72");
                    FentityModel2.Add("FEntity_Link_FFlowLineId", "5");
                    FentityModel2.Add("FEntity_Link_FRuleId", "PRD_MORPT2INSTOCK");
                    FentityModel2.Add("FEntity_Link_FRuleId", "PRD_MORPT2INSTOCK");
                    FentityModel2.Add("FEntity_Link_FSTableName", "T_PRD_MORPTENTRY");
                    FentityModel2.Add("FEntity_Link_FSTableId", "0");
                    FentityModel2.Add("FEntity_Link_FSBillId", item["HSourceInterID"].ToString());
@@ -869,6 +959,20 @@
                ////根据工序汇报单主ID获取工序汇报入库单的数据
                //DataSet ds = oCN.RunProcReturn("select * from h_v_MES_StationOutBillList_LastProc where HInterID=" + InterID, "h_v_MES_StationOutBillList_LastProc");
                //DataRow dr = ds.Tables[0].Rows[0];
                //判断本次报废总数量是否为0
                var DTable = oCN.RunProcReturn("select isnull(sum(HWasterQty),0) HWasterQty from  Sc_StationOutBillMain where  HProcExchBillNo='" + BillNo + "' and HBFFlag=0 ", "Sc_StationOutBillMain").Tables[0];
                if (double.Parse(DTable.Rows[0]["HWasterQty"].ToString()) == 0)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 2;
                    objJsonResult.Message = "报废数量为0,不需要入库!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //保存
                oCN.BeginTran();
                //生产汇报单主表
@@ -949,7 +1053,21 @@
                    FentityModel.Add("FBaseRealQty", item["数量"].ToString());//
                    FentityModel.Add("FOwnerTypeId", "BD_OwnerOrg");//
                    FentityModel.Add("FOwnerId", new JObject() { ["FNumber"] = item["HPrdOrgNumber"].ToString() });//
                    FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumber"].ToString() }); // 仓库
                    string sErr = "";
                    if (oSystemParameter.ShowBill(ref sErr))
                    {
                        if (oSystemParameter.omodel.WMS_CampanyName == "瑞与祺")
                        {
                            if (oSystemParameter.omodel.MES_StationOutBill_InStockType == "工艺路线")
                            {
                                FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumbers"].ToString() }); // 仓库
                            }
                            else if (oSystemParameter.omodel.MES_StationOutBill_InStockType == "工序")
                            {
                                FentityModel.Add("FStockId", new JObject() { ["FNumber"] = item["HStockNumber"].ToString() }); // 仓库
                            }
                        }
                    }
                    FentityModel.Add("FLot", new JObject() { ["FNumber"] = item["HBatchNo"].ToString() }); //批号
                    FentityModel.Add("FISBACKFLUSH", "true");//  
                    FentityModel.Add("FWorkShopId1", new JObject() { ["FNumber"] = item["HWorkShopNumber"].ToString() }); //  生产车间
@@ -964,7 +1082,7 @@
                    FentityModel.Add("FSrcInterId", item["HSourceInterID"].ToString());//  
                    FentityModel.Add("FBasePrdRealQty", item["数量"].ToString());//
                    FentityModel.Add("FIsFinished", "false");//
                    FentityModel.Add("FStockStatusId", new JObject() { ["FNumber"] = "KCZT08_SYS" }); //
                    FentityModel.Add("FStockStatusId", new JObject() { ["FNumber"] = "KCZT001" }); //
                    FentityModel.Add("FSrcEntrySeq", item["HSourceSeQ"].ToString());//  源单分录行号
                    FentityModel.Add("FMOMAINENTRYID", item["HMOEntryID"].ToString());//
                    FentityModel.Add("FKeeperTypeId", "BD_KeeperOrg");
@@ -1068,7 +1186,7 @@
                    return objJsonResult;
                }
                 //oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo + "'");
                //oCN.RunProc("update Sc_StationOutBillMain set HRelationQty=1 where  HBillNo='" + BillNo + "'");
                oCN.Commit();
                oCN.RunProc("update  sc_stationoutbillmain set HBFFlag =1 where HProcExchBillNo = '" + BillNo + "'");
@@ -1097,21 +1215,35 @@
        /// <returns></returns>
        [Route("QCStockInCheckBill/set_SaveQCStockInCheckBill_Json")]
        [HttpGet]
        public object set_SaveQCStockInCheckBill_Json(string HZJOrgNumber, string HMaterNumber, string HUnitNumber,
        public object set_SaveQCStockInCheckBill_Json(string HZJOrgNumber, string HMaterNumber, string HUnitNumber,
            double HCheckQty, double HRightQty, double HBadQty,
            string HCheckResult, string HSupNumber, string HWHNumber,
            string HUseResult, Int64 HSeQ, Int64 HSourceInterID,
            string HCheckResult, string HSupNumber,
            string HUseResult, Int64 HSeQ, Int64 HSourceInterID,
            Int64 HSourceEntryID, string HSourceBillNo, string user,
            Int64 HWHID, Int64 HSPID, Int64 HSupID, Int64 HKeeperID,
            Int64 HWHID, Int64 HSPID, Int64 HSupID, Int64 HKeeperID,
            Int64 HMaterID, string HSourceBillType, Int64 HSLInterID,
            Int64 HSLEntryID, string HSLBillNo, Int64 HSLSeQ)
            Int64 HSLEntryID, string HSLBillNo, Int64 HSLSeQ, string HBillNo, Int64 HInterID, string HBatchNo)
        {
            try
            {
                //获取生产汇报单最大InterID和单据号
                Int64 HInterID = DBUtility.ClsPub.CreateBillID("7503", ref DBUtility.ClsPub.sExeReturnInfo);
                string HBillNo = DBUtility.ClsPub.CreateBillCode("7503", ref DBUtility.ClsPub.sExeReturnInfo, true);
                //Int64 HInterID = DBUtility.ClsPub.CreateBillID("7503", ref DBUtility.ClsPub.sExeReturnInfo);
                //string HBillNo = DBUtility.ClsPub.CreateBillCode("7503", ref DBUtility.ClsPub.sExeReturnInfo, true);
                DataSet ds1 = oCN.RunProcReturn("select   * from MES_AccessoriesList  where  HSourceBillNo = '" + HBillNo + "'", "MES_AccessoriesList");
                string HFileName = DBUtility.ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HFileName"]);
                string HFilePath = DBUtility.ClsPub.isStrNull(ds1.Tables[0].Rows[0]["HFilePath"]);
                string path = HFilePath;
                FileInfo fi = new FileInfo(path);
                long len = fi.Length;
                byte[] buffer = new byte[len];
                FileStream fs = new FileStream(path, FileMode.Open);
                fs.Read(buffer, 0, (int)len);
                //文件IO流
                string a = Convert.ToBase64String(buffer);
                //保存
                oCN.BeginTran();
                //生产汇报单主表
@@ -1150,56 +1282,58 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                JObject model = new JObject();
                model.Add("FBillTypeID", new JObject() { ["Fnumber"] = "JYD001_SYS" }); //单据类型 来料检验单JYD001_SYS
                model.Add("FBusinessType", "1"); //业务类型
                model.Add("FDate", DateTime.Now.ToString("yyyy-MM-dd")); //单据日期
                model.Add("FSourceOrgId", new JObject() { ["Fnumber"] = HZJOrgNumber.ToString() }); //来源组织
                model.Add("FInspectOrgId", new JObject() { ["Fnumber"] = HZJOrgNumber.ToString() }); //质检组织
                model.Add("FSourceOrgId", new JObject() { ["Fnumber"] = HZJOrgNumber.ToString() }); //来源组织
                model.Add("FISSYNCED", "false");//  是否已同步
                model.Add("F_PGKJ_Date", DateTime.Now.ToString("yyyy-MM-dd"));//  报检日期
                model.Add("FBillNo", HBillNo);
                JArray Fentity = new JArray();
                    JObject FentityModel = new JObject();
                    FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                    FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//计量单位内码
                    FentityModel.Add("FInspectQty", HCheckQty.ToString());//  检验数量
                    FentityModel.Add("FQualifiedQty", HRightQty.ToString());//  合格数量
                    FentityModel.Add("FUnqualifiedQty", HBadQty.ToString());//  不合格数量
                    FentityModel.Add("FInspectResult", HCheckResult.ToString());//  检验结果
                    FentityModel.Add("FQCStatus", "1");//  质检状态
                    FentityModel.Add("FIsRelated", false);//  不良品关联标志
                    FentityModel.Add("FSrcBillType0", "PUR_ReceiveBill");//  源单类型
                    FentityModel.Add("FBaseUnitId", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//基本单位
                    FentityModel.Add("FBaseInspectQty", HCheckQty.ToString());//基本单位检验数量
                    FentityModel.Add("FSupplierId", new JObject() { ["Fnumber"] = HSupNumber.ToString() }); //  供应商
                    //FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = HWHNumber.ToString() }); // 仓库
                    FentityModel.Add("FInspectTimes","1"); // 检验次数
                    FentityModel.Add("FTimeUnit","24");//时间单位
                    FentityModel.Add("FSAMPLEDAMAGEBEARER","2");//样本破坏承担方
                    FentityModel.Add("FISFIRSTINSPECT", false);//首检
                    FentityModel.Add("FBaseQualifiedQty", HRightQty.ToString());//基本单位合格数
                JObject FentityModel = new JObject();
                FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//计量单位内码
                FentityModel.Add("FInspectQty", HCheckQty.ToString());//  检验数量
                FentityModel.Add("FQualifiedQty", HRightQty.ToString());//  合格数量
                FentityModel.Add("FUnqualifiedQty", HBadQty.ToString());//  不合格数量
                FentityModel.Add("FInspectResult", HCheckResult.ToString());//  检验结果
                FentityModel.Add("FQCStatus", "1");//  质检状态
                FentityModel.Add("FIsRelated", false);//  不良品关联标志
                FentityModel.Add("FSrcBillType0", "PUR_ReceiveBill");//  源单类型
                FentityModel.Add("FBaseUnitId", new JObject() { ["Fnumber"] = HUnitNumber.ToString() });//基本单位
                FentityModel.Add("FBaseInspectQty", HCheckQty.ToString());//基本单位检验数量
                FentityModel.Add("FSupplierId", new JObject() { ["Fnumber"] = HSupNumber.ToString() }); //  供应商
                                                                                                        //FentityModel.Add("FStockId", new JObject() { ["Fnumber"] = HWHNumber.ToString() }); // 仓库
                FentityModel.Add("FInspectTimes", "1"); // 检验次数
                FentityModel.Add("FTimeUnit", "24");//时间单位
                FentityModel.Add("FSAMPLEDAMAGEBEARER", "2");//样本破坏承担方
                FentityModel.Add("FISFIRSTINSPECT", false);//首检
                FentityModel.Add("FBaseQualifiedQty", HRightQty.ToString());//基本单位合格数
                FentityModel.Add("FBaseAcceptQty", HRightQty.ToString());//基本单位接收数
                FentityModel.Add("FCurrency", new JObject() { ["Fnumber"] = "PRE001" });//币别
                    FentityModel.Add("FIsSplitRow ", false);// 是否拆分行
                FentityModel.Add("FIsSplitRow ", false);// 是否拆分行
                FentityModel.Add("FLot", new JObject() { ["Fnumber"] = HBatchNo.ToString() });//批号
                    JArray Fentity2 = new JArray();
                    JObject FentityModel2 = new JObject();
                    FentityModel2.Add("FPolicyMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                    FentityModel2.Add("FPolicyStatus", "1");  //状态
                    FentityModel2.Add("FPolicyQty", HRightQty.ToString());    //数量
                    FentityModel2.Add("FBasePolicyQty", HRightQty.ToString()); //基本单位数量
                    FentityModel2.Add("FUsePolicy", HUseResult.ToString());   //使用决策
                    FentityModel2.Add("FIsCheck", false);   //是否抽检
                    FentityModel2.Add("FIsDefectProcess", false);  //不良处理
                    FentityModel2.Add("FCanSale", false);   //可销售
                    FentityModel2.Add("FIsMRBReview", false);   //MRP评审
                    FentityModel2.Add("FIsReturn", true);   //判退
                    FentityModel2.Add("FIsRelatedDefect", false);   //不良品关联标志
                    Fentity2.Add(FentityModel2);
                    FentityModel.Add("FPolicyDetail", Fentity2);
                JArray Fentity2 = new JArray();
                JObject FentityModel2 = new JObject();
                FentityModel2.Add("FPolicyMaterialId", new JObject() { ["Fnumber"] = HMaterNumber.ToString() });//  物料内码
                FentityModel2.Add("FPolicyStatus", "1");  //状态
                FentityModel2.Add("FPolicyQty", HRightQty.ToString());    //数量
                FentityModel2.Add("FBasePolicyQty", HRightQty.ToString()); //基本单位数量
                FentityModel2.Add("FUsePolicy", HUseResult.ToString());   //使用决策
                FentityModel2.Add("FIsCheck", false);   //是否抽检
                FentityModel2.Add("FIsDefectProcess", false);  //不良处理
                FentityModel2.Add("FCanSale", false);   //可销售
                FentityModel2.Add("FIsMRBReview", false);   //MRP评审
                FentityModel2.Add("FIsReturn", true);   //判退
                FentityModel2.Add("FIsRelatedDefect", false);   //不良品关联标志
                Fentity2.Add(FentityModel2);
                FentityModel.Add("FPolicyDetail", Fentity2);
@@ -1209,7 +1343,7 @@
                FentityModel3.Add("FSrcBillType", "PUR_ReceiveBill");   //源单类型
                FentityModel3.Add("FSrcBillNo", HSLBillNo.ToString());    //收料通知单单号
                FentityModel3.Add("FSrcInterId", HSLInterID.ToString());      //收料通知单主ID
                FentityModel3.Add("FSrcEntryId",HSLEntryID.ToString());    //收料通知单子ID
                FentityModel3.Add("FSrcEntryId", HSLEntryID.ToString());    //收料通知单子ID
                FentityModel3.Add("FSrcEntrySeq", HSLSeQ.ToString());    //源单行号
                FentityModel3.Add("FOrderType", new JObject() { ["FID"] = "PUR_PurchaseOrder" });  //  订单类型
                FentityModel3.Add("FOrderBillNo", HSourceBillNo.ToString());   //订单单号
@@ -1257,7 +1391,7 @@
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"来料检验单同步金蝶云失败!单号:{HBillNo.ToString()}" + result;
                    objJsonResult.Message = $"来料检验单同步金蝶云失败!单号:{HBillNo.ToString()}" + jsonRoot;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
@@ -1270,6 +1404,12 @@
                {
                    Ids = fID,
                };
                K3CloudApiClient client = new K3CloudApiClient("http://47.96.97.237/k3cloud");
                //        K3CloudApiClient client = new K3CloudApiClient("http://192.168.80.90/k3cloud/");
                result1 = InvokeHelper.Submit("QM_InspectBill", JsonConvert.SerializeObject(json));//提交
                result2 = InvokeHelper.Audit("QM_InspectBill", JsonConvert.SerializeObject(json));//提交
                if (JObject.Parse(result1)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
@@ -1280,6 +1420,20 @@
                    objJsonResult.Message = $"来料检验单号:{fBillNo},提交失败" + result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    string jsonStr = "{" +
                       " \"FileName\":\"" + HFileName + "\"," +
                           " \"FormId\":\"QM_InspectBill\"," +
                           " \"IsLast\":\"true\"," +
                           " \"InterId\":\"" + HInterID + "\"," +
                           " \"BillNO\":\"" + HBillNo + "\"," +
                           " \"AliasFileName\":\"test\"," +
                           " \"SendByte\":\"" + a + "\"," +
                       "}";
                    var ret = client.AttachmentUpload(jsonStr);
                }
                oCN.Commit();
@@ -1299,7 +1453,57 @@
                return objJsonResult;
            }
        }
        #endregion
        ///// <summary>
        ///// 生成金蝶云来料检验单
        ///// </summary>
        ///// <param name="InterID">工序汇报单主ID</param>
        ///// <returns></returns>
        //[Route("QCStockInCheckBill/set_SaveQCStockInCheckBill_Json")]
        //[HttpGet]
        //public object set_SaveQCStockInCheckBill_Json(string HZJOrgNumber, string HMaterNumber, string HUnitNumber,
        //    double HCheckQty, double HRightQty, double HBadQty,
        //    string HCheckResult, string HSupNumber,
        //    string HUseResult, Int64 HSeQ, Int64 HSourceInterID,
        //    Int64 HSourceEntryID, string HSourceBillNo, string user,
        //    Int64 HWHID, Int64 HSPID, Int64 HSupID, Int64 HKeeperID,
        //    Int64 HMaterID, string HSourceBillType, Int64 HSLInterID,
        //    Int64 HSLEntryID, string HSLBillNo, Int64 HSLSeQ, string HBillNo, Int64 HInterID,ref string sErrMsg)
        //{
        //    WebS.WebService1 oWebs1 = new WebS.WebService1();
        //    //oWebs1.Url = "http://localhost:9099/WebService1.asmx";
        //    //K3CloudApiClient client = new K3CloudApiClient("http://192.168.80.90/k3cloud/");
        //    if (oWebs1.set_SaveQcStockInCheckBill_New(HZJOrgNumber, HMaterNumber, HUnitNumber, HCheckQty, HRightQty, HBadQty
        //        , HCheckResult, HSupNumber, HUseResult, HSeQ, HSourceInterID
        //        , HSourceEntryID, HSourceBillNo, user, HWHID, HSPID
        //        , HSupID, HKeeperID, HMaterID, HSourceBillType, HSLInterID
        //        , HSLEntryID, HSLBillNo, HSLSeQ, HBillNo, HInterID
        //        , ref sErrMsg))
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 1;
        //        objJsonResult.Message = "生成单据成功!";
        //        objJsonResult.data = null;
        //        return objJsonResult;
        //    }
        //    else
        //    {
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "生成单据失败!";
        //        objJsonResult.data = sErrMsg;
        //        return objJsonResult;
        //    }
        //}
@@ -1328,7 +1532,7 @@
                string HBillNo = DBUtility.ClsPub.CreateBillCode("7501", ref DBUtility.ClsPub.sExeReturnInfo, true);
                //保存
                oCN.BeginTran();
                //oCN.BeginTran();
                //生成产品检验单
                //oCN.RunProc("Insert Into QC_POStockInCheckBillMain   " +
                //"(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
@@ -1464,6 +1668,10 @@
                //FentityModel.Add("FReferDetail", Fentity3);
                Fentity.Add(FentityModel);
                model.Add("FEntity", Fentity); //明细信息
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                DataSet ds = oCN.RunProcReturn("select HCheckdate from Sc_ProcessReportMain where hbillno = '" + HSourceBillNo + "'", "Sc_ProcessReportMain");
                DateTime HCheckDate = DBUtility.ClsPub.isDate(ds.Tables[0].Rows[0]["HCheckdate"]);
                JObject jsonRoot = new JObject()
                {
                    ["Creator"] = "",
@@ -1472,6 +1680,7 @@
                    ["IsDeleteEntry"] = "false",
                    ["SubSystemId"] = "",
                    ["IsVerifyBaseDataField"] = "false",
                    ["F_PGKJ_Date"] = HCheckDate.ToString(),
                    //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能
                    ["Model"] = model
                };
@@ -2799,6 +3008,115 @@
        }
        #endregion
        #region 不良品处理单关闭/反关闭功能
        [Route("Sc_ProcessMangement/CloseSc_ProcessMangement")]
        [HttpGet]
        public object CloseSc_ProcessMangement(string HInterID, int Type, string user)
        {
            try
            {
                //判断是否有删除权限
                if (!DBUtility.ClsPub.Security_Log("QC_NoPassProdCheckBill_Close", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (string.IsNullOrWhiteSpace(HInterID))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ClsPub.CurUserName = user;
                BillOld.MvarItemKey = "QC_NoPassProdCheckBillMain";
                oCN.BeginTran();//开始事务
                //Type 1 关闭  2  反关闭
                if (Type == 1)
                {
                    //判断单据是否已经关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已关闭!不需要再关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //关闭单据
                    if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                else
                {
                    //判断单据是否已经反关闭
                    DataSet ds;
                    string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID;
                    ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey);
                    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                    {
                        if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "")
                        {
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = "单据已反关闭!不需要再反关闭!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                    }
                    //反关闭单据
                    if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 1;
                        objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                oCN.Commit();//提交事务
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "执行成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "执行失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        /// <summary>
        /// PDA工序汇报单保存
        /// </summary>