From 1cf5992836d59a53a279de0486b86c0f0a5091fa Mon Sep 17 00:00:00 2001
From: 王 垚 <1402714037@qq.com>
Date: 星期二, 24 八月 2021 10:23:44 +0800
Subject: [PATCH] 齐套分析拉取数据时 由FNeedQty 更改为FMUSTQTY

---
 src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs |  860 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 793 insertions(+), 67 deletions(-)

diff --git a/src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs b/src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs
index 5002c02..5d7e7ae 100644
--- a/src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs
+++ b/src/BLL/Demo.BillView/PRD/Pro_WorkBillPlatform.cs
@@ -108,6 +108,11 @@
                 {
                     COMPLETE();
                 }
+                //榻愬鍒嗘瀽
+                if (e.BarItemKey.ToUpper() == "TBCOMPLETEBOM")
+                {
+                    COMPLETEBOM();
+                }
                 //tbXnqt铏氭嫙榻愬
                 if (e.BarItemKey.ToUpper() == "TBXNQT")
                 {
@@ -239,6 +244,9 @@
             }
             else
             {
+                var type = this.View.Model.GetValue("FQTTYPE");
+                if(type =="鏍囧噯Bom")
+                    formPa.CustomParams.Add("tempName", "JIT_MOMaterReadysBomBill");
                 //榻愬鍒嗘瀽鏄庣粏鍒楄〃璺宠浆
                 formPa.FormId = "paez_CompleteAnalysisDetail";
                 formPa.CustomParams.Add("FHICMOInterID", Convert.ToString(this.View.Model.GetValue("FDayPlanWorkID", e.Row).ToString()));
@@ -384,16 +392,7 @@
             string sql = $"/*dialect*/update t1 set t1.FHLockedSub=1 from Sc_WorkBillSortBillSub t1  join Sc_WorkBillSortBillMain t2 on  t1.FID = t2.FID  where  FHMASTERDATE between  DATEADD(day,-1,getdate()) and DATEADD(day,{day - 1},getdate())";
             sqlList.Add(sql);
             int result = DBServiceHelper.ExecuteBatch(Context, sqlList);
-            //if (result > 0)
-            //{
-            //閿佸畾鍚庣敓鎴愭棩璁″垝鐢ㄦ枡娓呭崟 鍙� 鎻愭枡璁″垝
             DayPlanPPBomBill();
-            //Extraction();
-            //SearchList();
-            
-            //}
-            //else
-            //    this.View.ShowMessage("鎿嶄綔澶辫触锛岃仈绯荤鐞嗗憳锛�");
         }
         /// <summary>
         /// 瑙i攣
@@ -407,7 +406,7 @@
             DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity);
             List<string> sqlList = new List<string>();
             string sql = $"/*dialect*/update t1 set t1.FHLockedSub=0 from Sc_WorkBillSortBillSub t1  join Sc_WorkBillSortBillMain t2 on  t1.FID = t2.FID  where  FHMASTERDATE between  DATEADD(day,-1,getdate()) and DATEADD(day,{day - 1},getdate())";
-              DBServiceHelper.Execute(Context, sql);
+            DBServiceHelper.Execute(Context, sql);
             //foreach (var item in entityDataObjoct)
             //{
             //    sql = $"/*dialect*/update t1 set t1.FHLockedSub=0 from Sc_WorkBillSortBillSub t1  join Sc_WorkBillSortBillMain t2 on  t1.FID = t2.FID  where  FHMASTERDATE between  DATEADD(day,-1,getdate()) and DATEADD(day,{day - 1},getdate())   and t1.FID = { Convert.ToString(item["FDayPlanWorkID"])} ";
@@ -442,49 +441,175 @@
             }
             foreach (DynamicObject current in entityDataObjoct)
             {
-                JObject jsonRoot = new JObject();
-                jsonRoot.Add("Creator", "");
-                jsonRoot.Add("NeedUpDateFields", new JArray());
-                jsonRoot.Add("NeedReturnFields", new JArray());
-                jsonRoot.Add("IsDeleteEntry", "false");
-                jsonRoot.Add("SubSystemId", "");
-                jsonRoot.Add("IsVerifyBaseDataField", "");
-                JObject jsonModel = new JObject();
-                jsonModel.Add("FID", Convert.ToString(current["FDayPlanWorkID"]));
-                jsonModel.Add("FOrderQuantity", Convert.ToString(current["FOrderQuantity"]));
-                jsonModel.Add("FDayPlanQuantity", Convert.ToDecimal(current["FDayPlanQuantity"]) + Convert.ToDecimal(current["FQTYLS"]));
-                jsonModel.Add("FNoScheduled", Convert.ToString(current["FNoScheduled"]));
-                sql = $" /*dialect*/ select FEntryID, FHMASTERDATE from SC_WORKBILLSORTBILLSub  where FID={Convert.ToString(current["FDayPlanWorkID"])} ";
-                List<DayPlanModel> dayPlanModel = new List<DayPlanModel>();
-                dayPlanModel = DBServiceHelper.ExecuteDataSet(Context, sql).ToModelList<DayPlanModel>();
-                JArray Entry = new JArray();
-                for (int i = 0; i <= 60; i++)
+                if (Convert.ToInt32(current["FDayPlanWorkID"]) > 0)
                 {
-                    if (Convert.ToString(current["FT" + "" + i + ""]) == "" || Convert.ToString(current["FT" + "" + i + ""]) == "0")
-                        continue;
-                    JObject jsonFPOOrderEntry = new JObject();
-                    jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈�
-                    jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲�
-                    List<DayPlanModel> _dayPlanModel = dayPlanModel.Where(x => x.FHMASTERDATE == date.AddDays(i)).ToList();
-                    if (_dayPlanModel.Count > 0)
+                    JObject jsonRoot = new JObject();
+                    jsonRoot.Add("Creator", "");
+                    jsonRoot.Add("NeedUpDateFields", new JArray());
+                    jsonRoot.Add("NeedReturnFields", new JArray());
+                    jsonRoot.Add("IsDeleteEntry", "false");
+                    jsonRoot.Add("SubSystemId", "");
+                    jsonRoot.Add("IsVerifyBaseDataField", "");
+                    JObject jsonModel = new JObject();
+                    jsonModel.Add("FID", Convert.ToString(current["FDayPlanWorkID"]));
+                    jsonModel.Add("FOrderQuantity", Convert.ToString(current["FOrderQuantity"]));
+                    jsonModel.Add("FDayPlanQuantity", Convert.ToDecimal(current["FDayPlanQuantity"]) + Convert.ToDecimal(current["FQTYLS"]));
+                    jsonModel.Add("FNoScheduled", Convert.ToString(current["FNoScheduled"]));
+                    sql = $" /*dialect*/ select FEntryID, FHMASTERDATE from SC_WORKBILLSORTBILLSub  where FID={Convert.ToString(current["FDayPlanWorkID"])} ";
+                    List<DayPlanModel> dayPlanModel = new List<DayPlanModel>();
+                    dayPlanModel = DBServiceHelper.ExecuteDataSet(Context, sql).ToModelList<DayPlanModel>();
+                    JArray Entry = new JArray();
+                    for (int i = 0; i <= 60; i++)
                     {
-                        jsonFPOOrderEntry.Add("FEntryID", _dayPlanModel.FirstOrDefault().FEntryID); ;//搴忓彿
+                        if (Convert.ToString(current["FT" + "" + i + ""]) == "" || Convert.ToString(current["FT" + "" + i + ""]) == "0")
+                            continue;
+                        JObject jsonFPOOrderEntry = new JObject();
+                        jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈�
+                        jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲�
+                        List<DayPlanModel> _dayPlanModel = dayPlanModel.Where(x => x.FHMASTERDATE == date.AddDays(i)).ToList();
+                        if (_dayPlanModel.Count > 0)
+                        {
+                            jsonFPOOrderEntry.Add("FEntryID", _dayPlanModel.FirstOrDefault().FEntryID); ;//搴忓彿
+                        }
+                        Entry.Add(jsonFPOOrderEntry);
                     }
-                    Entry.Add(jsonFPOOrderEntry);
+                    jsonModel.Add("FEntity", Entry);
+                    jsonRoot.Add("Model", jsonModel);
+                    CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
+                    var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString());
+                    JObject saveObj = JObject.Parse(result);
+                    string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
+                    if (saveIsSuc != "TRUE")
+                    {
+                        LogHelper.Error("鐢熶骇璁″垝骞冲彴淇濆瓨澶辫触:" + jsonRoot.ToString());
+                        this.View.ShowMessage("鏁版嵁鍌ㄥ瓨澶辫触锛佽鑱旂郴绠$悊鍛橈紒");
+                    }
                 }
