@ -722,7 +722,19 @@ namespace ICSSoft.DataProject
{
try
{
string sql = @ "DECLARE @Status VARCHAR(10)
string sql = @ "
IF NOT EXISTS ( SELECT 1
FROM ICSMO a
LEFT JOIN ICSInventoryLotDetail b ON b . TransCode = a . MoCode AND b . TransSequence = a . Sequence AND b . WorkPoint = a . WorkPoint
LEFT JOIN ICSInventoryLot c ON c . LotNo = b . LotNo AND c . WorkPoint = b . WorkPoint
LEFT JOIN ICSExtension d ON d . ID = c . ExtensionID AND d . WorkPoint = c . WorkPoint
LEFT JOIN ICSBackflushBCLog bclog ON a . MOCode = bclog . TransCode AND a . Sequence = bclog . TransSequence AND bclog . BatchCode = d . BatchCode
WHERE c . LotNo = ' { 0 } ' )
BEGIN
RAISERROR ( ' " + language.GetNameByCode(" WMSAPIInfo468 ") + @" ' , 1 6 , 1 ) ;
END
DECLARE @Status VARCHAR ( 1 0 )
SELECT @Status = c . ERPStatus FROM ICSInventoryLot a
INNER JOIN ICSInventoryLotDetail b ON a . LotNo = b . LotNo AND a . WorkPoint = b . WorkPoint
INNER JOIN ICSMO c ON b . TransCode = c . MOCode AND b . TransSequence = c . Sequence AND b . WorkPoint = c . WorkPoint
@ -947,8 +959,21 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
log . Debug ( resultStr ) ;
}
//副产品生成产成品入库单
sql = @ "SELECT c.BatchCode--,COUNT(*) AS batchCount
#region 副产品生成产成品入库单
try {
sql = @ "-- 判断本工单中对应行号与本批次副产品是否已生成入库单号
IF (
SELECT DISTINCT bypro . BatchCode
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b . LotNo = a . LotNo AND b . WorkPoint = a . WorkPoint
LEFT JOIN ICSExtension c ON c . ID = b . ExtensionID AND c . WorkPoint = b . WorkPoint
LEFT JOIN ICSMOByProductLog bypro ON bypro . MoCode = a . TransCode AND bypro . Sequence = a . TransSequence AND bypro . BatchCode = c . BatchCode AND bypro . WorkPoint = a . WorkPoint
WHERE a . Identification = ' { 0 } '
) IS NULL
BEGIN
- - 查 找 主 产 品 批 次 种 类 数 量
DECLARE @BatchCount VARCHAR ( 1 0 )
SELECT @BatchCount = COUNT ( DISTINCT c . BatchCode )
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b . LotNo = a . LotNo AND b . WorkPoint = a . WorkPoint
LEFT JOIN ICSExtension c ON c . ID = b . ExtensionID AND c . WorkPoint = b . WorkPoint
@ -956,14 +981,12 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
LEFT JOIN ICSMO e ON e . MOCode = d . TransCode AND e . WorkPoint = d . WorkPoint
LEFT JOIN ICSMOPick f ON f . MODetailID = e . MODetailID AND f . WorkPoint = d . WorkPoint
WHERE a . Identification = ' { 0 } '
AND ( SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro . MoCode = e . MoCode AND bypro . Sequence = f . Sequence AND bypro . BatchCode = c . BatchCode AND bypro . WorkPoint = a . WorkPoint ) IS NULL
GROUP BY c . BatchCode ";
sql = string . Format ( sql , Identification ) ;
log . Debug ( "查询主产品批次数目:" ) ;
log . Debug ( sql ) ;
DataTable dt = DBHelper . SQlReturnData ( sql , cmd ) ;
int times = dt . Rows . Count ;
sql = @ "SELECT e.DepCode+f.WHCode+e.MOCode+a.MUSER AS Costre,e.DepCode,f.WHCode AS WarehouseCode,e.MoCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY e.DepCode,f.WHCode,e.MOCode,e.MODetailID,f.InvCode) AS Sequence,f.InvCode,f.EATTRIBUTE2 AS Quantity,0 AS Amount,e.MODetailID,Enable AS UpdateTodoQuantity,a.WorkPoint
AND ( SELECT 1 FROM ICSMOByProductLog bypro WHERE bypro . MoCode = a . TransCode AND bypro . Sequence = a . TransSequence AND bypro . BatchCode = c . BatchCode AND bypro . WorkPoint = a . WorkPoint ) IS NULL
- - SELECT @BatchCount
- - 查 询 副 产 品 生 成 入 库 单 所 需 数 据
SELECT e . DepCode + f . WHCode + e . MOCode + a . MUSER AS Costre , e . DepCode , f . WHCode AS WarehouseCode , e . MoCode , a . MUSER , ROW_NUMBER ( ) OVER ( ORDER BY e . DepCode , f . WHCode , e . MOCode , e . MODetailID , f . InvCode ) AS Sequence , f . InvCode , f . EATTRIBUTE2 AS Quantity , 0 AS Amount , e . MODetailID , Enable AS UpdateTodoQuantity , a . WorkPoint
, ISNULL ( ext . ProjectCode , ' ' ) AS ProjectCode , CASE WHEN ( invBat . BatchEnable IS NULL AND ISNULL ( inv . BatchEnable , '0' ) = '1' ) OR ISNULL ( invBat . BatchEnable , '0' ) = '1' THEN ISNULL ( ext . BatchCode , ' ' ) ELSE ' ' END AS BatchCode , ISNULL ( ext . Version , ' ' ) AS Version , ISNULL ( ext . Brand , ' ' ) AS Brand , ISNULL ( ext . cFree1 , ' ' ) AS cFree1 , ISNULL ( ext . cFree2 , ' ' ) AS cFree2 , ISNULL ( ext . cFree3 , ' ' ) AS cFree3 , ISNULL ( ext . cFree4 , ' ' ) AS cFree4 , ISNULL ( ext . cFree5 , ' ' ) AS cFree5 , ISNULL ( ext . cFree6 , ' ' ) AS cFree6 , ISNULL ( ext . cFree7 , ' ' ) AS cFree7 , ISNULL ( ext . cFree8 , ' ' ) AS cFree8 , ISNULL ( ext . cFree9 , ' ' ) AS cFree9 , ISNULL ( ext . cFree10 , ' ' ) AS cFree10
INTO # TempERP
FROM ICSWareHouseLotInfoLog a
@ -982,12 +1005,18 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
, ISNULL ( ext . ProjectCode , ' ' ) , CASE WHEN ( invBat . BatchEnable IS NULL AND ISNULL ( inv . BatchEnable , '0' ) = '1' ) OR ISNULL ( invBat . BatchEnable , '0' ) = '1' THEN ISNULL ( ext . BatchCode , ' ' ) ELSE ' ' END , ISNULL ( ext . Version , ' ' ) , ISNULL ( ext . Brand , ' ' ) , ISNULL ( ext . cFree1 , ' ' ) , ISNULL ( ext . cFree2 , ' ' ) , ISNULL ( ext . cFree3 , ' ' ) , ISNULL ( ext . cFree4 , ' ' ) , ISNULL ( ext . cFree5 , ' ' ) , ISNULL ( ext . cFree6 , ' ' ) , ISNULL ( ext . cFree7 , ' ' ) , ISNULL ( ext . cFree8 , ' ' ) , ISNULL ( ext . cFree9 , ' ' ) , ISNULL ( ext . cFree10 , ' ' )
SELECT DISTINCT Costre , WorkPoint , DepCode , WarehouseCode AS WHCode , MOCode , MUSER AS [ User ] , SYSDATETIME ( ) AS MTime , UpdateTodoQuantity FROM # TempERP
SELECT Costre , Sequence , InvCode , Quantity * { 1 } AS Quantity , Amount , MODetailID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10
SELECT Costre , Sequence , InvCode , Quantity * @BatchCount AS Quantity , Amount , MODetailID , ProjectCode , BatchCode , Version , Brand , cFree1 , cFree2 , cFree3 , cFree4 , cFree5 , cFree6 , cFree7 , cFree8 , cFree9 , cFree10
FROM # TempERP
DROP TABLE # TempERP ";
sql = string . Format ( sql , Identification , times ) ;
log . Debug ( "副产品生成成品入库单:" ) ;
DROP TABLE # TempERP
END
ELSE
BEGIN
RAISERROR ( ' " + language.GetNameByCode(" WMSAPIInfo467 ") + @" ' , 1 6 , 1 ) ;
- - RAISERROR ( ' 本 次 副 产 品 不 需 要 生 成 入 库 单 ' , 1 6 , 1 )
END ";
sql = string . Format ( sql , Identification ) ;
log . Debug ( "副产品生成入库单逻辑:" ) ;
log . Debug ( sql ) ;
ds = DBHelper . SQlReturnDataSet ( sql , cmd ) ;
@ -997,22 +1026,26 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
result = JsonConvert . DeserializeObject < Result > ( byProductResultStr ) ;
if ( result . Success )
{
//向副产品生成入库单记录 表中插入数据
//向ICSMOByProductLog 表中插入数据
sql = @ "SELECT a.TransCode,a.TransSequence,a.Quantity,c.BatchCode,b.InvCode,a.WorkPoint
FROM ICSWareHouseLotInfoLog a
LEFT JOIN ICSInventoryLot b ON b . LotNo = a . LotNo AND b . WorkPoint = a . WorkPoint
LEFT JOIN ICSExtension c ON c . ID = b . ExtensionID AND c . WorkPoint = a . WorkPoint
WHERE a . Identification = ' { 0 } ' ";
sql = string . Format ( sql , Identification ) ;
log . Debug ( "查询入库的主产品及批次SQL:" ) ;
log . Error ( sql ) ;
DataTable dtt = DBHelper . SQlReturnData ( sql , cmd ) ;
Inputstr = dtt . ToString ( ) ;
List < MoStockInModel > moStockIns = JsonConvert . DeserializeObject < List < MoStockInModel > > ( Inputstr ) ;
string jsonStr = JsonConvert . SerializeObject ( dtt ) ;
log . Debug ( "SQL执行结果:" + jsonStr ) ;
List < MoStockInModel > moStockIns = JsonConvert . DeserializeObject < List < MoStockInModel > > ( jsonStr ) ;
foreach ( MoStockInModel moStockIn in moStockIns )
{
try
{
sql = @"INSERT INTO ICSMOByProductLog VALUES(NEWID(),'{0}','{1}',{2},'{3}','{4}','{5}')" ;
sql = string . Format ( sql , moStockIn . TransCode , moStockIn . TransSequence , moStockIn . Quantity , moStockIn . BatchCode , moStockIn . InvCode , moStockIn . WorkPoint ) ;
log . Debug ( "向副产品生成入库单记录 表中插入数据:" ) ;
log . Debug ( "向ICSMOByProductLog 表中插入数据:" ) ;
log . Debug ( sql ) ;
DBHelper . ExecuteNonQuery ( sql , cmd ) ;
}
@ -1029,11 +1062,16 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
}
}
catch ( Exception ex )
{
log . Debug ( ex . Message ) ;
}
#endregion
}
else
{
throw new Exception ( language . GetNameByCode ( "WMSAPIInfo080" ) + result . Message ) ;
}
#endregion
}
catch ( Exception )
{
@ -1364,3 +1402,4 @@ ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.
#endregion
}
}
#endregion