205 lines
8.2 KiB
C#
205 lines
8.2 KiB
C#
|
|
using ExtensionMethods;
|
|||
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
|||
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
|||
|
|
using Kingdee.BOS.Core.Metadata.EntityElement;
|
|||
|
|
using Kingdee.BOS.Orm.DataEntity;
|
|||
|
|
using Kingdee.BOS.Util;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace ZHSW.STK_MisDelivery
|
|||
|
|
{
|
|||
|
|
[Description("【其他出库单】1.获取参考单价"), HotUpdate]
|
|||
|
|
public class BillEventPlugInEx : AbstractDynamicFormPlugIn
|
|||
|
|
{
|
|||
|
|
public override void DataChanged(DataChangedEventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
base.DataChanged(e);
|
|||
|
|
|
|||
|
|
//表头日期
|
|||
|
|
if (e.Field.Key.EqualsIgnoreCase("FDATE"))
|
|||
|
|
{
|
|||
|
|
if (DoDetection())
|
|||
|
|
{
|
|||
|
|
//其他出库单 明细表
|
|||
|
|
var details = this.View.BusinessInfo.GetEntity("FEntity");
|
|||
|
|
|
|||
|
|
if (details != null)
|
|||
|
|
{
|
|||
|
|
var entrys = this.View.Model.GetEntityDataObject(details);
|
|||
|
|
|
|||
|
|
if (entrys != null && entrys.Any())
|
|||
|
|
{
|
|||
|
|
var dateValue = e.NewValue == null ? string.Empty : e.NewValue.ToString();
|
|||
|
|
var dataList = new List<string>();
|
|||
|
|
foreach (var entry in entrys)
|
|||
|
|
{
|
|||
|
|
var rowIndex = this.View.Model.GetRowIndex(details, entry);
|
|||
|
|
|
|||
|
|
var materialObjValue = entry["MaterialId_Id"];
|
|||
|
|
var materialValue = materialObjValue.IsNullOrEmptyOrWhiteSpace() ? 0 : materialObjValue.Long2Int();
|
|||
|
|
|
|||
|
|
var stockObjValue = entry["StockId_Id"];
|
|||
|
|
var stockValue = stockObjValue.IsNullOrEmptyOrWhiteSpace() ? 0 : stockObjValue.Long2Int();
|
|||
|
|
|
|||
|
|
var entityLinkObjList = entry["FEntity_Link"] as DynamicObjectCollection;
|
|||
|
|
DynamicObject entityLinkObj = null;
|
|||
|
|
if (entityLinkObjList != null && entityLinkObjList.Any())
|
|||
|
|
entityLinkObj = entityLinkObjList[0];
|
|||
|
|
|
|||
|
|
var sBillId = entityLinkObj.IsNullOrEmptyOrWhiteSpace() ? 0 : entityLinkObj["SBillId"].Long2Int();
|
|||
|
|
var sId = entityLinkObj.IsNullOrEmptyOrWhiteSpace() ? 0 : entityLinkObj["SId"].Long2Int();
|
|||
|
|
var sTableName = entityLinkObj.IsNullOrEmptyOrWhiteSpace() ? "" : entityLinkObj["STableName"].ToString();
|
|||
|
|
|
|||
|
|
if (materialValue != 0 && stockValue != 0 && dateValue != string.Empty)
|
|||
|
|
dataList.Add($"{materialValue},{rowIndex},{sBillId},{sId},{stockValue},{dateValue},{sTableName}");
|
|||
|
|
//UpdReferPriceAndExplain(dateValue, materialValue, stockValue, rowIndex);
|
|||
|
|
}
|
|||
|
|
TotalReferAmount(entrys, details);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//子表物料id
|
|||
|
|
if (e.Field.Key.EqualsIgnoreCase("FMaterialId"))
|
|||
|
|
{
|
|||
|
|
if (DoDetection())
|
|||
|
|
{
|
|||
|
|
var dateObjValue = this.View.Model.GetValue("FDATE");
|
|||
|
|
var dateValue = dateObjValue == null ? string.Empty : dateObjValue.ToString();
|
|||
|
|
|
|||
|
|
var materialValue = e.NewValue == null ? string.Empty : e.NewValue.ToString();
|
|||
|
|
|
|||
|
|
var stockObjValue = this.View.Model.GetValue("StockId_Id", e.Row);
|
|||
|
|
var stockValue = stockObjValue.IsNullOrEmptyOrWhiteSpace() ? string.Empty : stockObjValue.ToString();
|
|||
|
|
//UpdReferPriceAndExplain(dateValue, materialValue, stockValue, e.Row);
|
|||
|
|
TotalReferAmount(null, null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//仓库
|
|||
|
|
if (e.Field.Key.EqualsIgnoreCase("FStockId"))
|
|||
|
|
{
|
|||
|
|
if (DoDetection())
|
|||
|
|
{
|
|||
|
|
var materialObjValue = this.View.Model.GetValue("StockId_Id", e.Row); ;
|
|||
|
|
var materialValue = materialObjValue == null ? string.Empty : materialObjValue.ToString();
|
|||
|
|
|
|||
|
|
var dateObjValue = this.View.Model.GetValue("FDATE");
|
|||
|
|
var dateValue = dateObjValue == null ? string.Empty : dateObjValue.ToString();
|
|||
|
|
|
|||
|
|
var stockValue = e.NewValue == null ? string.Empty : e.NewValue.ToString();
|
|||
|
|
|
|||
|
|
//UpdReferPriceAndExplain(dateValue, materialValue, stockValue, e.Row);
|
|||
|
|
TotalReferAmount(null, null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//数量
|
|||
|
|
if (e.Field.Key.EqualsIgnoreCase("FQty"))
|
|||
|
|
{
|
|||
|
|
if (DoDetection())
|
|||
|
|
{
|
|||
|
|
//参考单价
|
|||
|
|
var referPrice = this.View.Model.GetValue("FReferPrice", e.Row).ToDecimalR();
|
|||
|
|
var amount = (e.NewValue.ToDecimal() * referPrice).ToDecimalR();
|
|||
|
|
//参考金额
|
|||
|
|
this.View.Model.SetValue("FReferAmount", amount == 0 ? "" : amount.ToString(), e.Row);
|
|||
|
|
//小数类型参考金额控件
|
|||
|
|
//this.View.Model.SetValue("FReferAmountM", amount, e.Row);
|
|||
|
|
TotalReferAmount(null, null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#region 2023-12-14 阿斌修改,参考单价改变更新金额
|
|||
|
|
//参考单价
|
|||
|
|
if (e.Field.Key.EqualsIgnoreCase("FReferPrice"))
|
|||
|
|
{
|
|||
|
|
if (DoDetection())
|
|||
|
|
{
|
|||
|
|
//数量
|
|||
|
|
var FQty = this.View.Model.GetValue("FQty", e.Row).ToDecimalR();
|
|||
|
|
#region 2024-01-27 参考金额修正
|
|||
|
|
//参考单价
|
|||
|
|
var referPrice = e.NewValue.ToDecimal();
|
|||
|
|
//参考金额
|
|||
|
|
this.View.Model.SetValue("FReferAmount", referPrice == 0M ? "" : (FQty * referPrice).ToDecimalR().ToString(), e.Row);
|
|||
|
|
#endregion
|
|||
|
|
//小数类型参考金额控件
|
|||
|
|
TotalReferAmount(null, null);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 检测组织
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private bool DoDetection()
|
|||
|
|
{
|
|||
|
|
//库存方向为退货时不执行取数
|
|||
|
|
var stockDirect = this.View.Model.GetValue("FStockDirect");
|
|||
|
|
if (!stockDirect.IsNullOrEmptyOrWhiteSpace() && stockDirect.Equals("RETURN"))
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
//直接调拨单 调出库存组织
|
|||
|
|
var org = this.View.Model.GetValue("FStockOutOrgId") as DynamicObject;
|
|||
|
|
//其他出库单 库存组织
|
|||
|
|
if (org == null)
|
|||
|
|
org = this.View.Model.GetValue("FStockOrgId") as DynamicObject;
|
|||
|
|
|
|||
|
|
return org != null && Convert.ToInt32(org["Id"]) == 101542;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 参考金额汇总
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="entrys"></param>
|
|||
|
|
private void TotalReferAmount(DynamicObjectCollection entrys, Entity details)
|
|||
|
|
{
|
|||
|
|
if (entrys == null)
|
|||
|
|
{
|
|||
|
|
//其他出库单 明细表
|
|||
|
|
details = this.View.BusinessInfo.GetEntity("FEntity");
|
|||
|
|
entrys = this.View.Model.GetEntityDataObject(details);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var total = 0M;
|
|||
|
|
|
|||
|
|
if (entrys != null && entrys.Any())
|
|||
|
|
{
|
|||
|
|
foreach (var entry in entrys)
|
|||
|
|
{
|
|||
|
|
var rowIndex = this.View.Model.GetRowIndex(details, entry);
|
|||
|
|
var tAmount = this.View.Model.GetValue("FReferAmount", rowIndex).ToDecimal();
|
|||
|
|
total += tAmount;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.View.Model.SetValue("F_GAT_Decimal1", total);
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
this.View.Model.SetValue("FTotalReferAmount", total);
|
|||
|
|
}
|
|||
|
|
catch { }
|
|||
|
|
finally { }
|
|||
|
|
}
|
|||
|
|
finally { }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|