7.6版本以下锁库和解锁二开示例
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.K3.Core.SCM.STK;
using Kingdee.K3.SCM.ServiceHelper;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DependencyRules;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Resource;
using Kingdee.BOS.ServiceHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
using Kingdee.BOS.App.Data;
using Kingdee.BOS;
namespace HCK
{
[Description("发货通知单创建预留锁库")]
public class SaveLockInfo : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
{
e.FieldKeys.Add("FID");
base.OnPreparePropertys(e);
}
public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
{
base.AfterExecuteOperationTransaction(e);
foreach (DynamicObject items in e.DataEntitys)
{
int FID = 0;
decimal FQTY = 0;
decimal FBASEAVBQTY = 0;
string fresult = "", FMATERIALID = "", FSHIPMENTSTOCKID = "", fseq = "";
if (items["Id"] != null)
{
FID = Convert.ToInt32(items["Id"]);
}
string SQL0 = "/*dialect*/" + string.Format(@" SELECT t1.fseq,t1.FMATERIALID,t1.FSHIPMENTSTOCKID,T1.FQTY FROM T_SAL_DELIVERYNOTICE t
left join T_SAL_DELIVERYNOTICEENTRY t1 on t.FID=t1.FID
where t.FID=" + FID + " and t1.FSHIPMENTSTOCKID=242404");
DynamicObjectCollection DynamData0 = DBUtils.ExecuteDynamicObject(this.Context, SQL0);
DynamicObjectCollection DynamData1 = DBUtils.ExecuteDynamicObject(this.Context, SQL0);
//判断是否满足可用量,可用量=库存量-预留数量
if (DynamData1.Count > 0)
{
for (int y = 0; y < DynamData1.Count; y++)
{
FMATERIALID = Convert.ToString(DynamData1[y]["FMATERIALID"]);
FSHIPMENTSTOCKID = Convert.ToString(DynamData1[y]["FSHIPMENTSTOCKID"]);
FQTY = Convert.ToDecimal(DynamData1[y]["FQTY"]);
fseq = Convert.ToString(DynamData1[y]["fseq"]);
string SQL2 = "/*dialect*/" + string.Format(@" select
case when (select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)>0 then (T.FBASEQTY-(select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)) else T.FBASEQTY end FBASEAVBQTY,
T.FSTOCKORGID StockOrgId,
T.FMATERIALID MaterialId,
T.FSTOCKID StockId into #A
from T_STK_INVENTORY T
where t.FMATERIALID='" + FMATERIALID + "' and t.FSTOCKID=" + FSHIPMENTSTOCKID + " " +
"order by T.FMATERIALID,T.FSTOCKID " +
"SELECT SUM(FBASEAVBQTY)FBASEAVBQTY,StockOrgId,MaterialId,StockId FROM #A " +
"GROUP BY StockOrgId,MaterialId,StockId");
DynamicObjectCollection DynamData2 = DBUtils.ExecuteDynamicObject(this.Context, SQL2);
if (DynamData2.Count > 0)
{
for (int x = 0; x < DynamData2.Count; x++)
{
FBASEAVBQTY = Convert.ToDecimal(DynamData2[x]["FBASEAVBQTY"]);
if (FBASEAVBQTY < FQTY)
{
throw new KDBusinessException("500", "第" + fseq + "行物料可用量不足!,无法生成发货单。");
return;
}
}
}
}
}
if (DynamData0.Count > 0)
{
for (int i = 0; i < DynamData0.Count; i++)
{
FMATERIALID = Convert.ToString(DynamData0[i]["FMATERIALID"]);
FSHIPMENTSTOCKID = Convert.ToString(DynamData0[i]["FSHIPMENTSTOCKID"]);
FQTY = Convert.ToDecimal(DynamData0[i]["FQTY"]);
List<LockStockArgs> list = new List<LockStockArgs>();
string SQL = "/*dialect*/" + string.Format(@" select
T.FBASEQTY,
case when (select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)>0 then (T.FBASEQTY-(select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)) else T.FBASEQTY end FBASEAVBQTY,
T.FID InvDetailID,
T.FSTOCKORGID StockOrgId,
T.FMATERIALID MaterialId,
T1.FPLANMODE PlanMode,
T.FBOMID BomId,
T.FAuxPropId AuxPropId,
T.FLOT,
T2.FNUMBER FLOTNUMBER,
T.FMTONO MtoNo,
T.FPROJECTNO ProjectNo,
T.FPRODUCEDATE ProduceDate,
T.FEXPIRYDATE ExpiryDate,
T.FSTOCKID StockId,
T.FSTOCKLOCID StockLocId,
T.FSTOCKSTATUSID StockStatusId,
T.FOWNERTYPEID OwnerTypeId,
T.FOWNERID OwnerId,
T.FKEEPERTYPEID KeeperTypeId,
T.FKEEPERID KeeperId,
T.FSTOCKUNITID UnitID,
T.FBASEUNITID BaseUnitId,
T.FSECUNITID SecUnitId,
T.FLOCKQTY LockQty,
T.FBASELOCKQTY BaseLockQty,
T.FSECLOCKQTY SecLockQty
from T_STK_INVENTORY T
LEFT JOIN t_BD_MaterialPlan T1 ON T.FMATERIALID=T1.FMATERIALID
LEFT JOIN T_BD_LOTMASTER T2 ON T.FLOT=T2.FLOTID
where T.FSTOCKID='" + FSHIPMENTSTOCKID + "' AND T.FMATERIALID='" + FMATERIALID + "'");
DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
if (DynamData.Count > 0)
{
foreach (DynamicObject item in DynamData)
{
FBASEAVBQTY = Convert.ToDecimal(item["FBASEAVBQTY"]);
if (FQTY <= FBASEAVBQTY)
{
list.Add(GetSubData(item, FQTY));
break;
}
if (FQTY > FBASEAVBQTY)
{
list.Add(GetSubData(item, FBASEAVBQTY));
FQTY = FQTY - FBASEAVBQTY;
}
}
}
var result = StockServiceHelper.SaveLockInfo(base.Context, list);
if (result.Count > 0)
{
fresult = result[0]["fresult"].ToString();
throw new KDBusinessException("500", fresult);
}
}
}
}
}
private LockStockArgs GetSubData(DynamicObject materialObj, decimal FQTY)
{
LockStockArgs lockStockArgs = new LockStockArgs();
lockStockArgs.ObjectId = "STK_Inventory";//单据对象内码
lockStockArgs.BillId = materialObj["InvDetailID"].ToString();//单据内码
lockStockArgs.BillDetailID = "";//单据明细内码
lockStockArgs.FInvDetailID = materialObj["InvDetailID"].ToString();//即时库存明细内码
lockStockArgs.StockOrgID = Convert.ToInt64(materialObj["StockOrgId"]);//库存组织
lockStockArgs.DemandOrgId = lockStockArgs.StockOrgID;//需求组织内码
lockStockArgs.MaterialID = Convert.ToInt64(materialObj["MaterialID"]);//物料内码
lockStockArgs.DemandMaterialId = lockStockArgs.MaterialID;//需求物料内码
lockStockArgs.DemandDateTime = null;//需求日期
lockStockArgs.DemandPriority = "";//需求优先级
if (materialObj["PlanMode"] != null && materialObj["PlanMode"].ToString() == "1")
{
lockStockArgs.IsMto = "1";//是否MTO
}
lockStockArgs.BOMID = Convert.ToInt64(materialObj["BomID"]);//BomID
lockStockArgs.AuxPropId = Convert.ToInt64(materialObj["AuxPropId"]);//辅助属性
if (materialObj["FLOT"] != null && Convert.ToInt64(materialObj["FLOT"]) > 0)
{
lockStockArgs.Lot = Convert.ToInt64(materialObj["FLOT"]);////批号内码
lockStockArgs.LotNo = Convert.ToString(materialObj["FLOTNUMBER"]);//批号编码
}
lockStockArgs.MtoNo = materialObj["MtoNo"].ToString();//MTO号
lockStockArgs.ProjectNo = materialObj["ProjectNo"].ToString();//计划跟踪号
if (materialObj["ProduceDate"] != null)
{
lockStockArgs.ProduceDate = DateTime.Parse(materialObj["ProduceDate"].ToString());//生成日期
}
if (materialObj["ExpiryDate"] != null)
{
lockStockArgs.ExpiryDate = DateTime.Parse(materialObj["ExpiryDate"].ToString());//有效期
}
lockStockArgs.STOCKID = Convert.ToInt64(materialObj["StockId"]);//仓库内码
lockStockArgs.StockLocID = Convert.ToInt64(materialObj["StockLocID"]);//仓位内码
lockStockArgs.StockStatusID = Convert.ToInt64(materialObj["StockStatusID"]);//仓库状态
lockStockArgs.OwnerTypeID = materialObj["OwnerTypeId"].ToString();//货主类型
lockStockArgs.OwnerID = Convert.ToInt64(materialObj["OwnerID"]);//货主
lockStockArgs.KeeperTypeID = materialObj["KeeperTypeId"].ToString();//保管者类型
lockStockArgs.KeeperID = Convert.ToInt64(materialObj["KeeperID"]);//保管者
lockStockArgs.UnitID = Convert.ToInt64(materialObj["UnitID"]);//库存单位
lockStockArgs.BaseUnitID = Convert.ToInt64(materialObj["BaseUnitID"]);//基本单位
lockStockArgs.SecUnitID = Convert.ToInt64(materialObj["SecUnitID"]);//辅助单位
//lockStockArgs.LockQty = decimal.Parse(materialObj["LockQty"].ToString());//锁库数量
//lockStockArgs.LockBaseQty = decimal.Parse(materialObj["BaseLockQty"].ToString());//锁库数量(基本)
//lockStockArgs.LockSecQty = decimal.Parse(materialObj["SecLockQty"].ToString());//锁库数量(辅助)
lockStockArgs.LockQty = FQTY;//锁库数量
lockStockArgs.LockBaseQty = FQTY;//锁库数量(基本)
lockStockArgs.LockSecQty = 0;//锁库数量(辅助)
//object obj2 = materialObj["ReserveDate"];
//if (obj2 != null && !string.IsNullOrWhiteSpace(obj2.ToString()))
//{
lockStockArgs.ReserveDate = DateTime.Now;//锁库日期
//}
//lockStockArgs.ReserveDays = Convert.ToInt32(materialObj["ReserveDays"]);//锁库天数
//obj2 = materialObj["ReleaseDate"];
//if (obj2 != null && !string.IsNullOrWhiteSpace(obj2.ToString()))
//{
// lockStockArgs.ReLeaseDate = DateTime.Parse(obj2.ToString());//预计解锁日期
//}
//lockStockArgs.SupplyNote = Convert.ToString(materialObj["SupplyNote"]);//供应备注
//lockStockArgs.RequestNote = lockStockArgs.SupplyNote;//需求备注
return lockStockArgs;
}
private long GetDynamicValue(DynamicObject obj)
{
if (obj == null)
{
return 0L;
}
if (obj.DynamicObjectType.Properties.ContainsKey(FormConst.MASTER_ID))
{
return Convert.ToInt64(obj[FormConst.MASTER_ID]);
}
if (obj.DynamicObjectType.Properties.ContainsKey("Id"))
{
return Convert.ToInt64(obj["Id"]);
}
return 0L;
}
}
[Description("发货通知单释放预留")]
public class SaveUnLockInfo : AbstractOperationServicePlugIn
{
public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
{
e.FieldKeys.Add("FID");
base.OnPreparePropertys(e);
}
public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
{
base.AfterExecuteOperationTransaction(e);
foreach (DynamicObject items in e.DataEntitys)
{
int FID = 0;
decimal FQTY = 0;
decimal FBASEAVBQTY = 0;
decimal FBASEDEMANDQTY = 0;
string fresult = "", FMATERIALID = "", FSHIPMENTSTOCKID = "", fseq = "";
if (items["Id"] != null)
{
FID = Convert.ToInt32(items["Id"]);
}
string SQL0 = "/*dialect*/" + string.Format(@" SELECT t1.fseq,t1.FMATERIALID,t1.FSHIPMENTSTOCKID,T1.FQTY FROM T_SAL_DELIVERYNOTICE t
left join T_SAL_DELIVERYNOTICEENTRY t1 on t.FID=t1.FID
where t.FID=" + FID + " and t1.FSHIPMENTSTOCKID=242404");
DynamicObjectCollection DynamData0 = DBUtils.ExecuteDynamicObject(this.Context, SQL0);
DynamicObjectCollection DynamData1 = DBUtils.ExecuteDynamicObject(this.Context, SQL0);
//判断是否满足可用量,可用量=库存量-预留数量
if (DynamData1.Count > 0)
{
for (int y = 0; y < DynamData1.Count; y++)
{
FMATERIALID = Convert.ToString(DynamData1[y]["FMATERIALID"]);
FSHIPMENTSTOCKID = Convert.ToString(DynamData1[y]["FSHIPMENTSTOCKID"]);
FQTY = Convert.ToDecimal(DynamData1[y]["FQTY"]);
fseq = Convert.ToString(DynamData1[y]["fseq"]);
string SQL2 = "/*dialect*/" + string.Format(@" select
case when (select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)>0 then (T.FBASEQTY-(select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)) else T.FBASEQTY end FBASEAVBQTY,
T.FSTOCKORGID StockOrgId,
T.FMATERIALID MaterialId,
T.FSTOCKID StockId into #A
from T_STK_INVENTORY T
where t.FMATERIALID='" + FMATERIALID + "' and t.FSTOCKID=" + FSHIPMENTSTOCKID + " " +
"order by T.FMATERIALID,T.FSTOCKID " +
"SELECT SUM(FBASEAVBQTY)FBASEAVBQTY,StockOrgId,MaterialId,StockId FROM #A " +
"GROUP BY StockOrgId,MaterialId,StockId");
DynamicObjectCollection DynamData2 = DBUtils.ExecuteDynamicObject(this.Context, SQL2);
if (DynamData2.Count > 0)
{
for (int x = 0; x < DynamData2.Count; x++)
{
FBASEAVBQTY = Convert.ToDecimal(DynamData2[x]["FBASEAVBQTY"]);
if (FBASEAVBQTY < FQTY)
{
throw new KDBusinessException("500", "第" + fseq + "行物料可用量不足!,无法生成发货单。");
return;
}
}
}
}
}
if (DynamData0.Count > 0)
{
for (int i = 0; i < DynamData0.Count; i++)
{
FMATERIALID = Convert.ToString(DynamData0[i]["FMATERIALID"]);
FSHIPMENTSTOCKID = Convert.ToString(DynamData0[i]["FSHIPMENTSTOCKID"]);
FQTY = Convert.ToDecimal(DynamData0[i]["FQTY"]);
List<LockStockArgs> list = new List<LockStockArgs>();
string SQL = "/*dialect*/" + string.Format(@" select
T4.FEntryID,
T3.FBASEDEMANDQTY,
T.FBASEQTY,
case when (select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)>0 then (T.FBASEQTY-(select FBASEDEMANDQTY from T_PLN_RESERVELINK where FSRCINTERID=T.FID)) else T.FBASEQTY end FBASEAVBQTY,
T.FID InvDetailID
--T.FSTOCKORGID StockOrgId,
--T.FMATERIALID MaterialId,
--T1.FPLANMODE PlanMode,
--T.FBOMID BomId,
--T.FAuxPropId AuxPropId,
--T.FLOT,
--T2.FNUMBER FLOTNUMBER,
--T.FMTONO MtoNo,
--T.FPROJECTNO ProjectNo,
--T.FPRODUCEDATE ProduceDate,
--T.FEXPIRYDATE ExpiryDate,
--T.FSTOCKID StockId,
--T.FSTOCKLOCID StockLocId,
--T.FSTOCKSTATUSID StockStatusId,
--T.FOWNERTYPEID OwnerTypeId,
--T.FOWNERID OwnerId,
--T.FKEEPERTYPEID KeeperTypeId,
--T.FKEEPERID KeeperId,
--T.FSTOCKUNITID UnitID,
--T.FBASEUNITID BaseUnitId,
--T.FSECUNITID SecUnitId,
--T.FLOCKQTY LockQty,
--T.FBASELOCKQTY BaseLockQty,
--T.FSECLOCKQTY SecLockQty
from T_STK_INVENTORY T
LEFT JOIN t_BD_MaterialPlan T1 ON T.FMATERIALID=T1.FMATERIALID
LEFT JOIN T_BD_LOTMASTER T2 ON T.FLOT=T2.FLOTID
LEFT JOIN T_PLN_RESERVELINK T3 ON T.FID=T3.FDEMANDINTERID
LEFT JOIN T_PLN_RESERVELINKENTRY T4 ON T3.FID=T4.FID
where T.FSTOCKID='" + FSHIPMENTSTOCKID + "' AND T.FMATERIALID='" + FMATERIALID + "'");
DynamicObjectCollection DynamData = DBUtils.ExecuteDynamicObject(this.Context, SQL);
if (DynamData.Count > 0)
{
foreach (DynamicObject item in DynamData)
{
FBASEAVBQTY = Convert.ToDecimal(item["FBASEAVBQTY"]);
FBASEDEMANDQTY = Convert.ToDecimal(item["FBASEDEMANDQTY"]);
if (FQTY <= FBASEDEMANDQTY)
{
list.Add(GetSubData(item, FQTY));
break;
}
if (FQTY > FBASEDEMANDQTY)
{
list.Add(GetSubData(item, FBASEDEMANDQTY));
FQTY = FQTY - FBASEDEMANDQTY;
}
}
}
StockServiceHelper.SaveUnLockInfo(base.Context, list);
//if (result.Count > 0)
//{
// fresult = result[0]["fresult"].ToString();
// throw new KDBusinessException("500", fresult);
//}
}
}
}
}
private LockStockArgs GetSubData(DynamicObject materialObj, decimal FQTY)
{
LockStockArgs lockStockArgs = new LockStockArgs();
lockStockArgs.FEntryID = Convert.ToInt64(materialObj["FEntryID"]);
lockStockArgs.FInvDetailID = materialObj["InvDetailID"].ToString();
lockStockArgs.BillDetailID = "";
lockStockArgs.BillNo = "";
//lockStockArgs.BillSEQ = "";
//DynamicObject dynamicObject = item["Lot"] as DynamicObject;
//lockStockArgs.Lot = GetDynamicValue(dynamicObject);
lockStockArgs.LockQty = FQTY;
lockStockArgs.UnLockQty = FQTY;
lockStockArgs.LockBaseQty = FQTY;
lockStockArgs.UnLockBaseQty = FQTY;
lockStockArgs.LockSecQty = 0;
lockStockArgs.UnLockSecQty = 0;
//lockStockArgs.ReserveDate = DateTime.Parse(item["ReserveDate"].ToString());
//lockStockArgs.ReserveDays = Convert.ToInt32(item["ReserveDays"]);
lockStockArgs.ReLeaseDate = DateTime.Now;
lockStockArgs.UnLockNote = "";
return lockStockArgs;
}
private long GetDynamicValue(DynamicObject obj)
{
if (obj == null)
{
return 0L;
}
if (obj.DynamicObjectType.Properties.ContainsKey(FormConst.MASTER_ID))
{
return Convert.ToInt64(obj[FormConst.MASTER_ID]);
}
if (obj.DynamicObjectType.Properties.ContainsKey("Id"))
{
return Convert.ToInt64(obj["Id"]);
}
return 0L;
}
}
}
老师好!用你的这个方法成功预留之后,预留查询查不到信息,并且下游出库单审核之后,无法自动清除预留,怎么解决这个问题??
7.6版本以下锁库和解锁二开示例
本文2024-09-16 17:42:51发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-17479.html