開發五-單據類型爲<訂金單>的實現按需關單與反關單

背景介紹:sql

           店面在銷售過程當中,可能會原單不選擇訂金單類型進行抵減當次顧客的應收金額,而是直接新增單據直接填寫扣減後的金額,這樣系統會存在大量的狀態爲正常的訂金單,形成後續財務沒法肯定是否訂金單是否已經使用,是否應該進行後續扣減。因此開發此功能實現批量更新當前選擇店面的時間段內的定金狀態,而且告訴操做者更新了多少條數據,將操做日誌寫入系統標準表,能夠進行查看。而且將當前何時關閉操做放到後臺表中,下次打開訂金單關單表單,經過查看上次關單日期能夠知道什麼時間關過單!ide

功能: 關單與反關單ui

知識點:後臺bos中開發一個bos表單,能夠實現關單與反關單的雙向的功能,經過開發插件實現邏輯隔離,獨立運行!this

代碼以下:編碼


using 省略。。。。。。spa


namespace YaTai.K3.SCM.Sal.BusinessPlugIn.LS插件

{日誌

    [Kingdee.BOS.Util.HotUpdate]orm

    [Description("訂金單關閉")]對象


    /*Yatai_pbka_CLOSEPROFILE新建表做爲訂金單關閉的中間表*/

    public class DepositForm : AbstractDynamicFormPlugIn

    { 

        //判斷是否關單與反關單

        bool isclose = true;

        ProgressBar processbar;

        /// <summary>

        /// 初始化,對其餘界面傳來的參數進行處理,對控件某些屬性進行處理

        /// 這裏不宜對數據DataModel進行處理

        /// </summary>

        /// <param name="e"></param>

        public override void OnInitialize(InitializeEventArgs e)

        {

            //給關單日期賦初始值;

            DynamicObjectType objType = this.Model.BillBusinessInfo.GetDynamicObjectType();

            DynamicObject dataObject = new DynamicObject(objType);

            dataObject["FCloseDate"] =TimeServiceHelper.GetSystemDateTime(this.View.Context).Date;

            //標題名稱獲取;

            string title=  this.View.OpenParameter.Caption;

            if (title.Contains("反關單"))

            {

                this.View.GetMainBarItem("tbauto").Text= "反關單";      

                isclose = false;

            }

            else

            {

                this.View.GetMainBarItem("tbauto").Text = "關單";

            }

            this.processbar = this.View.GetControl<ProgressBar>("F_PDLJ_ProgressBar");              

          }

        public override void AfterBindData(EventArgs e)

        {

            base.AfterBindData(e);

            EnableFileds();

            //true表示可見,false表示不可見

            this.View.GetControl("F_PDLJ_choice").Visible =isclose;

            // this.View.GetBarItem("ToolBar", "tbRverserColse").Visible = false;

            this.processbar.Visible = false;

        }

        /// <summary>

        /// 字段鎖定

        /// </summary>

        private void EnableFileds()

        {

         List<Field> fields=   this.View.BillBusinessInfo.GetEntryEntity("F_PDLJ_Entity").Fields;

            foreach (Field field in fields)

            {

                if(field.Key.Contains("FCheck") ==false)

                {

                    this.View.GetControl(field.Key).Enabled = false;

                }

            }

        }

        public override void AfterCreateNewData(EventArgs e)

        {

            base.AfterCreateNewData(e);

         

            //查詢出最終的數據集合

            DynamicObjectCollection queryDatas = GetQueryDatas();

            int seq = 0;

            if (queryDatas.Count > 0 && queryDatas != null)

            {


                Entity entity = this.View.BillBusinessInfo.GetEntryEntity("F_PDLJ_Entity");

                DynamicObjectCollection entitydataobject = this.Model.GetEntityDataObject(entity);

                entitydataobject.Clear();

                foreach (DynamicObject item in queryDatas)

                {

                    DynamicObject objectEntry = new DynamicObject(entitydataobject.DynamicCollectionItemPropertyType);

                    long orgId = Convert.ToInt32(item["FORGID"]);

                    DateTime? closedatetime = BillExtention.GetPbkaBillLastCloseDate(this.Context, orgId.ToString());

                    objectEntry["Seq"] = ++seq;//序號

                    objectEntry["FCheck"] = false;

                    objectEntry["FStockOrgNo"] = item["FNUMBER"].ToString();

                    objectEntry["FStockOrgName"] = (item["FNAME"] == null || string.IsNullOrEmpty(item["FNAME"].ToString())) ? "" : item["FNAME"].ToString();

                    objectEntry["FLastCloseDate"] = closedatetime == Convert.ToDateTime("2015-01-01") ? null:closedatetime;

                    objectEntry["FResult"] = "";

                    objectEntry["FStockOrgID"] = orgId.ToString();

                    entitydataobject.Add(objectEntry);

                }

                BillExtention.UpdateEntryView(this.View, "F_PDLJ_Entity");


            }

        }

