@ -252,160 +252,159 @@ namespace ICSSoft.DataProject
}
}
#endregion
#endregion
#region 成品(生产)入库,倒冲
#region 成品(生产)入库,倒冲
if ( BusinessCode . Equals ( TransTypeEnum . ManufactureReceiveDoc . GetDescription < DBValue > ( ) ) )
{
#region sql
sql = @ "-- 1.创建临时表 初始单据数据 maintemp
SELECT
c . MOCode AS TransCode ,
a . MODetailID AS DetailID ,
a . InvCode ,
b . InvName ,
b . InvStd ,
a . ParentQuantity / c . Quantity * { 2 } AS Quantity ,
a . Amount ,
a . Sequence AS TransSequence ,
a . IssueQuantity ,
c . Sequence ,
inv . InvUnit ,
0 AS LocationQty ,
inv . AmountUnit ,
a . ExtensionID ,
a . WorkPoint ,
ext . ProjectCode ,
CASE WHEN ISNULL ( inv . BatchEnable , '0' ) = '1' THEN ext . BatchCode ELSE ' ' END AS BatchCode ,
ext . Version ,
ext . Brand ,
ext . cFree1 ,
ext . cFree2 ,
ext . cFree3 ,
ext . cFree4 ,
ext . cFree5 ,
ext . cFree6 ,
ext . cFree7 ,
ext . cFree8 ,
ext . cFree9 ,
ext . cFree10
INTO # maintemp
//if (BusinessCode.Equals(TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>()))
//{
// #region sql
// sql = @ "-- 1.创建临时表 初始单据数据 maintemp
// SELECT
// c .MOCode AS TransCode,
// a .MODetailID AS DetailID,
// a .InvCode,
// b.InvName,
// b.InvStd,
// a .ParentQuantity/c .Quantity*{2} AS Quantity,
// a .Amount,
// a .Sequence AS TransSequence,
// a .IssueQuantity,
// c .Sequence,
// inv.InvUnit,
// 0 AS LocationQty,
// inv.AmountUnit,
// a .ExtensionID,
// a .WorkPoint,
// ext.ProjectCode,
// CASE WHEN ISNULL(inv.BatchEnable, '0')= '1' THEN ext.BatchCode ELSE '' END AS BatchCode,
// ext.Version,
// ext.Brand,
// ext.cFree1,
// ext.cFree2,
// ext.cFree3,
// ext.cFree4,
// ext.cFree5,
// ext.cFree6,
// ext.cFree7,
// ext.cFree8,
// ext.cFree9,
// ext.cFree10
// INTO #maintemp
FROM
ICSMOPick a
inner join ICSMO c on a . MODetailID = c . MODetailID and a . WorkPoint = c . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
INNER JOIN ICSExtension ext ON a . ExtensionID = ext . ID AND a . WorkPoint = ext . WorkPoint
INNER JOIN ICSInventory inv ON a . InvCode = inv . InvCode AND a . WorkPoint = inv . WorkPoint
INNER JOIN (
SELECT a . MOCode , a . Sequence , a . WorkPoint
FROM ICSMO a
INNER JOIN ICSInventoryLotDetail b ON b . TransCode = a . MOCode AND b . TransSequence = a . Sequence AND b . WorkPoint = a . WorkPoint
INNER JOIN ICSInventoryLot c ON c . LotNo = b . LotNo AND c . WorkPoint = b . WorkPoint
WHERE c . LotNo = ' { 0 } ' AND c . WorkPoint = ' { 1 } '
) temp ON c . MOCode = temp . MOCode AND a . WorkPoint = temp . WorkPoint AND c . Sequence = temp . Sequence
WHERE a . SupplyType = '1'
GROUP BY c . MOCode , a . Quantity , c . Quantity , a . InvCode , b . InvName , b . InvStd , a . WhCode , a . ExtensionID , a . WorkPoint , inv . BatchEnable , a . MODetailID , a . Amount , a . Sequence , a . IssueQuantity , inv . InvName , inv . InvCode , inv . InvUnit , inv . AmountUnit , c . Sequence ,
ext . ProjectCode , ext . BatchCode , ext . Version , ext . Brand , ext . cFree1 , ext . cFree2 , ext . cFree3 , ext . cFree4 , ext . cFree5 , ext . cFree6 , ext . cFree7 , ext . cFree8 , ext . cFree9 , ext . cFree10 ;
// FROM
// ICSMOPick a
// inner join ICSMO c on a.MODetailID=c .MODetailID and a .WorkPoint=c .WorkPoint
// LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a .WorkPoint= b.WorkPoint
// INNER JOIN ICSExtension ext ON a.ExtensionID= ext.ID AND a .WorkPoint= ext.WorkPoint
// INNER JOIN ICSInventory inv ON a.InvCode= inv.InvCode AND a .WorkPoint= inv.WorkPoint
// INNER JOIN (
// SELECT a .MOCode,a .Sequence,a .WorkPoint
// FROM ICSMO a
// INNER JOIN ICSInventoryLotDetail b ON b.TransCode=a .MOCode AND b.TransSequence=a .Sequence AND b.WorkPoint=a .WorkPoint
// INNER JOIN ICSInventoryLot c ON c.LotNo= b.LotNo AND c .WorkPoint= b.WorkPoint
// WHERE c .LotNo= '{0}' AND c .WorkPoint= '{1}'
// ) temp ON c .MOCode= temp.MOCode AND a.WorkPoint= temp.WorkPoint AND c .Sequence= temp.Sequence
// WHERE a .SupplyType= '1'
// GROUP BY c .MOCode,a .Quantity,c .Quantity,a .InvCode,b.InvName,b.InvStd,a .WhCode,a .ExtensionID,a .WorkPoint,inv.BatchEnable,a .MODetailID,a .Amount,a .Sequence,a .IssueQuantity,inv.InvName,inv.InvCode,inv.InvUnit,inv.AmountUnit,c .Sequence,
// ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10;
select * into # resulttemp from # maintemp
ALTER TABLE # resulttemp ADD LotNo VARCHAR ( 5 0 )
delete from # resulttemp
- - 2. 根 据 maintemp 中 的 物 料 信 息 查 出 库 存 中 对 应 的 条 码 信 息 barcodetemp
select a . lotno , a . invcode , ( a . quantity - a . lockQuantity ) as quantity , a . mtime into # barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
( select # maintemp . invcode from # maintemp group by # maintemp . InvCode ) b on a . invcode = b . invcode where a . Quantity - a . lockQuantity > 0 ORDER BY a . MTIME ASC
- - 3. 循 环 maintemp , 根 据 行 号 和 子 表 ID 向 最 终 结 果 集 中 写 入 数 据 ; barcodetemp 中 的 已 匹 配 数 据 删 除 或 更 新
BEGIN
DECLARE @transSequence int ; - - 当 前 循 环 的 行 号
DECLARE @qty int ; - - 条 码 表 数 量
DECLARE @needqty int ; - - 本 行 所 需 数 量
DECLARE @lotno VARCHAR ( 5 0 ) ; - - 条 码
DECLARE @DetailID VARCHAR ( 5 0 ) ; - - 本 行 所 在 工 单 行 ID
DECLARE tempCursor CURSOR FOR ( select transSequence , DetailID from # maintemp ) ; - - 创 建 游 标 tempCursor , 并 定 义 游 标 所 指 向 的 集 合
OPEN tempCursor ; - - 打 开 游 标
FETCH NEXT FROM tempCursor INTO @transSequence , @DetailID ; - - 游 标 读 取 下 一 个 数 据
WHILE @ @fetch_status = 0
BEGIN
select @needqty = Quantity from # maintemp where transSequence = @transSequence AND DetailID = @DetailID
PRINT @transSequence
WHILE @needqty > 0
BEGIN
select top 1 @qty = isnull ( quantity , 0 ) , @lotno = isnull ( lotno , ' ' ) from # barcodetemp a
RIGHT JOIN ( select invcode from # maintemp where transSequence = @transSequence AND DetailID = @DetailID ) b on a . invcode = b . invcode ORDER BY mtime
BEGIN
IF ( @needqty - @qty > = 0 and ISNULL ( @lotno , ' ' ) < > ' ' )
BEGIN
insert INTO # resulttemp ( lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
Amount , InvCode , InvName , InvStd , InvUnit , LocationQty , AmountUnit ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint )
SELECT @lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
ISNULL ( Amount , 0 ) , InvCode , InvName , ISNULL ( InvStd , ' ' ) , InvUnit , @qty , ISNULL ( AmountUnit , ' ' ) ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint from # maintemp
where # maintemp . transSequence = @transSequence AND DetailID = @DetailID
delete from # barcodetemp where lotno = @lotno
SET @needqty = @needqty - @qty
END
ELSE IF ( @needqty - @qty < 0 and ISNULL ( @lotno , ' ' ) < > ' ' )
BEGIN
insert INTO # resulttemp ( lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
Amount , InvCode , InvName , InvStd , InvUnit , LocationQty , AmountUnit ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint )
SELECT @lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
ISNULL ( Amount , 0 ) , InvCode , InvName , ISNULL ( InvStd , ' ' ) , InvUnit , @needqty , ISNULL ( AmountUnit , ' ' ) ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint from # maintemp
where # maintemp . transSequence = @transSequence AND DetailID = @DetailID
update # barcodetemp set quantity = @qty - @needqty where lotno = @lotno
SET @needqty = @needqty - @qty
END
ELSE
BEGIN
insert INTO # resulttemp ( lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
Amount , InvCode , InvName , InvStd , InvUnit , LocationQty , AmountUnit ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint )
SELECT @lotno , TransCode , DetailID , Sequence , TransSequence , IssueQuantity , Quantity ,
ISNULL ( Amount , 0 ) , InvCode , InvName , ISNULL ( InvStd , ' ' ) , InvUnit , 0 , ISNULL ( AmountUnit , ' ' ) ,
ExtensionID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10 , WorkPoint from # maintemp
where # maintemp . transSequence = @transSequence AND DetailID = @DetailID
// select * into #resulttemp from #maintemp
// ALTER TABLE #resulttemp ADD LotNo VARCHAR(50)
// delete from #resulttemp
// -- 2.根据maintemp 中的物料信息 查出库存中对应的条码信息 barcodetemp
// select a.lotno,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime into #barcodetemp from ICSWareHouseLotInfo a LEFT JOIN
// (select #maintemp.invcode from #maintemp group by #maintemp.InvCode) b on a.invcode = b.invcode where a.Quantity-a.lockQuantity>0 ORDER BY a.MTIME ASC
// -- 3.循环maintemp,根据 行号和子表ID 向最终结果集中写入数据 ;barcodetemp 中的已匹配数据删除或更新
// BEGIN
// DECLARE @transSequence int;--当前循环的行号
// DECLARE @qty int;--条码表数量
// DECLARE @needqty int;--本行所需数量
// DECLARE @lotno VARCHAR(50);--条码
// DECLARE @DetailID VARCHAR(50);--本行所在工单行ID
// DECLARE tempCursor CURSOR FOR (select transSequence,DetailID from #maintemp); --创建游标tempCursor,并定义游标所指向的集合
// OPEN tempCursor; --打开游标
// FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID; --游标读取下一个数据
// WHILE @@fetch_status=0
// BEGIN
// select @needqty= Quantity from #maintemp where transSequence = @transSequence AND DetailID = @DetailID
// PRINT @transSequence
// WHILE @needqty>0
// BEGIN
// select top 1 @qty = isnull(quantity,0),@lotno = isnull(lotno,'') from #barcodetemp a
// RIGHT JOIN (select invcode from #maintemp where transSequence = @transSequence AND DetailID = @DetailID) b on a .invcode= b.invcode ORDER BY mtime
// BEGIN
// IF(@needqty-@qty>=0 and ISNULL(@lotno, '')<>'')
// BEGIN
// insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
// Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
// SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
// ISNULL(Amount, 0), InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@qty,ISNULL(AmountUnit, ''),
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
// where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
// delete from #barcodetemp where lotno = @lotno
// SET @needqty=@needqty-@qty
// END
// ELSE IF(@needqty-@qty<0 and ISNULL(@lotno, '')<>'')
// BEGIN
// insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
// Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
// SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
// ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,@needqty,ISNULL(AmountUnit, ''),
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
// where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
// update #barcodetemp set quantity = @qty-@needqty where lotno = @lotno
// SET @needqty=@needqty-@qty
// END
// ELSE
// BEGIN
// insert INTO #resulttemp (lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity,Quantity,
// Amount,InvCode,InvName,InvStd,InvUnit,LocationQty,AmountUnit,
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint)
// SELECT @lotno,TransCode,DetailID,Sequence,TransSequence,IssueQuantity, Quantity,
// ISNULL(Amount, 0),InvCode,InvName,ISNULL(InvStd, ''),InvUnit,0,ISNULL(AmountUnit, ''),
// ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WorkPoint from #maintemp
// where #maintemp.transSequence = @transSequence AND DetailID = @DetailID
SET @needqty = 0
END
END
END
FETCH NEXT FROM tempCursor INTO @transSequence , @DetailID ;
END
CLOSE tempCursor
DEALLOCATE tempCursor
END
select TransCode , LotNo , LocationQty AS Quantity , InvCode , DetailID , Sequence , TransSequence from # resulttemp
- - select * from # resulttemp
DROP table # maintemp
DROP table # resulttemp
DROP table # barcodetemp ";
#endregion
sql = String . Format ( sql , LotNo , WorkPoint , Quantity ) ;
DataTable table = DBHelper . SQlReturnData ( sql , cmd ) ;
string json = JsonConvert . SerializeObject ( table ) ;
List < DownItemModel > downItemModels = JsonConvert . DeserializeObject < List < DownItemModel > > ( json ) ;
foreach ( DownItemModel model in downItemModels )
{
if ( model ! = null & & model . LotNo = = null | | "" = = model . LotNo )
{
throw new Exception ( language . GetNameByCode ( "WMSAPIInfo201" ) ) ;
}
WareHouseLotInfoDown ( Identification , model . TransCode , model . Sequence + "~" + model . TransSequence , model . LotNo , model . Quantity , User , WorkPoint , "12" , BusinessCode , cmd , language ) ;
//回写已领数量
sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model . Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'" ;
sql = String . Format ( sql , model . DetailID , model . TransSequence , WorkPoint ) ;
if ( ! DBHelper . ExecuteNonQuery ( sql , cmd ) )
{
throw new Exception ( language . GetNameByCode ( "WMSAPIInfo199" ) ) ;
}
}
}
// SET @needqty=0
// END
//END
// END
// FETCH NEXT FROM tempCursor INTO @transSequence,@DetailID;
// END
// CLOSE tempCursor
// DEALLOCATE tempCursor
// END
// select TransCode,LotNo,LocationQty AS Quantity,InvCode,DetailID,Sequence,TransSequence from #resulttemp
// --select * from #resulttemp
// DROP table #maintemp
// DROP table #resulttemp
// DROP table #barcodetemp ";
// #endregion
// sql = String.Format(sql, LotNo, WorkPoint, Quantity);
// DataTable table = DBHelper.SQlReturnData(sql, cmd);
// string json = JsonConvert.SerializeObject(table);
// List<DownItemModel> downItemModels = JsonConvert.DeserializeObject<List<DownItemModel>>(json);
// foreach (DownItemModel model in downItemModels)
// {
// if (model != null && model.LotNo == null || "" == model.LotNo)
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo201"));
// }
// WareHouseLotInfoDown(Identification, model.TransCode, model.Sequence + "~" + model.TransSequence, model.LotNo, model.Quantity, User, WorkPoint, "12", BusinessCode, cmd, language);
// //回写已领数量
// sql = @"UPDATE ICSMOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + model.Quantity + ") WHERE MODetailID='{0}' AND Sequence='{1}' AND WorkPoint='{2}'";
// sql = String.Format(sql, model.DetailID, model.TransSequence, WorkPoint);
// if (!DBHelper.ExecuteNonQuery(sql, cmd))
// {
// throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
// }
// }
//}
#endregion
#endregion
#region 委外入库,倒冲
#region 委外入库,倒冲