2021-05-25 00:40:12 +08:00
using NX.ERP.U8.Purchase ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Web ;
using Dapper ;
namespace NX.ERP.U8.Purchase
{
public class PurchaseQuery
{
/// <summary>
///
/// </summary>
/// <param name="strWhere"></param>
/// <param name="param"></param>
/// <returns></returns>
public IEnumerable < object > InventoryPoc ( NX . ERP . Model . Request . PoOrderRequest info1 )
{
string sql = $ @ "
select * from (
select A . cpersonname , A . cordercode , CONVERT ( varchar ( 100 ) , A . dpodate , 23 ) as dpodate , CONVERT ( varchar ( 100 ) , A . dArriveDate , 23 ) as dArriveDate ,
A . cvenabbname , A . cinvcode , A . cinvname , A . cinvstd , cinvm_unit , A . iquantity
, ( A . iquantity - isnull ( b . YDH , 0 ) ) AS wjh , ( A . iquantity - isnull ( b . YDH , 0 ) + isnull ( E . fRealQuantity , 0 ) ) AS wrk , isnull ( d . iQuantity , 0 ) AS xcl , isnull ( F . iqty , 0 ) AS qll , ( isnull ( d . iQuantity , 0 ) - isnull ( F . iqty , 0 ) ) AS bull , a0 . iQuantity as iQuantity00 , a1 . iQuantity as iQuantity01 from (
SELECT cpersonname , cordercode , dpodate , dArriveDate , cvencode , cvenabbname , cinvcode , cinvname , cinvstd , cinvm_unit , iquantity , id from copypolist WITH ( NOLOCK )
where bposourcearr = 1
and bservice < > 1 and binvtype < > 1
and ( isnull ( iquantity , 0 ) > isnull ( iarrqty , 0 ) or ( isnull ( inum , 0 ) > isnull ( iarrnum , 0 ) and iGroupType = 2 ) )
and isnull ( cbustype , ' ' ) < > N ' 直 运 采 购 ' and ( ( isnull ( cVerifier , ' ' ) < > ' ' and isnull ( cchanger , ' ' ) = ' ' ) or ( isnull ( cchangverifier , ' ' ) < > ' ' ) ) AND 1 = 1
and bInvEntrust = 0 AND isnull ( cbustype , ' ' ) = N ' 普 通 采 购 ' and 1 = 1 and iDiscountTaxType = 0
) A left join
(
select iPOsID , cInvCode , sum ( iQuantity ) AS YDH from PU_ArrivalVouchs WITH ( NOLOCK ) group by iPOsID , cInvCode
) B on A . ID = B . iPOsID and a . cInvCode = B . cInvCode
left join
CurrentStock D WITH ( NOLOCK ) on A . cinvcode = D . cInvCode and d . cWhCode = 2
left join
(
select
A . cInvCode ,
A . fRealQuantity ,
B . cVenCode ,
A . iPOsID
from
PU_ArrivalVouchs A WITH ( NOLOCK ) left join
PU_ArrivalVouch B WITH ( NOLOCK ) on A . ID = B . ID
where isnull ( cbcloser , ' ' ) = ' ' And iBillType = N '0' and cverifier is not null
and ( isnull ( iQuantity , 0 ) - isnull ( fRefuseQuantity , 0 ) > isnull ( fValidInQuan , 0 ) or ( isnull ( inum , 0 ) - isnull ( frefusenum , 0 ) > isnull ( fvalidinnum , 0 ) ) ) )
E on A . cinvcode = e . cInvCode and a . id = e . iPOsID
left join
(
SELECT ma . invcode , SUM ( isnull ( ma . qty , 0 ) - isnull ( issqty , 0 ) ) iqty
FROM mom_moallocate ma WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON ma . MoDId = md . MoDId
WHERE md . Status < > 4 AND ma . Qty - ISNULL ( ma . IssQty , 0 ) > 0
GROUP BY ma . InvCode ) F on A . cinvcode = F . InvCode
left join
( select a . cinvcode , sum ( a . iQuantity ) as iQuantity from (
select a . cinvcode , iQuantity from rdrecords11 a WITH ( nolock ) left join rdrecord11 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( getdate ( ) ) + 1 , getdate ( ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( getdate ( ) ) , dateadd ( month , 1 , getdate ( ) ) ) , 112 )
union all
select a . cinvcode , iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( getdate ( ) ) + 1 , getdate ( ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( getdate ( ) ) , dateadd ( month , 1 , getdate ( ) ) ) , 112 )
) a
group by a . cinvcode
) a0 on a . cInvCode = a0 . cInvCode
left join
( select a . cinvcode , sum ( a . iQuantity ) as iQuantity from (
select a . cinvcode , sum ( a . iQuantity ) as iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) + 1 , dateadd ( month , - 1 , getdate ( ) ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) , dateadd ( month , 1 , dateadd ( month , - 1 , getdate ( ) ) ) ) , 112 )
group by a . cinvcode
union all
select a . cinvcode , sum ( a . iQuantity ) as iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) + 1 , dateadd ( month , - 1 , getdate ( ) ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) , dateadd ( month , 1 , dateadd ( month , - 1 , getdate ( ) ) ) ) , 112 )
group by a . cinvcode
) a
group by a . cinvcode
) a1 on a . cInvCode = a1 . cInvCode
) mmm
";
if ( info1 . BeginDate2 ! = null & & info1 . EndDate2 ! = null )
{
sql = $ @ "select *from (
select A . cpersonname , A . cordercode , CONVERT ( varchar ( 100 ) , A . dpodate , 23 ) as dpodate , CONVERT ( varchar ( 100 ) , A . dArriveDate , 23 ) as dArriveDate ,
A . cvencode , A . cvenabbname , A . cinvcode , A . cinvname , A . cinvstd , cinvm_unit , A . iquantity
, ( A . iquantity - isnull ( b . YDH , 0 ) ) AS wjh , ( A . iquantity - isnull ( b . YDH , 0 ) + isnull ( E . fRealQuantity , 0 ) ) AS wrk , isnull ( d . iQuantity , 0 ) AS xcl , isnull ( F . iqty , 0 ) AS qll , ( isnull ( d . iQuantity , 0 ) - isnull ( F . iqty , 0 ) ) AS bull , a0 . iQuantity as iQuantity00 , a1 . iQuantity as iQuantity01 from (
SELECT cpersonname , cordercode , dpodate , dArriveDate , cvencode , cvenabbname , cinvcode , cinvname , cinvstd , cinvm_unit , iquantity , id from copypolist WITH ( NOLOCK )
where bposourcearr = 1
and bservice < > 1 and binvtype < > 1
and ( isnull ( iquantity , 0 ) > isnull ( iarrqty , 0 ) or ( isnull ( inum , 0 ) > isnull ( iarrnum , 0 ) and iGroupType = 2 ) )
and isnull ( cbustype , ' ' ) < > N ' 直 运 采 购 ' and ( ( isnull ( cVerifier , ' ' ) < > ' ' and isnull ( cchanger , ' ' ) = ' ' ) or ( isnull ( cchangverifier , ' ' ) < > ' ' ) ) AND 1 = 1
and bInvEntrust = 0 AND isnull ( cbustype , ' ' ) = N ' 普 通 采 购 ' and 1 = 1 and iDiscountTaxType = 0
) A left join
(
select iPOsID , cInvCode , sum ( iQuantity ) AS YDH from PU_ArrivalVouchs WITH ( NOLOCK ) group by iPOsID , cInvCode
) B on A . ID = B . iPOsID and a . cInvCode = B . cInvCode
left join
CurrentStock D WITH ( NOLOCK ) on A . cinvcode = D . cInvCode and d . cWhCode = 2
left join
(
select
A . cInvCode ,
A . fRealQuantity ,
B . cVenCode ,
A . iPOsID
from
PU_ArrivalVouchs A WITH ( NOLOCK ) left join
PU_ArrivalVouch B WITH ( NOLOCK ) on A . ID = B . ID
where isnull ( cbcloser , ' ' ) = ' ' And iBillType = N '0' and cverifier is not null
and ( isnull ( iQuantity , 0 ) - isnull ( fRefuseQuantity , 0 ) > isnull ( fValidInQuan , 0 ) or ( isnull ( inum , 0 ) - isnull ( frefusenum , 0 ) > isnull ( fvalidinnum , 0 ) ) ) )
E on A . cinvcode = e . cInvCode and a . id = e . iPOsID
left join
(
SELECT ma . invcode , SUM ( isnull ( ma . qty , 0 ) - isnull ( issqty , 0 ) ) iqty
FROM mom_moallocate ma WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON ma . MoDId = md . MoDId left join
mom_morder mor WITH ( NOLOCK ) ON ma . MoDId = mor . MoDId
WHERE md . Status < > 4 AND ma . Qty - ISNULL ( ma . IssQty , 0 ) > 0 and mor . DueDate between @beginDate2 and @endDate2
GROUP BY ma . InvCode ) F on A . cinvcode = F . InvCode
left join
( select a . cinvcode , sum ( a . iQuantity ) as iQuantity from (
select a . cinvcode , iQuantity from rdrecords11 a WITH ( nolock ) left join rdrecord11 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( getdate ( ) ) + 1 , getdate ( ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( getdate ( ) ) , dateadd ( month , 1 , getdate ( ) ) ) , 112 )
union all
select a . cinvcode , iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( getdate ( ) ) + 1 , getdate ( ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( getdate ( ) ) , dateadd ( month , 1 , getdate ( ) ) ) , 112 )
) a
group by a . cinvcode
) a0 on a . cInvCode = a0 . cInvCode
left join
( select a . cinvcode , sum ( a . iQuantity ) as iQuantity from (
select a . cinvcode , sum ( a . iQuantity ) as iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) + 1 , dateadd ( month , - 1 , getdate ( ) ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) , dateadd ( month , 1 , dateadd ( month , - 1 , getdate ( ) ) ) ) , 112 )
group by a . cinvcode
union all
select a . cinvcode , sum ( a . iQuantity ) as iQuantity from rdrecords32 a WITH ( nolock ) left join rdrecord32 b WITH ( nolock ) on a . id = b . id
where convert ( varchar , b . dDate , 112 ) between convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) + 1 , dateadd ( month , - 1 , getdate ( ) ) ) , 112 )
and convert ( varchar , dateadd ( day , - day ( dateadd ( month , - 1 , getdate ( ) ) ) , dateadd ( month , 1 , dateadd ( month , - 1 , getdate ( ) ) ) ) , 112 )
group by a . cinvcode
) a
group by a . cinvcode
) a1 on a . cInvCode = a1 . cInvCode
) mmm
";
}
List < string > where = new List < string > ( ) ;
2021-05-26 17:05:28 +08:00
if ( ! string . IsNullOrEmpty ( info1 . cMaker ) )
{
where . Add ( " mmm.cpersonname like @cMaker" ) ;
}
if ( ! string . IsNullOrEmpty ( info1 . vendor ) )
{
where . Add ( " mmm.cvenabbname like @vendor " ) ;
}
2021-05-25 00:40:12 +08:00
if ( info1 . InvCodes ! = null )
{
where . Add ( " mmm.cinvcode in @cinvcode" ) ;
}
if ( ! string . IsNullOrEmpty ( info1 . InvStd ) )
{
where . Add ( " mmm.cinvstd like @cInvStd " ) ;
}
if ( info1 . PoCodes ! = null )
{
where . Add ( " mmm.cordercode in @PoCodes " ) ;
}
if ( info1 . BeginDate ! = null & & info1 . EndDate ! = null )
{
where . Add ( " mmm.dPODate between @beginDate and @endDate " ) ;
}
var aa = string . Join ( " and " , where . ToArray ( ) ) ;
if ( ! string . IsNullOrEmpty ( aa ) )
{
sql + = "where " + aa ;
}
using ( var conn = NX . ERP . U8 . U8LoginContext . Instance . Connection )
{
2021-05-26 17:05:28 +08:00
return conn . Query < object > ( sql , new { cinvcode = info1 . InvCodes , info1 . cMaker , info1 . vendor , cInvStd = $"%{info1.InvStd}%" , info1 . PoCodes , info1 . AppCodes , info1 . BeginDate , info1 . EndDate , info1 . BeginDate2 , info1 . EndDate2 } ) ;
2021-05-25 00:40:12 +08:00
}
}
2021-05-25 11:59:26 +08:00
public IEnumerable < object > Purchasesum ( NX . ERP . Model . Request . PurchasesumRequest info )
2021-05-25 00:40:12 +08:00
{
string sql = $ @ "
2021-08-02 13:13:21 +08:00
DECLARE @RdRecord table (
2021-05-25 00:40:12 +08:00
cPsn_Num nvarchar ( 30 ) ,
cpersonname nvarchar ( 30 ) ,
puappnumall int ,
puappnum03 int ,
mommouth02 int ,
mommouth04 int
)
DECLARE @RdRecord2 table (
cpersonname nvarchar ( 30 ) ,
puappnumall int
)
DECLARE @RdRecord3 table (
cpersonname nvarchar ( 30 ) ,
puappnumall int
)
DECLARE @RdRecord4 table (
cpersonname nvarchar ( 30 ) ,
puappnumall int
)
DECLARE @RdRecord5 table (
cpersonname nvarchar ( 30 ) ,
puappnumall int
)
insert into @RdRecord
2021-05-26 17:05:28 +08:00
select cPsn_Num , cPsn_Name , 0 , 0 , 0 , 0 from hr_v_HR31_show WITH ( nolock ) where cDepCode = ' 52 ' and rEmployState = ' 在 职 ' and cPsn_Name < > ' 朱 华 英 '
2021-05-25 00:40:12 +08:00
insert into @RdRecord
select ' qt999 ',' 其 他 ' , 0 , 0 , 0 , 0
insert into @RdRecord2
select cPsn_Num , sum ( RQTY3 ) as puappnumall from (
select RQTY3 , isnull ( cMaker , ' 其 他 ' ) as cPsn_Num from
(
SELECT CINVCODE , SUM ( RQTY ) AS RQTY3
FROM (
SELECT ommds . cInvCode , 1 as RQTY
FROM pu_AppHead omm WITH ( nolock ) INNER JOIN
pu_appbody ommds WITH ( nolock ) ON omm . id = ommds . id LEFT JOIN
( SELECT iAppIds , sum ( iquantity ) AS qty
FROM PO_Podetails WITH ( nolock )
2021-05-26 08:50:35 +08:00
GROUP BY iAppIds ) rds ON isnull ( ommds . autoid , ' ' ) = isnull ( rds . iAppIds , ' ' )
2021-06-21 10:58:48 +08:00
WHERE ISNULL ( OMM . cCloser , N ' ' ) = N ' ' AND ISNULL ( ommds . cbCloser , N ' ' ) = N ' ' AND ISNULL ( omm . cverifier , N ' ' ) < > N ' ' AND ISNULL ( rds . qty , 0 ) = 0 and ommds . iReceivedQTY = 0 and
2021-05-25 00:40:12 +08:00
ommds . fquantity - ISNULL ( rds . qty , 0 ) > 0 ) OM
GROUP BY cInvCode
) as tbl1
left join
(
2021-05-26 17:05:28 +08:00
select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( NOLOCK ) , PO_Podetails b WITH ( NOLOCK ) where a . poid = b . poid )
2021-05-25 00:40:12 +08:00
as c where c . rownumber = 1
)
as tbl on tbl1 . cinvcode = tbl . cInvCode
) q group by cPsn_Num
2021-06-29 16:12:29 +08:00
update a set a . cpersonname = b . receive From @RdRecord2 a left join CGBB2021_0001_E001 b WITH ( NOLOCK ) on a . cpersonname = b . quit
where b . quit is not null
2021-08-02 13:13:21 +08:00
update a set a . puappnumall = isnull ( b . puappnumall , 0 ) From @RdRecord a left join
2021-06-29 16:12:29 +08:00
( select cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord2 group by cpersonname ) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . puappnumall = isnull ( a . puappnumall , 0 ) + isnull ( b . puappnumall , 0 ) From @RdRecord a left join (
2021-05-25 00:40:12 +08:00
select ' 其 他 ' as cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord2 where cpersonname not in ( select cpersonname From @RdRecord ) ) b on a . cpersonname = b . cpersonname
2021-08-02 13:13:21 +08:00
where a . cpersonname = ' 其 他 '
2021-05-25 00:40:12 +08:00
insert into @RdRecord3
select cPsn_Num , sum ( RQTY3 ) as puappnumall from (
select RQTY3 , isnull ( cMaker , ' 其 他 ' ) as cPsn_Num from
(
SELECT CINVCODE , SUM ( RQTY ) AS RQTY3
FROM (
SELECT ommds . cInvCode , 1 as RQTY
FROM pu_AppHead omm WITH ( nolock ) INNER JOIN
pu_appbody ommds WITH ( nolock ) ON omm . id = ommds . id LEFT JOIN
( SELECT iAppIds , sum ( iquantity ) AS qty
FROM PO_Podetails WITH ( nolock )
2021-05-26 08:50:35 +08:00
GROUP BY iAppIds ) rds ON isnull ( ommds . autoid , ' ' ) = isnull ( rds . iAppIds , ' ' )
2021-06-21 10:58:48 +08:00
WHERE ISNULL ( OMM . cCloser , N ' ' ) = N ' ' AND ISNULL ( ommds . cbCloser , N ' ' ) = N ' ' AND ISNULL ( omm . cverifier , N ' ' ) < > N ' ' AND ISNULL ( rds . qty , 0 ) = 0 and ommds . iReceivedQTY = 0 and DATEDIFF ( day , ddate , GETDATE ( ) ) > = 3 and
2021-05-25 00:40:12 +08:00
ommds . fquantity - ISNULL ( rds . qty , 0 ) > 0 ) OM
GROUP BY cInvCode
) as tbl1
left join
(
2021-05-26 17:05:28 +08:00
select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( NOLOCK ) , PO_Podetails b WITH ( NOLOCK ) where a . poid = b . poid )
2021-05-25 00:40:12 +08:00
as c where c . rownumber = 1
)
as tbl on tbl1 . cinvcode = tbl . cInvCode
) q group by cPsn_Num
2021-06-29 16:12:29 +08:00
update a set a . cpersonname = b . receive From @RdRecord3 a left join CGBB2021_0001_E001 b WITH ( NOLOCK ) on a . cpersonname = b . quit
where b . quit is not null
2021-08-02 13:13:21 +08:00
update a set a . puappnum03 = isnull ( b . puappnumall , 0 ) From @RdRecord a left join
2021-06-29 16:12:29 +08:00
( select cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord3 group by cpersonname ) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . puappnum03 = isnull ( a . puappnum03 , 0 ) + isnull ( b . puappnumall , 0 ) From @RdRecord a left join (
2021-05-25 00:40:12 +08:00
select ' 其 他 ' as cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord3 where cpersonname not in ( select cpersonname From @RdRecord ) ) b on a . cpersonname = b . cpersonname
where a . cpersonname = ' 其 他 '
insert into @RdRecord4
select cPsn_Num , sum ( RQTY3 ) as puappnumall from (
select RQTY3 , isnull ( cMaker , ' 其 他 ' ) as cPsn_Num from
(
SELECT CINVCODE , SUM ( RQTY ) AS RQTY3
FROM (
select a . InvCode as CINVCODE , 1 as RQTY From (
SELECT ma . invcode , SUM ( isnull ( ma . qty , 0 ) - isnull ( issqty , 0 ) ) iqty
FROM mom_moallocate ma WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON ma . MoDId = md . MoDId left join
mom_morder mor WITH ( NOLOCK ) ON ma . MoDId = mor . MoDId
WHERE md . Status < > 4 AND ma . Qty - ISNULL ( ma . IssQty , 0 ) > 0 and
2021-05-25 11:59:26 +08:00
mor . DueDate between @beginDate and @endDate
2021-05-25 00:40:12 +08:00
GROUP BY ma . InvCode
) a left join
CurrentStock cur WITH ( NOLOCK ) ON cur . cInvCode = a . InvCode where ( cur . iQuantity - iqty ) < 0 ) OM
GROUP BY cInvCode
) as tbl1
left join
(
2021-05-26 17:05:28 +08:00
select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( NOLOCK ) , PO_Podetails b WITH ( NOLOCK ) where a . poid = b . poid )
2021-05-25 00:40:12 +08:00
as c where c . rownumber = 1
)
as tbl on tbl1 . cinvcode = tbl . cInvCode )
q group by cPsn_Num
2021-06-29 16:12:29 +08:00
update a set a . cpersonname = b . receive From @RdRecord4 a left join CGBB2021_0001_E001 b WITH ( NOLOCK ) on a . cpersonname = b . quit
where b . quit is not null
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . mommouth02 = isnull ( b . puappnumall , 0 ) From @RdRecord a left join
2021-06-29 16:12:29 +08:00
( select cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord4 group by cpersonname
) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . mommouth02 = isnull ( a . mommouth02 , 0 ) + isnull ( b . mommouth02 , 0 ) From @RdRecord a left join (
2021-05-25 11:59:26 +08:00
select ' 其 他 ' as cpersonname , sum ( puappnumall ) as mommouth02 from @RdRecord4 where cpersonname not in ( select cpersonname From @RdRecord ) ) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
where a . cpersonname = ' 其 他 '
insert into @RdRecord5
select cPsn_Num , sum ( RQTY3 ) as puappnumall from (
select RQTY3 , isnull ( cMaker , ' 其 他 ' ) as cPsn_Num from
(
SELECT CINVCODE , SUM ( RQTY ) AS RQTY3
FROM (
select a . InvCode as CINVCODE , 1 as RQTY From (
SELECT ma . invcode , SUM ( isnull ( ma . qty , 0 ) - isnull ( issqty , 0 ) ) iqty
FROM mom_moallocate ma WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON ma . MoDId = md . MoDId left join
mom_morder mor WITH ( NOLOCK ) ON ma . MoDId = mor . MoDId
WHERE md . Status < > 4 AND ma . Qty - ISNULL ( ma . IssQty , 0 ) > 0 and
2021-05-25 11:59:26 +08:00
mor . DueDate between @beginDate2 and @endDate2
2021-05-25 00:40:12 +08:00
GROUP BY ma . InvCode
) a left join
CurrentStock cur WITH ( NOLOCK ) ON cur . cInvCode = a . InvCode where ( cur . iQuantity - iqty ) < 0 ) OM
GROUP BY cInvCode
) as tbl1
left join
(
2021-05-26 17:05:28 +08:00
select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( NOLOCK ) , PO_Podetails b WITH ( NOLOCK ) where a . poid = b . poid )
2021-05-25 00:40:12 +08:00
as c where c . rownumber = 1
)
as tbl on tbl1 . cinvcode = tbl . cInvCode )
q group by cPsn_Num
2021-06-29 16:12:29 +08:00
update a set a . cpersonname = b . receive From @RdRecord5 a left join CGBB2021_0001_E001 b WITH ( NOLOCK ) on a . cpersonname = b . quit
where b . quit is not null
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . mommouth04 = isnull ( b . puappnumall , 0 ) From @RdRecord a left join (
2021-06-29 16:12:29 +08:00
select cpersonname , sum ( puappnumall ) as puappnumall from @RdRecord5 group by cpersonname ) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
2021-08-02 13:13:21 +08:00
update a set a . mommouth04 = isnull ( a . mommouth04 , 0 ) + isnull ( b . mommouth04 , 0 ) From @RdRecord a left join (
2021-05-25 11:59:26 +08:00
select ' 其 他 ' as cpersonname , sum ( puappnumall ) as mommouth04 from @RdRecord5 where cpersonname not in ( select cpersonname From @RdRecord ) ) b on a . cpersonname = b . cpersonname
2021-05-25 00:40:12 +08:00
where a . cpersonname = ' 其 他 '
2021-06-29 16:12:29 +08:00
delete from @RdRecord where cpersonname in ( select quit from CGBB2021_0001_E001 )
2021-05-25 00:40:12 +08:00
select * from @RdRecord
2021-05-26 08:50:35 +08:00
2021-06-29 16:12:29 +08:00
2021-05-25 00:40:12 +08:00
";
2021-05-25 11:59:26 +08:00
using ( var conn = NX . ERP . U8 . U8LoginContext . Instance . Connection )
2021-05-25 00:40:12 +08:00
{
2021-05-25 11:59:26 +08:00
return conn . Query < object > ( sql , new { info . BeginDate , info . EndDate , info . BeginDate2 , info . EndDate2 } ) ;
2021-05-25 00:40:12 +08:00
}
}
public IEnumerable < object > Purchasesumpuapp ( NX . ERP . Model . Request . PurchasesumRequest info )
{
string sql = $ @ "
2021-06-29 16:12:29 +08:00
IF EXISTS ( SELECT NAME FROM tempdb . . SYSOBJECTS WHERE NAME = ' tablepuapp20210625 ' AND Xtype = 'U' ) DROP Table tempdb . . tablepuapp20210625
create table tempdb . . tablepuapp20210625 (
ccode nvarchar ( 200 ) ,
dDatel nvarchar ( 200 ) ,
ddate datetime ,
cInvCode nvarchar ( 200 ) ,
cinvname nvarchar ( 500 ) ,
cinvstd nvarchar ( 500 ) ,
RQTY decimal ( 28 , 6 ) ,
cMaker nvarchar ( 200 )
)
CREATE INDEX IX_test ON tempdb . . tablepuapp20210625 ( cinvcode )
insert into tempdb . . tablepuapp20210625
select * from (
SELECT omm . ccode , CONVERT ( varchar ( 100 ) , omm . ddate , 23 ) as dDatel , omm . ddate , ommds . cInvCode , ommds . cinvname , ommds . cinvstd , ommds . fquantity - ISNULL ( rds . qty , 0 ) as RQTY , isnull ( isnull ( k . receive , f . cMaker ) , ' 其 他 ' ) as cMaker
2021-05-25 00:40:12 +08:00
FROM pu_AppHead omm WITH ( nolock ) INNER JOIN
pu_appbody ommds WITH ( nolock ) ON omm . id = ommds . id LEFT JOIN
( SELECT iAppIds , sum ( iquantity ) AS qty
FROM PO_Podetails WITH ( nolock )
2021-05-26 08:50:35 +08:00
GROUP BY iAppIds ) rds ON isnull ( ommds . autoid , ' ' ) = isnull ( rds . iAppIds , ' ' )
2021-05-25 00:40:12 +08:00
left join
2021-05-26 17:05:28 +08:00
( select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( nolock ) , PO_Podetails b WITH ( nolock ) where a . poid = b . poid )
2021-05-25 00:40:12 +08:00
as c where c . rownumber = 1 ) f on ommds . cInvCode = f . cInvCode
2021-06-29 16:12:29 +08:00
left join CGBB2021_0001_E001 k WITH ( NOLOCK ) on f . cMaker = k . quit
2021-06-21 10:58:48 +08:00
WHERE ISNULL ( OMM . cCloser , N ' ' ) = N ' ' AND ISNULL ( ommds . cbCloser , N ' ' ) = N ' ' AND ISNULL ( omm . cverifier , N ' ' ) < > N ' ' AND ISNULL ( rds . qty , 0 ) = 0 and ommds . iReceivedQTY = 0 AND
2021-06-29 16:12:29 +08:00
ommds . fquantity - ISNULL ( rds . qty , 0 ) > 0 ) puapp
update tempdb . . tablepuapp20210625 set cmaker = ' 其 他 ' where cMaker not in ( select cPsn_Name from hr_v_HR31_show WITH ( NOLOCK ) where cDepCode = ' 52 ' and rEmployState = ' 在 职 ' )
and cMaker not in ( select quit from CGBB2021_0001_E001 WITH ( NOLOCK ) )
select * From tempdb . . tablepuapp20210625 puu
2021-05-25 00:40:12 +08:00
";
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( info . cpersonname ) )
{
where . Add ( " puu.cMaker = @cpersonname" ) ;
}
if ( info . InvCodes ! = null )
{
2021-05-25 11:59:26 +08:00
where . Add ( " puu.cInvCode in @InvCodes" ) ;
2021-05-25 00:40:12 +08:00
}
if ( info . cday > 0 )
{
where . Add ( " DATEDIFF(day,puu.ddate ,GETDATE()) >=@cday" ) ;
}
var aa = string . Join ( " and " , where . ToArray ( ) ) ;
if ( ! string . IsNullOrEmpty ( aa ) )
{
sql + = "where " + aa ;
}
2021-05-25 11:59:26 +08:00
using ( var conn = NX . ERP . U8 . U8LoginContext . Instance . Connection )
2021-05-25 00:40:12 +08:00
{
return conn . Query < object > ( sql , new { info . cpersonname , info . InvCodes , info . cday } ) ;
}
}
2021-05-25 11:59:26 +08:00
public IEnumerable < object > Purchasesummom ( NX . ERP . Model . Request . PurchasesumRequest info )
{
string sql = $ @ "
2021-06-29 16:12:29 +08:00
IF EXISTS ( SELECT NAME FROM tempdb . . SYSOBJECTS WHERE NAME = ' tablemom20210625 ' AND Xtype = 'U' ) DROP Table tempdb . . tablemom20210625
create table tempdb . . tablemom20210625 (
CINVCODE nvarchar ( 200 ) ,
2021-05-25 12:09:57 +08:00
RQTY int ,
iqty int ,
iQuantity int ,
bull int ,
cpersonname nvarchar ( 200 ) ,
cInvName nvarchar ( 200 ) ,
cInvStd nvarchar ( 500 )
2021-06-29 16:12:29 +08:00
)
insert into tempdb . . tablemom20210625
2021-05-25 12:09:57 +08:00
select * from (
2021-06-29 16:12:29 +08:00
select a . * , isnull ( isnull ( k . receive , f . cMaker ) , ' 其 他 ' ) as cpersonname , inv . cInvName , inv . cInvStd from (
2021-05-25 12:09:57 +08:00
select a . InvCode as CINVCODE , 1 as RQTY , iqty , cur . iQuantity , ( cur . iQuantity - iqty ) as bull From (
SELECT ma . invcode , SUM ( isnull ( ma . qty , 0 ) - isnull ( issqty , 0 ) ) iqty
FROM mom_moallocate ma WITH ( NOLOCK ) INNER JOIN
mom_orderdetail md WITH ( NOLOCK ) ON ma . MoDId = md . MoDId left join
mom_morder mor WITH ( NOLOCK ) ON ma . MoDId = mor . MoDId
2021-05-25 11:59:26 +08:00
2021-05-25 12:09:57 +08:00
WHERE md . Status < > 4 AND ma . Qty - ISNULL ( ma . IssQty , 0 ) > 0 and
mor . DueDate between @beginDate and @endDate
GROUP BY ma . InvCode
) a left join
CurrentStock cur WITH ( NOLOCK ) ON cur . cInvCode = a . InvCode where ( cur . iQuantity - iqty ) < 0
) a left join
( select cInvCode , cMaker from ( select cInvCode , ROW_NUMBER ( ) over ( partition by b . cInvCode order by a . poid desc ) as rownumber , a . cMaker from PO_Pomain a WITH ( NOLOCK ) , PO_Podetails b WITH ( NOLOCK ) where a . poid = b . poid )
as c where c . rownumber = 1 ) f on a . CINVCODE = f . cInvCode
2021-06-29 16:12:29 +08:00
left join CGBB2021_0001_E001 k WITH ( NOLOCK ) on f . cMaker = k . quit
2021-05-25 12:09:57 +08:00
left join Inventory inv WITH ( NOLOCK ) on a . CINVCODE = inv . cInvCode ) pumo
2021-06-29 16:12:29 +08:00
update tempdb . . tablemom20210625 set cpersonname = ' 其 他 ' where cpersonname not in ( select cPsn_Name from hr_v_HR31_show WITH ( NOLOCK ) where cDepCode = ' 52 ' and rEmployState = ' 在 职 ' )
and cpersonname not in ( select quit from CGBB2021_0001_E001 WITH ( NOLOCK ) )
2021-05-25 12:09:57 +08:00
2021-06-29 16:12:29 +08:00
select * From tempdb . . tablemom20210625
2021-05-25 11:59:26 +08:00
";
List < string > where = new List < string > ( ) ;
if ( ! string . IsNullOrEmpty ( info . cpersonname ) )
{
2021-05-25 12:09:57 +08:00
where . Add ( " cpersonname = @cpersonname" ) ;
2021-05-25 11:59:26 +08:00
}
if ( info . InvCodes ! = null )
{
2021-05-25 12:09:57 +08:00
where . Add ( " cInvCode = @InvCodes" ) ;
2021-05-25 11:59:26 +08:00
}
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 < object > ( sql , new { info . cpersonname , info . InvCodes , info . cday , info . BeginDate , info . EndDate } ) ;
}
}
2021-10-24 16:35:25 +08:00
public NX . ERP . Model . PmcWwInvlRes Purchasesuww ( )
{
var PmcWwInvlRes = new NX . ERP . Model . PmcWwInvlRes ( ) ;
using ( var conn = U8LoginContext . Instance . Connection )
{
var sql = @ " select aa.TaskItemID,aa.materialid,dd.code,dd.name,dd.standard, CONVERT(DECIMAL(13,3),aa.Qua) as Qua , CONVERT(DECIMAL(13,3),bb.qty) as qty , CONVERT(DECIMAL(13,3),(isnull(aa.Qua,0)-isnull(bb.qty,0))) as diff from [10.0.0.230].wxnx2021.dbo.t_TaskItem aa left join (
select TaskItemID , sum ( Qua ) AS qty
from [ 10.0 . 0.230 ] . wxnx2021 . dbo . t_OutSourcing_SendItems a left join
[10.0.0.230] . wxnx2021 . dbo . t_OutSourcing_SendSheet b on a . SID_Sheet = b . SID_Sheet
where b . IsChecked = 1 and isnull ( b . IsDeleted , 0 ) = 0 group by TaskItemID ) bb on aa . SID_Item = bb . TaskItemID
left join [ 10.0 . 0.230 ] . wxnx2021 . dbo . t_TaskSheet cc on aa . SID_Sheet = cc . SID_Sheet
left join [ 10.0 . 0.230 ] . wxnx2021 . dbo . t_Material dd on dd . SysID = aa . materialid
where cc . IsChecked = 1 and ( isnull ( aa . Qua , 0 ) - isnull ( bb . qty , 0 ) ) > 0 and cc . SheetType = 3 and isnull ( cc . IsDeleted , 0 ) = 0
";
PmcWwInvlRes . wfdetails = conn . Query < NX . ERP . Model . wfdetail > ( sql , "" ) ;
var sql2 = @ " select b.sheetid,dd.code,dd.name,dd.standard, CONVERT(DECIMAL(13,3),a.Qua) as Qua, CONVERT(DECIMAL(13,3),a.ReceivedQua) as ReceivedQua , CONVERT(DECIMAL(13,3),a.Qua-a.ReceivedQua) as diff
from [ 10.0 . 0.230 ] . wxnx2021 . dbo . t_OutSourcing_SendItems a left join
[10.0.0.230] . wxnx2021 . dbo . t_OutSourcing_SendSheet b on a . SID_Sheet = b . SID_Sheet
left join [ 10.0 . 0.230 ] . wxnx2021 . dbo . t_Material dd on dd . SysID = a . materialid
where b . IsChecked = 1 and isnull ( b . IsDeleted , 0 ) = 0 and a . Qua < > a . ReceivedQua
";
PmcWwInvlRes . wsdetails = conn . Query < NX . ERP . Model . wsdetail > ( sql2 , "" ) ;
PmcWwInvlRes . wfjl = PmcWwInvlRes . wfdetails . Count ( ) ;
PmcWwInvlRes . wsjl = PmcWwInvlRes . wsdetails . Count ( ) ;
}
return PmcWwInvlRes ;
}
2021-05-25 00:40:12 +08:00
}
}