        /// <summary>

        /// queryservice取數方案,經過業務對象來獲取數據,推薦使用

        /// </summary>

        /// <returns></returns>

        private DynamicObjectCollection GetQueryDatas()

        {

            string filterString = "";

            List<long> persion = new List<long>();

            if ((persion = GetOrgList("PDLJ_DepositForm")).Count > 0)

            {

                filterString = "  FDOCUMENTSTATUS = 'C' AND FFORBIDSTATUS = 'A' AND (FORGFUNCTIONS like'%103%') and " + GetOrgList(persion, "forgid");

            }

            QueryBuilderParemeter paramCatalog = new QueryBuilderParemeter()

            {

                FormId = "ORG_Organizations",//取數的業務對象1


                FilterClauseWihtKey = filterString,//過濾條件,經過業務對象的字段Key拼裝過濾條件

                IsolationOrgList = null,

                RequiresDataPermission = true,

                SelectItems = GetSelector(),//要篩選的字段【業務對象的字段Key】,能夠多個,若是要取主鍵,使用主鍵名

            };


            DynamicObjectCollection dyDatas = QueryServiceHelper.GetDynamicObjectCollection(base.Context, paramCatalog, null);

            return dyDatas;

        }

        /// <summary>

        /// 過濾條件,經過業務對象的字段Key拼裝過濾條件

        /// </summary>

        /// <returns></returns>

        private List<SelectorItemInfo> GetSelector()

        {

            List<SelectorItemInfo> selector = new List<SelectorItemInfo>();

            selector.Add(new SelectorItemInfo("FORGID"));

            selector.Add(new SelectorItemInfo("FName"));

            selector.Add(new SelectorItemInfo("FNumber"));

            return selector;

        }

        /// <summary>

        /// 得到組織列表

        /// </summary>

        /// <param name="orgList"></param>

        /// <param name="key"></param>

        /// <returns></returns>

        private string GetOrgList(List<long> orgList, string key)

        {

            if (orgList.Count <= 0 || orgList == null)

            {

                return string.Format("{0}=-1", key);


            }

            return string.Format("{0} in({1})", key, string.Join(",", orgList));

        }

        /// <summary>

        /// 權限項;

        /// </summary>

        /// <param name="formid"></param>

        /// <returns></returns>

        private List<long> GetOrgList(string formid)

        {

            BusinessObject obj2 = new BusinessObject();

            // 報表標識

            obj2.Id = formid;

            // 報表權限控制選項:是否授權限控制

            obj2.PermissionControl = this.View.BusinessInfo.GetForm().SupportPermissionControl;

            // 報表所在子系統

            obj2.SubSystemId = this.View.BusinessInfo.GetForm().SubsysId;

            List<long> orgs = new List<long>();

            if (obj2.PermissionControl != 0)

            {

                orgs = PermissionServiceHelper.GetPermissionOrg(Context, obj2, "6e44119a58cb4a8e86f6c385e14a17ad");//PermissionConst.View=" 6e44119a58cb4a8e86f6c385e14a17ad"


            }


            return orgs;

        }

        public override void BarItemClick(BarItemClickEventArgs e)

        {

            base.BarItemClick(e);

            string barItemKey;

            if((barItemKey=e.BarItemKey)!=null)

            {

                if (e.BarItemKey == "tbauto")

                {

                    string msg = this.isclose ? ResManager.LoadKDString("正在處理庫存組織關單", "") : ResManager.LoadKDString("正在處理庫存組織反關單", "");

                    this.View.ShowProcessForm(delegate (FormResult r1)

                    {

                    }, msg);

                    this.processbar.Start(1);

                    this.processbar.Visible = false;

                    this.processbar.SetValue(0);

                    string resultEnd;

                    this.DoAction(out resultEnd);

                    string resultEnd1;

                    MainWorker.QuequeTask(this.Context, delegate

                     {

                         resultEnd1=resultEnd;



                     }, delegate (AsynResult result)

                      {

                          if(!result.Success)

                          {

                              string excepMsg;

                              if (result.Exception.InnerException != null)

                              {

                                  if (result.Exception.InnerException.InnerException != null)

                                  {

                                      excepMsg = result.Exception.InnerException.InnerException.Message;

                                  }

                                  else

                                  {

                                      excepMsg = result.Exception.InnerException.Message;

                                  }

                              }

                              else

                              {

                                  excepMsg = result.Exception.Message;

                              }

                              this.View.ShowErrMessage(excepMsg, string.Format(ResManager.LoadKDString("執行{0}失敗", "004023030002137", SubSystemType.SCM, new object[0]), this.isclose ? ResManager.LoadKDString("關單", "004023030000238", SubSystemType.SCM, new object[0]) : ResManager.LoadKDString("反關單", "004023030000241", SubSystemType.SCM, new object[0])), MessageBoxType.Notice);

                          }

                          this.processbar.SetValue(100);

                          this.View.Session["Proce***ateValue"] = 100;

                      }



                     );

                 

                    return;

                }              

            }



        }

