2023-12-08 23:53:07 +08:00
|
|
|
|
using ExtensionMethods;
|
|
|
|
|
|
using Kingdee.BOS.App.Data;
|
|
|
|
|
|
using Kingdee.BOS.Core.Bill.PlugIn;
|
|
|
|
|
|
using Kingdee.BOS.Core.Bill.PlugIn.Args;
|
2023-12-15 09:08:09 +08:00
|
|
|
|
using Kingdee.BOS.Core.DynamicForm;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
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 UseGetFmaterialData
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 【单据插件】保存前事件
|
|
|
|
|
|
/// 触发顺序:BeforeDoOperation->BeforeSave
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Description("【单据插件】保存前事件"), HotUpdate]
|
|
|
|
|
|
public class BeforeSaveEventBillPlugIn : AbstractBillPlugIn
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public override void BeforeSave(BeforeSaveEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.BeforeSave(e);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
this.View.ShowMessage("插件触发了保存前事件:BeforeSave");
|
2023-12-14 10:31:17 +08:00
|
|
|
|
if (OrgIdCheck())
|
|
|
|
|
|
{
|
|
|
|
|
|
Entity details = null;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
2023-12-14 10:31:17 +08:00
|
|
|
|
//其他出库单 明细表
|
|
|
|
|
|
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
|
|
|
|
|
|
details = this.View.BusinessInfo.GetEntity("FEntity");
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
2023-12-14 10:31:17 +08:00
|
|
|
|
//直接调拨单 明细表
|
|
|
|
|
|
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
|
|
|
|
|
|
details = this.View.BusinessInfo.GetEntity("FBillEntry");
|
2023-12-15 09:08:09 +08:00
|
|
|
|
IOperationResult opResult = new OperationResult();
|
2023-12-14 10:31:17 +08:00
|
|
|
|
if (details != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entrys = this.View.Model.GetEntityDataObject(details);
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
2023-12-14 10:31:17 +08:00
|
|
|
|
if (entrys != null && entrys.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var tempValue2 = this.View.Model.GetValue("FDATE");
|
|
|
|
|
|
var dateValue = tempValue2.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue2.ToString();
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
2023-12-14 10:31:17 +08:00
|
|
|
|
foreach (var entry in entrys)
|
2023-12-08 23:53:07 +08:00
|
|
|
|
{
|
2023-12-14 10:31:17 +08:00
|
|
|
|
var rowIndex = this.View.Model.GetRowIndex(details, entry);
|
|
|
|
|
|
var tempValue = entry["MaterialId_Id"];
|
|
|
|
|
|
var rowValue = tempValue.IsNullOrEmptyOrWhiteSpace() ? string.Empty : tempValue.ToString();
|
2023-12-15 09:08:09 +08:00
|
|
|
|
string errMsg = string.Empty;
|
|
|
|
|
|
UpdReferPriceAndExplain(dateValue, rowValue, rowIndex, ref errMsg);
|
|
|
|
|
|
|
|
|
|
|
|
if (!errMsg.IsNullOrEmpty())
|
|
|
|
|
|
{
|
|
|
|
|
|
var number = (entry["MaterialId"] as DynamicObject)["Number"];
|
|
|
|
|
|
opResult.OperateResult.Add(new OperateResult
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = number.ToString(),
|
|
|
|
|
|
Message = errMsg,
|
|
|
|
|
|
SuccessStatus = false
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
2023-12-14 10:31:17 +08:00
|
|
|
|
TotalReferAmount(entrys, details);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (opResult.OperateResult.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Cancel = true;
|
|
|
|
|
|
this.View.ShowOperateResult(opResult.OperateResult);
|
|
|
|
|
|
}
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-14 10:31:17 +08:00
|
|
|
|
}
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 参考金额汇总
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="entrys"></param>
|
|
|
|
|
|
public void TotalReferAmount(DynamicObjectCollection entrys, Entity details)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (entrys == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//其他出库单 明细表
|
|
|
|
|
|
if (this.View.UserParameterKey.Equals("STK_MisDelivery"))
|
|
|
|
|
|
details = this.View.BusinessInfo.GetEntity("FEntity");
|
|
|
|
|
|
|
|
|
|
|
|
//直接调拨单 明细表
|
|
|
|
|
|
if (this.View.UserParameterKey.Equals("STK_TransferDirect"))
|
|
|
|
|
|
details = this.View.BusinessInfo.GetEntity("FBillEntry");
|
|
|
|
|
|
|
|
|
|
|
|
if (details != null)
|
|
|
|
|
|
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);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
//参考金额汇总
|
2023-12-08 23:53:07 +08:00
|
|
|
|
this.View.Model.SetValue("FTotalReferAmount", total);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
this.View.Model.SetValue("FTotalReferAmount", total);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
//参考金额汇总
|
2023-12-08 23:53:07 +08:00
|
|
|
|
this.View.Model.SetValue("F_GAT_Decimal1", total);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch { }
|
|
|
|
|
|
finally { }
|
|
|
|
|
|
}
|
|
|
|
|
|
finally { }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 检测组织
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public bool OrgIdCheck()
|
|
|
|
|
|
{
|
|
|
|
|
|
//直接调拨单 调出库存组织
|
|
|
|
|
|
var org = this.View.Model.GetValue("FStockOutOrgId") as DynamicObject;
|
|
|
|
|
|
//其他出库单 库存组织
|
|
|
|
|
|
if (org == null)
|
|
|
|
|
|
org = this.View.Model.GetValue("FStockOrgId") as DynamicObject;
|
|
|
|
|
|
|
2023-12-10 13:58:49 +08:00
|
|
|
|
return org != null && Convert.ToInt32(org["Id"]) == 101542;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新对应行数的参考单价与取价方向
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="date">表头日期</param>
|
|
|
|
|
|
/// <param name="materialId">子表物料id(物料编码)</param>
|
|
|
|
|
|
/// <param name="row"></param>
|
2023-12-15 09:08:09 +08:00
|
|
|
|
private void UpdReferPriceAndExplain(string date, string materialId, int row, ref string errMsg)
|
2023-12-08 23:53:07 +08:00
|
|
|
|
{
|
2023-12-15 09:08:09 +08:00
|
|
|
|
var isHasEmpty = false;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
var returnFlag = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (date.IsNullOrEmptyOrWhiteSpace())
|
2023-12-15 09:08:09 +08:00
|
|
|
|
isHasEmpty = returnFlag = true;
|
2023-12-08 23:53:07 +08:00
|
|
|
|
|
|
|
|
|
|
if (!returnFlag && (materialId.IsNullOrEmptyOrWhiteSpace() || materialId.Equals("0")))
|
|
|
|
|
|
returnFlag = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (returnFlag)
|
|
|
|
|
|
{
|
|
|
|
|
|
//参考单价
|
|
|
|
|
|
this.View.Model.SetValue("FReferPrice", "", row);
|
|
|
|
|
|
//参考金额
|
|
|
|
|
|
this.View.Model.SetValue("FReferAmount", "", row);
|
|
|
|
|
|
////小数类型参考金额控件
|
|
|
|
|
|
//this.View.Model.SetValue("FReferAmountM", 0, row);
|
|
|
|
|
|
//参考方向
|
2023-12-14 10:31:17 +08:00
|
|
|
|
this.View.Model.SetValue("FExplain", "没有找到价格", row);
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
var sqlL = $"EXEC GetFmaterialData {materialId},'{date}'";
|
|
|
|
|
|
|
|
|
|
|
|
var dataSet = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{sqlL}");
|
|
|
|
|
|
|
|
|
|
|
|
if (dataSet != null && dataSet.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var price = dataSet[0]["Fprice"].ToDecimalR();
|
|
|
|
|
|
//数量
|
|
|
|
|
|
var qty = this.View.Model.GetValue("FQty", row).ToDecimal();
|
|
|
|
|
|
|
|
|
|
|
|
var amount = (qty * price).ToDecimalR();
|
|
|
|
|
|
//参考单价
|
|
|
|
|
|
this.View.Model.SetValue("FReferPrice", (price == 0 ? "" : price.ToString()), row);
|
|
|
|
|
|
|
|
|
|
|
|
//参考金额
|
|
|
|
|
|
this.View.Model.SetValue("FReferAmount", (amount == 0 ? "" : amount.ToString()), row);
|
|
|
|
|
|
//小数类型参考金额控件
|
|
|
|
|
|
//this.View.Model.SetValue("FReferAmountM", amount, row);
|
|
|
|
|
|
|
|
|
|
|
|
//参考方向
|
|
|
|
|
|
this.View.Model.SetValue("FExplain", dataSet[0]["FNOTE"], row);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
|
|
|
|
|
if (price == 0 || amount == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
errMsg = "物料没有找到参考单价与参考金额,或数量为0";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var cSql = $@"
|
|
|
|
|
|
SELECT top 1
|
|
|
|
|
|
A.FBILLNO,C.FTAXPRICE
|
|
|
|
|
|
FROM
|
|
|
|
|
|
T_STK_INSTOCK A
|
|
|
|
|
|
INNER JOIN T_STK_INSTOCKENTRY B ON A.FID =B.FID
|
|
|
|
|
|
INNER JOIN T_STK_INSTOCKENTRY_F C ON C.FENTRYID = B.FENTRYID
|
|
|
|
|
|
WHERE
|
|
|
|
|
|
A.FDOCUMENTSTATUS = 'C'
|
|
|
|
|
|
AND A.FCANCELSTATUS = 'A'
|
|
|
|
|
|
AND A.FSTOCKORGID = 101542
|
|
|
|
|
|
AND B.FMATERIALID = {materialId}
|
|
|
|
|
|
AND FDATE<= '{date}'
|
|
|
|
|
|
AND FAPPROVEDATE <= '{date}'
|
|
|
|
|
|
ORDER BY
|
|
|
|
|
|
FDATE DESC,FAPPROVEDATE DESC ";
|
|
|
|
|
|
|
|
|
|
|
|
var inDataSet = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{cSql}");
|
|
|
|
|
|
if (inDataSet.Any())
|
|
|
|
|
|
{
|
|
|
|
|
|
var taxPrice = inDataSet[0]["FTAXPRICE"].ToDecimalR();
|
|
|
|
|
|
if (taxPrice == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
errMsg = "物料没有找到采购入库单单价";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var xAbs = Math.Abs((price - taxPrice) / taxPrice);
|
|
|
|
|
|
if (xAbs > 0.05M)
|
|
|
|
|
|
{
|
|
|
|
|
|
errMsg = "物料采购入库单价与参考单价相差值不能大于5%";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
errMsg = "物料没有找到采购入库单";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
//参考单价
|
|
|
|
|
|
this.View.Model.SetValue("FReferPrice", "", row);
|
|
|
|
|
|
//参考金额
|
|
|
|
|
|
this.View.Model.SetValue("FReferAmount", "", row);
|
|
|
|
|
|
//小数类型参考金额控件
|
|
|
|
|
|
//this.View.Model.SetValue("FReferAmountM", 0, row);
|
|
|
|
|
|
//参考方向
|
2023-12-14 10:31:17 +08:00
|
|
|
|
this.View.Model.SetValue("FExplain", "没有找到价格", row);
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-15 09:08:09 +08:00
|
|
|
|
|
2023-12-08 23:53:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|