wtt
2024-11-28 957b51cfdeb4374d817086a2ca761c75545e206d
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/JIT_DayPlanPlatFormBillController.cs
@@ -98,6 +98,40 @@
                return objJsonResult;
            }
        }
        /// <summary>
        /// æ ¹æ®ç‚¹å‡»è¡Œæ ‡é¢˜æ—¶é—´æŸ¥è¯¢ç¼ºæ–™åˆ†æž
        /// </summary>
        /// <param name="sWhere"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        [Route("JIT_DayPlanPlatFormBill/JIT_DayPlanPlatFormBillHDateTimeList")]
        [HttpGet]
        public object JIT_DayPlanPlatFormBillHDateTimeList(string sWhere)
        {
            try
            {
                MaterialShorAnalysis Report = JsonConvert.DeserializeObject<MaterialShorAnalysis>(sWhere);
                ds = oCN.RunProcReturn($"exec h_p_JIT_MaterialShorAnalysisReportList {Report.HORGID},'{Report.HBEGINDATE}','{Report.HENDDATE}' ", "h_p_JIT_PODemandPlanBill_ReportList");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                //objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ç”Ÿäº§æ—¥è®¡åˆ’平台 ä¿å­˜
@@ -129,7 +163,7 @@
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string[] sArray = msg1.Split(new string[] { "&和" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string user = sArray[1].ToString();
@@ -160,7 +194,7 @@
                LogService.CustomWriteLog("2:", DateTime.Now.ToString("yyyy-MM-dd"));
                int TrueCount = 0, SumCount = 0;
                LogService.CustomWriteLog("list.Count:"+ list.Count, DateTime.Now.ToString("yyyy-MM-dd"));
                for (int i = 0; i < list.Count; i++)
                {
                    TrueCount = 0;
@@ -169,6 +203,7 @@
                    var HBillNo = "";
                    if (list[i]["单据号"].ToString() == "" && list[i]["hmainid"].ToString() == "")
                    {
                        LogService.CustomWriteLog("2.01:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        var HICMOBillNo = list[i]["生产订单号"].ToString();
                        var HOrderType = list[i]["订单类型"].ToString();
                        var HICMOEntrySEQ = list[i]["生产订单明细行号"].ToString();
@@ -178,13 +213,14 @@
                        var HProdORGID = list[i]["HProdORGID"].ToString();
                        var HMaterID = list[i]["HMaterID"].ToString();
                        var HMaterName = list[i]["物料名称"].ToString();
                        var HMaterModel = list[i]["规格型号"].ToString();
                        var HMaterModel = list[i]["规格型号"].ToString().Replace("'", "''");
                        var HUnitID = list[i]["HUnitID"].ToString();
                        var HSeOrderBillQty = list[i]["销售订单数量"].ToString();
                        //var HOrderNeedQty = list[i]["订单需求数量"].ToString();
                        var HSplitQty = list[i]["拆单数量"].ToString();
                        var HDayPlanSumQty = list[i]["日计划数量总量"].ToString();
                        var HPlanBeginDate = list[i]["计划开始日期"].ToString();
                        var HPlanEndDate = list[i]["计划结束日期"].ToString();
                        var HSeOrderBillNo = list[i]["销售订单号"].ToString();
                        var HICMOBillType = list[i]["生产订单单据类型"].ToString();
                        var HSourceStockInQty = list[i]["产线入库数量"].ToString();
@@ -193,6 +229,9 @@
                        var HMainSourceInterID = list[i]["源单主内码"].ToString();
                        var HMainSourceEntryID = list[i]["源单子内码"].ToString();
                        var HPlanQty = list[i]["计划数量"].ToString();
                        var HEmpID = list[i]["HEmpID"].ToString();
                        LogService.CustomWriteLog("2.05:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        if (HSourceID == ""|| HSourceID == "0")
                        {
@@ -203,7 +242,7 @@
                            return objJsonResult;
                        }
                        ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
                        ds = oCN.RunProcReturn($"select * from Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
                            $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", "Sc_WorkBillSortBillMain");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
@@ -225,7 +264,7 @@
                            " HOrderNeedQty, HSplitQty, HDayPlanSumQty,HPlanBeginDate," +
                            "HSeOrderBillNo,HICMOBillType,HSourceStockInQty,HLeftPlanQty,HOrderLev,HPreparatDate," +
                            "HMainSourceInterID,HMainSourceEntryID,HICMOInterID_Sec,HICMOEntryID_Sec,HPlanQty" +
                            ",HICMOInterID,HICMOEntryID)values" +
                            ",HICMOInterID,HICMOEntryID,HPlanEndDate,HEmpID)values" +
                            $"({HInterID},'{HBillNo}',{DateTime.Now.Year},{DateTime.Now.Month},'{BillType}'," +
                            $"'{BillType}',GETDATE(),1,'{user}',getdate(),'{HICMOBillNo}','{HOrderType}'," +
                            $"{(HICMOEntrySEQ == "" ? 0.ToString() : HICMOEntrySEQ)},{(HWorkShopID == "" ? 0.ToString() : HWorkShopID)},{(HSourceID == "" ? 0.ToString() : HSourceID)}, {(HYX == "" ? 0.ToString() : HYX)}, {(HProdORGID == "" ? 0.ToString() : HProdORGID)}," +
@@ -233,7 +272,7 @@
                            $" 0, {(HSplitQty == "" ? 0.ToString() : HSplitQty)}, {(HDayPlanSumQty == "" ? 0.ToString() : HDayPlanSumQty)},'{HPlanBeginDate}'," +
                            $"'{HSeOrderBillNo}','{HICMOBillType}',{(HSourceStockInQty == "" ? 0.ToString() : HSourceStockInQty)},{(HLeftPlanQty == "" ? 0.ToString() : HLeftPlanQty)},'{HOrderLev}',getdate()," +
                            $"{HMainSourceInterID},{HMainSourceEntryID},{HMainSourceInterID},{HMainSourceEntryID},{HPlanQty}," +
                            $"{HMainSourceInterID},{HMainSourceEntryID})";
                            $"{HMainSourceInterID},{HMainSourceEntryID},'{HPlanEndDate}','{HEmpID}')";
                        //LogService.Write("sql:" + sql);
                        //主表
@@ -241,6 +280,9 @@
                    }
                    else
                    {
                        LogService.CustomWriteLog("2.0:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        HBillNo = list[i]["单据号"].ToString();
                        HInterID = int.Parse(list[i]["hmainid"].ToString());
                        var HMainSourceInterID = list[i]["源单主内码"].ToString();
                        var HMainSourceEntryID = list[i]["源单子内码"].ToString();
                        var HICMOBillNo = list[i]["生产订单号"].ToString();
@@ -254,6 +296,10 @@
                        var HLastEndDate = list[i]["最迟完工日期"].ToString();
                        var HOrderNeedQty = list[i]["订单需求数量"].ToString();
                        var HOrderCommitDate = list[i]["订单交货期"].ToString();
                        var HPlanEndDate = list[i]["计划结束日期"].ToString();
                        var HSplitQty = list[i]["拆单数量"].ToString();
                        LogService.CustomWriteLog("2.1:"+i, DateTime.Now.ToString("yyyy-MM-dd"));
                        if (HSourceID == "" || HSourceID == "0")
                        {
@@ -278,16 +324,20 @@
                        if (ds.Tables[0].Rows.Count > 1)
                        {
                            LogService.CustomWriteLog("第" + i + 1 + "行生产资源有重复,请修改", DateTime.Now.ToString("yyyy-MM-dd"));
                            LogService.CustomWriteLog($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={HMainSourceInterID}" +
                              $" and HMainSourceEntryID={HMainSourceEntryID} and HICMOBillNo='{HICMOBillNo}' and HICMOEntrySEQ={HICMOEntrySEQ} and HSourceID={HSourceID}", DateTime.Now.ToString("yyyy-MM-dd"));
                            objJsonResult.code = "0";
                            objJsonResult.count = 0;
                            objJsonResult.Message = $"第{i + 1}行生产资源有重复,请修改!";
                            objJsonResult.data = null;
                            return objJsonResult;
                        }
                        LogService.CustomWriteLog("2.2:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                        oCN.RunProc($"update Sc_WorkBillSortBillMain set HSourceID={(HSourceID == "" ? 0.ToString() : HSourceID)},HYX={HYX}" +
                            $",HWorkQty={HWorkQty},HProdTimes={HProdTimes},HReadyTimes={HReadyTimes},HLastBeginDate='{HLastBeginDate}'" +
                            $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}'" +
                            $",HLastEndDate='{HLastEndDate}',HOrderNeedQty={HOrderNeedQty},HOrderCommitDate='{HOrderCommitDate}',HPlanEndDate='{HPlanEndDate}',HSplitQty={HSplitQty}" +
                            $" where HInterID={list[i]["hmainid"].ToString()} and HBillNo='{list[i]["单据号"].ToString()}'");
                    }
@@ -295,6 +345,7 @@
                    int SumDay = 31; //动态两月之差 DateTime.Now.AddMonths(1).AddDays(-1).Subtract(DateTime.Now).Days;
                    LogService.CustomWriteLog("2.3:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                    for (int j = 0; j < SumDay; j++)
                    {
                        //主表子表都有数据
@@ -305,7 +356,7 @@
                            objJsonResult = AddBillSub(HInterID == 0 ? list[i]["hmainid"].ToString() : HInterID.ToString()
                                , HBillNo == "" ? list[i]["单据号"].ToString() : HBillNo
                                 , DateTime.Parse(DateTime.Now.AddDays(j).ToString("yyyy-MM-dd").ToString())
                                 , int.Parse(list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString())
                                 , Math.Round(double.Parse(list[i][DateTime.Now.AddDays(j).ToString("yyyy-MM-dd")].ToString()),1)
                                 , list[i]);
                            if (objJsonResult.count == 1)
                            {
@@ -315,22 +366,29 @@
                        //主表有数据 å­è¡¨æ— æ•°æ®
                        if (j == 30 && SumCount == 0 && HInterID != 0 && HBillNo != "")
                        {
                            //LogService.CustomWriteLog("3:"+ HInterID+","+ HBillNo, DateTime.Now.ToString("yyyy-MM-dd"));
                            objJsonResult = AddBillSub(HInterID.ToString(), HBillNo, DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd").ToString()), 0, list[i]);
                        }
                    }
                    LogService.CustomWriteLog("2.4:" + i, DateTime.Now.ToString("yyyy-MM-dd"));
                    if (TrueCount != SumCount)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                if (TrueCount != SumCount)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                LogService.CustomWriteLog("2.5:", DateTime.Now.ToString("yyyy-MM-dd"));
                //同步日计划工单
                oCN.RunProc("exec REALESE_SC_ICMOBILLSTATUS_TMP");
                LogService.CustomWriteLog("2.6:", DateTime.Now.ToString("yyyy-MM-dd"));
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -348,8 +406,8 @@
            }
        }
        public json AddBillSub(string HInterID, string HBillNo, DateTime date, int HQTY, Dictionary<string, string> dic)
        {
        public json AddBillSub(string HInterID, string HBillNo, DateTime date, double HQTY, Dictionary<string, string> dic)
        {
            //获取表格数据
            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where å•据号='{HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
            int count = 0;
@@ -366,14 +424,14 @@
                    }
                }
            }
            if (count != 1)
            {
                //插入子表
                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HSEQ," +
                    "HMasterDate,HQty,HUseTimes)" +
                            $"values({HInterID}, {(ds.Tables[0].Rows.Count + 1)}," +
                            $" '{date}', {HQTY},{(dic["小时产能"] == "0" ? 0 : HQTY / float.Parse(dic["小时产能"].ToString()))})");
                            $" '{date}', {HQTY},{ ( (dic["小时产能"] == "0.0000" ? 0 : HQTY / float.Parse(dic["小时产能"].ToString())).ToString()=="非数字" ? 0 : dic["小时产能"] == "0.0000" ? 0 : HQTY / float.Parse(dic["小时产能"].ToString())) })");
            }
            objJsonResult.code = "1";
@@ -775,9 +833,10 @@
                sw.Start();//开始计时
                //获取当前即时库存 åº“存数量+库存组织+物料+货主+仓库   
                //原查询即时库存方式:select * from h_v_jit_InventoryList
                ds = oCN.RunProcReturn(@" 
select * from h_v_jit_InventoryList
", "h_v_jit_InventoryList");
exec h_p_jit_Inventory_UsableList
", "h_p_jit_Inventory_UsableList");
                ListInventory = ds.ToModelList<PRD_Inventory>();
                //车间 ä»“库对照列表 
                ds = oCN.RunProcReturn(@" 
@@ -1529,6 +1588,14 @@
                    {
                        sqlName = "AIS20230129011339";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "凯贝奈特")
                    {
                        sqlName = "AIS20210820164804";
                    }
                    else if (oSystemParameter.omodel.WMS_CampanyName == "添康科技")
                    {
                        sqlName = "AIS20240809105013";
                    }
                    else
                    {
                        sqlName = "AIS20210811135644";
@@ -1701,7 +1768,8 @@
                                        F_QIMB_NOTE = Purchase.F_QIMB_NOTE,
                                        FNOTE = Purchase.FNOTE,
                                        FPURCHASEQTY = Purchase.FPURCHASEQTY,
                                        FJOINQTY = Purchase.FJOINQTY
                                        FJOINQTY = Purchase.FJOINQTY,
                                        FDAYPLANBILLNO = _item.FDAYPLANBILLNO
                                    });
                                    //扣除日计划明细已被分配的数量
                                    DayPlanPpbomls.NeedQty = 0;
@@ -1764,7 +1832,8 @@
                                        F_QIMB_NOTE = Purchase.F_QIMB_NOTE,
                                        FNOTE = Purchase.FNOTE,
                                        FPURCHASEQTY = Purchase.FPURCHASEQTY,
                                        FJOINQTY = Purchase.FJOINQTY
                                        FJOINQTY = Purchase.FJOINQTY,
                                        FDAYPLANBILLNO = _item.FDAYPLANBILLNO
                                    });
                                    //更新计划数量(剩余需要排的) ç»§ç»­åŽ»è®¡ç®—ä¸‹ä¸€ä¸ªé‡‡è´­è®¢å•
                                    DayPlanPpbomls.NeedQty -= Qty;
@@ -2545,7 +2614,7 @@
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "生产明细行重复,重复的生产订单号:" + ds.Tables[0].Rows[i]["生产订单号"].ToString() + ",明细行号:" + ds.Tables[0].Rows[i]["生产订单明细行号"].ToString();
                        objJsonResult.Message = "生产明细行重复,重复的生产订单号:" + dt.Tables[0].Rows[i]["生产订单号"].ToString() + ",明细行号:" + dt.Tables[0].Rows[i]["生产订单明细行号"].ToString();
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -2604,11 +2673,11 @@
        #region ç”Ÿäº§æ—¥è®¡åˆ’平台 æ•°æ®å‡†å¤‡ è®¾ç½®ä»»åŠ¡å•ç›¸å…³ä¿¡æ¯
        [Route("JIT_DayPlanPlatFormBill/ReadyData")]
        [HttpGet]
        public object ReadyData(string HICOMNum)
        public object ReadyData(string SWhere)
        {
            try
            {
                var list = HICOMNum.Split(',');
                var list = SWhere.Split(',');
                DataTable dt = new DataTable("date");
                dt.Columns.Add("HICMOInterID", typeof(string));
                dt.Columns.Add("HICMOEntryID", typeof(string));
@@ -2624,9 +2693,10 @@
                {
                    string HICMOInterID = list[i].Split(';')[0].ToString();
                    string HICMOEntryID = list[i].Split(';')[1].ToString();
                    string HSourceID = list[i].Split(';')[2].ToString();
                    Thread.Sleep(100);
                    ds = oCN.RunProcReturn("exec h_p_Sc_GetInfoByICMOBillNo " + HICMOInterID+","+ HICMOEntryID, "h_p_Sc_GetInfoByICMOBillNo");
                    ds = oCN.RunProcReturn("exec h_p_Sc_GetInfoByICMOBillNo " + HICMOInterID+","+ HICMOEntryID+","+ HSourceID, "h_p_Sc_GetInfoByICMOBillNo");
                    if (ds == null || ds.Tables[0].Rows.Count == 0)
                    {
                        
@@ -2698,5 +2768,62 @@
        }
        #endregion
        #region æ ¹æ®ç‰©æ–™ID获取工艺路线 åˆ—表
        [Route("JIT_DayPlanPlatFormBill/GetRoutingListByMater")]
        [HttpGet]
        public object GetRoutingListByMater(int HMaterID, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                int IsHavingPermissions = 1;
                //判断是否有工艺路线编辑权限
                if (!DBUtility.ClsPub.Security_Log("Gy_RoutingBill_Edit", 1, false, user))
                {
                    IsHavingPermissions = 0;
                }
                ds = oCN.RunProcReturn("select * from  h_v_JIT_GetRoutingList_Mater where HMaterID = " + HMaterID , "h_v_JIT_GetRoutingList_Mater");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "当前物料没有维护工艺路线!请联系计划部进行维护";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.IsHavingPermissions = IsHavingPermissions;
                    return objJsonResult;
                }
                else
                {
                    //添加列名
                    foreach (DataColumn col in ds.Tables[0].Columns)
                    {
                        Type dataType = col.DataType;
                        string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                        columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    objJsonResult.list = columnNameList;
                    objJsonResult.IsHavingPermissions = IsHavingPermissions;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}