王 垚
2020-12-31 3ee1243be7aa6a7bdbfc23a96da82dc72b4de3b4
src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs
@@ -115,7 +115,6 @@
        public override void EntryBarItemClick(BarItemClickEventArgs e)
        {
            base.EntryBarItemClick(e);
            if (e.BarItemKey.ToUpper() == "TBEDIT")
            {
                SearchListEdit();
@@ -127,23 +126,25 @@
        /// <param name="e"></param>    
        public override void EntityRowDoubleClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.EntityRowClickEventArgs e)
        {
            var m = e.Row;
            var n = e.Key;
            base.EntityRowClick(e);
            DynamicFormShowParameter formPa = new DynamicFormShowParameter();
            formPa.FormId = "paez_CompleteAnalysisDetail";
            /* jsonModel.Add("FHMainICMOInterID", FMainInterID);//主生产订单主内码
             jsonModel.Add("FHMainICMOEntryID", FMainEntryID);//主生产订单子内码
             jsonModel.Add("FHICMOInterID", FDayPlanWorkID);//日计划订单主内码
            current["FMatrailId_Id"].ToString(), current["FHMainSourceInterID"].ToString(), current["FHMainSourceEntryID"].ToString(), current["FDayPlanWorkID"].ToString())
            */
            formPa.CustomParams.Add("FHMainICMOInterID", Convert.ToString(this.View.Model.GetValue("FHMainSourceInterID", e.Row).ToString()));
            formPa.CustomParams.Add("FHMainICMOEntryID", Convert.ToString(this.View.Model.GetValue("FHMainSourceEntryID", e.Row).ToString()));
            formPa.CustomParams.Add("FHICMOInterID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString()));
            formPa.CustomParams.Add("FMatrailId_Id", Convert.ToString((this.View.Model.GetValue("FMatrailId", e.Row) as DynamicObject)["Id"].ToString()));
            if (e.ColKey == "FDELAYLNUM")
            {
                //生产计划平台拖期明细跳转
                formPa.FormId = "paez_TardinessDetails";
                formPa.CustomParams.Add("FID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString()));
            }
            else
            {
                //齐套分析明细列表跳转
                formPa.FormId = "paez_CompleteAnalysisDetail";
                formPa.CustomParams.Add("FHMainICMOInterID", Convert.ToString(this.View.Model.GetValue("FHMainSourceInterID", e.Row).ToString()));
                formPa.CustomParams.Add("FHMainICMOEntryID", Convert.ToString(this.View.Model.GetValue("FHMainSourceEntryID", e.Row).ToString()));
                formPa.CustomParams.Add("FHICMOInterID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString()));
                formPa.CustomParams.Add("FMatrailId_Id", Convert.ToString((this.View.Model.GetValue("FMatrailId", e.Row) as DynamicObject)["Id"].ToString()));
            }
            this.View.ShowForm(formPa);
        }
        /// <summary>
@@ -711,7 +712,6 @@
        /// </summary>
        public void CompleteSetAnalysis()
        {
            try
            {
                Stopwatch sw = new Stopwatch();
@@ -760,7 +760,7 @@
                string sql = @"
/*dialect*/
select a.FPRDMOMAINID,a.FPRDMOENTYID,a.FID,b.FEntryID,a.FHPRDORGID FStockOrgId,t5.FNUMBER as OrgFnumber,a.FHOrderLev,b.FHQTY,b.FHMASTERDATE,T1.FBillNo,T1.FMOBillNO,T1.FMOEntrySeq,T1.FMoId,T1.FMaterialID,T1.FQty,
T2.FMATERIALID FMATERIALID2, T4.FNumber,T2.FNeedQty,FNeedQty/FQty dwyl,FHQTY*(FNeedQty/FQty) PlanCount  from SC_WORKBILLSORTBILLMAIN a
T2.FMATERIALID FMATERIALID2, T4.FNumber,T2.FNeedQty,FNeedQty/FQty dwyl,(FHQTY-ISNULL(FProductNum,0))*(FNeedQty/FQty) PlanCount  from SC_WORKBILLSORTBILLMAIN a
join SC_WORKBILLSORTBILLSub b on a.FID = b.FID
join T_PRD_PPBOM T1 on a.FPRDMOMAINID = t1.FMoId and a.FPRDMOENTYID = t1.FMOENTRYID
LEFT JOIN(select FID, MAX(FENTRYID) FENTRYID, SUM(FNeedQty) FNeedQty, FMATERIALID from T_PRD_PPBOMENTRY
@@ -768,10 +768,10 @@
 --LEFT JOIN T_STK_Inventory T3 on t2.FMATERIALID = t3.FMATERIALID
JOIN T_BD_MATERIAL T4 on T2.FMATERIALID = T4.FMATERIALID
JOIN T_ORG_Organizations t5 on a.FHPRDORGID = t5.FORGID
--where FPRDMOMAINID = 100010
--where  t4.FMATERIALID in (105773
--)
ORDER BY b.FHMASTERDATE,a.FHOrderLev  ";
--条件为今天往后的日计划 + 今天之前未关闭的日计划
where (FHEntryCloseDate is null and DATEDIFF(D,GETDATE(),FHMASTERDATE)<0)or DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0
ORDER BY b.FHMASTERDATE,a.FHOrderLev
";
                ds = DBServiceHelper.ExecuteDataSet(Context, sql);
                List<PRD_PPBOM> BomList = ds.ToModelList<PRD_PPBOM>();
                //日计划+生产订单子表编码ID
@@ -779,18 +779,17 @@
                //CompleteAnalysisTempModel 用于存储临时需要插入数据
                List<CompleteAnalysisTempModel> completeAnalysisTempModel = new List<CompleteAnalysisTempModel>();
                int i = 1;
                //创建字典 用于储存物料 + 占用数量
                Dictionary<string, decimal> occupyDic = new Dictionary<string, decimal>();
                foreach (var item in DatePlanList)
                {
                    this.View.Session["ProcessRateValue"] = Convert.ToInt32(this.View.Session["ProcessRateValue"]) + Convert.ToInt32((decimal)(1.0 / DatePlanList.Count));
                    //筛选出当日计划数据
                    var _BomList = BomList.Where(x => x.FHMASTERDATE == item.FHMASTERDATE && x.FPRDMOENTYID == item.FPRDMOENTYID).ToList();
                    foreach (var _item in _BomList)
                    {
                        //该日计划物料需要数
                        decimal need = _item.PlanCount;
                        //实际总库存
                        decimal sjkc = 0;
                        var sjkcList = ListInventoryByStockOrgId.Where(x => x.FMATERIALID == _item.FMATERIALID2 && x.FStockOrgId == _item.FStockOrgId).FirstOrDefault();
                        //真正需要取计算的数量(拆分货主)
                        //货主匹配
@@ -800,10 +799,20 @@
                            decimal _fLackCount = _item.PlanCount > sjkcList.FBASEQTY ? (_item.PlanCount - sjkcList.FBASEQTY) : 0;//缺料数量
                            foreach (var Inventory in _ListInventory)
                            {
                                if (need == 0)
                                    break;
                                decimal fCompleteCount = need >= Inventory.FBASEQTY ? Inventory.FBASEQTY : need;//齐套数量
                                //总计划数量 和 总库存数量比对
                                decimal occupyMaterial = 0;
                                if (!occupyDic.ContainsKey(_item.FMATERIALID2))
                                {
                                    occupyDic.Add(_item.FMATERIALID2, fCompleteCount);
                                }
                                else
                                {
                                    occupyMaterial = occupyDic[_item.FMATERIALID2];
                                    occupyDic[_item.FMATERIALID2] = occupyMaterial + fCompleteCount;
                                }
                                completeAnalysisTempModel.Add(new Demo.Model.Model.CompleteAnalysisTempModel
                                {
                                    FHMainICMOInterIDr = _item.FPRDMOMAINID,
@@ -822,6 +831,7 @@
                                    FLackCount = _fLackCount,//缺料数量
                                    FHStockQty = sjkcList.FBASEQTY,//即时库存
                                    FHLeftQty = Inventory.FBASEQTY,//可用数量
                                    FOccupyCount = occupyMaterial,//占用数量
                                    FComPlete = sjkcList.FBASEQTY >= _item.PlanCount ? "齐套" : "未齐套",
                                    FPlanDate = item.FHMASTERDATE // 日计划日期
                                });
@@ -835,6 +845,9 @@
                        }
                        else
                        {
                            decimal occupyMaterial = 0;
                            if (occupyDic.ContainsKey(_item.FMATERIALID2))
                                occupyMaterial = occupyDic[_item.FMATERIALID2];
                            completeAnalysisTempModel.Add(new Demo.Model.Model.CompleteAnalysisTempModel
                            {
                                FHMainICMOInterIDr = _item.FPRDMOMAINID,
@@ -852,12 +865,13 @@
                                FLackCount = _item.PlanCount,//缺料数量
                                FHStockQty = 0,//即时库存
                                FHLeftQty = 0,//可用数量
                                FOccupyCount = occupyMaterial,//占用数量
                                FComPlete = "未齐套",
                                FPlanDate = item.FHMASTERDATE // 日计划日期
                            });
                        }
                    }
                    Thread.Sleep(100);
                    //Thread.Sleep(100);
                    this.View.Session["ProcessRateValue"] = Convert.ToInt32((Convert.ToDecimal(40) / DatePlanList.Count) * i);
                    i++;
@@ -891,6 +905,7 @@
                    jsonModel.Add("FOwnerTypeId", item.FOwnerTypeId);
                    jsonModel.Add("FComPlete", item.FComPlete);
                    jsonModel.Add("FLackCount", item.FLackCount);
                    jsonModel.Add("FOccupyCount", item.FOccupyCount);
                    jsonModel.Add("FPlanDate", item.FPlanDate);
                    if (item.FOwnerId != null)
                        jsonModel.Add("FOwnerId", new JObject() { ["FNUMBER"] = item.FOwnerId });
@@ -954,8 +969,8 @@
                sqlwhere += $" and FPreparatDate='{FPreparatDate}'";
            try
            {
                string sql = @"/*dialect*/select t1.* from  Sc_WorkBillSortBillMain t1
   left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID
                string sql = @"/*dialect*/ select t1.*,isnull((select SUM(isnull(FNotProductNum,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FNotProductNum from  Sc_WorkBillSortBillMain t1
 left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID
" + sqlwhere;
                DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
                DateTime DateNow = DateTime.Now;//获取当前日期
@@ -987,15 +1002,11 @@
                    this.Model.SetValue("FOrderQuantity", dt.Rows[i]["FOrderQuantity"].ToString(), i);//生产订单数量
                    this.Model.SetValue("FDayPlanQuantity", dt.Rows[i]["FDayPlanQuantity"].ToString(), i);//日计划数量
                    this.Model.SetValue("FNoScheduled", dt.Rows[i]["FNoScheduled"].ToString(), i);//未排数量
                    this.Model.SetValue("FDelaylnUM", dt.Rows[i]["FNotProductNum"].ToString(), i);//拖期数量
                    sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[i]["FID"].ToString();
                    DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
                    foreach (DataRow dr in _dt.Rows)
                    {
                        /*
                        this.Model.SetValue(dr["FColumn"].ToString(), dr["FHQTY"].ToString(), i);//日计划工单FID
                        if (dr["FHLockedSub"].ToString() == "1")
                            this.View.GetFieldEditor(dr["FColumn"].ToString(), i).Enabled = false; //单据体行锁定字段
                        */
                        DateTime start = Convert.ToDateTime(DateNow.ToShortDateString());
                        DateTime end = Convert.ToDateTime(Convert.ToDateTime(dr["FHMASTERDATE"]).ToShortDateString());
                        TimeSpan getDay = end.Subtract(start);
@@ -1087,8 +1098,8 @@
                sqlwhere += $" and FPreparatDate='{FPreparatDate}'";
            try
            {
                string sql = @"/*dialect*/select t1.* from  Sc_WorkBillSortBillMain t1
   left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID
                string sql = @"/*dialect*/ select t1.*,isnull((select SUM(isnull(FNotProductNum,0)) from SC_WORKBILLSORTBILLSub t2 where t2.FID = t1.FID and DATEDIFF(D,FHMASTERDATE,GETDATE())>0),0)FNotProductNum from  Sc_WorkBillSortBillMain t1
 left join T_BD_MATERIAL t3 on t1.FHMaterID=t3.FMATERIALID
" + sqlwhere;
                DataTable dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
                DateTime DateNow = DateTime.Now;//获取当前日期
@@ -1120,6 +1131,7 @@
                    this.Model.SetValue("FOrderQuantity", dt.Rows[i]["FOrderQuantity"].ToString(), i);//生产订单数量
                    this.Model.SetValue("FDayPlanQuantity", dt.Rows[i]["FDayPlanQuantity"].ToString(), i);//日计划数量
                    this.Model.SetValue("FNoScheduled", dt.Rows[i]["FNoScheduled"].ToString(), i);//未排数量
                    this.Model.SetValue("FDelaylnUM", dt.Rows[i]["FNotProductNum"].ToString(), i);//拖期数量
                    sql = @"/*dialect*/SELECT * FROM Sc_WorkBillSortBillSub WHERE DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0 and FID=" + dt.Rows[i]["FID"].ToString();
                    DataTable _dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
                    foreach (DataRow dr in _dt.Rows)