-                jsonModel.Add("FEntity", Entry);
-                jsonRoot.Add("Model", jsonModel);
-                CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
-                var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString());
-                JObject saveObj = JObject.Parse(result);
-                string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
-                if (saveIsSuc != "TRUE")
+                else
                 {
-                    LogHelper.Error("鐢熶骇璁″垝骞冲彴淇濆瓨澶辫触:" + jsonRoot.ToString());
-                    this.View.ShowMessage("鏁版嵁鍌ㄥ瓨澶辫触锛佽鑱旂郴绠$悊鍛橈紒");
+                    //鏍规嵁鐢熶骇璁㈠崟鍙峰拰鐗╂枡鏌ヨ鏄惁瀛樺湪鏄庣粏 +鐢熶骇璁㈠崟鏄庣粏琛屽彿
+                    sql = string.Format(@"
+/*dialect*/
+SELECT t4.FNAME as FMoFBillType,T1.FBILLNO,T2.*,t3.FNUMBER as FUnitNumber,tBom.FNUMBER as FBomNumber FROM T_PRD_MO T1
+ LEFT JOIN T_PRD_MOENTRY T2 ON T1.FID = T2.FID
+ LEFT JOIN T_ENG_BOM tBom on t2.FBOMID = tBom.FID
+ join T_BD_UNIT t3 on t2.FUNITID=t3.FUNITID 
+ join (  select A.FBILLTYPEID,B.FNAME  from T_BAS_BILLTYPE A 
+JOIN T_BAS_BILLTYPE_L B ON A.FBILLTYPEID =B.FBILLTYPEID
+where FBILLFORMID='PRD_MO'  AND FNAME<>'鐢熺敘瑷傚柈')t4 on t1.FBILLTYPE =t4.FBILLTYPEID
+ WHERE T1.FBILLNO = '{0}'  AND T2.FMATERIALID = '{1}' AND T2.FSEQ = '{2}'", Convert.ToString(current["FSCOrderNo"]), Convert.ToString(current["FMatrailId_Id"]), Convert.ToString(current["FSRCBILLENTRYSEQ"]));
+                    DataTable dt = new DataTable();
+                    dt = DBServiceHelper.ExecuteDataSet(Context, sql).Tables[0];
+                    if (dt.Rows.Count == 0)
+                        continue;
+                    string FID = "";//FID 婧愬崟涓诲唴鐮�
+                    string FENTRYID = "";//FENTRYID 婧愬崟瀛愬唴鐮�
+                    string FLOT = "";//FLOT  鎵规
+                    string FQTY = "";//FQTY 鐢熶骇璁㈠崟鏁伴噺
+                    string FBILLNO = "";//FBILLNO 鍘熷崟鍙� 
+                    string FHUnitID = "";//鍗曚綅
+                    string FPlanBeginDate = "";//寮�濮嬫棩鏈�
+                    string FPlanEndDate = "";//缁撴潫鏃ユ湡
+                    string FMoFBillType = "";//
+                    string FBomNumber = "";//Bom 鐗堟湰
+                    if (dt.Rows.Count > 0)
+                    {
+                        FID = dt.Rows[0]["FID"].ToString();
+                        FENTRYID = dt.Rows[0]["FENTRYID"].ToString();
+                        FLOT = dt.Rows[0]["FLOT"].ToString();
+                        FQTY = dt.Rows[0]["FQTY"].ToString();
+                        FBILLNO = dt.Rows[0]["FBILLNO"].ToString();
+                        FHUnitID = dt.Rows[0]["FUnitNumber"].ToString();
+                        FPlanBeginDate = dt.Rows[0]["FPlanStartDate"].ToString();
+                        FPlanEndDate = dt.Rows[0]["FPlanFinishDate"].ToString();
+                        FMoFBillType = dt.Rows[0]["FMoFBillType"].ToString();
+                        FBomNumber = dt.Rows[0]["FBomNumber"].ToString();
+                    }
+
+                    //閫夊崟鏁版嵁 鍋氭柊澧�
+                    JObject jsonRoot = new JObject();
+                    jsonRoot.Add("Creator", "");
+                    jsonRoot.Add("NeedUpDateFields", new JArray());
+                    jsonRoot.Add("NeedReturnFields", new JArray());
+                    jsonRoot.Add("IsDeleteEntry", "false");
+                    jsonRoot.Add("SubSystemId", "");
+                    jsonRoot.Add("IsVerifyBaseDataField", "");
+                    JObject jsonModel = new JObject();
+                    jsonModel.Add("FPreparatDate", date.ToString());//缂栧埗鏃ユ湡
+                    jsonModel.Add("FMoFBillType", FMoFBillType);//
+                    jsonModel.Add("FSRCBILLENTRYSEQ", Convert.ToString(current["FSRCBILLENTRYSEQ"]));//鐢熶骇璁㈠崟鏄庣粏琛屽彿
+                    jsonModel.Add("FSCOrderNo", Convert.ToString(current["FSCOrderNo"])); //鐢熶骇璁㈠崟鍙稦SCOrderNo
+                    jsonModel.Add("FHSeOrderBillNo", Convert.ToString(current["FSalOrderNo"]));//閿�鍞鍗曞彿
+                    jsonModel.Add("FHOrderLev", current["FOrderLevel"].ToString());//璁㈠崟绛夌骇
+                    jsonModel.Add("FHOrderQty", Convert.ToString(current["FSalOrderCount"]));//閿�鍞鍗曟暟閲�
+                    jsonModel.Add("FHOrderCommitDate", Convert.ToString(current["FDeliveryDate"]));//浜よ揣鏈烪OrderCommitDate
+                    jsonModel.Add("FHUnitID", new JObject() { ["Fnumber"] = FHUnitID });//鍗曚綅
+                    jsonModel.Add("FBOMID", new JObject() { ["Fnumber"] = FBomNumber });//BOM鐗堟湰
+                    jsonModel.Add("FHPlanBeginDate", FPlanBeginDate);//璁″垝寮�濮嬫棩鏈�
+                    jsonModel.Add("FHPlanEndDate", FPlanEndDate);//璁″垝瀹屽伐鏃ユ湡
+                    //jsonModel.Add("FBatch", current["FBatch"].ToString());//鎵规
+                    jsonModel.Add("FBatch", FLOT);//鎵规
+                    jsonModel.Add("FHOrderNeedQty", FQTY);// 璁㈠崟闇�姹傛暟閲�
+                    jsonModel.Add("FPrdBillNo", FBILLNO); ;//婧愬崟缂栧彿
+                    jsonModel.Add("FPRDMOMAINID", FID); ;//婧愬崟涓诲唴鐮�
+                    jsonModel.Add("FPRDMOENTYID", FENTRYID); ;//婧愬崟瀛愬唴鐮�
+                    jsonModel.Add("FMoFID", FID); ;//婧愬崟涓诲唴鐮�
+                    jsonModel.Add("FMoFentryId", FENTRYID); ;//婧愬崟瀛愬唴鐮�
+                    jsonModel.Add("FOrderQuantity", Convert.ToString(current["FOrderQuantity"])); ;//鐢熶骇璁㈠崟鏁伴噺
+                    jsonModel.Add("FDayPlanQuantity", Convert.ToString(current["FDayPlanQuantity"])); ;//鏃ヨ鍒掓暟閲�
+                    jsonModel.Add("FNoScheduled", Convert.ToString(current["FNoScheduled"])); ;//鏈帓鏁伴噺
+                    JObject jsonFHMaterID = new JObject();
+                    jsonFHMaterID.Add("FNumber", (current["FMatrailId"] as DynamicObject)["Number"].ToString());
+                    jsonModel.Add("FHMaterID", jsonFHMaterID);//FHMaterID 鐗╂枡
+                    if (Convert.ToString(current["FORGID_Id"]) != "0")
+                    {
+                        JObject jsonFHPRDORGID = new JObject();
+                        jsonFHPRDORGID.Add("FNumber", (current["FORGID"] as DynamicObject)["Number"].ToString());
+                        jsonModel.Add("FHPRDORGID", jsonFHPRDORGID);//FHMaterID 鐢熶骇缁勭粐
+
+                    }
+                    if (Convert.ToString(current["FResourcesId_Id"]) != "0")
+                    {
+                        JObject jsonFProductWorkShopId = new JObject();
+                        jsonFProductWorkShopId.Add("FNumber", (current["FResourcesId"] as DynamicObject)["Number"].ToString());
+                        jsonModel.Add("FHSourceID", jsonFProductWorkShopId);//FHSourceID  鐢熶骇杞﹂棿
+                    }
+                    if (Convert.ToString(current["FProductWorkShopId_Id"]) != "0")
+                    {
+                        JObject jsonFResourcesId = new JObject();
+                        jsonFResourcesId.Add("FNumber", (current["FProductWorkShopId"] as DynamicObject)["Number"].ToString());
+                        jsonModel.Add("FHWorkShopID", jsonFResourcesId);//FHWorkShopID  鐢熶骇璧勬簮
+                    }
+                    JArray Entry = new JArray();
+                    for (int i = 0; i <= 60; i++)
+                    {
+                        if (Convert.ToString(current["FT" + "" + i + ""]) == "" || Convert.ToString(current["FT" + "" + i + ""]) == "0")
+                            continue;
+                        JObject jsonFPOOrderEntry = new JObject();
+                        jsonFPOOrderEntry.Add("FHMasterDate", date.AddDays(i).ToShortDateString()); ;//涓绘棩鏈�
+                        jsonFPOOrderEntry.Add("FHQty ", Convert.ToString(current["FT" + "" + i + ""])); ;//鏃ヨ鍒掓暟閲�
+                        Entry.Add(jsonFPOOrderEntry);
+                    }
+                    jsonModel.Add("FEntity", Entry);
+                    jsonRoot.Add("Model", jsonModel);
+                    CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
+                    var result = cloudClient.Save("Paez_Sc_WorkBillAutoSortBill", jsonRoot.ToString());
+                    JObject saveObj = JObject.Parse(result);
+                    string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper();
+                    if (saveIsSuc != "TRUE")
+                    {
+                        LogHelper.Error("鐢熶骇璁″垝骞冲彴淇濆瓨澶辫触:" + jsonRoot.ToString());
+                        this.View.ShowMessage("鏁版嵁鍌ㄥ瓨澶辫触锛佽鑱旂郴绠$悊鍛橈紒");
+                    }
+                    if (saveIsSuc == "TRUE")
+                    {
+                        string FDayPlanBillNo = saveObj["Result"]["Number"].ToString();
+                        string FDayPlanID = saveObj["Result"]["Id"].ToString();
+                        this.Model.SetValue("FDayPlanBillNo", FDayPlanBillNo, Convert.ToInt32(current["SEQ"]) - 1);// 
+                        this.Model.SetValue("FDayPlanID", FDayPlanID, Convert.ToInt32(current["SEQ"]) - 1);// 
+                    }
                 }
             }
