101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
|
|
using Kingdee.BOS.Core.Bill.PlugIn;
|
|||
|
|
using Kingdee.BOS.Core.Bill.PlugIn.Args;
|
|||
|
|
using Kingdee.BOS.App.Data;
|
|||
|
|
using Kingdee.BOS.Orm.DataEntity;
|
|||
|
|
using Kingdee.BOS.Core.DynamicForm;
|
|||
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
|||
|
|
using Kingdee.BOS.Core.Permission;
|
|||
|
|
using Kingdee.BOS.Util;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.ComponentModel;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
|
|||
|
|
using Kingdee.BOS.Core.Metadata.Util;
|
|||
|
|
|
|||
|
|
namespace ProductionMaterialRequisition
|
|||
|
|
{
|
|||
|
|
[HotUpdate, Description("生产领料单保存库存数量验证")]
|
|||
|
|
public class SaveVerification : AbstractBillPlugIn
|
|||
|
|
{
|
|||
|
|
public override void BeforeSave(BeforeSaveEventArgs e)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
base.BeforeSave(e);
|
|||
|
|
|
|||
|
|
if (VerificationStock())
|
|||
|
|
{
|
|||
|
|
//this.View.ShowMessage("保存验证失败", MessageBoxType.Error);
|
|||
|
|
e.Cancel = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public bool VerificationStock()
|
|||
|
|
{
|
|||
|
|
var details = this.View.BusinessInfo.GetEntity("FEntity");
|
|||
|
|
|
|||
|
|
var entrys = this.View.Model.GetEntityDataObject(details);
|
|||
|
|
if (entrys == null || !entrys.Any())
|
|||
|
|
return false;
|
|||
|
|
|
|||
|
|
var id = this.View.Model.DataObject["Id"].Long2Int();
|
|||
|
|
var inDBWhere = $" AND tpp.FID !={id} ";
|
|||
|
|
if (id == 0)
|
|||
|
|
inDBWhere = string.Empty;
|
|||
|
|
|
|||
|
|
var selectActualQtySQL = $@"
|
|||
|
|
SELECT
|
|||
|
|
tbm.FMATERIALID,
|
|||
|
|
tbm.FUSEORGID,
|
|||
|
|
tbm.FMASTERID,
|
|||
|
|
SUM ( tsi.FBASEQTY ) - SUM ( tppd.FACTUALQTY ) AS 'Difference'
|
|||
|
|
FROM
|
|||
|
|
T_PRD_PICKMTRL tpp
|
|||
|
|
LEFT JOIN T_PRD_PICKMTRLDATA tppd ON tpp.FID= tppd.FID
|
|||
|
|
LEFT JOIN T_BD_MATERIAL tbm ON tbm.FMATERIALID = tppd.FMATERIALID
|
|||
|
|
LEFT JOIN T_STK_INVENTORY tsi ON tbm.FMASTERID = tsi.FMATERIALID
|
|||
|
|
AND tppd.FSTOCKID= tsi.FSTOCKID
|
|||
|
|
WHERE
|
|||
|
|
( tpp.FDOCUMENTSTATUS = 'A' OR tpp.FDOCUMENTSTATUS = 'Z' )
|
|||
|
|
AND tsi.FISEFFECTIVED= 1
|
|||
|
|
AND tsi.fstockstatusid = 10000
|
|||
|
|
AND FBASEQTY > 0 {inDBWhere}
|
|||
|
|
GROUP BY
|
|||
|
|
tbm.FUSEORGID,
|
|||
|
|
tbm.FMATERIALID,
|
|||
|
|
tbm.FMASTERID ";
|
|||
|
|
|
|||
|
|
DynamicObjectCollection actualQtylData = DBUtils.ExecuteDynamicObject(this.Context, $"/*dialect*/{selectActualQtySQL}");
|
|||
|
|
|
|||
|
|
StringBuilder msg = new StringBuilder();
|
|||
|
|
|
|||
|
|
var tempTockOrgId = this.View.Model.GetValue("FStockOrgId");
|
|||
|
|
|
|||
|
|
var stockOrgId = tempTockOrgId == null ? 0 : tempTockOrgId.Long2Int();
|
|||
|
|
|
|||
|
|
foreach (var entry in entrys)
|
|||
|
|
{
|
|||
|
|
var tempObject = entry["MaterialId"] as DynamicObject;
|
|||
|
|
|
|||
|
|
var tempEntity = actualQtylData.FirstOrDefault(w =>
|
|||
|
|
w["FMATERIALID"].Long2Int() == entry["MaterialId_Id"].Long2Int()
|
|||
|
|
&& w["FUSEORGID"].Long2Int() == stockOrgId);
|
|||
|
|
|
|||
|
|
if (tempEntity == null)
|
|||
|
|
msg.AppendLine($"物料编码:{tempObject["Number"]},物料名称:{tempObject["Name"]},可用库存:0;");
|
|||
|
|
else if (tempEntity != null && tempEntity["Difference"].Long2Int() > entry["MaterialId_Id"].Long2Int())
|
|||
|
|
msg.AppendLine($"物料编码:{tempObject["Number"]},物料名称:{tempObject["Name"]},可用库存:{tempEntity["Difference"]};");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (msg.Length > 0)
|
|||
|
|
this.View.ShowMessage(msg.ToString(), MessageBoxType.Error);
|
|||
|
|
|
|||
|
|
return msg.Length > 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|