2021-01-05 16:49:51 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using Dapper ;
namespace NX.ERP.U8.Purchase
{
public class ArrivalDAL
{
2021-05-31 17:06:19 +08:00
public IEnumerable < Model . Purchase . Arrival > GetList ( List < string > strWhere , object param = null )
2021-01-05 16:49:51 +08:00
{
2021-01-25 09:47:41 +08:00
using ( var conn = U8LoginContext . Instance . Connection )
2021-01-05 16:49:51 +08:00
{
2021-03-15 15:50:14 +08:00
string strSQL = @ "select a.id AS ArrivalId,a.cCode as ArrivalCode,a.cpersoncode,a.cpersonname,A.cbustype AS busType,a.cptcode as PTCode,a.iTaxRate as TaxRate,a.iexchrate as Exchrate,cexch_name as ExchName,cVenCode as VenCode,a.dDate as ArrivalDate,A.cVenCode AS SupplierCode,
2021-01-07 14:06:26 +08:00
B . Autoid as id , b . ID as ArrivalID ,
2021-01-28 10:10:32 +08:00
b . cInvCode AS MaterialCode ,
2021-01-07 14:06:26 +08:00
b . cBatch AS BatchNo ,
2021-02-02 15:20:51 +08:00
b . fvalidinquan as RealQuantity ,
2021-03-23 15:06:34 +08:00
b . ccomunitcode AS UnitCode , b . ioricost as oricost , b . ioritaxcost as oritaxcost , b . icost as cost , b . iorimoney as orimoney , b . ioritaxprice as oritaxprice , b . iorisum as orisum , b . isum as sum ,
2021-05-31 17:06:19 +08:00
B . iQuantity as Quantity , b . iposid as PosId , B . CORDERCODE as OrderCode , C . POID as Poid , b . iNum , b . ccomunitcode , b . cunitid , b . cinva_unit , b . cinvm_unit , b . inspecexchrate ,
Pos . cPosName
2021-02-02 15:20:51 +08:00
FROM pu_ArrBody b inner join pu_ArrHead a on a . id = b . id
inner join ( select cinvcode as cinvcode1 , iId from inventory ) inventory on b . cinvcode = inventory . cinvcode1
2021-05-31 17:06:19 +08:00
Left Join PO_Podetails C WITH ( NOLOCK ) ON B . iPOsID = C . ID ,
( SELECT cinvcode ,
STUFF (
(
SELECT ',' + cPosName FROM ( select b . cPosName , a . cInvCode , a . iQuantity from InvPositionSum a WITH ( NOLOCK ) left join Position b WITH ( NOLOCK ) on a . cPosCode = b . cPosCode
where a . iQuantity < > 0 ) a WHERE b . cinvcode = a . cinvcode order by a . iQuantity desc FOR XML PATH ( ' ' )
) , 1 , 1 , ' ' ) cPosName
FROM InvPositionSum b
GROUP BY cinvcode
) Pos - - on isnull ( b . cInvCode , ' ' ) = isnull ( Pos . cInvCode , ' ' )
Where ( ( 1 > 0 ) AND ( 1 > 0 ) ) AND ( 1 > 0 ) and ( isnull ( cbustype , ' ' ) < > ' 委 外 加 工 ' ) and isnull ( b . cInvCode , ' ' ) = isnull ( Pos . cInvCode , ' ' )
2021-02-02 15:20:51 +08:00
And ( 1 = 1 ) and isnull ( b . cbcloser , N ' ' ) = N ' ' And isnull ( a . cverifier , ' ' ) < > ' '
And a . iBillType = N '0' and isnull ( b . bGsp , N ' ' ) = N '0' and ( isnull ( b . iQuantity , 0 ) - isnull ( b . fRefuseQuantity , 0 ) > isnull ( b . fValidInQuan , 0 ) or ( b . igrouptype = 2
2021-05-31 17:06:19 +08:00
and isnull ( b . inum , 0 ) - isnull ( b . frefusenum , 0 ) > isnull ( b . fvalidinnum , 0 ) ) ) and isnull ( a . bStorageArrivalOrder , 1 ) = 1 and 1 = 1
";
var aa = string . Join ( " and " , strWhere . ToArray ( ) ) ;
if ( ! string . IsNullOrEmpty ( aa ) )
2021-01-07 14:06:26 +08:00
{
2021-05-31 17:06:19 +08:00
strSQL + = " and " + aa ;
2021-01-07 14:06:26 +08:00
}
2021-05-31 17:06:19 +08:00
2021-01-05 16:49:51 +08:00
var lookup = new Dictionary < int , Model . Purchase . Arrival > ( ) ;
// return conn.Query<Model.Purchase.Arrival>(strSQL,null);
var list = conn . Query < Model . Purchase . Arrival , Model . Purchase . ArrivalDetail , Model . Purchase . Arrival > ( strSQL , ( arrival , ArrivalDetail ) = >
{
2021-01-21 16:00:58 +08:00
if ( ! lookup . TryGetValue ( arrival . ArrivalId , out var _arrival ) )
2021-01-05 16:49:51 +08:00
{
2021-01-21 16:00:58 +08:00
lookup . Add ( arrival . ArrivalId , arrival ) ;
2021-01-07 14:06:26 +08:00
}
else
2021-01-05 16:49:51 +08:00
{
arrival = _arrival ;
}
2021-01-21 16:00:58 +08:00
arrival . ArrivalDtlLst . Add ( ArrivalDetail ) ;
2021-01-05 16:49:51 +08:00
return arrival ;
2021-01-07 14:06:26 +08:00
} , param , null , true , "id" , 10 , System . Data . CommandType . Text ) ;
2021-01-05 16:49:51 +08:00
return lookup . Values ;
}
}
2021-01-07 14:06:26 +08:00
public Model . Purchase . Arrival GetModel ( int id )
{
2021-05-31 17:06:19 +08:00
List < string > where = new List < string > ( ) ;
where . Add ( "a.id=@Id" ) ;
return this . GetList ( where , new { id } ) . FirstOrDefault ( ) ;
2021-01-07 14:06:26 +08:00
}
2021-01-21 16:00:58 +08:00
public IEnumerable < Model . Purchase . Arrival > Query ( NX . ERP . Model . Request . Arrival arrival )
{
2021-05-31 17:06:19 +08:00
List < string > where = new List < string > ( ) ;
//处理-
if ( ! string . IsNullOrEmpty ( arrival . cInvCode ) )
{
where . Add ( " b.cinvcode = @cinvcode" ) ;
}
if ( arrival . ArrivalNolist ! = null & & arrival . ArrivalNolist . Count > 0 )
{
where . Add ( " a.cCode in @cCodelist" ) ;
}
2021-01-21 16:00:58 +08:00
if ( ! string . IsNullOrEmpty ( arrival . ArrivalNo ) )
{
2021-05-31 17:06:19 +08:00
where . Add ( " a.cCode = @cCode" ) ;
2021-01-21 16:00:58 +08:00
}
2021-05-31 17:06:19 +08:00
return this . GetList ( where , new { cCodelist = arrival . ArrivalNolist , cinvcode = arrival . cInvCode , cCode = arrival . ArrivalNo } ) ;
2021-01-21 16:00:58 +08:00
}
2021-01-07 14:06:26 +08:00
2021-01-13 10:21:56 +08:00
public IEnumerable < Model . Purchase . Arrival > GetListByLastId ( int Id )
{
2021-05-31 17:06:19 +08:00
List < string > where = new List < string > ( ) ;
where . Add ( " a.id>=@Id " ) ;
2021-01-13 10:21:56 +08:00
2021-05-31 17:06:19 +08:00
return this . GetList ( where , new { Id } ) ;
2021-01-13 10:21:56 +08:00
}
2021-01-07 14:06:26 +08:00
public Model . Purchase . Arrival GetModel ( string Code )
{
2021-05-31 17:06:19 +08:00
List < string > where = new List < string > ( ) ;
where . Add ( " a.cCode=@Code " ) ;
return this . GetList ( where , new { Code } ) . FirstOrDefault ( ) ;
2021-01-07 14:06:26 +08:00
}
2021-01-05 16:49:51 +08:00
}
}