yangle
2023-03-10 dabd6d20c31442d461fc30c49aa04abd4549be6b
WebAPI/Controllers/Sc_ProcessMangementController.cs
@@ -20,7 +20,7 @@
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
@@ -276,7 +276,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();
@@ -304,19 +303,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");
@@ -329,9 +324,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()
@@ -624,6 +616,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();
                //生产汇报单主表
@@ -672,7 +677,7 @@
                //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");
                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;
@@ -712,7 +717,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() }); //  生产车间
@@ -871,6 +890,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();
                //生产汇报单主表
@@ -951,7 +984,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() }); //  生产车间
@@ -1092,6 +1139,259 @@
        }
        ///// <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)
        //{
        //    try
        //    {
        //        //获取生产汇报单最大InterID和单据号
        //        //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();
        //        //生产汇报单主表
        //        oCN.RunProc("Insert Into QC_POStockInCheckBillMain   " +
        //        "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
        //        ",HYear,HPeriod,HRemark,HSupID,HMaterID" +
        //        ",HInstockQty,HCheckQty,HRightQty,HBadQty,HFirstCheckEmp" +
        //        ",HCheckerResult,HSteelStoveNo,HSteelCompReport,HAspect,HSize" +
        //        ") " +
        //        " values('7503','7503'," + HInterID.ToString() + ",'" + HBillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" +
        //        ",DATENAME(YEAR,GETDATE()),0,''," + HSupID.ToString() + "," + HMaterID.ToString() +
        //        ",'" + HCheckQty.ToString() + "','" + HCheckQty.ToString() + "','" + HRightQty.ToString() + "','" + HBadQty.ToString() + "','" + HKeeperID.ToString() + "'" +
        //        ",'" + HCheckResult.ToString() + "','', '','',''" +
        //        ") ");
        //        //生产汇报单子表
        //        oCN.RunProc("Insert into QC_POStockInCheckBillSub " +
        //              " (HInterID,HEntryID,HCloseMan,HCloseType" +
        //              ",HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
        //              ",HRelationQty,HRelationMoney,HQCCheckClassID,HQCCheckItemID,HQCStd," +
        //              "HResult,HQCRelValue,HProcCheckEmp,HProcCheckTime" +
        //              ") values("
        //              + HInterID.ToString() + ",1,'',''" +
        //              ",''," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','" + HSourceBillType.ToString() + "'" +
        //              ",0,0,0,0,''" +
        //              ",'" + HCheckResult.ToString() + "','" + HCheckResult.ToString() + "','" + HKeeperID.ToString() + "',getdate()" +
        //              ") ");
        //        //同步金蝶
        //        //访问金蝶
        //        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;
        //        }
        //        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("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());//基本单位合格数
        //        FentityModel.Add("FBaseAcceptQty", HRightQty.ToString());//基本单位接收数
        //        FentityModel.Add("FCurrency", new JObject() { ["Fnumber"] = "PRE001" });//币别
        //            FentityModel.Add("FIsSplitRow ", false);// 是否拆分行
        //            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 Fentity3 = new JArray();
        //        JObject FentityModel3 = new JObject();
        //        FentityModel3.Add("FDetailID", "0");//
        //        FentityModel3.Add("FSrcBillType", "PUR_ReceiveBill");   //源单类型
        //        FentityModel3.Add("FSrcBillNo", HSLBillNo.ToString());    //收料通知单单号
        //        FentityModel3.Add("FSrcInterId", HSLInterID.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());   //订单单号
        //        FentityModel3.Add("FOrderId", HSourceInterID.ToString());      //订单主ID
        //        FentityModel3.Add("FOrderEntryId", HSourceEntryID.ToString());  //订单子ID
        //        FentityModel3.Add("FOrderEntrySeq", HSeQ.ToString());  //订单行号
        //        Fentity3.Add(FentityModel3);
        //        FentityModel.Add("FReferDetail", Fentity3);
        //        JArray Fentity4 = new JArray();
        //        JObject FentityModel4 = new JObject();
        //        FentityModel4.Add("FEntity_Link_FRuleId", "QM_PURReceive2Inspect");   //单据转换规则
        //        FentityModel4.Add("FEntity_Link_FSTableName", "T_PUR_RECEIVEENTRY");    //收料通知单子表
        //        FentityModel4.Add("FEntity_Link_FSBillId", HSLInterID.ToString());      //收料通知单主内码
        //        FentityModel4.Add("FEntity_Link_FSId", HSLEntryID.ToString());    //收料通知单子内码
        //        FentityModel4.Add("FEntity_Link_FBaseAcceptQty", HRightQty.ToString());    //
        //        FentityModel4.Add("FEntity_Link_FBaseAcceptQtyOld", HRightQty.ToString());    //
        //        FentityModel4.Add("FEntity_Link_FBaseInspectQtyOld", HRightQty.ToString());    //
        //        FentityModel4.Add("FEntity_Link_FInspectQtyOld", HRightQty.ToString());    //
        //        Fentity4.Add(FentityModel4);
        //        FentityModel.Add("FEntity_Link", Fentity4);
        //        Fentity.Add(FentityModel);
        //        model.Add("FEntity", Fentity); //明细信息
        //        JObject jsonRoot = new JObject()
        //        {
        //            ["Creator"] = "",
        //            ["NeedUpDateFields"] = new JArray(),
        //            ["NeedReturnFields"] = new JArray(),
        //            ["IsDeleteEntry"] = "false",
        //            ["SubSystemId"] = "",
        //            ["IsVerifyBaseDataField"] = "false",
        //            //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能
        //            ["Model"] = model
        //        };
        //        string result = InvokeHelper.Save("QM_InspectBill", JsonConvert.SerializeObject(jsonRoot));//保存
        //        //判断保存是否成功
        //        if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
        //        {
        //            LogService.Write("来料检验单保存错误jsonRoot:" + jsonRoot);
        //            oCN.RollBack();
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            objJsonResult.Message = $"来料检验单同步金蝶云失败!单号:{HBillNo.ToString()}" + jsonRoot;
        //            objJsonResult.data = null;
        //            return objJsonResult;
        //        }
        //        //提交审核
        //        string result1 = string.Empty;
        //        string result2 = string.Empty;
        //        var fID = JObject.Parse(result)["Result"]["Id"].ToString();
        //        var fBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
        //        var json = new
        //        {
        //            Ids = fID,
        //        };
        //        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")
        //        {
        //            oCN.RollBack();
        //            objJsonResult.code = "0";
        //            objJsonResult.count = 0;
        //            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();
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 1;
        //        objJsonResult.Message = "保存成功!";
        //        objJsonResult.data = 1;
        //        return objJsonResult;
        //    }
        //    catch (Exception e)
        //    {
        //        oCN.RollBack();
        //        objJsonResult.code = "0";
        //        objJsonResult.count = 0;
        //        objJsonResult.Message = "Exception!" + e.ToString();
        //        objJsonResult.data = null;
        //        return objJsonResult;
        //    }
        //}
        //#endregion
        /// <summary>
        /// 生成金蝶云来料检验单
        /// </summary>