-
             this.View.ShowMessage("鎿嶄綔鎴愬姛");
             SearchList();
         }
@@ -515,11 +640,12 @@
             // using Kingdee.BOS.KDThread;
             MainWorker.QuequeTask(() =>
             {
+                var resuult = "";
                 try
                 {
                     // 闇�瑕佹崟鑾烽敊璇紝浠ョ‘淇濆鐞嗙粨鏉熸椂锛屽叧闂繘搴︽粴鍔ㄧ晫闈�
                     // 寮曞叆鍔熻兘瀹為檯澶勭悊鍑芥暟
-                    this.CompleteSetAnalysisBySQL();
+                    resuult = this.CompleteSetAnalysisByDataTable();
                 }
                 finally
                 {
@@ -531,11 +657,59 @@
                     {
                         processView.Close();
                         this.View.SendDynamicFormAction(processView);
+                        this.View.ShowMessage(resuult);
                     }
                 }
             },
             (t) => { });
         }
+        private void COMPLETEBOM()
+        {
+            // 鏄剧ず涓�涓繘搴︽樉绀虹晫闈細鏄剧ず涓�涓笉鍋滄粴鍔ㄧ殑妯℃嫙杩涘害
+            // bUseTruePro鍙傛暟锛氭槸鍚︽樉绀虹湡瀹炵殑杩涘害銆�
+            // bUseTruePro = false 锛�
+            // 鏄剧ず涓�涓笉鍋滄粴鍔ㄧ殑妯℃嫙杩涘害锛屼笌瀹為檯澶勭悊杩涘害娌℃湁鍏宠仈銆�
+            // 姝ゆ柟妗堜紭鐐癸細瀹為檯澶勭悊浠g爜鏃犻渶璁$畻杩涘害
+            // 姝ゆ柟妗堢己鐐癸細杩涘害涓嶅噯纭紝涓旇繘搴﹂〉闈笉浼氳嚜鍔ㄥ叧闂��
+            // bUseTruePro = true: 杩涘害鐣岄潰鏄剧ず鐪熷疄杩涘害
+            // 姝ゆ柟妗堜紭鐐癸細杩涘害鐪熷疄
+            // 姝ゆ柟妗堢己鐐癸細闇�瑕佸湪澶勭悊浠g爜涓紝涓嶆柇鐨勬洿鏂扮湡瀹炶繘搴︼紝鏇存柊璇彞
+            // this.View.Session["ProcessRateValue"] = 100;
+            // 鐗瑰埆璇存槑锛屽綋杩涘害鏇存柊鍒�100鏃讹紝杩涘害鐣岄潰浼氳嚜鍔ㄥ叧闂�
+            // 鏈渚嬮�夌敤姝ゆ柟妗�
+            var processForm = this.View.ShowProcessForm(
+                new Action<FormResult>(t => { }),
+                true,
+                "姝e湪鐢熸垚锛岃绋嶅��...");
+
+            // 寮�鍚竴涓紓姝ョ嚎绋嬶紝澶勭悊寮曞叆鍔熻兘
+            // using Kingdee.BOS.KDThread;
+            MainWorker.QuequeTask(() =>
+            {
+                var resuult = "";
+                try
+                {
+                    // 闇�瑕佹崟鑾烽敊璇紝浠ョ‘淇濆鐞嗙粨鏉熸椂锛屽叧闂繘搴︽粴鍔ㄧ晫闈�
+                    // 寮曞叆鍔熻兘瀹為檯澶勭悊鍑芥暟
+                    resuult = this.CompleteSetAnalysisByDataTableBom();
+                }
+                finally
+                {
+                    // 纭繚鏍囪杩涘害宸茬粡鍒拌揪100%
+                    this.View.Session["ProcessRateValue"] = 100;
+                    // 寮曞叆瀹屾瘯锛屽叧闂繘搴︽樉绀洪〉闈�
+                    var processView = this.View.GetView(processForm.PageId);
+                    if (processView != null)
+                    {
+                        processView.Close();
+                        this.View.SendDynamicFormAction(processView);
+                        this.View.ShowMessage(resuult);
+                    }
+                }
+            },
+            (t) => { });
+        }
+
         /// <summary>
         /// 榻愬鍒嗘瀽
         /// </summary>
@@ -1046,7 +1220,7 @@
             {
                 Stopwatch sw = new Stopwatch();
                 sw.Start();//寮�濮嬭鏃�
-                //娓呯┖榻愬涓存椂琛�
+                           //娓呯┖榻愬涓存椂琛�
                 DBServiceHelper.Execute(Context, "/*dialect*/  delete JIT_MOMaterReadysBill ");
                 //鏇存柊鐘舵��
                 DBServiceHelper.Execute(Context, "/*dialect*/  update Sc_WorkBillSortBillsub set FCOMPLETE='' ");
@@ -1254,6 +1428,537 @@
 
             }
         }