        /// <summary>

        /// 獲取單據體選擇的行的組織id與名稱

        /// </summary>

        /// <param name="fentryIden"></param>

        /// <param name="orgIds"></param>

        /// <param name="orgNames"></param>

        private  void UpdateEntryData(string fentryIden,Dictionary<long,int> orgIds,List<string> orgNames)

        {

            //單據體實體集合數據;

            DynamicObjectCollection entryDataObject = this.View.Model.DataObject[fentryIden] as DynamicObjectCollection;

            for (int i = 0; i < this.Model.GetEntryRowCount(fentryIden); i++)

            {

                if (Convert.ToBoolean(entryDataObject[i]["FCheck"]))

                {

                    orgIds.Add(Convert.ToInt64(entryDataObject[i]["FStockOrgID"]),i);

                    orgNames.Add(Convert.ToString(entryDataObject[i]["FStockOrgName"]));

                    this.View.Model.SetValue("FResult", "", i);

                }

            }

        }

        /// <summary>

        /// 更新訂金單的狀態

        /// </summary>

        /// <param name="ctx"></param>

        /// <param name="orgIds"></param>

        /// <param name="closeDate"></param>

        /// <param name="closeProFileDate"></param>

        /// <returns></returns>

        public static int UpdatePbkaDjStatus(Context ctx, long orgIds, DateTime closeDate, DateTime closeProFileDate)