@@ -1099,240 +1399,39 @@
        /// <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, string HBillNo, Int64 HInterID)
            Int64 HSLEntryID, string HSLBillNo, Int64 HSLSeQ, string HBillNo, Int64 HInterID,ref string sErrMsg)
        {
            try
            WebS2.WebService1 oWebs1 = new WebS2.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))
            {
                //获取生产汇报单最大InterID和单据号
                //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();
                //生产汇报单主表
                oCN.RunProc("Insert Into QC_POStockInCheckBillMain   " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMaker,HMakeDate,HBillStatus,HChecker,HCheckDate" +
                ",HYear,HPeriod,HRemark,HSupID,HMaterID" +
                ",HInstockQty,HCheckQty,HRightQty,HBadQty,HFirstCheckEmp" +
                ",HCheckerResult,HSteelStoveNo,HSteelCompReport,HAspect,HSize" +
                ") " +
                " values('7503','7503'," + HInterID.ToString() + ",'" + HBillNo + "',getdate(),'" + user + "',getdate(),2,'" + user + "',getdate()" +
                ",DATENAME(YEAR,GETDATE()),0,''," + HSupID.ToString() + "," + HMaterID.ToString() +
                ",'" + HCheckQty.ToString() + "','" + HCheckQty.ToString() + "','" + HRightQty.ToString() + "','" + HBadQty.ToString() + "','" + HKeeperID.ToString() + "'" +
                ",'" + HCheckResult.ToString() + "','', '','',''" +
                ") ");
                //生产汇报单子表
                oCN.RunProc("Insert into QC_POStockInCheckBillSub " +
                      " (HInterID,HEntryID,HCloseMan,HCloseType" +
                      ",HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
                      ",HRelationQty,HRelationMoney,HQCCheckClassID,HQCCheckItemID,HQCStd," +
                      "HResult,HQCRelValue,HProcCheckEmp,HProcCheckTime" +
                      ") values("
                      + HInterID.ToString() + ",1,'',''" +
                      ",''," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo.ToString() + "','" + HSourceBillType.ToString() + "'" +
                      ",0,0,0,0,''" +
                      ",'" + HCheckResult.ToString() + "','" + HCheckResult.ToString() + "','" + HKeeperID.ToString() + "',getdate()" +
                      ") ");
                //同步金蝶
                //访问金蝶
                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;
                }
                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("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());//基本单位合格数
                FentityModel.Add("FBaseAcceptQty", HRightQty.ToString());//基本单位接收数
                FentityModel.Add("FCurrency", new JObject() { ["Fnumber"] = "PRE001" });//币别
                    FentityModel.Add("FIsSplitRow ", false);// 是否拆分行
                    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 Fentity3 = new JArray();
                JObject FentityModel3 = new JObject();
                FentityModel3.Add("FDetailID", "0");//
                FentityModel3.Add("FSrcBillType", "PUR_ReceiveBill");   //源单类型
                FentityModel3.Add("FSrcBillNo", HSLBillNo.ToString());    //收料通知单单号
                FentityModel3.Add("FSrcInterId", HSLInterID.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());   //订单单号
                FentityModel3.Add("FOrderId", HSourceInterID.ToString());      //订单主ID
                FentityModel3.Add("FOrderEntryId", HSourceEntryID.ToString());  //订单子ID
                FentityModel3.Add("FOrderEntrySeq", HSeQ.ToString());  //订单行号
                Fentity3.Add(FentityModel3);
                FentityModel.Add("FReferDetail", Fentity3);
                JArray Fentity4 = new JArray();
                JObject FentityModel4 = new JObject();
                FentityModel4.Add("FEntity_Link_FRuleId", "QM_PURReceive2Inspect");   //单据转换规则
                FentityModel4.Add("FEntity_Link_FSTableName", "T_PUR_RECEIVEENTRY");    //收料通知单子表
                FentityModel4.Add("FEntity_Link_FSBillId", HSLInterID.ToString());      //收料通知单主内码
                FentityModel4.Add("FEntity_Link_FSId", HSLEntryID.ToString());    //收料通知单子内码
                FentityModel4.Add("FEntity_Link_FBaseAcceptQty", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FBaseAcceptQtyOld", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FBaseInspectQtyOld", HRightQty.ToString());    //
                FentityModel4.Add("FEntity_Link_FInspectQtyOld", HRightQty.ToString());    //
                Fentity4.Add(FentityModel4);
                FentityModel.Add("FEntity_Link", Fentity4);
                Fentity.Add(FentityModel);
                model.Add("FEntity", Fentity); //明细信息
                JObject jsonRoot = new JObject()
                {
                    ["Creator"] = "",
                    ["NeedUpDateFields"] = new JArray(),
                    ["NeedReturnFields"] = new JArray(),
                    ["IsDeleteEntry"] = "false",
                    ["SubSystemId"] = "",
                    ["IsVerifyBaseDataField"] = "false",
                    //["IsAutoSubmitAndAudit"] = true,//自动调用提交和审核功能
                    ["Model"] = model
                };
                string result = InvokeHelper.Save("QM_InspectBill", JsonConvert.SerializeObject(jsonRoot));//保存
                //判断保存是否成功
                if (JObject.Parse(result)["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
                {
                    LogService.Write("来料检验单保存错误jsonRoot:" + jsonRoot);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"来料检验单同步金蝶云失败!单号:{HBillNo.ToString()}" + jsonRoot;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                //提交审核
                string result1 = string.Empty;
                string result2 = string.Empty;
                var fID = JObject.Parse(result)["Result"]["Id"].ToString();
                var fBillNo = JObject.Parse(result)["Result"]["Number"].ToString();
                var json = new
                {
                    Ids = fID,
                };
                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")
                {
                    string jsonStr = "{" +
                        " \"FileName\":\"" + HFileName + "\"," +
                            " \"FormId\":\"QM_InspectBill\"," +
                            " \"IsLast\":\"true\"," +
                            " \"InterId\":\"" + HInterID + "\"," +
                            " \"BillNO\":\"" + HBillNo + "\"," +
                            " \"AliasFileName\":\"test\"," +
                            " \"SendByte\":\"" + a + "\"," +
                        "}";
                    var ret = client.AttachmentUpload(jsonStr);
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = $"来料检验单号:{fBillNo},提交失败" + result;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.Commit();
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存成功!";
                objJsonResult.data = 1;
                objJsonResult.Message = "生成单据成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            else
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                objJsonResult.Message = "生成单据失败!";
                objJsonResult.data = sErrMsg;
                return objJsonResult;
            }
        }