@ -7307,6 +7307,243 @@ WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by Transfer
}
#endregion
#region 拣料信息
/// <summary>
/// 获取拣料信息
/// </summary>
/// <param name="JsonData"></param>
/// <returns></returns>
public static DataTable GetICSMOPickMergeTemp ( WMSSourceDocumentModel JsonData )
{
var language = LanguageHelper . GetName ( "WMSAPIInfo" ) ;
using ( SqlConnection conn = new System . Data . SqlClient . SqlConnection ( connString ) )
{
conn . Open ( ) ;
SqlCommand cmd = new SqlCommand ( ) ;
cmd . Connection = conn ;
try
{
if ( string . IsNullOrEmpty ( JsonData . TransCode ) )
{
throw new Exception ( language . GetNameByCode ( "WMSAPIInfo001" ) ) ; //"单据号不能为空!"
}
else if ( string . IsNullOrEmpty ( JsonData . WorkPoint ) )
{
throw new Exception ( language . GetNameByCode ( "WMSAPIInfo004" ) ) ; //"站点不能为空!"
}
string information = String . Format ( language . GetNameByCode ( "WMSAPIInfo035" ) , "" , "" , "" , JsonData . TransCode ) ;
#region SLQ
string sqls = "" ;
#region 工单领料
if ( JsonData . TransType = = TransTypeEnum . MOApply . GetDescription ( ) )
{
#region 工单领料SQL
sqls = @ " select
x . MergeID ,
a . ApplyCode as Code ,
a . InvCode ,
b . InvName ,
b . InvStd ,
b . InvUnit ,
SUM ( ISNULL ( a . Quantity , 0 ) ) AS iQuantity ,
a . WhCode ,
a . ExtensionID
FROM
ICSMOApply a
inner join ICSMOPickMerge x on a . ID = x . SourceID and a . WorkPoint = x . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
WHERE a . ApplyCode in ( { 0 } ) AND a . WorkPoint = ' { 1 } '
GROUP BY a . ApplyCode , a . InvCode , b . InvName , b . InvStd , b . InvUnit , a . WhCode , x . MergeID , a . ExtensionID ";
#endregion
}
#endregion
#region 委外领料
if ( JsonData . TransType = = TransTypeEnum . OutsourcingIssueDoc . GetDescription ( ) )
{
#region 委外领料SQL
sqls = @ " select
x . MergeID ,
a . ApplyCode as Code ,
a . InvCode ,
b . InvName ,
b . InvStd ,
b . InvUnit ,
SUM ( ISNULL ( a . Quantity , 0 ) ) AS iQuantity ,
a . WhCode ,
a . ExtensionID
FROM
ICSOApply a
inner join ICSMOPickMerge x on a . ID = x . SourceID and a . WorkPoint = x . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
WHERE a . ApplyCode in ( { 0 } ) AND a . WorkPoint = ' { 1 } '
GROUP BY a . ApplyCode , a . InvCode , b . InvName , b . InvStd , b . InvUnit , a . WhCode , a . ExtensionID , x . MergeID ";
#endregion
}
#endregion
#region 销售发货
if ( JsonData . TransType = = TransTypeEnum . OutsourcingIssueDoc . GetDescription ( ) )
{
#region 销售发货SQL
sqls = @ " select
x . MergeID ,
a . SDNCode as Code ,
a . InvCode ,
b . InvName ,
b . InvStd ,
b . InvUnit ,
SUM ( ISNULL ( a . Quantity , 0 ) ) AS iQuantity ,
a . WhCode ,
a . ExtensionID
FROM
ICSSDN a
inner join ICSMOPickMerge x on a . ID = x . SourceID and a . WorkPoint = x . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
WHERE a . SDNCode in ( { 0 } ) AND a . WorkPoint = ' { 1 } '
GROUP BY a . SDNCode , a . InvCode , b . InvName , b . InvStd , b . InvUnit , a . WhCode , a . ExtensionID , x . MergeID ";
#endregion
}
#endregion
#region 其他出库
if ( JsonData . TransType = = TransTypeEnum . OutsourcingIssueDoc . GetDescription ( ) )
{
#region 其它出库SQL
sqls = @ " select
x . MergeID ,
a . OutCode as Code ,
a . InvCode ,
b . InvName ,
b . InvStd ,
b . InvUnit ,
SUM ( ISNULL ( a . Quantity , 0 ) ) AS iQuantity ,
a . WhCode ,
a . ExtensionID
FROM
ICSOtherOut a
inner join ICSMOPickMerge x on a . ID = x . SourceID and a . WorkPoint = x . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
WHERE a . OutCode in ( { 0 } ) AND a . WorkPoint = ' { 1 } '
GROUP BY a . OutCode , a . InvCode , b . InvName , b . InvStd , b . InvUnit , a . WhCode , a . ExtensionID , x . MergeID ";
#endregion
}
#endregion
#region 物料调拨
if ( JsonData . TransType = = TransTypeEnum . OutsourcingIssueDoc . GetDescription ( ) )
{
#region 物料调拨
sqls = @ " select
x . MergeID ,
a . TransferNO as Code ,
a . InvCode ,
b . InvName ,
b . InvStd ,
b . InvUnit ,
SUM ( ISNULL ( a . Quantity , 0 ) ) AS iQuantity ,
a . FromWarehouseCode as WhCode ,
a . ExtensionID
FROM
ICSTransfer a
inner join ICSMOPickMerge x on a . ID = x . SourceID and a . WorkPoint = x . WorkPoint
LEFT JOIN ICSINVENTORY b ON a . InvCode = b . InvCode AND a . WorkPoint = b . WorkPoint
WHERE a . TransferNO in ( { 0 } ) AND a . WorkPoint = ' { 1 } '
GROUP BY a . TransferNO , a . InvCode , b . InvName , b . InvStd , b . InvUnit , a . FromWarehouseCode , a . ExtensionID , x . MergeID ";
#endregion
}
#endregion
sqls = string . Format ( sqls , JsonData . TransCode , JsonData . WorkPoint ) ;
#region sql
string sql = $ @ "SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
c . MergeID ,
c . Code ,
c . InvCode ,
c . InvName ,
c . InvStd ,
c . InvUnit ,
FLOOR ( c . iQuantity ) AS iQuantity ,
d . WarehouseCode ,
d . LocationCode ,
d . LotNO ,
FLOOR ( ISNULL ( d . Quantity , 0 ) ) AS QTY ,
CONVERT ( varchar ( 1 0 0 ) , d . MTIME , 2 3 ) MTIME ,
FLOOR ( f . QTYTotal ) QTYTotal
FROM
( { sqls } ) c
left join ( select d . WarehouseCode , d . Quantity , d . INVCode , m . LotNo , d . MTIME , d . LocationCode , m . ExtensionID
from ICSWareHouseLotInfo d , ICSInventoryLot m
where d . LotNo = m . LotNo and d . WorkPoint = m . WorkPoint
and d . WorkPoint = ' { JsonData . WorkPoint } ' AND d . Quantity > 0 ) d
on c . InvCode = d . INVCode AND c . WhCode = d . WarehouseCode and d . ExtensionID = c . ExtensionID
LEFT JOIN ( SELECT INVCode , WarehouseCode , SUM ( Quantity ) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint = ' { JsonData . WorkPoint } ' GROUP BY INVCode , WarehouseCode ) f ON c . InvCode = f . INVCode AND c . WhCode = f . WarehouseCode
order by c . Code , c . InvCode , d . MTIME ";
#endregion
var dataset = DBHelper . SQlReturnDataSet ( sql , cmd ) ; ;
if ( dataset . Tables . Count = = 0 )
return null ;
DataTable table = dataset . Tables [ 0 ] ;
decimal qtyCount = 0 ;
bool remove = false ;
List < int > removeList = new List < int > ( ) ;
for ( int i = 0 ; i < table . Rows . Count ; i + + )
{
if ( i ! = 0
& & ( ! table . Rows [ i ] [ "InvCode" ] . ToString ( ) . Equals ( table . Rows [ i - 1 ] [ "InvCode" ] . ToString ( ) )
| | ! table . Rows [ i ] [ "Code" ] . ToString ( ) . Equals ( table . Rows [ i - 1 ] [ "Code" ] . ToString ( ) ) )
)
{
qtyCount = 0 ;
remove = false ;
}
if ( remove )
{
removeList . Add ( i ) ;
}
else
{
var lotQty = decimal . Parse ( table . Rows [ i ] [ "QTY" ] . ToString ( ) ) ;
var orderQty = decimal . Parse ( table . Rows [ i ] [ "iQuantity" ] . ToString ( ) ) ;
qtyCount + = lotQty ;
if ( qtyCount > = orderQty )
{
remove = true ;
}
}
}
if ( removeList . Count > 0 )
{
removeList . Reverse ( ) ;
foreach ( var item in removeList )
{
table . Rows . RemoveAt ( item ) ;
}
}
#endregion
//DataTable table = DBHelper.SQlReturnData(sql, cmd);
return table ;
}
catch ( Exception ex )
{
log . Error ( ex . Message ) ;
throw new Exception ( ex . Message ) ;
}
finally
{
if ( conn . State = = ConnectionState . Open )
{
conn . Close ( ) ;
}
conn . Dispose ( ) ;
}
}
}
#endregion
/// <summary>
/// 形态转换
/// <param name="JsonData"></param>