在应收单审核后下推收款单失败
金蝶云社区-小卖部部长
小卖部部长
0人赞赏了该文章 1,574次浏览 未经作者许可,禁止转载编辑于2017年10月26日 16:05:32

public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
{
base.AfterExecuteOperationTransaction(e);

OperateResultCollection oResult = this.OperationResult.OperateResult;

if (e.DataEntitys != null && e.DataEntitys.Count() > 0)
{
foreach (DynamicObject item in e.DataEntitys)
{
string sourceFormId = "AR_receivable";
string targetFormId = "AR_RECEIVEBILL";

// 获取源单与目标单直接的转换规则,如果规则未启用,则返回为空,注意容错
// 假设:上游单据FormId为sourceFormId,下游单据FormId为targetFormId
var rules = ConvertServiceHelper.GetConvertRules(this.Context, sourceFormId, targetFormId);
var rule = rules.FirstOrDefault(t => t.IsDefault);
// 获取在列表上当前选择需下推的行
//ListSelectedRow[] selectedRows = (from t1 in (item["AP_PAYABLEPLAN"] as DynamicObjectCollection) select new ListSelectedRow(item["Id"].ToString(), t1["Id"].ToString(), Convert.ToInt32(t1["Seq"]), "AR_receivable")).ToArray();

ListSelectedRow[] selectedRows = new ListSelectedRow[] { new ListSelectedRow("102135", "102102", 0, "AR_receivable") };

// 如下代码为单据上获取当前当前选择行
// string primaryKeyValue = ((IBillView)this.View).Model.GetPKValue().ToString();
// ListSelectedRow row = new ListSelectedRow(primaryKeyValue, string.Empty, 0, this.View.BillBusinessInfo.GetForm().Id);
// ListSelectedRow[] selectedRows = new ListSelectedRow[] { row };

// 调用下推服务,生成下游单据数据包
ConvertOperationResult operationResult = null;
Dictionary custParams = new Dictionary();
try
{

PushArgs pushArgs = new PushArgs(rule, selectedRows)
{
TargetBillTypeId = "36cf265bd8c3452194ed9c83ec5e73d24", // 请设定目标单据单据类型。如无单据类型,可以空字符
TargetOrgId = Convert.ToInt64(item["SALEORGID_Id"]), // 请设定目标单据主业务组织。如无主业务组织,可以为0
CustomParams = custParams, // 可以传递额外附加的参数给单据转换插件,如无此需求,可以忽略
};
//执行下推操作,并获取下推结果
operationResult = ConvertServiceHelper.Push(this.Context, pushArgs, OperateOption.Create());
}
catch (KDExceptionValidate ex)
{

throw new KDException(ex.Message, ex.ValidateString);
}
catch (KDException ex)
{
throw new KDException("", ex.Message);
}
catch
{
throw;
}
// 获取生成的目标单据数据包
DynamicObject[] objs = (from p in operationResult.TargetDataEntities
select p.DataEntity).ToArray();
// 读取目标单据元数据
var targetBillMeta = MetaDataServiceHelper.Load(this.Context, targetFormId) as FormMetadata;
OperateOption saveOption = OperateOption.Create();
// 忽略全部需要交互性质的提示,直接保存;
//saveOption.SetIgnoreWarning(true); // 提交数据库保存,并获取保存结果
var saveResult = BusinessDataServiceHelper.Save(this.Context, targetBillMeta.BusinessInfo, objs, saveOption, "Save");
// 根据保存结果,显示对应的提示
// TODO: 略,请自行查看saveResult对象的结构,利用this.View.ShowMessage之类函数,显示结果..

}
}

}

错误提示为
必须满足如下条件:1.单据已审核;2、应收金额大于关联金额;3、立账类型不为暂估应收。\r\n\r\n取数失败原因分析:\r\n1. 共选择了1行数据进行下推;\r\n2. 有1行数据不满足下推数据筛选条件:所选目标单据类型,不允许由本源单下推\r\n