a
This commit is contained in:
165
14.宝锐/GZ.LJY000.Biori/STK_TransferDirect/BillEventPlugInEx.cs
Normal file
165
14.宝锐/GZ.LJY000.Biori/STK_TransferDirect/BillEventPlugInEx.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using Kingdee.BOS.Core.DynamicForm;
|
||||
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
||||
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
||||
using Kingdee.BOS.Core.List;
|
||||
using Kingdee.BOS.Core.Metadata.EntityElement;
|
||||
using Kingdee.BOS.Orm.DataEntity;
|
||||
using Kingdee.BOS.Util;
|
||||
using Kingdee.K3.Core.Mobile.Utils;
|
||||
using Kingdee.K3.SCM.Business;
|
||||
using Kingdee.K3.SCM.Core.SAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace GZ.LJY000.Biori.STK_TransferDirect
|
||||
{
|
||||
[HotUpdate, Description("直接调拨单表单插件")]
|
||||
public class BillEventPlugInEx : AbstractDynamicFormPlugIn
|
||||
{
|
||||
|
||||
public override void BeforeUpdateValue(BeforeUpdateValueEventArgs e)
|
||||
{
|
||||
base.BeforeUpdateValue(e);
|
||||
}
|
||||
|
||||
public override void EntryBarItemClick(BarItemClickEventArgs e)
|
||||
{
|
||||
base.EntryBarItemClick(e);
|
||||
|
||||
if (e.BarItemKey.Equals("tbScanPack"))
|
||||
{
|
||||
var billShowParameter = new DynamicFormShowParameter();
|
||||
if (this.Context.DBId.Equals("6735f10547df64"))
|
||||
billShowParameter.FormId = "k474702e8884e43a3b11c235d9d430f5d";
|
||||
else
|
||||
billShowParameter.FormId = "UHIK_ScanGetPack";
|
||||
|
||||
billShowParameter.ParentPageId = this.View.PageId;
|
||||
|
||||
var billObj = this.View.Model.DataObject;
|
||||
var billId = billObj["Id"].ToString();
|
||||
var entity = billObj["TransferDirectEntry"] as DynamicObjectCollection;
|
||||
|
||||
this.View.ShowForm(billShowParameter, (result) =>
|
||||
{
|
||||
if (result != null)
|
||||
{
|
||||
if (entity != null && entity.Any())
|
||||
{
|
||||
var rows = result.ReturnData as DynamicObjectCollection;
|
||||
foreach (var item in entity)
|
||||
{
|
||||
//var row = rows.FirstOrDefault(w => w["FRowId"].ToString() == item["RowId"].ToString());
|
||||
var row = rows.FirstOrDefault(w => w["FMaterialID_Id"].Long2Int() == item["MaterialID_Id"].Long2Int());
|
||||
|
||||
if (row != null)
|
||||
{
|
||||
item["FPackBillNo"] = row["FBILLNO"].ToString();
|
||||
item["FPackBillSeq"] = row["FBILLSEQ"].Long2Int();
|
||||
item["FPackBillEntryId"] = row["FBILLENTRYID"].Long2Int();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var rows = result.ReturnData as DynamicObjectCollection;
|
||||
var parentRowIdxs = new List<int>();
|
||||
foreach (var row in rows)
|
||||
{
|
||||
var parentRowId = row["FParentRowId"].ToString();
|
||||
var rowId = row["FRowId"].ToString();
|
||||
|
||||
this.View.Model.CreateNewEntryRow("FBillEntry");
|
||||
int entryCurrentRowIndex = Model.GetEntryCurrentRowIndex("FBillEntry");
|
||||
|
||||
if (parentRowId.IsNullOrEmptyOrWhiteSpace())
|
||||
parentRowIdxs.Add(entryCurrentRowIndex);
|
||||
|
||||
this.View.Model.SetValue("FRowType", (parentRowId.IsNullOrEmptyOrWhiteSpace() ? "Parent" : "Son"), entryCurrentRowIndex);
|
||||
this.View.Model.SetItemValueByID("FMaterialId", row["FMaterialId_Id"], entryCurrentRowIndex);
|
||||
this.View.InvokeFieldUpdateService("FMaterialId", entryCurrentRowIndex);
|
||||
|
||||
this.View.Model.SetValue("FParentRowId", parentRowId, entryCurrentRowIndex);
|
||||
this.View.Model.SetValue("FRowId", rowId, entryCurrentRowIndex);
|
||||
this.View.Model.SetValue("FQty", row["FQty"], entryCurrentRowIndex);
|
||||
this.View.Model.SetValue("FPackBillNo", row["FBILLNO"], entryCurrentRowIndex);
|
||||
this.View.Model.SetValue("FPackBillSeq", row["FBILLSEQ"], entryCurrentRowIndex);
|
||||
this.View.Model.SetValue("FPackBillEntryId", row["FBILLENTRYID"], entryCurrentRowIndex);
|
||||
}
|
||||
|
||||
if (parentRowIdxs.Any())
|
||||
{
|
||||
foreach (var idx in parentRowIdxs)
|
||||
{
|
||||
this.View.InvokeFieldUpdateService("FQty", idx);
|
||||
}
|
||||
}
|
||||
//GetBOMExpandResult();
|
||||
}
|
||||
}
|
||||
|
||||
this.View.UpdateView("FEntity");
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 调用生产接口获取套件展开数据包,FDemandOrgId 需求组织,FSUPPLYORGID 供应组织
|
||||
/// </summary>
|
||||
/// <param name="sCurrRowId"></param>
|
||||
/// <returns></returns>
|
||||
private DynamicObjectCollection GetBOMExpandResult(string sCurrRowId = "")
|
||||
{
|
||||
//提前保证所有套件父项行,行标识FRowId必须有值(有可能下推的单据没有值)
|
||||
CheckRowIDValueForParentEntry();
|
||||
|
||||
DynamicObjectCollection dycExpandResult = null;
|
||||
ProductBomExpandArgs pbeArgs = new ProductBomExpandArgs("FDemandOrgId", "FSUPPLYORGID", "FRowType", "FRowId", "FParentRowId", "FParentMatId",
|
||||
"FMaterialId", "FBomId", "FBaseUnitId", "FStockBaseQty", "FMaterialId", "FUnitId", "FQty"
|
||||
);
|
||||
ProductBomExpand pbe = new ProductBomExpand(this.Context, this.View.BusinessInfo.GetForm().Id, this.View.BusinessInfo, this.View.Model.DataObject);
|
||||
if (!sCurrRowId.IsNullOrEmptyOrWhiteSpace())
|
||||
{
|
||||
dycExpandResult = pbe.GetProductBomExpandResult(pbeArgs, sCurrRowId);
|
||||
}
|
||||
else
|
||||
{
|
||||
//首次展开或者重复执行全部展开操作
|
||||
dycExpandResult = pbe.GetProductBomExpandResult(pbeArgs);
|
||||
}
|
||||
return dycExpandResult;
|
||||
|
||||
}
|
||||
|
||||
//提前保证所有套件父项行,行标识FRowId必须有值(有可能下推的单据没有值)
|
||||
private void CheckRowIDValueForParentEntry()
|
||||
{
|
||||
|
||||
Entity entryEntity = this.View.BusinessInfo.GetEntity("FBillEntry");
|
||||
this.View.Model.ClearNoDataRow();
|
||||
DynamicObjectCollection dycEntryList = this.View.Model.GetEntityDataObject(entryEntity);
|
||||
if (dycEntryList == null || dycEntryList.Count < 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string sRowType = "";
|
||||
string sRowId = "";
|
||||
foreach (DynamicObject dyItem in dycEntryList)
|
||||
{
|
||||
sRowType = Convert.ToString(dyItem["RowType"]);
|
||||
sRowId = Convert.ToString(dyItem["RowId"]);
|
||||
if (sRowType.EqualsIgnoreCase("Parent") && sRowId.IsNullOrEmptyOrWhiteSpace())
|
||||
{
|
||||
dyItem["RowId"] = SequentialGuid.NewGuid().ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
using Kingdee.BOS.App.Data;
|
||||
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
|
||||
using Kingdee.BOS.Core.DynamicForm.PlugIn;
|
||||
using Kingdee.BOS.Orm.DataEntity;
|
||||
using Kingdee.BOS.Util;
|
||||
using Kingdee.K3.BD.NewCode.Core.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace GZ.LJY000.Biori.STK_TransferDirect
|
||||
{
|
||||
[HotUpdate, Description("直接调拨单服务操作插件")]
|
||||
public class OperationEventPlugInEx : AbstractOperationServicePlugIn
|
||||
{
|
||||
public override void OnPreparePropertys(PreparePropertysEventArgs e)
|
||||
{
|
||||
base.OnPreparePropertys(e);
|
||||
|
||||
e.FieldKeys.Add("FToWorkShop");
|
||||
e.FieldKeys.Add("FRowType");
|
||||
e.FieldKeys.Add("FPackBillNo");
|
||||
e.FieldKeys.Add("FPackBillSeq");
|
||||
e.FieldKeys.Add("FPackBillEntryId");
|
||||
e.FieldKeys.Add("FQty");
|
||||
}
|
||||
|
||||
public override void OnAddValidators(AddValidatorsEventArgs e)
|
||||
{
|
||||
base.OnAddValidators(e);
|
||||
if (this.FormOperation.OperationId == 1)
|
||||
{
|
||||
|
||||
//添加检查校验器:
|
||||
var validator = new VaildatorEventPlugInEx();//新增的校验器
|
||||
validator.EntityKey = "FEntity";
|
||||
e.Validators.Add(validator);//添加校验器
|
||||
}
|
||||
}
|
||||
|
||||
public override void EndOperationTransaction(EndOperationTransactionArgs e)
|
||||
{
|
||||
base.EndOperationTransaction(e);
|
||||
//保存8 提交9 审核1 反审核26 删除3
|
||||
if (this.FormOperation.OperationId == 1)
|
||||
{
|
||||
DoComputePackgeQty(e.DataEntitys, false);
|
||||
}
|
||||
else if (this.FormOperation.OperationId == 26)
|
||||
{
|
||||
DoComputePackgeQty(e.DataEntitys, true);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dataEntitys"></param>
|
||||
/// <param name="isInStock"></param>
|
||||
private void DoComputePackgeQty(DynamicObject[] dataEntitys, bool isInStock)
|
||||
{
|
||||
var dataEntityList = new List<DynamicObject>();
|
||||
var sqlL = new List<string>();
|
||||
foreach (var data in dataEntitys)
|
||||
{
|
||||
var toWorkShop = data["FToWorkShop"].Long2Int();
|
||||
foreach (var item in data["TransferDirectEntry"] as DynamicObjectCollection)
|
||||
{
|
||||
var packBillNo = item["FPackBillNo"];
|
||||
var rowType = item["RowType"].ToString();
|
||||
if (!packBillNo.IsNullOrEmpty() && rowType.Equals("Parent") && toWorkShop == 1)
|
||||
{
|
||||
sqlL.Add($" SELECT '{packBillNo}' AS FBILLNO , {item["Qty"]} AS QTY ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isInStock)
|
||||
DoComputePackgeInStockQty(sqlL);
|
||||
else
|
||||
DoComputePackgeOutStockQty(sqlL);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 入库操作
|
||||
/// </summary>
|
||||
/// <param name="sqlL"></param>
|
||||
private void DoComputePackgeInStockQty(List<string> sqlL)
|
||||
{
|
||||
if (sqlL.Any())
|
||||
{
|
||||
var updSqlL = $@"/*dialect*/
|
||||
|
||||
WITH #基础数据 AS (
|
||||
{string.Join(" UNION ALL ", sqlL)}
|
||||
)
|
||||
UPDATE t0 SET t0.FQTY = t0.FQTY + t1.QTY
|
||||
,t0.FOUTSTOCKQTY = t0.FOUTSTOCKQTY - t1.QTY
|
||||
FROM T_PRD_PACKAGEINSTOCK t0
|
||||
INNER JOIN #基础数据 t1 on t1.FBILLNO = t0.FBILLNO
|
||||
WHERE 1 = 1
|
||||
AND t0.FDOCUMENTSTATUS = 'C'
|
||||
|
||||
";
|
||||
|
||||
//更新组装单信
|
||||
var resData = DBUtils.Execute(this.Context, updSqlL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 出库操作
|
||||
/// </summary>
|
||||
/// <param name="dataEntitys"></param>
|
||||
private void DoComputePackgeOutStockQty(List<string> sqlL)
|
||||
{
|
||||
if (sqlL.Any())
|
||||
{
|
||||
var updSqlL = $@"/*dialect*/
|
||||
|
||||
WITH #基础数据 AS (
|
||||
{string.Join(" UNION ALL ", sqlL)}
|
||||
)
|
||||
UPDATE t0 SET t0.FQTY = t0.FQTY - t1.QTY
|
||||
,t0.FOUTSTOCKQTY = t0.FOUTSTOCKQTY + t1.QTY
|
||||
FROM T_PRD_PACKAGEINSTOCK t0
|
||||
INNER JOIN #基础数据 t1 on t1.FBILLNO = t0.FBILLNO
|
||||
WHERE 1 = 1
|
||||
AND t0.FDOCUMENTSTATUS = 'C'
|
||||
AND (t0.FQTY - t1.QTY) >= 0
|
||||
|
||||
";
|
||||
|
||||
//更新组装单信
|
||||
var resData = DBUtils.Execute(this.Context, updSqlL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
using Kingdee.BOS.Core.DynamicForm;
|
||||
using Kingdee.BOS.Core.Validation;
|
||||
using Kingdee.BOS.Core;
|
||||
using Kingdee.K3.BD.NewCode.Core.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Kingdee.BOS;
|
||||
using Kingdee.BOS.Orm.DataEntity;
|
||||
using Kingdee.BOS.Util;
|
||||
using Kingdee.BOS.ServiceHelper;
|
||||
|
||||
namespace GZ.LJY000.Biori.STK_TransferDirect
|
||||
{
|
||||
/// <summary>
|
||||
/// 直接调拨单审核时校验对应组装单是否有足够数量
|
||||
/// </summary>
|
||||
[Description("直接调拨单审核时校验对应组装单是否有足够数量")]
|
||||
public class VaildatorEventPlugInEx : AbstractValidator
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="dataEntities"></param>
|
||||
/// <param name="validateContext"></param>
|
||||
/// <param name="ctx"></param>
|
||||
public override void Validate(ExtendedDataEntity[] dataEntities, ValidateContext validateContext, Context ctx)
|
||||
{
|
||||
IOperationResult opResult = new OperationResult();
|
||||
|
||||
var dataEntityList = new List<DynamicObject>();
|
||||
var sqlL = new List<string>();
|
||||
foreach (var data in dataEntities)
|
||||
{
|
||||
var item = data.DataEntity;
|
||||
var packBillNo = item["FPackBillNo"].ToString();
|
||||
var rowType = item["RowType"].ToString();
|
||||
if (!packBillNo.IsNullOrEmpty() && rowType.Equals("Parent"))
|
||||
{
|
||||
sqlL.Add($" SELECT '{packBillNo}' AS FBILLNO , {item["RealQty"]} AS QTY ");
|
||||
}
|
||||
}
|
||||
|
||||
if (sqlL.Any())
|
||||
{
|
||||
var selectSql = $@"/*dialect*/
|
||||
WITH #基础数据 AS (
|
||||
{string.Join(" UNION ALL ", sqlL)}
|
||||
)
|
||||
SELECT t0.FBILLNO,t0.FMATERIALID,t0.FQTY,t0.FINSTOCKQTY,t0.FNOINSTOCKQTY,t0.FOUTSTOCKQTY
|
||||
,t0.FQTY - t1.QTY AS 'surplusQty'
|
||||
FROM T_PRD_PACKAGEINSTOCK t0
|
||||
INNER JOIN #基础数据 t1 on t1.FBILLNO = t0.FBILLNO
|
||||
WHERE 1 = 1
|
||||
AND t0.FDOCUMENTSTATUS = 'C'
|
||||
|
||||
";
|
||||
|
||||
var dataList = DBServiceHelper.ExecuteDynamicObject(this.Context, selectSql);
|
||||
if (dataList != null && dataList.Any())
|
||||
{
|
||||
foreach (var data in dataEntities)
|
||||
{
|
||||
var item = data.DataEntity;
|
||||
var packBillNo = item["FPackBillNo"].ToString();
|
||||
var rowType = item["RowType"].ToString();
|
||||
if (!packBillNo.IsNullOrEmpty() && rowType.Equals("Parent"))
|
||||
{
|
||||
var res = dataList.FirstOrDefault(w => w["FBILLNO"].ToString() == packBillNo);
|
||||
if (res != null)
|
||||
{
|
||||
var surplusQty = Convert.ToDecimal(res["surplusQty"]);
|
||||
if (surplusQty < 0)
|
||||
{
|
||||
ValidatorUnique(validateContext, data, data.DataEntity["Id"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="validateContext"></param>
|
||||
/// <param name="entity"></param>
|
||||
/// <param name="id"></param>
|
||||
private void ValidatorUnique(ValidateContext validateContext, ExtendedDataEntity entity, string id)
|
||||
{
|
||||
//添加校验的错误信息
|
||||
validateContext.AddError(entity,
|
||||
new ValidationErrorInfo(
|
||||
"RealQty", // 出错的字段Key,可以空
|
||||
id, // 数据包内码,必填,后续操作会据此内码避开此数据包
|
||||
entity.DataEntityIndex, // 出错的数据包在全部数据包中的顺序
|
||||
0, // 出错的数据行在全部数据行中的顺序,如果校验基于单据头,此为0
|
||||
"REF", // 错误编码,可以任意设定一个字符,主要用于追查错误来源
|
||||
$"对应组装单可出库数量不足!", // 错误的详细提示信息
|
||||
$"对应组装单可出库数量不足!", // 错误的简明提示信息
|
||||
ErrorLevel.Error)); // 错误级别:警告、错误...
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user