背景介绍:
店面在销售过程中,可能会原单不选择订金单类型进行抵减当次顾客的应收金额,而是直接新增单据直接填写扣减后的金额,这样系统会存在大量的状态为正常的订金单,造成后续财务无法确定是否订金单是否已经使用,是否应该进行后续扣减。所以开发此功能实现批量更新当前选择店面的时间段内的定金状态,并且告诉操作者更新了多少条数据,将操作日志写入系统标准表,可以进行查看。并且将当前什么时候关闭操作放到后台表中,下次打开订金单关单表单,通过查看上次关单日期可以知道什么时间关过单!
功能: 关单与反关单
知识点:后台bos中开发一个bos表单,可以实现关单与反关单的双向的功能,通过开发插件实现逻辑隔离,独立运行!
代码如下:
using 省略。。。。。。
namespace YaTai.K3.SCM.Sal.BusinessPlugIn.LS
{
[Kingdee.BOS.Util.HotUpdate]
[Description("订金单关闭")]
/*Yatai_pbka_CLOSEPROFILE新建表作为订金单关闭的中间表*/
public class DepositForm : AbstractDynamicFormPlugIn
{
//判断是否关单与反关单
bool isclose = true;
ProgressBar processbar;
///
/// 初始化,对其他界面传来的参数进行处理,对控件某些属性进行处理
/// 这里不宜对数据DataModel进行处理
///
///
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
}
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;
}
///
/// 字段锁定
///
private void EnableFileds()
{
List
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");
}
}
///
/// queryservice取数方案,通过业务对象来获取数据,推荐使用
///
///
private DynamicObjectCollection GetQueryDatas()
{
string filterString = "";
List
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;
}
///
/// 过滤条件,通过业务对象的字段Key拼装过滤条件
///
///
private List
{
List
selector.Add(new SelectorItemInfo("FORGID"));
selector.Add(new SelectorItemInfo("FName"));
selector.Add(new SelectorItemInfo("FNumber"));
return selector;
}
///
/// 获得组织列表
///
///
///
///
private string GetOrgList(List
{
if (orgList.Count <= 0 || orgList == null)
{
return string.Format("{0}=-1", key);
}
return string.Format("{0} in({1})", key, string.Join(",", orgList));
}
///
/// 权限项;
///
///
///
private List
{
BusinessObject obj2 = new BusinessObject();
// 报表标识
obj2.Id = formid;
// 报表权限控制选项:是否受权限控制
obj2.PermissionControl = this.View.BusinessInfo.GetForm().SupportPermissionControl;
// 报表所在子系统
obj2.SubSystemId = this.View.BusinessInfo.GetForm().SubsysId;
List
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;
}
}
}
///
/// 获取单据体选择的行的组织id与名称
///
///
///
///
private void UpdateEntryData(string fentryIden,Dictionary
{
//单据体实体集合数据;
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);
}
}
}
///
/// 更新订金单的状态
///
///
///
///
///
///
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;
}
///
/// 插入关单历史表调用更新订金单状态,做更新成功状态的提示
///
private void DoAction(out string msg)
{ //存放组织ID;
// List
Dictionary
//存放组织编码;
List
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
{
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
{
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();
}
///
/// 关单判断是否存在异常
///
///
///
///
/// 为false则不异常,true则异常
private void StartDoKdClose(Dictionary
{
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
{
//订金单的关单日期;
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++;
}
}
}
}
}