+        //鐢熶骇鐢ㄦ枡娓呭崟 榻愬鍒嗘瀽
+        public string CompleteSetAnalysisByDataTable()
+        {
+            LogHelper.Info("榻愬鍒嗘瀽sql妯″紡寮�濮嬪噯澶囨暟鎹細");
+            string sql = "";
+            try
+            {
+                Stopwatch sw = new Stopwatch();
+                sw.Start();//寮�濮嬭鏃�
+                int maxFid = DBServiceHelper.ExecuteScalar<int>(Context, "select max(FID)FID FROM  JIT_MOMaterReadysBill", 0);
+                //娓呯┖榻愬涓存椂琛�
+                DBServiceHelper.Execute(Context, "/*dialect*/  delete JIT_MOMaterReadysBill ");
+                //鏇存柊鐘舵��
+                DBServiceHelper.Execute(Context, "/*dialect*/  update Sc_WorkBillSortBillsub set FCOMPLETE='' ");
+                //鑾峰彇褰撳墠鍗虫椂搴撳瓨 鎸夌収鐗╂枡+搴撳瓨缁勭粐+璐т富+搴撳瓨鏁伴噺  
+                DataSet ds = DBServiceHelper.ExecuteDataSet(Context, @" 
+/*dialect*/ 
+  select  isnull(a.FBASEQTY,0)-ISNULL(b.FHUseQty,0) FBASEQTY,T1.FStockOrgId,T1.FMATERIALID,a.FOWNERID,c.FNUMBER from 
+(
+select a.FHPRDORGID FStockOrgId,T2.FMATERIALID 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,FMATERIALID from T_PRD_PPBOMENTRY
+group by FMATERIALID,FID) T2 on T1.FID = t2.FID
+group by a.FHPRDORGID,T2.FMATERIALID
+) T1 
+LEFT JOIN T_STK_Inventory a on T1.FStockOrgId = a.FStockOrgId and T1.FMATERIALID =a.FMATERIALID 
+LEFT JOIN JIT_MOMaterReadysBill B ON T1.FStockOrgId = b.FHSTOCKORGID and T1.FMATERIALID =b.FHMATERID and a.FOwnerId = b.FOwnerId 
+LEFT join T_ORG_Organizations c on a.FOWNERID = c.FORGID
+join t_BD_Stock d on a.FSTOCKID =d.FSTOCKID
+where d.FAvailableComplete<>0
+--where T1.FMATERIALID in (105773)
+");
+                ListInventory = ds.ToModelList<PRD_Inventory>();
+                //鎬诲簱瀛� 鐗╂枡+搴撳瓨缁勭粐+搴撳瓨鏁伴噺
+                ds = DBServiceHelper.ExecuteDataSet(Context, @" 
+/*dialect*/ 
+ select  sum(isnull(a.FBASEQTY,0)-ISNULL(b.FHUseQty,0))FBASEQTY,T1.FStockOrgId,T1.FMATERIALID from 
+(
+select a.FHPRDORGID FStockOrgId,T2.FMATERIALID 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,FMATERIALID from T_PRD_PPBOMENTRY
+group by FMATERIALID,FID) T2 on T1.FID = t2.FID
+group by a.FHPRDORGID,T2.FMATERIALID
+) T1 
+LEFT JOIN T_STK_Inventory a on T1.FStockOrgId = a.FStockOrgId and T1.FMATERIALID =a.FMATERIALID 
+LEFT JOIN JIT_MOMaterReadysBill B ON T1.FStockOrgId = b.FHSTOCKORGID and T1.FMATERIALID =b.FHMATERID
+join t_BD_Stock d on a.FSTOCKID =d.FSTOCKID
+where d.FAvailableComplete<>0
+--where T1.FMATERIALID in (105773)
+group by T1.FStockOrgId,T1.FMATERIALID
+");
+                ListInventoryByStockOrgId = ds.ToModelList<PRD_Inventory>();
+                //闇�瑕侀綈濂楀垎鏋愮殑鏁版嵁
+                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-ISNULL(FProductNum,0))*(FNeedQty/FQty) PlanCount,TBase.FErpClsID  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(FMUSTQTY) FNeedQty, FMATERIALID from T_PRD_PPBOMENTRY
+group by FMATERIALID, FID ) T2 on T1.FID = t2.FID
+ --LEFT JOIN T_STK_Inventory T3 on t2.FMATERIALID = t3.FMATERIALID
+JOIN T_BD_MATERIAL T4 on T2.FMATERIALID = T4.FMATERIALID
+JOIN t_BD_MaterialBase TBase on T2.FMATERIALID = TBase.FMATERIALID
+JOIN T_ORG_Organizations t5 on a.FHPRDORGID = t5.FORGID
+--鏉′欢涓轰粖澶╁線鍚庣殑鏃ヨ鍒� + 浠婂ぉ涔嬪墠鏈叧闂殑鏃ヨ鍒�
+where (FHEntryCloseDate is null and DATEDIFF(D,GETDATE(),FHMASTERDATE)<0)or DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0
+and b.FHQTY>0
+ORDER BY b.FHMASTERDATE,a.FHOrderLev 
+";
+                ds = DBServiceHelper.ExecuteDataSet(Context, sql);
+                List<PRD_PPBOM> BomList = ds.ToModelList<PRD_PPBOM>();
+                //鏃ヨ鍒�+鐢熶骇璁㈠崟瀛愯〃缂栫爜ID
+                var DatePlanList = BomList.GroupBy(p => new { p.FHMASTERDATE, p.FPRDMOENTYID }).Select(x => new PRD_PPBOM { FHMASTERDATE = x.Key.FHMASTERDATE, FPRDMOENTYID = x.Key.FPRDMOENTYID }).ToList();
+                //CompleteAnalysisTempModel 鐢ㄤ簬瀛樺偍涓存椂闇�瑕佹彃鍏ユ暟鎹�
+                List<CompleteAnalysisTempModel> completeAnalysisTempModel = new List<CompleteAnalysisTempModel>();
+                int i = 1;
+                //鍒涘缓瀛楀吀 鐢ㄤ簬鍌ㄥ瓨鐗╂枡 + 鍗犵敤鏁伴噺
+                Dictionary<string, decimal> occupyDic = new Dictionary<string, decimal>();
+                LogHelper.Info("榻愬鍒嗘瀽鍑嗗鏁版嵁瀹屾垚锛�" + sw.Elapsed);
+                foreach (var item in DatePlanList)
+                {
+                    //绛涢�夊嚭褰撴棩璁″垝鏁版嵁
+                    var _BomList = BomList.Where(x => x.FHMASTERDATE == item.FHMASTERDATE && x.FPRDMOENTYID == item.FPRDMOENTYID).ToList();
+                    foreach (var _item in _BomList)
+                    {
+                        //璇ユ棩璁″垝鐗╂枡闇�瑕佹暟 
+                        decimal need = _item.PlanCount;
+                        var sjkcList = ListInventoryByStockOrgId.Where(x => x.FMATERIALID == _item.FMATERIALID2 && x.FStockOrgId == _item.FStockOrgId).FirstOrDefault();
+                        //鐪熸闇�瑕佸彇璁$畻鐨勬暟閲忥紙鎷嗗垎璐т富锛�
+                        //璐т富鍖归厤
+                        List<PRD_Inventory> _ListInventory = ListInventory.Where(c => c.FMATERIALID == _item.FMATERIALID2 && c.FStockOrgId == _item.FStockOrgId && c.FBASEQTY > 0).ToList();
+                        if (_ListInventory.Count > 0)
+                        {
+                            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,
+                                    FHMainICMOEntryID = _item.FPRDMOENTYID,
+                                    FHICMOInterID = _item.FID.ToString(),
+                                    FHICMOEntryID = _item.FEntryID.ToString(),
+                                    FHMaterID = _item.FMATERIALID2,
+                                    FHStockOrgID = _item.FStockOrgId,
+                                    FHPRDORGID = _item.FStockOrgId,
+                                    FErpClsID = _item.FErpClsID,
+                                    FPRDBillNo = _item.FMOBillNO,
+                                    FOwnerTypeId = "BD_OwnerOrg",
+                                    FOwnerId = Inventory.FOwnerId,
+                                    FUnitDosage = _item.dwyl.ToString(),//鍗曚綅鐢ㄩ噺
+                                    FSumPlanCount = _item.PlanCount.ToString(),//璁″垝鎬绘暟閲�
+                                    FCompleteCount1 = fCompleteCount, //榻愬鏁伴噺
+                                    FLackCount = _fLackCount,//缂烘枡鏁伴噺
+                                    FHStockQty = sjkcList.FBASEQTY,//鍗虫椂搴撳瓨
+                                    FHLeftQty = Inventory.FBASEQTY,//鍙敤鏁伴噺
+                                    FOccupyCount = occupyMaterial,//鍗犵敤鏁伴噺
+                                    /* 2021 1.26 鏇存敼涓簄eed
+                                    FComPlete = sjkcList.FBASEQTY >= _item.PlanCount ? "榻愬" : "鏈綈濂�",
+                                    */
+                                    FComPlete = sjkcList.FBASEQTY >= need ? "榻愬" : "鏈綈濂�",
+                                    FPlanDate = item.FHMASTERDATE // 鏃ヨ鍒掓棩鏈�
+                                });
+                                //鎵e噺鎬诲簱瀛樻暟閲�
+                                sjkcList.FBASEQTY = sjkcList.FBASEQTY >= fCompleteCount ? sjkcList.FBASEQTY - fCompleteCount : 0;
+                                //鍓╀綑鏃ヨ鍒掗渶姹傛暟閲�
+                                need = need >= Inventory.FBASEQTY ? need - Inventory.FBASEQTY : 0;
+                                //鎵e噺娑堣�楀簱瀛�
+                                Inventory.FBASEQTY = Inventory.FBASEQTY - fCompleteCount;
+                            }
+                        }
+                        else
+                        {
+                            decimal occupyMaterial = 0;
+                            if (occupyDic.ContainsKey(_item.FMATERIALID2))
+                            {
+                                occupyMaterial = occupyDic[_item.FMATERIALID2];
+                            }
+                            completeAnalysisTempModel.Add(new Demo.Model.Model.CompleteAnalysisTempModel
+                            {
+                                FHMainICMOInterIDr = _item.FPRDMOMAINID,
+                                FHMainICMOEntryID = _item.FPRDMOENTYID,
+                                FHICMOInterID = _item.FID.ToString(),
+                                FHICMOEntryID = _item.FEntryID.ToString(),
+                                FHMaterID = _item.FMATERIALID2,
+                                FErpClsID = _item.FErpClsID,
+                                FHStockOrgID = _item.FStockOrgId,
+                                FHPRDORGID = _item.FStockOrgId,
+                                FPRDBillNo = _item.FMOBillNO,
+                                FOwnerTypeId = "BD_OwnerOrg",
+                                FUnitDosage = _item.dwyl.ToString(),//鍗曚綅鐢ㄩ噺
+                                FSumPlanCount = _item.PlanCount.ToString(),//璁″垝鎬绘暟閲�
+                                FCompleteCount1 = 0, //榻愬鏁伴噺
+                                FLackCount = _item.PlanCount,//缂烘枡鏁伴噺
+                                FHStockQty = 0,//鍗虫椂搴撳瓨
+                                FHLeftQty = 0,//鍙敤鏁伴噺
+                                FOccupyCount = occupyMaterial,//鍗犵敤鏁伴噺
+                                FComPlete = "鏈綈濂�",
+                                FPlanDate = item.FHMASTERDATE // 鏃ヨ鍒掓棩鏈�
+                            });
+                        }
+                    }
+                    //Thread.Sleep(100);
+                    // this.View.Session["ProcessRateValue"] = Convert.ToInt32((Convert.ToDecimal(40) / DatePlanList.Count) * i);
+                    i++;
+
+                }
+                LogHelper.Info($"榻愬鍒嗘瀽锛屾暟鎹噯澶囧畬鎴愶紝淇濆瓨鍒癕odel瀹炰綋锛屾�昏鏁帮細{completeAnalysisTempModel.Count}锛岃�楁椂锛�" + sw.Elapsed);
+                List<string> sqlList = new List<string>();
+                DataTable insertDT = new DataTable();
+                insertDT.TableName = "JIT_MOMaterReadysBill";
+                insertDT.Columns.Add("FID", typeof(long));
+                //insertDT.Columns.Add("FBILLNO", typeof(string));
+                insertDT.Columns.Add("FDOCUMENTSTATUS", typeof(string));
+                insertDT.Columns.Add("FHMAINICMOINTERIDR", typeof(long));
+                insertDT.Columns.Add("FHMAINICMOENTRYID", typeof(long));
+                insertDT.Columns.Add("FHICMOINTERID", typeof(long));
+                insertDT.Columns.Add("FHICMOENTRYID", typeof(long));
+                insertDT.Columns.Add("FHMATERID", typeof(long));
+                insertDT.Columns.Add("FHSTOCKORGID", typeof(long));
+                insertDT.Columns.Add("FHSTOCKQTY", typeof(decimal));
+                insertDT.Columns.Add("FHLEFTQTY", typeof(decimal));
+                insertDT.Columns.Add("FHPRDORGID", typeof(long));
+                insertDT.Columns.Add("FUNITDOSAGE", typeof(decimal));
+                insertDT.Columns.Add("FSUMPLANCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FPRDBILLNO", typeof(string));
+                insertDT.Columns.Add("FOWNERID", typeof(long));
+                insertDT.Columns.Add("FOWNERTYPEID", typeof(string));
+                //insertDT.Columns.Add("FIDENTIFICAT", typeof(long));
+                insertDT.Columns.Add("FPLANDATE", typeof(DateTime));
+                insertDT.Columns.Add("FCOMPLETE", typeof(string));
+                insertDT.Columns.Add("FLACKCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FOCCUPYCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FCOMPLETECOUNT1", typeof(decimal));
+                insertDT.Columns.Add("FERPCLSID", typeof(string));
+                int jdtmmm = 1;
+                foreach (var item in completeAnalysisTempModel)
+                {
+                    DataRow dr = insertDT.NewRow();
+                    dr["FID"] = maxFid + jdtmmm;
+                    //dr["FBILLNO"] = "";
+                    dr["FDOCUMENTSTATUS"] = "A";
+                    dr["FHMAINICMOINTERIDR"] = item.FHMainICMOInterIDr;
+                    dr["FHMAINICMOENTRYID"] = item.FHMainICMOEntryID;
+                    dr["FHICMOINTERID"] = item.FHICMOInterID;
+                    dr["FHICMOENTRYID"] = item.FHICMOEntryID;
+                    dr["FHMATERID"] = item.FHMaterID;
+                    dr["FHSTOCKORGID"] = item.FHStockOrgID;
+                    dr["FHSTOCKQTY"] = item.FHStockQty;
+                    dr["FHLEFTQTY"] = item.FHLeftQty;
+                    dr["FHPRDORGID"] = item.FHPRDORGID;
+                    dr["FUNITDOSAGE"] = item.FUnitDosage;
+                    dr["FSUMPLANCOUNT"] = item.FSumPlanCount;
+                    dr["FPRDBILLNO"] = item.FPRDBillNo;
+                    dr["FOWNERID"] = item.FOwnerId == null ? "0" : item.FOwnerId;
+                    dr["FOWNERTYPEID"] = "BD_OwnerOrg";
+                    //dr["FIDENTIFICAT"] = "";
+                    dr["FPLANDATE"] = item.FPlanDate.ToString("yyyy-MM-dd");
+                    dr["FCOMPLETE"] = item.FComPlete;
+                    dr["FLACKCOUNT"] = item.FLackCount;
+                    dr["FOCCUPYCOUNT"] = item.FOccupyCount;
+                    dr["FCOMPLETECOUNT1"] = item.FCompleteCount1;
+                    dr["FERPCLSID"] = item.FErpClsID;
+                    insertDT.Rows.Add(dr);
+                    //Thread.Sleep(6000);
+                    this.View.Session["ProcessRateValue"] = Convert.ToInt32((Convert.ToDecimal(80) / completeAnalysisTempModel.Count) * jdtmmm);
+                    jdtmmm++;
+                }
+                insertDT.EndLoadData(); // 鐏屽叆鏁版嵁缁撴潫
+                                        // 鎵归噺鎻掑叆鍒版暟鎹簱
+                DBServiceHelper.BulkInserts(this.Context, string.Empty, string.Empty, insertDT);
+                //DBServiceHelper.ExecuteBatch(Context, sqlList);
+                //鎵ц瀹屾垚鍚� 鏇存柊鏃ヨ鍒掑伐鍗曠姸鎬�
+                DBServiceHelper.Execute(Context, @"
+/*dialect*/update Sc_WorkBillSortBillSub set FComplete = '鏈綈濂�' where FEntryID IN (select distinct FHICMOEntryID from JIT_MOMaterReadysBill where isnull(FCOMPLETE,'鏈綈濂�') ='鏈綈濂�')
+");
+                DBServiceHelper.Execute(Context, @"
+/*dialect*/update Sc_WorkBillSortBillSub set FComplete = '榻愬' where FEntryID NOT IN (select distinct FHICMOEntryID from JIT_MOMaterReadysBill where isnull(FCOMPLETE,'鏈綈濂�') ='鏈綈濂�')
+");
+                sw.Stop();//缁撴潫璁℃椂
+                LogHelper.Info("榻愬鍒嗘瀽杩愯鎬绘椂闀匡細" + sw.Elapsed);
+                return "鎿嶄綔鎴愬姛";
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Error("榻愬鍒嗘瀽璺冲嚭锛�" + ex.Message.ToString());
+                return "鎿嶄綔澶辫触锛�" + ex.Message.ToString();
+
+            }
+        }
+        //鐗╂枡鐢ㄦ枡娓呭崟 榻愬鍒嗘瀽
+        public string CompleteSetAnalysisByDataTableBom()
+        {
+            LogHelper.Info("榻愬鍒嗘瀽(bom)sql妯″紡寮�濮嬪噯澶囨暟鎹細");
+            string sql = "";
+            try
+            {
+                Stopwatch sw = new Stopwatch();
+                sw.Start();//寮�濮嬭鏃�
+                int maxFid = DBServiceHelper.ExecuteScalar<int>(Context, "select max(FID)FID FROM  JIT_MOMaterReadysBomBill", 0);
+                //娓呯┖榻愬涓存椂琛�
+                DBServiceHelper.Execute(Context, "/*dialect*/  delete JIT_MOMaterReadysBomBill ");
+                //鏇存柊鐘舵��
+                DBServiceHelper.Execute(Context, "/*dialect*/  update Sc_WorkBillSortBillsub set FCOMPLETEBOM='' ");
+                //鑾峰彇褰撳墠鍗虫椂搴撳瓨 鎸夌収鐗╂枡+搴撳瓨缁勭粐+璐т富+搴撳瓨鏁伴噺  
+                DataSet ds = DBServiceHelper.ExecuteDataSet(Context, @" 
+/*dialect*/ 
+  select  isnull(a.FBASEQTY,0)-ISNULL(b.FHUseQty,0) FBASEQTY,T1.FStockOrgId,T1.FMATERIALID,a.FOWNERID,c.FNUMBER from 
+(
+select a.FHPRDORGID FStockOrgId,T2.FMATERIALID 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,FMATERIALID from T_PRD_PPBOMENTRY
+group by FMATERIALID,FID) T2 on T1.FID = t2.FID
+group by a.FHPRDORGID,T2.FMATERIALID
+) T1 
+LEFT JOIN T_STK_Inventory a on T1.FStockOrgId = a.FStockOrgId and T1.FMATERIALID =a.FMATERIALID 
+LEFT JOIN JIT_MOMaterReadysBomBill B ON T1.FStockOrgId = b.FHSTOCKORGID and T1.FMATERIALID =b.FHMATERID and a.FOwnerId = b.FOwnerId 
+LEFT join T_ORG_Organizations c on a.FOWNERID = c.FORGID
+join t_BD_Stock d on a.FSTOCKID =d.FSTOCKID
+where d.FAvailableComplete<>0
+--where T1.FMATERIALID in (105773)
+");
+                ListInventory = ds.ToModelList<PRD_Inventory>();
+                //鎬诲簱瀛� 鐗╂枡+搴撳瓨缁勭粐+搴撳瓨鏁伴噺
+                ds = DBServiceHelper.ExecuteDataSet(Context, @" 
+/*dialect*/ 
+ select  sum(isnull(a.FBASEQTY,0)-ISNULL(b.FHUseQty,0))FBASEQTY,T1.FStockOrgId,T1.FMATERIALID from 
+(
+select a.FHPRDORGID FStockOrgId,T2.FMATERIALID 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,FMATERIALID from T_PRD_PPBOMENTRY
+group by FMATERIALID,FID) T2 on T1.FID = t2.FID
+group by a.FHPRDORGID,T2.FMATERIALID
+) T1 
+LEFT JOIN T_STK_Inventory a on T1.FStockOrgId = a.FStockOrgId and T1.FMATERIALID =a.FMATERIALID 
+LEFT JOIN JIT_MOMaterReadysBomBill B ON T1.FStockOrgId = b.FHSTOCKORGID and T1.FMATERIALID =b.FHMATERID
+join t_BD_Stock d on a.FSTOCKID =d.FSTOCKID
+where d.FAvailableComplete<>0
+--where T1.FMATERIALID in (105773)
+group by T1.FStockOrgId,T1.FMATERIALID
+");
+                ListInventoryByStockOrgId = ds.ToModelList<PRD_Inventory>();
+                //闇�瑕侀綈濂楀垎鏋�(bom)鐨勬暟鎹�
+                sql = @"
+ /*dialect*/
+select a.FPRDMOMAINID,a.FPRDMOENTYID,a.FID,b.FEntryID,a.FHPRDORGID FStockOrgId,t5.FNUMBER as OrgFnumber,a.FHOrderLev,b.FHQTY,b.FHMASTERDATE, a.FSCORDERNO as FMOBillNO,
+T2.FMATERIALID FMATERIALID2, T4.FNumber,t2.FNUMERATOR/t2.FDENOMINATOR dwyl,(FHQTY-ISNULL(FProductNum,0))*(t2.FNUMERATOR/t2.FDENOMINATOR ) PlanCount,TBase.FErpClsID
+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 T_ENG_BOMCHILD T2 on a.FBOMID = t2.FID
+ --LEFT JOIN T_STK_Inventory T3 on t2.FMATERIALID = t3.FMATERIALID
+JOIN T_BD_MATERIAL T4 on T2.FMATERIALID = T4.FMATERIALID
+JOIN t_BD_MaterialBase TBase on T2.FMATERIALID = TBase.FMATERIALID
+JOIN T_ORG_Organizations t5 on a.FHPRDORGID = t5.FORGID
+--鏉′欢涓轰粖澶╁線鍚庣殑鏃ヨ鍒� + 浠婂ぉ涔嬪墠鏈叧闂殑鏃ヨ鍒�
+where (FHEntryCloseDate is null and DATEDIFF(D,GETDATE(),FHMASTERDATE)<0)or DATEDIFF(D,GETDATE(),FHMASTERDATE)>=0
+and b.FHQTY>0
+ORDER BY b.FHMASTERDATE,a.FHOrderLev 
+";
+                ds = DBServiceHelper.ExecuteDataSet(Context, sql);
+                List<PRD_PPBOM> BomList = ds.ToModelList<PRD_PPBOM>();
+                //鏃ヨ鍒�+鐢熶骇璁㈠崟瀛愯〃缂栫爜ID
+                var DatePlanList = BomList.GroupBy(p => new { p.FHMASTERDATE, p.FPRDMOENTYID }).Select(x => new PRD_PPBOM { FHMASTERDATE = x.Key.FHMASTERDATE, FPRDMOENTYID = x.Key.FPRDMOENTYID }).ToList();
+                //CompleteAnalysisTempModel 鐢ㄤ簬瀛樺偍涓存椂闇�瑕佹彃鍏ユ暟鎹�
+                List<CompleteAnalysisTempModel> completeAnalysisTempModel = new List<CompleteAnalysisTempModel>();
+                int i = 1;
+                //鍒涘缓瀛楀吀 鐢ㄤ簬鍌ㄥ瓨鐗╂枡 + 鍗犵敤鏁伴噺
+                Dictionary<string, decimal> occupyDic = new Dictionary<string, decimal>();
+                LogHelper.Info("榻愬鍒嗘瀽(bom)鍑嗗鏁版嵁瀹屾垚锛�" + sw.Elapsed);
+                foreach (var item in DatePlanList)
+                {
+                    //绛涢�夊嚭褰撴棩璁″垝鏁版嵁
+                    var _BomList = BomList.Where(x => x.FHMASTERDATE == item.FHMASTERDATE && x.FPRDMOENTYID == item.FPRDMOENTYID).ToList();
+                    foreach (var _item in _BomList)
+                    {
+                        //璇ユ棩璁″垝鐗╂枡闇�瑕佹暟 
+                        decimal need = _item.PlanCount;
+                        var sjkcList = ListInventoryByStockOrgId.Where(x => x.FMATERIALID == _item.FMATERIALID2 && x.FStockOrgId == _item.FStockOrgId).FirstOrDefault();
+                        //鐪熸闇�瑕佸彇璁$畻鐨勬暟閲忥紙鎷嗗垎璐т富锛�
+                        //璐т富鍖归厤
+                        List<PRD_Inventory> _ListInventory = ListInventory.Where(c => c.FMATERIALID == _item.FMATERIALID2 && c.FStockOrgId == _item.FStockOrgId && c.FBASEQTY > 0).ToList();
+                        if (_ListInventory.Count > 0)
+                        {
+                            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,
+                                    FHMainICMOEntryID = _item.FPRDMOENTYID,
+                                    FHICMOInterID = _item.FID.ToString(),
+                                    FHICMOEntryID = _item.FEntryID.ToString(),
+                                    FHMaterID = _item.FMATERIALID2,
+                                    FHStockOrgID = _item.FStockOrgId,
+                                    FHPRDORGID = _item.FStockOrgId,
+                                    FErpClsID = _item.FErpClsID,
+                                    FPRDBillNo = _item.FMOBillNO,
+                                    FOwnerTypeId = "BD_OwnerOrg",
+                                    FOwnerId = Inventory.FOwnerId,
+                                    FUnitDosage = _item.dwyl.ToString(),//鍗曚綅鐢ㄩ噺
+                                    FSumPlanCount = _item.PlanCount.ToString(),//璁″垝鎬绘暟閲�
+                                    FCompleteCount1 = fCompleteCount, //榻愬鏁伴噺
+                                    FLackCount = _fLackCount,//缂烘枡鏁伴噺
+                                    FHStockQty = sjkcList.FBASEQTY,//鍗虫椂搴撳瓨
+                                    FHLeftQty = Inventory.FBASEQTY,//鍙敤鏁伴噺
+                                    FOccupyCount = occupyMaterial,//鍗犵敤鏁伴噺
+                                    /* 2021 1.26 鏇存敼涓簄eed
+                                    FComPlete = sjkcList.FBASEQTY >= _item.PlanCount ? "榻愬" : "鏈綈濂�",
+                                    */
+                                    FComPlete = sjkcList.FBASEQTY >= need ? "榻愬" : "鏈綈濂�",
+                                    FPlanDate = item.FHMASTERDATE // 鏃ヨ鍒掓棩鏈�
+                                });
+                                //鎵e噺鎬诲簱瀛樻暟閲�
+                                sjkcList.FBASEQTY = sjkcList.FBASEQTY >= fCompleteCount ? sjkcList.FBASEQTY - fCompleteCount : 0;
+                                //鍓╀綑鏃ヨ鍒掗渶姹傛暟閲�
+                                need = need >= Inventory.FBASEQTY ? need - Inventory.FBASEQTY : 0;
+                                //鎵e噺娑堣�楀簱瀛�
+                                Inventory.FBASEQTY = Inventory.FBASEQTY - fCompleteCount;
+                            }
+                        }
+                        else
+                        {
+                            decimal occupyMaterial = 0;
+                            if (occupyDic.ContainsKey(_item.FMATERIALID2))
+                            {
+                                occupyMaterial = occupyDic[_item.FMATERIALID2];
+                            }
+                            completeAnalysisTempModel.Add(new Demo.Model.Model.CompleteAnalysisTempModel
+                            {
+                                FHMainICMOInterIDr = _item.FPRDMOMAINID,
+                                FHMainICMOEntryID = _item.FPRDMOENTYID,
+                                FHICMOInterID = _item.FID.ToString(),
+                                FHICMOEntryID = _item.FEntryID.ToString(),
+                                FHMaterID = _item.FMATERIALID2,
+                                FErpClsID = _item.FErpClsID,
+                                FHStockOrgID = _item.FStockOrgId,
+                                FHPRDORGID = _item.FStockOrgId,
+                                FPRDBillNo = _item.FMOBillNO,
+                                FOwnerTypeId = "BD_OwnerOrg",
+                                FUnitDosage = _item.dwyl.ToString(),//鍗曚綅鐢ㄩ噺
+                                FSumPlanCount = _item.PlanCount.ToString(),//璁″垝鎬绘暟閲�
+                                FCompleteCount1 = 0, //榻愬鏁伴噺
+                                FLackCount = _item.PlanCount,//缂烘枡鏁伴噺
+                                FHStockQty = 0,//鍗虫椂搴撳瓨
+                                FHLeftQty = 0,//鍙敤鏁伴噺
+                                FOccupyCount = occupyMaterial,//鍗犵敤鏁伴噺
+                                FComPlete = "鏈綈濂�",
+                                FPlanDate = item.FHMASTERDATE // 鏃ヨ鍒掓棩鏈�
+                            });
+                        }
+                    }
+                    //Thread.Sleep(100);
+                    // this.View.Session["ProcessRateValue"] = Convert.ToInt32((Convert.ToDecimal(40) / DatePlanList.Count) * i);
+                    i++;
+
+                }
+                LogHelper.Info($"榻愬鍒嗘瀽(bom)锛屾暟鎹噯澶囧畬鎴愶紝淇濆瓨鍒癕odel瀹炰綋锛屾�昏鏁帮細{completeAnalysisTempModel.Count}锛岃�楁椂锛�" + sw.Elapsed);
+                List<string> sqlList = new List<string>();
+                DataTable insertDT = new DataTable();
+                insertDT.TableName = "JIT_MOMaterReadysBomBill";
+                insertDT.Columns.Add("FID", typeof(long));
+                //insertDT.Columns.Add("FBILLNO", typeof(string));
+                insertDT.Columns.Add("FDOCUMENTSTATUS", typeof(string));
+                insertDT.Columns.Add("FHMAINICMOINTERIDR", typeof(long));
+                insertDT.Columns.Add("FHMAINICMOENTRYID", typeof(long));
+                insertDT.Columns.Add("FHICMOINTERID", typeof(long));
+                insertDT.Columns.Add("FHICMOENTRYID", typeof(long));
+                insertDT.Columns.Add("FHMATERID", typeof(long));
+                insertDT.Columns.Add("FHSTOCKORGID", typeof(long));
+                insertDT.Columns.Add("FHSTOCKQTY", typeof(decimal));
+                insertDT.Columns.Add("FHLEFTQTY", typeof(decimal));
+                insertDT.Columns.Add("FHPRDORGID", typeof(long));
+                insertDT.Columns.Add("FUNITDOSAGE", typeof(decimal));
+                insertDT.Columns.Add("FSUMPLANCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FPRDBILLNO", typeof(string));
+                insertDT.Columns.Add("FOWNERID", typeof(long));
+                insertDT.Columns.Add("FOWNERTYPEID", typeof(string));
+                //insertDT.Columns.Add("FIDENTIFICAT", typeof(long));
+                insertDT.Columns.Add("FPLANDATE", typeof(DateTime));
+                insertDT.Columns.Add("FCOMPLETE", typeof(string));
+                insertDT.Columns.Add("FLACKCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FOCCUPYCOUNT", typeof(decimal));
+                insertDT.Columns.Add("FCOMPLETECOUNT1", typeof(decimal));
+                insertDT.Columns.Add("FERPCLSID", typeof(string));
+                int jdtmmm = 1;
+                foreach (var item in completeAnalysisTempModel)
+                {
+                    DataRow dr = insertDT.NewRow();
+                    dr["FID"] = maxFid + jdtmmm;
+                    //dr["FBILLNO"] = "";
+                    dr["FDOCUMENTSTATUS"] = "A";
+                    dr["FHMAINICMOINTERIDR"] = item.FHMainICMOInterIDr;
+                    dr["FHMAINICMOENTRYID"] = item.FHMainICMOEntryID;
+                    dr["FHICMOINTERID"] = item.FHICMOInterID;
+                    dr["FHICMOENTRYID"] = item.FHICMOEntryID;
+                    dr["FHMATERID"] = item.FHMaterID;
+                    dr["FHSTOCKORGID"] = item.FHStockOrgID;
+                    dr["FHSTOCKQTY"] = item.FHStockQty;
+                    dr["FHLEFTQTY"] = item.FHLeftQty;
+                    dr["FHPRDORGID"] = item.FHPRDORGID;
+                    dr["FUNITDOSAGE"] = item.FUnitDosage;
+                    dr["FSUMPLANCOUNT"] = item.FSumPlanCount;
+                    dr["FPRDBILLNO"] = item.FPRDBillNo;
+                    dr["FOWNERID"] = item.FOwnerId == null ? "0" : item.FOwnerId;
+                    dr["FOWNERTYPEID"] = "BD_OwnerOrg";
+                    //dr["FIDENTIFICAT"] = "";
+                    dr["FPLANDATE"] = item.FPlanDate.ToString("yyyy-MM-dd");
+                    dr["FCOMPLETE"] = item.FComPlete;
+                    dr["FLACKCOUNT"] = item.FLackCount;
+                    dr["FOCCUPYCOUNT"] = item.FOccupyCount;
+                    dr["FCOMPLETECOUNT1"] = item.FCompleteCount1;
+                    dr["FERPCLSID"] = item.FErpClsID;
+                    insertDT.Rows.Add(dr);
+                    //Thread.Sleep(6000);
+                    this.View.Session["ProcessRateValue"] = Convert.ToInt32((Convert.ToDecimal(80) / completeAnalysisTempModel.Count) * jdtmmm);
+                    jdtmmm++;
+                }
+                insertDT.EndLoadData(); // 鐏屽叆鏁版嵁缁撴潫
+                                        // 鎵归噺鎻掑叆鍒版暟鎹簱
+                DBServiceHelper.BulkInserts(this.Context, string.Empty, string.Empty, insertDT);
+                //DBServiceHelper.ExecuteBatch(Context, sqlList);
+                //鎵ц瀹屾垚鍚� 鏇存柊鏃ヨ鍒掑伐鍗曠姸鎬�
+                DBServiceHelper.Execute(Context, @"
+/*dialect*/update Sc_WorkBillSortBillSub set FCompletebom = '鏈綈濂�' where FEntryID IN (select distinct FHICMOEntryID from JIT_MOMaterReadysBomBill where isnull(FCOMPLETE,'鏈綈濂�') ='鏈綈濂�')
+");
+                DBServiceHelper.Execute(Context, @"
+/*dialect*/update Sc_WorkBillSortBillSub set FCompletebom = '榻愬' where FEntryID NOT IN (select distinct FHICMOEntryID from JIT_MOMaterReadysBomBill where isnull(FCOMPLETE,'鏈綈濂�') ='鏈綈濂�')
+");
+                sw.Stop();//缁撴潫璁℃椂
+                LogHelper.Info("榻愬鍒嗘瀽(bom)杩愯鎬绘椂闀匡細" + sw.Elapsed);
+                return "鎿嶄綔鎴愬姛";
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Error("榻愬鍒嗘瀽(bom)璺冲嚭锛�" + ex.Message.ToString());
+                return "鎿嶄綔澶辫触锛�" + ex.Message.ToString();
+
+            }
+        }
+
 
         /// <summary>
         /// 铏氭嫙榻愬
