项目实战分享:通过插件代码下推单据时按需求修改相应的数据进行保存

1、调用下推单据的方法
//传递参数,自行定义参数类retMatchGeneration
retMGen.FSTOCKID = this.Model.GetValue("FSTOCKID", rowIndex) as DynamicObject; //收货仓库
retMGen.FSTOCKLOCID = this.Model.GetValue("FStockLocId", rowIndex) as DynamicObject; //仓位
retMGen.F_T_SHIPNAME = this.Model.GetValue("F_T_ShipName", rowIndex).ToString(); //快递公司
retMGen.F_T_SHIPNO = this.Model.GetValue("F_T_ShipNo", rowIndex).ToString(); //快递单号
retMGen.F_T_BARCODE = this.Model.GetValue("F_T_BarCode", rowIndex).ToString(); //条码
//源单数据SQL,按项目实际需求编写
strSql = "select * from T_SAL_OUTSTOCK t1 inner join T_SAL_OUTSTOCKENTRY t2 on t1.FID=t2.FID where t1.FBILLNO='" + strSOSBillno + "'";
//销售出库单 下推 销售退货单
operResult = this.PushDown_OUTSTOCK_RETURNSTOCK("SAL_OUTSTOCK", "SAL_RETURNSTOCK", strSql, "73383412199a402bb58439509e089077", retMGen);
2、传递需要修改的内容,通过修改元数据,可以在保存目标单据元数据前,按实际需求影响下推时的数据。
/// 下推 单据转换 销售出库单 下推 销售退货单
/// </summary>
/// <param name="source">源单 业务对象标识</param>
/// <param name="target">目标单 业务对象标识</param>
/// <param name="getSourceSql">源单 查询语句</param>
/// <param name="sargetBillTypeId">目标单 转换目标类型</param>
/// <param name="retMatchGen">传递参数类</param>
/// <returns></returns>
public IOperationResult PushDown_OUTSTOCK_RETURNSTOCK(string source, string target, string getSourceSql, string sargetBillTypeId, retMatchGeneration retMatchGen)
{
IOperationResult result = new OperationResult();
IOperationResult saveResult = new OperationResult();
List<long> stockOrgIds = new List<long>();
List<string> materialNumbers = new List<string>();
object systemProfile = CommonServiceHelper.GetSystemProfile(this.Context, 0L, "STK_StockParameter", "RecInvCheckMidData", false);
bool recordMidData = false;
if (systemProfile != null && !string.IsNullOrWhiteSpace(systemProfile.ToString()))
{
recordMidData = Convert.ToBoolean(systemProfile);
}
//systemProfile = CommonServiceHelper.GetSystemProfile(ctx, 0L, "STK_StockParameter", "CleanReleaseLink", false);
//bool cleanReleaseLink = false;
//if (systemProfile != null && !string.IsNullOrWhiteSpace(systemProfile.ToString()))
//{
// cleanReleaseLink = Convert.ToBoolean(systemProfile);
//}
//获取单据转换规则
ConvertRuleElement ruleElement = ServiceHelper.GetService<IConvertService>().GetConvertRules(this.Context, source, target).FirstOrDefault();
//如下代码 直接通过查询数据库获取单据转换源单数据
ListSelectedRowCollection rows = new ListSelectedRowCollection();
int i = 0;
using (IDataReader reader = DBUtils.ExecuteReader(this.Context, getSourceSql))
{
while (reader.Read())
{
ListSelectedRow row = new ListSelectedRow(reader["FID"].ToString(), reader["FEntryID"].ToString(), i++, source);
row.EntryEntityKey = "FEntity";
rows.Add(row);
}
}
if (rows.Count() == 0) { return new OperationResult(); }
PushArgs pushArgs = new PushArgs(ruleElement, rows.ToArray());
pushArgs.TargetBillTypeId = sargetBillTypeId;
////转换生成目标单
//ConvertOperationResult convertResult = ServiceHelper.GetService<IConvertService>().Push(this.Context, pushArgs);
//转换生成目标单
ConvertOperationResult convertResult = ConvertServiceHelper.Push(this.Context, pushArgs, OperateOption.Create());
//合并转换操作结果
result.MergeResult(convertResult);
//目标单据数据集合
DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray();
stockOrgIds.Add(Convert.ToInt64(destObjs[0]["StockOrgId_id"])); //库存组织明细 校对即时库存参数
//根据实际情况,处理目标单据数据
DynamicObjectCollection col_FEntityDetail = destObjs[0]["SAL_RETURNSTOCKENTRY"] as DynamicObjectCollection;
//int sum = 0;
foreach (var item in col_FEntityDetail)
{
DynamicObject dyoMater = (DynamicObject)item["MaterialId"];
materialNumbers.Add(Convert.ToString(dyoMater["Number"])); //物料明细 校对即时库存参数
//应退数量
item["Mustqty"] = retMatchGen.FQTY;
//实退数量
item["RealQty"] = retMatchGen.FQTY;
//库存基本数量
item["BaseunitQty"] = retMatchGen.FQTY;
//库存更新标示
item["STOCKFLAG"] = 1;
//金额 单价*数量,数量默认都是1,直接取单价。
item["Amount"] = Math.Round(Convert.ToDecimal( item["Price"])* retMatchGen.FQTY,2);
//金额(本位币) 单价*数量,数量默认都是1,直接取单价。
item["Amount_LC"] = Math.Round(Convert.ToDecimal(item["Price"]) * retMatchGen.FQTY,2);
//decimal iTaxRate = Convert.ToDecimal(item["TaxRate"].ToString()); //税率
//税额 单价*数量*税率/100,数量默认都是1,直接取单价。
item["TaxAmount"] = Math.Round(retMatchGen.FQTY * Convert.ToDecimal(item["Price"].ToString()) * Convert.ToDecimal(item["TaxRate"].ToString()) / 100, 2);
//税额(本位币) 单价*数量*税率/100,数量默认都是1,直接取单价。
item["TaxAmount_LC"] = Math.Round(retMatchGen.FQTY * Convert.ToDecimal(item["Price"].ToString()) * Convert.ToDecimal(item["TaxRate"].ToString()) / 100, 2);
//价税合计 含税单价*数量,数量默认都是1,直接取含税单价。
item["AllAmount"] = Math.Round(Convert.ToDecimal(item["TaxPrice"]) * retMatchGen.FQTY, 2) ;
//价税合计(本位币) 含税单价*数量,数量默认都是1,直接取含税单价。
item["AllAmount_LC"] = Math.Round(Convert.ToDecimal(item["TaxPrice"]) * retMatchGen.FQTY, 2) ;
//计价数量
item["PriceUnitQty"] = retMatchGen.FQTY;
//计价基本数量
item["PriceBaseQty"] = retMatchGen.FQTY;
//销售数量
item["SalUnitQty"] = retMatchGen.FQTY;
//销售基本数量
item["SalBaseQty"] = retMatchGen.FQTY;
项目实战分享:通过插件代码下推单据时按需求修改相应的数据进行保存
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



