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