@@ -1746,11 +2451,12 @@
             // using Kingdee.BOS.KDThread;
             MainWorker.QuequeTask(() =>
             {
+                var result = "鎿嶄綔鎴愬姛";
                 try
                 {
                     // 闇�瑕佹崟鑾烽敊璇紝浠ョ‘淇濆鐞嗙粨鏉熸椂锛屽叧闂繘搴︽粴鍔ㄧ晫闈�
                     // 寮曞叆鍔熻兘瀹為檯澶勭悊鍑芥暟
-                    this.DayPlanPPBomBillBatch();
+                    result = this.DayPlanPPBomBillBatch();
                 }
                 finally
                 {
@@ -1762,20 +2468,23 @@
                     {
                         processView.Close();
                         this.View.SendDynamicFormAction(processView);
-                        this.View.ShowMessage("鎿嶄綔鎴愬姛");
+                        this.View.ShowMessage(result);
                     }
                 }
             },
             (t) => { });
+
+            //this.View.ShowMessage("鎿嶄綔鎴愬姛");
         }
 
         /// <summary>
         /// 鏃ヨ鍒掔敤鏂欐竻鍗曠敓鎴�
         /// </summary>  
-        public void DayPlanPPBomBillBatch()
+        public string DayPlanPPBomBillBatch()
         {
             //LogService.WriteAsync(entrys);
             //鏌ユ壘鍒扮殑鍚屾壒椤规
+            int day = Convert.ToInt32(this.Model.GetValue("FLockDays"));
             Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
             //鍗曟嵁浣撲俊鎭浆鎹负鍒楄〃闆嗗悎
             DynamicObjectCollection entityDataObjoct = this.View.Model.GetEntityDataObject(entity);
@@ -1804,7 +2513,7 @@
             DBServiceHelper.ExecuteBatch(Context, zxSqlList);
             Stopwatch sw = new Stopwatch();
             sw.Start();//寮�濮嬭鏃�
-            
+
             LogHelper.Info("鐢熸垚鏃ヨ鍒掔敤鏂欐竻鍗曞噯澶囨暟鎹�");
             //閿佸畾鐨勬棩璁″垝涓嶇敓鎴�
             try
@@ -1832,10 +2541,18 @@
  LEFT join T_ORG_Organizations t10 on t2.FHPRDORGID = t10.FORGID
  LEFT join T_ENG_WORKCENTER t11 on t2.FHSOURCEID = t11.FID
  left join T_BD_DEPARTMENT td on t3.FWORKSHOPID=td.FDEPTID
- WHERE t1.FEntryID not in 
+ WHERE
+t1.FHMASTERDATE between  DATEADD(day,-1,getdate()) and DATEADD(day,{{1} - 1},getdate())
+and t1.FEntryID not in 
 (
-select distinct FDAYPLANFID from Sc_DayPlanPPBomBillMain where FID IN (
-select distinct FDAYPLANFID from T_PRD_PICKMTRLDATA)
+select distinct FDAYPLANFID from Sc_DayPlanPPBomBillMain where FID IN 
+(
+--棰嗘枡鍗�
+select distinct FDAYPLANFID from T_PRD_PICKMTRLDATA
+union all
+--鏃ヨ鍒掔敤鏂欐竻鍗曞彉鏇村崟
+select distinct FDAYPLANID from Sc_DayPlanPPBomBillSubBG
+)
 )
 AND {0}
 -- and T4.FMustQty>0
@@ -1843,7 +2560,7 @@
 -- select  FDayPlanFID FROM Sc_DayPlanPPBomBillMain WHERE FID IN ( select distinct FID from  Sc_DayPlanPPBomBillSub WHERE FTranslateQty >0 or FPickedQty >0)
 -- )
 ",