        {

            int updaeStatusResult = 0;

            if (!string.IsNullOrWhiteSpace(orgIds.ToString()))

            {

                StringBuilder sql = new StringBuilder("/*dialect*/");

                sql.AppendFormat(@" UPDATE PBKA_t_BillHead SET FCLOSESTATUSDJT = 'B',F_YATAI_CLOSEPROFILE='{2}' from PBKA_t_BillHead

                    where FBILLTYPEID in('58427f3fa95a23', '58427f67a95aed', '57faf492b10d31') and FBILLNO LIKE 'D%' and FDOCUMENTSTATUS = 'C' AND FCLOSESTATUSDJT = 'A'

                   AND F_PBKA_SALORGID = '{0}' AND(F_PBKA_DATE >='{1}' AND F_PBKA_DATE<='{2}') ", orgIds.ToString(), closeProFileDate.ToShortDateString(), closeDate.ToShortDateString());

                updaeStatusResult = DBUtils.Execute(ctx, sql.ToString());

            }

            return updaeStatusResult;

        }

        /// <summary>

        /// 插入關單歷史表調用更新訂金單狀態,作更新成功狀態的提示

        /// </summary>

        private void DoAction(out string msg)

        {   //存放組織ID;

            // List<long> orgIds = new List<long>();

            Dictionary<long, int> orgIds = new Dictionary<long, int>();

            //存放組織編碼;

            List<string> orgNames = new List<string>();

            DateTime closeDt = (DateTime)this.Model.GetValue("FCloseDate");

            UpdateEntryData("F_PDLJ_Entity", orgIds, orgNames);

            msg = "";

            #region 選擇的是關單表單

            if (isclose == true)

            {

                bool resultyc;

                this.StartDoKdClose(orgIds, orgNames, closeDt, out resultyc);

                //若是沒有異常執行如下邏輯處理;

                if (resultyc == false)

                {

                    int result = 0;

                    if (orgIds.Count > 0)

                    {

                        StringBuilder resultstr = new StringBuilder();

                        foreach (KeyValuePair<long, int> item in orgIds)

                        {

                            string orgNumber;

                            string orgName;

                            CommHelper.GetOrgInfo(this.Context, item.Key, out orgNumber, out orgName);

                            DateTime lastCloseDate = BillExtention.GetPbkaBillLastCloseDate(this.Context, item.Key.ToString());

                            int uCount = UpdatePbkaDjStatus(this.Context, item.Key, closeDt, lastCloseDate);

                            if (uCount >= 0)

                            {

                                resultstr.Append("\t" + string.Format(@"【{0}】共更新【{1}】條訂單記錄", orgName, uCount));

                                result = CommHelper.InsertYataiPbkaCLOSEPROFILE(this.Context, item.Key, "PBKA", closeDt);

                                if (result == 1)

                                {

                                    resultstr.Append("\t 關單成功!");

                                    this.Model.SetValue("FLastCloseDate", closeDt.ToShortDateString(), item.Value);

                                }

                                else

                                {

                                    resultstr.Append("\t 關單失敗!");

                                }

                            }

                            else

                            {

                                resultstr.Append("\t 關單失敗!");

                                resultstr.AppendFormat("\t 更新訂金單成功【0】條!");

                            }

                            this.Model.SetValue("FResult", resultstr.ToString(), item.Value);

                            CommHelper.WriteLog(this.Context, resultstr.ToString(), "訂金單關單", this.View.BusinessInfo.GetForm().Id, this.View.OpenParameter.SubSystemId.ToString());

                            resultstr.Clear();

                        }

                    }

                }

                msg = "訂金單關單成功!";


            }

            #endregion

            else

            #region  選擇的是反關單表單

            if (isclose == false)

            {

                int result = 0;

                if (orgIds.Count > 0)

                {

                    StringBuilder resultstr = new StringBuilder();

                    foreach (KeyValuePair<long, int> item in orgIds)

                    {

                        string orgNumber;

                        string orgName;

                        CommHelper.GetOrgInfo(this.Context, item.Key, out orgNumber, out orgName);

                        //獲取關單日期;

                        DateTime lastCloseDate = BillExtention.GetPbkaBillLastCloseDate(this.Context, item.Key.ToString());

                        if (lastCloseDate == Convert.ToDateTime("2015-01-01"))

                        {

                            resultstr.AppendFormat(string.Format(@"{0}組織沒有關過單,反關單失敗!更新訂單狀態失敗!", orgName), "");

                        }

                        else

                        {

                            CommHelper.DeleteYataiPbkaCLOSEPROFILE(this.Context, item.Key, "PBKA", lastCloseDate);

                            result = CommHelper.UpdatePbkaDjStatus(this.Context, item.Key,lastCloseDate);

                            if(result>=0)

                            {

                                resultstr.Append("\t反關單成功!更新訂金狀態成功!");

                                string datetime1 ="";

                                if ((datetime1 = BillExtention.GetPbkaBillLastCloseDate(this.Context, item.Key.ToString()).ToShortDateString()) == "2015-01-01")

                                { this.Model.SetValue("FLastCloseDate", "", item.Value); }

                                else

                                {

                                    this.Model.SetValue("FLastCloseDate", BillExtention.GetPbkaBillLastCloseDate(this.Context, item.Key.ToString()).ToShortDateString(), item.Value);

                                }

                                }

                        }

                        this.Model.SetValue("FResult", resultstr.ToString(), item.Value);

                        CommHelper.WriteLog(this.Context, resultstr.ToString(), "訂金單反關單", this.View.BusinessInfo.GetForm().Id, this.View.OpenParameter.SubSystemId.ToString());

                        resultstr.Clear();

                    }

                }

                else

                {

                 this.View.ShowErrMessage(ResManager.LoadKDString("至少選擇一個庫存組織進行反關單!", ""));                

                }


                msg = "訂金單反關單成功!";

            }

            #endregion

            orgIds.Clear();

            orgNames.Clear();           

        }  

        /// <summary>

        /// 關單判斷是否存在異常

        /// </summary>

        /// <param name="orgIds"></param>

        /// <param name="orgNames"></param>

        /// <param name="closeDate"></param>

        /// <param name="result">爲false則不異常,true則異常</param>

        private void StartDoKdClose(Dictionary<long,int> orgIds, List<string> orgNames, DateTime closeDate,out bool resultyc)

        {

            resultyc = false;

            if(orgIds.Count<1)

            {

                resultyc = true;

                this.View.ShowMessage(ResManager.LoadKDString("請選擇未成功處理過的庫存組織!", ""));

                return;

            }

            if (isclose == true)

            {

                if (closeDate == DateTime.MinValue)

                {

                    resultyc = true;

                    this.View.ShowMessage(ResManager.LoadKDString("請先錄入關單日期", "'"));

                    return;

                }

                int count = 0;

                foreach (KeyValuePair<long, int> item in orgIds)

                {

                    //訂金單的關單日期;


                    DateTime closeTime = BillExtention.GetPbkaBillLastCloseDate(this.Context, item.Key.ToString());

                    if (closeTime >= Convert.ToDateTime(this.View.Model.GetValue("FCloseDate")))

                    {

                        resultyc = true;

                        this.View.ShowMessage(ResManager.LoadKDString(string.Format("庫存組織【{0}】的關單日期須要大於最後的關單日期{1},請從新選擇關單日期!", orgNames[count], closeTime), ""));

                        return;

                    }

                    count++;

                }

            }

                    

        }

    }

}

QQ截圖20190709211653.jpgQQ截圖20190709211455.jpg

相關文章
相關標籤/搜索