2021-01-12 14:45:59 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using Dapper ;
namespace NX.ERP.U8.Mom
{
2021-05-19 15:19:27 +08:00
/// <summary>
/// 生产订单
/// </summary>
2021-01-13 10:21:56 +08:00
public class MomOrderDAL
2021-01-12 14:45:59 +08:00
{
2021-02-06 16:36:58 +08:00
/// <summary>
2021-05-19 15:19:27 +08:00
/// 获取生产订单明细
2021-02-06 16:36:58 +08:00
/// </summary>
/// <param name="strWhere"></param>
/// <param name="param"></param>
/// <returns></returns>
2021-01-12 14:45:59 +08:00
public IEnumerable < Model . MOM . MomOrder > GetList ( string strWhere = "" , object param = null )
{
2021-01-25 09:47:41 +08:00
using ( var conn = U8LoginContext . Instance . Connection )
2021-01-12 14:45:59 +08:00
{
2021-06-04 14:48:56 +08:00
string strSQL = @ " select a.MoId as ProductOrderId,a.moCode as ProductOrderNo,ISNULL( ModifyDate,createDate) as ModifyDate,CONVERT(BIGINT,a.Ufts) AS pubufts,a.CreateDate as ProductDate,a.CreateUser as PreparedBy,
2021-10-15 16:51:48 +08:00
b . MoId as id , b . MoDId as ProductOrderDtlId , b . MoId as ProductOrderId , b . MoTypeId , d . DueDate , b . Remark as Remark , ISNULL ( b . MDeptCode , ' 53 ' ) as MDeptCode , a . MoCode as ProductOrderNo ,
2021-06-04 14:48:56 +08:00
a . CreateDate as ProductOrderDate , b . InvCode as ProductCode , b . Qty as Qty , b . SortSeq , b . SoCode , b . Status , InvDetail . cInvName as ProductName , InvDetail . cInvStd ProductSpecsModel ,
c . AllocateId as id , c . AllocateId as AllocateId , c . MoDId as ProductOrderDtlId , c . InvCode as MaterialCode , InvLocate . cInvName as MaterialName , InvLocate . cInvStd as MaterialSpecsModel , b . MoId as ProductOrderId , c . IssQty as IssQty , c . Qty ,
2021-05-15 16:03:52 +08:00
e . cInvSN as ID
2021-01-22 11:25:03 +08:00
from mom_order as a
left join mom_orderdetail as b on a . MoId = b . MoId
2021-05-15 16:03:52 +08:00
left join mom_morder as d on b . MoDId = d . MoDId
left join mom_SNDetail as e on b . MoDId = e . iVouchsID
2021-06-04 14:48:56 +08:00
left join mom_moallocate as c on b . MoDId = c . MoDId
left join Inventory as InvDetail on b . InvCode = InvDetail . cInvCode
2021-10-15 16:51:48 +08:00
left join Inventory as InvLocate on c . InvCode = InvLocate . cInvCode ";
2021-01-12 14:45:59 +08:00
if ( ! string . IsNullOrEmpty ( strWhere ) )
{
2021-10-14 09:15:14 +08:00
strSQL + = $" where {strWhere} " ;
2021-01-12 14:45:59 +08:00
}
var lookupDetail = new Dictionary < int , Model . MOM . MomDetail > ( ) ;
var lookupOrder = new Dictionary < int , Model . MOM . MomOrder > ( ) ;
2021-01-15 11:30:02 +08:00
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
2021-05-17 15:40:43 +08:00
var list = conn . Query < Model . MOM . MomOrder , Model . MOM . MomDetail , Model . MOM . MoAllocate , string , Model . MOM . MomOrder > ( strSQL , ( Order , OrderDetail , MoAllocate , SN ) = >
{
if ( ! lookupOrder . TryGetValue ( Order . ProductOrderId , out var _order ) )
{
lookupOrder . Add ( Order . ProductOrderId , Order ) ;
2021-05-15 16:03:52 +08:00
2021-05-17 15:40:43 +08:00
}
else
{
Order = _order ;
}
2021-05-15 16:03:52 +08:00
2021-05-17 15:40:43 +08:00
if ( ! lookupDetail . TryGetValue ( OrderDetail . ProductOrderDtlId , out var momDetail ) )
{
lookupDetail . Add ( OrderDetail . ProductOrderDtlId , OrderDetail ) ;
Order . ProductDtlLst . Add ( OrderDetail ) ;
}
else
{
OrderDetail = momDetail ;
}
2021-05-24 14:59:32 +08:00
if ( SN ! = null )
{
OrderDetail . SN . Add ( SN ) ;
}
2021-10-12 08:59:07 +08:00
if ( MoAllocate ! = null )
{
Order . Allocates . Add ( MoAllocate ) ;
OrderDetail . ProductAllocateOrderLst . Add ( MoAllocate ) ;
MoAllocate . momDetail = OrderDetail ;
}
2021-05-17 15:40:43 +08:00
return Order ;
} , param , null , true , "id" , 10 , System . Data . CommandType . Text ) ;
2021-01-12 14:45:59 +08:00
return lookupOrder . Values ;
}
}
2021-06-04 11:22:42 +08:00
public IEnumerable < Model . MOM . MomOrder > GetList ( long Pubufts )
{
return this . GetList ( "CONVERT(BIGINT,a.Ufts) > @Pubufts" , new { Pubufts } ) ;
}
2021-05-19 15:19:27 +08:00
/// <summary>
///
/// </summary>
/// <param name="Params"></param>
/// <returns></returns>
2021-05-15 16:03:52 +08:00
public IEnumerable < Model . MOM . MomOrder > GetList ( NX . ERP . Model . Request . MomOrder Params )
{
if ( Params = = null )
{
return this . GetOrders ( ) ;
}
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( Params . ProductCode ) )
{
2021-06-04 14:48:56 +08:00
where . Add ( " b.InvCode like @ProductCode" ) ;
2021-05-15 16:03:52 +08:00
}
2021-10-12 08:59:07 +08:00
if ( Params . ProductOrderNo ! = null & & Params . ProductOrderNo . Count ( ) > 0 )
2021-05-15 16:03:52 +08:00
{
2021-06-07 11:09:46 +08:00
where . Add ( " a.moCode in @ProductOrderNo " ) ;
2021-05-15 16:03:52 +08:00
}
if ( ! string . IsNullOrEmpty ( Params . ProductOrderendID ) )
{
where . Add ( " a.MoId >= @ProductOrderendID " ) ;
}
2021-05-22 09:53:21 +08:00
2021-06-04 11:22:42 +08:00
if ( Params . ModifyDate ! = null )
2021-05-22 09:53:21 +08:00
{
2021-06-04 14:48:56 +08:00
where . Add ( " ISNULL( b.ModifyDate,createDate) >= @ModifyDate or b.RelsTime>=@ModifyDate " ) ;
2021-06-03 12:06:26 +08:00
}
if ( Params . Pubufts ! = null )
{
2021-06-03 16:04:28 +08:00
where . Add ( "CONVERT(BIGINT,a.Ufts) > @Pubufts " ) ;
2021-06-04 11:22:42 +08:00
2021-05-22 09:53:21 +08:00
}
2021-10-14 09:15:14 +08:00
else
{
where . Add ( " b.Status<>'4' " ) ;
}
2021-05-22 09:53:21 +08:00
2021-10-14 09:15:14 +08:00
if ( Params . Status ! = null & & Params . Status . Count ( ) > 0 )
2021-06-03 16:04:28 +08:00
{
where . Add ( " b.Status in @Status " ) ;
}
2021-05-22 09:53:21 +08:00
2021-10-14 09:15:14 +08:00
2021-05-15 16:03:52 +08:00
return this . GetList ( string . Join ( " and " , where . ToArray ( ) ) , new
{
ProductCode = $"%{Params.ProductCode}%" ,
2021-06-10 14:04:00 +08:00
ProductOrderNo = Params . ProductOrderNo ,
2021-05-22 09:54:06 +08:00
Params . ProductOrderendID ,
2021-06-03 12:06:26 +08:00
Params . ModifyDate ,
2021-06-03 16:04:28 +08:00
Params . Pubufts ,
Params . Status
2021-05-15 16:03:52 +08:00
} ) ;
}
2021-02-06 16:36:58 +08:00
/// <summary>
///
/// </summary>
/// <param name="Params"></param>
/// <returns></returns>
2021-01-22 11:25:03 +08:00
public IEnumerable < Model . MOM . MomOrder > QueryOrders ( NX . ERP . Model . Request . MomOrder Params )
{
if ( Params = = null )
{
return this . GetOrders ( ) ;
}
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( Params . ProductCode ) )
{
2021-02-06 16:12:48 +08:00
where . Add ( " a.InvCode like @ProductCode" ) ;
2021-01-22 11:25:03 +08:00
}
2021-06-10 14:04:00 +08:00
if ( Params . ProductOrderNo ! = null )
2021-01-22 11:25:03 +08:00
{
2021-06-07 11:09:46 +08:00
where . Add ( " a.moCode in @ProductOrderNo " ) ;
2021-01-22 11:25:03 +08:00
}
2021-03-03 14:29:15 +08:00
if ( ! string . IsNullOrEmpty ( Params . ProductOrderendID ) )
{
where . Add ( " a.MoId >= @ProductOrderendID " ) ;
}
2021-01-22 11:25:03 +08:00
return this . GetOrders ( string . Join ( " and " , where . ToArray ( ) ) , new
{
ProductCode = $"%{Params.ProductCode}%" ,
2021-06-07 11:09:46 +08:00
ProductOrderNo = Params . ProductOrderNo ,
2021-03-03 14:29:15 +08:00
ProductOrderendID = $"{Params.ProductOrderendID}"
2021-01-22 11:25:03 +08:00
} ) ;
}
2021-11-04 10:47:29 +08:00
/// <summary>
///
/// </summary>
/// <param name="Params"></param>
/// <returns></returns>
public IEnumerable < Model . MOM . MomOrder > QueryOrderWithClose ( NX . ERP . Model . Request . MomOrder Params )
{
if ( Params = = null )
{
return this . GetOrders ( ) ;
}
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( Params . ProductCode ) )
{
where . Add ( " a.InvCode like @ProductCode" ) ;
}
if ( Params . ProductOrderNo ! = null )
{
where . Add ( " a.moCode in @ProductOrderNo " ) ;
}
if ( ! string . IsNullOrEmpty ( Params . ProductOrderendID ) )
{
where . Add ( " a.MoId >= @ProductOrderendID " ) ;
}
return this . GetOrdersWithClose ( string . Join ( " and " , where . ToArray ( ) ) , new
{
ProductCode = $"%{Params.ProductCode}%" ,
ProductOrderNo = Params . ProductOrderNo ,
ProductOrderendID = $"{Params.ProductOrderendID}"
} ) ;
}
2021-02-06 16:36:58 +08:00
/// <summary>
2021-05-15 16:03:52 +08:00
/// 查询生产订单不包括用料明细
2021-02-06 16:36:58 +08:00
/// </summary>
/// <param name="strWhere"></param>
/// <param name="Param"></param>
/// <returns></returns>
2021-01-22 11:25:03 +08:00
public IEnumerable < Model . MOM . MomOrder > GetOrders ( string strWhere = "" , object Param = null )
{
2021-01-25 09:47:41 +08:00
using ( var conn = U8LoginContext . Instance . Connection )
2021-01-22 11:25:03 +08:00
{
string strSQL = @ "select
2021-02-06 16:12:48 +08:00
a . MoId as ProductOrderId , a . moCode as ProductOrderNo , a . MakeDate as ProductDate , a . ModifyUser as PreparedBy ,
2021-11-04 10:47:29 +08:00
a . MoId as id , a . MoDId as ProductOrderDtlId , a . MoId as ProductOrderId , a . MoCode as ProductOrderNo , a . MakeDate as ProductOrderDate , a . InvCode as ProductCode , a . Qty as Qty , a . QualifiedInQty
2021-02-06 16:12:48 +08:00
FROM v_st_mom_orderdetail a with ( nolock ) Where ( ( 1 > 0 ) AND ( 1 > 0 ) )
AND ( 1 > 0 ) and ( case when ISNULL ( SfcFlag , 0 ) = 1 then iquantity + QualifiedInQty else 1 end ) < > 0
2021-05-24 14:59:32 +08:00
and ISNULL ( QCFLAG , 0 ) = 0 and ISNULL ( Status , 0 ) = 3 and ( ISNULL ( iQuantity , 0 ) ) > 0 and isnull ( MrpQty , 0 ) < > 0 and 1 = 1 ";
2021-01-22 11:25:03 +08:00
if ( ! string . IsNullOrEmpty ( strWhere ) )
{
2021-02-06 16:12:48 +08:00
strSQL + = $" and {strWhere} " ;
2021-01-22 11:25:03 +08:00
}
var lookupDetail = new Dictionary < int , Model . MOM . MomDetail > ( ) ;
var lookupOrder = new Dictionary < int , Model . MOM . MomOrder > ( ) ;
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
var list = conn . Query < Model . MOM . MomOrder , Model . MOM . MomDetail , Model . MOM . MomOrder > ( strSQL , ( Order , OrderDetail ) = >
{
if ( ! lookupOrder . TryGetValue ( Order . ProductOrderId , out var _order ) )
{
lookupOrder . Add ( Order . ProductOrderId , Order ) ;
}
else
{
Order = _order ;
}
Order . ProductDtlLst . Add ( OrderDetail ) ;
2021-11-04 10:47:29 +08:00
return Order ;
} , Param , null , true , "id" , 10 , System . Data . CommandType . Text ) ;
return lookupOrder . Values ;
}
}
/// <summary>
/// 查询生产订单不包括用料明细(包含关闭)
/// </summary>
/// <param name="strWhere"></param>
/// <param name="Param"></param>
/// <returns></returns>
public IEnumerable < Model . MOM . MomOrder > GetOrdersWithClose ( string strWhere = "" , object Param = null )
{
using ( var conn = U8LoginContext . Instance . Connection )
{
string strSQL = @ "select
a . MoId as ProductOrderId , a . moCode as ProductOrderNo , a . MakeDate as ProductDate , a . ModifyUser as PreparedBy ,
a . MoId as id , a . MoDId as ProductOrderDtlId , a . MoId as ProductOrderId , a . MoCode as ProductOrderNo , a . MakeDate as ProductOrderDate , a . InvCode as ProductCode , a . Qty as Qty , a . QualifiedInQty
FROM v_st_mom_orderdetail a with ( nolock ) Where 1 = 1 ";
if ( ! string . IsNullOrEmpty ( strWhere ) )
{
strSQL + = $" and {strWhere} " ;
}
var lookupDetail = new Dictionary < int , Model . MOM . MomDetail > ( ) ;
var lookupOrder = new Dictionary < int , Model . MOM . MomOrder > ( ) ;
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
var list = conn . Query < Model . MOM . MomOrder , Model . MOM . MomDetail , Model . MOM . MomOrder > ( strSQL , ( Order , OrderDetail ) = >
{
if ( ! lookupOrder . TryGetValue ( Order . ProductOrderId , out var _order ) )
{
lookupOrder . Add ( Order . ProductOrderId , Order ) ;
}
else
{
Order = _order ;
}
Order . ProductDtlLst . Add ( OrderDetail ) ;
2021-01-22 11:25:03 +08:00
return Order ;
} , Param , null , true , "id" , 10 , System . Data . CommandType . Text ) ;
return lookupOrder . Values ;
}
}
2021-02-06 16:36:58 +08:00
/// <summary>
///
/// </summary>
/// <param name="Params"></param>
/// <returns></returns>
2021-01-22 11:25:03 +08:00
public IEnumerable < Model . MOM . MomDetail > QueryDetails ( NX . ERP . Model . Request . MomOrder Params )
{
if ( Params = = null )
{
return this . GetDetails ( ) ;
}
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( Params . ProductCode ) )
{
2021-01-28 10:10:32 +08:00
where . Add ( " b.InvCode like @ProductCode" ) ;
2021-01-22 11:25:03 +08:00
}
2021-06-10 14:04:00 +08:00
if ( Params . ProductOrderNo ! = null )
2021-01-22 11:25:03 +08:00
{
2021-06-07 11:09:46 +08:00
where . Add ( " b.moCode in @ProductOrderNo " ) ;
2021-01-22 11:25:03 +08:00
}
2021-02-27 10:47:44 +08:00
if ( ! string . IsNullOrEmpty ( Params . ProductOrderendID ) )
{
where . Add ( " b.MoId >= @ProductOrderendID " ) ;
}
2021-01-22 11:25:03 +08:00
return this . GetDetails ( string . Join ( " and " , where . ToArray ( ) ) , new
{
ProductCode = $"%{Params.ProductCode}%" ,
2021-06-10 14:04:00 +08:00
ProductOrderNo = Params . ProductOrderNo ,
2021-02-27 10:47:44 +08:00
ProductOrderendID = $"{Params.ProductOrderendID}"
2021-01-22 11:25:03 +08:00
} ) ;
}
2021-02-06 16:36:58 +08:00
/// <summary>
///
/// </summary>
/// <param name="strWhere"></param>
/// <param name="Param"></param>
/// <returns></returns>
2021-01-22 11:25:03 +08:00
public IEnumerable < Model . MOM . MomDetail > GetDetails ( string strWhere = "" , object Param = null )
{
2021-03-29 14:41:40 +08:00
var strSql = @ "select b.MoId as id ,b.MoDId as ProductOrderDtlId,b.MoId as ProductOrderId,b.MoCode as ProductOrderNo,b.MakeDate as ProductOrderDate,b.InvCode as ProductCode,b.InvName as ProductName ,b.Qty as Qty,
2021-09-03 15:44:50 +08:00
d . AllocateId as id , d . AllocateId as AllocateId , b . MoDId as ProductOrderDtlId , d . InvCode as MaterialCode , b . MoId as ProductOrderId , d . IssQty as IssQty , d . Qty , Allocate . SortSeq as irowno
2021-02-02 15:20:51 +08:00
FROM v_st_mom_orderdetail b INNER JOIN
( SELECT modid as m_modid , allocateid , CREJECTCODE , IssQty , Qty , InvCode
from v_st_moallocate
where isnull ( WIPType , 0 ) = 3
and isnull ( ByproductFlag , 0 ) = 0
and ( ISNULL ( Qty , 0 ) - ISNULL ( IssQty , 0 ) + ISNULL ( ReplenishQty , 0 ) ) > 0
and isnull ( RequisitionFlag , 0 ) = 0 and 1 = 1 )
d ON b . modid = d . m_modid
2021-09-03 15:44:50 +08:00
left join mom_moallocate
Allocate WITH ( NOLOCK ) ON Allocate . AllocateId = d . AllocateId
2021-02-02 15:20:51 +08:00
Where b . byproductflag = 0
and ISNULL ( b . Status , 0 ) = 3
and ( isnull ( b . bWorkshopTrans , 0 ) = 0 or ( isnull ( b . bWorkshopTrans , 0 ) = 1
2021-03-29 14:41:40 +08:00
and isnull ( b . sfcflag , 0 ) = 1 ) ) ";
2021-01-22 15:15:43 +08:00
if ( ! string . IsNullOrEmpty ( strWhere ) )
{
2021-02-02 15:20:51 +08:00
strSql + = $" and {strWhere} " ;
2021-01-22 15:15:43 +08:00
}
2021-01-22 11:25:03 +08:00
var lookup = new Dictionary < int , Model . MOM . MomDetail > ( ) ;
2021-01-25 09:47:41 +08:00
using ( var conn = U8LoginContext . Instance . Connection )
2021-01-22 11:25:03 +08:00
{
conn . Query < Model . MOM . MomDetail , Model . MOM . MoAllocate , Model . MOM . MomDetail > ( strSql , ( OrderDetail , MoAllocate ) = >
{
if ( ! lookup . TryGetValue ( OrderDetail . ProductOrderDtlId , out var _OrderDetail ) )
{
lookup . Add ( OrderDetail . ProductOrderDtlId , OrderDetail ) ;
}
else
{
OrderDetail = _OrderDetail ;
}
OrderDetail . ProductAllocateOrderLst . Add ( MoAllocate ) ;
return OrderDetail ;
} , Param , null , true , "id" , 100 , System . Data . CommandType . Text ) ;
}
return lookup . Values ;
}
2021-01-12 14:45:59 +08:00
public Model . MOM . MomOrder GetModel ( string Code )
{
2021-02-06 09:35:05 +08:00
return this . GetList ( "a.moCode=@Code" , new { Code } ) . FirstOrDefault ( ) ;
2021-01-12 14:45:59 +08:00
}
2021-01-13 10:21:56 +08:00
public IEnumerable < Model . MOM . MomOrder > GetListByLastID ( int Id )
{
2021-02-02 15:20:51 +08:00
return this . GetList ( "b.moid >= @id" , new { Id } ) ;
2021-01-13 10:21:56 +08:00
}
2021-01-12 14:45:59 +08:00
2021-09-01 15:31:16 +08:00
public IEnumerable < NX . ERP . Model . PmcInventorymomRes > Pick ( NX . ERP . Model . Request . MomOrderRequest info )
{
string sql = $ @ "
select * from (
SELECT m . . mocode , CONVERT ( varchar ( 100 ) , mor . StartDate , 23 ) as StartDate , md . Remark , CONVERT ( varchar ( 100 ) , mor . DueDate , 23 ) as DueDate , DATEDIFF ( day , GETDATE ( ) , mor . DueDate ) AS jandete , md . SortSeq , md . InvCode , p . cInvName , p . cInvStd , KK . cComUnitName , md . Qty , md . QualifiedInQty , ( md . Qty - md . QualifiedInQty ) as wwc , ma . InvCode invcode1 ,
c . cInvName cinvname1 , c . cInvStd cinvstd1 , LL . cComUnitName as cComUnitName1 , CASE
WHEN c . bPurchase = 1 AND c . bProxyForeign = 1 and c . bself = 1 THEN ' 外 购 , 委 外 , 自 制 '
WHEN c . bPurchase = 1 AND c . bProxyForeign = 1 and c . bself < > 1 THEN ' 外 购 , 委 外 '
WHEN c . bPurchase = 1 AND c . bProxyForeign < > 1 and c . bself < > 1 THEN ' 外 购 '
WHEN c . bPurchase = 1 AND c . bProxyForeign < > 1 and c . bself = 1 THEN ' 外 购 , 自 制 '
WHEN c . bPurchase < > 1 AND c . bProxyForeign < > 1 and c . bself = 1 THEN ' 自 制 '
WHEN c . bPurchase < > 1 AND c . bProxyForeign = 1 and c . bself = 1 THEN ' 委 外 , 自 制 '
WHEN c . bPurchase < > 1 AND c . bProxyForeign = 1 and c . bself < > 1 THEN ' 委 外 '
ELSE ' 其 它 '
END AS std , ma . Qty qty1 , ma . IssQty issqty , ( ma . Qty - ma . IssQty ) as wll , motype . description ,
2021-09-03 11:30:15 +08:00
CASE WHEN md . Status = 2 THEN ' 锁 定 ' WHEN md . Status = 4 THEN ' 关 闭 ' WHEN md . Status = 3 THEN ' 审 核 ' ELSE ' 新 建 ' END AS st , md . Status , ISNULL ( ds . qty , 0 ) dqty , post . cPosName , ma . SortSeq as invsort
2021-09-01 15:31:16 +08:00
FROM mom_order m WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON m . MoId = md . MoId INNER JOIN
mom_morder mor WITH ( NOLOCK ) ON md . MoDId = mor . MoDId INNER JOIN
mom_moallocate ma WITH ( NOLOCK ) ON md . MoDId = ma . MoDId
left JOIN
mom_motype motype WITH ( NOLOCK ) ON motype . MoTypeId = md . MoTypeId
LEFT JOIN
( SELECT cinvcode , SUM ( iquantity ) qty
FROM InvPositionSum WITH ( NOLOCK ) where cPosCode not in ( ' 00701 ',' 00801 ',' 09001 ' ) and cWhCode not in ( 4 , 5 )
GROUP BY cInvCode ) ds ON ma . InvCode = ds . cInvCode
LEFT JOIN (
SELECT
cinvcode ,
STUFF (
(
SELECT
',' + cPosName
FROM
(
SELECT
b . cPosName ,
a . cInvCode ,
a . iQuantity
FROM
InvPositionSum a WITH ( NOLOCK ) ,
POSITION b WITH ( NOLOCK )
WHERE
a . iQuantity < > 0
AND a . cPosCode = b . cPosCode
) a
WHERE
b . cinvcode = a . cinvcode
ORDER BY
a . iQuantity DESC FOR XML PATH ( ' ' )
) ,
1 ,
1 ,
' '
) cPosName
FROM
InvPositionSum b WITH ( NOLOCK ) where b . cPosCode not in ( ' 00701 ',' 00801 ',' 09001 ' ) and b . cWhCode not in ( 4 , 5 )
GROUP BY
cinvcode
) AS post ON ma . InvCode = post . cinvcode
INNER JOIN
Inventory p WITH ( NOLOCK ) ON md . InvCode = p . cInvCode INNER JOIN
Inventory c WITH ( NOLOCK ) ON ma . InvCode = c . cInvCode LEFT JOIN
ComputationUnit kk WITH ( nolock ) on p . cComUnitCode = kk . cComunitCode
left join ComputationUnit LL WITH ( nolock ) on c . cComUnitCode = LL . cComunitCode
) mmm
";
List < string > where = new List < string > ( ) ;
///处理-
if ( info . moCodes ! = null & & info . moCodes . Count > 0 )
{
where . Add ( " mmm.mocode in @moCodes" ) ;
}
if ( info . InvCodes ! = null )
{
where . Add ( " mmm.InvCode in @invcode" ) ;
}
if ( info . InvCodes1 ! = null )
{
where . Add ( " mmm.invcode1 in @invcode1" ) ;
}
if ( info . byFinish ! = null )
{
where . Add ( " mmm.Status in @byFinish" ) ;
}
if ( ! info . byiss )
{
where . Add ( " isnull(mmm.qty1,0)- isnull(mmm.issqty,0)> 0" ) ;
}
else { where . Add ( " mmm.issqty > 0" ) ; }
var aa = string . Join ( " and " , where . ToArray ( ) ) ;
if ( ! string . IsNullOrEmpty ( aa ) )
{
sql + = "where " + aa ;
}
using ( var conn = NX . ERP . U8 . U8LoginContext . Instance . Connection )
{
return conn . Query < NX . ERP . Model . PmcInventorymomRes > ( sql , new { moCodes = info . moCodes , invcode = info . InvCodes , invcode1 = info . InvCodes1 , info . byFinish } ) ;
}
}
2021-01-12 14:45:59 +08:00
}
}