-sqlWhere);
+sqlWhere, day);
                 LogHelper.Info("鐢熸垚鏃ヨ鍒掔敤鏂欐竻鍗曞噯澶囨暟鎹畇ql:" + sql);
                 DataSet ds = DBServiceHelper.ExecuteDataSet(Context, sql);
                 DataTable dt = ds.Tables[0];
@@ -1963,6 +2680,7 @@
                                 ["IsDeleteEntry"] = "true",
                                 ["SubSystemId"] = "",
                                 ["IsVerifyBaseDataField"] = "false",
+                                ["IsAutoSubmitAndAudit"] = true,//鑷姩璋冪敤鎻愪氦鍜屽鏍稿姛鑳�
                                 ["Model"] = Fentity
                             };
                             CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/");
@@ -1985,8 +2703,10 @@
                             }
                             if (saveIsSuc != "TRUE")
                             {
-                                LogHelper.Error("鏃ヨ鍒掔敤鏂欐竻鍗曞垪琛ㄧ敓鎴愬け璐�:" + jsonRoot.ToString());
-                                this.View.ShowMessage(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString());
+                                //LogHelper.Error("鏃ヨ鍒掔敤鏂欐竻鍗曞垪琛ㄧ敓鎴愬け璐�:" + jsonRoot.ToString());
+                                LogHelper.Error(saveObj.ToString());
+                                return "鎿嶄綔澶辫触锛�" + saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString();
+                                //this.View.ShowMessage(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString());
                             }
                             Fentity = new JArray();
                         }
