很多客户提单关于应收票据审核生成收款单 怎样把票据上字段携带到收款单上 以下是我关于票据携带到收款单总结,有什么问题欢迎一起交流:
应收票据生成收款单主要是两个不同路线方法 二开要从这两个方面处理
1. 在应收票据表单里审核自动生成收款单,打开收款单界面走的是表单插件这里要重写应收票据表单插件和收款单表单插件还有重写票据映射收付款单方法主体如下;
1-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.K3.FIN.CN.Common.Core.Object;
namespace test.Common.Core
{
public class TestBillInfos : RecBillInfos
{
/// <summary>
/// 初始化源单到目标单映射对应关系字段
/// </summary>
public override void OninitSrcToDesFieldKeyDic()
{
base.OninitSrcToDesFieldKeyDic();
//要携带字段
this.DesToSrcFieldKeyDic.Add("FTargeKey", "FSourkey");
}
}
}
重写票据映射到收付款方法OninitSrcToDesFieldKeyDic增加要携带字段
1-2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.K3.FIN.CN.Business.PlugIn.BillReceivable;
using System.ComponentModel;
using Kingdee.K3.FIN.CN.Common.Core.Object;
using test.Common.Core;
namespace test.Business.PlugIn
{
/// <summary>
/// 应收票据二开维护客户端插件
/// </summary>
[Description("应收票据二开维护客户端插件")]
public class BillRec : BillReceivableEdit
{
/// <summary>
/// 返回收款到票据映射类。
/// </summary>
/// <returns></returns>
protected override AbstractRecPayBillInfos OnInitRecPayBillInfos()
{
AbstractRecPayBillInfos recbillInfos = new TestBillInfos();
recbillInfos.OninitSrcInfos(this.View);
return recbillInfos;
}
}
}
重写应收票据表单插件把传过去参数的类容改成二开重写方法TestBillInfos
1-3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using test.Common.Core;
using Kingdee.K3.FIN.CN.Business.PlugIn.RecPayRefund;
using System.ComponentModel;
using Kingdee.K3.FIN.CN.Common.Core.Object;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Util;
namespace test.Business.PlugIn
{
/// <summary>
/// 收款单携带票据二开字段
/// </summary>
[Description("收款单维护客户端插件")]
public class RecBill : ReceiveBillEdit
{
/// <summary>
/// 设置目标单信息
/// </summary>
protected override void SetBillInfos()
{
AbstractRecPayBillInfos recBillInfo = this.GetBillInfo();
if (!recBillInfo.IsNullOrEmpty())
{
recBillInfo.SetDesInfos(this.View);
}
}
private AbstractRecPayBillInfos GetBillInfo()
{
object objBillInfo = this.View.OpenParameter.GetCustomParameter("RecPayBillInfo");
if (objBillInfo.IsNullOrEmptyOrWhiteSpace())
{
return null;
}
AbstractRecPayBillInfos recBillInfo = objBillInfo as TestBillInfos;
return recBillInfo;
}
}
}
重写收款单设置目标单信息 根据传过来参数 设置目标单信息
应收票据注册插件处理
收款单注册插件处理
2. 应收票据列表审核自动生成收款单这个需要重写应收票据审核操作插件
注:由于生成收款单有很多私有方法 几乎把标准的审核插件重写一遍(只是在生成收款单加了携带字段), 后期版本会优化 方便二开携带字段
重新写应收票据审核插件处理
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.K3.FIN.CN.App.ServicePlugIn.RecPayRefund;
using Kingdee.K3.FIN.Core;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Util;
using Kingdee.BOS.ServiceHelper;
using Kingdee.K3.FIN.CN.App.Core;
using Kingdee.K3.FIN.CN.App.ServicePlugIn;
using Kingdee.BOS;
namespace test.App.ServicePlugIn
{
/// <summary>
/// 应收票据审核生成收款单
/// 注:由于生成收款单有很多私有方法 几乎把标准的审核插件重写一遍(只是在生成收款单加了携带字段), 后期版本会优化 方便二开携带字段
/// 只需要停用以前营收票据审核插件 注册此插件即可
/// </summary>
[Description("应收票据审核操作的服务端插件")]
public class BillReceivableAudit : AbstractOperationServicePlugIn
{
/// <summary>
/// 操作标识
/// </summary>
public string CurrOperIndentify { get; private set; }
public override void OnPreparePropertys(PreparePropertysEventArgs e)
{
base.OnPreparePropertys(e);
e.FieldKeys.Add("FDATE");
e.FieldKeys.Add("FSETTLEORGID");
e.FieldKeys.Add("FCONTACTUNITTYPE");
e.FieldKeys.Add("FCONTACTUNIT");
e.FieldKeys.Add("FBILLNUMBER");
e.FieldKeys.Add("FCURRENCYID");
e.FieldKeys.Add("FMainBookCurId");
e.FieldKeys.Add("FExchangeTypeId");
e.FieldKeys.Add("FExchangeRate");
e.FieldKeys.Add("FPAYORGID");
e.FieldKeys.Add("FDEPARTMENTID");
e.FieldKeys.Add("FSALEORGID");
e.FieldKeys.Add("FSALEGROUPID");
e.FieldKeys.Add("FSALEERID");
e.FieldKeys.Add("FPARLEFTAMOUNTFOR");
e.FieldKeys.Add("FPARAMOUNTFOR");
e.FieldKeys.Add("FSETTLESTATUS");
e.FieldKeys.Add("FDUEDATE");
e.FieldKeys.Add("FBILLTYPE");
e.FieldKeys.Add("FScanPoint");
//增加营收票据要携带的字段
e.FieldKeys.Add("FSourkey");
}
public override void EndOperationTransaction(EndOperationTransactionArgs e)
{
base.EndOperationTransaction(e);
this.CurrOperIndentify = Guid.NewGuid().ToString();
if (IsBillAuto() == 0)
{
return;
}
this.GenerateRecBillAndUpDateRecBillStatus(e);
}
private void GenerateRecBillAndUpDateRecBillStatus(EndOperationTransactionArgs e)
{
this.MakeRecBillSettleDoc(e);
}
/// <summary>
/// 生成收款单,并反写对应字段值
/// </summary>
/// <param name="e"></param>
private void MakeRecBillSettleDoc(EndOperationTransactionArgs e)
{
FormMetadata formMetadata = ServiceFactory.GetMetaDataService(this.Context).Load(this.Context, BusinessObjectConst.AR_RECEIVEBILL, true) as FormMetadata;
foreach (var item in e.DataEntitys)
{
this.SaveDynamicObjects(item, formMetadata);
}
}
/// <summary>
/// 保存收款单
/// </summary>
private void SaveDynamicObjects(DynamicObject receiveData, FormMetadata formMetadata)
{
DynamicObject dynamicObject = this.GenerateBillRecSettleObj(receiveData, formMetadata);
if (dynamicObject == null)
{
return;
}
string billtypeid = dynamicObject["BillTypeID_ID"].ToString();
long payorgId = Convert.ToInt64(dynamicObject[BillRecKeyConst.FPAYORGID_ID]);
DynamicObject billtypeObj = CNServiceCommonFun.GetBillTypeInfoByBillTypeId(this.Context, billtypeid, payorgId, BusinessObjectConst.AR_RECEIVEBILL);
if (billtypeObj == null)
{
return;
}
IDraftService draftService = Kingdee.BOS.Contracts.ServiceFactory.GetDraftService(this.Context);
IOperationResult result = draftService.Draft(this.Context, formMetadata.BusinessInfo, new DynamicObject[] { dynamicObject }, OperateOption.Create(), "Draft");
if (!result.IsSuccess) return;
ISaveService saveService = Kingdee.BOS.Contracts.ServiceFactory.GetSaveService(this.Context);
result = saveService.Save(this.Context, formMetadata.BusinessInfo, new DynamicObject[] { dynamicObject }, OperateOption.Create(), "Save");
if (!result.IsSuccess) return;
this.UpdateBillNoBeforeSave(dynamicObject);
return;
}
private DynamicObject GenerateBillRecSettleObj(DynamicObject receiveData, FormMetadata formMetadata)
{
DynamicObject dynamicObject = this.CreateBillRecSettle(receiveData, formMetadata);
return dynamicObject;
}
/// <summary>
/// 创建收款单
/// </summary>
private DynamicObject CreateBillRecSettle(DynamicObject receiveData, FormMetadata formMetadata)
{
DynamicObject data = formMetadata.BusinessInfo.GetDynamicObjectType().CreateInstance() as DynamicObject;
IDBService service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IDBService>(this.Context);
long[] ids = service.GetSequenceInt64(this.Context, "T_AR_RECEIVEBILL", 1).ToArray();
data["Id"] = ids[0];
data["CONTACTUNITTYPE"] = receiveData["FCONTACTUNITTYPE"];
data["CONTACTUNIT"] = receiveData["FCONTACTUNIT"];
data["CONTACTUNIT_ID"] = receiveData["FCONTACTUNIT_ID"];
data[BillRecKeyConst.CURRENCYID] = receiveData[BillRecKeyConst.CURRENCYID];
data[BillRecKeyConst.CURRENCYID_ID] = receiveData[BillRecKeyConst.CURRENCYID_ID];
data["SETTLECUR"] = receiveData[BillRecKeyConst.CURRENCYID];
data["SETTLECUR_ID"] = receiveData[BillRecKeyConst.CURRENCYID_ID];
data[BillRecKeyConst.FPAYORGID] = receiveData[BillRecKeyConst.FPAYORGID];
data[BillRecKeyConst.FPAYORGID_ID] = receiveData[BillRecKeyConst.FPAYORGID_ID];
data[BillRecKeyConst.SETTLEORGID] = receiveData[BillRecKeyConst.SETTLEORGID];
data[BillRecKeyConst.SETTLEORGID_ID] = receiveData[BillRecKeyConst.SETTLEORGID_ID];
data["MAINBOOKCURID"] = receiveData["MainBookCurId"];
data[BillRecKeyConst.MAINBOOKCURID_ID] = receiveData["MainBookCurId_ID"];
data["EXCHANGETYPE"] = receiveData["ExchangeTypeId"];
data["EXCHANGETYPE_ID"] = receiveData["ExchangeTypeId_ID"];
data[BillRecKeyConst.DOCUMENTSTATUS] = DocumentStatus.Z;
data[BillRecKeyConst.FISSAMEORG] = receiveData[BillRecKeyConst.SETTLEORGID_ID] == receiveData[BillRecKeyConst.FPAYORGID_ID];
data["RECEIVEAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
data["REALRECAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
data["RECAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
decimal rate = Convert.ToDecimal(receiveData["ExchangeRate"]);
data[BillRecKeyConst.EXCHANGERATE] = rate;
data["SETTLERATE"] = rate;
data["RECAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
data["RECEIVEAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
data["REALRECAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
data["SALEORGID"] = receiveData["SALEORGID"];
data["SALEORGID_ID"] = receiveData["SALEORGID_ID"];
data["SALEDEPTID"] = receiveData["DEPARTMENTID"];
data["SALEDEPTID_ID"] = receiveData["DEPARTMENTID_ID"];
data["SALEGROUPID"] = receiveData["SALEGROUPID"];
data["SALEGROUPID_ID"] = receiveData["SALEGROUPID_ID"];
data["SALEERID"] = receiveData["SALEERID"];
data["SALEERID_ID"] = receiveData["SALEERID_ID"];
data["PAYUNITTYPE"] = receiveData["FCONTACTUNITTYPE"];
data["PAYUNIT"] = receiveData["FCONTACTUNIT"];
data["PAYUNIT_ID"] = receiveData["FCONTACTUNIT_ID"];
// 创建人创建日期审核人审核日期:当前用户和当前日期
DateTime dt = Kingdee.BOS.Contracts.ServiceFactory.GetTimeService(this.Context).GetSystemDateTime(this.Context);
data["FCreatorId_Id"] = this.Context.UserId;
data["FCreateDate"] = dt;
data["ModifierId_Id"] = this.Context.UserId;
data["FModifyDate"] = dt;
data["ApproverId_Id"] = this.Context.UserId;
data["ApproveDate"] = dt;
data[BillRecKeyConst.DATE] = receiveData[BillRecKeyConst.DATE];
data["FScanPoint"] = receiveData["FScanPoint"];
data["FScanPoint_Id"] = receiveData["FScanPoint_Id"];
//此处设置携带字段
data["FTargeKey"] = receiveData["FSourkey"];
DynamicObjectCollection collection = data["RECEIVEBILLENTRY"] as DynamicObjectCollection;
DynamicObject entry = collection.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IDBService>(this.Context);
ids = service.GetSequenceInt64(this.Context, "T_AR_RECEIVEBILLENTRY", 1).ToArray();
entry["Id"] = ids[0];
entry["Seq"] = 1;
entry["SETTLETYPEID_ID"] = receiveData["BILLTYPE"].ToString() == "1" ? "7" : "6";
if (data["CONTACTUNITTYPE"].ToString() == "BD_Customer")
{
data["BillTypeID_ID"] = "36cf265bd8c3452194ed9c83ec5e73d2";
data["BUSINESSTYPE"] = "1";
entry["PURPOSEID_ID"] = "20010";
}
else
{
data["BillTypeID_ID"] = "670b3608188c425a9f696d7ccb47843d";
data["BUSINESSTYPE"] = "3";
entry["PURPOSEID_ID"] = "20012";
}
entry["RECTOTALAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
entry["REALRECAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
entry["SETTLERECAMOUNTFOR"] = receiveData["PARAMOUNTFOR"];
entry["RECAMOUNTFOR_E"] = receiveData["PARAMOUNTFOR"];
entry["RECTOTALAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
entry["FREALRECAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
entry["SETTLERECAMOUNT"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
entry["RECAMOUNT_E"] = Convert.ToDecimal(receiveData["PARAMOUNTFOR"]) * rate;
entry["FPOSTDATE"] = data[BillRecKeyConst.DATE];
entry["FISPOST"] = CNServiceCommonFun.GetSysParaIsPostByOrg(this.Context, Convert.ToInt64(receiveData[BillRecKeyConst.FPAYORGID_ID]));
DynamicObjectCollection collectionBill = data["RECEIVEBILLREC"] as DynamicObjectCollection;
DynamicObject entryBill = collectionBill.DynamicCollectionItemPropertyType.CreateInstance() as DynamicObject;
service = Kingdee.BOS.Contracts.ServiceFactory.GetService<IDBService>(this.Context);
ids = service.GetSequenceInt64(this.Context, "T_AR_RECEIVEBILLREC", 1).ToArray();
entryBill["Id"] = ids[0];
entryBill["Seq"] = 1;
entryBill["BILLID_ID"] = receiveData["ID"];
entryBill["PARLEFTAMOUNTFOR"] = receiveData["PARLEFTAMOUNTFOR"];
entryBill["USEDAMOUNTFOR"] = receiveData["PARLEFTAMOUNTFOR"];
entryBill["FBPBILLNUMBER"] = receiveData["BILLNUMBER"];
entryBill["FBPBILLPARAMOUNT"] = receiveData["PARAMOUNTFOR"];
long PayOrgId = Convert.ToInt64(data[BillRecKeyConst.FPAYORGID_ID]);
long FSETTLEORGID = Convert.ToInt64(data[BillRecKeyConst.SETTLEORGID_ID]);
object isInner = SystemParameterServiceHelper.GetParamter(this.Context, PayOrgId, 0, BusinessObjectConst.CN_SystemParameter, "FINNERBANKDIS");
if ((PayOrgId == FSETTLEORGID && Convert.ToBoolean(isInner)) || PayOrgId != FSETTLEORGID)
{
object innerAcctType = Kingdee.BOS.ServiceHelper.SystemParameterServiceHelper.GetParamter(this.Context, PayOrgId, 0, BusinessObjectConst.CN_SystemParameter, "InnerAccountType");
if (innerAcctType.IsNullOrEmptyOrWhiteSpace())
{
innerAcctType = "1";
}
string filterClause = " FDOCUMENTSTATUS='C' AND FFORBIDSTATUS='A' AND FISDEFAULTINNERACCT='1' ";
if (Convert.ToInt64(innerAcctType) < 3)
{
filterClause = String.Format("{0} AND FORGSETGROUP = '{1}' AND FUseOrgId={2} AND FMAPPINGORGID={3} ", filterClause, innerAcctType, PayOrgId, FSETTLEORGID);
}
else
{
filterClause = String.Format("{0} AND FUseOrgId={1} AND FMAPPINGORGID={2} ", filterClause, PayOrgId, FSETTLEORGID);
}
QueryBuilderParemeter param = new QueryBuilderParemeter
{
FormId = BusinessObjectConst.CN_INNERACCOUNT,
SelectItems = SelectorItemInfo.CreateItems("FID,FNumber,FCreateOrgId,FMAPPINGORGID,FUseOrgId,FOrgSetGroup,FISDEFAULTINNERACCT"),
FilterClauseWihtKey = filterClause,
OrderByClauseWihtKey = "FORGSETGROUP DESC "
};
DynamicObjectCollection Finneraccountid = QueryServiceHelper.GetDynamicObjectCollection(this.Context, param);
if (Finneraccountid != null && Finneraccountid.Count > 0)
{
entry["FINNERACCOUNTID_id"] = Finneraccountid[0]["FID"];
entryBill["FInnerAccountID_B_id"] = Finneraccountid[0]["FID"];
DynamicObject Ffinneraccountid = CNCommonFunction.GetDynamicObjectByID(this.Context, BusinessObjectConst.CN_INNERACCOUNT, Convert.ToInt64(Finneraccountid[0]["FID"]));
entry["FINNERACCOUNTID"] = Ffinneraccountid;
entryBill["FInnerAccountID_B"] = Ffinneraccountid;
}
}
collection.Add(entry);
collectionBill.Add(entryBill);
return data;
}
/// <summary>
/// 获取票据用户参数:是否审核自动生成收款单
/// </summary>
/// <returns></returns>
private int IsBillAuto()
{
FormMetadata formMetadata = ServiceFactory.GetMetaDataService(this.Context).Load(this.Context, "CN_UserRecSystemParameter", true) as FormMetadata;
IUserParameterService userParameterService = Kingdee.BOS.Contracts.ServiceFactory.GetService<IUserParameterService>(this.Context);
DynamicObject strUser = userParameterService.Load(this.Context, formMetadata.BusinessInfo,
this.Context.UserId, "CN_BILLRECEIVABLE", "UserParameter");
if (strUser == null || strUser["FBillRecAuto"].ToString() == "")
{
return 1;
}
return Convert.ToInt32(strUser["FBillRecAuto"]);
}
/// <summary>
/// 更新实体对象的单据编号
/// </summary>
/// <param name="dynamicObject"></param>
private void UpdateBillNoBeforeSave(DynamicObject dynamicObject)
{
BusinessInfo businessInfo = ((FormMetadata)ServiceFactory.GetMetaDataService(this.Context).Load(this.Context, BusinessObjectConst.AR_RECEIVEBILL, true)).BusinessInfo;
DynamicObject[] objs = new DynamicObject[] { Kingdee.BOS.Util.ObjectUtils.CreateCopy(dynamicObject) as DynamicObject };
BusinessInfo bizInfo = Kingdee.BOS.Util.ObjectUtils.CreateCopy(businessInfo) as BusinessInfo;
bizInfo.GetBillNoField().Entity.TableName = "";
IBusinessDataService bizSev = Kingdee.BOS.App.ServiceHelper.GetService<IBusinessDataService>();
List<BillNoInfo> billNos = bizSev.GetBillNo(this.Context, bizInfo, objs, true);
if ((billNos != null) || (billNos.Count > 0))
{
dynamicObject["BillNo"] = billNos[0].BillNo;
}
}
}
}
由于工程太大传不了 !有什么问题 一起交流!
推荐阅读