@@ -1999,11 +2719,13 @@
                 }
                 sw.Stop();//缁撴潫璁℃椂
                 LogHelper.Info("鐢熸垚鏃ヨ鍒掔敤鏂欐竻鍗曡繍琛屾�绘椂闀匡細" + sw.Elapsed);
+                return "鎿嶄綔鎴愬姛";
             }
             catch (Exception ex)
             {
                 LogHelper.Error("鏃ヨ鍒掔敤鏂欐竻鍗�+" + ex.Message.ToString());
-                this.View.ShowErrMessage(ex.Message.ToString());
+                return "鎿嶄綔澶辫触锛�" + ex.Message.ToString();
+                //this.View.ShowErrMessage(ex.Message.ToString());
             }
         }
 
@@ -2196,8 +2918,8 @@
                                 {
                                     var DayPlanPpbomls = DayPlanPpbom.Where(c => c.FENTRYID == id && c.FMATERIALID == _item.FMATERIALID).FirstOrDefault();
                                     decimal Qty = DayPlanPpbomls.NeedQty;//璁㈠崟鏁伴噺
-                                    //if (Qty == 0)
-                                    //    LogHelper.Info("璁㈠崟鏁伴噺涓�0");
+                                                                         //if (Qty == 0)
+                                                                         //    LogHelper.Info("璁㈠崟鏁伴噺涓�0");
                                     if (Qty > _NeedQty)
                                         Qty = _NeedQty; //璁㈠崟鏁伴噺>閲囪喘璁㈠崟鏁伴噺 鍙栭噰璐鍗�
 
@@ -2394,7 +3116,7 @@
                         FentityModel.Add("FHPOOrderEntryID", _item.PurchseFentryID); //閲囪喘璁㈠崟瀛愬唴鐮侊細FHPOOrderEntryID
                         FentityModel.Add("FHPOOrderBillNo", _item.PurchseFBillNo); //閲囪喘璁㈠崟鍙凤細FHPOOrderBillNo
                         FentityModel.Add("FERPCLSID", _item.FErpClsID); //鍙戞枡鏂瑰紡
-                        //FentityModel.Add("FSEQ", FSEQ); //鍙戞枡鏂瑰紡
+                                                                        //FentityModel.Add("FSEQ", FSEQ); //鍙戞枡鏂瑰紡
                         FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //鍙戞枡鏂瑰紡
 
                         Fentity.Add(FentityModel);
@@ -2440,7 +3162,7 @@
         /// <summary>
         /// 1.閿佸簱锛屽叿浣撳瓧娈垫牴鎹笟鍔″崟鎹喅瀹氾紝鈥業nv鈥欒〃绀哄嵆鏃跺簱瀛橈紝鈥楩InvDetailID鈥欎负鍗虫椂搴撳瓨ID
         /// </summary>
-        public void Reserve()   
+        public void Reserve()
         {
             try
             {
@@ -2568,7 +3290,7 @@
                         lockStockArgs.FID = Convert.ToInt32(current["FHMainSourceInterID"]); //鐢熶骇璁㈠崟琛孖D
                         lockStockArgs.BaseQty = decimal.Parse(dr["FBASEQTY"].ToString());//鍩烘湰鍗曚綅鏁伴噺
                         lockStockArgs.BaseUnitID = int.Parse(dr["FBASEUNITID"].ToString());//鍩烘湰鍗曚綅
-                        //lockStockArgs.Lot = Convert.ToString(current["FBatch"]); ;//鎵规 FBatch
+                                                                                           //lockStockArgs.Lot = Convert.ToString(current["FBatch"]); ;//鎵规 FBatch
                         lockStockArgs.MaterialID = long.Parse(dr["FMATERIALID2"].ToString());
                         lockStockArgs.OwnerID = long.Parse(dr["FOwnerID"].ToString());
                         lockStockArgs.OwnerTypeID = dr["FOwnerTypeID"].ToString();
@@ -2645,7 +3367,8 @@
             }
         }
 
-        public void SelectMenu() {
+        public void SelectMenu()
+        {
             //鑾峰彇鍗曟嵁浣撲俊鎭�
             Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");
             //鍗曟嵁浣撲俊鎭浆鎹负鍒楄〃闆嗗悎
@@ -2670,15 +3393,18 @@
                     {
                         foreach (var listSelectedRow in listSelectedRowCollection)
                         {
+                            string sql = $"select DATEDIFF(d,FPlanStartDate,getdate())days from T_PRD_MOENTRY where FENTRYID = {listSelectedRow.DataRow["t1_FENTRYID"].ToString()}";
+                            int day = DBServiceHelper.ExecuteScalar<int>(Context, sql, 0);
                             this.Model.CreateNewEntryRow("FEntity");
-                            this.View.Model.SetValue("FORGID",100, Fseq);
+                            this.View.Model.SetItemValueByNumber("FORGID", "100", Fseq);
                             this.View.Model.SetValue("FSCOrderNo", listSelectedRow.DataRow["FBillNo"].ToString(), Fseq);
                             this.View.Model.SetValue("FSRCBILLENTRYSEQ", listSelectedRow.DataRow["t1_FSeq"].ToString(), Fseq);
-                            this.View.Model.SetValue("FMatrailId", listSelectedRow.DataRow["FMaterialId_Id"].ToString(), Fseq);
+                            this.View.Model.SetValue("FMatrailId", listSelectedRow.DataRow["FMaterialId_Id"].ToString(), Fseq);//2129900005
                             this.View.Model.SetValue("FFUnit", listSelectedRow.DataRow["FUnitId_Id"].ToString(), Fseq);
                             this.View.Model.SetValue("FOrderQuantity", listSelectedRow.DataRow["FQty"].ToString(), Fseq);
                             this.View.Model.SetValue("FProductWorkShopId", listSelectedRow.DataRow["FWorkShopID_Id"].ToString(), Fseq);
                             this.View.Model.SetValue("FOrderLevel", "3", Fseq);
+                            this.View.Model.SetValue("FT" + day.ToString(), listSelectedRow.DataRow["FQty"].ToString(), Fseq);
                             Fseq++;
                         }
                     }

--
Gitblit v1.9.1